From 7b239007bd87bc3fdfd6a3a3726937f1210997f2 Mon Sep 17 00:00:00 2001 From: Louis Van Der Walt <26077665+Louisvdw@users.noreply.github.com> Date: Thu, 15 Dec 2022 21:11:36 +0200 Subject: [PATCH] Cvl fix (#353) * fix #334 missing CVL * fix #325 restore GUI * fix #339 negative temp * Deprecate Revov driver - replaced by LifePower --- buildfiles.lst | 2 +- etc/dbus-serialbattery/battery.py | 18 +++++++++--------- etc/dbus-serialbattery/jkbms.py | 4 ++-- etc/dbus-serialbattery/restoregui.sh | 11 +++++++++++ etc/dbus-serialbattery/utils.py | 3 +-- 5 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 etc/dbus-serialbattery/restoregui.sh diff --git a/buildfiles.lst b/buildfiles.lst index eb59db07..fd65c8bf 100644 --- a/buildfiles.lst +++ b/buildfiles.lst @@ -9,6 +9,7 @@ etc/dbus-serialbattery/disabledriver.sh etc/dbus-serialbattery/installlocal.sh etc/dbus-serialbattery/installrelease.sh etc/dbus-serialbattery/reinstalllocal.sh +etc/dbus-serialbattery/restoregui.sh etc/dbus-serialbattery/installqml.sh etc/dbus-serialbattery/qml/PageBattery.qml etc/dbus-serialbattery/qml/PageBatteryCellVoltages.qml @@ -26,6 +27,5 @@ etc/dbus-serialbattery/mnb.py etc/dbus-serialbattery/jkbms.py etc/dbus-serialbattery/sinowealth.py etc/dbus-serialbattery/renogy.py -etc/dbus-serialbattery/revov.py etc/dbus-serialbattery/ecs.py etc/dbus-serialbattery/lifepower.py \ No newline at end of file diff --git a/etc/dbus-serialbattery/battery.py b/etc/dbus-serialbattery/battery.py index c03de54a..b8385dbd 100644 --- a/etc/dbus-serialbattery/battery.py +++ b/etc/dbus-serialbattery/battery.py @@ -104,12 +104,13 @@ def to_temp(self, sensor, value): def manage_charge_voltage(self): if LINEAR_LIMITATION_ENABLE: - return self.manage_charge_voltage_linear() - return self.manage_charge_voltage_step() + self.manage_charge_voltage_linear() + else: + self.manage_charge_voltage_step() def manage_charge_voltage_linear(self): + foundHighCellVoltage = False if CVCM_ENABLE: - foundHighCellVoltage = False currentBatteryVoltage = 0 penaltySum = 0 for i in range(self.cell_count): @@ -120,13 +121,12 @@ def manage_charge_voltage_linear(self): if cv >= PENALTY_AT_CELL_VOLTAGE[0]: foundHighCellVoltage = True penaltySum += calcLinearRelationship(cv, PENALTY_AT_CELL_VOLTAGE, PENALTY_BATTERY_VOLTAGE) - self.voltage = currentBatteryVoltage # for testing - if foundHighCellVoltage: - self.control_voltage = currentBatteryVoltage - penaltySum - else: - self.control_voltage = MAX_CELL_VOLTAGE * self.cell_count - return penaltySum + + if foundHighCellVoltage: + self.control_voltage = currentBatteryVoltage - penaltySum + else: + self.control_voltage = MAX_CELL_VOLTAGE * self.cell_count def manage_charge_voltage_step(self): voltageSum = 0 diff --git a/etc/dbus-serialbattery/jkbms.py b/etc/dbus-serialbattery/jkbms.py index e49eb650..b51be6b8 100644 --- a/etc/dbus-serialbattery/jkbms.py +++ b/etc/dbus-serialbattery/jkbms.py @@ -85,8 +85,8 @@ def read_status_data(self): temp1 = unpack_from('>H', self.get_data(status_data, b'\x81', offset, 2))[0] offset = cellbyte_count + 9 temp2 = unpack_from('>H', self.get_data(status_data, b'\x82', offset, 2))[0] - self.to_temp(1, temp1 if temp1 <= 100 else 100 - temp1) - self.to_temp(2, temp2 if temp2 <= 100 else 100 - temp2) + self.to_temp(1, temp1 if temp1 <= 100 else -(temp1 - 100)) + self.to_temp(2, temp1 if temp2 <= 100 else -(temp2 - 100)) offset = cellbyte_count + 12 voltage = unpack_from('>H', self.get_data(status_data, b'\x83', offset, 2))[0] diff --git a/etc/dbus-serialbattery/restoregui.sh b/etc/dbus-serialbattery/restoregui.sh new file mode 100644 index 00000000..bd521103 --- /dev/null +++ b/etc/dbus-serialbattery/restoregui.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +#restore original backup +cp -f /opt/victronenergy/gui/qml/PageBattery.qml.backup /opt/victronenergy/gui/qml/PageBattery.qml + +#stop gui +svc -d /service/gui +#sleep 1 sec +sleep 1 +#start gui +svc -u /service/gui diff --git a/etc/dbus-serialbattery/utils.py b/etc/dbus-serialbattery/utils.py index 4ff55dc6..8becb88b 100644 --- a/etc/dbus-serialbattery/utils.py +++ b/etc/dbus-serialbattery/utils.py @@ -22,14 +22,13 @@ {"bms" : "Lifepower"}, {"bms" : "Renogy", "address": b"\x30"}, {"bms" : "Renogy", "address": b"\xF7"}, -# {"bms" : "Revov"}, {"bms" : "Ecs", "baud" : 19200}, # {"bms" : "MNB"}, ] # Constants - Need to dynamically get them in future DRIVER_VERSION = 0.14 -DRIVER_SUBVERSION = '1' +DRIVER_SUBVERSION = '2' zero_char = chr(48) degree_sign = u'\N{DEGREE SIGN}'