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

Q: Custom routing to a specific channel/endpoint #2

Closed
gediminasgu opened this issue May 24, 2021 · 2 comments
Closed

Q: Custom routing to a specific channel/endpoint #2

gediminasgu opened this issue May 24, 2021 · 2 comments
Labels
question Further information is requested

Comments

@gediminasgu
Copy link

Thank you for a great example of the mavlink router on Go. I really like it.

I have a question. I'm routing messages between all endpoints as it is presented in an example (https://github.com/aler9/mavp2p/blob/main/main.go#L220). But for one endpoint (microcontroller which runs on serial) I want to route just some specific messages to do not overload it with all incoming traffic.

When creating a node, I need to pass endpoints (https://github.com/aler9/mavp2p/blob/main/main.go#L153) but later we need to operate with channels (https://github.com/aler9/mavp2p/blob/main/main.go#L220). Is it possible to get a channel from an endpoint? Or any other ideas on how to implement the following logic:

  • Send a message to all channels except my specific endpoint
  • Send a message to my specific endpoint only if the message ID is X.

I would be very thankful for ideas here.

@aler9 aler9 added the question Further information is requested label May 30, 2021
@aler9
Copy link
Member

aler9 commented May 30, 2021

Hello, i'm a little rusty about this project since i did it almost 3 years ago, but if i remember correctly you should be able to perform this task by by writing a very simple Golang program and instantiating two nodes:

  • one with all the endpoints except the serial one
  • another with the serial endpoint
package main

import (
	"fmt"

	"github.com/aler9/gomavlib"
)

func main() {
	node1, err := gomavlib.NewNode(gomavlib.NodeConf{
		Endpoints: []gomavlib.EndpointConf{
			gomavlib.EndpointUDPClient{"1.2.3.4:5900"},
			// insert any other endpoint here
		},
		Dialect:     nil,
		OutVersion:  gomavlib.V2, // change to V1 if you're unable to communicate with the target
		OutSystemID: 10,
	})
	if err != nil {
		panic(err)
	}
	defer node1.Close()

	node2, err := gomavlib.NewNode(gomavlib.NodeConf{
		Endpoints: []gomavlib.EndpointConf{
			gomavlib.EndpointSerial{"/dev/ttyUSB0:57600"},
		},
		Dialect:     nil,
		OutVersion:  gomavlib.V2, // change to V1 if you're unable to communicate with the target
		OutSystemID: 11,
	})
	if err != nil {
		panic(err)
	}
	defer node2.Close()

	for evt := range node1.Events() {
		if frm, ok := evt.(*gomavlib.EventFrame); ok {
			// route frame to every other channel
			node.WriteFrameExcept(frm.Channel, frm.Frame)

		 	// route to serial only if a certain condition is satisfied
			if conditionSatisfied {
				node2.WriteFrameAll(frm.Frame)
			}
		}
	}
}

@gediminasgu
Copy link
Author

That's exactly how I did solve it. Thank you a lot for a comprehensive answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants