-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
57 lines (49 loc) · 1.31 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
48
49
50
51
52
53
54
55
56
57
package main
import (
"log"
"github.com/bluenviron/gomavlib/v3"
"github.com/bluenviron/gomavlib/v3/pkg/dialect"
"github.com/bluenviron/gomavlib/v3/pkg/message"
)
// this example shows how to:
// 1) create a custom dialect from a list of messages
// 2) create a node which understands the custom dialect
// 3) print incoming messages
// this is a custom message.
// It must be prefixed with "Message" and implement the message.Message interface.
type MessageCustom struct {
Param1 uint8
Param2 uint8
Param3 uint32
}
func (*MessageCustom) GetID() uint32 {
return 304
}
func main() {
// create a custom dialect from a list of messages
dialect := &dialect.Dialect{3, []message.Message{
&MessageCustom{},
}}
// create a node which understands the custom dialect
node, err := gomavlib.NewNode(gomavlib.NodeConf{
Endpoints: []gomavlib.EndpointConf{
gomavlib.EndpointSerial{
Device: "/dev/ttyUSB0",
Baud: 57600,
},
},
Dialect: 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 incoming messages
for evt := range node.Events() {
if frm, ok := evt.(*gomavlib.EventFrame); ok {
log.Printf("received: id=%d, %+v\n", frm.Message().GetID(), frm.Message())
}
}
}