Skip to content

Commit

Permalink
#5 remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
HusseinAbdelhamid committed Sep 2, 2024
1 parent 109a20f commit c56e130
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 52 deletions.
50 changes: 0 additions & 50 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,53 +202,3 @@ impl RxHeader {
}
}
}

/// Receive message object header
#[bitfield(bits = 64)]
#[derive(Default, PartialEq, Eq, Debug)]
#[repr(u64)]
pub struct RxHeader {
// R0
#[skip]
__: B2,
sid11: bool,
extended_identifier: B18,
standard_identifier: B11,
#[skip]
__: B16,
filter_hit: B5,
#[skip]
__: B2,
error_status_indicator: bool,
fd_frame: bool,
bit_rate_switch: bool,
remote_transmission_request: bool,
identifier_extension_flag: bool,
data_length_code: DLC,
}

impl RxHeader {
fn get_id(&self) -> Id {
if self.identifier_extension_flag() {
let id = ((self.standard_identifier() as u32) << 18) | (self.extended_identifier());
let extended_id = ExtendedId::new(id);
Id::Extended(extended_id.unwrap())
} else {
let id = StandardId::new(self.standard_identifier());
Id::Standard(id.unwrap())
}
}
#[cfg(test)]
pub fn new_test_cfg(identifier: Id) -> Self {
match identifier {
Id::Extended(eid) => Self::new()
.with_data_length_code(DLC::Eight)
.with_standard_identifier((eid.as_raw() >> 18) as u16 & STANDARD_IDENTIFIER_MASK)
.with_extended_identifier(eid.as_raw() & EXTENDED_IDENTIFIER_MASK)
.with_identifier_extension_flag(true),
Id::Standard(sid) => Self::new()
.with_data_length_code(DLC::Eight)
.with_standard_identifier(sid.as_raw()),
}
}
}
1 change: 1 addition & 0 deletions src/registers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use modular_bitfield_msb::prelude::*;

/// Fourth byte of FIFO Control register
#[bitfield]
#[derive(Default)]
Expand Down
5 changes: 3 additions & 2 deletions src/tests/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ fn test_transmit() {
fn test_receive() {
let mut mocks = Mocks::default();

let mut seq = Sequence::new();
let id = ExtendedId::new(EXTENDED_ID).unwrap();

// custom Rx message header for testing
Expand All @@ -284,10 +285,10 @@ fn test_receive() {
let mut message_buff = [0u8; 16];

// status register read
mocks.mock_register_read::<0b0000_0001>([0x30, 0x60]);
mocks.mock_register_read::<0b0000_0001>([0x30, 0x60], &mut seq);

// user address register read
mocks.mock_read32::<0x00_00_04_7C>([0x30, 0x64]);
mocks.mock_read32::<0x00_00_04_7C>([0x30, 0x64], &mut seq);

// Message read from RAM address 0x47C
//transfer cmd+address
Expand Down

0 comments on commit c56e130

Please sign in to comment.