From cdf7900e588e95612c4734d83d70509d783f706c Mon Sep 17 00:00:00 2001 From: Petr <5851137+pvyleta@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:09:48 +0100 Subject: [PATCH] Removed empty and useless Flair base files --- .../FlairBase.10101.10110.params.basic.csv | 1 - .../FlairBase.10101.10110.params.plus.csv | 1 - .../FlairBase.10111.99999.params.basic.csv | 1 - .../FlairBase.10111.99999.params.plus.csv | 1 - src/main.py | 34 +++++++++++++------ src/model.py | 5 +-- src/out.py | 32 ++++++++--------- src/parameter.py | 6 +++- 8 files changed, 46 insertions(+), 35 deletions(-) delete mode 100644 ebusd-configuration/FlairBase.10101.10110.params.basic.csv delete mode 100644 ebusd-configuration/FlairBase.10101.10110.params.plus.csv delete mode 100644 ebusd-configuration/FlairBase.10111.99999.params.basic.csv delete mode 100644 ebusd-configuration/FlairBase.10111.99999.params.plus.csv diff --git a/ebusd-configuration/FlairBase.10101.10110.params.basic.csv b/ebusd-configuration/FlairBase.10101.10110.params.basic.csv deleted file mode 100644 index 68ee56d8..00000000 --- a/ebusd-configuration/FlairBase.10101.10110.params.basic.csv +++ /dev/null @@ -1 +0,0 @@ -# type (r[1-9];w;u),circuit,name,[comment],[QQ],ZZ,PBSB,[ID],field1,part (m/s),datatypes/templates,divider/values,unit,comment,field2,part (m/s),datatypes/templates,divider/values,unit,comment,field3,part (m/s),datatypes/templates,divider/values,unit,comment,field4,part (m/s),datatypes/templates,divider/values,unit,comment,field5,part (m/s),datatypes/templates,divider/values,unit,comment diff --git a/ebusd-configuration/FlairBase.10101.10110.params.plus.csv b/ebusd-configuration/FlairBase.10101.10110.params.plus.csv deleted file mode 100644 index 68ee56d8..00000000 --- a/ebusd-configuration/FlairBase.10101.10110.params.plus.csv +++ /dev/null @@ -1 +0,0 @@ -# type (r[1-9];w;u),circuit,name,[comment],[QQ],ZZ,PBSB,[ID],field1,part (m/s),datatypes/templates,divider/values,unit,comment,field2,part (m/s),datatypes/templates,divider/values,unit,comment,field3,part (m/s),datatypes/templates,divider/values,unit,comment,field4,part (m/s),datatypes/templates,divider/values,unit,comment,field5,part (m/s),datatypes/templates,divider/values,unit,comment diff --git a/ebusd-configuration/FlairBase.10111.99999.params.basic.csv b/ebusd-configuration/FlairBase.10111.99999.params.basic.csv deleted file mode 100644 index 68ee56d8..00000000 --- a/ebusd-configuration/FlairBase.10111.99999.params.basic.csv +++ /dev/null @@ -1 +0,0 @@ -# type (r[1-9];w;u),circuit,name,[comment],[QQ],ZZ,PBSB,[ID],field1,part (m/s),datatypes/templates,divider/values,unit,comment,field2,part (m/s),datatypes/templates,divider/values,unit,comment,field3,part (m/s),datatypes/templates,divider/values,unit,comment,field4,part (m/s),datatypes/templates,divider/values,unit,comment,field5,part (m/s),datatypes/templates,divider/values,unit,comment diff --git a/ebusd-configuration/FlairBase.10111.99999.params.plus.csv b/ebusd-configuration/FlairBase.10111.99999.params.plus.csv deleted file mode 100644 index 68ee56d8..00000000 --- a/ebusd-configuration/FlairBase.10111.99999.params.plus.csv +++ /dev/null @@ -1 +0,0 @@ -# type (r[1-9];w;u),circuit,name,[comment],[QQ],ZZ,PBSB,[ID],field1,part (m/s),datatypes/templates,divider/values,unit,comment,field2,part (m/s),datatypes/templates,divider/values,unit,comment,field3,part (m/s),datatypes/templates,divider/values,unit,comment,field4,part (m/s),datatypes/templates,divider/values,unit,comment,field5,part (m/s),datatypes/templates,divider/values,unit,comment diff --git a/src/main.py b/src/main.py index 70e733f0..3c043b7e 100644 --- a/src/main.py +++ b/src/main.py @@ -45,22 +45,36 @@ device_model = device_models.setdefault(device.device_name, DeviceModel(device.device_name)) device_model.sensors[device.version] = sensors -# Check if subsequent version alwas contain all parameters from previous version +for device, parameters in dict_devices_parameters.items(): + device_model = device_models.setdefault(device.device_name, DeviceModel(device.device_name)) + device_model.parameters[device.version] = parameters + +# Check if subsequent version always contain all parameters from previous version for device_model in device_models.values(): - versions: list[VersionRange] = sorted(list(device_model.sensors.keys())) - previous_sensors = device_model.sensors[versions[0]] # initialize to the first version - for version in versions: - sensors = device_model.sensors[version] + sensors_versions: list[VersionRange] = sorted(list(device_model.sensors.keys())) + previous_sensors = device_model.sensors[sensors_versions[0]] # initialize to the first version + for sensor_version in sensors_versions: + sensors = device_model.sensors[sensor_version] for sensor in previous_sensors: - if sensor not in sensors: - print(f"ERROR: Sensor {sensor} from previous version not present in version {version} for device {device_model.name}") - # By default, Fails only for DecentralAir70 for two parameters, where converters were added in newer version. That almost seems like omitment, so we just correct that when assigning converters, and keep this assert as a sanity check # assert sensor in sensors + if sensor not in sensors: + pass + # print(f"WARNING: Sensor {sensor} from previous version not present in version {sensor_version} for device {device_model.name}") + previous_sensors = sensors - - + parameters_versions: list[VersionRange] = sorted(list(device_model.parameters.keys())) + previous_parameters = device_model.parameters[parameters_versions[0]] # initialize to the first version + for parameter_version in parameters_versions: + parameters = device_model.parameters[parameter_version] + for parameter in previous_parameters: + # TODO This fails for surprising amount of devices. Either we need to fix somethign deep in parameter creation, or we just cannot make it subsets + if parameter not in parameters: + pass + # print(f"WARNING: Parameter {parameter} from previous version not present in version {parameter_version} for device {device_model.name}") + + previous_parameters = parameters print("len(device_models): " + str(len(device_models))) print("unused_converters_set: " + str(unused_converters_set)) diff --git a/src/model.py b/src/model.py index 74f3ed52..f751ff60 100644 --- a/src/model.py +++ b/src/model.py @@ -125,10 +125,7 @@ def __init__(self, current: int, min: int, max: int, step: int, default: int): self.default = default class Parameter(BaseObject): - def __init__(self, device_name: str, first_version: int, last_version: int, is_plus_only: bool, id: int, name: str, unit: str, multiplier: float, datatype: str, is_read_only: bool, fields: Fields): - self.device_name = device_name - self.first_version = first_version - self.last_version = last_version + def __init__(self, is_plus_only: bool, id: int, name: str, unit: str, multiplier: float, datatype: str, is_read_only: bool, fields: Fields): self.is_plus_only = is_plus_only self.id = id self.name = name diff --git a/src/out.py b/src/out.py index 63164f85..ea0884b1 100644 --- a/src/out.py +++ b/src/out.py @@ -37,11 +37,11 @@ def dump_sensor(sensor: Sensor, device_version: DeviceVersion) -> SensorDump: return SensorDump(**dump_sensor_dict) -def dump_param(param: Parameter) -> ParameterDump: +def dump_param(param: Parameter, device_version: DeviceVersion) -> ParameterDump: dump_param_dict: dict[str, str] = {} - dump_param_dict['device_name'] = param.device_name - dump_param_dict['first_version'] = str(param.first_version) - dump_param_dict['last_version'] = str(param.last_version) + dump_param_dict['device_name'] = device_version.device_name + dump_param_dict['first_version'] = str(device_version.version.first_version) + dump_param_dict['last_version'] = str(device_version.version.last_version) dump_param_dict['name'] = param.name dump_param_dict['id'] = f'0x{param.id:02x}' dump_param_dict['unit'] = param.unit @@ -69,23 +69,23 @@ def csv_line_sensor(sensor: Sensor, device_name: str, slave_address: str) -> str return f'r,{device_name},{sensor.name_current.removeprefix('Current')},{sensor.name_description},,{slave_address},4022,{sensor.id:02x},,,{type},{values},{sensor.unit},\n' -def csv_line_parameters_read(param: Parameter, slave_address: str) -> str: +def csv_line_parameters_read(param: Parameter, device_name: str, slave_address: str) -> str: # type (r[1-9];w;u),circuit,name,[comment],[QQ],ZZ,PBSB,[ID],field1,part (m/s),datatypes/templates,divider/values,unit,comment datatype = convert_to_ebus_datatype(param.datatype) if values := param.values: comment = f'[default:{param.field_default}] - min/max/step fields of enum message omitted' - return f'r,{param.device_name},{param.name},{param.name},,{slave_address},4050,{param.id:02x},,,{datatype},{values},{param.unit},,,,IGN:6,,,,Default,,{datatype},{values},{param.unit},{comment}\n' + return f'r,{device_name},{param.name},{param.name},,{slave_address},4050,{param.id:02x},,,{datatype},{values},{param.unit},,,,IGN:6,,,,Default,,{datatype},{values},{param.unit},{comment}\n' else: values = multiplier_to_divider(param.multiplier) - return f'r,{param.device_name},{param.name},{param.name},,{slave_address},4050,{param.id:02x},,,{datatype},{values},{param.unit},,Min,,{datatype},{values},{param.unit},[min:{param.field_min}],Max,,{datatype},{values},{param.unit},[max:{param.field_max}],Step,,{datatype},{values},{param.unit},[step:{param.field_step}],Default,,{datatype},{values},{param.unit},[default:{param.field_default}]\n' + return f'r,{device_name},{param.name},{param.name},,{slave_address},4050,{param.id:02x},,,{datatype},{values},{param.unit},,Min,,{datatype},{values},{param.unit},[min:{param.field_min}],Max,,{datatype},{values},{param.unit},[max:{param.field_max}],Step,,{datatype},{values},{param.unit},[step:{param.field_step}],Default,,{datatype},{values},{param.unit},[default:{param.field_default}]\n' -def csv_line_parameters_write(param: Parameter, slave_address: str) -> str: +def csv_line_parameters_write(param: Parameter, device_name: str, slave_address: str) -> str: # type (r[1-9];w;u),circuit,name,[comment],[QQ],ZZ,PBSB,[ID],field1,part (m/s),datatypes/templates,divider/values,unit,comment datatype = convert_to_ebus_datatype(param.datatype) if not (values := param.values): values = multiplier_to_divider(param.multiplier) - return f'w,{param.device_name},{param.name},{param.name},,{slave_address},4080,{param.id:02x},,,{datatype},{values},{param.unit},[min:{param.field_min};max:{param.field_max};step:{param.field_step};default:{param.field_default}]\n' + return f'w,{device_name},{param.name},{param.name},,{slave_address},4080,{param.id:02x},,,{datatype},{values},{param.unit},[min:{param.field_min};max:{param.field_max};step:{param.field_step};default:{param.field_default}]\n' def convert_to_ebus_datatype(datatype: str) -> str: @@ -104,13 +104,13 @@ def csv_from_sensors(sensors: list[Sensor], device_name: str, slave_address = '' return file_str -def csv_from_parameters(parameters: list[Parameter], is_plus: bool, slave_address: str = ''): +def csv_from_parameters(parameters: list[Parameter], device_name: str, is_plus: bool, slave_address: str = ''): file_str = "" for param in parameters: if is_plus or not param.is_plus_only: # Output if device is plus or param does not require plus if not param.is_read_only: - file_str += csv_line_parameters_write(param, slave_address) - file_str += csv_line_parameters_read(param, slave_address) + file_str += csv_line_parameters_write(param, device_name, slave_address) + file_str += csv_line_parameters_read(param, device_name, slave_address) return file_str @@ -137,7 +137,7 @@ def csv_known_device(sensors: list[Sensor], device_name: str, parameters: list[P file_str += ''' ## Configuration parameters ## ''' - file_str += csv_from_parameters(parameters, True, slave_address) + file_str += csv_from_parameters(parameters, device_name, True, slave_address) return file_str @@ -164,14 +164,14 @@ def write_output(dict_devices_sensor: dict[DeviceVersion, list[Sensor]], dict_de text_file.write(csv_from_sensors(sensors, device.device_name)) for device_param, parameters in dict_devices_parameter.items(): - params_all.extend([dump_param(param) for param in parameters]) + params_all.extend([dump_param(param, device_param) for param in parameters]) with open(os.path.join(OUTPUT_DIR, f'{device_param.device_name}.{device_param.version.first_version}.{device_param.version.last_version}.params.basic.csv'), "w", encoding="utf-8") as text_file: text_file.write(CSV_HEADER) - text_file.write(csv_from_parameters(parameters, False)) + text_file.write(csv_from_parameters(parameters, device_param.device_name, False)) with open(os.path.join(OUTPUT_DIR, f'{device_param.device_name}.{device_param.version.first_version}.{device_param.version.last_version}.params.plus.csv'), "w", encoding="utf-8") as text_file: text_file.write(CSV_HEADER) - text_file.write(csv_from_parameters(parameters, True)) + text_file.write(csv_from_parameters(parameters, device_param.device_name, True)) if os.path.exists(KNOWN_DEVICES_EN_DIR): shutil.rmtree(KNOWN_DEVICES_EN_DIR) diff --git a/src/parameter.py b/src/parameter.py index eae3405a..9bfea7a7 100644 --- a/src/parameter.py +++ b/src/parameter.py @@ -39,6 +39,10 @@ def get_device_parameters() -> dict[DeviceParameters, list[Parameter]]: view_no = int(match.group('view_no')) device_type = match.group('device_type') + # We deal with Flair devices having a base class on following lines + if device_name == 'FlairBase': + continue + # Flair units have two different base classes, we manually overwrite the relevant base class values if device_type == 'FlairBaseParameterSet_01': params_basic = params_plus = 57 @@ -76,7 +80,7 @@ def get_device_parameters() -> dict[DeviceParameters, list[Parameter]]: fields = Fields(int(m.group('current')), int(m.group('min')), int(m.group('max')), int(m.group('step')), int(m.group('default'))) datatype = INT16 if m.group('is_signed') == 'true' else UINT16 is_read_only = bool(m.group('is_read_only') == 'true') - param = Parameter(device_name, first_version, last_version, is_plus_only, int(m.group('id')), m.group('name'), value_type_dict_config[m.group('unit')], float(m.group('multiplier')), datatype, is_read_only, fields) + param = Parameter(is_plus_only, int(m.group('id')), m.group('name'), value_type_dict_config[m.group('unit')], float(m.group('multiplier')), datatype, is_read_only, fields) params.append(param) device_parameters[device] = params