From a1147afcf2f806b265502f0e38d9513f7f8fcff0 Mon Sep 17 00:00:00 2001 From: Martin Polehla Date: Fri, 15 Mar 2024 20:58:08 +0100 Subject: [PATCH 1/5] Fixing JK BMS black version. Adding JKBMS_CAN_CELL_COUNT to predefine number of cells. Fixing CAN reinstallation process. --- etc/dbus-serialbattery/bms/jkbms_can.py | 22 +++++++++++++--------- etc/dbus-serialbattery/config.default.ini | 4 ++++ etc/dbus-serialbattery/dbushelper.py | 6 ++++++ etc/dbus-serialbattery/reinstall-local.sh | 11 +++++------ etc/dbus-serialbattery/utils.py | 4 ++++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/etc/dbus-serialbattery/bms/jkbms_can.py b/etc/dbus-serialbattery/bms/jkbms_can.py index 7a9f7da7..8326e1b9 100644 --- a/etc/dbus-serialbattery/bms/jkbms_can.py +++ b/etc/dbus-serialbattery/bms/jkbms_can.py @@ -8,6 +8,7 @@ MAX_BATTERY_DISCHARGE_CURRENT, MAX_CELL_VOLTAGE, MIN_CELL_VOLTAGE, + JKBMS_CAN_CELL_COUNT, zero_char, ) from struct import unpack_from @@ -49,12 +50,14 @@ def __del__(self): MESSAGES_TO_READ = 100 - # Changed from 0x0XF4 to 0x0XF5. See https://github.com/Louisvdw/dbus-serialbattery/issues/950 + # B2A... Black is using 0x0XF4 + # B2A... Silver is using 0x0XF5 + # See https://github.com/Louisvdw/dbus-serialbattery/issues/950 CAN_FRAMES = { - BATT_STAT: 0x02F5, - CELL_VOLT: 0x04F5, - CELL_TEMP: 0x05F5, - ALM_INFO: 0x07F5, + BATT_STAT: [0x02F4,0x02F5], + CELL_VOLT: [0x04F4,0x04F5], + CELL_TEMP: [0x05F4,0x05F5], + ALM_INFO: [0x07F4,0x07F5] } def test_connection(self): @@ -67,6 +70,7 @@ def get_settings(self): # After successful connection get_settings will be call to set up the battery. # Set the current limits, populate cell count, etc # Return True if success, False for failure + self.cell_count = JKBMS_CAN_CELL_COUNT self.max_battery_charge_current = MAX_BATTERY_CHARGE_CURRENT self.max_battery_discharge_current = MAX_BATTERY_DISCHARGE_CURRENT self.max_battery_voltage = MAX_CELL_VOLTAGE * self.cell_count @@ -204,7 +208,7 @@ def read_serial_data_jkbms_CAN(self): # print("message received") messages_to_read -= 1 # print(messages_to_read) - if msg.arbitration_id == self.CAN_FRAMES[self.BATT_STAT]: + if msg.arbitration_id in self.CAN_FRAMES[self.BATT_STAT]: voltage = unpack_from(" /dev/null 2>&1; then + echo "Killing old BLE battery services..." svc -t /service/dbus-blebattery.* # always remove existing blebattery services to cleanup @@ -386,7 +387,8 @@ can_lenght=${#can_array[@]} # echo $can_lenght # stop all dbus-canbattery services, if at least one exists -if [ -d "/service/dbus-canbattery.0" ]; then +if ls /service/dbus-canbattery.* 1> /dev/null 2>&1; then + echo "Killing old CAN battery services..." svc -t /service/dbus-canbattery.* # always remove existing canbattery services to cleanup @@ -395,10 +397,7 @@ if [ -d "/service/dbus-canbattery.0" ]; then # kill all canbattery processes that remain pkill -f "supervise dbus-canbattery.*" pkill -f "multilog .* /var/log/dbus-canbattery.*" - pkill -f "python .*/dbus-serialbattery.py .*_Ble" - - # kill opened bluetoothctl processes - pkill -f "^bluetoothctl " + pkill -f "python .*/dbus-serialbattery.py can.*" fi diff --git a/etc/dbus-serialbattery/utils.py b/etc/dbus-serialbattery/utils.py index 4539d41e..92be67ef 100644 --- a/etc/dbus-serialbattery/utils.py +++ b/etc/dbus-serialbattery/utils.py @@ -53,6 +53,7 @@ def _get_list_from_config( # save config values to constants + # --------- Battery Current limits --------- MAX_BATTERY_CHARGE_CURRENT = float(config["DEFAULT"]["MAX_BATTERY_CHARGE_CURRENT"]) MAX_BATTERY_DISCHARGE_CURRENT = float( @@ -250,6 +251,9 @@ def _get_list_from_config( BATTERY_CAPACITY = float(config["DEFAULT"]["BATTERY_CAPACITY"]) INVERT_CURRENT_MEASUREMENT = int(config["DEFAULT"]["INVERT_CURRENT_MEASUREMENT"]) +# -- JK BMS settings +JKBMS_CAN_CELL_COUNT = int(config["DEFAULT"]["JKBMS_CAN_CELL_COUNT"]) + # -- ESC GreenMeter and Lipro device settings GREENMETER_ADDRESS = int(config["DEFAULT"]["GREENMETER_ADDRESS"]) LIPRO_START_ADDRESS = int(config["DEFAULT"]["LIPRO_START_ADDRESS"]) From db4cfecb638055e0285b4450018fe3e03a831a13 Mon Sep 17 00:00:00 2001 From: Martin Polehla Date: Mon, 18 Mar 2024 10:06:52 +0100 Subject: [PATCH 2/5] Update config.default.ini --- etc/dbus-serialbattery/config.default.ini | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/etc/dbus-serialbattery/config.default.ini b/etc/dbus-serialbattery/config.default.ini index 96201563..2c71a838 100644 --- a/etc/dbus-serialbattery/config.default.ini +++ b/etc/dbus-serialbattery/config.default.ini @@ -12,11 +12,6 @@ LOGGING = INFO MAX_BATTERY_CHARGE_CURRENT = 50.0 MAX_BATTERY_DISCHARGE_CURRENT = 60.0 -; ----------Cell count ------------ -; Predefine cell count for Jkbms_can -; Should be autodetected if not set -JKBMS_CAN_CELL_COUNT = 1 - ; --------- Cell Voltages --------- ; Description: ; Cell min/max voltages which are used to calculate the min/max battery voltage @@ -390,6 +385,14 @@ BATTERY_CAPACITY = 50 ; Invert Battery Current. Default non-inverted. Set to -1 to invert INVERT_CURRENT_MEASUREMENT = 1 +; -- JK (Jikong) settings +; Cell count +; Predefine cell count for Jkbms_can +; The cell count should be normally auto-detected by identifying the highest cell number, +; but this process is sometimes slow what may cause that cells are not updated on VenusOS. +; Try this workaround if you have experience problems with cell voltage. +JKBMS_CAN_CELL_COUNT = 1 + ; -- ESC GreenMeter and Lipro device settings GREENMETER_ADDRESS = 1 LIPRO_START_ADDRESS = 2 From 23269bb8feac25986234ced34538d9f8f8fe2837 Mon Sep 17 00:00:00 2001 From: Martin Polehla Date: Mon, 18 Mar 2024 10:16:46 +0100 Subject: [PATCH 3/5] Update config.default.ini --- etc/dbus-serialbattery/config.default.ini | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/etc/dbus-serialbattery/config.default.ini b/etc/dbus-serialbattery/config.default.ini index 2c71a838..235ef561 100644 --- a/etc/dbus-serialbattery/config.default.ini +++ b/etc/dbus-serialbattery/config.default.ini @@ -386,11 +386,10 @@ BATTERY_CAPACITY = 50 INVERT_CURRENT_MEASUREMENT = 1 ; -- JK (Jikong) settings -; Cell count -; Predefine cell count for Jkbms_can -; The cell count should be normally auto-detected by identifying the highest cell number, -; but this process is sometimes slow what may cause that cells are not updated on VenusOS. -; Try this workaround if you have experience problems with cell voltage. +; Predefines cell count for Jkbms_can +; The cell count should be auto-detected by identifying the highest cell number, +; but this process may be sometimes slow what could cause that cells voltage is not not +; updated in VenusOS. Try this workaround if you experience problems with cell voltage. JKBMS_CAN_CELL_COUNT = 1 ; -- ESC GreenMeter and Lipro device settings From 063d1f48602613c2c6d62af4e6d162e756b6726c Mon Sep 17 00:00:00 2001 From: Martin Polehla Date: Mon, 18 Mar 2024 10:33:25 +0100 Subject: [PATCH 4/5] Update jkbms_can.py --- etc/dbus-serialbattery/bms/jkbms_can.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/etc/dbus-serialbattery/bms/jkbms_can.py b/etc/dbus-serialbattery/bms/jkbms_can.py index 8326e1b9..de8557da 100644 --- a/etc/dbus-serialbattery/bms/jkbms_can.py +++ b/etc/dbus-serialbattery/bms/jkbms_can.py @@ -54,10 +54,10 @@ def __del__(self): # B2A... Silver is using 0x0XF5 # See https://github.com/Louisvdw/dbus-serialbattery/issues/950 CAN_FRAMES = { - BATT_STAT: [0x02F4,0x02F5], - CELL_VOLT: [0x04F4,0x04F5], - CELL_TEMP: [0x05F4,0x05F5], - ALM_INFO: [0x07F4,0x07F5] + BATT_STAT: [0x02F4, 0x02F5], + CELL_VOLT: [0x04F4, 0x04F5], + CELL_TEMP: [0x05F4, 0x05F5], + ALM_INFO: [0x07F4, 0x07F5] } def test_connection(self): From fa137d981138856b89b5aa34682788475a8331af Mon Sep 17 00:00:00 2001 From: Martin Polehla Date: Mon, 18 Mar 2024 10:56:55 +0100 Subject: [PATCH 5/5] Update jkbms_can.py --- etc/dbus-serialbattery/bms/jkbms_can.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/dbus-serialbattery/bms/jkbms_can.py b/etc/dbus-serialbattery/bms/jkbms_can.py index de8557da..e5407dc4 100644 --- a/etc/dbus-serialbattery/bms/jkbms_can.py +++ b/etc/dbus-serialbattery/bms/jkbms_can.py @@ -57,7 +57,7 @@ def __del__(self): BATT_STAT: [0x02F4, 0x02F5], CELL_VOLT: [0x04F4, 0x04F5], CELL_TEMP: [0x05F4, 0x05F5], - ALM_INFO: [0x07F4, 0x07F5] + ALM_INFO: [0x07F4, 0x07F5], } def test_connection(self):