Restructure data objects, BREAKING backwards compatibility!

This was necessary as some IDs were used that are reserved in spec v0.4.

The also includes some additions to the Python parser script.
This commit is contained in:
Martin Jäger
2021-08-29 16:53:05 +02:00
parent ea53bc7628
commit a584bf8a7f
6 changed files with 808 additions and 782 deletions
+45 -33
View File
@@ -1,38 +1,43 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Parser to create JSON file containing data object metadata
#
# TODO
# - Parse nesting in .pub/serial/Enable properly (needs to take parent IDs into account)
# - Also add metadata to groups (using "self" key)
import json
output_path = "info.json"
json_str = ""
main_obj = {}
temp_obj = {}
current_key = ""
name = ""
beginning_line = 0
save_lines = False
save_name = False
output_path = "cc-05.json" # version has to match DATA_OBJECTS_VERSION
def append_stuff(temp_obj):
if current_key != "":
main_obj[current_key] = temp_obj.copy()
temp_obj.clear()
data_objects = {}
id_macros = {}
with open("src/data_objects.cpp", 'r') as fd:
# get IDs which are defined as macros
with open("src/data_objects.h", 'r') as fd:
for (num, line) in enumerate(fd, 1):
if line =="\n":
if "#define ID_" in line:
id_macros[line.split()[1]] = int(line.split()[2], base=16)
continue
if "TS_NODE_PATH" in line:
if current_key != "":
append_stuff(temp_obj)
current_key = line.strip().split(",")[1].strip(' "')
# get actual metadata from data_objects file
with open("src/data_objects.cpp", 'r') as fd:
json_str = ""
group_name = ""
save_lines = False
save_name = False
beginning_line = 0
for (num, line) in enumerate(fd, 1):
if "TS_GROUP" in line:
group_name = line.strip().split(",")[1].strip(' "')
data_objects[group_name] = {}
continue
if (line.strip(" \n") == "/*{"):
save_lines = True
beginning_line = num
json_str +="{"
json_str += "{"
continue
elif (line.strip(" \n") == "}*/"):
json_str += "}"
@@ -46,7 +51,15 @@ with open("src/data_objects.cpp", 'r') as fd:
if save_name:
try:
name = line.strip().split(",")[1].strip(' "')
temp_obj[name] = json.loads(json_str)
data_objects[group_name][name] = {}
obj_id = line.split("(")[1].split(",")[0]
try:
data_objects[group_name][name]["id"] = int(obj_id, base=16)
data_objects[group_name][name]["idx"] = str(obj_id)
except ValueError:
data_objects[group_name][name]["id"] = id_macros[obj_id]
data_objects[group_name][name]["idx"] = hex(id_macros[obj_id])
data_objects[group_name][name].update(json.loads(json_str))
except Exception as e:
print("Error while parsing block between lines {} and {}".format(beginning_line, num))
print(e)
@@ -54,19 +67,18 @@ with open("src/data_objects.cpp", 'r') as fd:
save_name = False
json_str = ""
append_stuff(temp_obj)
# add missing fields
for category in main_obj:
for node in main_obj[category]:
if not 'unit' in main_obj[category][node]:
main_obj[category][node]['unit'] = None
if not 'min' in main_obj[category][node]:
main_obj[category][node]['min'] = None
if not 'max' in main_obj[category][node]:
main_obj[category][node]['max'] = None
for category in data_objects:
for item in data_objects[category]:
if not 'unit' in data_objects[category][item]:
data_objects[category][item]['unit'] = None
if not 'min' in data_objects[category][item]:
data_objects[category][item]['min'] = None
if not 'max' in data_objects[category][item]:
data_objects[category][item]['max'] = None
# save result
with open(output_path, "w", encoding='utf8') as filename:
json.dump(main_obj, filename, indent=4, ensure_ascii=False)
json.dump(data_objects, filename, indent=4, ensure_ascii=False)
print("Saved file under: " + output_path)
print("Saved JSON output as: " + output_path)
+2
View File
@@ -19,5 +19,7 @@
#define BOARD_HAS_PWM_PORT DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), pwm_switch))
#define BOARD_HAS_LOAD_OUTPUT DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), load))
#define BOARD_HAS_USB_OUTPUT DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), usb_pwr))
#define BOARD_HAS_TEMP_FETS DT_NODE_EXISTS(DT_CHILD(DT_PATH(adc_inputs), temp_fets))
#define BOARD_HAS_TEMP_BAT DT_NODE_EXISTS(DT_CHILD(DT_PATH(adc_inputs), temp_bat))
#endif /* BOARD_H_ */
+2 -3
View File
@@ -246,7 +246,7 @@ void daq_update()
load.power = load.bus->voltage * load.current;
#endif
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(adc_inputs), temp_bat))
#if BOARD_HAS_TEMP_BAT
// battery temperature calculation
float bat_temp = ntc_temp(ADC_POS(temp_bat), vref, ADC_GAIN(temp_bat));
@@ -262,8 +262,7 @@ void daq_update()
}
#endif
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(adc_inputs), temp_fets))
// MOSFET temperature calculation
#if BOARD_HAS_TEMP_FETS
dcdc.temp_mosfets = ntc_temp(ADC_POS(temp_fets), vref, ADC_GAIN(temp_fets));
#endif
+753 -743
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -27,9 +27,9 @@
#define ID_CONF 0x06 // configurable settings
#define ID_CAL 0x07 // calibration
#define ID_REPORT 0x0A // reports
#define ID_DFU 0x0D // device firmware upgrade
#define ID_RPC 0x0E // remote procedure calls
#define ID_PUB 0x0F // publication setup
#define ID_DFU 0x0F // device firmware upgrade
#define ID_PUB 0x100 // publication setup
#define ID_CTRL 0x8000 // control functions
/*
@@ -46,7 +46,7 @@
* Increment the version number each time any data object IDs stored in NVM are changed. Otherwise
* data might get corrupted.
*/
#define DATA_OBJECTS_VERSION 4
#define DATA_OBJECTS_VERSION 05
extern bool pub_serial_enable;
extern bool pub_can_enable;
+3
View File
@@ -108,3 +108,6 @@ typedef uint32_t gpio_flags_t;
* where the value is defined to 1, and 0 if not:
*/
#define Z_IS_ENABLED3(ignore_this, val, ...) val
#define Z_STRINGIFY(x) #x
#define STRINGIFY(s) Z_STRINGIFY(s)