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

Commit

Permalink
lpp: add Heartbeat event
Browse files Browse the repository at this point in the history
with this, application is able to validate heartbeat data and can implement a watchdog for failsafe watching
  • Loading branch information
DAMEK86 committed May 21, 2024
1 parent 4f62fd9 commit a62f37d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions uclppserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type UCLPPServerInterface interface {
// Scenario 3

// this is automatically covered by the SPINE implementation
//
// returns true, if the last heartbeat is within 2 minutes, otherwise false
IsHeartbeatWithinDuration() bool

// Scenario 4

Expand Down
6 changes: 6 additions & 0 deletions uclppserver/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (e *UCLPPServer) HandleEvent(payload spineapi.EventPayload) {
return
}

if util.IsHeartbeat(localEntity, payload) {
e.eventCB(payload.Ski, payload.Device, payload.Entity, Heartbeat)
}

if localEntity == nil ||
payload.EventType != spineapi.EventTypeDataChange ||
payload.ChangeType != spineapi.ElementChangeUpdate ||
Expand Down Expand Up @@ -98,6 +102,7 @@ func (e *UCLPPServer) deviceConnected(payload spineapi.EventPayload) {
// we only found one matching entity, as it should be, subscribe
if len(deviceDiagEntites) == 1 {
if localDeviceDiag, err := util.DeviceDiagnosis(e.service, deviceDiagEntites[0]); err == nil {
e.heartbeatDiag = localDeviceDiag
if _, err := localDeviceDiag.Subscribe(); err != nil {
logging.Log().Debug(err)
}
Expand All @@ -124,6 +129,7 @@ func (e *UCLPPServer) subscribeHeartbeatWorkaround(payload spineapi.EventPayload
}

if localDeviceDiag, err := util.DeviceDiagnosis(e.service, payload.Entity); err == nil {
e.heartbeatDiag = localDeviceDiag
if _, err := localDeviceDiag.Subscribe(); err != nil {
logging.Log().Debug(err)
}
Expand Down
6 changes: 6 additions & 0 deletions uclppserver/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ func (e *UCLPPServer) SetFailsafeDurationMinimum(duration time.Duration, changea
return util.SetLocalDeviceConfigurationKeyValue(e.service, keyName, changeable, keyValue)
}

// Scenario 3

func (e *UCLPPServer) IsHeartbeatWithinDuration() bool {
return e.heartbeatDiag.IsHeartbeatWithinDuration(2 * time.Minute)
}

// Scenario 4

// return nominal maximum active (real) power the Controllable System is
Expand Down
5 changes: 5 additions & 0 deletions uclppserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ const (
//
// Use Case LPC, Scenario 2
DataUpdateFailsafeDurationMinimum api.EventType = "DataUpdateFailsafeDurationMinimum"

// Indicates a notify heartbeat event the application should care of.
// E.g. going into or out of the Failsafe state
// Use Case LPP, Scenario 3
Heartbeat api.EventType = "Heartbeat"
)
3 changes: 3 additions & 0 deletions uclppserver/uclpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/enbility/cemd/api"
"github.com/enbility/cemd/util"
eebusapi "github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features"
eebusutil "github.com/enbility/eebus-go/util"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
Expand All @@ -23,6 +24,8 @@ type UCLPPServer struct {
pendingMux sync.Mutex
pendingLimits map[model.MsgCounterType]*spineapi.Message

heartbeatDiag *features.DeviceDiagnosis

heartbeatKeoWorkaround bool // required because KEO Stack uses multiple identical entities for the same functionality, and it is not clear which to use
}

Expand Down

0 comments on commit a62f37d

Please sign in to comment.