Skip to content

Commit

Permalink
Option to modify existing Frame instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Oct 13, 2023
1 parent fac304f commit 81fe0a7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ static READ_NOTIFICATION: Notification = Notification::new();
static WRITE_NOTIFICATION: Notification = Notification::new();
static ALERT_NOTIFICATION: Notification = Notification::new();

pub const NO_DATA: [u8; 8] = [0; u8];
pub const NO_DATA: [u8; 8] = [0; 8];

pub struct Frame(twai_message_t);

Expand All @@ -737,7 +737,7 @@ impl Frame {
}

pub fn new_remote(id: u32, extended: bool, dlc: usize) -> Result<Self, EspError> {
if data.len() <= 8 {
if dlc <= 8 {
let mut frame = Frame(Default::default());

frame.set(id, true, extended, &NO_DATA[..dlc])?;
Expand All @@ -762,11 +762,11 @@ impl Frame {

// set bits in an union
if remote {
unsafe { self.0.__bindgen_anon_1.set_rtr(1) };
unsafe { self.0.__bindgen_anon_1.__bindgen_anon_1.set_rtr(1) };
}

if extended {
unsafe { self.0.__bindgen_anon_1.set_extd(1) };
unsafe { self.0.__bindgen_anon_1.__bindgen_anon_1.set_extd(1) };
}

self.0.identifier = id;
Expand Down Expand Up @@ -890,7 +890,7 @@ impl embedded_can::Frame for Frame {
embedded_can::Id::Extended(id) => (id.as_raw(), true),
};

Self::new(id, extended, data)
Self::new(id, extended, data).ok()
}

fn new_remote(id: impl Into<embedded_can::Id>, dlc: usize) -> Option<Self> {
Expand All @@ -899,7 +899,7 @@ impl embedded_can::Frame for Frame {
embedded_can::Id::Extended(id) => (id.as_raw(), true),
};

Self::new_remote(id, extended, dlc)
Self::new_remote(id, extended, dlc).ok()
}

fn is_extended(&self) -> bool {
Expand Down

0 comments on commit 81fe0a7

Please sign in to comment.