From 0539573f8232fb462d0095b51b28a6d442307083 Mon Sep 17 00:00:00 2001 From: Cyril Fougeray Date: Thu, 2 May 2024 14:57:51 +0200 Subject: [PATCH 1/2] mcu-util: serial can only be obtained if orb-ui not running make it optional still unused anyway --- mcu-util/src/orb/main_board.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mcu-util/src/orb/main_board.rs b/mcu-util/src/orb/main_board.rs index a01d66fa..a4f4671b 100644 --- a/mcu-util/src/orb/main_board.rs +++ b/mcu-util/src/orb/main_board.rs @@ -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, message_queue_rx: mpsc::Receiver, } @@ -55,7 +56,7 @@ impl MainBoardBuilder { self.message_queue_tx.clone(), )?; - 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 From 0b6aedea78dba137d53752070c7517e9a104c1b3 Mon Sep 17 00:00:00 2001 From: Cyril Fougeray Date: Thu, 2 May 2024 14:59:22 +0200 Subject: [PATCH 2/2] mcu-util: better errors (and printing) unwrap all errors --- mcu-util/src/main.rs | 2 +- mcu-util/src/orb/main_board.rs | 21 +++++++++++++-------- mcu-util/src/orb/security_board.rs | 8 +++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/mcu-util/src/main.rs b/mcu-util/src/main.rs index 143d9a3f..44b4ed08 100644 --- a/mcu-util/src/main.rs +++ b/mcu-util/src/main.rs @@ -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); diff --git a/mcu-util/src/orb/main_board.rs b/mcu-util/src/orb/main_board.rs index a4f4671b..3d95bae3 100644 --- a/mcu-util/src/orb/main_board.rs +++ b/mcu-util/src/orb/main_board.rs @@ -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; @@ -47,14 +47,16 @@ 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).ok(); @@ -326,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 { - main.isotp_iface + async fn build(mut self, main_board: &mut MainBoard) -> Result { + main_board + .isotp_iface .send(McuPayload::ToMain( main_messaging::jetson_to_mcu::Payload::ValueGet( main_messaging::ValueGet { @@ -337,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 { @@ -347,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 { @@ -365,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) => { diff --git a/mcu-util/src/orb/security_board.rs b/mcu-util/src/orb/security_board.rs index 16b8430c..c6d6eaeb 100644 --- a/mcu-util/src/orb/security_board.rs +++ b/mcu-util/src/orb/security_board.rs @@ -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; @@ -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