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.
59 lines
1.2 KiB
59 lines
1.2 KiB
package main
|
|
|
|
import (
|
|
"cli-mon/can"
|
|
"cli-mon/ui"
|
|
"cli-mon/yabl"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"reflect"
|
|
)
|
|
|
|
func main() {
|
|
filename := flag.String("f", "", "Candump filename")
|
|
canbus := flag.String("i", "", "CAN bus interface")
|
|
stdin := flag.Bool("s", false, "Read from stdin")
|
|
gui := flag.Bool("gui", false, "Text mode gui")
|
|
flag.Parse()
|
|
|
|
var frames <-chan *can.CanFrame
|
|
|
|
switch {
|
|
case *stdin:
|
|
frames = can.ReadStdin()
|
|
case len(*filename) > 0:
|
|
frames = can.Readfile(filename)
|
|
case len(*canbus) > 0:
|
|
var err error
|
|
frames, err = can.StartCan(*canbus)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
default:
|
|
flag.Usage()
|
|
}
|
|
|
|
if frames == nil {
|
|
fmt.Println("Get no data")
|
|
os.Exit(0)
|
|
}
|
|
|
|
var messages = yabl.StartProtocolParsing(frames)
|
|
|
|
if *gui {
|
|
ui.InitCliApp(messages)
|
|
} else {
|
|
for msg := range messages {
|
|
// val := getField(msg.Object, msg.Field)
|
|
fmt.Printf("%v %v.%v [%d] %v\n", msg.Updated.Format("Jan _2 15:04:05.000"), msg.ActionName, msg.Field, msg.UnitId, msg.Value)
|
|
}
|
|
}
|
|
}
|
|
|
|
func getField(v yabl.Action, field yabl.FName) interface{} {
|
|
r := reflect.ValueOf(v)
|
|
f := reflect.Indirect(r).FieldByName(string(field))
|
|
return f.Interface()
|
|
}
|
|
|