mavlink.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. mavlink class for handling OpenDroneID messages
  3. */
  4. #pragma once
  5. // we have separate helpers disabled to make it possible
  6. // to select MAVLink 1.0 in the arduino GUI build
  7. #define MAVLINK_SEPARATE_HELPERS
  8. #define MAVLINK_NO_CONVERSION_HELPERS
  9. #define MAVLINK_SEND_UART_BYTES(chan, buf, len) comm_send_buffer(chan, buf, len)
  10. // two buffers, one for USB, one for UART. This makes for easier testing with SITL
  11. #define MAVLINK_COMM_NUM_BUFFERS 2
  12. #define MAVLINK_MAX_PAYLOAD_LEN 255
  13. #include <mavlink2.h>
  14. /// MAVLink system definition
  15. extern mavlink_system_t mavlink_system;
  16. void comm_send_buffer(mavlink_channel_t chan, const uint8_t *buf, uint8_t len);
  17. #define MAVLINK_USE_CONVENIENCE_FUNCTIONS
  18. #include <generated/all/mavlink.h>
  19. /*
  20. abstraction for MAVLink on a serial port
  21. */
  22. class MAVLinkSerial {
  23. public:
  24. MAVLinkSerial(HardwareSerial &serial, mavlink_channel_t chan);
  25. void init(void);
  26. void update(void);
  27. const mavlink_open_drone_id_location_t &get_location(void) const {
  28. return location;
  29. }
  30. const mavlink_open_drone_id_basic_id_t &get_basic_id(void) const {
  31. return basic_id;
  32. }
  33. const mavlink_open_drone_id_authentication_t &get_authentication(void) const {
  34. return authentication;
  35. }
  36. const mavlink_open_drone_id_self_id_t &get_self_id(void) const {
  37. return self_id;
  38. }
  39. const mavlink_open_drone_id_system_t &get_system(void) const {
  40. return system;
  41. }
  42. const mavlink_open_drone_id_operator_id_t &get_operator_id(void) const {
  43. return operator_id;
  44. }
  45. // return true when we have the key messages available
  46. bool initialised(void);
  47. private:
  48. HardwareSerial &serial;
  49. mavlink_channel_t chan;
  50. uint32_t last_hb_ms;
  51. enum {
  52. PKT_LOCATION = (1U<<0),
  53. PKT_BASIC_ID = (1U<<1),
  54. PKT_AUTHENTICATION = (1U<<2),
  55. PKT_SELF_ID = (1U<<3),
  56. PKT_SYSTEM = (1U<<4),
  57. PKT_OPERATOR_ID = (1U<<5),
  58. };
  59. void update_receive(void);
  60. void update_send(void);
  61. void process_packet(mavlink_status_t &status, mavlink_message_t &msg);
  62. void mav_printf(uint8_t severity, const char *fmt, ...);
  63. mavlink_open_drone_id_location_t location;
  64. mavlink_open_drone_id_basic_id_t basic_id;
  65. mavlink_open_drone_id_authentication_t authentication;
  66. mavlink_open_drone_id_self_id_t self_id;
  67. mavlink_open_drone_id_system_t system;
  68. mavlink_open_drone_id_operator_id_t operator_id;
  69. uint32_t last_system_msg_ms;
  70. uint32_t packets_received_mask;
  71. };