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

bugfix: LLT/JBD BMS general packet data size check #798

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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