a Go library and command line utility for reading values from a Sutron data logger
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
909 B

package main
import (
"git.binarythought.com/cdramey/sutron"
"fmt"
"bytes"
"io/ioutil"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr,
"required argument missing\n")
os.Exit(1)
}
var raw []byte
var err error
if os.Args[1] == "-" {
raw, err = ioutil.ReadAll(os.Stdin)
} else {
raw, err = ioutil.ReadFile(os.Args[1])
}
if err != nil {
fmt.Fprintf(os.Stderr,
"error reading \"%s\": %s\n",
os.Args[1], err.Error())
}
i := bytes.Index(raw, []byte("B"))
if i != -1 {
sutrondata, err := sutron.ParseSutronB(raw[i:])
if err != nil {
fmt.Fprintf(os.Stderr,
"%s\n", err.Error())
os.Exit(1)
}
fmt.Printf("Sutron Block: %s\n", string(sutrondata.Block))
fmt.Printf("Sutron Group: %s\n", string(sutrondata.Group))
fmt.Printf("Sutron Delta: %s\n", string(sutrondata.Delta))
fmt.Printf("Sutron Voltage: %s\n", string(sutrondata.Voltage))
}
}