Skip to content

Commit

Permalink
mcu-util: better errors and printing (#87)
Browse files Browse the repository at this point in the history
* mcu-util: serial can only be obtained if orb-ui not running

make it optional
still unused anyway

* mcu-util: better errors (and printing)

unwrap all errors
  • Loading branch information
fouge authored May 4, 2024
1 parent 056f8f9 commit 495672e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
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
21 changes: 13 additions & 8 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 Down Expand Up @@ -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();

Expand Down Expand Up @@ -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<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 @@ -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 {
Expand All @@ -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 {
Expand All @@ -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) => {
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

0 comments on commit 495672e

Please sign in to comment.