Skip to content

Commit

Permalink
add commanded_address function
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdewid committed Jun 10, 2024
1 parent fa3b6d1 commit 53c9eac
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{Frame, FrameBuilder, IdBuilder, Name, PDU_NOT_AVAILABLE, PGN};
use crate::{
transport::BroadcastTransport, Frame, FrameBuilder, IdBuilder, Name, PDU_NOT_AVAILABLE, PGN,
};

/// Create PGN request frame.
pub fn request(da: u8, sa: u8, pgn: PGN) -> Frame {
Expand Down Expand Up @@ -50,3 +52,28 @@ pub fn acknowledgement(sa: u8, pgn: PGN) -> Frame {
])
.build()
}

/// Assign address to node.
pub fn commanded_address(sa: u8, name: &Name, address: u8) -> [Frame; 3] {
let name_bytes = name.to_bytes();

let data = [
name_bytes[0],
name_bytes[1],
name_bytes[2],
name_bytes[3],
name_bytes[4],
name_bytes[5],
name_bytes[6],
name_bytes[7],
address,
];

let mut transport = BroadcastTransport::new(sa, PGN::CommandedAddress).with_data(&data);

let frame0 = transport.next_frame();
let frame1 = transport.next_frame();
let frame2 = transport.next_frame();

[frame0, frame1, frame2]
}

0 comments on commit 53c9eac

Please sign in to comment.