Skip to content

Commit

Permalink
Removed empty and useless Flair base files
Browse files Browse the repository at this point in the history
  • Loading branch information
pvyleta committed Mar 24, 2024
1 parent 2ed9361 commit cdf7900
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 35 deletions.
1 change: 0 additions & 1 deletion ebusd-configuration/FlairBase.10101.10110.params.basic.csv

This file was deleted.

1 change: 0 additions & 1 deletion ebusd-configuration/FlairBase.10101.10110.params.plus.csv

This file was deleted.

1 change: 0 additions & 1 deletion ebusd-configuration/FlairBase.10111.99999.params.basic.csv

This file was deleted.

1 change: 0 additions & 1 deletion ebusd-configuration/FlairBase.10111.99999.params.plus.csv

This file was deleted.

34 changes: 24 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 1 addition & 4 deletions src/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions src/out.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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


Expand All @@ -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


Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cdf7900

Please sign in to comment.