-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
#[derive(Debug, PartialEq, Copy, Clone)] | ||
use strum_macros::FromRepr; | ||
|
||
pub static FRAME_TYPE_MASK: u8 = 0xf0; | ||
pub static FLOW_SATUS_MASK: u8 = 0x0f; | ||
|
||
#[derive(Debug, PartialEq, Copy, Clone, FromRepr)] | ||
#[repr(u8)] | ||
pub enum FrameType { | ||
Single = 0x00, | ||
First = 0x10, | ||
Consecutive = 0x20, | ||
FlowControl = 0x30, | ||
Unknown = 0xff, | ||
} | ||
|
||
pub static FRAME_TYPE_MASK: u8 = 0xf0; | ||
|
||
impl From<u8> for FrameType { | ||
fn from(val: u8) -> FrameType { | ||
match val { | ||
0x00 => FrameType::Single, | ||
0x10 => FrameType::First, | ||
0x20 => FrameType::Consecutive, | ||
0x30 => FrameType::FlowControl, | ||
_ => FrameType::Unknown, | ||
} | ||
} | ||
#[derive(Debug, PartialEq, Copy, Clone, FromRepr)] | ||
#[repr(u8)] | ||
pub enum FlowStatus { | ||
ContinueToSend = 0x0, | ||
Wait = 0x1, | ||
Overflow = 0x2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::can::Frame; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct FlowControlConfig { | ||
pub block_size: u8, | ||
pub separation_time_min: std::time::Duration, | ||
} | ||
|
||
impl TryFrom<&Frame> for FlowControlConfig { | ||
type Error = crate::error::Error; | ||
fn try_from(frame: &Frame) -> Result<Self, Self::Error> { | ||
if frame.data.len() < 3 { | ||
return Err(crate::isotp::error::Error::MalformedFrame.into()); | ||
} | ||
|
||
let block_size = frame.data[1]; | ||
|
||
let separation_time_min = frame.data[2] as u64; | ||
let separation_time_min = match separation_time_min { | ||
0x0..=0x7f => std::time::Duration::from_millis(separation_time_min), | ||
0xf1..=0xf9 => std::time::Duration::from_micros((separation_time_min - 0xf0) * 100), | ||
_ => return Err(crate::isotp::error::Error::MalformedFrame.into()), | ||
}; | ||
|
||
Ok(Self { | ||
block_size, | ||
separation_time_min, | ||
}) | ||
} | ||
} |