Skip to content

Commit

Permalink
Moved default configurations to a separate file, added tests for defa…
Browse files Browse the repository at this point in the history
…ults, updated go mod version.
  • Loading branch information
xBlaz3kx committed Jul 23, 2024
1 parent 72bf0c2 commit c91d8ae
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 213 deletions.
9 changes: 7 additions & 2 deletions examples/v16/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ func main() {
log.SetLevel(log.DebugLevel)

supportedProfiles := []string{core.ProfileName, smartcharging.ProfileName}
defaultConfig := ocpp_v16.DefaultConfiguration(supportedProfiles...)
manager, err := ocpp_v16.NewV16ConfigurationManager(defaultConfig, supportedProfiles...)
defaultConfig, err := ocpp_v16.DefaultConfigurationFromProfiles(supportedProfiles...)
if err != nil {
log.Errorf("Error getting configuration value: %v", err)
return
}

manager, err := ocpp_v16.NewV16ConfigurationManager(*defaultConfig, supportedProfiles...)

// Get value
value, err := manager.GetConfigurationValue(ocpp_v16.AuthorizeRemoteTxRequests)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ChargePi/ocppManager-go

go 1.18
go 1.22.1

replace github.com/lorenzodonini/ocpp-go v0.18.0 => github.com/ChargePi/ocpp-go v0.18.1

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
210 changes: 0 additions & 210 deletions ocpp_v16/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ package ocpp_v16
import (
"errors"
"fmt"
"strings"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/localauth"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
)
Expand All @@ -30,211 +25,6 @@ type Config struct {
Keys []core.ConfigurationKey `fig:"keys"`
}

func NewEmptyConfiguration() Config {
return Config{
Version: 1,
Keys: []core.ConfigurationKey{},
}
}

func DefaultConfiguration(profiles ...string) Config {
keys := DefaultCoreConfiguration()

for _, profile := range profiles {
switch profile {
case localauth.ProfileName:
keys = append(keys, DefaultLocalAuthConfiguration()...)
case smartcharging.ProfileName:
keys = append(keys, DefaultSmartChargingConfiguration()...)
case firmware.ProfileName:
keys = append(keys, DefaultFirmwareConfiguration()...)
}
}

return Config{
Version: 1,
Keys: keys,
}
}

func DefaultCoreConfiguration() []core.ConfigurationKey {
return []core.ConfigurationKey{
{
Key: AuthorizeRemoteTxRequests.String(),
Readonly: false,
Value: lo.ToPtr("true"),
},
{
Key: ClockAlignedDataInterval.String(),
Readonly: false,
Value: lo.ToPtr("0"),
},
{
Key: ConnectionTimeOut.String(),
Readonly: false,
Value: lo.ToPtr("60"),
},
{
Key: GetConfigurationMaxKeys.String(),
Readonly: false,
Value: lo.ToPtr("100"),
},
{
Key: HeartbeatInterval.String(),
Readonly: false,
Value: lo.ToPtr("60"),
},
{
Key: LocalPreAuthorize.String(),
Readonly: false,
Value: lo.ToPtr("false"),
},
{
Key: MeterValuesAlignedData.String(),
Readonly: false,
Value: lo.ToPtr("true"),
},
{
Key: MeterValuesSampledData.String(),
Readonly: false,
Value: lo.ToPtr(strings.Join([]string{
string(types.MeasurandVoltage),
string(types.MeasurandCurrentImport),
string(types.MeasurandPowerActiveImport),
string(types.MeasurandEnergyActiveImportInterval),
string(types.MeasueandSoC),
}, ",")),
},
{
Key: MeterValueSampleInterval.String(),
Readonly: false,
Value: lo.ToPtr("20"),
},
{
Key: NumberOfConnectors.String(),
Readonly: true,
Value: lo.ToPtr("1"),
},
{
Key: ResetRetries.String(),
Readonly: false,
Value: lo.ToPtr("3"),
},
{
Key: ConnectorPhaseRotation.String(),
Readonly: true,
Value: lo.ToPtr("Unknown"),
},
{
Key: StopTransactionOnEVSideDisconnect.String(),
Readonly: false,
Value: lo.ToPtr("true"),
},
{
Key: StopTransactionOnInvalidId.String(),
Readonly: false,
Value: lo.ToPtr("true"),
},
{
Key: StopTxnAlignedData.String(),
Readonly: false,
Value: lo.ToPtr(strings.Join([]string{
string(types.MeasurandVoltage),
string(types.MeasurandCurrentImport),
string(types.MeasurandPowerActiveImport),
string(types.MeasurandEnergyActiveImportInterval),
string(types.MeasueandSoC),
}, ",")),
},
{
Key: StopTxnSampledData.String(),
Readonly: false,
Value: lo.ToPtr(strings.Join([]string{
string(types.MeasurandVoltage),
string(types.MeasurandCurrentImport),
string(types.MeasurandPowerActiveImport),
string(types.MeasurandEnergyActiveImportInterval),
string(types.MeasueandSoC),
}, ",")),
},
{
Key: SupportedFeatureProfiles.String(),
Readonly: true,
Value: lo.ToPtr("Core"),
},
{
Key: TransactionMessageAttempts.String(),
Readonly: false,
Value: lo.ToPtr("3"),
},
{
Key: TransactionMessageRetryInterval.String(),
Readonly: false,
Value: lo.ToPtr("30"),
},
{
Key: UnlockConnectorOnEVSideDisconnect.String(),
Readonly: false,
Value: lo.ToPtr("true"),
},
}
}

func DefaultLocalAuthConfiguration() []core.ConfigurationKey {
return []core.ConfigurationKey{
{
Key: LocalAuthListEnabled.String(),
Readonly: false,
Value: lo.ToPtr("true"),
},
{
Key: LocalAuthListMaxLength.String(),
Readonly: true,
Value: lo.ToPtr("100"),
},
{
Key: SendLocalListMaxLength.String(),
Readonly: true,
Value: lo.ToPtr("100"),
},
}
}

func DefaultSmartChargingConfiguration() []core.ConfigurationKey {
return []core.ConfigurationKey{
{
Key: ChargeProfileMaxStackLevel.String(),
Readonly: true,
Value: lo.ToPtr("5"),
},
{
Key: ChargingScheduleAllowedChargingRateUnit.String(),
Readonly: true,
Value: lo.ToPtr("Current,Power"),
},
{
Key: ChargingScheduleMaxPeriods.String(),
Readonly: true,
Value: lo.ToPtr("6"),
},
{
Key: MaxChargingProfilesInstalled.String(),
Readonly: true,
Value: lo.ToPtr("5"),
},
}
}

func DefaultFirmwareConfiguration() []core.ConfigurationKey {
return []core.ConfigurationKey{
{
Key: SupportedFileTransferProtocols.String(),
Readonly: true,
Value: lo.ToPtr("HTTP,HTTPS,FTP,FTPS,SFTP"),
},
}
}

// UpdateKey Update the configuration variable in the configuration if it is not readonly.
func (config *Config) UpdateKey(key string, value *string) error {
log.Debugf("Updating key %s", key)
Expand Down
Loading

0 comments on commit c91d8ae

Please sign in to comment.