Skip to content

Commit

Permalink
improving gneral structure
Browse files Browse the repository at this point in the history
  • Loading branch information
maebli committed Nov 19, 2023
1 parent 61a57de commit 5302f24
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/frames/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn parse_frame(data: &[u8]) -> Result<FrameType, FrameError> {
_ => Ok(FrameType::LongFrame{
function: Function::from(data[4])?,
address: Address::from(data[5]),
data: &data[7..data.len() - 2],
data: &data[6..data.len() - 2],
}),
}
},
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ mod frames;
mod user_data;

pub fn parse_frame(data: &[u8]) -> Result<frames::FrameType, frames::FrameError> {
frames::parse_frame(data)
let frame = frames::parse_frame(data);

if let Ok(frames::FrameType::LongFrame{function, address, data}) = &frame {
let user_data = user_data::parse_user_data(data);
println!("Function: {:?}, Address: {:?}, User Data: {:?}", function, address, user_data);
}

frame
}
5 changes: 3 additions & 2 deletions src/user_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl std::fmt::Display for IdentificationNumberError {
impl std::error::Error for IdentificationNumberError {}


#[derive(Debug, Clone, Copy)]
#[derive(Debug, PartialEq)]
pub struct IdentificationNumber {
number: u32,
}
Expand All @@ -155,6 +155,7 @@ impl IdentificationNumber {
}


#[derive(Debug, PartialEq)]
pub enum UserDataBlock {
ResetAtApplicationLevel{subcode: ApplicationResetSubcode},
FixedDataStructure{
Expand All @@ -172,7 +173,7 @@ pub enum UserDataError {
InvalidUserData,
}

fn parse_user_data(data: &[u8]) -> Result<UserDataBlock, ApplicationLayerError> {
pub fn parse_user_data(data: &[u8]) -> Result<UserDataBlock, ApplicationLayerError> {

let control_information = ControlInformation::from(data[0])?;

Expand Down

0 comments on commit 5302f24

Please sign in to comment.