mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-06 19:00:27 +08:00
AP_CANManager: create a new class for MAVLink CAN
This commit is contained in:
committed by
Andrew Tridgell
parent
62fadb915c
commit
0ba6e570d3
File diff suppressed because it is too large
Load Diff
@@ -28,8 +28,7 @@
|
||||
#include "AP_CANDriver.h"
|
||||
#include <GCS_MAVLink/GCS_config.h>
|
||||
#if HAL_GCS_ENABLED
|
||||
#include <GCS_MAVLink/GCS_MAVLink.h>
|
||||
#include <AP_HAL/utility/RingBuffer.h>
|
||||
#include "AP_MAVLinkCAN.h"
|
||||
#endif
|
||||
|
||||
#include "AP_CAN.h"
|
||||
@@ -106,9 +105,20 @@ public:
|
||||
static const struct AP_Param::GroupInfo var_info[];
|
||||
|
||||
#if HAL_GCS_ENABLED
|
||||
bool handle_can_forward(mavlink_channel_t chan, const mavlink_command_int_t &packet, const mavlink_message_t &msg);
|
||||
void handle_can_frame(const mavlink_message_t &msg);
|
||||
void handle_can_filter_modify(const mavlink_message_t &msg);
|
||||
inline bool handle_can_forward(mavlink_channel_t chan, const mavlink_command_int_t &packet, const mavlink_message_t &msg)
|
||||
{
|
||||
return mavlink_can.handle_can_forward(chan, packet, msg);
|
||||
}
|
||||
|
||||
inline void handle_can_frame(const mavlink_message_t &msg)
|
||||
{
|
||||
mavlink_can.handle_can_frame(msg);
|
||||
}
|
||||
|
||||
inline void handle_can_filter_modify(const mavlink_message_t &msg)
|
||||
{
|
||||
mavlink_can.handle_can_filter_modify(msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
@@ -183,33 +193,8 @@ private:
|
||||
HAL_Semaphore _sem;
|
||||
|
||||
#if HAL_GCS_ENABLED
|
||||
/*
|
||||
handler for CAN frames from the registered callback, sending frames
|
||||
out as CAN_FRAME messages
|
||||
*/
|
||||
void can_frame_callback(uint8_t bus, const AP_HAL::CANFrame &frame, AP_HAL::CANIface::CanIOFlags flags);
|
||||
|
||||
struct {
|
||||
mavlink_channel_t chan;
|
||||
uint8_t system_id;
|
||||
uint8_t component_id;
|
||||
uint8_t frame_counter;
|
||||
uint32_t last_callback_enable_ms;
|
||||
HAL_Semaphore sem;
|
||||
uint16_t num_filter_ids;
|
||||
uint16_t *filter_ids;
|
||||
uint8_t callback_id;
|
||||
uint8_t callback_bus;
|
||||
} can_forward;
|
||||
|
||||
// buffer for MAVCAN frames
|
||||
struct BufferFrame {
|
||||
uint8_t bus;
|
||||
AP_HAL::CANFrame frame;
|
||||
};
|
||||
ObjectBuffer<BufferFrame> *frame_buffer;
|
||||
|
||||
void process_frame_buffer(void);
|
||||
// Class for handling MAVLink CAN frames
|
||||
AP_MAVLinkCAN mavlink_can;
|
||||
#endif // HAL_GCS_ENABLED
|
||||
|
||||
#if AP_CAN_LOGGING_ENABLED && HAL_LOGGING_ENABLED
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AP_HAL/AP_HAL.h>
|
||||
#include <AP_HAL/utility/RingBuffer.h>
|
||||
#include "AP_CANManager_config.h"
|
||||
|
||||
#if HAL_CANMANAGER_ENABLED && HAL_GCS_ENABLED
|
||||
|
||||
#include <GCS_MAVLink/GCS_MAVLink.h>
|
||||
#include <AP_HAL/CANIface.h>
|
||||
#include <AP_HAL/utility/OwnPtr.h>
|
||||
#include <GCS_MAVLink/GCS.h>
|
||||
|
||||
class AP_MAVLinkCAN {
|
||||
public:
|
||||
AP_MAVLinkCAN() {}
|
||||
|
||||
// Process CAN frame forwarding
|
||||
void process_frame_buffer();
|
||||
|
||||
// Handle commands to forward CAN frames to GCS
|
||||
bool handle_can_forward(mavlink_channel_t chan, const mavlink_command_int_t &packet, const mavlink_message_t &msg);
|
||||
|
||||
// Handle received MAVLink CAN frames
|
||||
void handle_can_frame(const mavlink_message_t &msg);
|
||||
|
||||
// Handle CAN filter modification
|
||||
void handle_can_filter_modify(const mavlink_message_t &msg);
|
||||
|
||||
private:
|
||||
// Callback for receiving CAN frames from CAN bus and sending to GCS
|
||||
void can_frame_callback(uint8_t bus, const AP_HAL::CANFrame &frame, AP_HAL::CANIface::CanIOFlags flags);
|
||||
|
||||
/*
|
||||
* Structure to maintain forwarding state
|
||||
*/
|
||||
struct {
|
||||
mavlink_channel_t chan;
|
||||
uint8_t system_id;
|
||||
uint8_t component_id;
|
||||
uint8_t frame_counter;
|
||||
uint32_t last_callback_enable_ms;
|
||||
HAL_Semaphore sem;
|
||||
uint16_t num_filter_ids;
|
||||
uint16_t *filter_ids;
|
||||
uint8_t callback_id;
|
||||
uint8_t callback_bus;
|
||||
} can_forward;
|
||||
|
||||
// Buffer for storing CAN frames to be sent
|
||||
struct BufferFrame {
|
||||
uint8_t bus;
|
||||
AP_HAL::CANFrame frame;
|
||||
};
|
||||
|
||||
// Frame buffer for queuing frames
|
||||
ObjectBuffer<BufferFrame> *frame_buffer;
|
||||
};
|
||||
|
||||
#endif // HAL_CANMANAGER_ENABLED && HAL_GCS_ENABLED
|
||||
Reference in New Issue
Block a user