Fw-136-Code-generation-for-data-packets#479
Closed
Cantonplas wants to merge 8 commits intodevelopmentfrom
Closed
Conversation
Member
|
This should be in the template project, not the ST-LIB |
jmaralo
requested changes
Dec 28, 2024
| StackPacket* lcu_data; | ||
|
|
||
|
|
||
| DataPacket(uint16_t idpacket316,uint32_t current_control_frequency,uint32_t levitation_control_frequency,float32 lcu_coil_current_ref_1,float32 lcu_coil_current_ref_2,float32 lcu_coil_current_ref_3,float32 lcu_coil_current_ref_4,float32 lcu_coil_current_ref_5,float32 lcu_coil_current_ref_6,float32 lcu_coil_current_ref_7,float32 lcu_coil_current_ref_8,float32 lcu_coil_current_ref_9,float32 lcu_coil_current_ref_10,float32 pos_y,float32 pos_y_d,float32 pos_y_i,float32 pos_z,float32 pos_z_d,float32 pos_z_i,float32 pos_rot_x,float32 pos_rot_x_d,float32 pos_rot_x_i,float32 pos_rot_y,float32 pos_rot_y_d,float32 pos_rot_y_i,float32 pos_rot_z,float32 pos_rot_z_d,float32 pos_rot_z_i,uint16_t idpacket315,general_state general_state,slave_state slave_state,float32 lcu_coil_temp_1,float32 lcu_coil_temp_2,float32 lcu_coil_temp_3,float32 lcu_coil_temp_4,float32 lcu_coil_temp_5,float32 lcu_coil_temp_6,float32 lcu_coil_temp_7,float32 lcu_coil_temp_8,float32 lcu_coil_temp_9,float32 lcu_coil_temp_10,float32 lcu_driver_temp_1,float32 lcu_driver_temp_2,float32 lcu_driver_temp_3,float32 lcu_driver_temp_4,float32 lcu_driver_temp_5,float32 lcu_driver_temp_6,float32 lcu_driver_temp_7,float32 lcu_driver_temp_8,float32 lcu_driver_temp_9,float32 lcu_driver_temp_10,float32 lcu_coil_current_1,float32 lcu_coil_current_2,float32 lcu_coil_current_3,float32 lcu_coil_current_4,float32 lcu_coil_current_5,float32 lcu_coil_current_6,float32 lcu_coil_current_7,float32 lcu_coil_current_8,float32 lcu_coil_current_9,float32 lcu_coil_current_10,float32 lcu_vbat_1,float32 lcu_vbat_2,float32 lcu_vbat_3,float32 lcu_vbat_4,float32 lcu_vbat_5,float32 lcu_vbat_6,float32 lcu_vbat_7,float32 lcu_vbat_8,float32 lcu_vbat_9,float32 lcu_vbat_10,float32 lcu_airgap_1,float32 lcu_airgap_2,float32 lcu_airgap_3,float32 lcu_airgap_4,float32 lcu_airgap_5,float32 lcu_airgap_6,float32 lcu_airgap_7,float32 lcu_airgap_8) |
Member
There was a problem hiding this comment.
the constructor should take references, like uint16_t &idpacket316, uint32_t ¤t_control_frequency, and so on, otherwise it wont work as expected
Inc/Packet_generation/Generator.py
Outdated
Comment on lines
8
to
91
| class BoardDescription: | ||
| def __init__(self,name:str,board:dict): | ||
| self.name = name | ||
| self.id = board["board_id"] | ||
| self.ip = board["board_ip"] | ||
| self.size =0 | ||
| i = 0 | ||
| self.packets = {} | ||
| for packets in board["packets"]: | ||
| packets_name = re.split(r'_|\.', packets)[0] | ||
| self.packets[packets_name] = [] | ||
| measurement = self._MeasurementFileSearch(packets,board["measurements"]) | ||
| with open("Inc/Packet_generation/JSON_ADE/boards/" + name+"/" + board["packets"][i]) as f: | ||
| p= json.load(f) | ||
| with open("Inc/Packet_generation/JSON_ADE/boards/" + name + "/" + measurement) as f: | ||
| m = json.load(f) | ||
| i += 1 | ||
| for packet in p["packets"]: | ||
| self.packets[packets_name].append(PacketDescription(packet,m)) | ||
| self.size = self.size +1 | ||
| @staticmethod | ||
| def _MeasurementFileSearch(packet:str,measurements:dict): | ||
| packet_name = packet.split('_')[0] | ||
| for measurement in measurements: | ||
| measurement_name = measurement.split('_')[0] | ||
| if packet_name[0] == measurement_name[0]: | ||
| return measurement | ||
| else: | ||
| return measurements[0] | ||
| class PacketDescription: | ||
| def __init__(self, packet:dict,measurements:dict): | ||
| self.id =packet["id"] | ||
| self.name = (packet["name"].replace(" ", "_")) | ||
| self.type = packet["type"] | ||
| self.variables = [] | ||
| self.measurements = [] | ||
| i=0 | ||
| for variable in packet["variables"]: | ||
| self.variables.append(variable["name"]) | ||
| self.measurements.append(MeasurmentsDescription(measurements,variable["name"])) | ||
|
|
||
|
|
||
| class MeasurmentsDescription: | ||
| def __init__(self,measurements:dict, variable:str): | ||
| self.id = variable | ||
| measurement = self._MeasurementSearch(measurements,variable) | ||
| if measurement is None: | ||
| raise Exception("Measurement not found") | ||
| else: | ||
| self.name = measurement["name"] | ||
| self.type = self._unsigned_int_correction(measurement["type"]) | ||
| if self.type == "enum": | ||
| self.enum = self._create_enum(measurement) | ||
| self.type = measurement["id"] | ||
|
|
||
| @staticmethod | ||
| def _MeasurementSearch(measurements:dict, variable:str): | ||
| for measurment in measurements["measurements"]: | ||
| if measurment["id"] == variable: | ||
| return measurment | ||
| return None | ||
|
|
||
| @staticmethod | ||
| def _create_enum(measurement: dict): | ||
| if "enumValues" not in measurement: | ||
| raise ValueError("Measurement does not contain 'enumValues'") | ||
|
|
||
| enum = enum_template.replace("%name%", measurement["id"]) | ||
| values = "" | ||
| for value in measurement["enumValues"]: | ||
| values += value + ",\n" | ||
| if values.endswith(",\n"): | ||
| values = values[:-2] | ||
| values += "\n" | ||
| enum = enum.replace("%values%", values.strip()) | ||
| return enum | ||
|
|
||
| @staticmethod | ||
| def _unsigned_int_correction(type:str): | ||
| aux_type = type[:4] | ||
| if aux_type == "uint": | ||
| type += "_t" | ||
| return type | ||
|
|
Member
There was a problem hiding this comment.
since we are going to reuse this logic in multiple places, it would be great if you could split this file into two, one which parses the documents and another one that fills the template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python script that creates the .hpp for the data packets based on the .json files from the JSON.ADE directory. It also has description classes to make it more easy for more code generation based on this script. Works quite good, it has an example attached that has been autogenerated.