Show mavlink packet loss somewhere in toolbar dropdown
Hello
I have come across this code snippet in the MAVLinkProtocol.cc file:
totalReceiveCounter[mavlinkChannel]++;
currReceiveCounter[mavlinkChannel]++;
// Determine what the next expected sequence number is, accounting for
// never having seen a message for this system/component pair.
int lastSeq = lastIndex[message.sysid][message.compid];
int expectedSeq = (lastSeq == -1) ? message.seq : (lastSeq + 1);
// And if we didn't encounter that sequence number, record the error
if (message.seq != expectedSeq)
{
// Determine how many messages were skipped
int lostMessages = message.seq - expectedSeq;
// Out of order messages or wraparound can cause this, but we just ignore these conditions for simplicity
if (lostMessages < 0)
{
lostMessages = 0;
}
// And log how many were lost for all time and just this timestep
totalLossCounter[mavlinkChannel] += lostMessages;
currLossCounter[mavlinkChannel] += lostMessages;
}
// And update the last sequence number for this system/component pair
lastIndex[message.sysid][message.compid] = expectedSeq;
// Update on every 32th packet
if ((totalReceiveCounter[mavlinkChannel] & 0x1F) == 0)
{
// Calculate new loss ratio
// Receive loss
float receiveLossPercent = (double)currLossCounter[mavlinkChannel]/(double)(currReceiveCounter[mavlinkChannel]+currLossCounter[mavlinkChannel]);
receiveLossPercent *= 100.0f;
currLossCounter[mavlinkChannel] = 0;
currReceiveCounter[mavlinkChannel] = 0;
emit receiveLossPercentChanged(message.sysid, receiveLossPercent);
emit receiveLossTotalChanged(message.sysid, totalLossCounter[mavlinkChannel]);
}
The loss % calculated by this method fluctuates a lot and also i am unable to find where the variable lastIndex is reset.
Can you suggest a more reliable method to calculate RSSI based on packet losses.
Thanks
I don't think the values calculated here are exposed in the QGC ui anywhere. Hence it could easily be buggy. Othen than using sequence numbers I don't see a way to determine packet loss. So theoretically this code or something like it could give you decent information. Assuming vehicle side is sending correct sequence numbers. Any fixes to make it work would be helpful. Then we can figure out where to expose in ui.
seems like an easy place for packet% status would be inside the telemetry details pop-up with the other stats:

Hmm. @dogmaphobic Where do those numbers come from?
Where do those numbers come from?
From the RADIO_STATUS message (http://mavlink.org/messages/common#RADIO_STATUS). The SiK radios actually populate these with real values. The ESP8266/WiFi thingy fills in what it can (it doesn't have all values). Not sure about others.
So the mavlink packet loss stuff is valid for all connection types. The telemetry toolbar thingy shows up for both SiK Radio and UDP connections then I assume? So that may make it a decent place for the mavlink data. Although it's already quite crowded in there.
MAVLink packet loss is shown in the Settings -> MAVlink page. I think adding to Telemetry dropdown makes sense.