2014-12-09 23:00:53 -04:00
|
|
|
/// @file MAVLink_routing.h
|
|
|
|
/// @brief handle routing of MAVLink packets by ID
|
2016-02-17 21:25:55 -04:00
|
|
|
#pragma once
|
2014-12-09 23:00:53 -04:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include "GCS_MAVLink.h"
|
2014-12-09 23:00:53 -04:00
|
|
|
|
2014-12-16 19:30:09 -04:00
|
|
|
// 20 routes should be enough for now. This may need to increase as
|
|
|
|
// we make more extensive use of MAVLink forwarding
|
|
|
|
#define MAVLINK_MAX_ROUTES 20
|
2014-12-09 23:00:53 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
object to handle MAVLink packet routing
|
|
|
|
*/
|
|
|
|
class MAVLink_routing
|
|
|
|
{
|
2016-05-11 06:24:59 -03:00
|
|
|
friend class GCS_MAVLINK;
|
|
|
|
|
2014-12-09 23:00:53 -04:00
|
|
|
public:
|
|
|
|
MAVLink_routing(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
forward a MAVLink message to the right port. This also
|
|
|
|
automatically learns the route for the sender if it is not
|
|
|
|
already known.
|
|
|
|
|
2014-12-16 19:30:09 -04:00
|
|
|
This returns true if the message should be processed locally
|
2014-12-09 23:00:53 -04:00
|
|
|
*/
|
2019-07-11 05:31:45 -03:00
|
|
|
bool check_and_forward(mavlink_channel_t in_channel, const mavlink_message_t &msg);
|
2014-12-09 23:00:53 -04:00
|
|
|
|
2015-03-28 22:36:06 -03:00
|
|
|
/*
|
|
|
|
send a MAVLink message to all components with this vehicle's system id
|
|
|
|
This is a no-op if no routes to components have been learned
|
2019-10-17 04:07:23 -03:00
|
|
|
|
|
|
|
msgid here is the mavlink message ID, pkt is a pointer to a
|
|
|
|
mavlink message structure (e.g. a mavlink_command_long_t)
|
2015-03-28 22:36:06 -03:00
|
|
|
*/
|
2019-10-17 04:07:23 -03:00
|
|
|
void send_to_components(uint32_t msgid, const char *pkt, uint8_t pkt_len);
|
2015-03-28 22:36:06 -03:00
|
|
|
|
2015-07-24 08:52:06 -03:00
|
|
|
/*
|
|
|
|
search for the first vehicle or component in the routing table with given mav_type and retrieve it's sysid, compid and channel
|
|
|
|
returns true if a match is found
|
|
|
|
*/
|
|
|
|
bool find_by_mavtype(uint8_t mavtype, uint8_t &sysid, uint8_t &compid, mavlink_channel_t &channel);
|
|
|
|
|
2014-12-09 23:00:53 -04:00
|
|
|
private:
|
|
|
|
// a simple linear routing table. We don't expect to have a lot of
|
|
|
|
// routes, so a scalable structure isn't worthwhile yet.
|
|
|
|
uint8_t num_routes;
|
|
|
|
struct route {
|
|
|
|
uint8_t sysid;
|
|
|
|
uint8_t compid;
|
|
|
|
mavlink_channel_t channel;
|
2015-07-24 08:52:06 -03:00
|
|
|
uint8_t mavtype;
|
2014-12-09 23:00:53 -04:00
|
|
|
} routes[MAVLINK_MAX_ROUTES];
|
2016-05-11 06:24:59 -03:00
|
|
|
|
|
|
|
// a channel mask to block routing as required
|
2016-07-12 02:01:50 -03:00
|
|
|
uint8_t no_route_mask;
|
2016-05-11 06:24:59 -03:00
|
|
|
|
2014-12-09 23:00:53 -04:00
|
|
|
// learn new routes
|
2019-07-11 05:31:45 -03:00
|
|
|
void learn_route(mavlink_channel_t in_channel, const mavlink_message_t &msg);
|
2014-12-09 23:00:53 -04:00
|
|
|
|
|
|
|
// extract target sysid and compid from a message
|
2019-07-11 05:31:45 -03:00
|
|
|
void get_targets(const mavlink_message_t &msg, int16_t &sysid, int16_t &compid);
|
2014-12-09 23:00:53 -04:00
|
|
|
|
|
|
|
// special handling for heartbeat messages
|
2019-07-11 05:31:45 -03:00
|
|
|
void handle_heartbeat(mavlink_channel_t in_channel, const mavlink_message_t &msg);
|
2019-10-17 04:07:23 -03:00
|
|
|
|
|
|
|
void send_to_components(const char *pkt, const mavlink_msg_entry_t *entry, uint8_t pkt_len);
|
2014-12-09 23:00:53 -04:00
|
|
|
};
|