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

demo: improve initial startup #33

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ go.work

# VS Code
.vscode

cert.*
14 changes: 6 additions & 8 deletions cmd/democem/democem.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import (

type DemoCem struct {
cem *cem.Cem

remoteSki string
}

func NewDemoCem(configuration *eebusapi.Configuration, remoteSki string) *DemoCem {
demo := &DemoCem{
remoteSki: remoteSki,
}
func NewDemoCem(configuration *eebusapi.Configuration) *DemoCem {
demo := &DemoCem{}

demo.cem = cem.NewCEM(configuration, demo, demo.deviceEventCB, demo)

return demo
}

func (d *DemoCem) RegisterRemoteSKI(remoteSki string) {
d.cem.Service.RegisterRemoteSKI(remoteSki, true)
}

func (d *DemoCem) Setup() error {
if err := d.cem.Setup(); err != nil {
return err
Expand Down Expand Up @@ -77,8 +77,6 @@ func (d *DemoCem) Setup() error {
evsecc := ucevsecc.NewUCEVSECC(d.cem.Service, d.entityEventCB)
d.cem.AddUseCase(evsecc)

d.cem.Service.RegisterRemoteSKI(d.remoteSki, true)

d.cem.Start()

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/democem/eventcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

// Handle incoming usecase specific events
func (h *DemoCem) deviceEventCB(ski string, device spineapi.DeviceRemoteInterface, event api.EventType) {
func (d *DemoCem) deviceEventCB(ski string, device spineapi.DeviceRemoteInterface, event api.EventType) {
}

func (h *DemoCem) entityEventCB(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
func (d *DemoCem) entityEventCB(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
}
4 changes: 2 additions & 2 deletions cmd/democem/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ func (d *DemoCem) RemoteSKIDisconnected(service eebusapi.ServiceInterface, ski s
func (d *DemoCem) VisibleRemoteServicesUpdated(service eebusapi.ServiceInterface, entries []shipapi.RemoteService) {
}

func (h *DemoCem) ServiceShipIDUpdate(ski string, shipdID string) {}
func (d *DemoCem) ServiceShipIDUpdate(ski string, shipdID string) {}

func (h *DemoCem) ServicePairingDetailUpdate(ski string, detail *shipapi.ConnectionStateDetail) {}
func (d *DemoCem) ServicePairingDetailUpdate(ski string, detail *shipapi.ConnectionStateDetail) {}
11 changes: 5 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ func main() {

flag.Parse()

if len(os.Args) == 1 || remoteSki == nil || *remoteSki == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without providing an SKI the service can not run meaningful right now. One would have to also integrate accepting any (because there is no UX to deny them) incoming remote pairing requests.

Otherwise block should stay.

Copy link
Contributor Author

@DAMEK86 DAMEK86 Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current implementation isn't able to generate the cert and print the SKI for pairing without knowing the remote ski.
The idea behind that is providing an easier startup for pairing the cemd with a other eebus device.
Therefore the cemd ski is needed if the target is not auto accept the ski.

Copy link
Member

@DerAndereAndi DerAndereAndi Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I suggest simply moving this code block before configuration, err := eebusapi.NewConfiguration

flag.Usage()
return
}

certificate, err := tls.LoadX509KeyPair(*crt, *key)
if err != nil {
certificate, err = cert.CreateCertificate("Demo", "Demo", "DE", "Demo-Unit-10")
Expand Down Expand Up @@ -89,7 +84,11 @@ func main() {
configuration.SetInterfaces(ifaces)
}

demo := democem.NewDemoCem(configuration, *remoteSki)
demo := democem.NewDemoCem(configuration)

if len(os.Args) > 1 && *remoteSki != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't check of the amount of args here, but rather:

if remoteSki != nil && *remoteSki != "" {

If the nil check above stays, this could also be removed here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil in general isn't needed, because the default remoteSkivalue is an empty string.

demo.RegisterRemoteSKI(*remoteSki)
}

if err := demo.Setup(); err != nil {
fmt.Println("Error setting up cem: ", err)
Expand Down