From a2503a47cc22465a6c987f50814f3f1dd4d8249b Mon Sep 17 00:00:00 2001 From: Tobi177 Date: Mon, 27 Jul 2020 14:21:15 +0200 Subject: [PATCH] debug packets with logger --- driver/chargerybms.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/driver/chargerybms.py b/driver/chargerybms.py index 2ad4fc3..34339cc 100644 --- a/driver/chargerybms.py +++ b/driver/chargerybms.py @@ -21,6 +21,7 @@ logging.basicConfig( format='%(asctime)s %(levelname)-8s %(message)s', level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S') + # filename='log.txt') # connect and register to dbus @@ -553,7 +554,7 @@ BMS_TEST_PACKETS = { 2 : bytearray.fromhex('2424570F0E240100E4008100845B25'), 3 : bytearray.fromhex('2424570F0E240100E1008300845B24'), 4 : bytearray.fromhex('2424562D0CFD0D040D040D020D030D040D060D010D080D020D050CFE0D060CFB0D0F0CFC76FED50263140E0095'), - 5 : bytearray.fromhex('2424582801E4000100030003000300020003000000000001000100010000000500020003000300CC'), + 5 : bytearray.fromhex('2424582801E4000100030003000300020003000000000001000100010000000500020003000300CC'), 6 : bytearray.fromhex('2424570F0E240100E4008300845B27') } @@ -565,12 +566,12 @@ SPECIAL_DISPLAY_SYMBOLS = { } def debug_packet(packet): - print - for packet_byte in packet: - print ord(packet_byte),"[",packet_byte.encode("hex"),"]", - print - print + string_output = "" + for packet_byte in packet: + byte_string = str(ord(packet_byte)) + " [" + packet_byte.encode("hex") + "] " + string_output = string_output + byte_string + logging.debug(string_output); def get_header_position(packet): @@ -614,6 +615,7 @@ def get_cell_impedance(byte1, byte2): def parse_packet(packet): logging.debug("Parse Packet [" + str(len(packet)) + "] bytes") + debug_packet(packet) while (len(packet) >= PACKET_LENGTH_MINIMUM): header_position = get_header_position(packet) @@ -630,7 +632,7 @@ def parse_packet(packet): if ((ord(packet[0]) == PACKET_HEADER) and (ord(packet[1]) == PACKET_HEADER)): packet_length = ord(packet[3]) logging.debug("Packet Length [" + str (packet_length) + " bytes]") - # debug_packet(packet) + debug_packet(packet) if (ord(packet[2]) == PACKET_STATUS_BMS):