Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocpp: support ChargeAmps custom phase switching key #16244

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions charger/ocpp/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
KeyMaxChargingProfilesInstalled = "MaxChargingProfilesInstalled"

// Vendor specific keys
KeyAlfenPlugAndChargeIdentifier = "PlugAndChargeIdentifier"
KeyEvBoxSupportedMeasurands = "evb_SupportedMeasurands"
KeyAlfenPlugAndChargeIdentifier = "PlugAndChargeIdentifier"
KeyChargeAmpsPhaseSwitchingSupported = "ACPhaseSwitchingSupported"
KeyEvBoxSupportedMeasurands = "evb_SupportedMeasurands"
)
24 changes: 14 additions & 10 deletions charger/ocpp/cp_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +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, 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
}
Expand All @@ -66,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")
}
Expand All @@ -86,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
}
Expand Down