Events instead raw frames

Signed-off-by: didinst <9f6129a2ddff0d0c6d03169eaa75e3fea1c1770f>
feature/evse-to-ev-win
didinst 3 years ago
parent 11f1f179d9
commit 781d83297e
Signed by untrusted user who does not match committer: didinst
GPG Key ID: 2EA0BE33BF9516AD
  1. 302
      chademo.go

@ -9,29 +9,29 @@ const (
CAN_ID_101 = 101 CAN_ID_101 = 101
CAN_ID_102 = 102 CAN_ID_102 = 102
DISABLED VehicleCharging = iota DISABLED VehicleChargingEnabled = iota
ENABLED ENABLED
PARKING ShiftLever = iota PARKING ShiftLeverPosition = iota
OTHER OTHER
NORMAL SystemFault = iota NORMAL SystemFault = iota
FAULT FAULT
CONTACTOR_CLOSED VehicleStatus = iota CONTACTOR_CLOSED ContactorVehicleStatus = iota
CONTACTOR_OPEN CONTACTOR_OPEN
NO_REQUEST StopRequest = iota NO_REQUEST StopRequest = iota
STOP_REQUEST STOP_REQUEST
) )
type VehicleCharging uint8 type VehicleChargingEnabled uint8
type ShiftLever uint8 type ShiftLeverPosition uint8
type SystemFault uint8 type SystemFault uint8
type VehicleStatus uint8 type ContactorVehicleStatus uint8
type StopRequest uint8 type StopRequest uint8
@ -39,47 +39,69 @@ type ChademoEvent interface {
GetValue() interface{} GetValue() interface{}
} }
type MaximumBatteryVoltage interface { type frame struct {
// GetMaxBattVoltage Maximum battery voltage *CanFrame
GetMaxBattVoltage() uint16
} }
type ConstChargingRateInd interface { // MaximumBatteryVoltage The maximum voltage value at the vehicle inlet terminals, at which the station stops charging to protect the vehicle battery
// GetChargingRate Constant of charging rate indication type MaximumBatteryVoltage frame
GetChargingRate() uint8
}
type frame100 struct { // ConstChargingRateInd Fixed value for charging rate indication, which is the maximum charging rate (100 %) of vehicle battery
maxBattVoltage uint16 // The maximum voltage value at the vehicle inlet terminals, at which the station stops charging to protect the vehicle battery type ConstChargingRateInd frame
chargingRateInd uint8 // Fixed value for charging rate indication, which is the maximum charging rate (100 %) of vehicle battery
date string
}
type frame101 struct { // BatteryCapacity Rated capacity of battery
batteryCapacity float32 // Rated capacity of battery type BatteryCapacity frame
maxChargingTimeS uint16 // Maximum charging time permitted by EV, set by 10 s
maxChargingTimeM uint8 // Maximum charging time permitted by EV, set by minute
estChargingTimeM uint8 // Estimated remaining time before the end of charging calculated by EV
date string
}
type frame102 struct { // MaxChargingTimeS Maximum charging time permitted by EV, set by 10 s
controlProtocolNumber uint8 // Software version of control protocol to which EV corresponds type MaxChargingTimeS frame
targetBatteryVoltage uint16 // Target battery voltage ed charging voltage at the vehicle inlet terminals
chargingCurrentReq uint8 // Current value requested by EV during charging // MaxChargingTimeM Maximum charging time permitted by EV, set by minute
chargingRate uint8 // Charging rate of vehicle battery type MaxChargingTimeM frame
vehicleCharging VehicleCharging // Status flag indicating charge permission status of EV
shiftLever ShiftLever // Status flag indicating the shift lever position // EstChargingTimeM Estimated remaining time before the end of charging calculated by EV
chargingSystemFault SystemFault // Status flag indicating Charging system fault a malfunction caused by EV or the station, and detected by EV type EstChargingTimeM frame
vehicleStatus VehicleStatus // Status flag indicating the EV contactor status
normalStopReq StopRequest // Status flag indicating the request of EV to stop charging control // ControlProtocolNumber Software version of control protocol to which EV corresponds
battOvervoltage SystemFault // Status flag indicating whether or not the vehicle battery voltage exceeds the maximum limit specified by EV type ControlProtocolNumber frame
battUndervoltage SystemFault // Status flag indicating whether or not the vehicle battery voltage is less than the lower limit specified by EV
battCurrentDeviationErr SystemFault // Status flag indicating whether or not the output current deviates from EV requested current // TargetBatteryVoltage Target battery voltage ed charging voltage at the vehicle inlet terminals
highBattTemperature SystemFault // Status flag indicating whether or not the temperature of vehicle battery exceeds the maximum limit type TargetBatteryVoltage frame
battVoltageDeviationErr SystemFault // Status flag indicating whether or not the vehicle battery voltage deviates from the output voltage measured by the station
date string // ChargingCurrentReq Current value requested by EV during charging
} type ChargingCurrentReq frame
// ChargingRate Charging rate of vehicle battery
type ChargingRate frame
// VehicleCharging Status flag indicating charge permission status of EV
type VehicleCharging frame
// ShiftLever Status flag indicating the shift lever position
type ShiftLever frame
// ChargingSystemFault Status flag indicating Charging system fault a malfunction caused by EV or the station, and detected by EV
type ChargingSystemFault frame
// VehicleStatus Status flag indicating the EV contactor status
type VehicleStatus frame
// NormalStopReq Status flag indicating the request of EV to stop charging control
type NormalStopReq frame
// BattOvervoltage Status flag indicating whether or not the vehicle battery voltage exceeds the maximum limit specified by EV
type BattOvervoltage frame
// BattUndervoltage Status flag indicating whether or not the vehicle battery voltage is less than the lower limit specified by EV
type BattUndervoltage frame
// BattCurrentDeviationErr Status flag indicating whether or not the output current deviates from EV requested current
type BattCurrentDeviationErr frame
// HighBattTemperature Status flag indicating whether or not the temperature of vehicle battery exceeds the maximum limit
type HighBattTemperature frame
// BattVoltageDeviationErr Status flag indicating whether or not the vehicle battery voltage deviates from the output voltage measured by the station
type BattVoltageDeviationErr frame
func FromCanFrames(frames <-chan *CanFrame) <-chan ChademoEvent { func FromCanFrames(frames <-chan *CanFrame) <-chan ChademoEvent {
events := make(chan ChademoEvent) events := make(chan ChademoEvent)
@ -90,41 +112,28 @@ func FromCanFrames(frames <-chan *CanFrame) <-chan ChademoEvent {
for frame := range frames { for frame := range frames {
switch frame.canid { switch frame.canid {
case CAN_ID_100: case CAN_ID_100:
event := &frame100{ events <- &MaximumBatteryVoltage{frame}
maxBattVoltage: bytesToUint16(frame.payload[4:6]), events <- &ConstChargingRateInd{frame}
chargingRateInd: frame.payload[6],
date: frame.date,
}
events <- event
case CAN_ID_101: case CAN_ID_101:
event := &frame101{ events <- &BatteryCapacity{frame}
batteryCapacity: 0.1 * float32(bytesToUint16(frame.payload[5:7])), events <- &MaxChargingTimeS{frame}
maxChargingTimeS: 10 * uint16(frame.payload[1]), events <- &MaxChargingTimeM{frame}
maxChargingTimeM: frame.payload[2], events <- &EstChargingTimeM{frame}
estChargingTimeM: frame.payload[3],
date: frame.date,
}
fmt.Println(event)
//events <- event
case CAN_ID_102: case CAN_ID_102:
event := &frame102{ events <- &ControlProtocolNumber{frame}
controlProtocolNumber: frame.payload[0], events <- &TargetBatteryVoltage{frame}
targetBatteryVoltage: bytesToUint16(frame.payload[1:3]), events <- &ChargingCurrentReq{frame}
chargingCurrentReq: frame.payload[3], events <- &ChargingRate{frame}
chargingRate: frame.payload[6], events <- &VehicleCharging{frame}
vehicleCharging: getVehicleCharging(&frame.payload), events <- &ShiftLever{frame}
shiftLever: getVehicleShiftLever(&frame.payload), events <- &ChargingSystemFault{frame}
chargingSystemFault: getFault(&frame.payload, 5, 2), events <- &VehicleStatus{frame}
vehicleStatus: getVehicleStatus(&frame.payload), events <- &NormalStopReq{frame}
normalStopReq: getNormalStopReq(&frame.payload), events <- &BattOvervoltage{frame}
battOvervoltage: getFault(&frame.payload, 4, 0), events <- &BattUndervoltage{frame}
battUndervoltage: getFault(&frame.payload, 4, 1), events <- &BattCurrentDeviationErr{frame}
battCurrentDeviationErr: getFault(&frame.payload, 4, 2), events <- &HighBattTemperature{frame}
highBattTemperature: getFault(&frame.payload, 4, 3), events <- &BattVoltageDeviationErr{frame}
battVoltageDeviationErr: getFault(&frame.payload, 4, 4),
}
fmt.Println(event)
//events <- event
} }
} }
}() }()
@ -132,14 +141,14 @@ func FromCanFrames(frames <-chan *CanFrame) <-chan ChademoEvent {
return events return events
} }
func getVehicleShiftLever(bytes *[]byte) ShiftLever { func getVehicleShiftLever(bytes *[]byte) ShiftLeverPosition {
if isBitSet((*bytes)[5], 1) { if isBitSet((*bytes)[5], 1) {
return OTHER return OTHER
} }
return PARKING return PARKING
} }
func getVehicleStatus(bytes *[]byte) VehicleStatus { func getVehicleStatus(bytes *[]byte) ContactorVehicleStatus {
if isBitSet((*bytes)[5], 3) { if isBitSet((*bytes)[5], 3) {
return CONTACTOR_OPEN return CONTACTOR_OPEN
} }
@ -160,7 +169,7 @@ func getFault(bytes *[]byte, octet byte, bit byte) SystemFault {
return NORMAL return NORMAL
} }
func getVehicleCharging(bytes *[]uint8) VehicleCharging { func getVehicleCharging(bytes *[]uint8) VehicleChargingEnabled {
if isBitSet((*bytes)[5], 0) { if isBitSet((*bytes)[5], 0) {
return ENABLED return ENABLED
} }
@ -188,24 +197,137 @@ func bytesToUint16(bytes []uint8) uint16 {
return result return result
} }
func (f frame100) GetMaxBattVoltage() uint16 { func (m MaximumBatteryVoltage) GetValue() interface{} {
return f.maxBattVoltage return bytesToUint16(m.payload[4:6])
}
func (c ConstChargingRateInd) GetValue() interface{} {
return c.payload[6]
}
func (b BatteryCapacity) GetValue() interface{} {
return 0.1 * float32(bytesToUint16(b.payload[5:7]))
}
func (m MaxChargingTimeS) GetValue() interface{} {
return 10 * uint16(m.payload[1])
}
func (m MaxChargingTimeM) GetValue() interface{} {
return m.payload[2]
}
func (e EstChargingTimeM) GetValue() interface{} {
return e.payload[3]
}
func (c ControlProtocolNumber) GetValue() interface{} {
return c.payload[0]
} }
func (f frame100) GetChargingRate() uint8 { func (t TargetBatteryVoltage) GetValue() interface{} {
return f.chargingRateInd return bytesToUint16(t.payload[1:3])
} }
func (f frame100) GetValue() interface{} { func (c ChargingCurrentReq) GetValue() interface{} {
return fmt.Sprintf("%v | MaxBattVoltage = %vV, ChargingRate = %v%%", f.date, f.maxBattVoltage, f.chargingRateInd) return c.payload[3]
} }
func (f frame101) GetValue() interface{} { func (c ChargingRate) GetValue() interface{} {
return fmt.Sprintf("%v | batteryCapacity = %vkWh, maxChargingTime = %vsec, maxChargingTime = %vmin, estChargingTime = %vmin", return c.payload[6]
f.date, f.batteryCapacity, f.maxChargingTimeS, f.maxChargingTimeM, f.estChargingTimeM)
} }
func (f frame102) GetValue() interface{} { func (s ShiftLever) GetValue() interface{} {
//TODO implement me return getVehicleShiftLever(&s.payload)
return "" }
func (v VehicleCharging) GetValue() interface{} {
return getVehicleCharging(&v.payload)
}
func (c ChargingSystemFault) GetValue() interface{} {
return getFault(&c.payload, 5, 2)
}
func (v VehicleStatus) GetValue() interface{} {
return getVehicleStatus(&v.payload)
}
func (n NormalStopReq) GetValue() interface{} {
return getNormalStopReq(&n.payload)
}
func (b BattOvervoltage) GetValue() interface{} {
return getFault(&b.payload, 4, 0)
}
func (b BattUndervoltage) GetValue() interface{} {
return getFault(&b.payload, 4, 1)
}
func (b BattCurrentDeviationErr) GetValue() interface{} {
return getFault(&b.payload, 4, 2)
}
func (h HighBattTemperature) GetValue() interface{} {
return getFault(&h.payload, 4, 3)
}
func (b BattVoltageDeviationErr) GetValue() interface{} {
return getFault(&b.payload, 4, 4)
}
func (v VehicleChargingEnabled) String() string {
switch v {
case DISABLED:
return "disabled"
case ENABLED:
return "enabled"
default:
panic("VehicleChargingEnabled not implemented")
}
}
func (s ShiftLeverPosition) String() string {
switch s {
case PARKING:
return "parking"
case OTHER:
return "other"
default:
panic("ShiftLeverPosition not implemented")
}
}
func (s SystemFault) String() string {
switch s {
case NORMAL:
return "normal"
case FAULT:
return "fault"
default:
panic("SystemFault not implemented")
}
}
func (c ContactorVehicleStatus) String() string {
switch c {
case CONTACTOR_CLOSED:
return "contactor closed"
case CONTACTOR_OPEN:
return "contactor open"
default:
panic("ContactorVehicleStatus not implemented")
}
}
func (s StopRequest) String() string {
switch s {
case NO_REQUEST:
return "no request"
case STOP_REQUEST:
return "stop request"
default:
panic("StopRequest not implemented")
}
} }

Loading…
Cancel
Save