Skip to content

Commit 020484c

Browse files
committed
Update to Id changes of embedded-can
timokroeger/embedded-can#7
1 parent e675be6 commit 020484c

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

pcan-basic/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ authors = ["Timo Kröger <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
embedded-can = "0.1.0"
98
nb = "0.1.2"
109
pcan-basic-sys = { path = "../pcan-basic-sys" }
1110
winapi = { version = "0.3.8", features = ["synchapi"] }
1211

12+
[dependencies.embedded-can]
13+
git = "https://github.com/timokroeger/embedded-can"
14+
branch = "id"
15+
1316
[dev-dependencies]
1417
anyhow = "1.0"
1518
thiserror = "1.0"

pcan-basic/examples/stm32-fwupdate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ where
7171
self.receive_ack(0x21)
7272
}
7373

74-
pub fn send(&mut self, id: u32, data: &[u8]) -> Result<()> {
75-
let tx_frame = Can::Frame::new(Id::Standard(id), data).unwrap();
74+
pub fn send(&mut self, id: u16, data: &[u8]) -> Result<()> {
75+
let tx_frame = Can::Frame::new(Id::new_standard(id).unwrap(), data).unwrap();
7676
self.can.try_write(&tx_frame)?;
7777
Ok(())
7878
}
7979

80-
fn receive_ack(&mut self, id: u32) -> Result<()> {
80+
fn receive_ack(&mut self, id: u16) -> Result<()> {
8181
let msg = self.can.try_read()?;
82-
if msg.id() == Id::Standard(id) && msg.data() == &[0x79] {
82+
if msg.id() == Id::new_standard(id).unwrap() && msg.data() == &[0x79] {
8383
return Ok(());
8484
}
8585

pcan-basic/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod prelude {
2-
pub use embedded_can::{Can as _, Frame as _, Id};
2+
pub use embedded_can::{Can as _, ExtendedId, Frame as _, Id, StandardId};
33
}
44

55
use std::{
@@ -109,13 +109,13 @@ pub struct Frame(TPCANMsg);
109109

110110
impl embedded_can::Frame for Frame {
111111
fn new(id: Id, data: &[u8]) -> Result<Frame, ()> {
112-
if !id.valid() || data.len() > 8 {
112+
if data.len() > 8 {
113113
return Err(());
114114
}
115115

116116
let (id, msg_type) = match id {
117-
Id::Standard(id) => (id as u32, PCAN_MESSAGE_STANDARD),
118-
Id::Extended(id) => (id, PCAN_MESSAGE_EXTENDED),
117+
Id::Standard(id) => (id.into(), PCAN_MESSAGE_STANDARD),
118+
Id::Extended(id) => (id.into(), PCAN_MESSAGE_EXTENDED),
119119
};
120120

121121
let mut msg = TPCANMsg {
@@ -149,9 +149,9 @@ impl embedded_can::Frame for Frame {
149149

150150
fn id(&self) -> Id {
151151
if self.is_extended() {
152-
Id::Extended(self.0.ID)
152+
Id::new_extended(self.0.ID).unwrap()
153153
} else {
154-
Id::Standard(self.0.ID)
154+
Id::new_standard(self.0.ID as u16).unwrap()
155155
}
156156
}
157157

@@ -255,13 +255,13 @@ impl Filter {
255255
Id::Standard(id) => Self {
256256
accept_all: false,
257257
is_extended: false,
258-
id: id as u32,
258+
id: id.into(),
259259
mask: 0x7FF,
260260
},
261261
Id::Extended(id) => Self {
262262
accept_all: false,
263263
is_extended: true,
264-
id,
264+
id: id.into(),
265265
mask: 0x1FFF_FFFF,
266266
},
267267
}

0 commit comments

Comments
 (0)