Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit d54e409

Browse files
committed
Refactor
- Introduce use case specific interface - Introduce generic event mechanism - Start implementation of EVSECC and EVCC Use Cases
1 parent 78ea63e commit d54e409

24 files changed

+1336
-139
lines changed

.github/workflows/default.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ jobs:
3333
skip-build-cache: true
3434

3535
- name: Test
36-
run: go test -race -v -coverprofile=coverage.out -covermode=atomic ./...
36+
run: go test -race -v -coverprofile=coverage_temp.out -covermode=atomic ./...
37+
38+
- name: Remove mocks and cmd from coverage
39+
run: grep -v -e "/cemd/mocks/" -e "/cemd/cmd/" coverage_temp.out > coverage.out
3740

3841
- name: Send coverage
3942
uses: coverallsapp/github-action@v2

.mockery.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
with-expecter: true
2+
inpackage: false
3+
dir: "{{ .InterfaceDir }}/mocks/"
4+
mockname: "{{.InterfaceName}}"
5+
outpkg: "mocks"
6+
filename: "{{.InterfaceName}}.go"
7+
all: true
8+
packages:
9+
github.com/enbility/cemd/api:
10+
github.com/enbility/cemd/evsecc:

api/api.go

+51
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
11
package api
22

33
import (
4+
"errors"
5+
46
shipapi "github.com/enbility/ship-go/api"
7+
spineapi "github.com/enbility/spine-go/api"
8+
"github.com/enbility/spine-go/model"
59
)
610

