From ec8a87260a14428f7ab329d1a33a14ab522b674d Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 20 Sep 2024 17:26:11 +0200 Subject: [PATCH 1/2] Ocpp: support ChargeAmps custom phase switching key --- charger/ocpp/const.go | 5 +++-- charger/ocpp/cp_setup.go | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/charger/ocpp/const.go b/charger/ocpp/const.go index 3eab0a0e7..970fc50e8 100644 --- a/charger/ocpp/const.go +++ b/charger/ocpp/const.go @@ -20,6 +20,7 @@ const ( KeyMaxChargingProfilesInstalled = "MaxChargingProfilesInstalled" // Vendor specific keys - KeyAlfenPlugAndChargeIdentifier = "PlugAndChargeIdentifier" - KeyEvBoxSupportedMeasurands = "evb_SupportedMeasurands" + KeyAlfenPlugAndChargeIdentifier = "PlugAndChargeIdentifier" + KeyChargeAmpsPhaseSwitchingSupported = "ACPhaseSwitchingSupported" + KeyEvBoxSupportedMeasurands = "evb_SupportedMeasurands" ) diff --git a/charger/ocpp/cp_setup.go b/charger/ocpp/cp_setup.go index f2116fa84..59fe6f6e0 100644 --- a/charger/ocpp/cp_setup.go +++ b/charger/ocpp/cp_setup.go @@ -43,6 +43,9 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error { cp.ChargingRateUnit = types.ChargingRateUnitWatts } + case strings.EqualFold(opt.Key, KeyChargeAmpsPhaseSwitchingSupported): + fallthrough + case strings.EqualFold(opt.Key, KeyConnectorSwitch3to1PhaseSupported): var val bool if val, err = strconv.ParseBool(*opt.Value); err == nil { From 8e7a231e9efe4ef279ebbd65e66e079477a753ab Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 20 Sep 2024 17:28:25 +0200 Subject: [PATCH 2/2] wip --- charger/ocpp/cp_setup.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/charger/ocpp/cp_setup.go b/charger/ocpp/cp_setup.go index 59fe6f6e0..d82f16dab 100644 --- a/charger/ocpp/cp_setup.go +++ b/charger/ocpp/cp_setup.go @@ -32,32 +32,33 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error { continue } + match := func(s string) bool { + return strings.EqualFold(opt.Key, s) + } + switch { - case strings.EqualFold(opt.Key, KeyChargeProfileMaxStackLevel): + case match(KeyChargeProfileMaxStackLevel): if val, err := strconv.Atoi(*opt.Value); err == nil { cp.StackLevel = val } - case strings.EqualFold(opt.Key, KeyChargingScheduleAllowedChargingRateUnit): + case match(KeyChargingScheduleAllowedChargingRateUnit): if *opt.Value == "Power" || *opt.Value == "W" { // "W" is not allowed by spec but used by some CPs cp.ChargingRateUnit = types.ChargingRateUnitWatts } - case strings.EqualFold(opt.Key, KeyChargeAmpsPhaseSwitchingSupported): - fallthrough - - case strings.EqualFold(opt.Key, KeyConnectorSwitch3to1PhaseSupported): + case match(KeyConnectorSwitch3to1PhaseSupported) || match(KeyChargeAmpsPhaseSwitchingSupported): var val bool if val, err = strconv.ParseBool(*opt.Value); err == nil { cp.PhaseSwitching = val } - case strings.EqualFold(opt.Key, KeyMaxChargingProfilesInstalled): + case match(KeyMaxChargingProfilesInstalled): if val, err := strconv.Atoi(*opt.Value); err == nil { cp.ChargingProfileId = val } - case strings.EqualFold(opt.Key, KeyMeterValuesSampledData): + case match(KeyMeterValuesSampledData): if opt.Readonly { meterValuesSampledDataMaxLength = 0 } @@ -69,17 +70,17 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error { cp.meterValuesSample = *opt.Value } - case strings.EqualFold(opt.Key, KeyMeterValuesSampledDataMaxLength): + case match(KeyMeterValuesSampledDataMaxLength): if val, err := strconv.Atoi(*opt.Value); err == nil { meterValuesSampledDataMaxLength = val } - case strings.EqualFold(opt.Key, KeyNumberOfConnectors): + case match(KeyNumberOfConnectors): if val, err := strconv.Atoi(*opt.Value); err == nil { cp.NumberOfConnectors = val } - case strings.EqualFold(opt.Key, KeySupportedFeatureProfiles): + case match(KeySupportedFeatureProfiles): if !hasProperty(*opt.Value, smartcharging.ProfileName) { cp.log.WARN.Printf("the required SmartCharging feature profile is not indicated as supported") } @@ -89,11 +90,11 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error { } // vendor-specific keys - case strings.EqualFold(opt.Key, KeyAlfenPlugAndChargeIdentifier): + case match(KeyAlfenPlugAndChargeIdentifier): cp.IdTag = *opt.Value cp.log.DEBUG.Printf("overriding default `idTag` with Alfen-specific value: %s", cp.IdTag) - case strings.EqualFold(opt.Key, KeyEvBoxSupportedMeasurands): + case match(KeyEvBoxSupportedMeasurands): if meterValues == "" { meterValues = *opt.Value }