NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
testsuite.h
Go to the documentation of this file.
1 
5 #ifndef MINIMAL_TESTSUITE_H
6 #define MINIMAL_TESTSUITE_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #ifndef MAVLINK_TEST_ALL
13 #define MAVLINK_TEST_ALL
14 
15 static void mavlink_test_minimal(uint8_t, uint8_t, mavlink_message_t *last_msg);
16 
17 static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
18 {
19 
20  mavlink_test_minimal(system_id, component_id, last_msg);
21 }
22 #endif
23 
24 
25 
26 
27 static void mavlink_test_heartbeat(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
28 {
29  mavlink_message_t msg;
30  uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
31  uint16_t i;
32  mavlink_heartbeat_t packet_in = {
33  963497464,17,84,151,218,2
34  };
35  mavlink_heartbeat_t packet1, packet2;
36  memset(&packet1, 0, sizeof(packet1));
37  packet1.custom_mode = packet_in.custom_mode;
38  packet1.type = packet_in.type;
39  packet1.autopilot = packet_in.autopilot;
40  packet1.base_mode = packet_in.base_mode;
41  packet1.system_status = packet_in.system_status;
42  packet1.mavlink_version = packet_in.mavlink_version;
43 
44 
45 
46  memset(&packet2, 0, sizeof(packet2));
47  mavlink_msg_heartbeat_encode(system_id, component_id, &msg, &packet1);
48  mavlink_msg_heartbeat_decode(&msg, &packet2);
49  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
50 
51  memset(&packet2, 0, sizeof(packet2));
52  mavlink_msg_heartbeat_pack(system_id, component_id, &msg , packet1.type , packet1.autopilot , packet1.base_mode , packet1.custom_mode , packet1.system_status );
53  mavlink_msg_heartbeat_decode(&msg, &packet2);
54  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
55 
56  memset(&packet2, 0, sizeof(packet2));
57  mavlink_msg_heartbeat_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.type , packet1.autopilot , packet1.base_mode , packet1.custom_mode , packet1.system_status );
58  mavlink_msg_heartbeat_decode(&msg, &packet2);
59  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
60 
61  memset(&packet2, 0, sizeof(packet2));
62  mavlink_msg_to_send_buffer(buffer, &msg);
63  for (i=0; i<mavlink_msg_get_send_buffer_length(&msg); i++) {
64  comm_send_ch(MAVLINK_COMM_0, buffer[i]);
65  }
66  mavlink_msg_heartbeat_decode(last_msg, &packet2);
67  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
68 
69  memset(&packet2, 0, sizeof(packet2));
70  mavlink_msg_heartbeat_send(MAVLINK_COMM_1 , packet1.type , packet1.autopilot , packet1.base_mode , packet1.custom_mode , packet1.system_status );
71  mavlink_msg_heartbeat_decode(last_msg, &packet2);
72  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
73 }
74 
75 static void mavlink_test_minimal(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
76 {
77  mavlink_test_heartbeat(system_id, component_id, last_msg);
78 }
79 
80 #ifdef __cplusplus
81 }
82 #endif // __cplusplus
83 #endif // MINIMAL_TESTSUITE_H
#define MAVLINK_ASSERT(x)
Definition: protocol.h:26