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.1 KiB
59 lines
1.1 KiB
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"reflect"
|
|
)
|
|
|
|
func main() {
|
|
filename := flag.String("f", "", "Candump filename")
|
|
canbus := flag.String("c", "", "CAN bus interface")
|
|
all := flag.Bool("a", false, "Show all packets")
|
|
flag.Parse()
|
|
|
|
var frames <-chan *CanFrame
|
|
last := make(map[interface{}]interface{})
|
|
|
|
switch {
|
|
case len(*filename) > 0:
|
|
fmt.Printf("Open file %v\n", *filename)
|
|
frames = Readfile(filename)
|
|
case len(*canbus) > 0:
|
|
fmt.Printf("Open device %v\n", canbus)
|
|
var err error
|
|
frames, err = StartCan(*canbus)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
default:
|
|
flag.Usage()
|
|
}
|
|
|
|
if frames == nil {
|
|
fmt.Println("Get no data")
|
|
os.Exit(0)
|
|
}
|
|
|
|
events := FromCanFrames(frames)
|
|
|
|
for event := range events {
|
|
|
|
eventType := reflect.TypeOf(event)
|
|
|
|
lastValue := last[eventType]
|
|
value, date := event.GetValue()
|
|
|
|
if lastValue != value || *all {
|
|
fmt.Printf("%v | %s = %v\n", *date, eventType, value)
|
|
last[eventType] = value
|
|
}
|
|
|
|
//if msg, isType := event.(MaximumBatteryVoltage); isType {
|
|
// fmt.Printf("MaximumBatteryVoltage: %v\n", msg.GetMaxBattVoltage())
|
|
//}
|
|
}
|
|
}
|
|
|