From 4586ead6d9d136dd11a54c25bd90d80ab7bca277 Mon Sep 17 00:00:00 2001 From: Peyton-McKee Date: Thu, 11 Jan 2024 17:44:47 -0500 Subject: [PATCH] #20 Seperate Yaml Files --- oxy/RustSynth.py | 4 +- oxy/YAMLParser.py | 2 +- oxy/typedpoc.py | 10 ++++- oxy/{mapping.yaml => yaml/bms.yaml} | 70 ----------------------------- oxy/yaml/mpu.yaml | 51 +++++++++++++++++++++ oxy/yaml/wheel.yaml | 14 ++++++ 6 files changed, 77 insertions(+), 74 deletions(-) rename oxy/{mapping.yaml => yaml/bms.yaml} (79%) create mode 100644 oxy/yaml/mpu.yaml create mode 100644 oxy/yaml/wheel.yaml diff --git a/oxy/RustSynth.py b/oxy/RustSynth.py index 6e40ac6..2d3c491 100644 --- a/oxy/RustSynth.py +++ b/oxy/RustSynth.py @@ -44,7 +44,7 @@ class RustSynth: } """ - def parse_messages(self, msgs: Messages) -> Result: + def parse_messages(self, msgs: [CANMsg]) -> Result: result = Result("", "") result.decode_data += self.ignore_clippy result.decode_data += self.decode_data_import @@ -54,7 +54,7 @@ def parse_messages(self, msgs: Messages) -> Result: result.master_mapping += self.message_info result.master_mapping += self.master_mapping_signature - for msg in msgs.msgs: + for msg in msgs: result.decode_data += self.synthesize(msg) + "\n" result.master_mapping += self.map_msg_to_decoder(msg) diff --git a/oxy/YAMLParser.py b/oxy/YAMLParser.py index af54cf4..8805bb4 100644 --- a/oxy/YAMLParser.py +++ b/oxy/YAMLParser.py @@ -21,5 +21,5 @@ def __init__(self): self.yaml.register_class(decoding) - def parse(self, file: Any) -> CANMsg: + def parse(self, file: Any) -> Messages: return self.yaml.load(file) diff --git a/oxy/typedpoc.py b/oxy/typedpoc.py index a7595e7..3aa2ba8 100644 --- a/oxy/typedpoc.py +++ b/oxy/typedpoc.py @@ -4,7 +4,15 @@ decode_data = open("../src/decode_data.rs", "w") master_mapping = open("../src/master_mapping.rs", "w") -result = RustSynth().parse_messages(YAMLParser().parse(open("mapping.yaml", "r"))) +bms_messages = YAMLParser().parse(open("yaml/bms.yaml", "r")) +mpu_messages = YAMLParser().parse(open("yaml/mpu.yaml", "r")) +wheel_messages = YAMLParser().parse(open("yaml/wheel.yaml", "r")) + + +bms_messages.msgs.extend(mpu_messages.msgs) +bms_messages.msgs.extend(wheel_messages.msgs) + +result = RustSynth().parse_messages(bms_messages.msgs) decode_data.write(result.decode_data) decode_data.close() diff --git a/oxy/mapping.yaml b/oxy/yaml/bms.yaml similarity index 79% rename from oxy/mapping.yaml rename to oxy/yaml/bms.yaml index 9edb3d6..87ced71 100644 --- a/oxy/mapping.yaml +++ b/oxy/yaml/bms.yaml @@ -241,73 +241,3 @@ msgs: decodings: - !TwosComplement bits: 8 - -# MPU BROADCAST -- !CANMsg - id: "0x500" - desc: "NERduino Acceleromter" - fields: - - !CANField - name: "MPU/Accel/X" - unit: "g" - size: 2 - decodings: - - !BigEndian - bits: 8 - format: "acceleration" - - !CANField - name: "MPU/Accel/Y" - unit: "g" - size: 2 - decodings: - - !BigEndian - bits: 8 - format: "acceleration" - - !CANField - name: "MPU/Accel/Z" - unit: "g" - size: 2 - decodings: - - !BigEndian - bits: 8 - format: "acceleration" - -- !CANMsg - id: "0x501" - desc: "MPU Status" - fields: - - !CANField - name: "MPU/State/Mode" - unit: "" - size: 1 - - !CANField - name: "MPU/State/Torque_Limit_Percentage" - unit: "" - size: 1 - - !CANField - name: "MPU/State/Regen_Strength" - unit: "" - size: 1 - - !CANField - name: "MPU/State/Traction_Control" - unit: "" - size: 1 - - -#STEERINGWHEEL -- !CANMsg - id: "0x680" - desc: "Wheel State" - fields: - - !CANField - name: "WHEEL/Buttons/1" - unit: "" - size: 1 - - !CANField - name: "WHEEL/Buttons/2" - unit: "" - size: 1 - - - - diff --git a/oxy/yaml/mpu.yaml b/oxy/yaml/mpu.yaml new file mode 100644 index 0000000..e3ff76e --- /dev/null +++ b/oxy/yaml/mpu.yaml @@ -0,0 +1,51 @@ +!Messages +msgs: +- !CANMsg + id: "0x500" + desc: "NERduino Acceleromter" + fields: + - !CANField + name: "MPU/Accel/X" + unit: "g" + size: 2 + decodings: + - !BigEndian + bits: 8 + format: "acceleration" + - !CANField + name: "MPU/Accel/Y" + unit: "g" + size: 2 + decodings: + - !BigEndian + bits: 8 + format: "acceleration" + - !CANField + name: "MPU/Accel/Z" + unit: "g" + size: 2 + decodings: + - !BigEndian + bits: 8 + format: "acceleration" + +- !CANMsg + id: "0x501" + desc: "MPU Status" + fields: + - !CANField + name: "MPU/State/Mode" + unit: "" + size: 1 + - !CANField + name: "MPU/State/Torque_Limit_Percentage" + unit: "" + size: 1 + - !CANField + name: "MPU/State/Regen_Strength" + unit: "" + size: 1 + - !CANField + name: "MPU/State/Traction_Control" + unit: "" + size: 1 \ No newline at end of file diff --git a/oxy/yaml/wheel.yaml b/oxy/yaml/wheel.yaml new file mode 100644 index 0000000..3f92646 --- /dev/null +++ b/oxy/yaml/wheel.yaml @@ -0,0 +1,14 @@ +!Messages +msgs: +- !CANMsg + id: "0x680" + desc: "Wheel State" + fields: + - !CANField + name: "WHEEL/Buttons/1" + unit: "" + size: 1 + - !CANField + name: "WHEEL/Buttons/2" + unit: "" + size: 1 \ No newline at end of file