diff --git a/src/message.rs b/src/message.rs index f9750bc..be0e99a 100644 --- a/src/message.rs +++ b/src/message.rs @@ -173,6 +173,7 @@ pub struct TxMessage, const L: usize> { } impl, const L: usize> TxMessage { + /// Create new CAN message pub fn new(message_type: T, data: Bytes, identifier: Id) -> Result { let mut header = TxHeader::new(); @@ -202,6 +203,16 @@ impl, const L: usize> TxMessage { message_type, }) } + + /// Returns payload as a `&[u8]` + pub fn get_payload(&self) -> &[u8] { + self.buff.as_ref() + } + + /// Returns Header register of Transmit Message Object + pub fn get_header(&self) -> &TxHeader { + &self.header + } } /// Receive message object header diff --git a/src/tests/message.rs b/src/tests/message.rs index 2c47fda..00a40bb 100644 --- a/src/tests/message.rs +++ b/src/tests/message.rs @@ -111,3 +111,15 @@ fn test_payload_greater_than_generic_type_args() { assert_eq!(message_2_0.unwrap_err(), MessageError::InvalidLength(5)); assert_eq!(message_fd.unwrap_err(), MessageError::InvalidLength(23)); } + +#[test] +fn test_get_payload() { + let payload_bytes = Bytes::copy_from_slice(&[1u8; 8]); + let standard_id = StandardId::new(STANDARD_ID).unwrap(); + + let msg_type = Can20::<8> {}; + + let message = TxMessage::new(msg_type, payload_bytes, Id::Standard(standard_id)).unwrap(); + + assert_eq!(message.get_payload(), &[1u8; 8]); +}