Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry log endpoint feature #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Features:
* serial
* UDP (client, server or broadcast mode)
* TCP (client or server mode)
* Telemetry log
* Support Mavlink 2.0 and 1.0, support any dialect
* Emit heartbeats
* Automatically request streams to Ardupilot devices and block stream requests from ground stations
Expand Down Expand Up @@ -128,6 +129,8 @@ Arguments:

udps:listen_ip:port (udp, server mode)

tlog:filename (telemetry log)

Flags:
-h, --help Show context-sensitive help.
--version print version.
Expand Down
34 changes: 34 additions & 0 deletions endpoint_tlog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"io"
"os"
"time"
"encoding/binary"
)

type TlogWriter struct {
file *os.File
io.Closer
}

// can't read from the log, but we don't want to error out either
func (t *TlogWriter) Read(_ []byte) (int, error) {
// FIXME: this runs in a gorountine so it's somewhat safe to lock up
// TODO: but we need a way to get out of there too
for {
}
return 0, nil
}

func (t *TlogWriter) Write(b []byte) (n int, e error) {
// 64 bit timestamp in microseconds (big endian)
var usec uint64 = uint64(time.Now().UnixNano() / 1000)
e = binary.Write(t.file, binary.BigEndian, usec)
if e != nil {
return 0, e
}

n, e = t.file.Write(b)
return n + 8, e
}
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ var endpointTypes = map[string]endpointType{
return gomavlib.EndpointTCPClient{Address: args}, nil
},
},
"tlog": {
"filename",
"telemetry log",
func(args string) (gomavlib.EndpointConf, error) {
fp, err := os.Create(args)
if err != nil {
return nil, fmt.Errorf("Unable to open file %s", args)
}
tlog := &TlogWriter{
file: fp,
Closer: fp,
}
return gomavlib.EndpointCustom{ReadWriteCloser: tlog}, nil
},
},
}

func generateEndpointConfs(endpoints []string) ([]gomavlib.EndpointConf, error) {
Expand Down