Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDB BMS - Control FETs for charge, discharge and disable / enable balancer #761

Merged
merged 269 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
269 commits
Select commit Hold shift + click to select a range
9774633
Update jkbms_brn.py (#411)
baranator Jan 14, 2023
7052a7b
update version
Louisvdw Jan 14, 2023
183910c
update version
Louisvdw Jan 14, 2023
60a4cf4
workaround for crash of bluetooth-stack
Jan 20, 2023
4af0a5a
lint
Jan 20, 2023
7d0e167
added info-message
Jan 21, 2023
edd9da8
workaround for dying bluetooth working
baranator Feb 7, 2023
e35cc51
added battery details
mr-manuel Feb 9, 2023
a02e71d
changed cell imbalance thresholds
mr-manuel Feb 11, 2023
8bac054
added battery details
mr-manuel Feb 12, 2023
a668a24
JKBMS Bluetooth - added battery details (#454)
mr-manuel Feb 13, 2023
f07eb01
added support for the newer 32s systems, that have slightly different…
baranator Feb 15, 2023
770d054
syncing with upstream
Feb 16, 2023
4e8bbb5
added stop of scraping if detection of jkbms fails
Feb 16, 2023
c734938
lint
Feb 16, 2023
ea6a1c3
indentation was wrong
mr-manuel Feb 17, 2023
fbbd17b
adding fix for Venus OS >= v3.00~14 QML files
mr-manuel Feb 20, 2023
23a60db
merge with baranator:dbus-serialbattery:master
mr-manuel Mar 5, 2023
2eae591
BLE JK BMS model recognition
mr-manuel Mar 5, 2023
d9518f2
Small fixes
mr-manuel Mar 6, 2023
de39112
Added driver restart script
mr-manuel Mar 6, 2023
a6668f6
added informations to run the driver
mr-manuel Mar 9, 2023
c8a5796
pasted code in wrong function
mr-manuel Mar 9, 2023
dd14607
fixed cell balancing color
mr-manuel Mar 10, 2023
3ba192d
Merge branch 'master' into jdb_ble
Mar 18, 2023
b05738d
BLE support for JBD
Mar 22, 2023
dd2f7b3
feature: Improve BLE async communication
Mar 23, 2023
99e1835
bugfix: Failing dbus-systemcalc due to ':' in /Mgmt/Connection
Mar 23, 2023
3d140f1
clean-up
Mar 23, 2023
a37244f
Fix dbus-systemcalc requires for TimeToGo integer value only
Mar 23, 2023
30dacf6
clean-up #2
Mar 23, 2023
eecd512
clean-up
Mar 23, 2023
7009e65
Remove dependency on statistics (not available by default on VenusOS)
Mar 23, 2023
3f67884
BLE JK BMS model recognition (#462)
tcrichton Mar 27, 2023
500e7ab
Merge branch 'jkbms_ble' into master
baranator Mar 28, 2023
b0a97e3
install BLE battery as local independent service
Mar 28, 2023
79f82f0
add disconnect before starting the service
Mar 29, 2023
2a65d6c
unique id per BLE device
Mar 29, 2023
646ca4c
Merge branch 'jkbms_ble' into jkbms_ble
mr-manuel Mar 29, 2023
0a2adb2
enable logging and improve error messages
Mar 29, 2023
f5eb089
Merge pull request #466 from baranator/master
mr-manuel Apr 12, 2023
8eabbc4
Merge branch 'jkbms_ble' into jkbms_ble
mr-manuel Apr 13, 2023
acea6bf
Merge pull request #503 from mr-manuel/jkbms_ble
mr-manuel Apr 13, 2023
20d828f
Merge branch 'jkbms_ble' into jkbms_ble
mr-manuel Apr 13, 2023
5065083
Merge pull request #502 from seidler2547/jkbms_ble
mr-manuel Apr 13, 2023
5f3fc34
Update jkbms_ble from master
mr-manuel Apr 13, 2023
534c483
fixes
mr-manuel Apr 13, 2023
26e07aa
Merge pull request #527 from mr-manuel/jkbms_ble
mr-manuel Apr 13, 2023
9c0290f
moved ble part to installble.sh
mr-manuel Apr 15, 2023
ee840ce
added script to install directly from repository
mr-manuel Apr 15, 2023
9488b83
added QML
mr-manuel Apr 15, 2023
953fbb4
create empty config.ini for easier user usage
mr-manuel Apr 15, 2023
92bb2a0
optimize installation scripts
mr-manuel Apr 15, 2023
cd8a30f
changed bash output
mr-manuel Apr 15, 2023
efd5555
added post install notes
mr-manuel Apr 15, 2023
60ddcf2
corrected errors
mr-manuel Apr 15, 2023
c3a50a4
fix black lint errors
mr-manuel Apr 15, 2023
3b82562
Merge branch 'Louisvdw:jkbms_ble' into jkbms_ble
mr-manuel Apr 15, 2023
fd1894a
fix black lint errors
mr-manuel Apr 15, 2023
5ead8b4
Merge branch 'jkbms_ble' of https://github.com/mr-manuel/venus-os_dbu…
mr-manuel Apr 15, 2023
59d91e7
fix black lint errors
mr-manuel Apr 15, 2023
194b83f
bump version
mr-manuel Apr 15, 2023
567f953
Improvements and preparation to merge with master
mr-manuel Apr 15, 2023
3219e70
fixed serial-starter.d
mr-manuel Apr 15, 2023
144d46b
fix errors, move install notes to show always
mr-manuel Apr 18, 2023
8ed26c7
fix errors
mr-manuel Apr 18, 2023
962d21d
Update install-nightly.sh
mr-manuel Apr 18, 2023
008082c
Update install-nightly.sh
mr-manuel Apr 18, 2023
5e029bf
make use of bluetooth configurable
mr-manuel Apr 19, 2023
94411e2
remove modules with uninstall script
mr-manuel Apr 19, 2023
a695052
fix typo
mr-manuel Apr 19, 2023
8f3d76e
Bluetooth enable over config file
mr-manuel Apr 19, 2023
1ad14e6
Added install notes
mr-manuel Apr 19, 2023
fe9cfdf
fix #351
mr-manuel Apr 20, 2023
bda2534
fix #351
mr-manuel Apr 20, 2023
0963923
fix System Switch in IO page
mr-manuel Apr 20, 2023
520eedc
fix #239
mr-manuel Apr 20, 2023
4ed644f
fix black lint errors
mr-manuel Apr 20, 2023
9646528
Merge branch 'Louisvdw:jkbms_ble' into jkbms_ble
mr-manuel Apr 20, 2023
13863f8
run code analyse only on code change
mr-manuel Apr 21, 2023
2bdfc56
Merge branch 'jkbms_ble' of https://github.com/mr-manuel/venus-os_dbu…
mr-manuel Apr 21, 2023
a4da321
fix #311
mr-manuel Apr 21, 2023
a32c738
Separate Time-To-Go and Time-To-SoC activation
mr-manuel Apr 23, 2023
017df8a
fix UnicodeDecodeError
mr-manuel Apr 25, 2023
d8a5d64
Some fixes
mr-manuel Apr 25, 2023
e0a55e9
fix UnicodeDecodeError
mr-manuel Apr 25, 2023
307e40c
Merge branch 'Louisvdw:jkbms_ble' into jkbms_ble
mr-manuel Apr 26, 2023
f11897b
fix UnicodeDecodeError
mr-manuel Apr 26, 2023
627383d
optimize uninstall script
mr-manuel Apr 26, 2023
65a5ef2
fix typo in log_settings
mr-manuel Apr 26, 2023
4890ad1
add charge mode display
mr-manuel Apr 26, 2023
c935363
Merge branch 'jkbms_ble' of https://github.com/mr-manuel/venus-os_dbu…
mr-manuel Apr 26, 2023
a28ae98
Merge branch 'Louisvdw:jkbms_ble' into jkbms_ble
mr-manuel Apr 26, 2023
9d993fc
Added: Temp name for sensor 1 & 2
mr-manuel Apr 26, 2023
8067045
Added: Choose how battery temperature is assembled
mr-manuel Apr 26, 2023
3777d50
Added/Changed alarms for JKBMS
mr-manuel Apr 26, 2023
89dfdbf
Removed Alarms/HighCellVoltage
mr-manuel Apr 26, 2023
8ffa730
Changed: Moved charge mode
mr-manuel Apr 26, 2023
1940d5d
Added: Show (dis)charge current limitation reason
mr-manuel Apr 26, 2023
acd9ea3
added changelog
mr-manuel Apr 26, 2023
b46c67f
Fixes and improvements
mr-manuel Apr 26, 2023
2e67a5e
corrected file permissions
mr-manuel Apr 26, 2023
3f81fa5
fix dbus-daemon memory leak
seidler2547 Apr 26, 2023
3caad73
fix typo
mr-manuel Apr 26, 2023
e0b4e99
fix dbus-daemon memory leak
mr-manuel Apr 26, 2023
3429fe2
Merge branch 'Louisvdw:jkbms_ble' into jkbms_ble
mr-manuel Apr 26, 2023
e28facf
Update readme
mr-manuel Apr 26, 2023
ed80385
Merge branch 'jkbms_ble' of https://github.com/mr-manuel/venus-os_dbu…
mr-manuel Apr 26, 2023
b011e0e
Remove bluetooth option from the config file
mr-manuel Apr 26, 2023
8d0db98
Small word case changes
mr-manuel Apr 26, 2023
2ffa358
Added: Show specific TimeToSoC points in GUI
mr-manuel Apr 26, 2023
5a16cbd
fix black lint error
mr-manuel Apr 26, 2023
964ec17
Some improvement and fixes
mr-manuel Apr 26, 2023
1e6d410
Improved JBD BMS soc calculation
mr-manuel Apr 27, 2023
922b82c
Fix for #397
mr-manuel Apr 27, 2023
23356f6
small fixes
mr-manuel Apr 27, 2023
4bd257f
sort bms imports
mr-manuel Apr 27, 2023
c56a9d1
Add support for HLPdata BMS4S
mr-manuel Apr 27, 2023
314bb93
Add support for Seplos BMS
mr-manuel Apr 27, 2023
aceeac9
change flake8 settings
mr-manuel Apr 27, 2023
64a08f4
fix black lint errors
mr-manuel Apr 27, 2023
31647db
removed wildcard imports
mr-manuel Apr 27, 2023
8d3f25e
fixed black lint errors
mr-manuel Apr 27, 2023
a4a3efb
change flake8 settings
mr-manuel Apr 27, 2023
4a26d0d
remove wildcard import and fix black lint errors
mr-manuel Apr 27, 2023
564d4ed
removed wildcard import
mr-manuel Apr 27, 2023
41cdadb
fixed black lint check
mr-manuel Apr 27, 2023
440b113
config changes
mr-manuel Apr 27, 2023
bc91973
remove old log message in handle_changed_setting()
mr-manuel Apr 27, 2023
83668b6
simplified condition for Time-To-Go/Soc
mr-manuel Apr 27, 2023
ed4d57b
Improvements and fixes
mr-manuel Apr 27, 2023
aee71f0
fix renogy import
mr-manuel Apr 27, 2023
362916c
Merge pull request #588 from mr-manuel/jkbms_ble
mr-manuel Apr 27, 2023
9e358fa
added BMS info and cleanup
mr-manuel Apr 28, 2023
09034a1
moved BMS to subfolder
mr-manuel Apr 28, 2023
a0918ee
moved BMS to subfolder
mr-manuel Apr 28, 2023
8f7d705
corrected installble to run correct script
mr-manuel Apr 28, 2023
3a62eed
Added self.unique_identifier to the battery class
mr-manuel Apr 28, 2023
d882937
changed ble service name
mr-manuel Apr 28, 2023
0aed855
Changes 2023.04.28
mr-manuel Apr 28, 2023
d3a72d6
read installed capacity at startup
transistorgit Apr 28, 2023
b113bff
Merge pull request #594 from transistorgit/daly_capacity
mr-manuel Apr 28, 2023
9cea902
disable ANT BMS by default
mr-manuel Apr 29, 2023
49694b6
fix cell voltage header parser
transistorgit Apr 29, 2023
3a583ed
rework daly receive routine
transistorgit Apr 29, 2023
554c01d
improve read cell voltages - only work on sufficient data, drop only …
transistorgit Apr 29, 2023
e8ad26d
allow read_soc to also retry serial transmission
transistorgit Apr 29, 2023
93a4e98
add daly cell balance state info. cells are red only if unbalanced now
transistorgit Apr 29, 2023
fdd0bd1
bump version
mr-manuel Apr 29, 2023
ec04969
typo
mr-manuel Apr 29, 2023
ae1e447
Fixes
mr-manuel Apr 29, 2023
878014b
Merge branch 'Louisvdw:jkbms_ble' into jkbms_ble
transistorgit Apr 29, 2023
d1238e0
moved read_serialport_data() to daly.py
transistorgit May 1, 2023
62422de
revert read_serialport_data() to the state before my changes
transistorgit May 1, 2023
a3915cb
fix connection log startup message.
transistorgit May 1, 2023
4d4d256
Revert utils.py changes, improved Daly driver
mr-manuel May 1, 2023
3153962
black reformatting
transistorgit May 1, 2023
ec4a334
flake config change
mr-manuel May 1, 2023
31a1e53
added linear voltage recalculation interval
mr-manuel May 1, 2023
295efd1
replaced penalty voltage calculation
mr-manuel May 1, 2023
f95dc05
fix black lint errors
mr-manuel May 1, 2023
52fdc4a
updated config.default.ini
mr-manuel May 1, 2023
d820050
Changes 2023.05.01
mr-manuel May 1, 2023
912cd74
update nightly install script
mr-manuel May 1, 2023
4de2ae5
update nightly install script
mr-manuel May 1, 2023
93caa23
Removed line
mr-manuel May 1, 2023
fce00b9
fixed error in HLPdataBMS4S
mr-manuel May 1, 2023
9e4b069
fixed wrong variable assignment
mr-manuel May 2, 2023
80e2c67
updated battery template
mr-manuel May 2, 2023
70658e9
Fix for #450
mr-manuel May 2, 2023
fbfdcc7
Read charge/discharge limit JKBMS
mr-manuel May 2, 2023
5c9d30a
updated battery template
mr-manuel May 2, 2023
6a9ee0a
Progress with config limits reason
mr-manuel May 2, 2023
ebfb5bc
updated CELL_VOLTAGE_DIFF_TO_RESET_VOLTAGE_LIMIT default value
mr-manuel May 2, 2023
1d82436
Changes 2023.05.02
mr-manuel May 2, 2023
f44157a
added SoC round for LLT/JBD
mr-manuel May 2, 2023
da3fa07
fixed log typo
mr-manuel May 2, 2023
cf46dab
reworked installation procedure
mr-manuel May 2, 2023
9907912
Merge branch 'Louisvdw:jkbms_ble' into jkbms_ble
mr-manuel May 2, 2023
94b1a21
Merge branch 'master' into jkbms_ble
mr-manuel May 2, 2023
93cb3f0
Merge branch 'jkbms_ble' of https://github.com/mr-manuel/venus-os_dbu…
mr-manuel May 2, 2023
557b9ac
Merge branch 'master' of into jkbms_ble
mr-manuel May 2, 2023
335a0e7
GitHub pages config change
mr-manuel May 2, 2023
9f1da97
cleanup
mr-manuel May 2, 2023
74b459a
Renamed scripts for better reading #532
mr-manuel May 3, 2023
dff74d7
update docusaurus dependencies
mr-manuel May 3, 2023
c615a61
change sh with bash
mr-manuel May 3, 2023
a1972c8
Merge branch 'master' into jkbms_ble
mr-manuel May 3, 2023
43368fe
limitation reason cleanup
mr-manuel May 3, 2023
ad2855d
changed default config settings
mr-manuel May 3, 2023
2c9d3dd
Merge branch 'jkbms_ble' into jkbms_ble
mr-manuel May 3, 2023
9fcf1a5
Changes 2023.05.03
mr-manuel May 3, 2023
66f982a
removed testing line
mr-manuel May 3, 2023
524321c
Cleanup duplicated files
mr-manuel May 3, 2023
ff1b143
Cleanup
mr-manuel May 3, 2023
12ec57e
MOSFET temperature was displayed twice after merge
mr-manuel May 3, 2023
84556e8
updated changelog
mr-manuel May 3, 2023
56fecf3
Small fixes
mr-manuel May 3, 2023
bbb7b1b
fix disconnection behaviour: on disconnect, show '---' after 10s and …
transistorgit May 3, 2023
1514206
fix merge conflicts
transistorgit May 3, 2023
d647b1e
fix flake errors
transistorgit May 3, 2023
f496103
Merge pull request #4 from transistorgit/jkbms_ble
mr-manuel May 4, 2023
8ed42ae
small fix
mr-manuel May 4, 2023
77fc212
Added: apply max voltage if CVCM_ENABLE is False
mr-manuel May 4, 2023
9acfb15
fixed type error
mr-manuel May 4, 2023
7e1ada1
Added: BMS disconnect behaviour
mr-manuel May 4, 2023
2b32e11
Changed: Remove wildcard import from dbushelper.py
mr-manuel May 4, 2023
cd8c22a
small fixes
mr-manuel May 4, 2023
8a37bf2
Changes 2023.05.04
mr-manuel May 4, 2023
b423d20
Fix test routine
May 5, 2023
bd54368
Merge branch 'jkbms_ble' into jdb_ble
May 5, 2023
0301a62
Update imports
May 5, 2023
143c06e
Revert changes
May 5, 2023
3831890
Merge pull request #646 from Louisvdw/master
mr-manuel May 16, 2023
2f6ea71
Changes 2023.05.18 (#649)
mr-manuel May 18, 2023
5d0ed22
Merge remote-tracking branch 'upstream/dev' into jdb_ble
May 19, 2023
5242573
Remove unused
May 19, 2023
da6ef9e
Add reading current limits
May 19, 2023
ac674fc
clean-up
May 19, 2023
0902d59
Prototype primitive SoC calibration
May 19, 2023
2b2bdfd
Sync Temp 3 / 4 with config.default.ini
May 19, 2023
df12cbb
black lint
May 19, 2023
6e33458
Jbd uses digit like mac address 70:3E:97:D2:F4:D0
May 19, 2023
6da9e3d
Jbd uses digit like mac address 70:3E:97:D2:F4:D0
May 19, 2023
ef5380b
Fix reading settings
May 19, 2023
3c21953
Limit control voltage to max cell voltage
ogurevich May 20, 2023
c0056c6
Limit dynamic CVL to max charge voltage
mr-manuel May 20, 2023
f7d61c7
Fix issue with bluetooth restarts (e.g. cronjob)
May 21, 2023
3811281
Rework serial parser (#12)
transistorgit May 21, 2023
361146e
Merge branch 'Louisvdw:dev' into dev
mr-manuel May 21, 2023
a69118e
updated changelog
mr-manuel May 21, 2023
96d7c38
fix black lint error
mr-manuel May 21, 2023
f7d7621
fixed black lint error
mr-manuel May 21, 2023
e17ebab
added infos to battery template
mr-manuel May 22, 2023
9b669e4
Fix issue with bluetooth restarts (e.g. cronjob)
May 22, 2023
ef376e3
WIP Add func controls for balancer, chg/dsg MOS FET
May 22, 2023
37a589d
black formatting
May 22, 2023
bb93ee3
JDB BLE support (#499)
idstein May 23, 2023
cffd869
Merge branch 'Louisvdw:dev' into dev
mr-manuel May 23, 2023
a0a5ebf
updated changelog
mr-manuel May 23, 2023
5aa6163
Optimized Daly driver
mr-manuel May 23, 2023
f19e004
Add Supoprt for HeltecSmartBMS (YYBMS) using modbus via RS485 connect…
ramack May 24, 2023
fc95f6b
Changes 2023.05.24 (#667)
mr-manuel May 24, 2023
886005d
fix Jkbms_Ble error
mr-manuel May 25, 2023
81ddf57
updated changelog
mr-manuel May 25, 2023
8151719
Merge pull request #668 from mr-manuel/dev
mr-manuel May 25, 2023
25494dd
Merge branch 'dev' into jdb_func_config
May 26, 2023
02bb883
Merge branch 'dev' into jdb_func_config
Jul 27, 2023
d1fe9f9
feature: Allow to control charge / discharge FET
Jul 27, 2023
aafc5b6
Merge branch 'dev' into jdb_func_config
mr-manuel Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 144 additions & 3 deletions etc/dbus-serialbattery/bms/lltjbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from battery import Protection, Battery, Cell
from utils import is_bit_set, read_serial_data, logger
import utils
from struct import unpack_from
from struct import unpack_from, pack
import struct

# Protocol registers
Expand Down Expand Up @@ -68,8 +68,10 @@
REG_CELL_V_DELAYS = 0x3D
REG_CHGOC_DELAYS = 0x3E
REG_DSGOC_DELAYS = 0x3F
REG_GPSOFF = 0x40
REG_GPSOFF_TIME = 0x41
# Cut-off voltage turns off GPS protection board
REG_GPS_OFF = 0x40
# Cut-off voltage delay for GPS protection board
REG_GPS_OFF_TIME = 0x41
REG_CAP_90 = 0x42
REG_CAP_70 = 0x43
REG_CAP_50 = 0x44
Expand Down Expand Up @@ -141,6 +143,27 @@
CMD_EXIT_FACTORY_MODE = b"\x00\x00"
CMD_EXIT_AND_SAVE_FACTORY_MODE = b"\x28\x28"

# Weak current switch function
FUNC_SW_EN = 0x0001 # bit 0
# Load lock function used to disconnect the load when short circuit is required to recover
FUNC_LOAD_EN = 0x0002 # bit 1
# Enable balancer function
FUNC_BALANCE_EN = 0x0004 # bit 2
# Charge balance, only turn on balance when charging
FUNC_BALANCE_CHARGING_ONLY = 0x0008 # bit 3
# LED power indicator function
FUNC_LED = 0x0010 # bit 4
# Compatible with LED modes
FUNC_LED_NUM = 0x0020 # bit 5
# With history recording
FUNC_RTC = 0x0040 # bit 6
# whether it is necessary to set the range when it is currently used for FCC update
FUNC_EDV = 0x0080 # bit 7
# Additional GPS protection board is connected
FUNC_GPS_EN = 0x0100 # bit 8
# Enable onboard buzzer / GPS protection board buzzer?
FUNC_BUZZER_EN = 0x0200 # bit 9


def checksum(payload):
return (0x10000 - sum(payload)) % 0x10000
Expand Down Expand Up @@ -217,6 +240,9 @@ def __init__(self, port, baud, address):
self.soc_to_set = None
self.factory_mode = False
self.writable = False
self.trigger_force_disable_discharge = None
self.trigger_force_disable_charge = None
self.trigger_disable_balancer = None
self.cycle_capacity = None

# degree_sign = u'\N{DEGREE SIGN}'
Expand Down Expand Up @@ -267,6 +293,9 @@ def get_settings(self):
self.max_battery_discharge_current = float(
unpack_from(">h", discharge_over_current)[0] / -100.0
)
func_config = self.read_serial_data_llt(readCmd(REG_FUNC_CONFIG))
if func_config:
self.func_config = func_config

return True

Expand All @@ -292,7 +321,119 @@ def write_soc(self):
pack_voltage = struct.pack(">H", int(self.voltage * 10))
self.read_serial_data_llt(writeCmd(REG_CAP_100, pack_voltage))

def force_charging_off_callback(self, path, value):
if value is None:
return False

if value == 0:
self.trigger_force_disable_charge = False
return True

if value == 1:
self.trigger_force_disable_charge = True
return True

return False

def force_discharging_off_callback(self, path, value):
if value is None:
return False

if value == 0:
self.trigger_force_disable_discharge = False
return True

if value == 1:
self.trigger_force_disable_discharge = True
return True

return False

def write_charge_discharge_mos(self):
if (
self.trigger_force_disable_charge is None
and self.trigger_force_disable_discharge is None
):
return False

charge_disabled = 0 if self.charge_fet else 1
if self.trigger_force_disable_charge is not None and self.control_allow_charge:
charge_disabled = 1 if self.trigger_force_disable_charge else 0
logger.info(
f"write force disable charging: {'true' if self.trigger_force_disable_charge else 'false'}"
)
self.trigger_force_disable_charge = None

discharge_disabled = 0 if self.discharge_fet else 1
if (
self.trigger_force_disable_discharge is not None
and self.control_allow_discharge
):
discharge_disabled = 1 if self.trigger_force_disable_discharge else 0
logger.info(
f"write force disable discharging: {'true' if self.trigger_force_disable_discharge else 'false'}"
)
self.trigger_force_disable_discharge = None

mosdata = pack(">BB", 0, charge_disabled | (discharge_disabled << 1))

reply = self.read_serial_data_llt(writeCmd(REG_CTRL_MOSFET, mosdata))

if reply is False:
logger.error("write force disable charge/discharge failed")
return False

def turn_balancing_off_callback(self, path, value):
if value is None:
return False

if value == 0:
self.trigger_disable_balancer = False
return True

if value == 1:
self.trigger_disable_balancer = True
return True

return False

def write_balancer(self):
if self.trigger_disable_balancer is None:
return False

disable_balancer = self.trigger_disable_balancer
logger.info(
f"write disable balancer: {'true' if self.trigger_disable_balancer else 'false'}"
)
self.trigger_disable_balancer = None
new_func_config = None

with self.eeprom():
func_config = self.read_serial_data_llt(readCmd(REG_FUNC_CONFIG))
if func_config:
self.func_config = unpack_from(">H", func_config)[0]
balancer_enabled = self.func_config & FUNC_BALANCE_EN
# Balance is enabled, force disable OR balancer is disabled and force enable
if (balancer_enabled != 0 and disable_balancer) or (
balancer_enabled == 0 and not disable_balancer
):
new_func_config = self.func_config ^ FUNC_BALANCE_EN

if new_func_config:
new_func_config_bytes = pack(">H", new_func_config)
with self.eeprom(writable=True):
reply = self.read_serial_data_llt(
writeCmd(REG_FUNC_CONFIG, new_func_config_bytes)
)
if reply is False:
logger.error("write force disable balancer failed")
return False

return True

def refresh_data(self):
self.write_charge_discharge_mos()
self.write_balancer()
result = self.read_gen_data()
result = result and self.read_cell_data()
return result
Expand Down
11 changes: 11 additions & 0 deletions etc/dbus-serialbattery/bms/lltjbd_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,16 @@ def read_serial_data_llt(self, command):
if not bat.test_connection():
logger.error(">>> ERROR: Unable to connect")
else:
# Allow to change charge / discharge FET
bat.control_allow_charge = True
bat.control_allow_discharge = True

bat.trigger_disable_balancer = True
bat.trigger_force_disable_charge = True
bat.trigger_force_disable_discharge = True
bat.refresh_data()
bat.trigger_disable_balancer = False
bat.trigger_force_disable_charge = False
bat.trigger_force_disable_discharge = False
bat.refresh_data()
bat.get_settings()