Skip to content

Commit

Permalink
fix for Louisvdw#716
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Nov 2, 2023
1 parent 631dfc9 commit 7c38c44
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* Changed: Improved driver disable script by @md-manuel
* Changed: Improved driver reinstall when multiple Bluetooth BMS are enabled by @mr-manuel
* Changed: JKBMS - Driver do not start if manufacturer date in BMS is empty https://github.com/Louisvdw/dbus-serialbattery/issues/823 by @mr-manuel
* Changed: JKBMS_BLE BMS - Fixed MOSFET Temperature for HW 11 by @jensbehrens & @mr-manuel
* Changed: JKBMS_BLE BMS - Improved driver by @seidler2547 & @mr-manuel
* Changed: LLT/JBD BMS - Fix cycle capacity with https://github.com/Louisvdw/dbus-serialbattery/pull/762 by @idstein
* Changed: LLT/JBD BMS - Fixed https://github.com/Louisvdw/dbus-serialbattery/issues/730 by @mr-manuel
Expand Down
53 changes: 48 additions & 5 deletions etc/dbus-serialbattery/bms/jkbms_brn.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
]


TRANSLATE_CELL_INFO = [
TRANSLATE_CELL_INFO_16S = [
[["cell_info", "voltages", 32], 6, "<H", 0.001],
[["cell_info", "average_cell_voltage"], 58, "<H", 0.001],
[["cell_info", "delta_cell_voltage"], 60, "<H", 0.001],
Expand All @@ -82,6 +82,31 @@
]


TRANSLATE_CELL_INFO_32S = [
[["cell_info", "voltages", 32], 6, "<H", 0.001],
[["cell_info", "average_cell_voltage"], 58, "<H", 0.001],
[["cell_info", "delta_cell_voltage"], 60, "<H", 0.001],
[["cell_info", "max_voltage_cell"], 62, "<B"],
[["cell_info", "min_voltage_cell"], 63, "<B"],
[["cell_info", "resistances", 32], 64, "<H", 0.001],
[["cell_info", "total_voltage"], 118, "<H", 0.001],
[["cell_info", "current"], 126, "<l", 0.001],
[["cell_info", "temperature_sensor_1"], 130, "<H", 0.1],
[["cell_info", "temperature_sensor_2"], 132, "<H", 0.1],
[["cell_info", "temperature_mos"], 112, "<H", 0.1],
[["cell_info", "balancing_current"], 138, "<H", 0.001],
[["cell_info", "balancing_action"], 140, "<B", 0.001],
[["cell_info", "battery_soc"], 141, "B"],
[["cell_info", "capacity_remain"], 142, "<L", 0.001],
[["cell_info", "capacity_nominal"], 146, "<L", 0.001],
[["cell_info", "cycle_count"], 150, "<L"],
[["cell_info", "cycle_capacity"], 154, "<L", 0.001],
[["cell_info", "charging_switch_enabled"], 166, "1?"],
[["cell_info", "discharging_switch_enabled"], 167, "1?"],
[["cell_info", "balancing_active"], 191, "1?"],
]


class Jkbms_Brn:
# entries for translating the bytearray to py-object via unpack
# [[py dict entry as list, each entry ] ]
Expand All @@ -101,6 +126,12 @@ class Jkbms_Brn:
ovp_initial_voltage = None
ovpr_initial_voltage = None

# will be set by get_bms_max_cell_count()
bms_max_cell_count = None

# translate info placeholder, since it depends on the bms_max_cell_count
translate_cell_info = []

def __init__(self, addr):
self.address = addr
self.bt_thread = threading.Thread(target=self.connect_and_scrape)
Expand All @@ -111,6 +142,17 @@ async def scanForDevices(self):
for d in devices:
logging.debug(d)

# check if the bms is a 16s or 32s type
def get_bms_max_cell_count(self):
fb = self.frame_buffer
has32s = fb[189] == 0x00 and fb[189 + 32] > 0
if has32s:
self.bms_max_cell_count = 32
self.translate_cell_info = TRANSLATE_CELL_INFO_32S
else:
self.bms_max_cell_count = 16
self.translate_cell_info = TRANSLATE_CELL_INFO_16S

# iterative implementation maybe later due to referencing
def translate(self, fb, translation, o, f32s=False, i=0):
if i == len(translation[0]) - 1:
Expand Down Expand Up @@ -196,8 +238,8 @@ def decode_device_info_jk02(self):

def decode_cellinfo_jk02(self):
fb = self.frame_buffer
has32s = fb[189] == 0x00 and fb[189 + 32] > 0
for t in TRANSLATE_CELL_INFO:
has32s = self.bms_max_cell_count == 32
for t in self.translate_cell_info:
self.translate(fb, t, self.bms_status, f32s=has32s)
self.decode_warnings(fb)
logging.debug("decode_cellinfo_jk02(): self.frame_buffer")
Expand All @@ -213,15 +255,16 @@ def decode_settings_jk02(self):
def decode(self):
# check what kind of info the frame contains
info_type = self.frame_buffer[4]
self.get_bms_max_cell_count()
if info_type == 0x01:
logging.info("Processing frame with settings info")
if protocol_version == PROTOCOL_VERSION_JK02:
self.decode_settings_jk02()
# adapt translation table for cell array lengths
ccount = self.bms_status["settings"]["cell_count"]
for i, t in enumerate(TRANSLATE_CELL_INFO):
for i, t in enumerate(self.translate_cell_info):
if t[0][-2] == "voltages" or t[0][-2] == "voltages":
TRANSLATE_CELL_INFO[i][0][-1] = ccount
self.translate_cell_info[i][0][-1] = ccount
self.bms_status["last_update"] = time()

elif info_type == 0x02:
Expand Down
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _get_list_from_config(


# Constants
DRIVER_VERSION = "1.0.20231010dev2"
DRIVER_VERSION = "1.0.20231102dev"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down

0 comments on commit 7c38c44

Please sign in to comment.