Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcu-util: better errors and printing #87

Merged
merged 2 commits into from
May 4, 2024
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
2 changes: 1 addition & 1 deletion mcu-util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async fn main() -> Result<()> {
}

if let Err(e) = execute(args).await {
error!("{}", e);
error!("{:#?}", e);
std::process::exit(-1);
} else {
std::process::exit(0);
Expand Down
26 changes: 16 additions & 10 deletions mcu-util/src/orb/main_board.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use eyre::{eyre, Result};
use eyre::{eyre, Context, Result};
use orb_messages::{mcu_main as main_messaging, CommonAckError};
use std::ops::Sub;
use std::sync::mpsc;
Expand All @@ -21,8 +21,9 @@ const REBOOT_DELAY: u32 = 3;
pub struct MainBoard {
canfd_iface: CanRawMessaging,
isotp_iface: CanIsoTpMessaging,
/// Optional serial interface for the main board, if available (ie orb-ui might own it)
#[allow(dead_code)]
serial_iface: SerialMessaging,
serial_iface: Option<SerialMessaging>,
message_queue_rx: mpsc::Receiver<McuPayload>,
}

Expand All @@ -46,16 +47,18 @@ impl MainBoardBuilder {
String::from("can0"),
Device::Main,
self.message_queue_tx.clone(),
)?;
)
.wrap_err("Failed to create CanRawMessaging for MainBoard")?;

let isotp_iface = CanIsoTpMessaging::new(
String::from("can0"),
IsoTpNodeIdentifier::JetsonApp7,
IsoTpNodeIdentifier::MainMcu,
self.message_queue_tx.clone(),
)?;
)
.wrap_err("Failed to create CanIsoTpMessaging for MainBoard")?;

let serial_iface = SerialMessaging::new(Device::Main)?;
let serial_iface = SerialMessaging::new(Device::Main).ok();

// Send a heartbeat to the main mcu to ensure it is alive
// & "subscribe" to the main mcu messages: messages to the Jetson
Expand Down Expand Up @@ -325,8 +328,9 @@ impl MainBoardInfo {

/// Fetches `MainBoardInfo` from the main board
/// on timeout, returns the info that was fetched so far
async fn build(mut self, main: &mut MainBoard) -> Result<Self> {
main.isotp_iface
async fn build(mut self, main_board: &mut MainBoard) -> Result<Self> {
main_board
.isotp_iface
.send(McuPayload::ToMain(
main_messaging::jetson_to_mcu::Payload::ValueGet(
main_messaging::ValueGet {
Expand All @@ -336,7 +340,8 @@ impl MainBoardInfo {
),
))
.await?;
main.isotp_iface
main_board
.isotp_iface
.send(McuPayload::ToMain(
main_messaging::jetson_to_mcu::Payload::ValueGet(
main_messaging::ValueGet {
Expand All @@ -346,7 +351,8 @@ impl MainBoardInfo {
),
))
.await?;
main.isotp_iface
main_board
.isotp_iface
.send(McuPayload::ToMain(
main_messaging::jetson_to_mcu::Payload::ValueGet(
main_messaging::ValueGet {
Expand All @@ -364,7 +370,7 @@ impl MainBoardInfo {
};
loop {
if let Ok(McuPayload::FromMain(main_mcu_payload)) =
main.message_queue_rx.recv_timeout(timeout)
main_board.message_queue_rx.recv_timeout(timeout)
{
match main_mcu_payload {
main_messaging::mcu_to_jetson::Payload::Versions(v) => {
Expand Down
8 changes: 5 additions & 3 deletions mcu-util/src/orb/security_board.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use eyre::{eyre, Result};
use eyre::{eyre, Context, Result};
use orb_messages::mcu_sec::battery_status::BatteryState;
use orb_messages::{mcu_sec as security_messaging, CommonAckError};
use std::ops::Sub;
Expand Down Expand Up @@ -43,14 +43,16 @@ impl SecurityBoardBuilder {
String::from("can0"),
Device::Security,
self.message_queue_tx.clone(),
)?;
)
.wrap_err("Failed to create CanRawMessaging for SecurityBoard")?;

let isotp_iface = CanIsoTpMessaging::new(
String::from("can0"),
IsoTpNodeIdentifier::JetsonApp7,
IsoTpNodeIdentifier::SecurityMcu,
self.message_queue_tx.clone(),
)?;
)
.wrap_err("Failed to create CanIsoTpMessaging for SecurityBoard")?;

// Send a heartbeat to the mcu to ensure it is alive
// & "subscribe" to the mcu messages: messages to the Jetson
Expand Down
Loading