From fc01f2a56988291bfcd606347449e542798ba3b5 Mon Sep 17 00:00:00 2001 From: Carsten Schmiemann Date: Sat, 20 May 2023 18:32:08 +0200 Subject: [PATCH] Fix logging, fix cell module readout --- dbus_batrium_native/batrium.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/dbus_batrium_native/batrium.py b/dbus_batrium_native/batrium.py index 06bf75f..e40d254 100644 --- a/dbus_batrium_native/batrium.py +++ b/dbus_batrium_native/batrium.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import sys +import os import logging import itertools @@ -71,7 +73,6 @@ class BatriumBattery(can.Listener): def on_message_received(self, msg): self.updated = msg.timestamp - logging.debug("CAN message arrived") if msg.arbitration_id == 0x00111500: self.soc = (msg.data[0] * 0.5) - 5 self.voltage = ((msg.data[3] * 256) + msg.data[2]) * 0.01 @@ -109,7 +110,7 @@ class BatriumBattery(can.Listener): elif ((msg.arbitration_id >= 0x001D1101) and (msg.arbitration_id <= 0x001D11F9)): cell_id = msg.arbitration_id & 0xff - logging.debug("Cell ID: %d", cell_id) + logging.debug("Cell ID: %d, Voltage_min: %2.2f, Voltage_max: %2.2f, Temperature: %d, Bypass_Temperature: %d, BypassPWM: %d", cell_id, ((msg.data[1] * 256) + msg.data[0]) * 0.001, ((msg.data[3] * 256) + msg.data[2]) * 0.001, msg.data[4] - 40, msg.data[5] - 40, msg.data[6]) #self.cellVoltages_min[cell_id] = ((msg.data[1] * 256) + msg.data[0]) * 0.001 #self.cellVoltages_max[cell_id] = ((msg.data[3] * 256) + msg.data[2]) * 0.001 #self.cellTemperatures[cell_id] = msg.data[4] - 40 @@ -123,7 +124,12 @@ class BatriumBattery(can.Listener): # === All code below is to simply run it from the commandline for debugging purposes === def main(): - + logging.basicConfig( format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + level=logging.DEBUG, + stream=sys.stdout, + ) + logging.info('Starting dbus_batrium_native listener') #logger = can.Logger('logfile.asc') @@ -144,15 +150,5 @@ def main(): notifier.stop() bat._ci.shutdown() - - logging.basicConfig( format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', - datefmt='%Y-%m-%d %H:%M:%S', - level=(logging.DEBUG), - handlers=[ - logging.FileHandler("%s/current.log" % (os.path.dirname(os.path.realpath(__file__)))), - logging.StreamHandler() - ]) - - if __name__ == "__main__": main()