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.
76 lines
1.2 KiB
76 lines
1.2 KiB
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"reflect"
|
|
)
|
|
|
|
func main() {
|
|
filename := flag.String("f", "", "Candump filename")
|
|
flag.Parse()
|
|
|
|
var frames <-chan *CanFrame
|
|
last := make(map[interface{}]interface{})
|
|
|
|
switch {
|
|
case len(*filename) > 0:
|
|
fmt.Printf("Open %v\n", *filename)
|
|
frames = readfile(filename)
|
|
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 {
|
|
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())
|
|
//}
|
|
}
|
|
}
|
|
|
|
func readfile(filename *string) <-chan *CanFrame {
|
|
c := make(chan *CanFrame)
|
|
|
|
go func() {
|
|
defer close(c)
|
|
|
|
file, err := os.Open(*filename)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
defer file.Close()
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
for scanner.Scan() {
|
|
text := scanner.Text()
|
|
c <- FromString(&text)
|
|
}
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
}()
|
|
|
|
return c
|
|
}
|
|
|