Removed sdb dependency
This commit is contained in:
parent
4f034e132e
commit
6a9d3e1a0f
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.binarythought.com/cdramey/sdb"
|
||||
"git.binarythought.com/cdramey/sutron"
|
||||
"fmt"
|
||||
"bytes"
|
||||
@ -16,39 +15,31 @@ 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:])
|
||||
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))
|
||||
}
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user