Path: blob/master/libraries/AP_CANManager/AP_MAVLinkCAN.h
9623 views
/*1* This file is free software: you can redistribute it and/or modify it2* under the terms of the GNU General Public License as published by the3* Free Software Foundation, either version 3 of the License, or4* (at your option) any later version.5*6* This file is distributed in the hope that it will be useful, but7* WITHOUT ANY WARRANTY; without even the implied warranty of8* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.9* See the GNU General Public License for more details.10*11* You should have received a copy of the GNU General Public License along12* with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#pragma once1617#include "AP_CANManager_config.h"1819#if AP_MAVLINKCAN_ENABLED2021#include <AP_HAL/AP_HAL.h>22#include <AP_HAL/utility/RingBuffer.h>23#include <GCS_MAVLink/GCS_MAVLink.h>24#include <AP_HAL/CANIface.h>25#include <AP_HAL/utility/OwnPtr.h>26#include <GCS_MAVLink/GCS.h>2728class AP_MAVLinkCAN {29public:30AP_MAVLinkCAN() {}3132// Handle commands to forward CAN frames to GCS33static bool handle_can_forward(mavlink_channel_t chan, const mavlink_command_int_t &packet, const mavlink_message_t &msg);3435// Handle received MAVLink CAN frames36static void handle_can_frame(const mavlink_message_t &msg);3738// Handle CAN filter modification39static void handle_can_filter_modify(const mavlink_message_t &msg);4041private:42// Callback for receiving CAN frames from CAN bus and sending to GCS43void can_frame_callback(uint8_t bus, const AP_HAL::CANFrame &frame, AP_HAL::CANIface::CanIOFlags flags);4445/*46* Structure to maintain forwarding state47*/48struct {49mavlink_channel_t chan;50uint8_t system_id;51uint8_t component_id;52uint8_t frame_counter;53uint32_t last_callback_enable_ms;54HAL_Semaphore sem;55uint16_t num_filter_ids;56uint16_t *filter_ids;57uint8_t callback_id;58uint8_t callback_bus;59} can_forward;6061// Buffer for storing CAN frames to be sent62struct BufferFrame {63uint8_t bus;64AP_HAL::CANFrame frame;65};6667// Frame buffer for queuing frames68HAL_Semaphore frame_buffer_sem;69ObjectBuffer<BufferFrame> *frame_buffer;7071static AP_MAVLinkCAN *ensure_singleton();7273// Process CAN frame forwarding74void process_frame_buffer();7576// Handle commands to forward CAN frames to GCS77bool _handle_can_forward(mavlink_channel_t chan, const mavlink_command_int_t &packet, const mavlink_message_t &msg);7879// Handle received MAVLink CAN frames80void _handle_can_frame(const mavlink_message_t &msg);8182// Handle CAN filter modification83void _handle_can_filter_modify(const mavlink_message_t &msg);84};8586#endif // AP_MAVLINKCAN_ENABLED878889