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 UALBERTA_TESTSUITE_H
6 #define UALBERTA_TESTSUITE_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #ifndef MAVLINK_TEST_ALL
13 #define MAVLINK_TEST_ALL
14 static void mavlink_test_common(uint8_t, uint8_t, mavlink_message_t *last_msg);
15 static void mavlink_test_ualberta(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  mavlink_test_common(system_id, component_id, last_msg);
20  mavlink_test_ualberta(system_id, component_id, last_msg);
21 }
22 #endif
23 
24 #include "../common/testsuite.h"
25 
26 
27 static void mavlink_test_nav_filter_bias(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_nav_filter_bias_t packet_in = {
33  93372036854775807ULL,73.0,101.0,129.0,157.0,185.0,213.0
34  };
35  mavlink_nav_filter_bias_t packet1, packet2;
36  memset(&packet1, 0, sizeof(packet1));
37  packet1.usec = packet_in.usec;
38  packet1.accel_0 = packet_in.accel_0;
39  packet1.accel_1 = packet_in.accel_1;
40  packet1.accel_2 = packet_in.accel_2;
41  packet1.gyro_0 = packet_in.gyro_0;
42  packet1.gyro_1 = packet_in.gyro_1;
43  packet1.gyro_2 = packet_in.gyro_2;
44 
45 
46 
47  memset(&packet2, 0, sizeof(packet2));
48  mavlink_msg_nav_filter_bias_encode(system_id, component_id, &msg, &packet1);
49  mavlink_msg_nav_filter_bias_decode(&msg, &packet2);
50  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
51 
52  memset(&packet2, 0, sizeof(packet2));
53  mavlink_msg_nav_filter_bias_pack(system_id, component_id, &msg , packet1.usec , packet1.accel_0 , packet1.accel_1 , packet1.accel_2 , packet1.gyro_0 , packet1.gyro_1 , packet1.gyro_2 );
54  mavlink_msg_nav_filter_bias_decode(&msg, &packet2);
55  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
56 
57  memset(&packet2, 0, sizeof(packet2));
58  mavlink_msg_nav_filter_bias_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.usec , packet1.accel_0 , packet1.accel_1 , packet1.accel_2 , packet1.gyro_0 , packet1.gyro_1 , packet1.gyro_2 );
59  mavlink_msg_nav_filter_bias_decode(&msg, &packet2);
60  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
61 
62  memset(&packet2, 0, sizeof(packet2));
63  mavlink_msg_to_send_buffer(buffer, &msg);
64  for (i=0; i<mavlink_msg_get_send_buffer_length(&msg); i++) {
65  comm_send_ch(MAVLINK_COMM_0, buffer[i]);
66  }
67  mavlink_msg_nav_filter_bias_decode(last_msg, &packet2);
68  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
69 
70  memset(&packet2, 0, sizeof(packet2));
71  mavlink_msg_nav_filter_bias_send(MAVLINK_COMM_1 , packet1.usec , packet1.accel_0 , packet1.accel_1 , packet1.accel_2 , packet1.gyro_0 , packet1.gyro_1 , packet1.gyro_2 );
72  mavlink_msg_nav_filter_bias_decode(last_msg, &packet2);
73  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
74 }
75 
76 static void mavlink_test_radio_calibration(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
77 {
78  mavlink_message_t msg;
79  uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
80  uint16_t i;
81  mavlink_radio_calibration_t packet_in = {
82  { 17235, 17236, 17237 },{ 17547, 17548, 17549 },{ 17859, 17860, 17861 },{ 18171, 18172 },{ 18379, 18380, 18381, 18382, 18383 },{ 18899, 18900, 18901, 18902, 18903 }
83  };
84  mavlink_radio_calibration_t packet1, packet2;
85  memset(&packet1, 0, sizeof(packet1));
86 
87  mav_array_memcpy(packet1.aileron, packet_in.aileron, sizeof(uint16_t)*3);
88  mav_array_memcpy(packet1.elevator, packet_in.elevator, sizeof(uint16_t)*3);
89  mav_array_memcpy(packet1.rudder, packet_in.rudder, sizeof(uint16_t)*3);
90  mav_array_memcpy(packet1.gyro, packet_in.gyro, sizeof(uint16_t)*2);
91  mav_array_memcpy(packet1.pitch, packet_in.pitch, sizeof(uint16_t)*5);
92  mav_array_memcpy(packet1.throttle, packet_in.throttle, sizeof(uint16_t)*5);
93 
94 
95  memset(&packet2, 0, sizeof(packet2));
96  mavlink_msg_radio_calibration_encode(system_id, component_id, &msg, &packet1);
97  mavlink_msg_radio_calibration_decode(&msg, &packet2);
98  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
99 
100  memset(&packet2, 0, sizeof(packet2));
101  mavlink_msg_radio_calibration_pack(system_id, component_id, &msg , packet1.aileron , packet1.elevator , packet1.rudder , packet1.gyro , packet1.pitch , packet1.throttle );
102  mavlink_msg_radio_calibration_decode(&msg, &packet2);
103  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
104 
105  memset(&packet2, 0, sizeof(packet2));
106  mavlink_msg_radio_calibration_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.aileron , packet1.elevator , packet1.rudder , packet1.gyro , packet1.pitch , packet1.throttle );
107  mavlink_msg_radio_calibration_decode(&msg, &packet2);
108  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
109 
110  memset(&packet2, 0, sizeof(packet2));
111  mavlink_msg_to_send_buffer(buffer, &msg);
112  for (i=0; i<mavlink_msg_get_send_buffer_length(&msg); i++) {
113  comm_send_ch(MAVLINK_COMM_0, buffer[i]);
114  }
115  mavlink_msg_radio_calibration_decode(last_msg, &packet2);
116  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
117 
118  memset(&packet2, 0, sizeof(packet2));
119  mavlink_msg_radio_calibration_send(MAVLINK_COMM_1 , packet1.aileron , packet1.elevator , packet1.rudder , packet1.gyro , packet1.pitch , packet1.throttle );
120  mavlink_msg_radio_calibration_decode(last_msg, &packet2);
121  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
122 }
123 
124 static void mavlink_test_ualberta_sys_status(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
125 {
126  mavlink_message_t msg;
127  uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
128  uint16_t i;
129  mavlink_ualberta_sys_status_t packet_in = {
130  5,72,139
131  };
132  mavlink_ualberta_sys_status_t packet1, packet2;
133  memset(&packet1, 0, sizeof(packet1));
134  packet1.mode = packet_in.mode;
135  packet1.nav_mode = packet_in.nav_mode;
136  packet1.pilot = packet_in.pilot;
137 
138 
139 
140  memset(&packet2, 0, sizeof(packet2));
141  mavlink_msg_ualberta_sys_status_encode(system_id, component_id, &msg, &packet1);
142  mavlink_msg_ualberta_sys_status_decode(&msg, &packet2);
143  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
144 
145  memset(&packet2, 0, sizeof(packet2));
146  mavlink_msg_ualberta_sys_status_pack(system_id, component_id, &msg , packet1.mode , packet1.nav_mode , packet1.pilot );
147  mavlink_msg_ualberta_sys_status_decode(&msg, &packet2);
148  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
149 
150  memset(&packet2, 0, sizeof(packet2));
151  mavlink_msg_ualberta_sys_status_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.mode , packet1.nav_mode , packet1.pilot );
152  mavlink_msg_ualberta_sys_status_decode(&msg, &packet2);
153  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
154 
155  memset(&packet2, 0, sizeof(packet2));
156  mavlink_msg_to_send_buffer(buffer, &msg);
157  for (i=0; i<mavlink_msg_get_send_buffer_length(&msg); i++) {
158  comm_send_ch(MAVLINK_COMM_0, buffer[i]);
159  }
160  mavlink_msg_ualberta_sys_status_decode(last_msg, &packet2);
161  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
162 
163  memset(&packet2, 0, sizeof(packet2));
164  mavlink_msg_ualberta_sys_status_send(MAVLINK_COMM_1 , packet1.mode , packet1.nav_mode , packet1.pilot );
165  mavlink_msg_ualberta_sys_status_decode(last_msg, &packet2);
166  MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
167 }
168 
169 static void mavlink_test_ualberta(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
170 {
171  mavlink_test_nav_filter_bias(system_id, component_id, last_msg);
172  mavlink_test_radio_calibration(system_id, component_id, last_msg);
173  mavlink_test_ualberta_sys_status(system_id, component_id, last_msg);
174 }
175 
176 #ifdef __cplusplus
177 }
178 #endif // __cplusplus
179 #endif // UALBERTA_TESTSUITE_H
#define MAVLINK_ASSERT(x)
Definition: protocol.h:26