From 170188d415dc0b774556dcec5ace10e59a4c8221 Mon Sep 17 00:00:00 2001 From: tszwingli <43227796+tszwinglitw@users.noreply.github.com> Date: Sun, 6 Oct 2024 15:28:15 -0400 Subject: [PATCH 1/4] added sim code generation --- cangen/CANField.py | 4 + cangen/CANMsg.py | 1 + cangen/Result.py | 4 +- cangen/RustSynthFromJSON.py | 75 ++- cangen/can-messages/bms.json | 1098 ++++++++++++++++------------------ 5 files changed, 602 insertions(+), 580 deletions(-) diff --git a/cangen/CANField.py b/cangen/CANField.py index 03c867c..e823502 100644 --- a/cangen/CANField.py +++ b/cangen/CANField.py @@ -43,3 +43,7 @@ class NetField: points: list[CANPoint] send: bool = True topic_append: bool = False + sim_min: Optional[float] = -1.0 + sim_max: Optional[float] = -1.0 + sim_inc_min: Optional[float] = -1.0 + sim_inc_max: Optional[float] = -1.0 diff --git a/cangen/CANMsg.py b/cangen/CANMsg.py index 6d2a1bd..c81616a 100644 --- a/cangen/CANMsg.py +++ b/cangen/CANMsg.py @@ -11,6 +11,7 @@ class CANMsg: id: str # Hex value of CAN ID, i.e. `0x88` desc: str # Brief name of CAN message, used for generating function names fields: list[NetField] # List of CAN fields in the message + sim_freq: Optional[int] # Frequency to simulate this message at, in ms @dataclass class EncodableCANMsg(CANMsg): diff --git a/cangen/Result.py b/cangen/Result.py index c1c01f0..a42d7cc 100644 --- a/cangen/Result.py +++ b/cangen/Result.py @@ -10,10 +10,12 @@ class Result: encode_data: str encode_master_mapping: str format_data: str + simulate_data: str - def __init__(self, decode_data: str, master_mapping: str, encode_data: str, encode_master_mapping: str, format_data: str): + def __init__(self, decode_data: str, master_mapping: str, encode_data: str, encode_master_mapping: str, format_data: str, simulate_data: str = ""): self.decode_data = decode_data self.decode_master_mapping = master_mapping self.encode_data = encode_data self.encode_master_mapping = encode_master_mapping self.format_data = format_data + self.simulate_data = simulate_data diff --git a/cangen/RustSynthFromJSON.py b/cangen/RustSynthFromJSON.py index 27ffb45..1d2951d 100644 --- a/cangen/RustSynthFromJSON.py +++ b/cangen/RustSynthFromJSON.py @@ -1,6 +1,8 @@ from cangen.Result import Result from typing import List, Dict, Optional import math +import re +import logging class RustSynthFromJSON: """ @@ -13,7 +15,8 @@ def parse_messages(self, msgs: List[Dict]) -> Result: returns a Result object that contains the synthesized Rust code for the decode_data.rs and master_mapping.rs files """ - result = Result("", "", "", "", "") + + result = Result("", "", "", "", "", "") result.decode_data += RustSnippets.ignore_clippy result.decode_data += RustSnippets.decode_data_import result.decode_data += RustSnippets.decode_mock @@ -49,6 +52,7 @@ def parse_messages(self, msgs: List[Dict]) -> Result: result.format_data = RustSnippets.format_impl + result.simulate_data = self.create_simulate_data(msgs) return result @@ -343,6 +347,75 @@ def encode_data_inst(self, msg: Dict) -> str: is_ext: {str(msg['is_ext'] if 'is_ext' in msg else 'false').lower()}, }}""" + def create_simulate_data(self, msgs: List[Dict]) -> str: + def sanitize_fnname(name): + name = re.sub(r'\W|^(?=\d)', '_', name) + name = name.lower() + return name + + sim_funcbody = "" + # process each CAN message + for msg in msgs: + if ('sim_freq' in msg.keys()): + id = msg['id'] + desc = msg['desc'] + sim_freq = msg['sim_freq'] + net_fields = msg['fields'] + for netfield in net_fields: + # check if sim_min, sim_max, sim_inc_max, sim_inc_min, points are present + if ("sim_min" not in netfield.keys() or + "sim_max" not in netfield.keys() or + "sim_inc_max" not in netfield.keys() or + "sim_inc_min" not in netfield.keys()): + continue + + cmp_name = netfield['name'] + func_name = sanitize_fnname(cmp_name) + unit = netfield['unit'] + sim_min = netfield['sim_min'] + sim_max = netfield['sim_max'] + sim_inc_max = netfield['sim_inc_max'] + sim_inc_min = netfield['sim_inc_min'] + n_canpoints = len(netfield['points']) + format = "" + if 'format' in netfield: + format = netfield['format'] + signed = False + if 'signed' in netfield: + signed = netfield['signed'] + + new_component = f""" + let {func_name} = SimulatedComponents::new( + "{cmp_name}".to_string(), + "{unit}".to_string(), + {float(sim_min)}, + {float(sim_max)}, + {float(sim_inc_min)}, + {float(sim_inc_max)}, + {float(sim_freq)}, + {n_canpoints}, + "{format}".to_string(), + "{id}".to_string(), + {str(signed).lower()}, + ); + simulatable_messages.push({func_name}); + """ + sim_funcbody += new_component + + + sim_fnblock = f""" + #![allow(clippy::all)] + use crate::simulatable_message::SimulatedComponents; + pub fn create_simulated_components() -> Vec {{ + let mut simulatable_messages: Vec = Vec::new(); + + {sim_funcbody} + + simulatable_messages + }} + """ + return sim_fnblock + class RustSnippets: diff --git a/cangen/can-messages/bms.json b/cangen/can-messages/bms.json index 62a7d97..643f3a8 100644 --- a/cangen/can-messages/bms.json +++ b/cangen/can-messages/bms.json @@ -1,587 +1,529 @@ [ { - "id": "0x80", - "desc": "accumulator status", - "fields": [ - { - "name": "BMS/Pack/Voltage", - "unit": "V", - "points": [ - { - "size": 16, - "format": "divide10" - } - ] - } - , - { - "name": "BMS/Pack/Current", - "unit": "A", - "send": "false", - "points": [ - { - "size": 16 - } - ] - } - , - { - "name": "BMS/Pack/Amp-hours", - "unit": "Ah", - "points": [ - { - "size": 16 - } - ] - } - , - { - "name": "BMS/Pack/SOC", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/Pack/Health", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - ] - } - , - { - "id": "0x81", - "desc": "BMS Status", - "fields": [ - { - "name": "BMS/Status/State", - "unit": "", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/Status/Faults", - "unit": "", - "points": [ - { - "size": 32 - } - ] - } - , - { - "name": "BMS/Status/Temp_Average", - "unit": "C", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/Status/Temp_Internal", - "unit": "C", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/Status/Balancing", - "unit": "", - "points": [ - { - "size": 8 - } - ] - } - ] - } - , - { - "id": "0x82", - "desc": "Shutdown Control", - "fields": [ - { - "name": "BMS/Shutdown/MPE", - "unit": "", - "points": [ - { - "size": 8 - } - ] - } - ] - } - , - { - "id": "0x83", - "desc": "Cell Data", - "fields": [ - { - "name": "BMS/Cells/Volts_High_Value", - "unit": "V", - "points": [ - { - "size": 16, - "format": "divide10000" - } - ] - } - , - { - "name": "BMS/Cells/Volts_High_Chip", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Volts_High_Cell", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Volts_Low_Value", - "unit": "V", - "points": [ - { - "size": 16, - "format": "divide10000" - } - ] - } - , - { - "name": "BMS/Cells/Volts_Low_Chip", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Volts_Low_Cell", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Volts_Avg_Value", - "unit": "V", - "points": [ - { - "size": 16, - "format": "divide10000" - } - ] - } - ] - } - , - { - "id": "0x84", - "desc": "Cell Temperatures", - "fields": [ - { - "name": "BMS/Cells/Temp_High_Value", - "unit": "C", - "points": [ - { - "size": 16 - } - ] - } - , - { - "name": "BMS/Cells/Temp_High_Cell", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Temp_High_Chip", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Temp_Low_Value", - "unit": "C", - "points": [ - { - "size": 16 - } - ] - } - , - { - "name": "BMS/Cells/Temp_Low_Cell", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Temp_Low_Chip", - "unit": "", - "points": [ - { - "size": 4 - } - ] - } - , - { - "name": "BMS/Cells/Temp_Avg_Value", - "unit": "C", - "points": [ - { - "size": 16 - } - ] - } - ] - } - , + "id": "0x80", + "desc": "accumulator status", + "sim_freq": 700, + "fields": [ + { + "name": "BMS/Pack/Voltage", + "unit": "V", + "sim_min": 400, + "sim_max": 505, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 16, + "format": "divide10" + } + ] + }, + { + "name": "BMS/Pack/Current", + "unit": "A", + "sim_min": 0, + "sim_max": 50, + "sim_inc_min": 0, + "sim_inc_max": 3, + "send": "false", + "points": [ + { + "size": 16 + } + ] + }, + { + "name": "BMS/Pack/Amp-hours", + "unit": "Ah", + "sim_min": 0, + "sim_max": 100, + "sim_inc_min": 0, + "sim_inc_max": 0.1, + "points": [ + { + "size": 16 + } + ] + }, + { + "name": "BMS/Pack/SOC", + "unit": "%", + "sim_min": 0, + "sim_max": 100, + "sim_inc_min": 0.01, + "sim_inc_max": 0.1, + "points": [ + { + "size": 8 + } + ] + }, + { + "name": "BMS/Pack/Health", + "unit": "%", + "sim_min": 0, + "sim_max": 100, + "sim_inc_min": 0, + "sim_inc_max": 0.1, + "points": [ + { + "size": 8 + } + ] + } + ] + }, { - "id": "0x85", - "desc": "Segment Temperatures", - "fields": [ - { - "name": "BMS/Segment_Temp/1", - "unit": "C", - "points": [ - { - "size": 8, - "signed": true - } - ] - } - , - { - "name": "BMS/Segment_Temp/2", - "unit": "C", - "points": [ - { - "size": 8, - "signed": true - } - ] - } - , - { - "name": "BMS/Segment_Temp/3", - "unit": "C", - "points": [ - { - "size": 8, - "signed": true - } - ] - } - , - { - "name": "BMS/Segment_Temp/4", - "unit": "C", - "points": [ - { - "size": 8, - "signed": true - } - ] - } - , - { - "name": "BMS/Segment_Temp/5", - "unit": "C", - "points": [ - { - "size": 8, - "signed": true - } - ] - } - , - { - "name": "BMS/Segment_Temp/6", - "unit": "C", - "points": [ - { - "size": 8, - "signed": true - } - ] - } - ] - } - , + "id": "0x81", + "desc": "BMS Status", + "sim_freq": 700, + "fields": [ + { + "name": "BMS/Status/State", + "unit": "", + "sim_min": 0, + "sim_max": 4, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 8 + } + ] + }, + { + "name": "BMS/Status/Faults", + "unit": "", + "sim_min": 0, + "sim_max": 131072, + "sim_inc_min": 4, + "sim_inc_max": 16, + "points": [ + { + "size": 32 + } + ] + }, + { + "name": "BMS/Status/Temp_Average", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.5, + "points": [ + { + "size": 8 + } + ] + }, + { + "name": "BMS/Status/Temp_Internal", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 8 + } + ] + }, + { + "name": "BMS/Status/Balancing", + "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 0, + "sim_inc_max": 1, + "points": [ + { + "size": 8 + } + ] + } + ] + }, { - "id": "0x86", - "desc": "Current Limits", - "fields": [ - { - "name": "BMS/Pack/DCL", - "unit": "", - "points": [ - { - "size": 16 - } - ] - } - , - { - "name": "BMS/Pack/CCL", - "unit": "", - "points": [ - { - "size": 16, - "signed": true - } - ] - } - , - { - "name": "BMS/Pack/Current", - "unit": "", - "points": [ - { - "size": 16, - "signed": true - } - ] - } - ] - } - , + "id": "0x83", + "desc": "Cell Data", + "sim_freq": 700, + "fields": [ + { + "name": "BMS/Cells/Volts_High_Value", + "unit": "V", + "sim_min": 2.5, + "sim_max": 4.25, + "sim_inc_min": 0.001, + "sim_inc_max": 0.1, + "points": [ + { + "size": 16, + "format": "divide10000" + } + ] + }, + { + "name": "BMS/Cells/Volts_High_Chip", + "unit": "", + "sim_min": 1, + "sim_max": 12, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Volts_High_Cell", + "unit": "", + "sim_min": 1, + "sim_max": 120, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Volts_Low_Value", + "unit": "V", + "sim_min": 2.5, + "sim_max": 4.25, + "sim_inc_min": 0.001, + "sim_inc_max": 0.1, + "points": [ + { + "size": 16, + "format": "divide10000" + } + ] + }, + { + "name": "BMS/Cells/Volts_Low_Chip", + "unit": "", + "sim_min": 1, + "sim_max": 12, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Volts_Low_Cell", + "unit": "", + "sim_min": 1, + "sim_max": 120, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Volts_Avg_Value", + "unit": "V", + "sim_min": 2.5, + "sim_max": 4.25, + "sim_inc_min": 0.001, + "sim_inc_max": 0.1, + "points": [ + { + "size": 16, + "format": "divide10000" + } + ] + } + ] + }, { - "id": "0x87", - "desc": "Cell Voltage", - "fields": [ - { - "name": "BMS/PerCell/CellVoltage", - "unit": "", - "topic_append": "true", - "points": [ - { - "size": 8 - } - , - { - "size": 16 - } - ] - } - , - { - "name": "BMS/PerCell/InstantVoltage", - "unit": "", - "points": [ - { - "size": 16 - } - ] - } - , - { - "name": "BMS/PerCell/InternalResistance", - "unit": "", - "points": [ - { - "size": 16 - } - ] - } - ] - } - , + "id": "0x84", + "desc": "Cell Temperatures", + "sim_freq": 700, + "fields": [ + { + "name": "BMS/Cells/Temp_High_Value", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 16 + } + ] + }, + { + "name": "BMS/Cells/Temp_High_Cell", + "unit": "", + "sim_min": 1, + "sim_max": 120, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Temp_High_Chip", + "unit": "", + "sim_min": 1, + "sim_max": 12, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Temp_Low_Value", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 16 + } + ] + }, + { + "name": "BMS/Cells/Temp_Low_Cell", + "unit": "", + "sim_min": 1, + "sim_max": 120, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Temp_Low_Chip", + "unit": "", + "sim_min": 1, + "sim_max": 12, + "sim_inc_min": 1, + "sim_inc_max": 1, + "points": [ + { + "size": 4 + } + ] + }, + { + "name": "BMS/Cells/Temp_Avg_Value", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 16 + } + ] + } + ] + }, { - "id": "0x88", - "desc": "BMS Voltage Noise", - "fields": [ - { - "name": "BMS/NoiseVoltage/1", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/NoiseVoltage/2", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/NoiseVoltage/3", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/NoiseVoltage/4", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/NoiseVoltage/5", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/NoiseVoltage/6", - "unit": "%", - "points": [ - { - "size": 8 - } - ] - } - ] - } - , + "id": "0x85", + "desc": "Segment Temperatures", + "sim_freq": 700, + "fields": [ + { + "name": "BMS/Segment_Temp/1", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 8, + "signed": true + } + ] + }, + { + "name": "BMS/Segment_Temp/2", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 8, + "signed": true + } + ] + }, + { + "name": "BMS/Segment_Temp/3", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 8, + "signed": true + } + ] + }, + { + "name": "BMS/Segment_Temp/4", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 8, + "signed": true + } + ] + }, + { + "name": "BMS/Segment_Temp/5", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 8, + "signed": true + } + ] + }, + { + "name": "BMS/Segment_Temp/6", + "unit": "C", + "sim_min": 10, + "sim_max": 50, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, + "points": [ + { + "size": 8, + "signed": true + } + ] + } + ] + }, { - "id": "0x702", - "desc": "BMS Debug", - "fields": [ - { - "name": "BMS/Debug/Spare0", - "unit": "", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/Debug/Spare1", - "unit": "", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/Debug/Spare2", - "unit": "", - "points": [ - { - "size": 16 - } - ] - } - , - { - "name": "BMS/Debug/Spare3", - "unit": "", - "points": [ - { - "size": 32 - } - ] - } - ] - } - , + "id": "0x86", + "desc": "Current Limits", + "sim_freq": 700, + "fields": [ + { + "name": "BMS/Pack/DCL", + "unit": "", + "sim_min": 20, + "sim_max": 520, + "sim_inc_min": 0.1, + "sim_inc_max": 4, + "points": [ + { + "size": 16 + } + ] + }, + { + "name": "BMS/Pack/CCL", + "unit": "", + "sim_min": 0, + "sim_max": 25, + "sim_inc_min": 0, + "sim_inc_max": 2, + "points": [ + { + "size": 16, + "signed": true + } + ] + }, + { + "name": "BMS/Pack/Current", + "unit": "", + "sim_min": 0, + "sim_max": 100, + "sim_inc_min": 0, + "sim_inc_max": 5, + "points": [ + { + "size": 16, + "signed": true + } + ] + } + ] + }, { - "id": "0x703", - "desc": "BMS Fault Debug", - "fields": [ - { - "name": "BMS/FaultDebug/Status", - "unit": "", - "points": [ - { - "size": 8 - } - ] - } - , - { - "name": "BMS/FaultDebug/PackCurrent", - "unit": "", - "points": [ - { - "size": 16, - "signed": true - } - ] - } - , - { - "name": "BMS/FaultDebug/DCL", - "unit": "", - "points": [ - { - "size": 16, - "signed": true - } - ] - } - ] + "id": "0x702", + "desc": "BMS Debug", + "sim_freq": 700, + "fields": [ + { + "name": "BMS/Debug/Spare0", + "unit": "", + "points": [ + { + "size": 8 + } + ] + }, + { + "name": "BMS/Debug/Spare1", + "unit": "", + "points": [ + { + "size": 8 + } + ] + }, + { + "name": "BMS/Debug/Spare2", + "unit": "", + "points": [ + { + "size": 16 + } + ] + }, + { + "name": "BMS/Debug/Spare3", + "unit": "", + "points": [ + { + "size": 32 + } + ] + } + ] } -] +] \ No newline at end of file From fff29f33ebb5d35b58ae2edaa6e3d045faae1e5c Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Tue, 8 Oct 2024 01:12:09 -0400 Subject: [PATCH 2/4] JSON definitions for most of YAML (still in progress) --- cangen/can-messages/calypso_cmd.json | 27 ++++ cangen/can-messages/charger.json | 42 ++++++ cangen/can-messages/dti.json | 209 +++++++++++++++++++++++++++ cangen/can-messages/mpu.json | 156 ++++++++++++++++++++ cangen/can-messages/msb.json | 156 ++++++++++++++++++++ cangen/can-messages/wheel.json | 9 ++ 6 files changed, 599 insertions(+) diff --git a/cangen/can-messages/calypso_cmd.json b/cangen/can-messages/calypso_cmd.json index 6ba5e9a..d21bea8 100644 --- a/cangen/can-messages/calypso_cmd.json +++ b/cangen/can-messages/calypso_cmd.json @@ -3,10 +3,15 @@ "id": "0x450", "desc": "Example Enc Msg", "key": "FirstOff", + "sim_freq": 750, "fields": [ { "name": "Calypso/Bidir/State/FirstOff/A", "unit": "Z", + "sim_min": 1, + "sim_max": 100, + "sim_inc_min": 1, + "sim_inc_max": 2, "points": [ { "size": 32, @@ -19,6 +24,10 @@ { "name": "Calypso/Bidir/State/FirstOff/B", "unit": "G", + "sim_min": 1, + "sim_max": 100, + "sim_inc_min": 1, + "sim_inc_max": 2, "points": [ { "size": 8, @@ -31,6 +40,10 @@ { "name": "Calypso/Bidir/State/FirstOff/C", "unit": "G", + "sim_min": 1, + "sim_max": 100, + "sim_inc_min": 1, + "sim_inc_max": 2, "points": [ { "size": 8, @@ -42,6 +55,10 @@ { "name": "Calypso/Bidir/State/FirstOff/D", "unit": "G", + "sim_min": 1, + "sim_max": 100, + "sim_inc_min": 1, + "sim_inc_max": 2, "points": [ { "size": 16, @@ -60,10 +77,15 @@ "desc": "Example Enc Msg Ext", "key": "SecondOff", "is_ext": true, + "sim_freq": 750, "fields": [ { "name": "Calypso/Bidir/State/SecondOff/A", "unit": "GG", + "sim_min": 1, + "sim_max": 100, + "sim_inc_min": 1, + "sim_inc_max": 2, "points": [ { "size": 32, @@ -77,10 +99,15 @@ { "id": "0x7FF", "desc": "Calypso bidir unknown key", + "sim_freq": 750, "fields": [ { "name": "Calypso/Bidir/Unknown", "unit": "pts", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 0, + "sim_inc_max": 1, "points": [ { "size": 8 diff --git a/cangen/can-messages/charger.json b/cangen/can-messages/charger.json index 016148a..070a91c 100644 --- a/cangen/can-messages/charger.json +++ b/cangen/can-messages/charger.json @@ -2,10 +2,15 @@ { "id": "0x1806E5F4", "desc": "BMS Message Send", + "sim_freq": 700, "fields": [ { "name": "BMS/Charging/Voltage", "unit": "V", + "sim_min": 400, + "sim_max": 505, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, "points": [ { "size": 16, @@ -17,6 +22,10 @@ { "name": "BMS/Charging/Current", "unit": "A", + "sim_min": 0, + "sim_max": 12, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 16, @@ -28,6 +37,10 @@ { "name": "BMS/Charging/Control", "unit": "", + "sim_min": 0, + "sim_max": 255, + "sim_inc_min": 255, + "sim_inc_max": 255, "points": [ { "size": 8 @@ -51,10 +64,15 @@ { "id": "0x18FF50E5", "desc": "Charger Box Status", + "sim_freq": 1000, "fields": [ { "name": "Charger/Box/Voltage", "unit": "V", + "sim_min": 400, + "sim_max": 505, + "sim_inc_min": 0.01, + "sim_inc_max": 0.3, "points": [ { "size": 16, @@ -66,6 +84,10 @@ { "name": "Charger/Box/Current", "unit": "A", + "sim_min": 0, + "sim_max": 12, + "sim_inc_min": 0.1, + "sim_inc_max": 1, "points": [ { "size": 16, @@ -78,6 +100,10 @@ { "name": "Charger/Box/F_CommTimeout", "unit": "bool", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -88,6 +114,10 @@ { "name": "Charger/Box/F_WrongBatConnection", "unit": "bool", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -98,6 +128,10 @@ { "name": "Charger/Box/F_VoltageWrong", "unit": "bool", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -108,6 +142,10 @@ { "name": "Charger/Box/F_OverTemp", "unit": "bool", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -118,6 +156,10 @@ { "name": "Charger/Box/F_HardwareFailure", "unit": "bool", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 diff --git a/cangen/can-messages/dti.json b/cangen/can-messages/dti.json index c753692..df47eb7 100644 --- a/cangen/can-messages/dti.json +++ b/cangen/can-messages/dti.json @@ -2,10 +2,15 @@ { "id": "0x416", "desc": "ERPM_Duty_Input_Voltage_Status", + "sim_freq": 25, "fields": [ { "name": "DTI/RPM/ERPM", "unit": "ERPM", + "sim_min": -2147483648, + "sim_max": 2147483648, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 32, @@ -17,6 +22,10 @@ { "name": "DTI/Power/Duty_Cycle", "unit": "%", + "sim_min": -32768, + "sim_max": 32767, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 16, @@ -29,6 +38,10 @@ { "name": "DTI/Power/Input_Voltage", "unit": "V", + "sim_min": 0, + "sim_max": 505, + "sim_inc_min": 0.01, + "sim_inc_max": 10, "points": [ { "size": 16, @@ -42,10 +55,15 @@ { "id": "0x436", "desc": "Currents_Status", + "sim_freq": 25, "fields": [ { "name": "DTI/Power/AC_Current", "unit": "A", + "sim_min": -125, + "sim_max": 250, + "sim_inc_min": 0.01, + "sim_inc_max": 20, "points": [ { "size": 16, @@ -58,6 +76,10 @@ { "name": "DTI/Power/DC_Current", "unit": "A", + "sim_min": -300, + "sim_max": 300, + "sim_inc_min": 2, + "sim_inc_max": 5, "points": [ { "size": 16, @@ -83,10 +105,15 @@ { "id": "0x456", "desc": "Temps_Fault_Code_Status", + "sim_freq": 25, "fields": [ { "name": "DTI/Temps/Controller_Temperature", "unit": "C", + "sim_min": 5, + "sim_max": 80, + "sim_inc_min": 0.05, + "sim_inc_max": 0.5, "points": [ { "size": 16, @@ -99,6 +126,10 @@ { "name": "DTI/Temps/Motor_Temperature", "unit": "C", + "sim_min": 5, + "sim_max": 80, + "sim_inc_min": 0.05, + "sim_inc_max": 0.5, "points": [ { "size": 16, @@ -111,6 +142,10 @@ { "name": "DTI/Fault/Fault_Code", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 @@ -134,10 +169,15 @@ { "id": "0x476", "desc": "MC_FOC_Algorithm", + "sim_freq": 25, "fields": [ { "name": "DTI/FOC/Component_Id", "unit": "A", + "sim_min": -2147483648, + "sim_max": 2147483648, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 32, @@ -150,6 +190,10 @@ { "name": "DTI/FOC/Component_Iq", "unit": "A", + "sim_min": -2147483648, + "sim_max": 2147483648, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 32, @@ -164,10 +208,15 @@ { "id": "0x496", "desc": "MC_General_Data", + "sim_freq": 25, "fields": [ { "name": "DTI/General/Throttle_Signal", "unit": "%", + "sim_min": -100, + "sim_max": 100, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8, @@ -179,6 +228,10 @@ { "name": "DTI/General/Brake_Signal", "unit": "%", + "sim_min": -100, + "sim_max": 100, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8, @@ -190,6 +243,10 @@ { "name": "DTI/General/Digital_Out_4", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -200,6 +257,10 @@ { "name": "DTI/General/Digital_Out_3", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -210,6 +271,10 @@ { "name": "DTI/General/Digital_Out_2", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -220,6 +285,10 @@ { "name": "DTI/General/Digital_Out_1", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -230,6 +299,10 @@ { "name": "DTI/General/Digital_In_4", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -240,6 +313,10 @@ { "name": "DTI/General/Digital_In_3", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -250,6 +327,10 @@ { "name": "DTI/General/Digital_In_2", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -260,6 +341,10 @@ { "name": "DTI/General/Digital_In_1", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -270,6 +355,10 @@ { "name": "DTI/General/Drive_Enable", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 @@ -280,6 +369,10 @@ { "name": "DTI/Limit/Motor_Temp_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -290,6 +383,10 @@ { "name": "DTI/Limit/Motor_Acc_Temp_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -300,6 +397,10 @@ { "name": "DTI/Limit/Input_Voltage_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -310,6 +411,10 @@ { "name": "DTI/Limit/IGBT_Temp_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -320,6 +425,10 @@ { "name": "DTI/Limit/IGBT_Acc_Temp_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -330,6 +439,10 @@ { "name": "DTI/Limit/Drive_Enable_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -340,6 +453,10 @@ { "name": "DTI/Limit/DC_Current_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -350,6 +467,10 @@ { "name": "DTI/Limit/Cap_Temp_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -360,6 +481,10 @@ { "name": "DTI/Limit/Power_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -370,6 +495,10 @@ { "name": "DTI/Limit/RPM_Max_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -380,6 +509,10 @@ { "name": "DTI/Limit/RPM_Min_Limit", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -412,6 +545,10 @@ { "name": "DTI/General/CAN_Map_Version", "unit": "", + "sim_min": 20, + "sim_max": 24, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 @@ -424,10 +561,15 @@ { "id": "0x036", "desc": "AC_Current_Command", + "sim_freq": 25, "fields": [ { "name": "MPU/Commands/AC_Current_Target", "unit": "A", + "sim_min": 0, + "sim_max": 380, + "sim_inc_min": 0.01, + "sim_inc_max": 25, "points": [ { "size": 16, @@ -442,10 +584,15 @@ { "id": "0x056", "desc": "Brake_Current_Command", + "sim_freq": 25, "fields": [ { "name": "MPU/Commands/Brake_Current_Target", "unit": "A", + "sim_min": 0, + "sim_max": 150, + "sim_inc_min": 0.01, + "sim_inc_max": 10, "points": [ { "size": 16, @@ -471,10 +618,15 @@ { "id": "0x076", "desc": "ERPM_Command", + "sim_freq": 25, "fields": [ { "name": "DTI/Commands/ERPM_Target", "unit": "A", + "sim_min": -2147483648, + "sim_max": 2147483648, + "sim_inc_min": 1, + "sim_inc_max": 10, "points": [ { "size": 32, @@ -499,10 +651,15 @@ { "id": "0x096", "desc": "Position_Command", + "sim_freq": 25, "fields": [ { "name": "DTI/Commands/Position_Target", "unit": "degree", + "sim_min": 0, + "sim_max": 360, + "sim_inc_min": 0.05, + "sim_inc_max": 5, "points": [ { "size": 16, @@ -528,10 +685,15 @@ { "id": "0x0B6", "desc": "Relative_Current_Command", + "sim_freq": 25, "fields": [ { "name": "DTI/Commands/Relative_Current_Target", "unit": "A", + "sim_min": -100, + "sim_max": 100, + "sim_inc_min": 0.01, + "sim_inc_max": 5, "points": [ { "size": 16, @@ -557,10 +719,15 @@ { "id": "0x0D6", "desc": "Relative_Brake_Current_Command", + "sim_freq": 25, "fields": [ { "name": "DTI/Commands/Relative_Brake_Current_Target", "unit": "A", + "sim_min": -100, + "sim_max": 100, + "sim_inc_min": 0.01, + "sim_inc_max": 5, "points": [ { "size": 16, @@ -586,10 +753,15 @@ { "id": "0x0F6", "desc": "Digital_Output_Command", + "sim_freq": 25, "fields": [ { "name": "DTI/Commands/Digital_Output_1_Target", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -600,6 +772,10 @@ { "name": "DTI/Commands/Digital_Output_2_Target", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -610,6 +786,10 @@ { "name": "DTI/Commands/Digital_Output_3_Target", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -620,6 +800,10 @@ { "name": "DTI/Commands/Digital_Output_4_Target", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -643,10 +827,15 @@ { "id": "0x116", "desc": "Max_AC_Current_Command", + "sim_freq": 25, "fields": [ { "name": "BMS/Commands/Max_AC_Current_Target", "unit": "A", + "sim_min": 0, + "sim_max": 250, + "sim_inc_min": 0.01, + "sim_inc_max": 25, "points": [ { "size": 16, @@ -672,10 +861,15 @@ { "id": "0x136", "desc": "Max_AC_Brake_Current_Command", + "sim_freq": 25, "fields": [ { "name": "BMS/Commands/Max_AC_Brake_Current_Target", "unit": "A", + "sim_min": -250, + "sim_max": 0, + "sim_inc_min": 0.01, + "sim_inc_max": 25, "points": [ { "size": 16, @@ -701,10 +895,15 @@ { "id": "0x156", "desc": "Max_DC_Current_Command", + "sim_freq": 25, "fields": [ { "name": "BMS/Commands/Max_DC_Current_Target", "unit": "A", + "sim_min": 0, + "sim_max": 505, + "sim_inc_min": 0.05, + "sim_inc_max": 5, "points": [ { "size": 16, @@ -719,10 +918,15 @@ { "id": "0x176", "desc": "Max_DC_Brake_Current_Command", + "sim_freq": 25, "fields": [ { "name": "BMS/Commands/Max_DC_Brake_Current_Target", "unit": "A", + "sim_min": -250, + "sim_max": 0, + "sim_inc_min": 0.01, + "sim_inc_max": 10, "points": [ { "size": 16, @@ -737,10 +941,15 @@ { "id": "0x196", "desc": "Drive_Enable_Command", + "sim_freq": 25, "fields": [ { "name": "MPU/Commands/Drive_Enable_Target", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 diff --git a/cangen/can-messages/mpu.json b/cangen/can-messages/mpu.json index bce1ac8..2863b96 100644 --- a/cangen/can-messages/mpu.json +++ b/cangen/can-messages/mpu.json @@ -2,10 +2,15 @@ { "id": "0x501", "desc": "MPU Status", + "sim_freq": 250, "fields": [ { "name": "MPU/State/Mode", "unit": "", + "sim_min": 0, + "sim_max": 4, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 @@ -16,6 +21,10 @@ { "name": "MPU/State/ModeIndex", "unit": "", + "sim_min": 0, + "sim_max": 6, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 @@ -26,6 +35,10 @@ { "name": "MPU/State/Speed", "unit": "mph", + "sim_min": 0, + "sim_max": 88, + "sim_inc_min": 0, + "sim_inc_max": 2, "points": [ { "size": 8, @@ -37,6 +50,10 @@ { "name": "MPU/State/TSMS", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 @@ -49,10 +66,15 @@ { "id": "0x500", "desc": "MPU Sense Acceleromter", + "sim_freq": 250, "fields": [ { "name": "MPU/Sense/Accel", "unit": "g", + "sim_min": 0, + "sim_max": 2, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -73,10 +95,16 @@ { "id": "0x506", "desc": "MPU Sense Gyro", + "sim_freq": 250, + "fields": [ { "name": "MPU/Sense/Gyro", "unit": "", + "sim_min": 0, + "sim_max": 7, + "sim_inc_min": 0.01, + "sim_inc_max": 0.5, "points": [ { "size": 16 @@ -97,10 +125,15 @@ { "id": "0x507", "desc": "MPU Sense Temp", + "sim_freq": 1000, "fields": [ { "name": "MPU/Sense/Temp_IMU", "unit": "C", + "sim_min": 0, + "sim_max": 70, + "sim_inc_min": 1, + "sim_inc_max": 2, "points": [ { "size": 16, @@ -114,10 +147,15 @@ { "id": "0x502", "desc": "MPU Fault", + "sim_freq": 250, "fields": [ { "name": "MPU/Fault/Code", "unit": "", + "sim_min": 0, + "sim_max": 2048, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 32 @@ -128,6 +166,10 @@ { "name": "MPU/Fault/Severity", "unit": "", + "sim_min": 0, + "sim_max": 5, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 @@ -140,10 +182,15 @@ { "id": "0x503", "desc": "MPU Sense Voltage", + "sim_freq": 1000, "fields": [ { "name": "MPU/Sense/Voltage", "unit": "V", + "sim_min": 22.5, + "sim_max": 29, + "sim_inc_min": 0.02, + "sim_inc_max": 0.15, "points": [ { "size": 32, @@ -158,10 +205,15 @@ { "id": "0x504", "desc": "MPU Accel Pedals", + "sim_freq": 100, "fields": [ { "name": "MPU/Pedals/Accelerator_1", "unit": "", + "sim_min": 800, + "sim_max": 1900, + "sim_inc_min": 1, + "sim_inc_max": 24, "points": [ { "size": 32 @@ -172,6 +224,10 @@ { "name": "MPU/Pedals/Accelerator_2", "unit": "", + "sim_min": 1200, + "sim_max": 2300, + "sim_inc_min": 1, + "sim_inc_max": 24, "points": [ { "size": 32 @@ -184,10 +240,15 @@ { "id": "0x505", "desc": "MPU Brake Pedals", + "sim_freq": 100, "fields": [ { "name": "MPU/Pedals/Brake_1", "unit": "", + "sim_min": 580, + "sim_max": 990, + "sim_inc_min": 1, + "sim_inc_max": 10, "points": [ { "size": 32 @@ -198,6 +259,10 @@ { "name": "MPU/Pedals/Brake_2", "unit": "", + "sim_min": 580, + "sim_max": 990, + "sim_inc_min": 1, + "sim_inc_max": 10, "points": [ { "size": 32 @@ -210,10 +275,15 @@ { "id": "0x701", "desc": "MPU Debug", + "sim_freq": 1000, "fields": [ { "name": "MPU/Debug/Spare0", "unit": "", + "sim_min": 580, + "sim_max": 990, + "sim_inc_min": 1, + "sim_inc_max": 10, "points": [ { "size": 8 @@ -224,6 +294,10 @@ { "name": "MPU/Debug/Spare1", "unit": "", + "sim_min": 580, + "sim_max": 990, + "sim_inc_min": 1, + "sim_inc_max": 10, "points": [ { "size": 8, @@ -235,6 +309,10 @@ { "name": "MPU/Debug/Spare2", "unit": "", + "sim_min": 580, + "sim_max": 990, + "sim_inc_min": 1, + "sim_inc_max": 10, "points": [ { "size": 16, @@ -246,6 +324,10 @@ { "name": "MPU/Debug/Spare3", "unit": "", + "sim_min": 580, + "sim_max": 990, + "sim_inc_min": 1, + "sim_inc_max": 10, "points": [ { "size": 32, @@ -260,10 +342,15 @@ { "id": "0x123", "desc": "MPU Shutdown", + "sim_freq": 1000, "fields": [ { "name": "MPU/Shutdown/CockpitBRB", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -274,6 +361,10 @@ { "name": "MPU/Shutdown/BMS", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -284,6 +375,10 @@ { "name": "MPU/Shutdown/Inertia", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -294,6 +389,10 @@ { "name": "MPU/Shutdown/Spare_GPIO_1", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -304,6 +403,10 @@ { "name": "MPU/Shutdown/IMD", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -314,6 +417,10 @@ { "name": "MPU/Shutdown/BSPD", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -324,6 +431,10 @@ { "name": "MPU/Shutdown/BOTS", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -334,6 +445,10 @@ { "name": "MPU/Shutdown/HVD_Interlock", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -344,6 +459,10 @@ { "name": "MPU/Shutdown/HVC_Interlock", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -367,10 +486,15 @@ { "id": "0x111", "desc": "MPU Fuses", + "sim_freq": 1000, "fields": [ { "name": "MPU/Fuses/Battbox", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -381,6 +505,10 @@ { "name": "MPU/Fuses/LVBox", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -391,6 +519,10 @@ { "name": "MPU/Fuses/FanRadiator", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -401,6 +533,10 @@ { "name": "MPU/Fuses/MC", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -411,6 +547,10 @@ { "name": "MPU/Fuses/FanBattbox", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -421,6 +561,10 @@ { "name": "MPU/Fuses/Pump", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -431,6 +575,10 @@ { "name": "MPU/Fuses/Dashboard", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -441,6 +589,10 @@ { "name": "MPU/Fuses/Brakelight", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 @@ -451,6 +603,10 @@ { "name": "MPU/Fuses/BRB", "unit": "", + "sim_min": 0, + "sim_max": 1, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 1 diff --git a/cangen/can-messages/msb.json b/cangen/can-messages/msb.json index b67baa9..30636e3 100644 --- a/cangen/can-messages/msb.json +++ b/cangen/can-messages/msb.json @@ -2,10 +2,15 @@ { "id": "0x602", "desc": "Front Left MSB Env", + "sim_freq": 500, "fields": [ { "name": "MSB/FL/Temp", "unit": "C", + "sim_min": 0, + "sim_max": 80, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -16,6 +21,10 @@ { "name": "MSB/FL/Humidity", "unit": "", + "sim_min": 20, + "sim_max": 80, + "sim_inc_min": 1, + "sim_inc_max": 2.5, "points": [ { "size": 16 @@ -28,10 +37,15 @@ { "id": "0x603", "desc": "Front Left MSB Accel", + "sim_freq": 500, "fields": [ { "name": "MSB/FL/Accel", "unit": "g", + "sim_min": 0, + "sim_max": 2, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -52,9 +66,14 @@ { "id": "0x604", "desc": "Front Left MSB Gyro", + "sim_freq": 500, "fields": [ { "name": "MSB/FL/Gyro", + "sim_min": 0, + "sim_max": 15, + "sim_inc_min": 0.1, + "sim_inc_max": 0.5, "unit": "", "points": [ { @@ -76,10 +95,15 @@ { "id": "0x605", "desc": "Front Left MSB Strain", + "sim_freq": 500, "fields": [ { "name": "MSB/FL/Strain", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -96,10 +120,15 @@ { "id": "0x606", "desc": "Front Left Shockpot", + "sim_freq": 500, "fields": [ { "name": "MSB/FL/Shock", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -112,10 +141,15 @@ { "id": "0x607", "desc": "Front Left Ride Height", + "sim_freq": 500, "fields": [ { "name": "MSB/FL/RideHeight", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 16, @@ -129,10 +163,15 @@ { "id": "0x608", "desc": "Front Left Wheel Temp", + "sim_freq": 500, "fields": [ { "name": "MSB/FL/WheelTemp", "unit": "C", + "sim_min": 0, + "sim_max": 110, + "sim_inc_min": 0.5, + "sim_inc_max": 1.5, "points": [ { "size": 16 @@ -145,10 +184,15 @@ { "id": "0x622", "desc": "Front Right MSB Env", + "sim_freq": 500, "fields": [ { "name": "MSB/FR/Temp", "unit": "C", + "sim_min": 0, + "sim_max": 80, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -159,6 +203,10 @@ { "name": "MSB/FR/Humidity", "unit": "", + "sim_min": 20, + "sim_max": 80, + "sim_inc_min": 1, + "sim_inc_max": 2.5, "points": [ { "size": 16 @@ -171,10 +219,15 @@ { "id": "0x623", "desc": "Front Right MSB Accel", + "sim_freq": 500, "fields": [ { "name": "MSB/FR/Accel", "unit": "g", + "sim_min": 0, + "sim_max": 2, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -195,10 +248,15 @@ { "id": "0x624", "desc": "Front Right MSB Gyro", + "sim_freq": 500, "fields": [ { "name": "MSB/FR/Gyro", "unit": "", + "sim_min": 0, + "sim_max": 15, + "sim_inc_min": 0.1, + "sim_inc_max": 0.5, "points": [ { "size": 16 @@ -219,10 +277,15 @@ { "id": "0x625", "desc": "Front Right MSB Strain", + "sim_freq": 500, "fields": [ { "name": "MSB/FR/Strain", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -239,10 +302,15 @@ { "id": "0x626", "desc": "Front Right Shockpot", + "sim_freq": 500, "fields": [ { "name": "MSB/FR/Shock", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -255,10 +323,15 @@ { "id": "0x627", "desc": "Front Right Ride Height", + "sim_freq": 500, "fields": [ { "name": "MSB/FR/RideHeight", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 16, @@ -272,10 +345,15 @@ { "id": "0x628", "desc": "Front Right Wheel Temp", + "sim_freq": 500, "fields": [ { "name": "MSB/FR/WheelTemp", "unit": "C", + "sim_min": 0, + "sim_max": 110, + "sim_inc_min": 0.5, + "sim_inc_max": 1.5, "points": [ { "size": 16 @@ -288,10 +366,15 @@ { "id": "0x642", "desc": "Back Left MSB Env", + "sim_freq": 500, "fields": [ { "name": "MSB/BL/Temp", "unit": "C", + "sim_min": 0, + "sim_max": 80, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -302,6 +385,10 @@ { "name": "MSB/BL/Humidity", "unit": "", + "sim_min": 20, + "sim_max": 80, + "sim_inc_min": 1, + "sim_inc_max": 2.5, "points": [ { "size": 16 @@ -314,10 +401,15 @@ { "id": "0x643", "desc": "Back Left MSB Accel", + "sim_freq": 500, "fields": [ { "name": "MSB/BL/Accel", "unit": "g", + "sim_min": 0, + "sim_max": 2, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -338,10 +430,15 @@ { "id": "0x644", "desc": "Back Left MSB Gyro", + "sim_freq": 500, "fields": [ { "name": "MSB/BL/Gyro", "unit": "", + "sim_min": 0, + "sim_max": 15, + "sim_inc_min": 0.1, + "sim_inc_max": 0.5, "points": [ { "size": 16 @@ -362,10 +459,15 @@ { "id": "0x645", "desc": "Back Left MSB Strain", + "sim_freq": 500, "fields": [ { "name": "MSB/BL/Strain", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -382,10 +484,15 @@ { "id": "0x646", "desc": "Back Left Shockpot", + "sim_freq": 500, "fields": [ { "name": "MSB/BL/Shock", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -398,10 +505,15 @@ { "id": "0x647", "desc": "Front Back Ride Height", + "sim_freq": 500, "fields": [ { "name": "MSB/BL/RideHeight", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 16, @@ -415,10 +527,15 @@ { "id": "0x648", "desc": "Back Left Wheel Temp", + "sim_freq": 500, "fields": [ { "name": "MSB/BL/WheelTemp", "unit": "C", + "sim_min": 0, + "sim_max": 110, + "sim_inc_min": 0.5, + "sim_inc_max": 1.5, "points": [ { "size": 16 @@ -431,10 +548,15 @@ { "id": "0x662", "desc": "Back Right MSB Env", + "sim_freq": 500, "fields": [ { "name": "MSB/BR/Temp", "unit": "C", + "sim_min": 0, + "sim_max": 80, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -445,6 +567,10 @@ { "name": "MSB/BR/Humidity", "unit": "", + "sim_min": 20, + "sim_max": 80, + "sim_inc_min": 1, + "sim_inc_max": 2.5, "points": [ { "size": 16 @@ -457,10 +583,15 @@ { "id": "0x663", "desc": "Back Right MSB Accel", + "sim_freq": 500, "fields": [ { "name": "MSB/BR/Accel", "unit": "g", + "sim_min": 0, + "sim_max": 2, + "sim_inc_min": 0.01, + "sim_inc_max": 0.25, "points": [ { "size": 16 @@ -481,10 +612,15 @@ { "id": "0x664", "desc": "Back Right MSB Gyro", + "sim_freq": 500, "fields": [ { "name": "MSB/BR/Gyro", "unit": "", + "sim_min": 0, + "sim_max": 15, + "sim_inc_min": 0.1, + "sim_inc_max": 0.5, "points": [ { "size": 16 @@ -505,10 +641,15 @@ { "id": "0x665", "desc": "Back Right MSB Strain", + "sim_freq": 500, "fields": [ { "name": "MSB/BR/Strain", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -525,10 +666,15 @@ { "id": "0x666", "desc": "Back Right Shockpot", + "sim_freq": 500, "fields": [ { "name": "MSB/BR/Shock", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 32 @@ -541,10 +687,15 @@ { "id": "0x667", "desc": "Back Right Ride Height", + "sim_freq": 500, "fields": [ { "name": "MSB/BR/RideHeight", "unit": "", + "sim_min": 0, + "sim_max": 10, + "sim_inc_min": 0.001, + "sim_inc_max": 0.020, "points": [ { "size": 16, @@ -558,10 +709,15 @@ { "id": "0x668", "desc": "Back Right Wheel Temp", + "sim_freq": 500, "fields": [ { "name": "MSB/BR/WheelTemp", "unit": "C", + "sim_min": 0, + "sim_max": 110, + "sim_inc_min": 0.5, + "sim_inc_max": 1.5, "points": [ { "size": 16 diff --git a/cangen/can-messages/wheel.json b/cangen/can-messages/wheel.json index 66e1366..dc79dab 100644 --- a/cangen/can-messages/wheel.json +++ b/cangen/can-messages/wheel.json @@ -2,10 +2,15 @@ { "id": "0x680", "desc": "Wheel State", + "sim_freq": 8, "fields": [ { "name": "WHEEL/Buttons/1", "unit": "", + "sim_min": 0, + "sim_max": 8, + "sim_inc_min": 1, + "sim_inc_max": 8, "points": [ { "size": 8 @@ -16,6 +21,10 @@ { "name": "WHEEL/Buttons/2", "unit": "", + "sim_min": 0, + "sim_max": 2, + "sim_inc_min": 1, + "sim_inc_max": 1, "points": [ { "size": 8 From dad16f8fedddff381fb0d89ed6e6f5695dba3939 Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Tue, 8 Oct 2024 01:17:53 -0400 Subject: [PATCH 3/4] remove sneaky quotes --- cangen/can-messages/bms.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cangen/can-messages/bms.json b/cangen/can-messages/bms.json index 643f3a8..9d2da6f 100644 --- a/cangen/can-messages/bms.json +++ b/cangen/can-messages/bms.json @@ -25,7 +25,7 @@ "sim_max": 50, "sim_inc_min": 0, "sim_inc_max": 3, - "send": "false", + "send": false, "points": [ { "size": 16 @@ -526,4 +526,4 @@ } ] } -] \ No newline at end of file +] From 035394888fbf58ceb6d953c546e296a28d26ac19 Mon Sep 17 00:00:00 2001 From: tszwingli <43227796+tszwinglitw@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:37:50 -0400 Subject: [PATCH 4/4] created struct for constructor params --- cangen/RustSynthFromJSON.py | 45 +++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/cangen/RustSynthFromJSON.py b/cangen/RustSynthFromJSON.py index 1d2951d..9ac5979 100644 --- a/cangen/RustSynthFromJSON.py +++ b/cangen/RustSynthFromJSON.py @@ -352,7 +352,7 @@ def sanitize_fnname(name): name = re.sub(r'\W|^(?=\d)', '_', name) name = name.lower() return name - + sim_funcbody = "" # process each CAN message for msg in msgs: @@ -369,45 +369,42 @@ def sanitize_fnname(name): "sim_inc_min" not in netfield.keys()): continue - cmp_name = netfield['name'] - func_name = sanitize_fnname(cmp_name) + component_name = netfield['name'] + component_var = sanitize_fnname(component_name) unit = netfield['unit'] sim_min = netfield['sim_min'] sim_max = netfield['sim_max'] sim_inc_max = netfield['sim_inc_max'] sim_inc_min = netfield['sim_inc_min'] n_canpoints = len(netfield['points']) - format = "" - if 'format' in netfield: - format = netfield['format'] - signed = False - if 'signed' in netfield: - signed = netfield['signed'] new_component = f""" - let {func_name} = SimulatedComponents::new( - "{cmp_name}".to_string(), + let {component_var}_attr: SimulatedComponentAttr = SimulatedComponentAttr {{ + sim_min: {float(sim_min)}, + sim_max: {float(sim_max)}, + sim_inc_min: {float(sim_inc_min)}, + sim_inc_max: {float(sim_inc_max)}, + sim_freq: {float(sim_freq)}, + n_canpoints: {n_canpoints}, + id: "{id}".to_string(), + }}; + + + let {component_var} = SimulatedComponent::new( + "{component_name}".to_string(), "{unit}".to_string(), - {float(sim_min)}, - {float(sim_max)}, - {float(sim_inc_min)}, - {float(sim_inc_max)}, - {float(sim_freq)}, - {n_canpoints}, - "{format}".to_string(), - "{id}".to_string(), - {str(signed).lower()}, + {component_var}_attr, ); - simulatable_messages.push({func_name}); + simulatable_messages.push({component_var}); """ sim_funcbody += new_component sim_fnblock = f""" #![allow(clippy::all)] - use crate::simulatable_message::SimulatedComponents; - pub fn create_simulated_components() -> Vec {{ - let mut simulatable_messages: Vec = Vec::new(); + use crate::simulatable_message::{{SimulatedComponent, SimulatedComponentAttr}}; + pub fn create_simulated_components() -> Vec {{ + let mut simulatable_messages: Vec = Vec::new(); {sim_funcbody}