Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Install dependencies and run tests
run: |
go mod download
go test -v ./... -coverpkg=./... -short -coverprofile=unit_coverage.out
go test -v ./... -coverpkg=./... -short -coverprofile=unit_coverage.out -race

- name: Archive code coverage results
uses: actions/upload-artifact@v4
Expand Down
39 changes: 39 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "2"
linters:
default: all
enable:
- bodyclose
- copyloopvar
- decorder
- errcheck
- errname
- forbidigo
- goconst
- gocritic
- gosec
- govet
- ineffassign
- intrange
- misspell
- nestif
- predeclared
- staticcheck
- testifylint
- unparam
- unused
- wastedassign
- whitespace
- wrapcheck
exclusions:
generated: lax
paths:
- ./examples

formatters:
settings:
goimports:
local-prefixes:
- github.com/ChargePi/ocpp-manager
enable:
- gofmt
- goimports
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY:gen format lint

gen:
mockery

lint:
golangci-lint run

format:
golangci-lint fmt
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ getting and setting values, validating values, and enforcing mandatory keys.
- Mandatory key enforcement
- Custom value validation
- Provides sane default values
- Supports OCPP 1.6 and 2.0.1 (separate packages for each version)

## Roadmap

- [x] Configuration versioning
- [x] Custom value validation
- [x] Mandatory key enforcement
- [x] Support for OCPP 1.6
- [ ] Support for OCPP 2.0.1
- [x] Support for OCPP 2.0.1

## Installing

Expand All @@ -26,6 +27,8 @@ getting and setting values, validating values, and enforcing mandatory keys.

## ⚡ Usage

### OCPP 1.6

Check out the full [OCPP 1.6 example](examples/v16/example.go).

```go
Expand Down Expand Up @@ -92,6 +95,10 @@ func main() {

```

### OCPP 2.0.1

TBD

## Notes

1. This library is still in development, and the API might change in the future.
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.22.1
replace github.com/lorenzodonini/ocpp-go v0.18.0 => github.com/ChargePi/ocpp-go v0.21.0

require (
github.com/ChargePi/ocppManager-go v1.2.0
github.com/agrison/go-commons-lang v0.0.0-20240106075236-2e001e6401ef
github.com/lorenzodonini/ocpp-go v0.18.0
github.com/samber/lo v1.47.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.10.0
github.com/zyedidia/generic v1.2.1
)

