From 0f66337e499f4f33fb6911ce47c91ce7200a9335 Mon Sep 17 00:00:00 2001 From: Petr <5851137+pvyleta@users.noreply.github.com> Date: Mon, 25 Mar 2024 11:30:08 +0100 Subject: [PATCH] added sub-version-ranges for each device --- src/main.py | 49 +++++++++++++++++++++++++++++++++++++---------- src/model.py | 14 +++++++++++--- src/out.py | 2 +- src/sw_version.py | 9 +++++++++ 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/main.py b/src/main.py index be6911b0..85ebd560 100644 --- a/src/main.py +++ b/src/main.py @@ -3,7 +3,8 @@ from sensor import get_dict_devices_sensor from parameter import get_device_parameters from command_ebus import get_commands_dict -from model import DeviceModel, VersionRange +from model import DeviceModel, VersionRange, VersionBase, DEBUG +from sw_version import Version # TODO Simplify output to less files by removing redundancy and extending parameter ranges # TODO Simplify output by joining params + sensors in one file per version range @@ -12,6 +13,11 @@ # TODO consider to hack the scanning through scan with different ID. the units might be willing to accept it # TODO make sure all output files have only LF and not CRLF +# TODO Make the output of joined files for a given device and SW version +# Publish known files to ebusd configuration, distinguish them by dipswitch for 3c and 7c +# consider adding comments for version +# 4. Write code to write the include line + # This script expects BCSServiceTool via JetBrains DotPeak in its child folder device_to_name_current_to_name_param_dict = device_to_name_current_to_name_param() @@ -34,13 +40,6 @@ converters_set: set[str] = {c for c in converters_map.keys()} unused_converters_set = converters_set - used_converters_set -# Make the output of joined files for a given device and SW version -# Publish known files to ebusd configuration, distinguish them by dipswitch for 3c and 7c -# consider adding comments for version -# 1. re-define scan for SW so that the string is parsed as integers -# 2. check the scan results on real device -# 3. write code to parse SW version to match the sw received -# 4. Write code to write the include line # Reorder to more layered structure device_models: dict[str, DeviceModel] = {} @@ -52,6 +51,38 @@ device_model = device_models.setdefault(device.device_name, DeviceModel(device.device_name)) device_model.parameters[device.version] = parameters + +# Add all sw-version-sub-ranges. We take advantage of having only two sets of non-intersecting version ranges. We merge the first/last versions, and make a joined list, and then construct a set out of it. +for device_model in device_models.values(): + version_set: set[Version] = set() + for version_range in device_model.parameters.keys(): + version_set.add(Version(version_range.first_version, 'first')) + version_set.add(Version(version_range.last_version, 'last')) + for version_range in device_model.sensors.keys(): + version_set.add(Version(version_range.first_version, 'first')) + version_set.add(Version(version_range.last_version, 'last')) + + version_list: list[Version] = sorted(list(version_set)) + while len(version_list) > 0: + first = version_list.pop(0) + + # If the next version is first again, insert artificial last version. + # Note: can happen if the two original set of ranges did not start at the same number, e.g. params start at 10806, sensors start at 10803 + if version_list[0].type == 'first': + version_list.insert(0, Version(version_list[0].version-1, 'last')) + + last = version_list.pop(0) + + # Sanity checks + assert first.type == 'first' + assert last.type == 'last' + + device_model.version_sub_ranges.add(VersionBase(first.version, last.version)) + + if DEBUG: + print(f'{device_model.name} {sorted(list(device_model.version_sub_ranges))}') + + # Check if subsequent version always contain all parameters from previous version for device_model in device_models.values(): sensors_versions: list[VersionRange] = sorted(list(device_model.sensors.keys())) @@ -80,8 +111,6 @@ previous_parameters = parameters -print("len(device_models): " + str()) - print("len(device_models): " + str(len(device_models))) print("unused_converters_set: " + str(unused_converters_set)) print("sensors_without_converters_set: " + str(len(sensors_without_converters_set))) diff --git a/src/model.py b/src/model.py index f751ff60..cba1bfcb 100644 --- a/src/model.py +++ b/src/model.py @@ -41,6 +41,14 @@ def __init__(self, name: str, type: str, multiplier: float, length: int, values: self.name_actual: str = "" self.converter_str: str = "" +class VersionBase(BaseObject): + def __init__(self, first_version: int, last_version: int): + self.first_version = first_version + self.last_version = last_version + + def __lt__(self, other): + return self.first_version < other.first_version + class VersionRange(BaseObject): def __init__(self, view_no: int, first_version: int, last_version: int): self.view_no = view_no @@ -48,8 +56,8 @@ def __init__(self, view_no: int, first_version: int, last_version: int): self.last_version = last_version def __lt__(self, other): - return self.view_no < other.view_no - + return self.first_version < other.first_version + class DeviceVersion(BaseObject): def __init__(self, device_name: str, version: VersionRange): @@ -61,8 +69,8 @@ class DeviceModel(BaseObject): def __init__(self, name: str): self.name = name self.sensors: dict[VersionRange, list[Sensor]] = {} - self.converters: dict[VersionRange, list[Converter]] = {} self.parameters: dict[VersionRange, list[Parameter]] = {} + self.version_sub_ranges: set[VersionBase] = set() # .xaml files do not have verson information, so we must rely on the view 'index' for matching diff --git a/src/out.py b/src/out.py index 31a08608..caace7d0 100644 --- a/src/out.py +++ b/src/out.py @@ -161,7 +161,7 @@ def write_known_devices(dict_devices_sensor: dict[DeviceVersion, list[Sensor]], # Contents of output_dir are always cleaned before writing -# File format is [device_name].[lowest_sw_version].[highest_sw_version].[params|sensors.basic|sensors.plus].csv +# File format is [device_name].[lowest_sw_version].[highest_sw_version].[sensors|params|params.basic|params.plus].csv def write_output(dict_devices_sensor: dict[DeviceVersion, list[Sensor]], dict_devices_parameter: dict[DeviceParameters, list[Parameter]]): if os.path.exists(OUTPUT_DIR): shutil.rmtree(OUTPUT_DIR) diff --git a/src/sw_version.py b/src/sw_version.py index c2260f14..20942ccb 100644 --- a/src/sw_version.py +++ b/src/sw_version.py @@ -1,5 +1,14 @@ from model import BaseObject +class Version(BaseObject): + def __init__(self, version: int, type: str): + self.version = version + self.type = type # assuming only 'first' and 'last' + + def __lt__(self, other): + return str(self.version) + self.type < str(other.version) + other.type + + # This class represents the Brink SoftwareVersion string represented as three integers class SWVersionBrinkEbusd(BaseObject): def __init__(self, major: int, minor: int, patch: int):