From 10d724763b6524eea285267eebf5816d0c2a394b Mon Sep 17 00:00:00 2001 From: Martin Polehla Date: Tue, 30 Jul 2024 03:30:28 +0200 Subject: [PATCH] Update jkbms_can.py Removed single cell info emulation code. The cell info is not accurate since the BMS provices only min and max cell voltage and "middle voltage" cells remain outdated until they become min or max. But in such case, the previous min/max cell becomes outdated itself. Such emulation would just confuse users. The single cell value emulation also caused issues with other project feature which excepts that cell values are available. Apart of that, tweaked temperature sensor nr. and arbitary_id list. --- etc/dbus-serialbattery/bms/jkbms_can.py | 33 +++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/etc/dbus-serialbattery/bms/jkbms_can.py b/etc/dbus-serialbattery/bms/jkbms_can.py index e5407dc4..6529bf21 100644 --- a/etc/dbus-serialbattery/bms/jkbms_can.py +++ b/etc/dbus-serialbattery/bms/jkbms_can.py @@ -54,10 +54,10 @@ def __del__(self): # B2A... Silver is using 0x0XF5 # See https://github.com/Louisvdw/dbus-serialbattery/issues/950 CAN_FRAMES = { - BATT_STAT: [0x02F4, 0x02F5], - CELL_VOLT: [0x04F4, 0x04F5], - CELL_TEMP: [0x05F4, 0x05F5], - ALM_INFO: [0x07F4, 0x07F5], + BATT_STAT: [0x02F4, 0x02F5, 0x02F9], + CELL_VOLT: [0x04F4, 0x04F5, 0x04F9], + CELL_TEMP: [0x05F4, 0x05F5, 0x05F9], + ALM_INFO: [0x07F4, 0x07F5, 0x07F9], } def test_connection(self): @@ -76,12 +76,6 @@ def get_settings(self): self.max_battery_voltage = MAX_CELL_VOLTAGE * self.cell_count self.min_battery_voltage = MIN_CELL_VOLTAGE * self.cell_count - # init the cell array add only missing Cell instances - missing_instances = self.cell_count - len(self.cells) - if missing_instances > 0: - for c in range(missing_instances): - self.cells.append(Cell(False)) - self.hardware_version = "JKBMS CAN " + str(self.cell_count) + " cells" return True @@ -242,22 +236,17 @@ def read_serial_data_jkbms_CAN(self): if max_cell_cnt > self.cell_count: self.cell_count = max_cell_cnt self.get_settings() - - for c_nr in range(len(self.cells)): - self.cells[c_nr].balance = False - - if self.cell_count == len(self.cells): - self.cells[max_cell_nr - 1].voltage = max_cell_volt - self.cells[max_cell_nr - 1].balance = True - - self.cells[min_cell_nr - 1].voltage = min_cell_volt - self.cells[min_cell_nr - 1].balance = True + + self.min_cell_voltage = min_cell_volt + self.max_cell_voltage = max_cell_volt elif msg.arbitration_id in self.CAN_FRAMES[self.CELL_TEMP]: max_temp = unpack_from("