require (
Expand All @@ -22,6 +22,8 @@ require (
github.com/leodido/go-urn v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/relvacode/iso8601 v1.6.0 // indirect
github.com/segmentio/fasthash v1.0.3 // indirect
golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e // indirect
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/go-playground/validator.v9 v9.30.0 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/ChargePi/ocpp-go v0.21.0 h1:YP6uCu75D/TJFwkWsRHHtRthapmrxZscKBylBc8oc9Q=
github.com/ChargePi/ocpp-go v0.21.0/go.mod h1:2kcukDdhui4u730VfnYVWuwzDLgw+mBRGDir/QAyBhg=
github.com/ChargePi/ocppManager-go v1.2.0 h1:OV90kAD22yVYTSE+uHIgTtiwUOYpEwyHDPJb8d6AltM=
github.com/ChargePi/ocppManager-go v1.2.0/go.mod h1:7kWtV1+qQw+OSOHBuE/wUsTH5Id5+/euzsCfke9NQ2E=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/agrison/go-commons-lang v0.0.0-20240106075236-2e001e6401ef h1:KkznClyESbRaLmRo7Oam4vv5L4oknDK+mixJ9mypl6E=
Expand Down Expand Up @@ -33,6 +31,8 @@ github.com/relvacode/iso8601 v1.6.0 h1:eFXUhMJN3Gz8Rcq82f9DTMW0svjtAVuIEULglM7QH
github.com/relvacode/iso8601 v1.6.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
Expand All @@ -47,6 +47,10 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/zyedidia/generic v1.2.1 h1:Zv5KS/N2m0XZZiuLS82qheRG4X1o5gsWreGb0hR7XDc=
github.com/zyedidia/generic v1.2.1/go.mod h1:ly2RBz4mnz1yeuVbQA/VFwGjK3mnHGRj1JuoG336Bis=
golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e h1:iWVPgObh6F4UDtjBLK51zsy5UHTPLQwCmsNjCsbKhQ0=
golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 h1:9vYwv7OjYaky/tlAeD7C4oC9EsPTlaFl1H2jS++V+ME=
Expand Down
9 changes: 9 additions & 0 deletions ocpp_v201/charging_station.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ocpp_v201

import "github.com/ChargePi/ocpp-manager/ocpp_v201/component"

type ChargingStation struct {
ID string
components map[component.Name]component.Component // Charging station (top level) specific components
controllerManager Manager
}
62 changes: 62 additions & 0 deletions ocpp_v201/component/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package component

import "github.com/ChargePi/ocpp-manager/ocpp_v201/variables"

type Component interface {

// GetName Essentially a component type.
GetName() Name

// GetInstanceId returns the unique instance ID of this component.
GetInstanceId() string

// RegisterSubComponent registers a sub-component to this component.
RegisterSubComponent(component Component)

// UnregisterSubComponent unregisters a sub-component from this component.
UnregisterSubComponent(component Component)

// GetSubComponents returns all sub-components of this component.
GetSubComponents() []Component

// GetRequiredVariables returns required variables for this component
GetRequiredVariables() []variables.VariableName

// GetSupportedVariables returns supported variables (both required and optional) for this component
GetSupportedVariables() []variables.VariableName

// GetVariable retrieves a variable by its name.
GetVariable(key variables.VariableName, opts ...GetSetVariableOption) (*variables.Variable, error)

// UpdateVariable updates a variable's attribute with a new value.
UpdateVariable(variable variables.VariableName, attribute string, value interface{}, opts ...GetSetVariableOption) error

// Validate checks if the variable is valid for this component.
Validate(key variables.VariableName) bool
}

type Name string

const (
ComponentNameOCPPCommCtrlr Name = "OCPPCommCtrlr"
ComponentNameLocalAuthListCtrlr Name = "LocalAuthListCtrlr"
ComponentNameTxCtrlr Name = "TxCtrlr"
ComponentNameDeviceDataCtrlr Name = "DeviceDataCtrlr"
ComponentNameSecurityCtrlr Name = "SecurityCtrlr"
ComponentNameClockCtrlr Name = "ClockCtrlr"
ComponentNameCustomizationCtrlr Name = "CustomizationCtrlr"
ComponentNameSampledDataCtrlr Name = "SampledDataCtrlr"
ComponentNameAlignedDataCtrlr Name = "AlignedDataCtrlr"
ComponentNameReservationCtrlr Name = "ReservationCtrlr"
ComponentNameSmartChargingCtrlr Name = "SmartChargingCtrlr"
ComponentNameTariffCostCtrlr Name = "TariffCostCtrlr"
ComponentNameMonitoringCtrlr Name = "MonitoringCtrlr"
ComponentNameDisplayMessageCtrlr Name = "DisplayMessageCtrlr"
ComponentNameISO15118Ctrlr Name = "ISO15118Ctrlr"
ComponentNameAuthCtrlr Name = "AuthCtrlr"
ComponentNameAuthCacheCtrlr Name = "AuthCacheCtrlr"
ComponentNameChargingStation Name = "ChargingStation"
ComponentNameEVSE Name = "EVSE"
ComponentNameConnector Name = "Connector"
ComponentNameConnectedEV Name = "ConnectedEV"
)
14 changes: 14 additions & 0 deletions ocpp_v201/component/component_variable_opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package component

type GetSetVariableOption func(o *componentVariableOptions)

type componentVariableOptions struct {
attributeType string
}

// WithAttributeType sets the attribute type for the variable options.
func WithAttributeType(attributeType string) GetSetVariableOption {
return func(o *componentVariableOptions) {
o.attributeType = attributeType
}
}
42 changes: 42 additions & 0 deletions ocpp_v201/component/component_variable_opts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package component

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestOptions(t *testing.T) {
tests := []struct {
name string
opts []GetSetVariableOption
expected componentVariableOptions
}{
{
name: "default options",
expected: componentVariableOptions{
attributeType: "",
},
opts: []GetSetVariableOption{},
},
{
name: "with attribute type",
expected: componentVariableOptions{
attributeType: "abc",
},
opts: []GetSetVariableOption{
WithAttributeType("abc"),
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := componentVariableOptions{}
for _, opt := range tt.opts {
opt(&opts)
}

assert.Equal(t, tt.expected, opts)
})
}
}
8 changes: 8 additions & 0 deletions ocpp_v201/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ocpp_v201

import "github.com/ChargePi/ocpp-manager/ocpp_v201/component"

type Connector struct {
ID int
components map[component.Name]component.Component
}
Loading