Line data Source code
1 : /// @file GCS_MAVLink.h 2 : /// @brief One size fits all header for MAVLink integration. 3 : #pragma once 4 : 5 : #include <AP_HAL/AP_HAL_Boards.h> 6 : #include <AP_Networking/AP_Networking_Config.h> 7 : 8 : // we have separate helpers disabled to make it possible 9 : // to select MAVLink 1.0 in the arduino GUI build 10 : #define MAVLINK_SEPARATE_HELPERS 11 : #define MAVLINK_NO_CONVERSION_HELPERS 12 : 13 : #define MAVLINK_SEND_UART_BYTES(chan, buf, len) comm_send_buffer(chan, buf, len) 14 : 15 : #define MAVLINK_START_UART_SEND(chan, size) comm_send_lock(chan, size) 16 : #define MAVLINK_END_UART_SEND(chan, size) comm_send_unlock(chan) 17 : 18 : #ifndef MAVLINK_COMM_NUM_BUFFERS 19 : #if CONFIG_HAL_BOARD == HAL_BOARD_SITL 20 : #define MAVLINK_COMM_NUM_BUFFERS 16 21 : #elif HAL_PROGRAM_SIZE_LIMIT_KB > 1024 22 : // allow 8 telemetry ports, allowing for extra networking or CAN ports 23 : #define MAVLINK_COMM_NUM_BUFFERS 8 24 : #else 25 : // allow five telemetry ports 26 : #define MAVLINK_COMM_NUM_BUFFERS 5 27 : #endif 28 : #endif // MAVLINK_COMM_NUM_BUFFERS 29 : 30 : typedef uint32_t mavlink_channel_mask_t; 31 : 32 : #define MAVLINK_GET_CHANNEL_BUFFER 1 33 : #define MAVLINK_GET_CHANNEL_STATUS 1 34 : 35 : /* 36 : The MAVLink protocol code generator does its own alignment, so 37 : alignment cast warnings can be ignored 38 : */ 39 : #pragma GCC diagnostic push 40 : #pragma GCC diagnostic ignored "-Wcast-align" 41 : 42 : #if defined(__GNUC__) && __GNUC__ >= 9 43 : #pragma GCC diagnostic ignored "-Waddress-of-packed-member" 44 : #endif 45 : 46 : #include "include/mavlink/v2.0/all/version.h" 47 : 48 : #define MAVLINK_MAX_PAYLOAD_LEN 255 49 : 50 : #include "include/mavlink/v2.0/mavlink_types.h" 51 : 52 : /// MAVLink streams used for each telemetry port 53 : extern AP_HAL::UARTDriver *mavlink_comm_port[MAVLINK_COMM_NUM_BUFFERS]; 54 : extern bool gcs_alternative_active[MAVLINK_COMM_NUM_BUFFERS]; 55 : 56 : /// MAVLink system definition 57 : extern mavlink_system_t mavlink_system; 58 : 59 : /// Sanity check MAVLink channel 60 : /// 61 : /// @param chan Channel to send to 62 106080885 : static inline bool valid_channel(mavlink_channel_t chan) 63 : { 64 106080885 : return static_cast<int>(chan) < MAVLINK_COMM_NUM_BUFFERS; 65 : } 66 : 67 : mavlink_message_t* mavlink_get_channel_buffer(uint8_t chan); 68 : mavlink_status_t* mavlink_get_channel_status(uint8_t chan); 69 : 70 : void comm_send_buffer(mavlink_channel_t chan, const uint8_t *buf, uint8_t len); 71 : 72 : /// Check for available transmit space on the nominated MAVLink channel 73 : /// 74 : /// @param chan Channel to check 75 : /// @returns Number of bytes available 76 : uint16_t comm_get_txspace(mavlink_channel_t chan); 77 : 78 : #define MAVLINK_USE_CONVENIENCE_FUNCTIONS 79 : 80 : #pragma GCC diagnostic push 81 : // mavlink relies on strncpy() supporting deliberate truncation 82 : #if !defined(__clang__) // avoid -Wunknown-warning-option 83 : #pragma GCC diagnostic ignored "-Wstringop-truncation" 84 : #endif // clang 85 : #include "include/mavlink/v2.0/all/mavlink.h" 86 : #pragma GCC diagnostic pop 87 : 88 : // lock and unlock a channel, for multi-threaded mavlink send 89 : void comm_send_lock(mavlink_channel_t chan, uint16_t size); 90 : void comm_send_unlock(mavlink_channel_t chan); 91 : HAL_Semaphore &comm_chan_lock(mavlink_channel_t chan); 92 : 93 : #pragma GCC diagnostic pop