chore: remove ocpp public wait (#15911)
This commit is contained in:
parent
04a4696b80
commit
119c37cd77
5 changed files with 97 additions and 103 deletions
|
|
@ -381,28 +381,22 @@ func (c *OCPP) Diagnose() {
|
|||
}
|
||||
|
||||
fmt.Printf("\tConfiguration:\n")
|
||||
rc := make(chan error, 1)
|
||||
err := ocpp.Instance().GetConfiguration(c.cp.ID(), func(resp *core.GetConfigurationConfirmation, err error) {
|
||||
if err == nil {
|
||||
// sort configuration keys for printing
|
||||
slices.SortFunc(resp.ConfigurationKey, func(i, j core.ConfigurationKey) int {
|
||||
return cmp.Compare(i.Key, j.Key)
|
||||
})
|
||||
if resp, err := c.cp.GetConfiguration(); err == nil {
|
||||
// sort configuration keys for printing
|
||||
slices.SortFunc(resp.ConfigurationKey, func(i, j core.ConfigurationKey) int {
|
||||
return cmp.Compare(i.Key, j.Key)
|
||||
})
|
||||
|
||||
rw := map[bool]string{false: "r/w", true: "r/o"}
|
||||
rw := map[bool]string{false: "r/w", true: "r/o"}
|
||||
|
||||
for _, opt := range resp.ConfigurationKey {
|
||||
if opt.Value == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("\t\t%s (%s): %s\n", opt.Key, rw[opt.Readonly], *opt.Value)
|
||||
for _, opt := range resp.ConfigurationKey {
|
||||
if opt.Value == nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
rc <- err
|
||||
}, nil)
|
||||
ocpp.Wait(err, rc)
|
||||
fmt.Printf("\t\t%s (%s): %s\n", opt.Key, rw[opt.Readonly], *opt.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _ loadpoint.Controller = (*OCPP)(nil)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func (conn *Connector) remoteStartTransactionRequest() {
|
|||
request.ConnectorId = &connector
|
||||
})
|
||||
|
||||
if err := Wait(err, rc); err != nil {
|
||||
if err := wait(err, rc); err != nil {
|
||||
conn.log.ERROR.Printf("failed to start remote transaction: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,84 +22,73 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error {
|
|||
var meterValuesSampledData string
|
||||
meterValuesSampledDataMaxLength := len(strings.Split(desiredMeasurands, ","))
|
||||
|
||||
rc := make(chan error, 1)
|
||||
resp, err := cp.GetConfiguration()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := Instance().GetConfiguration(cp.ID(), func(resp *core.GetConfigurationConfirmation, err error) {
|
||||
if err == nil {
|
||||
for _, opt := range resp.ConfigurationKey {
|
||||
if opt.Value == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
switch opt.Key {
|
||||
case KeyChargeProfileMaxStackLevel:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
cp.StackLevel = val
|
||||
}
|
||||
|
||||
case KeyChargingScheduleAllowedChargingRateUnit:
|
||||
if *opt.Value == "Power" || *opt.Value == "W" { // "W" is not allowed by spec but used by some CPs
|
||||
cp.ChargingRateUnit = types.ChargingRateUnitWatts
|
||||
}
|
||||
|
||||
case KeyConnectorSwitch3to1PhaseSupported:
|
||||
var val bool
|
||||
if val, err = strconv.ParseBool(*opt.Value); err == nil {
|
||||
cp.PhaseSwitching = val
|
||||
}
|
||||
|
||||
case KeyMaxChargingProfilesInstalled:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
cp.ChargingProfileId = val
|
||||
}
|
||||
|
||||
case KeyMeterValuesSampledData:
|
||||
if opt.Readonly {
|
||||
meterValuesSampledDataMaxLength = 0
|
||||
}
|
||||
meterValuesSampledData = *opt.Value
|
||||
|
||||
case KeyMeterValuesSampledDataMaxLength:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
meterValuesSampledDataMaxLength = val
|
||||
}
|
||||
|
||||
case KeyNumberOfConnectors:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
cp.NumberOfConnectors = val
|
||||
}
|
||||
|
||||
case KeySupportedFeatureProfiles:
|
||||
if !hasProperty(*opt.Value, smartcharging.ProfileName) {
|
||||
cp.log.WARN.Printf("the required SmartCharging feature profile is not indicated as supported")
|
||||
}
|
||||
// correct the availability assumption of RemoteTrigger only in case of a valid looking FeatureProfile list
|
||||
if hasProperty(*opt.Value, core.ProfileName) {
|
||||
cp.HasRemoteTriggerFeature = hasProperty(*opt.Value, remotetrigger.ProfileName)
|
||||
}
|
||||
|
||||
// vendor-specific keys
|
||||
case KeyAlfenPlugAndChargeIdentifier:
|
||||
cp.IdTag = *opt.Value
|
||||
cp.log.DEBUG.Printf("overriding default `idTag` with Alfen-specific value: %s", cp.IdTag)
|
||||
|
||||
case KeyEvBoxSupportedMeasurands:
|
||||
if meterValues == "" {
|
||||
meterValues = *opt.Value
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, opt := range resp.ConfigurationKey {
|
||||
if opt.Value == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
rc <- err
|
||||
}, nil)
|
||||
switch opt.Key {
|
||||
case KeyChargeProfileMaxStackLevel:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
cp.StackLevel = val
|
||||
}
|
||||
|
||||
if err := Wait(err, rc); err != nil {
|
||||
return err
|
||||
case KeyChargingScheduleAllowedChargingRateUnit:
|
||||
if *opt.Value == "Power" || *opt.Value == "W" { // "W" is not allowed by spec but used by some CPs
|
||||
cp.ChargingRateUnit = types.ChargingRateUnitWatts
|
||||
}
|
||||
|
||||
case KeyConnectorSwitch3to1PhaseSupported:
|
||||
var val bool
|
||||
if val, err = strconv.ParseBool(*opt.Value); err == nil {
|
||||
cp.PhaseSwitching = val
|
||||
}
|
||||
|
||||
case KeyMaxChargingProfilesInstalled:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
cp.ChargingProfileId = val
|
||||
}
|
||||
|
||||
case KeyMeterValuesSampledData:
|
||||
if opt.Readonly {
|
||||
meterValuesSampledDataMaxLength = 0
|
||||
}
|
||||
meterValuesSampledData = *opt.Value
|
||||
|
||||
case KeyMeterValuesSampledDataMaxLength:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
meterValuesSampledDataMaxLength = val
|
||||
}
|
||||
|
||||
case KeyNumberOfConnectors:
|
||||
if val, err := strconv.Atoi(*opt.Value); err == nil {
|
||||
cp.NumberOfConnectors = val
|
||||
}
|
||||
|
||||
case KeySupportedFeatureProfiles:
|
||||
if !hasProperty(*opt.Value, smartcharging.ProfileName) {
|
||||
cp.log.WARN.Printf("the required SmartCharging feature profile is not indicated as supported")
|
||||
}
|
||||
// correct the availability assumption of RemoteTrigger only in case of a valid looking FeatureProfile list
|
||||
if hasProperty(*opt.Value, core.ProfileName) {
|
||||
cp.HasRemoteTriggerFeature = hasProperty(*opt.Value, remotetrigger.ProfileName)
|
||||
}
|
||||
|
||||
// vendor-specific keys
|
||||
case KeyAlfenPlugAndChargeIdentifier:
|
||||
cp.IdTag = *opt.Value
|
||||
cp.log.DEBUG.Printf("overriding default `idTag` with Alfen-specific value: %s", cp.IdTag)
|
||||
|
||||
case KeyEvBoxSupportedMeasurands:
|
||||
if meterValues == "" {
|
||||
meterValues = *opt.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// see who's there
|
||||
|
|
@ -158,6 +147,19 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetConfiguration
|
||||
func (cp *CP) GetConfiguration() (*core.GetConfigurationConfirmation, error) {
|
||||
rc := make(chan error, 1)
|
||||
|
||||
var res *core.GetConfigurationConfirmation
|
||||
err := Instance().GetConfiguration(cp.ID(), func(resp *core.GetConfigurationConfirmation, err error) {
|
||||
res = resp
|
||||
rc <- err
|
||||
}, nil)
|
||||
|
||||
return res, wait(err, rc)
|
||||
}
|
||||
|
||||
// HasMeasurement checks if meterValuesSample contains given measurement
|
||||
func (cp *CP) HasMeasurement(val types.Measurand) bool {
|
||||
return hasProperty(cp.meterValuesSample, string(val))
|
||||
|
|
@ -185,5 +187,5 @@ func (cp *CP) configure(key, val string) error {
|
|||
rc <- err
|
||||
}, key, val)
|
||||
|
||||
return Wait(err, rc)
|
||||
return wait(err, rc)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func (cs *CS) TriggerResetRequest(id string, resetType core.ResetType) error {
|
|||
rc <- err
|
||||
}, resetType)
|
||||
|
||||
return Wait(err, rc)
|
||||
return wait(err, rc)
|
||||
}
|
||||
|
||||
func (cs *CS) TriggerMessageRequest(id string, requestedMessage remotetrigger.MessageTrigger, props ...func(request *remotetrigger.TriggerMessageRequest)) error {
|
||||
|
|
@ -37,7 +37,7 @@ func (cs *CS) TriggerMessageRequest(id string, requestedMessage remotetrigger.Me
|
|||
rc <- err
|
||||
}, requestedMessage, props...)
|
||||
|
||||
return Wait(err, rc)
|
||||
return wait(err, rc)
|
||||
}
|
||||
|
||||
func (cs *CS) ChangeAvailabilityRequest(id string, connector int, availabilityType core.AvailabilityType) error {
|
||||
|
|
@ -51,7 +51,7 @@ func (cs *CS) ChangeAvailabilityRequest(id string, connector int, availabilityTy
|
|||
rc <- err
|
||||
}, connector, availabilityType)
|
||||
|
||||
return Wait(err, rc)
|
||||
return wait(err, rc)
|
||||
}
|
||||
|
||||
func (cs *CS) SetChargingProfileRequest(id string, connector int, profile *types.ChargingProfile) error {
|
||||
|
|
@ -65,7 +65,7 @@ func (cs *CS) SetChargingProfileRequest(id string, connector int, profile *types
|
|||
rc <- err
|
||||
}, connector, profile)
|
||||
|
||||
return Wait(err, rc)
|
||||
return wait(err, rc)
|
||||
}
|
||||
|
||||
func (cs *CS) GetCompositeScheduleRequest(id string, connector int, duration int) (*types.ChargingSchedule, error) {
|
||||
|
|
@ -82,9 +82,7 @@ func (cs *CS) GetCompositeScheduleRequest(id string, connector int, duration int
|
|||
rc <- err
|
||||
}, connector, duration)
|
||||
|
||||
err = Wait(err, rc)
|
||||
|
||||
return schedule, err
|
||||
return schedule, wait(err, rc)
|
||||
}
|
||||
|
||||
// cp actions
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
|
||||
)
|
||||
|
||||
// Wait waits for a CP roundtrip with timeout
|
||||
func Wait(err error, rc chan error) error {
|
||||
// wait waits for a CP roundtrip with timeout
|
||||
func wait(err error, rc chan error) error {
|
||||
if err == nil {
|
||||
select {
|
||||
case err = <-rc:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue