forked from bluenviron/gomavlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (41 loc) · 1.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"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.EndpointSerial{"/dev/ttyUSB0:57600"},
},
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()
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,
})
}
}
}
}