Skip to content

Commit

Permalink
Add support for heartbeat events in EG LPC/LPP
Browse files Browse the repository at this point in the history
The Energy Guard implementations of LPC and LPP should also get incoming heartbeat events, so it can react on missing heartbeatss from the controllable systems.
  • Loading branch information
DerAndereAndi committed Oct 10, 2024
1 parent 94653eb commit 4c85022
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions usecases/eg/lpc/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func (e *LPC) HandleEvent(payload spineapi.EventPayload) {
return
}

if internal.IsHeartbeat(payload) && e.EventCB != nil {
e.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateHeartbeat)
return
}

if payload.EventType != spineapi.EventTypeDataChange ||
payload.ChangeType != spineapi.ElementChangeUpdate {
return
Expand Down
9 changes: 9 additions & 0 deletions usecases/eg/lpc/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func (s *EgLPCSuite) Test_Events() {
payload.Data = util.Ptr(model.DeviceConfigurationKeyValueListDataType{})
s.sut.HandleEvent(payload)

payload.EventType = spineapi.EventTypeDataChange
payload.ChangeType = spineapi.ElementChangeUpdate
payload.Function = model.FunctionTypeDeviceDiagnosisHeartbeatData
deviceDiagF := s.sut.LocalEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
payload.LocalFeature = deviceDiagF
payload.CmdClassifier = util.Ptr(model.CmdClassifierTypeNotify)
payload.Data = util.Ptr(model.DeviceDiagnosisHeartbeatDataType{})
s.sut.HandleEvent(payload)

payload.Data = util.Ptr(model.NodeManagementUseCaseDataType{})
s.sut.HandleEvent(payload)
}
Expand Down
6 changes: 6 additions & 0 deletions usecases/eg/lpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ const (
//
// Use Case LPC, Scenario 2
DataUpdateFailsafeDurationMinimum api.EventType = "eg-lpc-DataUpdateFailsafeDurationMinimum"

// Indicates a notify heartbeat event the application should care of.
// E.g. going into or out of the Failsafe state
//
// Use Case LPC, Scenario 3
DataUpdateHeartbeat api.EventType = "cs-lpc-DataUpdateHeartbeat"
)
5 changes: 5 additions & 0 deletions usecases/eg/lpp/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (e *LPP) HandleEvent(payload spineapi.EventPayload) {
return
}

if internal.IsHeartbeat(payload) && e.EventCB != nil {
e.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateHeartbeat)
return
}

if payload.EventType != spineapi.EventTypeDataChange ||
payload.ChangeType != spineapi.ElementChangeUpdate {
return
Expand Down
9 changes: 9 additions & 0 deletions usecases/eg/lpp/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func (s *EgLPPSuite) Test_Events() {
payload.Data = util.Ptr(model.DeviceConfigurationKeyValueListDataType{})
s.sut.HandleEvent(payload)

payload.EventType = spineapi.EventTypeDataChange
payload.ChangeType = spineapi.ElementChangeUpdate
payload.Function = model.FunctionTypeDeviceDiagnosisHeartbeatData
deviceDiagF := s.sut.LocalEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
payload.LocalFeature = deviceDiagF
payload.CmdClassifier = util.Ptr(model.CmdClassifierTypeNotify)
payload.Data = util.Ptr(model.DeviceDiagnosisHeartbeatDataType{})
s.sut.HandleEvent(payload)

payload.Data = util.Ptr(model.NodeManagementUseCaseDataType{})
s.sut.HandleEvent(payload)
}
Expand Down
6 changes: 6 additions & 0 deletions usecases/eg/lpp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ const (
//
// Use Case LPC, Scenario 2
DataUpdateFailsafeDurationMinimum api.EventType = "eg-lpp-DataUpdateFailsafeDurationMinimum"

// Indicates a notify heartbeat event the application should care of.
// E.g. going into or out of the Failsafe state
//
// Use Case LPC, Scenario 3
DataUpdateHeartbeat api.EventType = "cs-lpc-DataUpdateHeartbeat"
)

0 comments on commit 4c85022

Please sign in to comment.