Work ok
Signed-off-by: didinst <9f6129a2ddff0d0c6d03169eaa75e3fea1c1770f>
This commit is contained in:
+10
-7
@@ -5,6 +5,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -12,6 +13,7 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
var frames <-chan *CanFrame
|
||||
last := make(map[interface{}]interface{})
|
||||
|
||||
switch {
|
||||
case len(*filename) > 0:
|
||||
@@ -28,16 +30,17 @@ func main() {
|
||||
|
||||
events := FromCanFrames(frames)
|
||||
|
||||
fmt.Printf("Value %v", PARKING)
|
||||
|
||||
for event := range events {
|
||||
|
||||
switch msg := event.(type) {
|
||||
default:
|
||||
fmt.Println(msg)
|
||||
}
|
||||
eventType := reflect.TypeOf(event)
|
||||
|
||||
fmt.Println(event.GetValue())
|
||||
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())
|
||||
|
||||
+42
-41
@@ -36,7 +36,8 @@ type ContactorVehicleStatus uint8
|
||||
type StopRequest uint8
|
||||
|
||||
type ChademoEvent interface {
|
||||
GetValue() interface{}
|
||||
// GetValue Return processed/calculated value and timestamp string
|
||||
GetValue() (interface{}, *string)
|
||||
}
|
||||
|
||||
type frame struct {
|
||||
@@ -197,84 +198,84 @@ func bytesToUint16(bytes []uint8) uint16 {
|
||||
return result
|
||||
}
|
||||
|
||||
func (m MaximumBatteryVoltage) GetValue() interface{} {
|
||||
return bytesToUint16(m.payload[4:6])
|
||||
func (m MaximumBatteryVoltage) GetValue() (interface{}, *string) {
|
||||
return bytesToUint16(m.payload[4:6]), &m.date
|
||||
}
|
||||
|
||||
func (c ConstChargingRateInd) GetValue() interface{} {
|
||||
return c.payload[6]
|
||||
func (c ConstChargingRateInd) GetValue() (interface{}, *string) {
|
||||
return c.payload[6], &c.date
|
||||
}
|
||||
|
||||
func (b BatteryCapacity) GetValue() interface{} {
|
||||
return 0.1 * float32(bytesToUint16(b.payload[5:7]))
|
||||
func (b BatteryCapacity) GetValue() (interface{}, *string) {
|
||||
return 0.1 * float32(bytesToUint16(b.payload[5:7])), &b.date
|
||||
}
|
||||
|
||||
func (m MaxChargingTimeS) GetValue() interface{} {
|
||||
return 10 * uint16(m.payload[1])
|
||||
func (m MaxChargingTimeS) GetValue() (interface{}, *string) {
|
||||
return 10 * uint16(m.payload[1]), &m.date
|
||||
}
|
||||
|
||||
func (m MaxChargingTimeM) GetValue() interface{} {
|
||||
return m.payload[2]
|
||||
func (m MaxChargingTimeM) GetValue() (interface{}, *string) {
|
||||
return m.payload[2], &m.date
|
||||
}
|
||||
|
||||
func (e EstChargingTimeM) GetValue() interface{} {
|
||||
return e.payload[3]
|
||||
func (e EstChargingTimeM) GetValue() (interface{}, *string) {
|
||||
return e.payload[3], &e.date
|
||||
}
|
||||
|
||||
func (c ControlProtocolNumber) GetValue() interface{} {
|
||||
return c.payload[0]
|
||||
func (c ControlProtocolNumber) GetValue() (interface{}, *string) {
|
||||
return c.payload[0], &c.date
|
||||
}
|
||||
|
||||
func (t TargetBatteryVoltage) GetValue() interface{} {
|
||||
return bytesToUint16(t.payload[1:3])
|
||||
func (t TargetBatteryVoltage) GetValue() (interface{}, *string) {
|
||||
return bytesToUint16(t.payload[1:3]), &t.date
|
||||
}
|
||||
|
||||
func (c ChargingCurrentReq) GetValue() interface{} {
|
||||
return c.payload[3]
|
||||
func (c ChargingCurrentReq) GetValue() (interface{}, *string) {
|
||||
return c.payload[3], &c.date
|
||||
}
|
||||
|
||||
func (c ChargingRate) GetValue() interface{} {
|
||||
return c.payload[6]
|
||||
func (c ChargingRate) GetValue() (interface{}, *string) {
|
||||
return c.payload[6], &c.date
|
||||
}
|
||||
|
||||
func (s ShiftLever) GetValue() interface{} {
|
||||
return getVehicleShiftLever(&s.payload)
|
||||
func (s ShiftLever) GetValue() (interface{}, *string) {
|
||||
return getVehicleShiftLever(&s.payload), &s.date
|
||||
}
|
||||
|
||||
func (v VehicleCharging) GetValue() interface{} {
|
||||
return getVehicleCharging(&v.payload)
|
||||
func (v VehicleCharging) GetValue() (interface{}, *string) {
|
||||
return getVehicleCharging(&v.payload), &v.date
|
||||
}
|
||||
|
||||
func (c ChargingSystemFault) GetValue() interface{} {
|
||||
return getFault(&c.payload, 5, 2)
|
||||
func (c ChargingSystemFault) GetValue() (interface{}, *string) {
|
||||
return getFault(&c.payload, 5, 2), &c.date
|
||||
}
|
||||
|
||||
func (v VehicleStatus) GetValue() interface{} {
|
||||
return getVehicleStatus(&v.payload)
|
||||
func (v VehicleStatus) GetValue() (interface{}, *string) {
|
||||
return getVehicleStatus(&v.payload), &v.date
|
||||
}
|
||||
|
||||
func (n NormalStopReq) GetValue() interface{} {
|
||||
return getNormalStopReq(&n.payload)
|
||||
func (n NormalStopReq) GetValue() (interface{}, *string) {
|
||||
return getNormalStopReq(&n.payload), &n.date
|
||||
}
|
||||
|
||||
func (b BattOvervoltage) GetValue() interface{} {
|
||||
return getFault(&b.payload, 4, 0)
|
||||
func (b BattOvervoltage) GetValue() (interface{}, *string) {
|
||||
return getFault(&b.payload, 4, 0), &b.date
|
||||
}
|
||||
|
||||
func (b BattUndervoltage) GetValue() interface{} {
|
||||
return getFault(&b.payload, 4, 1)
|
||||
func (b BattUndervoltage) GetValue() (interface{}, *string) {
|
||||
return getFault(&b.payload, 4, 1), &b.date
|
||||
}
|
||||
|
||||
func (b BattCurrentDeviationErr) GetValue() interface{} {
|
||||
return getFault(&b.payload, 4, 2)
|
||||
func (b BattCurrentDeviationErr) GetValue() (interface{}, *string) {
|
||||
return getFault(&b.payload, 4, 2), &b.date
|
||||
}
|
||||
|
||||
func (h HighBattTemperature) GetValue() interface{} {
|
||||
return getFault(&h.payload, 4, 3)
|
||||
func (h HighBattTemperature) GetValue() (interface{}, *string) {
|
||||
return getFault(&h.payload, 4, 3), &h.date
|
||||
}
|
||||
|
||||
func (b BattVoltageDeviationErr) GetValue() interface{} {
|
||||
return getFault(&b.payload, 4, 4)
|
||||
func (b BattVoltageDeviationErr) GetValue() (interface{}, *string) {
|
||||
return getFault(&b.payload, 4, 4), &b.date
|
||||
}
|
||||
|
||||
func (v VehicleChargingEnabled) String() string {
|
||||
|
||||
Reference in New Issue
Block a user