Removed sdb dependency

This commit is contained in:
Christopher Ramey 2019-10-06 15:23:50 -08:00 committed by Christopher Ramey
parent 4f034e132e
commit 6a9d3e1a0f
2 changed files with 19 additions and 29 deletions

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"git.binarythought.com/cdramey/sdb"
"git.binarythought.com/cdramey/sutron" "git.binarythought.com/cdramey/sutron"
"fmt" "fmt"
"bytes" "bytes"
@ -16,28 +15,22 @@ func main() {
os.Exit(1) os.Exit(1)
} }
raw, err := ioutil.ReadFile(os.Args[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 { if err != nil {
fmt.Fprintf(os.Stderr, fmt.Fprintf(os.Stderr,
"error reading \"%s\": %s\n", "error reading \"%s\": %s\n",
os.Args[1], err.Error()) os.Args[1], err.Error())
} }
sdbdata, err := sdb.ParseSDB(raw) i := bytes.Index(raw, []byte("B"))
if err != nil { if i != -1 {
fmt.Fprintf(os.Stderr, sutrondata, err := sutron.ParseSutronB(raw[i:])
"%s\n", err.Error())
os.Exit(1)
}
for _, i := range sdbdata.Elements {
switch v := i.(type) {
case sdb.MOPayload:
// Seek forward to the First "B" - Sadly necessary
// in certain scenarios
l := bytes.Index(v.Payload, []byte("B"))
if l != -1 {
sutrondata, err := sutron.ParseSutronB(v.Payload[l:])
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, fmt.Fprintf(os.Stderr,
"%s\n", err.Error()) "%s\n", err.Error())
@ -49,6 +42,4 @@ func main() {
fmt.Printf("Sutron Delta: %s\n", string(sutrondata.Delta)) fmt.Printf("Sutron Delta: %s\n", string(sutrondata.Delta))
fmt.Printf("Sutron Voltage: %s\n", string(sutrondata.Voltage)) fmt.Printf("Sutron Voltage: %s\n", string(sutrondata.Voltage))
} }
}
}
} }

View File

@ -1,7 +1,6 @@
package sutron package sutron
import ( import (
// "encoding/binary"
"fmt" "fmt"
) )