Skip to content

Commit

Permalink
added sub-version-ranges for each device
Browse files Browse the repository at this point in the history
  • Loading branch information
pvyleta committed Mar 25, 2024
1 parent 62a0f46 commit 0f66337
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
49 changes: 39 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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] = {}
Expand All @@ -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()))
Expand Down Expand Up @@ -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)))
Expand Down
14 changes: 11 additions & 3 deletions src/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,23 @@ 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
self.first_version = first_version
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):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/out.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/sw_version.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 0f66337

Please sign in to comment.