From b4ca37a5140bba6fa4efe4e997802ad7e67ca061 Mon Sep 17 00:00:00 2001 From: Carsten Schmiemann Date: Mon, 12 Jun 2023 21:56:26 +0200 Subject: [PATCH] Clean up and comment out not used stuff for later usage --- dbus-batrium-native/batrium.py | 51 +++++++++++++--------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/dbus-batrium-native/batrium.py b/dbus-batrium-native/batrium.py index 8295a7c..f3fb359 100644 --- a/dbus-batrium-native/batrium.py +++ b/dbus-batrium-native/batrium.py @@ -15,10 +15,10 @@ VERSION = '1.0' class BatriumBattery(can.Listener): def __init__(self, connection): + ##Capacity of battery need to set here, because Batrium not transmitting self.capacity = 300 self.maxChargeVoltage = 0 self.numberOfModules = 0 - self.chargeComplete = 0 self.soc = 0 self.voltage = 0 self.current = 0 @@ -28,10 +28,10 @@ class BatriumBattery(can.Listener): self.minCellTemperature = 0 self.minCellTemperatureId = 0 self.cellVoltages_min = dict() - self.cellVoltages_max = dict() - self.cellTemperatures = dict() - self.cellBypassTemperatures = dict() - self.cellBypassPWM = dict() + #self.cellVoltages_max = dict() + #self.cellTemperatures = dict() + #self.cellBypassTemperatures = dict() + #self.cellBypassPWM = dict() self.maxCellVoltage = 0 self.maxCellVoltageId = 0 self.minCellVoltage = 0 @@ -39,17 +39,15 @@ class BatriumBattery(can.Listener): self.maxChargeCurrent = 0 self.maxDischargeCurrent = 0 self.updated = -1 - self.cyclicModeTask = None self.TimeToEmpty = 0 self.TimeToFull = 0 - self.AhToEmpty = 0 - self.AhToFull = 0 + #self.AhToEmpty = 0 + #self.AhToFull = 0 self.NumberInBypass = 0 self.alarm_high_temperature = 0 self.alarm_high_voltage = 0 self.alarm_low_temperature = 0 self.alarm_low_voltage = 0 - self.alarm_low_soc = 0 self.alarm_high_charge_current = 0 self.alarm_high_discharge_current = 0 @@ -83,10 +81,10 @@ class BatriumBattery(can.Listener): self.current = round((struct.unpack('>f', bytearray([msg.data[7], msg.data[6], msg.data[5], msg.data[4]])))[0] * 0.001, 2) self.temperature = msg.data[1] - 40 - elif msg.arbitration_id == 0x00111900: - logging.debug("Ah 0x00111900 received") + #elif msg.arbitration_id == 0x00111900: + #logging.debug("Ah 0x00111900 received") - # message never arrived, batrium fw bug? + # message never arrived, batrium fw bug? contacted Batrium I hope they fix it too #self.AhToFull = round((struct.unpack('>f', bytearray([msg.data[3], msg.data[2], msg.data[1], msg.data[0]])))[0] * 0.001, 2) #self.AhToEmpty = round((struct.unpack('>f', bytearray([msg.data[7], msg.data[6], msg.data[5], msg.data[4]])))[0] * 0.001, 2) @@ -150,21 +148,15 @@ 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, 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]) + 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 - self.cellBypassTemperatures[cell_id] = msg.data[5] - 40 - self.cellBypassPWM[cell_id] = msg.data[6] + #self.cellVoltages_max[cell_id] = ((msg.data[3] * 256) + msg.data[2]) * 0.001 + #self.cellTemperatures[cell_id] = msg.data[4] - 40 + #self.cellBypassTemperatures[cell_id] = msg.data[5] - 40 + #self.cellBypassPWM[cell_id] = msg.data[6] self.numberOfModules = len(self.cellVoltages_min.keys()) - def prnt(self): - print("SOC: %2d, I: %2.2fA, U: %2.2fV, T:%2.1fC" % (self.soc, self.current, self.voltage, self.maxCellTemperature)) - print("MinCellVolt: %1.2f, MaxCellVolt: %1.2f CellVoltDelta: %1.2f" % (self.minCellVoltage, self.maxCellVoltage, self.maxCellVoltage-self.minCellVoltage)) - print("MaxChargeCurrent (CCL): %4.1f A MaxChargeVoltage (CVL): %2.2f V" % (self.maxChargeCurrent, self.maxChargeVoltage)) - print("Number of modules found: %1.0f" % (self.numberOfModules)) - -# === All code below is to simply run it from the commandline for debugging purposes === +## 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', @@ -172,23 +164,20 @@ def main(): stream=sys.stdout, ) - logging.info('Starting dbus_batrium_native listener') + logging.info('Starting dbus-batrium-native listener') - #logger = can.Logger('logfile.asc') + #logger = can.Logger('logfile.asc') # CAN raw data logging bat = BatriumBattery(connection='can1') listeners = [ - #logger, # Regular Listener object + #logger, # CAN raw data logging bat ] notifier = can.Notifier(bat._ci, listeners) - for msg in bat._ci: - if msg.arbitration_id == 0x00140100: - bat.prnt() - # Clean-up + # Shutdown notifier.stop() bat._ci.shutdown()