Skip to content

Commit

Permalink
Fix Topic Synthesizing
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyton-McKee committed Feb 23, 2024
1 parent 6843799 commit 470a40b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 38 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ run ```/home/ner/Desktop/Calypso/target/release/calypso ipc /tmp/ipc.sock```
Utilizes MQTT Web Socket to offload data from the car for our telemetry system
run ```/home/ner/Desktop/Calypso/target/release/calypso mqtt localhost:1883```

### Generate code
### Synthesize Rust
`cd oxy`

`python3 typedpoc.py`

### Generate Proto

#### linux
`apt-get install protobuf-compiler -y`
Expand Down
5 changes: 3 additions & 2 deletions oxy/RustSynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from structs.Messages import Messages
from structs.Result import Result
from structs.NetworkEncoding import CSV, SinglePoint
from typing import List

class RustSynth:
'''
Expand Down Expand Up @@ -46,7 +47,7 @@ class RustSynth:
""" # The MessageInfo struct that is used to store the decode function for a given message

# The main function of the RustSynth class. Takes a list of CANMsgs and returns a Result object that contains the synthesized Rust code for the decode_data.rs and master_mapping.rs files
def parse_messages(self, msgs: [CANMsg]) -> Result:
def parse_messages(self, msgs: List[CANMsg]) -> Result:
result = Result("", "")
result.decode_data += self.ignore_clippy
result.decode_data += self.decode_data_import
Expand Down Expand Up @@ -89,7 +90,7 @@ def parse_network_encoding(self, msg: CANMsg) -> list[str]: # Change return typ
result.append(f" {networkEncoding.start}")
result.append(f" {self.decode_field_value(field)}")
result.append(f" {networkEncoding.closing}")
result.append(f" , \"{networkEncoding.topic}\", \"{networkEncoding.unit}\"), ")
result.append(f" , \"{field.name}\", \"{field.unit}\"), ")
return result

def decode_field_value(self, field: CANField) -> str:
Expand Down
70 changes: 35 additions & 35 deletions src/decode_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ pub fn decode_accumulator_status(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
fd::high_voltage(pd::big_endian(&data[0..2] as &[u8], 8) as f32)
]
, "None", "None"),
, "BMS/Pack/Voltage", "V"),
Data::new(vec![
fd::current(pd::twos_comp(pd::big_endian(&data[2..4] as &[u8], 8) as u32, 16) as f32)
]
, "None", "None"),
, "BMS/Pack/Current", "A"),
Data::new(vec![
pd::big_endian(&data[4..6] as &[u8], 8) as f32
]
, "None", "None"),
, "BMS/Pack/Amp-hours", "Ah"),
Data::new(vec![
data[6] as f32
]
, "None", "None"),
, "BMS/Pack/SOC", "%"),
Data::new(vec![
data[7] as f32
]
, "None", "None"),
, "BMS/Pack/Health", "%"),
];
result
}
Expand All @@ -38,23 +38,23 @@ pub fn decode_bms_status(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
data[0] as f32
]
, "None", "None"),
, "BMS/State", ""),
Data::new(vec![
pd::little_endian(&data[1..5] as &[u8], 8) as f32
]
, "None", "None"),
, "BMS/Faults", ""),
Data::new(vec![
pd::twos_comp(data[5] as u32, 8) as f32
]
, "None", "None"),
, "BMS/Temps/Average", "C"),
Data::new(vec![
pd::twos_comp(data[6] as u32, 8) as f32
]
, "None", "None"),
, "BMS/Temps/Internal", "C"),
Data::new(vec![
data[7] as f32
]
, "None", "None"),
, "BMS/Cells/BurningStatus", ""),
];
result
}
Expand All @@ -64,7 +64,7 @@ pub fn decode_shutdown_control(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
data[0] as f32
]
, "None", "None"),
, "BMS/Shutdown/MPE", ""),
];
result
}
Expand All @@ -74,31 +74,31 @@ pub fn decode_cell_data(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
fd::cell_voltage(pd::little_endian(&data[0..2] as &[u8], 8) as f32)
]
, "None", "None"),
, "BMS/Cells/Volts/High/Value", "V"),
Data::new(vec![
pd::half(data[2] as u8, 4) as f32
]
, "None", "None"),
, "BMS/Cells/Volts/High/Chip", ""),
Data::new(vec![
pd::half(data[3] as u8, 0) as f32
]
, "None", "None"),
, "BMS/Cells/Volts/High/Cell", ""),
Data::new(vec![
fd::cell_voltage(pd::little_endian(&data[4..6] as &[u8], 8) as f32)
]
, "None", "None"),
, "BMS/Cells/Volts/Low/Value", "V"),
Data::new(vec![
pd::half(data[6] as u8, 4) as f32
]
, "None", "None"),
, "BMS/Cells/Volts/Low/Chip", ""),
Data::new(vec![
pd::half(data[7] as u8, 0) as f32
]
, "None", "None"),
, "BMS/Cells/Volts/Low/Cell", ""),
Data::new(vec![
fd::cell_voltage(pd::little_endian(&data[8..10] as &[u8], 8) as f32)
]
, "None", "None"),
, "BMS/Cells/Volts/Avg/Value", "V"),
];
result
}
Expand All @@ -108,31 +108,31 @@ pub fn decode_cell_temperatures(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
pd::twos_comp(pd::little_endian(&data[0..2] as &[u8], 8) as u32, 16) as f32
]
, "None", "None"),
, "BMS/Cells/Temp/High/Value", "C"),
Data::new(vec![
pd::half(data[2] as u8, 4) as f32
]
, "None", "None"),
, "BMS/Cells/Temp/High/Cell", ""),
Data::new(vec![
pd::half(data[3] as u8, 0) as f32
]
, "None", "None"),
, "BMS/Cells/Temp/High/Chip", ""),
Data::new(vec![
pd::twos_comp(pd::little_endian(&data[4..6] as &[u8], 8) as u32, 16) as f32
]
, "None", "None"),
, "BMS/Cells/Temp/Low/Value", "C"),
Data::new(vec![
pd::half(data[6] as u8, 4) as f32
]
, "None", "None"),
, "BMS/Cells/Temp/Low/Cell", ""),
Data::new(vec![
pd::half(data[7] as u8, 0) as f32
]
, "None", "None"),
, "BMS/Cells/Temp/Low/Chip", ""),
Data::new(vec![
pd::twos_comp(pd::little_endian(&data[8..10] as &[u8], 8) as u32, 16) as f32
]
, "None", "None"),
, "BMS/Cells/Temp/Avg/Value", "C"),
];
result
}
Expand All @@ -142,19 +142,19 @@ pub fn decode_segment_temperatures(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
pd::twos_comp(data[0] as u32, 8) as f32
]
, "None", "None"),
, "BMS/Segment/Temp/1", "C"),
Data::new(vec![
pd::twos_comp(data[1] as u32, 8) as f32
]
, "None", "None"),
, "BMS/Segment/Temp/2", "C"),
Data::new(vec![
pd::twos_comp(data[2] as u32, 8) as f32
]
, "None", "None"),
, "BMS/Segment/Temp/3", "C"),
Data::new(vec![
pd::twos_comp(data[3] as u32, 8) as f32
]
, "None", "None"),
, "BMS/Segment/Temp/4", "C"),
];
result
}
Expand All @@ -174,19 +174,19 @@ pub fn decode_mpu_status(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
data[0] as f32
]
, "None", "None"),
, "MPU/State/Mode", ""),
Data::new(vec![
data[1] as f32
]
, "None", "None"),
, "MPU/State/Torque_Limit_Percentage", ""),
Data::new(vec![
data[2] as f32
]
, "None", "None"),
, "MPU/State/Regen_Strength", ""),
Data::new(vec![
data[3] as f32
]
, "None", "None"),
, "MPU/State/Traction_Control", ""),
];
result
}
Expand All @@ -196,11 +196,11 @@ pub fn decode_wheel_state(data: &[u8]) -> Vec::<Data> {
Data::new(vec![
data[0] as f32
]
, "None", "None"),
, "WHEEL/Buttons/1", ""),
Data::new(vec![
data[1] as f32
]
, "None", "None"),
, "WHEEL/Buttons/2", ""),
];
result
}
Expand Down

0 comments on commit 470a40b

Please sign in to comment.