Skip to content

Commit

Permalink
Merge pull request #798 from idstein/bugfix/llt-jdb-general-data-temp…
Browse files Browse the repository at this point in the history
…-sensor-count

bugfix: LLT/JBD BMS general packet data size check
  • Loading branch information
mr-manuel authored Sep 5, 2023
2 parents 251dcc3 + 1a22ea3 commit b07cf18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions etc/dbus-serialbattery/bms/lltjbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,14 @@ def test_connection(self):
# Return True if success, False for failure
result = False
try:
result = self.get_settings()
# get first data to show in startup log, only if result is true
if result:
# 1) Read name of BMS
# 2) Try read BMS settings
# 3) Refresh general data
result = (
self.read_hardware_data()
self.refresh_data()
and self.get_settings()
and self.refresh_data()
)
except Exception as err:
logger.error(f"Unexpected {err=}, {type(err)=}")
result = False
Expand Down Expand Up @@ -438,9 +441,7 @@ def write_balancer(self):
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
return self.read_gen_data() and self.read_cell_data()

def to_protection_bits(self, byte_data):
tmp = bin(byte_data)[2:].rjust(13, utils.zero_char)
Expand Down Expand Up @@ -530,7 +531,7 @@ def to_fet_bits(self, byte_data):
def read_gen_data(self):
gen_data = self.read_serial_data_llt(self.command_general)
# check if connect success
if gen_data is False or len(gen_data) < 27:
if gen_data is False or len(gen_data) < 23:
return False

(
Expand Down Expand Up @@ -567,6 +568,13 @@ def read_gen_data(self):

# 0 = MOS, 1 = temp 1, 2 = temp 2
for t in range(self.temp_sensors):
if len(gen_data) < 23 + (2 * t) + 2:
logger.warn(
"Expected %d temperature sensors, but received only %d sensor readings!",
self.temp_sensors,
t,
)
return True
temp1 = unpack_from(">H", gen_data, 23 + (2 * t))[0]
self.to_temp(t, utils.kelvin_to_celsius(temp1 / 10))

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyserial==3.5
minimalmodbus==2.0.1
bleak==0.20.0
bleak==0.20.2

0 comments on commit b07cf18

Please sign in to comment.