From 349050edb4c25e11917cfec0bce60e37ab97a68f Mon Sep 17 00:00:00 2001 From: didinst <9f6129a2ddff0d0c6d03169eaa75e3fea1c1770f> Date: Sat, 30 Jul 2022 16:49:19 +0300 Subject: [PATCH] 109 full impl Signed-off-by: didinst <9f6129a2ddff0d0c6d03169eaa75e3fea1c1770f> --- chademo.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/chademo.go b/chademo.go index c1b730d..9497858 100644 --- a/chademo.go +++ b/chademo.go @@ -34,6 +34,12 @@ const ( CONNECTOR_LOCKED ConnectorLock = iota CONNECTOR_UNLOCKED + + BATTERY_COMPATIBLE BatteryCompatible = iota + BATTERY_INCOMPATIBLE + + OPERATING StopControl = iota + SHUTDOWN_STOP ) type VehicleChargingEnabled uint8 @@ -52,6 +58,10 @@ type StationState uint8 type ConnectorLock uint8 +type BatteryCompatible uint8 + +type StopControl uint8 + type ChademoEvent interface { // GetValue Return processed/calculated value and timestamp string GetValue() (interface{}, *string) @@ -213,6 +223,9 @@ func FromCanFrames(frames <-chan *CanFrame) <-chan ChademoEvent { events <- &StationStatus{frame} events <- &StationMalfunction{frame} events <- &VehicleConnectorLock{frame} + events <- &BatteryIncompatibility{frame} + events <- &ChargingSystemMalfunction{frame} + events <- &ChargerStopControl{frame} } } }() @@ -297,6 +310,20 @@ func getConnectorLock(bytes *[]byte) ConnectorLock { return CONNECTOR_UNLOCKED } +func getBatteryCompatibility(bytes *[]uint8) BatteryCompatible { + if isBitSet((*bytes)[5], 3) { + return BATTERY_INCOMPATIBLE + } + return BATTERY_COMPATIBLE +} + +func getChargerStopControl(bytes *[]uint8) StopControl { + if isBitSet((*bytes)[5], 5) { + return SHUTDOWN_STOP + } + return OPERATING +} + func (m MaximumBatteryVoltage) GetValue() (interface{}, *string) { return bytesToUint16(m.payload[4:6]), &m.date } @@ -425,6 +452,18 @@ func (v VehicleConnectorLock) GetValue() (interface{}, *string) { return getConnectorLock(&v.payload), &v.date } +func (b BatteryIncompatibility) GetValue() (interface{}, *string) { + return getBatteryCompatibility(&b.payload), &b.date +} + +func (c ChargingSystemMalfunction) GetValue() (interface{}, *string) { + return getFault(&c.payload, 5, 4), &c.date +} + +func (c ChargerStopControl) GetValue() (interface{}, *string) { + return getChargerStopControl(&c.payload), &c.date +} + func (v VehicleChargingEnabled) String() string { switch v { case DISABLED: @@ -512,3 +551,25 @@ func (c ConnectorLock) String() string { panic("ConnectorLock not implemented") } } + +func (b BatteryCompatible) String() string { + switch b { + case BATTERY_COMPATIBLE: + return "compatible" + case BATTERY_INCOMPATIBLE: + return "incompatible" + default: + panic("BatteryCompatible not implemented") + } +} + +func (s StopControl) String() string { + switch s { + case OPERATING: + return "operating" + case SHUTDOWN_STOP: + return "shutdown or stop charging" + default: + panic("StopControl not implemented") + } +}