mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-21 07:13:56 -04:00
GCS_MAVLink: correct encoding used for send_to_components
These have to be packed onto the channel - otherwise they may ge tencoded as mavlink1 instead of mavlink2 (or vice-versa)
This commit is contained in:
parent
5f6b3a1f5b
commit
a96a4c0510
@ -259,8 +259,8 @@ public:
|
|||||||
send a MAVLink message to all components with this vehicle's system id
|
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
|
This is a no-op if no routes to components have been learned
|
||||||
*/
|
*/
|
||||||
static void send_to_components(const mavlink_message_t &msg) { routing.send_to_components(msg); }
|
static void send_to_components(uint32_t msgid, const char *pkt, uint8_t pkt_len) { routing.send_to_components(msgid, pkt, pkt_len); }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
allow forwarding of packets / heartbeats to be blocked as required by some components to reduce traffic
|
allow forwarding of packets / heartbeats to be blocked as required by some components to reduce traffic
|
||||||
*/
|
*/
|
||||||
|
@ -184,27 +184,54 @@ bool MAVLink_routing::check_and_forward(mavlink_channel_t in_channel, const mavl
|
|||||||
|
|
||||||
This is a no-op if no routes to components have been learned
|
This is a no-op if no routes to components have been learned
|
||||||
*/
|
*/
|
||||||
void MAVLink_routing::send_to_components(const mavlink_message_t &msg)
|
void MAVLink_routing::send_to_components(uint32_t msgid, const char *pkt, uint8_t pkt_len)
|
||||||
{
|
{
|
||||||
bool sent_to_chan[MAVLINK_COMM_NUM_BUFFERS];
|
const mavlink_msg_entry_t *entry = mavlink_get_msg_entry(msgid);
|
||||||
memset(sent_to_chan, 0, sizeof(sent_to_chan));
|
if (entry == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
send_to_components(pkt, entry, pkt_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MAVLink_routing::send_to_components(const char *pkt, const mavlink_msg_entry_t *entry, const uint8_t pkt_len)
|
||||||
|
{
|
||||||
|
bool sent_to_chan[MAVLINK_COMM_NUM_BUFFERS] {};
|
||||||
|
|
||||||
// check learned routes
|
// check learned routes
|
||||||
for (uint8_t i=0; i<num_routes; i++) {
|
for (uint8_t i=0; i<num_routes; i++) {
|
||||||
if ((routes[i].sysid == mavlink_system.sysid) && !sent_to_chan[routes[i].channel]) {
|
if (routes[i].sysid != mavlink_system.sysid) {
|
||||||
if (comm_get_txspace(routes[i].channel) >= ((uint16_t)msg.len) +
|
// our system ID hasn't been seen on this link
|
||||||
GCS_MAVLINK::packet_overhead_chan(routes[i].channel)) {
|
continue;
|
||||||
#if ROUTING_DEBUG
|
|
||||||
::printf("send msg %u on chan %u sysid=%u compid=%u\n",
|
|
||||||
msg.msgid,
|
|
||||||
(unsigned)routes[i].channel,
|
|
||||||
(unsigned)routes[i].sysid,
|
|
||||||
(unsigned)routes[i].compid);
|
|
||||||
#endif
|
|
||||||
_mavlink_resend_uart(routes[i].channel, &msg);
|
|
||||||
sent_to_chan[routes[i].channel] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (sent_to_chan[routes[i].channel]) {
|
||||||
|
// we've already send it on this link
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (comm_get_txspace(routes[i].channel) <
|
||||||
|
((uint16_t)entry->max_msg_len) + GCS_MAVLINK::packet_overhead_chan(routes[i].channel)) {
|
||||||
|
// it doesn't fit on this channel
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#if ROUTING_DEBUG
|
||||||
|
::printf("send msg %u on chan %u sysid=%u compid=%u\n",
|
||||||
|
msg.msgid,
|
||||||
|
(unsigned)routes[i].channel,
|
||||||
|
(unsigned)routes[i].sysid,
|
||||||
|
(unsigned)routes[i].compid);
|
||||||
|
#endif
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
||||||
|
if (entry->max_msg_len > pkt_len) {
|
||||||
|
AP_HAL::panic("Passed packet message length (%u > %u)",
|
||||||
|
entry->max_msg_len, pkt_len);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
_mav_finalize_message_chan_send(routes[i].channel,
|
||||||
|
entry->msgid,
|
||||||
|
pkt,
|
||||||
|
entry->min_msg_len,
|
||||||
|
MIN(entry->max_msg_len, pkt_len),
|
||||||
|
entry->crc_extra);
|
||||||
|
sent_to_chan[routes[i].channel] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,11 @@ public:
|
|||||||
/*
|
/*
|
||||||
send a MAVLink message to all components with this vehicle's system id
|
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
|
This is a no-op if no routes to components have been learned
|
||||||
|
|
||||||
|
msgid here is the mavlink message ID, pkt is a pointer to a
|
||||||
|
mavlink message structure (e.g. a mavlink_command_long_t)
|
||||||
*/
|
*/
|
||||||
void send_to_components(const mavlink_message_t &msg);
|
void send_to_components(uint32_t msgid, const char *pkt, uint8_t pkt_len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
search for the first vehicle or component in the routing table with given mav_type and retrieve it's sysid, compid and channel
|
search for the first vehicle or component in the routing table with given mav_type and retrieve it's sysid, compid and channel
|
||||||
@ -63,4 +66,6 @@ private:
|
|||||||
|
|
||||||
// special handling for heartbeat messages
|
// special handling for heartbeat messages
|
||||||
void handle_heartbeat(mavlink_channel_t in_channel, const mavlink_message_t &msg);
|
void handle_heartbeat(mavlink_channel_t in_channel, const mavlink_message_t &msg);
|
||||||
|
|
||||||
|
void send_to_components(const char *pkt, const mavlink_msg_entry_t *entry, uint8_t pkt_len);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user