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: pull out messaging module into a crate #115

Merged
merged 5 commits into from
Jun 3, 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
20 changes: 15 additions & 5 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"endpoints",
"header-parsing",
"hil",
"mcu-interface",
"mcu-util",
"orb-attest",
"orb-backend-state",
Expand Down
27 changes: 27 additions & 0 deletions mcu-interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "orb-mcu-interface"
version = "0.0.0"
authors = ["Cyril Fougeray <[email protected]>"]
description = "Higher-level interface used to communicate with the MCUs"
publish = false

edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
async-trait = "0.1.77"
can-rs = { path = "../can", features = ["isotp"] }
color-eyre.workspace = true
orb-messages.workspace = true
prost = "0.12.3"
tokio.workspace = true
tokio-serial = "5.4.1"
tracing.workspace = true

[package.metadata.orb]
unsupported_targets = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
]
7 changes: 7 additions & 0 deletions mcu-interface/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# orb-mcu-interface

Higher-level interface used to communicate with the MCUs.

## Platform support notes

This binary only works on {aarch64,x86_64}-unknown-linux-gnu, due to `can-rs`.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::sync::{mpsc, Arc};
use tokio::time::Duration;
use tracing::debug;

use crate::messaging::Device::{JetsonFromMain, JetsonFromSecurity, Main, Security};
use crate::messaging::{
use crate::Device::{JetsonFromMain, JetsonFromSecurity, Main, Security};
use crate::{
create_ack, handle_main_mcu_message, handle_sec_mcu_message, Device, McuPayload,
MessagingInterface,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use can_rs::isotp::addr::CanIsotpAddr;
use can_rs::isotp::stream::IsotpStream;
use can_rs::{Id, CAN_DATA_LEN};

use crate::messaging::{
use crate::{
handle_main_mcu_message, handle_sec_mcu_message, McuPayload, MessagingInterface,
};

Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions mcu-util/src/messaging/mod.rs → mcu-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use tracing::debug;
pub mod can;
pub mod serial;

pub use orb_messages;

#[derive(Clone, Debug)]
pub enum McuPayload {
ToMain(orb_messages::mcu_main::jetson_to_mcu::Payload),
Expand Down Expand Up @@ -39,7 +41,7 @@ impl From<u8> for Device {
}

#[async_trait]
pub(crate) trait MessagingInterface {
pub trait MessagingInterface {
async fn send(&mut self, payload: McuPayload) -> Result<CommonAckError>;
}

Expand All @@ -55,7 +57,7 @@ fn create_ack(counter: u16) -> u32 {

/// Check that ack contains the process ID
#[inline]
pub fn is_ack_for_us(ack_number: u32) -> bool {
fn is_ack_for_us(ack_number: u32) -> bool {
ack_number >> 16 == process::id()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::messaging::{Device, McuPayload, MessagingInterface};
use crate::{Device, McuPayload, MessagingInterface};
use async_trait::async_trait;
use color_eyre::eyre::{eyre, Result};
use orb_messages::CommonAckError;
Expand Down
10 changes: 3 additions & 7 deletions mcu-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ repository.workspace = true
rust-version.workspace = true

[dependencies]
anyhow = "1.0.79"
async-trait = "0.1.77"
can-rs = { path = "../can", features = ["isotp"] }
clap.workspace = true
crc32fast = "1.3.2"
color-eyre.workspace = true
crc32fast = "1.3.2"
image = "0.24.8"
orb-messages.workspace = true
prost = "0.12.3"
orb-mcu-interface.path = "../mcu-interface"
tokio.workspace = true
tokio-serial = "5.4.1"
tracing.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true

[package.metadata.orb]
unsupported_targets = [
Expand Down
1 change: 0 additions & 1 deletion mcu-util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::time::Duration;
use tracing::{debug, error};

mod logging;
mod messaging;
mod orb;

/// Utility args
Expand Down
4 changes: 2 additions & 2 deletions mcu-util/src/orb/dfu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use color_eyre::eyre::{eyre, Result};
use orb_messages::mcu_main as main_messaging;
use orb_messages::mcu_sec as sec_messaging;
use orb_mcu_interface::orb_messages::mcu_main as main_messaging;
use orb_mcu_interface::orb_messages::mcu_sec as sec_messaging;
use std::cmp::min;
use std::fs::File;
use std::io;
Expand Down
13 changes: 7 additions & 6 deletions mcu-util/src/orb/main_board.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use async_trait::async_trait;
use color_eyre::eyre::{eyre, Context, Result};
use orb_messages::{mcu_main as main_messaging, CommonAckError};
use std::ops::Sub;
use std::sync::mpsc;
use std::time::Duration;
use tokio::time;
use tracing::{debug, info, warn};

use crate::messaging::can::canfd::CanRawMessaging;
use crate::messaging::can::isotp::{CanIsoTpMessaging, IsoTpNodeIdentifier};
use crate::messaging::serial::SerialMessaging;
use crate::messaging::{Device, McuPayload, MessagingInterface};
use orb_mcu_interface::can::canfd::CanRawMessaging;
use orb_mcu_interface::can::isotp::{CanIsoTpMessaging, IsoTpNodeIdentifier};
use orb_mcu_interface::orb_messages::{mcu_main as main_messaging, CommonAckError};
use orb_mcu_interface::serial::SerialMessaging;
use orb_mcu_interface::{Device, McuPayload, MessagingInterface};

use crate::orb::dfu::BlockIterator;
use crate::orb::revision::OrbRevision;
use crate::orb::{dfu, BatteryStatus};
Expand Down Expand Up @@ -94,7 +95,7 @@ impl Board for MainBoard {
let delay = delay.unwrap_or(REBOOT_DELAY);
self.isotp_iface
.send(McuPayload::ToMain(
orb_messages::mcu_main::jetson_to_mcu::Payload::Reboot(
main_messaging::jetson_to_mcu::Payload::Reboot(
main_messaging::RebootWithDelay { delay },
),
))
Expand Down
5 changes: 3 additions & 2 deletions mcu-util/src/orb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::time::Duration;

use async_trait::async_trait;
use color_eyre::eyre::Result;
use orb_messages::mcu_main as main_messaging;
use orb_messages::mcu_sec as sec_messaging;

use orb_mcu_interface::orb_messages::mcu_main as main_messaging;
use orb_mcu_interface::orb_messages::mcu_sec as sec_messaging;

use crate::orb::main_board::MainBoard;
use crate::orb::revision::OrbRevision;
Expand Down
7 changes: 3 additions & 4 deletions mcu-util/src/orb/revision.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use orb_messages::mcu_main as main_messaging;
use orb_mcu_interface::orb_messages::mcu_main as main_messaging;
use std::fmt::{Display, Formatter};

#[derive(Clone, Debug, Default)]
Expand All @@ -7,16 +7,15 @@ pub struct OrbRevision(pub main_messaging::Hardware);
impl Display for OrbRevision {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.0.version
< orb_messages::mcu_main::hardware::OrbVersion::HwVersionDiamondPoc1 as i32
< main_messaging::hardware::OrbVersion::HwVersionDiamondPoc1 as i32
{
write!(f, "EVT{:?}", self.0.version)
} else {
write!(
f,
"Diamond_POC{:?}",
self.0.version
- orb_messages::mcu_main::hardware::OrbVersion::HwVersionDiamondPoc1
as i32
- main_messaging::hardware::OrbVersion::HwVersionDiamondPoc1 as i32
+ 1
)
}
Expand Down
12 changes: 7 additions & 5 deletions mcu-util/src/orb/security_board.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use async_trait::async_trait;
use color_eyre::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;
use std::sync::mpsc;
use std::time::Duration;
use tokio::time;
use tracing::{debug, info, warn};

use crate::messaging::can::canfd::CanRawMessaging;
use crate::messaging::can::isotp::{CanIsoTpMessaging, IsoTpNodeIdentifier};
use crate::messaging::{Device, McuPayload, MessagingInterface};
use orb_mcu_interface::can::canfd::CanRawMessaging;
use orb_mcu_interface::can::isotp::{CanIsoTpMessaging, IsoTpNodeIdentifier};
use orb_mcu_interface::orb_messages;
use orb_mcu_interface::{Device, McuPayload, MessagingInterface};
use orb_messages::mcu_sec::battery_status::BatteryState;
use orb_messages::{mcu_sec as security_messaging, CommonAckError};

use crate::orb::dfu::BlockIterator;
use crate::orb::{dfu, BatteryStatus};
use crate::orb::{Board, OrbInfo};
Expand Down
Loading