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.
73 lines
1.1 KiB
73 lines
1.1 KiB
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
filename := flag.String("f", "", "Candump filename")
|
|
flag.Parse()
|
|
|
|
var frames <-chan *CanFrame
|
|
|
|
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)
|
|
|
|
fmt.Printf("Value %v", PARKING)
|
|
|
|
for event := range events {
|
|
|
|
switch msg := event.(type) {
|
|
default:
|
|
fmt.Println(msg)
|
|
}
|
|
|
|
fmt.Println(event.GetValue())
|
|
|
|
//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
|
|
}
|
|
|