Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic protocol version handshake #5233

Merged
merged 9 commits into from
Jul 31, 2017
Merged

Automatic protocol version handshake #5233

merged 9 commits into from
Jul 31, 2017

Conversation

LorenzMeier
Copy link
Member

This extension allows to negotiate with all connected vehicles the highest possible MAVLink version supported by all. It is compatible with legacy vehicle software (interprets NACK and timeouts as v1.0 requests). This allows to have the best possible version enabled without any user configuration.

Before connecting QGC:

instance #0:
	mavlink chan: #0
	no telem status.
	flow control:	OFF
	rates:
	tx: 23.215 kB/s
	txerr: 0.000 kB/s
	rx: 0.000 kB/s
	rate mult: 1.000
	accepting commands: YES
	MAVLink version: 1
	transport protocol: UDP (14556)

After connecting QGC with this extension:

instance #0:
	GCS heartbeat:	988721 us ago
	mavlink chan: #0
	type:		GENERIC LINK OR RADIO
	flow control:	OFF
	rates:
	tx: 30.495 kB/s
	txerr: 0.000 kB/s
	rx: 0.021 kB/s
	rate mult: 1.000
	accepting commands: YES
	MAVLink version: 2
	transport protocol: UDP (14556)

@LorenzMeier
Copy link
Member Author

Matching firmware PR: PX4/PX4-Autopilot#7344

@LorenzMeier
Copy link
Member Author

@DonLakeFlyer Firmware PR is through. If you can review / cross-test we can get this in (but its not needed for v3.2).

@LorenzMeier
Copy link
Member Author

@DonLakeFlyer
Copy link
Contributor

DonLakeFlyer commented Jun 4, 2017

This isn't quite right. It treats all links as a single group. Either mavlink 1 or 2 based on lowest common denominator vehicle reporting. It should really be on a link by link basis based only on the vehicles on the specific link. That said, I think that gets way more complicated. This should be fine for 3.2. And maybe forever.

I still don't get how if there is a radio that doesn't support mav 2 in the middle how this works. Mavlink defaults to mav 1 for status flags doesn't it? So initial send of MAV_CMD_REQUEST_PROTOCOL_VERSION will be over mavlink 1 protocol. And it will go through. Is the link supposed to start out as mav 2 and then fall back? If so I don't see the code for that.

@LorenzMeier
Copy link
Member Author

@DonLakeFlyer The reason I don't want to treat it link-by-link, vehicle-by-vehicle is that managing that configuration space is super error prone (imagine that you can send geofence over one link, but not over another - how do you want to deal with that?). Anyone who knows what he is doing will use MAVLink 2 exclusively. The only reason to have detection and fallback is to ensure that random users don't get bitten when they upgrade to a new QGC version and their old plane is not yet supporting MAVLink 2 throughout.

But really, the main focus here is to enable a safe upgrade path - I'm not really trying to support mixed setups.

In terms of detection: The trick is that the PROTOCOL_VERSION message is sent in MAVLink 2 framing. That ensures that the link supports 2.0. But the message will in the future be also important for cases where we have v2.1 or v2.5.

@LorenzMeier
Copy link
Member Author

This is good to go. If the remote vehicle does not support discovery but sends MAVLink 2 it will stick with that as default.

@LorenzMeier
Copy link
Member Author

LorenzMeier commented Jun 17, 2017

@DonLakeFlyer I haven't tested this yet on hardware, but wanted to see if it fits the flash. This branch teaches the SiK radio to respond properly to PROTOCOL_VERSION, which in turn would allow QGC to detect wether or not the radio can do MAVLink 2. It likely will require adjustments to this pull, but this would be the watertight solution.

LorenzMeier/SiK#1

@LorenzMeier
Copy link
Member Author

I will test this one round more and then get it in. @bkueng This is needed for polygons and stuff as it switches the system automatically.

@LorenzMeier
Copy link
Member Author

Re-tested: With just USB connected the link auto-switches to MAVLink 2, with a 3DR Radio it stays at MAVLink 1. And with forced MAVLink 2 it also seems to work:

nsh> mavlink status

