-
Notifications
You must be signed in to change notification settings - Fork 57
Hello, I wanted to set up a minimal working example of message interchange between two processes on my machine using UDP broadcast. So far I have this:
Broadcaster
package main import ( "fmt" "mavtest" "github.com/aler9/gomavlib" "github.com/aler9/gomavlib/pkg/dialects/ardupilotmega" ) func main() { // create a node which // - communicates with a serial port // - understands ardupilotmega dialect // - writes messages with given system id node, err := gomavlib.NewNode(gomavlib.NodeConf{ Endpoints: []gomavlib.EndpointConf{ gomavlib.EndpointUDPBroadcast{BroadcastAddress: "192.168.1.255:5660"}, }, Dialect: ardupilotmega.Dialect, OutVersion: gomavlib.V2, // change to V1 if you're unable to communicate with the target OutSystemID: 1, }) if err != nil { panic(err) } defer node.Close() msg := &ardupilotmega.MessageParamValue{ ParamId: "test_parameter", ParamValue: 123456, ParamType: ardupilotmega.MAV_PARAM_TYPE_UINT32, } node.WriteMessageAll(msg) for evt := range node.Events() { if frm, ok := evt.(*gomavlib.EventFrame); ok { fmt.Printf("received: id=%d, %+v\n", frm.Message().GetID(), frm.Message()) // if message is a parameter read request addressed to this node if msg, ok := frm.Message().(*ardupilotmega.MessageParamRequestRead); ok && msg.TargetSystem == 10 && msg.TargetComponent == 1 && msg.ParamId == "test_parameter" { // reply to sender (and no one else) and provide the requested parameter node.WriteMessageTo(frm.Channel, &ardupilotmega.MessageParamValue{ ParamId: "test_parameter", ParamValue: 123456, ParamType: ardupilotmega.MAV_PARAM_TYPE_UINT32, }) } } } }
Client
package main import ( "fmt" "mavtest" "github.com/aler9/gomavlib" "github.com/aler9/gomavlib/pkg/dialects/ardupilotmega" ) func main() { // create a node which // - communicates with an UDP endpoint in client mode // - understands ardupilotmega dialect // - writes messages with given system id node, err := gomavlib.NewNode(gomavlib.NodeConf{ Endpoints: []gomavlib.EndpointConf{ gomavlib.EndpointUDPClient{"0.0.0.0:5660"}, }, Dialect: ardupilotmega.Dialect, OutVersion: gomavlib.V2, // change to V1 if you're unable to communicate with the target OutSystemID: 10, }) if err != nil { panic(err) } defer node.Close() // print every message we receive for evt := range node.Events() { if frm, ok := evt.(*gomavlib.EventFrame); ok { fmt.Printf("received: id=%d, %+v\n", frm.Message().GetID(), frm.Message()) } } }
But no messages are coming through on either of them.
All reactions
Replies: 1 comment
Hello, in order to use broadcast you have to use two different PCs; in one of them (the one which is sending telemetry) you have to use use a broadcast endpoint
gomavlib.EndpointUDPBroadcast{BroadcastAddress: "192.168.1.255:5660"}
In the other (the one that is reading telemetry), a server endpoint
gomavlib.EndpointUDPServer{Address: "0.0.0.0:5660"}
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment