Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ egui_extras = "0.33.3"

rfd = "0.17.2"

can_decode = "0.6.1"
can-dbc = "8.1.0"
can_decode = "0.7.2"
can-dbc = "9.0.0"

chrono = "0.4.44"

hashbrown = "0.16.1"

log = "0.4.29"
env_logger = "0.11.9"
env_logger = "0.11.10"

slcan = { git = "https://github.com/LelsersLasers/slcan", features = ["sync"] }
serialport = "4.8.1"

rand = "0.10.0"
rand = "0.10.1"

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/can/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl Driver for SimulatedDriver {
Ok(vec![can_frame.into()])
} else {
// If no DBC is loaded, just return random frames with random IDs and data
let id = rng.random_range(0..=util::msg_id::STANDARD_ID_MASK) as u16;
let id = rng.random_range(0..=util::can::STANDARD_ID_MASK) as u16;
let sid = slcan::StandardId::new(id).expect("invalid standard id");
let mut data = [0u8; 8];
rng.fill_bytes(&mut data);
Expand Down
10 changes: 5 additions & 5 deletions src/can/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const BUS_LOAD_UPDATE_MS: u128 = 200;
fn process_can_frame(frame: slcan::CanFrame, state: &can::state::State) -> usize {
match frame {
slcan::CanFrame::Can2(frame2) => {
let decode_msg_id = util::msg_id::slcan_to_u32_with_extid_flag(&frame2.id());
let raw_msg_id = util::msg_id::slcan_to_u32_without_extid_flag(&frame2.id());
let decode_msg_id = util::can::slcan_to_u32_with_extid_flag(&frame2.id());
let raw_msg_id = util::can::slcan_to_u32_without_extid_flag(&frame2.id());

let data = frame2.data().unwrap_or(&[]);

Expand Down Expand Up @@ -44,7 +44,7 @@ fn process_can_frame(frame: slcan::CanFrame, state: &can::state::State) -> usize
data.len()
}
slcan::CanFrame::CanFd(frame_fd) => {
let msg_id_raw = util::msg_id::slcan_to_u32_without_extid_flag(&frame_fd.id());
let msg_id_raw = util::can::slcan_to_u32_without_extid_flag(&frame_fd.id());
log::warn!(
"Received CAN FD frame id=0x{:X} len={}",
msg_id_raw,
Expand Down Expand Up @@ -103,9 +103,9 @@ pub fn start_can_thread(
for msg in msgs_to_send {
if let Some(ref mut active_driver) = state.driver {
let id = if msg.is_msg_id_extended {
slcan::ExtendedId::new(msg.msg_id & util::msg_id::EXTENDED_ID_MASK)
slcan::ExtendedId::new(msg.msg_id & util::can::EXTENDED_ID_MASK)
.map(slcan::Id::Extended)
} else if msg.msg_id <= util::msg_id::STANDARD_ID_MASK {
} else if msg.msg_id <= util::can::STANDARD_ID_MASK {
slcan::StandardId::new(msg.msg_id as u16).map(slcan::Id::Standard)
} else {
log::warn!(
Expand Down
21 changes: 9 additions & 12 deletions src/daq_log_parse/correlate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ impl CorrelationChunkResult {
}
}

pub fn sig_to_value(dsv: &can_decode::DecodedSignalValue) -> u64 {
match &dsv {
can_decode::DecodedSignalValue::Numeric(v) => v.round() as u64,
can_decode::DecodedSignalValue::Enum(v, _) => *v as u64,
}
pub fn physical_to_u64(dsv: &can_decode::DecodedSignalValue) -> u64 {
dsv.physical.round() as u64
}

pub fn time_correlate_chunk(chunk: Vec<ParsedMessage>) -> CorrelationChunkResult {
Expand All @@ -77,37 +74,37 @@ pub fn time_correlate_chunk(chunk: Vec<ParsedMessage>) -> CorrelationChunkResult
.decoded
.signals
.get("millisecond")
.map(|sig| sig_to_value(&sig.value));
.map(|sig| physical_to_u64(&sig.value));
let second = msg
.decoded
.signals
.get("second")
.map(|sig| sig_to_value(&sig.value));
.map(|sig| physical_to_u64(&sig.value));
let minute = msg
.decoded
.signals
.get("minute")
.map(|sig| sig_to_value(&sig.value));
.map(|sig| physical_to_u64(&sig.value));
let hour = msg
.decoded
.signals
.get("hour")
.map(|sig| sig_to_value(&sig.value));
.map(|sig| physical_to_u64(&sig.value));
let day = msg
.decoded
.signals
.get("day")
.map(|sig| sig_to_value(&sig.value));
.map(|sig| physical_to_u64(&sig.value));
let month = msg
.decoded
.signals
.get("month")
.map(|sig| sig_to_value(&sig.value));
.map(|sig| physical_to_u64(&sig.value));
let year = msg
.decoded
.signals
.get("year")
.map(|sig| sig_to_value(&sig.value));
.map(|sig| physical_to_u64(&sig.value));

if let (Some(ms), Some(s), Some(min), Some(h), Some(d), Some(mon), Some(y)) =
(millisecond, second, minute, hour, day, month, year)
Expand Down
4 changes: 2 additions & 2 deletions src/daq_log_parse/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ fn parse_log_file(
}

let arb_id = if (frame.identity & consts::IS_EID_MASK) != 0 {
frame.identity & util::msg_id::EXTENDED_ID_MASK
frame.identity & util::can::EXTENDED_ID_MASK
} else {
frame.identity & util::msg_id::STANDARD_ID_MASK
frame.identity & util::can::STANDARD_ID_MASK
};

let bus_id = if (frame.identity & consts::BUS_ID_MASK) != 0 {
Expand Down
8 changes: 4 additions & 4 deletions src/daq_log_parse/table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::daq_log_parse::{consts, correlate};
use can_decode::DecodedSignalValue;

pub struct TableBuilder {
bus_row: Vec<String>,
Expand Down Expand Up @@ -105,9 +104,10 @@ impl TableBuilder {
if let Some(row) = csv_table.get_mut(row_idx as usize + 4)
&& let Some(cell) = row.get_mut(col_idx)
{
*cell = match &sig_value.value {
DecodedSignalValue::Numeric(v) => v.to_string(),
DecodedSignalValue::Enum(_, label) => label.clone(),
*cell = if let Some(enum_label) = &sig_value.value.enum_label {
format!("{} ({})", enum_label, sig_value.value.int_rounded())
} else {
sig_value.value.physical.to_string()
};
}
}
Expand Down
78 changes: 20 additions & 58 deletions src/ui/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl CellData {
}
}

#[derive(Default)]
struct ChargingTelemetry {
pack_voltage: f64,
pack_current: f64,
Expand Down Expand Up @@ -77,25 +78,16 @@ impl BatteryViewer {

for (_, sig) in parsed.decoded.signals.iter() {
match sig.name.as_str() {
"module_num" => {
if let can_decode::DecodedSignalValue::Numeric(v) = &sig.value {
module_num = Some(v.round() as usize);
}
}
"cell_num" => {
if let can_decode::DecodedSignalValue::Numeric(v) = &sig.value {
cell_num = Some(v.round() as usize);
}
}
"voltage" => {
if let can_decode::DecodedSignalValue::Numeric(v) = &sig.value {
voltage = Some(*v);
}
}
"module_num" => module_num = Some(sig.value.physical.round() as usize),
"cell_num" => cell_num = Some(sig.value.physical.round() as usize),
"voltage" => voltage = Some(sig.value.physical),
"balance_status" => {
if let can_decode::DecodedSignalValue::Enum(v, _) = &sig.value {
balancing = Some(*v != 0);
}
balancing = Some(
sig.value
.raw
.map(|v| v != 0)
.unwrap_or(sig.value.physical > 0.5),
)
}
_ => {}
}
Expand All @@ -117,52 +109,22 @@ impl BatteryViewer {
for (_, sig) in parsed.decoded.signals.iter() {
match sig.name.as_str() {
"pack_voltage" => {
if let can_decode::DecodedSignalValue::Numeric(v) = &sig.value {
self.charging_telemetry
.get_or_insert(ChargingTelemetry {
pack_voltage: *v,
pack_current: 0.0,
min_cell_voltage: 0.0,
max_cell_voltage: 0.0,
})
.pack_voltage = *v;
}
self.charging_telemetry.get_or_insert_default().pack_voltage =
sig.value.physical;
}
"pack_current" => {
if let can_decode::DecodedSignalValue::Numeric(v) = &sig.value {
self.charging_telemetry
.get_or_insert(ChargingTelemetry {
pack_voltage: 0.0,
pack_current: *v,
min_cell_voltage: 0.0,
max_cell_voltage: 0.0,
})
.pack_current = *v;
}
self.charging_telemetry.get_or_insert_default().pack_current =
sig.value.physical;
}
"min_cell_voltage" => {
if let can_decode::DecodedSignalValue::Numeric(v) = &sig.value {
self.charging_telemetry
.get_or_insert(ChargingTelemetry {
pack_voltage: 0.0,
pack_current: 0.0,
min_cell_voltage: *v,
max_cell_voltage: 0.0,
})
.min_cell_voltage = *v;
}
self.charging_telemetry
.get_or_insert_default()
.min_cell_voltage = sig.value.physical;
}
"max_cell_voltage" => {
if let can_decode::DecodedSignalValue::Numeric(v) = &sig.value {
self.charging_telemetry
.get_or_insert(ChargingTelemetry {
pack_voltage: 0.0,
pack_current: 0.0,
min_cell_voltage: 0.0,
max_cell_voltage: *v,
})
.max_cell_voltage = *v;
}
self.charging_telemetry
.get_or_insert_default()
.max_cell_voltage = sig.value.physical;
}
_ => {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/dbc_msg_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl DbcMsgPickerState {
.filter(|msg| {
let id_str = format!(
"0x{:03X}",
util::msg_id::can_dbc_to_u32_without_extid_flag(&msg.id)
util::can::can_dbc_to_u32_without_extid_flag(&msg.id)
);
id_str.contains(&search_lower)
|| msg.name.to_lowercase().contains(&search_lower)
Expand Down Expand Up @@ -76,7 +76,7 @@ impl DbcMsgPickerState {
.button(format!(
"{} (0x{:03X})",
msg.name,
util::msg_id::can_dbc_to_u32_without_extid_flag(&msg.id)
util::can::can_dbc_to_u32_without_extid_flag(&msg.id)
))
.clicked()
{
Expand Down
Loading
Loading