APM:Libraries
MAVLink_routing.h
Go to the documentation of this file.
1 #pragma once
4 
5 #include <AP_HAL/AP_HAL.h>
6 #include <AP_Common/AP_Common.h>
7 #include "GCS_MAVLink.h"
8 
9 // 20 routes should be enough for now. This may need to increase as
10 // we make more extensive use of MAVLink forwarding
11 #define MAVLINK_MAX_ROUTES 20
12 
13 /*
14  object to handle MAVLink packet routing
15  */
17 {
18  friend class GCS_MAVLINK;
19 
20 public:
21  MAVLink_routing(void);
22 
23  /*
24  forward a MAVLink message to the right port. This also
25  automatically learns the route for the sender if it is not
26  already known.
27 
28  This returns true if the message should be processed locally
29  */
30  bool check_and_forward(mavlink_channel_t in_channel, const mavlink_message_t* msg);
31 
32  /*
33  send a MAVLink message to all components with this vehicle's system id
34  This is a no-op if no routes to components have been learned
35  */
36  void send_to_components(const mavlink_message_t* msg);
37 
38  /*
39  search for the first vehicle or component in the routing table with given mav_type and retrieve it's sysid, compid and channel
40  returns true if a match is found
41  */
42  bool find_by_mavtype(uint8_t mavtype, uint8_t &sysid, uint8_t &compid, mavlink_channel_t &channel);
43 
44 private:
45  // a simple linear routing table. We don't expect to have a lot of
46  // routes, so a scalable structure isn't worthwhile yet.
47  uint8_t num_routes;
48  struct route {
49  uint8_t sysid;
50  uint8_t compid;
51  mavlink_channel_t channel;
52  uint8_t mavtype;
54 
55  // a channel mask to block routing as required
56  uint8_t no_route_mask;
57 
58  // learn new routes
59  void learn_route(mavlink_channel_t in_channel, const mavlink_message_t* msg);
60 
61  // extract target sysid and compid from a message
62  void get_targets(const mavlink_message_t* msg, int16_t &sysid, int16_t &compid);
63 
64  // special handling for heartbeat messages
65  void handle_heartbeat(mavlink_channel_t in_channel, const mavlink_message_t* msg);
66 };
Common definitions and utility routines for the ArduPilot libraries.