Skip to content

Commit

Permalink
Remove industry_group field and add test for NameBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdewid committed Feb 1, 2024
1 parent fafaf17 commit d0257d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ mod tests {
.function(0x5)
.vehicle_system(0x6)
.vehicle_system_instance(0x5)
.industry_group(0x0)
.arbitrary_address(true)
.build();

Expand All @@ -226,9 +225,24 @@ mod tests {
.function(0x5)
.vehicle_system(0x6)
.vehicle_system_instance(0x5)
.industry_group(0x0)
.arbitrary_address(true)
.build()
);
}

#[test]
fn test_name_builder() {
let name = NameBuilder::default()
.identity_number(0x1)
.manufacturer_code(0x717)
.function_instance(1)
.ecu_instance(1)
.function(0x3A)
.vehicle_system(9)
.build();

let bytes = name.to_bytes();

assert_eq!(bytes, [0x01, 0x00, 0xE0, 0xE2, 0x09, 0x3A, 0x09, 0x00]);
}
}
20 changes: 17 additions & 3 deletions src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use crate::{FrameBuilder, IdBuilder, PGN};
use crate::{Frame, FrameBuilder, IdBuilder, Name, PGN};

/// Create PGN request frame.
pub fn request(da: u8, pgn: PGN) -> crate::Frame {
pub fn request(da: u8, pgn: PGN) -> Frame {
let byte_array = pgn.to_le_bytes();

FrameBuilder::new(IdBuilder::from_pgn(PGN::Request).da(da).build())
let id = IdBuilder::from_pgn(PGN::Request).da(da).build();

FrameBuilder::new(id)
.copy_from_slice(&[byte_array[0], byte_array[1], byte_array[2]])
.build()
}

/// Create address claimed frame.
pub fn address_claimed(sa: u8, name: Name) -> Frame {
let id = IdBuilder::from_pgn(PGN::AddressClaimed)
.sa(sa)
.da(0xff)
.build();

FrameBuilder::new(id)
.copy_from_slice(&name.to_bytes()[..])
.build()
}

0 comments on commit d0257d5

Please sign in to comment.