diff --git a/libraries/GCS_MAVLink/MAVLink_routing.cpp b/libraries/GCS_MAVLink/MAVLink_routing.cpp index f4cebd1f40..3f7ac03e70 100644 --- a/libraries/GCS_MAVLink/MAVLink_routing.cpp +++ b/libraries/GCS_MAVLink/MAVLink_routing.cpp @@ -186,6 +186,26 @@ void MAVLink_routing::send_to_components(const mavlink_message_t* msg) } } +/* + 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 MAVLink_routing::find_by_mavtype(uint8_t mavtype, uint8_t &sysid, uint8_t &compid, mavlink_channel_t &channel) +{ + // check learned routes + for (uint8_t i=0; isysid && routes[i].compid == msg->compid && routes[i].channel == in_channel) { + if (routes[i].mavtype == 0 && msg->msgid == MAVLINK_MSG_ID_HEARTBEAT) { + routes[i].mavtype = mavlink_msg_heartbeat_get_type(msg); + } break; } } @@ -208,6 +231,9 @@ void MAVLink_routing::learn_route(mavlink_channel_t in_channel, const mavlink_me routes[i].sysid = msg->sysid; routes[i].compid = msg->compid; routes[i].channel = in_channel; + if (msg->msgid == MAVLINK_MSG_ID_HEARTBEAT) { + routes[i].mavtype = mavlink_msg_heartbeat_get_type(msg); + } num_routes++; #if ROUTING_DEBUG ::printf("learned route %u %u via %u\n", diff --git a/libraries/GCS_MAVLink/MAVLink_routing.h b/libraries/GCS_MAVLink/MAVLink_routing.h index 2c59c22061..3db08b60fc 100644 --- a/libraries/GCS_MAVLink/MAVLink_routing.h +++ b/libraries/GCS_MAVLink/MAVLink_routing.h @@ -41,6 +41,12 @@ public: */ void send_to_components(const mavlink_message_t* msg); + /* + 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); + private: // a simple linear routing table. We don't expect to have a lot of // routes, so a scalable structure isn't worthwhile yet. @@ -49,6 +55,7 @@ private: uint8_t sysid; uint8_t compid; mavlink_channel_t channel; + uint8_t mavtype; } routes[MAVLINK_MAX_ROUTES]; // learn new routes