diff --git a/tests/mav_frame_tests.rs b/tests/mav_frame_tests.rs new file mode 100644 index 0000000000..fac00da30a --- /dev/null +++ b/tests/mav_frame_tests.rs @@ -0,0 +1,45 @@ +pub mod test_shared; + +mod mav_frame_tests { + // NOTE: No header + pub const HEARTBEAT_V2: &[u8] = &[ + crate::test_shared::COMMON_MSG_HEADER.sequence, + crate::test_shared::COMMON_MSG_HEADER.system_id, + crate::test_shared::COMMON_MSG_HEADER.component_id, + 0x00, // msg ID + 0x00, + 0x00, + 0x05, // payload - custom_mode + 0x00, // + 0x00, // + 0x00, // + 0x02, // mav_type + 0x03, // autopilot + 0x59, // base_mode + 0x03, // system_status + 0x03, // mavlink_version + 0x10, // checksum + 0xf0, + ]; + + #[test] + pub fn test_deser() { + use mavlink::{common::MavMessage, MavFrame, MavlinkVersion}; + let frame = MavFrame::::deser(MavlinkVersion::V2, HEARTBEAT_V2) + .expect("failed to parse message"); + + assert_eq!(frame.header, crate::test_shared::COMMON_MSG_HEADER); + let heartbeat_msg = crate::test_shared::get_heartbeat_msg(); + + let msg = match frame.msg { + MavMessage::HEARTBEAT(msg) => msg, + _ => panic!("Decoded wrong message type"), + }; + assert_eq!(msg.custom_mode, heartbeat_msg.custom_mode); + assert_eq!(msg.mavtype, heartbeat_msg.mavtype); + assert_eq!(msg.autopilot, heartbeat_msg.autopilot); + assert_eq!(msg.base_mode, heartbeat_msg.base_mode); + assert_eq!(msg.system_status, heartbeat_msg.system_status); + assert_eq!(msg.mavlink_version, heartbeat_msg.mavlink_version); + } +} diff --git a/tests/v1_encode_decode_tests.rs b/tests/v1_encode_decode_tests.rs index ad3addc167..892de2fe0b 100644 --- a/tests/v1_encode_decode_tests.rs +++ b/tests/v1_encode_decode_tests.rs @@ -9,9 +9,9 @@ mod test_v1_encode_decode { pub const HEARTBEAT_V1: &'static [u8] = &[ mavlink::MAV_STX, 0x09, - 0xef, - 0x01, - 0x01, + crate::test_shared::COMMON_MSG_HEADER.sequence, + crate::test_shared::COMMON_MSG_HEADER.system_id, + crate::test_shared::COMMON_MSG_HEADER.component_id, 0x00, 0x05, 0x00, diff --git a/tests/v2_encode_decode_tests.rs b/tests/v2_encode_decode_tests.rs index b6cfd8b2fa..fa0a712ae6 100644 --- a/tests/v2_encode_decode_tests.rs +++ b/tests/v2_encode_decode_tests.rs @@ -10,9 +10,9 @@ mod test_v2_encode_decode { 0x09, //payload len 0, //incompat flags 0, //compat flags - 0xef, //seq 239 - 0x01, //sys ID - 0x01, //comp ID + crate::test_shared::COMMON_MSG_HEADER.sequence, + crate::test_shared::COMMON_MSG_HEADER.system_id, + crate::test_shared::COMMON_MSG_HEADER.component_id, 0x00, 0x00, 0x00, //msg ID