Skip to content

Commit

Permalink
Seplos BMS - Fix #81 regression
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Oct 5, 2024
1 parent 9865652 commit 10236a3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions etc/dbus-serialbattery/bms/seplos.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,34 @@ def get_info_length(info: bytes) -> int:
return (lchksum << 12) + lenid

@staticmethod
def encode_cmd(address: int, cid2: int, info: bytes = b"") -> bytes:
def encode_cmd(address: bytes, cid2: int, info: bytes = b"") -> bytes:
"""encodes a command sent to a battery (cid1=0x46)"""
try:
cid1 = 0x46

info_length = Seplos.get_info_length(info)

address_int = int.from_bytes(address, byteorder="big")

frame = "{:02X}{:02X}{:02X}{:02X}{:04X}".format(
0x20, address, cid1, cid2, info_length
0x20, address_int, cid1, cid2, info_length
).encode()
frame += info

checksum = Seplos.get_checksum(frame)
encoded = b"~" + frame + "{:04X}".format(checksum).encode() + b"\r"
return encoded
except Exception:
(
exception_type,
exception_object,
exception_traceback,
) = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
return b""

def test_connection(self):
Expand Down

0 comments on commit 10236a3

Please sign in to comment.