From ffdd8ec8c6407f7a14dc739baea68712aca4f459 Mon Sep 17 00:00:00 2001 From: ppuetsch <47553592+ppuetsch@users.noreply.github.com> Date: Sat, 14 Jan 2023 15:17:36 +0100 Subject: [PATCH] Make things configurable (#412) * bugfixes in midpoint calculation * publish constants to dbus * black and flake8 * update documentation * Fixes to cell voltage, temp and version (#390) (cherry picked from commit 3b68ea6b601dc1dc2cca97c704d060abad9d232a) * Automate release (#394) * automate release generation * make shell scripts +x * add yaml * rely on gh line ending conventions, simplify buildfiles.lst * add gitattributes * set file properties for run scripts to +x Co-authored-by: Philip Puetsch (cherry picked from commit ce601fb397d758f29ab02c57c2f99e9d2bb6d001) * configure limits as fractions * lint * cleanup * fixes * remove development logging Co-authored-by: Philip Puetsch Co-authored-by: pchiquit --- etc/dbus-serialbattery/battery.py | 4 +- etc/dbus-serialbattery/dbus-serialbattery.py | 17 +- etc/dbus-serialbattery/default_config.ini | 138 +++++++++++ etc/dbus-serialbattery/utils.py | 226 ++++++++++++------- 4 files changed, 292 insertions(+), 93 deletions(-) create mode 100644 etc/dbus-serialbattery/default_config.ini diff --git a/etc/dbus-serialbattery/battery.py b/etc/dbus-serialbattery/battery.py index 6e6f4a84..305cf4ef 100644 --- a/etc/dbus-serialbattery/battery.py +++ b/etc/dbus-serialbattery/battery.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from typing import Union, Tuple +from typing import Union, Tuple, List from utils import logger import utils @@ -76,7 +76,7 @@ def __init__(self, port, baud, address): self.temp_sensors = None self.temp1 = None self.temp2 = None - self.cells = [] + self.cells: List[Cell] = [] self.control_charging = None self.control_voltage = None self.allow_max_voltage = True diff --git a/etc/dbus-serialbattery/dbus-serialbattery.py b/etc/dbus-serialbattery/dbus-serialbattery.py index 55280e99..29a85bab 100644 --- a/etc/dbus-serialbattery/dbus-serialbattery.py +++ b/etc/dbus-serialbattery/dbus-serialbattery.py @@ -16,7 +16,8 @@ # from ve_utils import exit_on_error from dbushelper import DbusHelper -from utils import DRIVER_VERSION, DRIVER_SUBVERSION, logger +from utils import logger +import utils from battery import Battery from lltjbd import LltJbd from daly import Daly @@ -28,7 +29,7 @@ from ecs import Ecs from lifepower import Lifepower -battery_types = [ +supported_bms_types = [ {"bms": LltJbd, "baud": 9600}, {"bms": Ant, "baud": 19200}, {"bms": Daly, "baud": 9600, "address": b"\x40"}, @@ -40,7 +41,11 @@ {"bms": Renogy, "baud": 9600, "address": b"\xF7"}, {"bms": Ecs, "baud": 19200}, ] - +expected_bms_types = [ + battery_type + for battery_type in supported_bms_types + if battery_type["bms"].__name__ == utils.BMS_TYPE or utils.BMS_TYPE == "" +] logger.info("Starting dbus-serialbattery") @@ -60,7 +65,7 @@ def get_battery(_port) -> Union[Battery, None]: count = 3 while count > 0: # create a new battery object that can read the battery and run connection test - for test in battery_types: + for test in expected_bms_types: logger.info("Testing " + test["bms"].__name__) batteryClass = test["bms"] baud = test["baud"] @@ -86,7 +91,9 @@ def get_port() -> str: logger.info("No Port needed") return "/dev/tty/USB9" - logger.info("dbus-serialbattery v" + str(DRIVER_VERSION) + DRIVER_SUBVERSION) + logger.info( + "dbus-serialbattery v" + str(utils.DRIVER_VERSION) + utils.DRIVER_SUBVERSION + ) port = get_port() battery: Battery = get_battery(port) diff --git a/etc/dbus-serialbattery/default_config.ini b/etc/dbus-serialbattery/default_config.ini new file mode 100644 index 00000000..b9d96465 --- /dev/null +++ b/etc/dbus-serialbattery/default_config.ini @@ -0,0 +1,138 @@ +[DEFAULT] +LINEAR_LIMITATION_ENABLE = False + +; battery Current limits +MAX_BATTERY_CHARGE_CURRENT = 70.0 +MAX_BATTERY_DISCHARGE_CURRENT = 90.0 + +; -------- Cell Voltage limitation --------- +; Description: +; Maximal charge / discharge current will be in-/decreased depending on min- and max-cell-voltages +; Example: 18cells * 3.55V/cell = 63.9V max charge voltage. 18 * 2.7V = 48,6V min discharge voltage +; ... but the (dis)charge current will be (in-/)decreased, if even ONE SINGLE BATTERY CELL reaches the limits + +; Charge current control management referring to cell-voltage enable (True/False). +CCCM_CV_ENABLE = True +; Discharge current control management referring to cell-voltage enable (True/False). +DCCM_CV_ENABLE = True + +; Set Steps to reduce battery current. The current will be changed linear between those steps +CELL_VOLTAGES_WHILE_CHARGING = 3.55,3.50,3.45,3.30 +MAX_CHARGE_CURRENT_CV_FRACTION = 0,0.05,0.5,1 + +CELL_VOLTAGES_WHILE_DISCHARGING = 2.70,2.80,2.90,3.10 +MAX_DISCHARGE_CURRENT_CV_FRACTION = 0,0.1,0.5,1 + +; -------- Temperature limitation --------- +; Description: +; Maximal charge / discharge current will be in-/decreased depending on temperature +; Example: The temperature limit will be monitored to control the currents. If there are two temperature senors, +; then the worst case will be calculated and the more secure lower current will be set. +; Charge current control management referring to temperature enable (True/False). +CCCM_T_ENABLE = True +; Charge current control management referring to temperature enable (True/False). +DCCM_T_ENABLE = True + +; Set Steps to reduce battery current. The current will be changed linear between those steps +TEMPERATURE_LIMITS_WHILE_CHARGING = 0,2,5,10,15,20,35,40,55 +MAX_CHARGE_CURRENT_T_FRACTION = 0,0.1,0.2,0.4,0.8,1,1,0.4,0 + +TEMPERATURE_LIMITS_WHILE_DISCHARGING = -20,0,5,10,15,45,55 +MAX_DISCHARGE_CURRENT_T_FRACTION = 0,.2,.3,.4,1,1,0 + +; if the cell voltage reaches 3.55V, then reduce current battery-voltage by 0.01V +; if the cell voltage goes over 3.6V, then the maximum penalty will not be exceeded +; there will be a sum of all penalties for each cell, which exceeds the limits +PENALTY_AT_CELL_VOLTAGE = 3.45,3.55,3.6 +; this voltage will be subtracted +PENALTY_BATTERY_VOLTAGE = 0.01,1.0,2.0 + + +; -------- SOC limitation --------- +; Description: +; Maximal charge / discharge current will be increased / decreased depending on State of Charge, see CC_SOC_LIMIT1 etc. +; The State of Charge (SoC) charge / discharge current will be in-/decreased depending on SOC. +; Example: 16cells * 3.45V/cell = 55,2V max charge voltage. 16*2.9V = 46,4V min discharge voltage +; Cell min/max voltages - used with the cell count to get the min/max battery voltage +MIN_CELL_VOLTAGE = 2.9 +MAX_CELL_VOLTAGE = 3.45 +FLOAT_CELL_VOLTAGE = 3.35 +MAX_VOLTAGE_TIME_SEC = 900 +SOC_LEVEL_TO_RESET_VOLTAGE_LIMIT = 90 + +; Charge current control management enable (True/False). +CCCM_SOC_ENABLE = True +; Discharge current control management enable (True/False). +DCCM_SOC_ENABLE = True + +; charge current soc limits +CC_SOC_LIMIT1 = 98 +CC_SOC_LIMIT2 = 95 +CC_SOC_LIMIT3 = 91 + +; charge current limits +CC_CURRENT_LIMIT1_FRACTION = 0.1 +CC_CURRENT_LIMIT2_FRACTION = 0.3 +CC_CURRENT_LIMIT3_FRACTION = 0.5 + +; discharge current soc limits +DC_SOC_LIMIT1 = 10 +DC_SOC_LIMIT2 = 20 +DC_SOC_LIMIT3 = 30 + +; discharge current limits +DC_CURRENT_LIMIT1_FRACTION = 0.1 +DC_CURRENT_LIMIT2_FRACTION = 0.3 +DC_CURRENT_LIMIT3_FRACTION = 0.5 + +; Charge voltage control management enable (True/False). +CVCM_ENABLE = False + +; Simulate Midpoint graph (True/False). +MIDPOINT_ENABLE = False + +; soc low levels +SOC_LOW_WARNING = 20 +SOC_LOW_ALARM = 10 + +; Daly settings +; Battery capacity (amps) if the BMS does not support reading it +BATTERY_CAPACITY = 50 +; Invert Battery Current. Default non-inverted. Set to -1 to invert +INVERT_CURRENT_MEASUREMENT = 1 + +; TIME TO SOC settings [Valid values 0-100, but I don't recommend more that 20 intervals] +; Set of SoC percentages to report on dbus. The more you specify the more it will impact system performance. +; TIME_TO_SOC_POINTS = [100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0] +; Every 5% SoC +; TIME_TO_SOC_POINTS = [100, 95, 90, 85, 75, 50, 25, 20, 10, 0] +; No data set to disable +TIME_TO_SOC_POINTS = +; Specify TimeToSoc value type: [Valid values 1,2,3] +; TIME_TO_SOC_VALUE_TYPE = 1 ; Seconds +; TIME_TO_SOC_VALUE_TYPE = 2 ; Time string HH:MN:SC +; Both Seconds and time str " [days, HR:MN:SC]" +TIME_TO_SOC_VALUE_TYPE = 3 +; Specify how many loop cycles between each TimeToSoc updates +TIME_TO_SOC_LOOP_CYCLES = 5 +; Include TimeToSoC points when moving away from the SoC point. [Valid values True,False] +; These will be as negative time. Disabling this improves performance slightly. +TIME_TO_SOC_INC_FROM = False + + +; Select the format of cell data presented on dbus. [Valid values 0,1,2,3] +; 0 Do not publish all the cells (only the min/max cell data as used by the default GX) +; 1 Format: /Voltages/Cell; (also available for display on Remote Console) +; 2 Format: /Cell/#/Volts +; 3 Both formats 1 and 2 +BATTERY_CELL_DATA_FORMAT = 1 + +; Settings for ESC GreenMeter and Lipro devices +GREENMETER_ADDRESS = 1 +LIPRO_START_ADDRESS = 2 +LIPRO_END_ADDRESS = 4 +LIPRO_CELL_COUNT = 15 + +PUBLISH_CONFIG_VALUES = 1 + +BMS_TYPE = \ No newline at end of file diff --git a/etc/dbus-serialbattery/utils.py b/etc/dbus-serialbattery/utils.py index e22f10f1..032cfedf 100644 --- a/etc/dbus-serialbattery/utils.py +++ b/etc/dbus-serialbattery/utils.py @@ -1,5 +1,10 @@ # -*- coding: utf-8 -*- import logging + +import configparser +from pathlib import Path +from typing import List, Any, Callable + import serial from time import sleep from struct import unpack_from @@ -10,6 +15,22 @@ logger = logging.getLogger("SerialBattery") logger.setLevel(logging.INFO) +config = configparser.ConfigParser() +path = Path(__file__).parents[0] +default_config_file_path = path.joinpath("default_config.ini").absolute().__str__() +custom_config_file_path = path.joinpath("config.ini").absolute().__str__() +config.read([default_config_file_path, custom_config_file_path]) + + +def _get_list_from_config( + group: str, option: str, mapper: Callable[[Any], Any] = lambda v: v +) -> List[Any]: + rawList = config[group][option].split(",") + return list( + map(mapper, [item for item in rawList if item != "" and item is not None]) + ) + + # battery types # if not specified: baud = 9600 @@ -22,11 +43,13 @@ # Choose the mode for voltage / current limitations (True / False) # False is a Step mode. This is the default with limitations on hard boundary steps # True "Linear" # New linear limitations by WaldemarFech for smoother values -LINEAR_LIMITATION_ENABLE = False +LINEAR_LIMITATION_ENABLE = "True" == config["DEFAULT"]["LINEAR_LIMITATION_ENABLE"] # battery Current limits -MAX_BATTERY_CHARGE_CURRENT = 70.0 -MAX_BATTERY_DISCHARGE_CURRENT = 90.0 +MAX_BATTERY_CHARGE_CURRENT = float(config["DEFAULT"]["MAX_BATTERY_CHARGE_CURRENT"]) +MAX_BATTERY_DISCHARGE_CURRENT = float( + config["DEFAULT"]["MAX_BATTERY_DISCHARGE_CURRENT"] +) # -------- Cell Voltage limitation --------- # Description: @@ -35,26 +58,28 @@ # ... but the (dis)charge current will be (in-/)decreased, if even ONE SINGLE BATTERY CELL reaches the limits # Charge current control management referring to cell-voltage enable (True/False). -CCCM_CV_ENABLE = True +CCCM_CV_ENABLE = "True" == config["DEFAULT"]["CCCM_CV_ENABLE"] # Discharge current control management referring to cell-voltage enable (True/False). -DCCM_CV_ENABLE = True +DCCM_CV_ENABLE = "True" == config["DEFAULT"]["DCCM_CV_ENABLE"] # Set Steps to reduce battery current. The current will be changed linear between those steps -CELL_VOLTAGES_WHILE_CHARGING = [3.55, 3.50, 3.45, 3.30] -MAX_CHARGE_CURRENT_CV = [ - 0, - MAX_BATTERY_CHARGE_CURRENT * 0.05, - MAX_BATTERY_CHARGE_CURRENT * 0.5, - MAX_BATTERY_CHARGE_CURRENT, -] - -CELL_VOLTAGES_WHILE_DISCHARGING = [2.70, 2.80, 2.90, 3.10] -MAX_DISCHARGE_CURRENT_CV = [ - 0, - MAX_BATTERY_DISCHARGE_CURRENT * 0.1, - MAX_BATTERY_DISCHARGE_CURRENT * 0.5, - MAX_BATTERY_DISCHARGE_CURRENT, -] +CELL_VOLTAGES_WHILE_CHARGING = _get_list_from_config( + "DEFAULT", "CELL_VOLTAGES_WHILE_CHARGING", lambda v: float(v) +) +MAX_CHARGE_CURRENT_CV = _get_list_from_config( + "DEFAULT", + "MAX_CHARGE_CURRENT_CV_FRACTION", + lambda v: MAX_BATTERY_CHARGE_CURRENT * float(v), +) + +CELL_VOLTAGES_WHILE_DISCHARGING = _get_list_from_config( + "DEFAULT", "CELL_VOLTAGES_WHILE_DISCHARGING", lambda v: float(v) +) +MAX_DISCHARGE_CURRENT_CV = _get_list_from_config( + "DEFAULT", + "MAX_DISCHARGE_CURRENT_CV_FRACTION", + lambda v: MAX_BATTERY_DISCHARGE_CURRENT * float(v), +) # -------- Temperature limitation --------- # Description: @@ -62,41 +87,38 @@ # Example: The temperature limit will be monitored to control the currents. If there are two temperature senors, # then the worst case will be calculated and the more secure lower current will be set. # Charge current control management referring to temperature enable (True/False). -CCCM_T_ENABLE = True +CCCM_T_ENABLE = "True" == config["DEFAULT"]["CCCM_T_ENABLE"] # Charge current control management referring to temperature enable (True/False). -DCCM_T_ENABLE = True - -# Set Steps to reduce battery current. -# The current will be changed linear between those steps if LINEAR_LIMITATION_ENABLE = True is set above -TEMPERATURE_LIMITS_WHILE_CHARGING = [0, 2, 5, 10, 15, 20, 35, 40, 55] -MAX_CHARGE_CURRENT_T = [ - 0, # 0 - MAX_BATTERY_CHARGE_CURRENT * 0.1, # 2 - MAX_BATTERY_CHARGE_CURRENT * 0.2, # 5 - MAX_BATTERY_CHARGE_CURRENT * 0.4, # 10 - MAX_BATTERY_CHARGE_CURRENT * 0.8, # 15 - MAX_BATTERY_CHARGE_CURRENT, # 20 - MAX_BATTERY_CHARGE_CURRENT, # 35 - MAX_BATTERY_CHARGE_CURRENT * 0.4, # 40 - 0, # 55 -] - -TEMPERATURE_LIMITS_WHILE_DISCHARGING = [-20, 0, 5, 10, 15, 45, 55] -MAX_DISCHARGE_CURRENT_T = [ - 0, # -20 - MAX_BATTERY_DISCHARGE_CURRENT * 0.2, # 0 - MAX_BATTERY_DISCHARGE_CURRENT * 0.3, # 5 - MAX_BATTERY_DISCHARGE_CURRENT * 0.4, # 10 - MAX_BATTERY_DISCHARGE_CURRENT, # 15 - MAX_BATTERY_DISCHARGE_CURRENT, # 45 - 0, # 55 -] +DCCM_T_ENABLE = "True" == config["DEFAULT"]["DCCM_T_ENABLE"] + +# Set Steps to reduce battery current. The current will be changed linear between those steps +TEMPERATURE_LIMITS_WHILE_CHARGING = _get_list_from_config( + "DEFAULT", "TEMPERATURE_LIMITS_WHILE_CHARGING", lambda v: float(v) +) +MAX_CHARGE_CURRENT_T = _get_list_from_config( + "DEFAULT", + "MAX_CHARGE_CURRENT_T_FRACTION", + lambda v: MAX_BATTERY_CHARGE_CURRENT * float(v), +) + +TEMPERATURE_LIMITS_WHILE_DISCHARGING = _get_list_from_config( + "DEFAULT", "TEMPERATURE_LIMITS_WHILE_DISCHARGING", lambda v: float(v) +) +MAX_DISCHARGE_CURRENT_T = _get_list_from_config( + "DEFAULT", + "MAX_DISCHARGE_CURRENT_T_FRACTION", + lambda v: MAX_BATTERY_DISCHARGE_CURRENT * float(v), +) # if the cell voltage reaches 3.55V, then reduce current battery-voltage by 0.01V # if the cell voltage goes over 3.6V, then the maximum penalty will not be exceeded # there will be a sum of all penalties for each cell, which exceeds the limits -PENALTY_AT_CELL_VOLTAGE = [3.45, 3.55, 3.6] -PENALTY_BATTERY_VOLTAGE = [0.01, 1.0, 2.0] # this voltage will be subtracted +PENALTY_AT_CELL_VOLTAGE = _get_list_from_config( + "DEFAULT", "PENALTY_AT_CELL_VOLTAGE", lambda v: float(v) +) +PENALTY_BATTERY_VOLTAGE = _get_list_from_config( + "DEFAULT", "PENALTY_BATTERY_VOLTAGE", lambda v: float(v) +) # -------- SOC limitation --------- @@ -105,70 +127,82 @@ # The State of Charge (SoC) charge / discharge current will be in-/decreased depending on SOC. # Example: 16cells * 3.45V/cell = 55,2V max charge voltage. 16*2.9V = 46,4V min discharge voltage # Cell min/max voltages - used with the cell count to get the min/max battery voltage -MIN_CELL_VOLTAGE = 2.9 -MAX_CELL_VOLTAGE = 3.45 -FLOAT_CELL_VOLTAGE = 3.35 -MAX_VOLTAGE_TIME_SEC = 15 * 60 -SOC_LEVEL_TO_RESET_VOLTAGE_LIMIT = 90 - +MIN_CELL_VOLTAGE = float(config["DEFAULT"]["MIN_CELL_VOLTAGE"]) +MAX_CELL_VOLTAGE = float(config["DEFAULT"]["MAX_CELL_VOLTAGE"]) +FLOAT_CELL_VOLTAGE = float(config["DEFAULT"]["FLOAT_CELL_VOLTAGE"]) +MAX_VOLTAGE_TIME_SEC = float(config["DEFAULT"]["MAX_VOLTAGE_TIME_SEC"]) +SOC_LEVEL_TO_RESET_VOLTAGE_LIMIT = float( + config["DEFAULT"]["SOC_LEVEL_TO_RESET_VOLTAGE_LIMIT"] +) # Charge current control management enable (True/False). -CCCM_SOC_ENABLE = True +CCCM_SOC_ENABLE = "True" == config["DEFAULT"]["CCCM_SOC_ENABLE"] # Discharge current control management enable (True/False). -DCCM_SOC_ENABLE = True +DCCM_SOC_ENABLE = "True" == config["DEFAULT"]["DCCM_SOC_ENABLE"] # charge current soc limits -CC_SOC_LIMIT1 = 98 -CC_SOC_LIMIT2 = 95 -CC_SOC_LIMIT3 = 91 +CC_SOC_LIMIT1 = float(config["DEFAULT"]["CC_SOC_LIMIT1"]) +CC_SOC_LIMIT2 = float(config["DEFAULT"]["CC_SOC_LIMIT2"]) +CC_SOC_LIMIT3 = float(config["DEFAULT"]["CC_SOC_LIMIT3"]) # charge current limits -CC_CURRENT_LIMIT1 = MAX_BATTERY_CHARGE_CURRENT * 0.1 -CC_CURRENT_LIMIT2 = MAX_BATTERY_CHARGE_CURRENT * 0.3 -CC_CURRENT_LIMIT3 = MAX_BATTERY_CHARGE_CURRENT * 0.5 +CC_CURRENT_LIMIT1 = MAX_BATTERY_CHARGE_CURRENT * float( + config["DEFAULT"]["CC_CURRENT_LIMIT1_FRACTION"] +) +CC_CURRENT_LIMIT2 = MAX_BATTERY_CHARGE_CURRENT * float( + config["DEFAULT"]["CC_CURRENT_LIMIT2_FRACTION"] +) +CC_CURRENT_LIMIT3 = MAX_BATTERY_CHARGE_CURRENT * float( + config["DEFAULT"]["CC_CURRENT_LIMIT3_FRACTION"] +) # discharge current soc limits -# discharge current soc limits -DC_SOC_LIMIT1 = 10 -DC_SOC_LIMIT2 = 20 -DC_SOC_LIMIT3 = 30 +DC_SOC_LIMIT1 = float(config["DEFAULT"]["DC_SOC_LIMIT1"]) +DC_SOC_LIMIT2 = float(config["DEFAULT"]["DC_SOC_LIMIT2"]) +DC_SOC_LIMIT3 = float(config["DEFAULT"]["DC_SOC_LIMIT3"]) # discharge current limits -DC_CURRENT_LIMIT1 = MAX_BATTERY_DISCHARGE_CURRENT * 0.1 -DC_CURRENT_LIMIT2 = MAX_BATTERY_DISCHARGE_CURRENT * 0.3 -DC_CURRENT_LIMIT3 = MAX_BATTERY_DISCHARGE_CURRENT * 0.5 +DC_CURRENT_LIMIT1 = MAX_BATTERY_DISCHARGE_CURRENT * float( + config["DEFAULT"]["DC_CURRENT_LIMIT1_FRACTION"] +) +DC_CURRENT_LIMIT2 = MAX_BATTERY_DISCHARGE_CURRENT * float( + config["DEFAULT"]["DC_CURRENT_LIMIT2_FRACTION"] +) +DC_CURRENT_LIMIT3 = MAX_BATTERY_DISCHARGE_CURRENT * float( + config["DEFAULT"]["DC_CURRENT_LIMIT3_FRACTION"] +) # Charge voltage control management enable (True/False). -CVCM_ENABLE = False +CVCM_ENABLE = "True" == config["DEFAULT"]["CVCM_ENABLE"] # Simulate Midpoint graph (True/False). -MIDPOINT_ENABLE = False +MIDPOINT_ENABLE = "True" == config["DEFAULT"]["MIDPOINT_ENABLE"] # soc low levels -SOC_LOW_WARNING = 20 -SOC_LOW_ALARM = 10 +SOC_LOW_WARNING = float(config["DEFAULT"]["SOC_LOW_WARNING"]) +SOC_LOW_ALARM = float(config["DEFAULT"]["SOC_LOW_ALARM"]) # Daly settings # Battery capacity (amps) if the BMS does not support reading it -BATTERY_CAPACITY = 50 +BATTERY_CAPACITY = float(config["DEFAULT"]["BATTERY_CAPACITY"]) # Invert Battery Current. Default non-inverted. Set to -1 to invert -INVERT_CURRENT_MEASUREMENT = 1 +INVERT_CURRENT_MEASUREMENT = int(config["DEFAULT"]["INVERT_CURRENT_MEASUREMENT"]) # TIME TO SOC settings [Valid values 0-100, but I don't recommend more that 20 intervals] # Set of SoC percentages to report on dbus. The more you specify the more it will impact system performance. # TIME_TO_SOC_POINTS = [100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0] # Every 5% SoC # TIME_TO_SOC_POINTS = [100, 95, 90, 85, 75, 50, 25, 20, 10, 0] -TIME_TO_SOC_POINTS = [] # No data set to disable +TIME_TO_SOC_POINTS = _get_list_from_config("DEFAULT", "TIME_TO_SOC_POINTS") # Specify TimeToSoc value type: [Valid values 1,2,3] # TIME_TO_SOC_VALUE_TYPE = 1 # Seconds # TIME_TO_SOC_VALUE_TYPE = 2 # Time string HH:MN:SC -TIME_TO_SOC_VALUE_TYPE = 3 # Both Seconds and time str " [days, HR:MN:SC]" +TIME_TO_SOC_VALUE_TYPE = int(config["DEFAULT"]["TIME_TO_SOC_VALUE_TYPE"]) # Specify how many loop cycles between each TimeToSoc updates -TIME_TO_SOC_LOOP_CYCLES = 5 +TIME_TO_SOC_LOOP_CYCLES = int(config["DEFAULT"]["TIME_TO_SOC_LOOP_CYCLES"]) # Include TimeToSoC points when moving away from the SoC point. [Valid values True,False] # These will be as negative time. Disabling this improves performance slightly. -TIME_TO_SOC_INC_FROM = False +TIME_TO_SOC_INC_FROM = "True" == config["DEFAULT"]["TIME_TO_SOC_INC_FROM"] # Select the format of cell data presented on dbus. [Valid values 0,1,2,3] @@ -176,13 +210,17 @@ # 1 Format: /Voltages/Cell# (also available for display on Remote Console) # 2 Format: /Cell/#/Volts # 3 Both formats 1 and 2 -BATTERY_CELL_DATA_FORMAT = 1 +BATTERY_CELL_DATA_FORMAT = int(config["DEFAULT"]["BATTERY_CELL_DATA_FORMAT"]) # Settings for ESC GreenMeter and Lipro devices -GREENMETER_ADDRESS = 1 -LIPRO_START_ADDRESS = 2 -LIPRO_END_ADDRESS = 4 -LIPRO_CELL_COUNT = 15 +GREENMETER_ADDRESS = int(config["DEFAULT"]["GREENMETER_ADDRESS"]) +LIPRO_START_ADDRESS = int(config["DEFAULT"]["LIPRO_START_ADDRESS"]) +LIPRO_END_ADDRESS = int(config["DEFAULT"]["LIPRO_END_ADDRESS"]) +LIPRO_CELL_COUNT = int(config["DEFAULT"]["LIPRO_CELL_COUNT"]) + +PUBLISH_CONFIG_VALUES = int(config["DEFAULT"]["PUBLISH_CONFIG_VALUES"]) + +BMS_TYPE = config["DEFAULT"]["BMS_TYPE"] def constrain(val, min_val, max_val): @@ -353,3 +391,19 @@ def read_serialport_data( except serial.SerialException as e: logger.error(e) return False + + +locals_copy = locals().copy() + + +def publish_config_variables(dbusservice): + for variable, value in locals_copy.items(): + if variable.startswith("__"): + continue + if ( + isinstance(value, float) + or isinstance(value, int) + or isinstance(value, str) + or isinstance(value, List) + ): + dbusservice.add_path(f"/Info/Config/{variable}", value)