forked from bluenviron/gomavlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignature.go
43 lines (37 loc) · 1.03 KB
/
signature.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
// +build ignore
package main
import (
"fmt"
"github.com/team-rocos/gomavlib"
"github.com/team-rocos/gomavlib/dialects/ardupilotmega"
)
func main() {
// initialize a 6-bytes key. A key can have up to 32 bytes.
key := gomavlib.NewKey([]byte("abcdef"))
// create a node which
// - communicates with a serial port.
// - understands ardupilotmega dialect
// - writes messages with given system id
// - validates incoming messages via InKey
// - sign outgoing messages via OutKey
node, err := gomavlib.NewNode(gomavlib.NodeConf{
Endpoints: []gomavlib.EndpointConf{
gomavlib.EndpointSerial{"/dev/ttyUSB0:57600"},
},
Dialect: ardupilotmega.Dialect,
OutVersion: gomavlib.V2, // V2 is mandatory for signatures
OutSystemId: 10,
InKey: key,
OutKey: key,
})
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())
}
}
}