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
import (
"git.binarythought.com/cdramey/sdb"
"git.binarythought.com/cdramey/sutron"
"fmt"
"bytes"
@ -16,28 +15,22 @@ func main() {
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 {
fmt.Fprintf(os.Stderr,
"error reading \"%s\": %s\n",
os.Args[1], err.Error())
}
sdbdata, err := sdb.ParseSDB(raw)
if err != nil {
fmt.Fprintf(os.Stderr,
"%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:])
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())
@ -49,6 +42,4 @@ func main() {
fmt.Printf("Sutron Delta: %s\n", string(sutrondata.Delta))
fmt.Printf("Sutron Voltage: %s\n", string(sutrondata.Voltage))
}
}
}
}

View File

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