github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/examples/endpoint-udp-broadcast/main.go (about) 1 package main 2 3 import ( 4 "log" 5 6 "github.com/bluenviron/gomavlib/v2" 7 "github.com/bluenviron/gomavlib/v2/pkg/dialects/ardupilotmega" 8 ) 9 10 // this example shows how to: 11 // 1) create a node which communicates with a UDP endpoint in broadcast mode 12 // 2) print incoming messages 13 14 func main() { 15 // create a node which communicates with a UDP endpoint in broadcast mode 16 node, err := gomavlib.NewNode(gomavlib.NodeConf{ 17 Endpoints: []gomavlib.EndpointConf{ 18 gomavlib.EndpointUDPBroadcast{BroadcastAddress: "192.168.7.255:5600"}, 19 }, 20 Dialect: ardupilotmega.Dialect, 21 OutVersion: gomavlib.V2, // change to V1 if you're unable to communicate with the target 22 OutSystemID: 10, 23 }) 24 if err != nil { 25 panic(err) 26 } 27 defer node.Close() 28 29 // print incoming messages 30 for evt := range node.Events() { 31 if frm, ok := evt.(*gomavlib.EventFrame); ok { 32 log.Printf("received: id=%d, %+v\n", frm.Message().GetID(), frm.Message()) 33 } 34 } 35 }