Fix logging, fix cell module readout

This commit is contained in:
Carsten Schmiemann 2023-05-20 18:32:08 +02:00
parent 1c7eef7089
commit fc01f2a569
1 changed files with 9 additions and 13 deletions

View File

@ -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()