-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmain.go
50 lines (42 loc) · 1008 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/bluenviron/gomavlib/v3/pkg/dialect"
"github.com/bluenviron/gomavlib/v3/pkg/dialects/ardupilotmega"
"github.com/bluenviron/gomavlib/v3/pkg/tlog"
)
// this example shows how to:
// 1) open a telemetry log file.
// 2) print every telemetry log entry present inside the file.
func main() {
// open a telemetry log file.
f, err := os.Open("my-telemetry-log.tlog")
if err != nil {
panic(err)
}
defer f.Close()
// allocate dialect reader / writer.
dialectRW := &dialect.ReadWriter{Dialect: ardupilotmega.Dialect}
err = dialectRW.Initialize()
if err != nil {
panic(err)
}
// allocate telemetry log reader.
dec := tlog.Reader{
ByteReader: f,
DialectRW: dialectRW,
}
err = dec.Initialize()
if err != nil {
panic(err)
}
// print every telemetry log entry present inside the file.
for {
entry, err := dec.Read()
if err != nil {
panic(err)
}
fmt.Printf("date: %s message: %+v\n", entry.Time, entry.Frame.GetMessage())
}
}