11+
//go:generate mockery
12+
13+
// Implemented by CEM
14+
type CemInterface interface {
15+
// Setup the EEBUS service
16+
Setup() error
17+
18+
// Start the EEBUS service
19+
Start()
20+
21+
// Shutdown the EEBUS service
22+
Shutdown()
23+
24+
// Add a use case implementation
25+
AddUseCase(usecase UseCaseInterface)
26+
}
27+
28+
// Implemented by each UseCase
29+
type UseCaseInterface interface {
30+
// provide the usecase name
31+
UseCaseName() model.UseCaseNameType
32+
33+
// add the features
34+
AddFeatures()
35+
36+
// add the usecase
37+
AddUseCase()
38+
}
39+
40+
// interface for informing the cem about specific events
41+
// for each supported usecase
42+
//
43+
// UseCaseEventType values can be found in the api definition of each
44+
// supported usecase
45+
//
46+
// implemented by the actual CEM, used by UCEvseCCInterface implementation
47+
type UseCaseEventReaderInterface interface {
48+
// Inform about a new usecase specific event
49+
SpineEvent(ski string, entity spineapi.EntityRemoteInterface, event UseCaseEventType)
50+
}
51+
52+
// type for usecase specfic event names
53+
type UseCaseEventType string
54+
55+
var ErrNoEvseEntity = errors.New("entity is not an EVSE")
56+
var ErrNoEvEntity = errors.New("entity is not an EV")
57+
758
// Implemented by *Solutions, used by Cem
859
type SolutionInterface interface {
960
RegisterRemoteDevice(details *shipapi.ServiceDetails, dataProvider any) any

cem/cem.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package cem
22

33
import (
4-
"github.com/enbility/eebus-go/api"
4+
"github.com/enbility/cemd/api"
5+
eebusapi "github.com/enbility/eebus-go/api"
56
"github.com/enbility/eebus-go/service"
67
"github.com/enbility/ship-go/logging"
78
"github.com/enbility/spine-go/model"
89
)
910

1011
// Generic CEM implementation
11-
type CemImpl struct {
12-
Service api.ServiceInterface
12+
type Cem struct {
13+
Service eebusapi.ServiceInterface
1314

1415
Currency model.CurrencyType
16+
17+
usecases []api.UseCaseInterface
1518
}
1619

17-
func NewCEM(serviceDescription *api.Configuration, serviceHandler api.ServiceReaderInterface, log logging.LoggingInterface) *CemImpl {
18-
cem := &CemImpl{
20+
func NewCEM(serviceDescription *eebusapi.Configuration, serviceHandler eebusapi.ServiceReaderInterface, log logging.LoggingInterface) *Cem {
21+
cem := &Cem{
1922
Service: service.NewService(serviceDescription, serviceHandler),
2023
Currency: model.CurrencyTypeEur,
2124
}
@@ -25,19 +28,27 @@ func NewCEM(serviceDescription *api.Configuration, serviceHandler api.ServiceRea
2528
return cem
2629
}
2730

28-
// Set up the supported usecases and features
29-
func (h *CemImpl) Setup() error {
30-
if err := h.Service.Setup(); err != nil {
31-
return err
32-
}
31+
var _ api.CemInterface = (*Cem)(nil)
3332

34-
return nil
33+
// Set up the eebus service
34+
func (h *Cem) Setup() error {
35+
return h.Service.Setup()
3536
}
3637

37-
func (h *CemImpl) Start() {
38+
// Start the EEBUS service
39+
func (h *Cem) Start() {
3840
h.Service.Start()
3941
}
4042

41-
func (h *CemImpl) Shutdown() {
43+
// Shutdown the EEBUS servic
44+
func (h *Cem) Shutdown() {
4245
h.Service.Shutdown()
4346
}
47+
48+
// Add a use case implementation
49+
func (h *Cem) AddUseCase(usecase api.UseCaseInterface) {
50+
h.usecases = append(h.usecases, usecase)
51+
52+
usecase.AddFeatures()
53+
usecase.AddUseCase()
54+
}

cmd/democem/democem.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package democem
2+
3+
import (
4+
"github.com/enbility/cemd/cem"
5+
"github.com/enbility/cemd/ucevsecc"
6+
eebusapi "github.com/enbility/eebus-go/api"
7+
)
8+
9+
type DemoCem struct {
10+
cem *cem.Cem
11+
}
12+
13+
func NewDemoCem(configuration *eebusapi.Configuration) *DemoCem {
14+
demo := &DemoCem{}
15+
16+
demo.cem = cem.NewCEM(configuration, demo, demo)
17+
18+
return demo
19+
}
20+
21+
func (d *DemoCem) Setup() error {
22+
if err := d.cem.Setup(); err != nil {
23+
return err
24+
}
25+
26+
evsecc := ucevsecc.NewUCEvseCC(d.cem.Service, d.cem.Service.LocalService(), d)
27+
d.cem.AddUseCase(evsecc)
28+
29+
d.cem.Start()
30+
31+
return nil
32+
}

cmd/democem/evsecc.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package democem
2+
3+
import (
4+
"github.com/enbility/cemd/api"
5+
spineapi "github.com/enbility/spine-go/api"
6+
)
7+
8+
var _ api.UseCaseEventReaderInterface = (*DemoCem)(nil)
9+
10+
// Handle incomfing usecase specific event
11+
func (h *DemoCem) SpineEvent(ski string, entity spineapi.EntityRemoteInterface, event api.UseCaseEventType) {
12+
}

cmd/democem/logging.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package democem
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
// Logging interface
9+
10+
func (d *DemoCem) log(level string, args ...interface{}) {
11+
t := time.Now()
12+
fmt.Printf("%s: %s %s", t.Format(time.RFC3339), level, fmt.Sprintln(args...))
13+
}
14+
15+
func (d *DemoCem) logf(level, format string, args ...interface{}) {
16+
t := time.Now()
17+
fmt.Printf("%s: %s %s\n", t.Format(time.RFC3339), level, fmt.Sprintf(format, args...))
18+
}
19+
20+
func (d *DemoCem) Trace(args ...interface{}) {
21+
d.log("TRACE", args...)
22+
}
23+
24+
func (d *DemoCem) Tracef(format string, args ...interface{}) {
25+
d.logf("TRACE", format, args...)
26+
}
27+
28+
func (d *DemoCem) Debug(args ...interface{}) {
29+
d.log("DEBUG", args...)
30+
}
31+
32+
func (d *DemoCem) Debugf(format string, args ...interface{}) {
33+
d.logf("DEBUG", format, args...)
34+
}
35+
36+
func (d *DemoCem) Info(args ...interface{}) {
37+
d.log("INFO", args...)
38+
}
39+
40+
func (d *DemoCem) Infof(format string, args ...interface{}) {
41+
d.logf("INFO", format, args...)
42+
}
43+
44+
func (d *DemoCem) Error(args ...interface{}) {
45+
d.log("ERROR", args...)
46+
}
47+
48+
func (d *DemoCem) Errorf(format string, args ...interface{}) {
49+
d.logf("ERROR", format, args...)
50+
}

cmd/democem/service.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package democem
2+
3+
import (
4+
eebusapi "github.com/enbility/eebus-go/api"
5+
shipapi "github.com/enbility/ship-go/api"
6+
"github.com/enbility/ship-go/logging"
7+
)
8+
9+
// report the Ship ID of a newly trusted connection
10+
func (d *DemoCem) RemoteServiceShipIDReported(service eebusapi.ServiceInterface, ski string, shipID string) {
11+
// we should associated the Ship ID with the SKI and store it
12+
// so the next connection can start trusted
13+
logging.Log().Info("SKI", ski, "has Ship ID:", shipID)
14+
}
15+
16+
func (d *DemoCem) RemoteSKIConnected(service eebusapi.ServiceInterface, ski string) {}
17+
18+
func (d *DemoCem) RemoteSKIDisconnected(service eebusapi.ServiceInterface, ski string) {}
19+
20+
func (d *DemoCem) VisibleRemoteServicesUpdated(service eebusapi.ServiceInterface, entries []shipapi.RemoteService) {
21+
}
22+
23+
func (h *DemoCem) ServiceShipIDUpdate(ski string, shipdID string) {}
24+
25+
func (h *DemoCem) ServicePairingDetailUpdate(ski string, detail *shipapi.ConnectionStateDetail) {}
26+
27+
func (h *DemoCem) AllowWaitingForTrust(ski string) bool { return true }

0 commit comments

Comments
 (0)