Skip to content

Commit

Permalink
Update jkbms_can.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
p0l0us authored Jul 30, 2024
1 parent fd0fc1a commit 10d7247
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions etc/dbus-serialbattery/bms/jkbms_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down Expand Up @@ -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("<B", bytes([msg.data[0]]))[0] - 50
max_nr = unpack_from("<B", bytes([msg.data[1]]))[0]
min_temp = unpack_from("<B", bytes([msg.data[2]]))[0] - 50
self.to_temp(1, max_temp if max_temp <= 100 else 100)
self.to_temp(2, min_temp if min_temp <= 100 else 100)
min_nr = unpack_from("<B", bytes([msg.data[3]]))[0]
self.to_temp(max_nr, max_temp if max_temp <= 100 else 100)
self.to_temp(min_nr, min_temp if min_temp <= 100 else 100)
# print(max_temp)
# print(min_temp)
elif msg.arbitration_id in self.CAN_FRAMES[self.ALM_INFO]:
Expand Down

0 comments on commit 10d7247

Please sign in to comment.