instance #0:
	GCS heartbeat:	810149 us ago
	mavlink chan: #0
	type:		3DR RADIO
	rssi:		219
	remote rssi:	219
	txbuf:		100
	noise:		56
	remote noise:	45
	rx errors:	0
	fixed:		0
	flow control:	ON
	rates:
	tx: 0.138 kB/s
	txerr: 0.000 kB/s
	rx: 0.059 kB/s
	rate mult: 0.058
	accepting commands: YES
	MAVLink version: 2
	transport protocol: serial (/dev/ttyS1 @57600)

instance #1:
	mavlink chan: #1
	no telem status.
	flow control:	OFF
	rates:
	tx: 0.308 kB/s
	txerr: 0.000 kB/s
	rx: 0.014 kB/s
	rate mult: 0.050
	accepting commands: YES
	MAVLink version: 2
	transport protocol: serial (/dev/ttyS2 @57600)

instance #2:
	GCS heartbeat:	877322 us ago
	mavlink chan: #2
	type:		USB CDC
	flow control:	OFF
	rates:
	tx: 1.518 kB/s
	txerr: 0.000 kB/s
	rx: 0.021 kB/s
	rate mult: 1.000
	accepting commands: YES
	MAVLink version: 2
	transport protocol: serial (/dev/ttyACM0 @2000000)
nsh> 

From QGC output: Switching outbound to mavlink 2.0 due to incoming mavlink 2.0 packet

@LorenzMeier
Copy link
Member Author

This still needs work - I still need to test with the upgraded radio.

@DonLakeFlyer
Copy link
Contributor

Looking through this I can't quite see if it delays the initial plan request until it knows the mavlink version?

This extension introduces a complete version handshake mechanism which will detect wether the vehicle AND the complete link / routing infrastructure support MAVLink 2. If they do, QGC will switch to the highest protocol version supported by all connected vehicles. If a new vehicle connects, it will re-negotiate the highest possible version. This means that we error on the side of compatibility, which later can be easily changed.
…two links to the same vehicle are connected and one can only do v1
This is important to avoid having QGC hijack links that are active (we read 2000 bytes!) but are definitely not MAVLink. This can have nasty side-effects, e.g. if we would talk to an LTE modem in a laptop or alike.
@LorenzMeier
Copy link
Member Author

LorenzMeier commented Jul 30, 2017

@DonLakeFlyer Yes it does, because it queues the command requesting the protocol version and only fully initializes when that is received.

I've also taken care of the SiK / 3DR radio: This PR now contains an updated link to a stable build that is a) MAVLink 2.0 enabled and b) reacts correctly to the handshaking mechanism. Code for that is here: LorenzMeier/SiK#1

If a user has not yet updated his 3DR radio QGC will tell him now. It will still work as a link but fall back to MAVLink 1 automatically with a pop-up warning the user. With this addition this should be watertight and good upgrade path for the user base. It's properly documented, takes care of the corner cases and does not leave existing users behind.

@dogmaphobic You will want to upgrade your ESP8266 bridge too. Here are the handshaking docs: https://mavlink.io/en/mavlink-version.html

From my side this is now all good to go.

@DonLakeFlyer
Copy link
Contributor

Yes it does, because it queues the command requesting the protocol version and only fully initializes when that is received.

I still don't see how this causes _startPlanRequest to not be called until the protocol version is known. The code in Vehicle still triggers _startPlanRequest on capability bits known and parameters ready. I don't see any checked for protocol being known as well.

@LorenzMeier
Copy link
Member Author

Let me re-check it. I was relatively certain that the remaining load could not happen until the first commands were handled, but I might have missed a parallel code path. I will update here.

@LorenzMeier
Copy link
Member Author

@DonLakeFlyer I made the dependency explicit.

@DonLakeFlyer
Copy link
Contributor

@LorenzMeier Yup. Looks good. Any reason to not merge now. Then I can use this in my GeoFence stuff as well.

@LorenzMeier LorenzMeier merged commit db714c2 into master Jul 31, 2017
@LorenzMeier LorenzMeier deleted the proto_ver branch July 31, 2017 21:34
@LorenzMeier
Copy link
Member Author

Ok, merged.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants