You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
5.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /** @file
  2. * @brief MAVLink comm protocol testsuite generated from test.xml
  3. * @see http://qgroundcontrol.org/mavlink/
  4. */
  5. #pragma once
  6. #ifndef TEST_TESTSUITE_H
  7. #define TEST_TESTSUITE_H
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #ifndef MAVLINK_TEST_ALL
  12. #define MAVLINK_TEST_ALL
  13. static void mavlink_test_test(uint8_t, uint8_t, mavlink_message_t *last_msg);
  14. static void mavlink_test_all(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
  15. {
  16. mavlink_test_test(system_id, component_id, last_msg);
  17. }
  18. #endif
  19. static void mavlink_test_test_types(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
  20. {
  21. #ifdef MAVLINK_STATUS_FLAG_OUT_MAVLINK1
  22. mavlink_status_t *status = mavlink_get_channel_status(MAVLINK_COMM_0);
  23. if ((status->flags & MAVLINK_STATUS_FLAG_OUT_MAVLINK1) && MAVLINK_MSG_ID_TEST_TYPES >= 256) {
  24. return;
  25. }
  26. #endif
  27. mavlink_message_t msg;
  28. uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
  29. uint16_t i;
  30. mavlink_test_types_t packet_in = {
  31. 93372036854775807ULL,93372036854776311LL,235.0,{ 93372036854777319, 93372036854777320, 93372036854777321 },{ 93372036854778831, 93372036854778832, 93372036854778833 },{ 627.0, 628.0, 629.0 },963502456,963502664,745.0,{ 963503080, 963503081, 963503082 },{ 963503704, 963503705, 963503706 },{ 941.0, 942.0, 943.0 },24723,24827,{ 24931, 24932, 24933 },{ 25243, 25244, 25245 },'E',"FGHIJKLMN",198,9,{ 76, 77, 78 },{ 21, 22, 23 }
  32. };
  33. mavlink_test_types_t packet1, packet2;
  34. memset(&packet1, 0, sizeof(packet1));
  35. packet1.u64 = packet_in.u64;
  36. packet1.s64 = packet_in.s64;
  37. packet1.d = packet_in.d;
  38. packet1.u32 = packet_in.u32;
  39. packet1.s32 = packet_in.s32;
  40. packet1.f = packet_in.f;
  41. packet1.u16 = packet_in.u16;
  42. packet1.s16 = packet_in.s16;
  43. packet1.c = packet_in.c;
  44. packet1.u8 = packet_in.u8;
  45. packet1.s8 = packet_in.s8;
  46. mav_array_memcpy(packet1.u64_array, packet_in.u64_array, sizeof(uint64_t)*3);
  47. mav_array_memcpy(packet1.s64_array, packet_in.s64_array, sizeof(int64_t)*3);
  48. mav_array_memcpy(packet1.d_array, packet_in.d_array, sizeof(double)*3);
  49. mav_array_memcpy(packet1.u32_array, packet_in.u32_array, sizeof(uint32_t)*3);
  50. mav_array_memcpy(packet1.s32_array, packet_in.s32_array, sizeof(int32_t)*3);
  51. mav_array_memcpy(packet1.f_array, packet_in.f_array, sizeof(float)*3);
  52. mav_array_memcpy(packet1.u16_array, packet_in.u16_array, sizeof(uint16_t)*3);
  53. mav_array_memcpy(packet1.s16_array, packet_in.s16_array, sizeof(int16_t)*3);
  54. mav_array_memcpy(packet1.s, packet_in.s, sizeof(char)*10);
  55. mav_array_memcpy(packet1.u8_array, packet_in.u8_array, sizeof(uint8_t)*3);
  56. mav_array_memcpy(packet1.s8_array, packet_in.s8_array, sizeof(int8_t)*3);
  57. #ifdef MAVLINK_STATUS_FLAG_OUT_MAVLINK1
  58. if (status->flags & MAVLINK_STATUS_FLAG_OUT_MAVLINK1) {
  59. // cope with extensions
  60. memset(MAVLINK_MSG_ID_TEST_TYPES_MIN_LEN + (char *)&packet1, 0, sizeof(packet1)-MAVLINK_MSG_ID_TEST_TYPES_MIN_LEN);
  61. }
  62. #endif
  63. memset(&packet2, 0, sizeof(packet2));
  64. mavlink_msg_test_types_encode(system_id, component_id, &msg, &packet1);
  65. mavlink_msg_test_types_decode(&msg, &packet2);
  66. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  67. memset(&packet2, 0, sizeof(packet2));
  68. mavlink_msg_test_types_pack(system_id, component_id, &msg , packet1.c , packet1.s , packet1.u8 , packet1.u16 , packet1.u32 , packet1.u64 , packet1.s8 , packet1.s16 , packet1.s32 , packet1.s64 , packet1.f , packet1.d , packet1.u8_array , packet1.u16_array , packet1.u32_array , packet1.u64_array , packet1.s8_array , packet1.s16_array , packet1.s32_array , packet1.s64_array , packet1.f_array , packet1.d_array );
  69. mavlink_msg_test_types_decode(&msg, &packet2);
  70. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  71. memset(&packet2, 0, sizeof(packet2));
  72. mavlink_msg_test_types_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.c , packet1.s , packet1.u8 , packet1.u16 , packet1.u32 , packet1.u64 , packet1.s8 , packet1.s16 , packet1.s32 , packet1.s64 , packet1.f , packet1.d , packet1.u8_array , packet1.u16_array , packet1.u32_array , packet1.u64_array , packet1.s8_array , packet1.s16_array , packet1.s32_array , packet1.s64_array , packet1.f_array , packet1.d_array );
  73. mavlink_msg_test_types_decode(&msg, &packet2);
  74. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  75. memset(&packet2, 0, sizeof(packet2));
  76. mavlink_msg_to_send_buffer(buffer, &msg);
  77. for (i=0; i<mavlink_msg_get_send_buffer_length(&msg); i++) {
  78. comm_send_ch(MAVLINK_COMM_0, buffer[i]);
  79. }
  80. mavlink_msg_test_types_decode(last_msg, &packet2);
  81. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  82. memset(&packet2, 0, sizeof(packet2));
  83. mavlink_msg_test_types_send(MAVLINK_COMM_1 , packet1.c , packet1.s , packet1.u8 , packet1.u16 , packet1.u32 , packet1.u64 , packet1.s8 , packet1.s16 , packet1.s32 , packet1.s64 , packet1.f , packet1.d , packet1.u8_array , packet1.u16_array , packet1.u32_array , packet1.u64_array , packet1.s8_array , packet1.s16_array , packet1.s32_array , packet1.s64_array , packet1.f_array , packet1.d_array );
  84. mavlink_msg_test_types_decode(last_msg, &packet2);
  85. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  86. }
  87. static void mavlink_test_test(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
  88. {
  89. mavlink_test_test_types(system_id, component_id, last_msg);
  90. }
  91. #ifdef __cplusplus
  92. }
  93. #endif // __cplusplus
  94. #endif // TEST_TESTSUITE_H