route messages by target system ID and component ID #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR resolves #18
This PR adds some basic routing functionality to the mavp2p tool. I tried my best to follow the standard as defined in - https://mavlink.io/en/guide/routing.html
I apologies for my Go skills, its my first time using Go!
The following rules are iterated over every connected node, every time a message is received:
If the message is of type COMMAND_LONG, COMMAND_ACK or COMMAND_INT then, read the
target_system
andtarget_component
from it and mark therouteMsg
variable true. Otherwise broadcast it.if target_system is more than 0 (non-broadcasted) then route it, otherwise broadcast it
if routeMsg { if targetSystem > 0 { // Route only if it's non-broadcast command
if target_system matches the system id of one of the connected nodes then proceed with routing, otherwise discard
for remoteNode := range nh.remoteNodes { // Iterates through connected nodes
if remoteNode.SystemID == targetSystem {
If target_component matches a node or set to broadcast then route, otherwise discard
if remoteNode.ComponentID == targetComponent || targetComponent < 1 { // Route if compid matches or is a broadcast
Does a check that the message is not addressed to itself, if it is then it discards and prints a warning
if remoteNode.Channel != evt.Channel { // Prevents Loops
Finally, if all of these criteria are met then the message is sent to the node
node.WriteFrameTo(remoteNode.Channel, evt.Frame)
When the cli arg

--print-routes
is used we can see the behaviour of the routed frames. Eg, here is the interaction of a GCS connecting to a camera video stream using this camera protocol - https://mavlink.io/en/services/camera.html#video_streaming. The COMMAND_LONGS are replied with COMMAND_ACKS etc. (I censored our public IP here)Known Issues that should be fixed before merging:
target_system
field. I’m not sure right now how to check for every incoming message.So we'd need to allow for some nodes to be marked as loggers or listeners or whatever...