Skip to content

Commit

Permalink
remove AT cmds from end of message
Browse files Browse the repository at this point in the history
  • Loading branch information
patman15 committed Dec 23, 2024
1 parent ce977bb commit 7745113
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions custom_components/bms_ble/plugins/jikong_bms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _notification_handler(self, _sender, data: bytearray) -> None:

if (
len(self._data) >= self.INFO_LEN
and (data.startswith((BMS.HEAD_RSP, self.HEAD_CMD)))
and (data.startswith((BMS.HEAD_RSP, BMS.HEAD_CMD)))
) or not self._data.startswith(BMS.HEAD_RSP):
self._data = bytearray()

Expand All @@ -133,12 +133,16 @@ def _notification_handler(self, _sender, data: bytearray) -> None:
)
return

# trim AT\r\n message from the end
if self._data.endswith(BMS.BT_MODULE_MSG):
self._data = self._data[: -len(BMS.BT_MODULE_MSG)]

# trim message in case oversized
if len(self._data) > BMS.INFO_LEN:
self._log.debug("wrong data length (%i): %s", len(self._data), self._data)
self._data = self._data[: BMS.INFO_LEN]

crc = crc_sum(self._data[:-1])
crc: int = crc_sum(self._data[:-1])
if self._data[-1] != crc:
self._log.debug("invalid checksum 0x%X != 0x%X", self._data[-1], crc)
return
Expand Down
6 changes: 4 additions & 2 deletions tests/test_jikong_bms.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x93"
),
"ack": bytearray(
b"\xaa\x55\x90\xeb\xc8\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44"
#b"\xaa\x55\x90\xeb\xc8\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44"
b"\xaa\x55\x90\xeb\xc8\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x41\x54\x0d\x0a"
),
"cell": bytearray( # JK02_24S (SW: 10.08)
b"\x55\xaa\xeb\x90\x02\xc8\xee\x0c\xf2\x0c\xf1\x0c\xf0\x0c\xf0\x0c\xec\x0c\xf0\x0c\xed\x0c"
Expand Down Expand Up @@ -76,7 +77,8 @@
b"\x00\xfe\xbf\x21\x06\x00\x00\x00\x00\x00\x00\x00\x00\xd8"
), # Vendor_ID: JK_B2A8S20P, SN: 404092C2262, HW: V11.XA, SW: V11.48, power-on: 7, Version: 4.28.0
"ack": bytearray(
b"\xaa\x55\x90\xeb\xc8\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44"
#b"\xaa\x55\x90\xeb\xc8\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44"
b"\xaa\x55\x90\xeb\xc8\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x41\x54\x0d\x0a"
),
"cell": bytearray(
b"\x55\xaa\xeb\x90\x02\xc6\xc1\x0c\xc1\x0c\xc1\x0c\xc1\x0c\xc1\x0c\xc1\x0c\xc1\x0c\xc1\x0c"
Expand Down

0 comments on commit 7745113

Please sign in to comment.