{"action":"created","issue":{"url":"https://api.github.com/repos/mavlink/qgroundcontrol/issues/2627","labels_url":"https://api.github.com/repos/mavlink/qgroundcontrol/issues/2627/labels{/name}","comments_url":"https://api.github.com/repos/mavlink/qgroundcontrol/issues/2627/comments","events_url":"https://api.github.com/repos/mavlink/qgroundcontrol/issues/2627/events","html_url":"https://github.com/mavlink/qgroundcontrol/issues/2627","id":126939416,"number":2627,"title":"The sequence number for MavLink messages sent from QGC is not *in sequence*","user":{"login":"dogmaphobic","id":749243,"avatar_url":"https://avatars.githubusercontent.com/u/749243?v=3","gravatar_id":"","url":"https://api.github.com/users/dogmaphobic","html_url":"https://github.com/dogmaphobic","followers_url":"https://api.github.com/users/dogmaphobic/followers","following_url":"https://api.github.com/users/dogmaphobic/following{/other_user}","gists_url":"https://api.github.com/users/dogmaphobic/gists{/gist_id}","starred_url":"https://api.github.com/users/dogmaphobic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dogmaphobic/subscriptions","organizations_url":"https://api.github.com/users/dogmaphobic/orgs","repos_url":"https://api.github.com/users/dogmaphobic/repos","events_url":"https://api.github.com/users/dogmaphobic/events{/privacy}","received_events_url":"https://api.github.com/users/dogmaphobic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2016-01-15T19:23:25Z","updated_at":"2016-01-15T22:04:54Z","closed_at":null,"body":"While trying to process sequence numbers to keep track of packet loss, I run into this issue. I noticed that there were more than one *sequence* and some where incremented by two. @billbonney pointed out that the issue is the way QGC packs and sends messages.\r\n\r\nAs an example, in:\r\n\r\nhttps://github.com/mavlink/qgroundcontrol/blob/master/src/AutoPilotPlugins/AutoPilotPlugin.cc#L99-L106 \r\n\r\nthe message is packed (which calls ```mavlink_finalize_message()```, which calls ```mavlink_finalize_message_chan```, which increments the sequence number):\r\n\r\n```\r\nvoid AutoPilotPlugin::resetAllParametersToDefaults(void)\r\n{\r\n    mavlink_message_t msg;\r\n    MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol();\r\n    mavlink_msg_command_long_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, _vehicle->uas()->getUASID(), 0, MAV_CMD_PREFLIGHT_STORAGE, 0, 2, -1, 0, 0, 0, 0, 0);\r\n    _vehicle->sendMessage(msg);\r\n}\r\n```\r\n\r\nWhen the message is sent in:\r\n\r\nhttps://github.com/mavlink/qgroundcontrol/blob/master/src/Vehicle/Vehicle.cc#L451-L469\r\n\r\nIt is once again processed through ```mavlink_finalize_message_chan```, which increments the sequence again.\r\n\r\n```\r\nvoid Vehicle::_sendMessageOnLink(LinkInterface* link, mavlink_message_t message)\r\n{\r\n    // Make sure this is still a good link\r\n    if (!link || !_links.contains(link) || !link->isConnected()) {\r\n        return;\r\n    }\r\n    // Give the plugin a chance to adjust\r\n    _firmwarePlugin->adjustMavlinkMessage(this, &message);\r\n    static const uint8_t messageKeys[256] = MAVLINK_MESSAGE_CRCS;\r\n    mavlink_finalize_message_chan(&message, _mavlink->getSystemId(), _mavlink->getComponentId(), link->getMavlinkChannel(), message.len, messageKeys[message.msgid]);\r\n    // Write message into buffer, prepending start sign\r\n    uint8_t buffer[MAVLINK_MAX_PACKET_LEN];\r\n    int len = mavlink_msg_to_send_buffer(buffer, &message);\r\n    link->writeBytes((const char*)buffer, len);\r\n}\r\n```\r\n\r\nThat explains why I'm seeing increments by 2 but I have not figured out why I see multiple sequences.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/mavlink/qgroundcontrol/issues/comments/172107190","html_url":"https://github.com/mavlink/qgroundcontrol/issues/2627#issuecomment-172107190","issue_url":"https://api.github.com/repos/mavlink/qgroundcontrol/issues/2627","id":172107190,"user":{"login":"DonLakeFlyer","id":5876851,"avatar_url":"https://avatars.githubusercontent.com/u/5876851?v=3","gravatar_id":"","url":"https://api.github.com/users/DonLakeFlyer","html_url":"https://github.com/DonLakeFlyer","followers_url":"https://api.github.com/users/DonLakeFlyer/followers","following_url":"https://api.github.com/users/DonLakeFlyer/following{/other_user}","gists_url":"https://api.github.com/users/DonLakeFlyer/gists{/gist_id}","starred_url":"https://api.github.com/users/DonLakeFlyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonLakeFlyer/subscriptions","organizations_url":"https://api.github.com/users/DonLakeFlyer/orgs","repos_url":"https://api.github.com/users/DonLakeFlyer/repos","events_url":"https://api.github.com/users/DonLakeFlyer/events{/privacy}","received_events_url":"https://api.github.com/users/DonLakeFlyer/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T22:04:54Z","updated_at":"2016-01-15T22:04:54Z","body":"> Instead of looping through links, it should loop through Vehicles instead.\r\n\r\nThat's not the way it works. A message send is directly connected to a vehicle and only goes out on links which are associated with that Vehicle. Not to all links. Hence the send all being scoped to the Vehicle object."}}