@@ -3,7 +3,7 @@ mod test_shared;
33#[ cfg( feature = "dialect-common" ) ]
44mod helper_tests {
55 use mavlink:: {
6- MavlinkVersion , MessageData , calculate_crc,
6+ MessageData , calculate_crc,
77 dialects:: common:: MavMessage ,
88 error:: { MessageReadError , ParserError } ,
99 peek_reader:: PeekReader ,
@@ -38,36 +38,36 @@ mod helper_tests {
3838 }
3939
4040 #[ test]
41- fn test_invalid_bitflag ( ) {
42- use mavlink:: dialects:: common:: HIL_ACTUATOR_CONTROLS_DATA ;
41+ fn test_unknown_bitflag_bits_are_preserved ( ) {
42+ use mavlink:: dialects:: common:: {
43+ MavFrame , PositionTargetTypemask , SET_POSITION_TARGET_GLOBAL_INT_DATA ,
44+ } ;
4345
44- let msg = HIL_ACTUATOR_CONTROLS_DATA :: DEFAULT ;
45- let mut invalid_flag_buf = [ 0 ; 1 + 9 + HIL_ACTUATOR_CONTROLS_DATA :: ENCODED_LEN + 2 ] ;
46- let len = msg. ser (
47- MavlinkVersion :: V2 ,
48- & mut invalid_flag_buf[ 10 ..10 + HIL_ACTUATOR_CONTROLS_DATA :: ENCODED_LEN ] ,
49- ) ;
50- invalid_flag_buf[ 0 ] = mavlink:: MAV_STX_V2 ;
51- invalid_flag_buf[ 1 ] = len as u8 ;
52- invalid_flag_buf[ 7 ] = HIL_ACTUATOR_CONTROLS_DATA :: ID as u8 ;
53- // set flags to an invalid HilActuatorControlsFlags value
54- invalid_flag_buf[ 1 + 9 + 8 ..1 + 9 + 16 ] . copy_from_slice ( & u64:: MAX . to_le_bytes ( ) ) ;
55- // update crc
56- let crc = calculate_crc (
57- & invalid_flag_buf[ 1 ..1 + 9 + len] ,
58- HIL_ACTUATOR_CONTROLS_DATA :: EXTRA_CRC ,
59- ) ;
60- invalid_flag_buf[ 1 + 9 + len..1 + 9 + len + 2 ] . copy_from_slice ( & crc. to_le_bytes ( ) ) ;
46+ let send_msg = SET_POSITION_TARGET_GLOBAL_INT_DATA {
47+ coordinate_frame : MavFrame :: MAV_FRAME_GLOBAL ,
48+ // Regression test for https://github.com/mavlink/rust-mavlink/issues/484
49+ type_mask : PositionTargetTypemask :: from_bits_retain ( 65016 ) ,
50+ ..SET_POSITION_TARGET_GLOBAL_INT_DATA :: DEFAULT
51+ } ;
6152
62- let result = mavlink:: read_v2_msg :: < MavMessage , _ > ( & mut PeekReader :: new (
63- invalid_flag_buf. as_slice ( ) ,
64- ) ) ;
65- assert ! ( matches!(
66- result,
67- Err ( MessageReadError :: Parse ( ParserError :: InvalidFlag {
68- flag_type: "HilActuatorControlsFlags" ,
69- value: u64 :: MAX
70- } ) )
71- ) ) ;
53+ let mut buffer = [ 0u8 ; 280 ] ;
54+ let mut writer: & mut [ u8 ] = & mut buffer;
55+
56+ mavlink:: write_v2_msg (
57+ & mut writer,
58+ crate :: test_shared:: COMMON_MSG_HEADER ,
59+ & MavMessage :: SET_POSITION_TARGET_GLOBAL_INT ( send_msg) ,
60+ )
61+ . expect ( "failed to serialize SET_POSITION_TARGET_GLOBAL_INT" ) ;
62+
63+ let mut reader = PeekReader :: new ( buffer. as_slice ( ) ) ;
64+ let ( _header, recv_msg) = mavlink:: read_v2_msg :: < MavMessage , _ > ( & mut reader)
65+ . expect ( "failed to parse SET_POSITION_TARGET_GLOBAL_INT with unknown bitmask bits" ) ;
66+
67+ let MavMessage :: SET_POSITION_TARGET_GLOBAL_INT ( recv_msg) = recv_msg else {
68+ panic ! ( "decoded wrong message type" ) ;
69+ } ;
70+
71+ assert_eq ! ( recv_msg. type_mask. bits( ) , 65016 ) ;
7272 }
7373}
0 commit comments