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.

154 lines
6.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /** @file
  2. * @brief MAVLink comm protocol testsuite generated from minimal.xml
  3. * @see http://qgroundcontrol.org/mavlink/
  4. */
  5. #pragma once
  6. #ifndef MINIMAL_TESTSUITE_H
  7. #define MINIMAL_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_minimal(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_minimal(system_id, component_id, last_msg);
  17. }
  18. #endif
  19. static void mavlink_test_heartbeat(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_HEARTBEAT >= 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_heartbeat_t packet_in = {
  31. 963497464,17,84,151,218,3
  32. };
  33. mavlink_heartbeat_t packet1, packet2;
  34. memset(&packet1, 0, sizeof(packet1));
  35. packet1.custom_mode = packet_in.custom_mode;
  36. packet1.type = packet_in.type;
  37. packet1.autopilot = packet_in.autopilot;
  38. packet1.base_mode = packet_in.base_mode;
  39. packet1.system_status = packet_in.system_status;
  40. packet1.mavlink_version = packet_in.mavlink_version;
  41. #ifdef MAVLINK_STATUS_FLAG_OUT_MAVLINK1
  42. if (status->flags & MAVLINK_STATUS_FLAG_OUT_MAVLINK1) {
  43. // cope with extensions
  44. memset(MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN + (char *)&packet1, 0, sizeof(packet1)-MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN);
  45. }
  46. #endif
  47. memset(&packet2, 0, sizeof(packet2));
  48. mavlink_msg_heartbeat_encode(system_id, component_id, &msg, &packet1);
  49. mavlink_msg_heartbeat_decode(&msg, &packet2);
  50. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  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. memset(&packet2, 0, sizeof(packet2));
  56. 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 );
  57. mavlink_msg_heartbeat_decode(&msg, &packet2);
  58. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  59. memset(&packet2, 0, sizeof(packet2));
  60. mavlink_msg_to_send_buffer(buffer, &msg);
  61. for (i=0; i<mavlink_msg_get_send_buffer_length(&msg); i++) {
  62. comm_send_ch(MAVLINK_COMM_0, buffer[i]);
  63. }
  64. mavlink_msg_heartbeat_decode(last_msg, &packet2);
  65. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  66. memset(&packet2, 0, sizeof(packet2));
  67. mavlink_msg_heartbeat_send(MAVLINK_COMM_1 , packet1.type , packet1.autopilot , packet1.base_mode , packet1.custom_mode , packet1.system_status );
  68. mavlink_msg_heartbeat_decode(last_msg, &packet2);
  69. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  70. }
  71. static void mavlink_test_protocol_version(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
  72. {
  73. #ifdef MAVLINK_STATUS_FLAG_OUT_MAVLINK1
  74. mavlink_status_t *status = mavlink_get_channel_status(MAVLINK_COMM_0);
  75. if ((status->flags & MAVLINK_STATUS_FLAG_OUT_MAVLINK1) && MAVLINK_MSG_ID_PROTOCOL_VERSION >= 256) {
  76. return;
  77. }
  78. #endif
  79. mavlink_message_t msg;
  80. uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
  81. uint16_t i;
  82. mavlink_protocol_version_t packet_in = {
  83. 17235,17339,17443,{ 151, 152, 153, 154, 155, 156, 157, 158 },{ 175, 176, 177, 178, 179, 180, 181, 182 }
  84. };
  85. mavlink_protocol_version_t packet1, packet2;
  86. memset(&packet1, 0, sizeof(packet1));
  87. packet1.version = packet_in.version;
  88. packet1.min_version = packet_in.min_version;
  89. packet1.max_version = packet_in.max_version;
  90. mav_array_memcpy(packet1.spec_version_hash, packet_in.spec_version_hash, sizeof(uint8_t)*8);
  91. mav_array_memcpy(packet1.library_version_hash, packet_in.library_version_hash, sizeof(uint8_t)*8);
  92. #ifdef MAVLINK_STATUS_FLAG_OUT_MAVLINK1
  93. if (status->flags & MAVLINK_STATUS_FLAG_OUT_MAVLINK1) {
  94. // cope with extensions
  95. memset(MAVLINK_MSG_ID_PROTOCOL_VERSION_MIN_LEN + (char *)&packet1, 0, sizeof(packet1)-MAVLINK_MSG_ID_PROTOCOL_VERSION_MIN_LEN);
  96. }
  97. #endif
  98. memset(&packet2, 0, sizeof(packet2));
  99. mavlink_msg_protocol_version_encode(system_id, component_id, &msg, &packet1);
  100. mavlink_msg_protocol_version_decode(&msg, &packet2);
  101. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  102. memset(&packet2, 0, sizeof(packet2));
  103. mavlink_msg_protocol_version_pack(system_id, component_id, &msg , packet1.version , packet1.min_version , packet1.max_version , packet1.spec_version_hash , packet1.library_version_hash );
  104. mavlink_msg_protocol_version_decode(&msg, &packet2);
  105. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  106. memset(&packet2, 0, sizeof(packet2));
  107. mavlink_msg_protocol_version_pack_chan(system_id, component_id, MAVLINK_COMM_0, &msg , packet1.version , packet1.min_version , packet1.max_version , packet1.spec_version_hash , packet1.library_version_hash );
  108. mavlink_msg_protocol_version_decode(&msg, &packet2);
  109. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  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_protocol_version_decode(last_msg, &packet2);
  116. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  117. memset(&packet2, 0, sizeof(packet2));
  118. mavlink_msg_protocol_version_send(MAVLINK_COMM_1 , packet1.version , packet1.min_version , packet1.max_version , packet1.spec_version_hash , packet1.library_version_hash );
  119. mavlink_msg_protocol_version_decode(last_msg, &packet2);
  120. MAVLINK_ASSERT(memcmp(&packet1, &packet2, sizeof(packet1)) == 0);
  121. }
  122. static void mavlink_test_minimal(uint8_t system_id, uint8_t component_id, mavlink_message_t *last_msg)
  123. {
  124. mavlink_test_heartbeat(system_id, component_id, last_msg);
  125. mavlink_test_protocol_version(system_id, component_id, last_msg);
  126. }
  127. #ifdef __cplusplus
  128. }
  129. #endif // __cplusplus
  130. #endif // MINIMAL_TESTSUITE_H