Skip to content

Commit

Permalink
Multiple DeviceDiagnosis related updates
Browse files Browse the repository at this point in the history
- Add `StartHeartbeat` and `StopHeartbeat` access via the relevant use cases
- Add `SetOperationMode`  access via the releveant use cases
- Add `IsHeartbeatWithinDuration` to EG LPC & LPP
- Make sure CEM CEVC has a DeviceDiagnosis server feature setup
- Minor test fixes
  • Loading branch information
DerAndereAndi committed Oct 9, 2024
1 parent 6e1818c commit 087f015
Show file tree
Hide file tree
Showing 32 changed files with 1,101 additions and 35 deletions.
7 changes: 5 additions & 2 deletions api/featuresserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ type DeviceConfigurationServerInterface interface {
}

type DeviceDiagnosisServerInterface interface {
// set the local diagnosis state of the device
SetLocalState(operatingState *model.DeviceDiagnosisStateDataType)
// set the local device diagnosis state of the device
SetLocalState(statetate *model.DeviceDiagnosisStateDataType)

// set the local device diagnosis operating state
SetLocalOperatingState(operatingState model.DeviceDiagnosisOperatingStateType)
}

type ElectricalConnectionServerInterface interface {
Expand Down
16 changes: 12 additions & 4 deletions features/server/devicediagnosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type DeviceDiagnosis struct {
}

func NewDeviceDiagnosis(localEntity spineapi.EntityLocalInterface) (*DeviceDiagnosis, error) {
feature, err := NewFeature(model.FeatureTypeTypeDeviceConfiguration, localEntity)
feature, err := NewFeature(model.FeatureTypeTypeDeviceDiagnosis, localEntity)
if err != nil {
return nil, err
}
Expand All @@ -29,7 +29,15 @@ func NewDeviceDiagnosis(localEntity spineapi.EntityLocalInterface) (*DeviceDiagn

var _ api.DeviceDiagnosisServerInterface = (*DeviceDiagnosis)(nil)

// set the local diagnosis state of the device
func (d *DeviceDiagnosis) SetLocalState(operatingState *model.DeviceDiagnosisStateDataType) {
d.featureLocal.SetData(model.FunctionTypeDeviceDiagnosisStateData, operatingState)
// set the local device diagnosis state of the device
func (d *DeviceDiagnosis) SetLocalState(state *model.DeviceDiagnosisStateDataType) {
d.featureLocal.SetData(model.FunctionTypeDeviceDiagnosisStateData, state)
}

// set the local device diagnosis operating state
func (d *DeviceDiagnosis) SetLocalOperatingState(operatingState model.DeviceDiagnosisOperatingStateType) {
stateData := &model.DeviceDiagnosisStateDataType{
OperatingState: &operatingState,
}
d.SetLocalState(stateData)
}
4 changes: 4 additions & 0 deletions features/server/devicediagnosis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ func (s *DeviceDiagnosisSuite) Test_SetState() {
}
s.sut.SetLocalState(data)
}

func (s *DeviceDiagnosisSuite) Test_SetLocalOperatingState() {
s.sut.SetLocalOperatingState(model.DeviceDiagnosisOperatingStateTypeNormalOperation)
}
4 changes: 4 additions & 0 deletions features/server/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func setupFeatures(
f.AddFunctionType(model.FunctionTypeDeviceClassificationManufacturerData, true, false)
f.AddFunctionType(model.FunctionTypeDeviceClassificationUserData, true, true)
localEntity.AddFeature(f)
f = spine.NewFeatureLocal(9, localEntity, model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
f.AddFunctionType(model.FunctionTypeDeviceDiagnosisStateData, true, false)
f.AddFunctionType(model.FunctionTypeDeviceDiagnosisHeartbeatData, true, true)
localEntity.AddFeature(f)
f = spine.NewFeatureLocal(10, localEntity, model.FeatureTypeTypeMeasurement, model.RoleTypeServer)
f.AddFunctionType(model.FunctionTypeMeasurementDescriptionListData, true, false)
f.AddFunctionType(model.FunctionTypeMeasurementListData, true, false)
Expand Down
47 changes: 40 additions & 7 deletions mocks/DeviceDiagnosisServerInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion usecases/api/cem_cevc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,19 @@ type CemCEVCInterface interface {

// Scenario 5 & 6

// this is automatically covered by the SPINE implementation
// start sending heartbeat from the local CEM entity
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
StartHeartbeat()

// stop sending heartbeat from the local CEM entity
StopHeartbeat()

// Scenario 7 & 8

// set the local operating state of the local cem entity
//
// parameters:
// - failureState: if true, the operating state is set to failure, otherwise to normal
SetOperatingState(failureState bool) error
}
15 changes: 12 additions & 3 deletions usecases/api/cem_opev.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ type CemOPEVInterface interface {

// Scenario 2

// this is automatically covered by the SPINE implementation
// start sending heartbeat from the local CEM entity
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
StartHeartbeat()

// stop sending heartbeat from the local CEM entity
StopHeartbeat()

// Scenario 3

// this is covered by the central CEM interface implementation
// use that one to set the CEM's operation state which will inform all remote devices
// set the local operating state of the local cem entity
//
// parameters:
// - failureState: if true, the operating state is set to failure, otherwise to normal
SetOperatingState(failureState bool) error
}
15 changes: 12 additions & 3 deletions usecases/api/cem_oscev.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ type CemOSCEVInterface interface {

// Scenario 2

// this is automatically covered by the SPINE implementation
// start sending heartbeat from the local CEM entity
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
StartHeartbeat()

// stop sending heartbeat from the local CEM entity
StopHeartbeat()

// Scenario 3

// this is covered by the central CEM interface implementation
// use that one to set the CEM's operation state which will inform all remote devices
// set the local operating state of the local cem entity
//
// parameters:
// - failureState: if true, the operating state is set to failure, otherwise to normal
SetOperatingState(failureState bool) error
}
9 changes: 8 additions & 1 deletion usecases/api/cs_lpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ type CsLPCInterface interface {

// Scenario 3

// this is automatically covered by the SPINE implementation
// start sending heartbeat from the local entity supporting this usecase
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
StartHeartbeat()

// stop sending heartbeat from the local entity supporting this usecase
StopHeartbeat()

//
// returns true, if the last heartbeat is within 2 minutes, otherwise false
IsHeartbeatWithinDuration() bool
Expand Down
10 changes: 9 additions & 1 deletion usecases/api/cs_lpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ type CsLPPInterface interface {

// Scenario 3

// this is automatically covered by the SPINE implementation
// start sending heartbeat from the local entity supporting this usecase
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
StartHeartbeat()

// stop sending heartbeat from the local entity supporting this usecase
StopHeartbeat()

// check wether there was a heartbeat received within the last 2 minutes
//
// returns true, if the last heartbeat is within 2 minutes, otherwise false
IsHeartbeatWithinDuration() bool
Expand Down
13 changes: 12 additions & 1 deletion usecases/api/eg_lpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,18 @@ type EgLPCInterface interface {

// Scenario 3

// this is automatically covered by the SPINE implementation
// start sending heartbeat from the local entity supporting this usecase
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
StartHeartbeat()

// stop sending heartbeat from the local entity supporting this usecase
StopHeartbeat()

// check wether there was a heartbeat received within the last 2 minutes
//
// returns true, if the last heartbeat is within 2 minutes, otherwise false
IsHeartbeatWithinDuration(entity spineapi.EntityRemoteInterface) bool

// Scenario 4

Expand Down
13 changes: 12 additions & 1 deletion usecases/api/eg_lpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,18 @@ type EgLPPInterface interface {

// Scenario 3

// this is automatically covered by the SPINE implementation
// start sending heartbeat from the local entity supporting this usecase
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
StartHeartbeat()

// stop sending heartbeat from the local entity supporting this usecase
StopHeartbeat()

// check wether there was a heartbeat received within the last 2 minutes
//
// returns true, if the last heartbeat is within 2 minutes, otherwise false
IsHeartbeatWithinDuration(entity spineapi.EntityRemoteInterface) bool

// Scenario 4

Expand Down
5 changes: 5 additions & 0 deletions usecases/cem/cevc/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ func (e *CEVC) AddFeatures() {
for _, feature := range clientFeatures {
_ = e.LocalEntity.GetOrAddFeature(feature, model.RoleTypeClient)
}

// server features
f := e.LocalEntity.GetOrAddFeature(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
f.AddFunctionType(model.FunctionTypeDeviceDiagnosisStateData, true, false)
f.AddFunctionType(model.FunctionTypeDeviceDiagnosisHeartbeatData, true, false)
}
40 changes: 40 additions & 0 deletions usecases/cem/opev/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package opev
import (
"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features/client"
"github.com/enbility/eebus-go/features/server"
ucapi "github.com/enbility/eebus-go/usecases/api"
"github.com/enbility/eebus-go/usecases/internal"
spineapi "github.com/enbility/spine-go/api"
Expand Down Expand Up @@ -106,3 +107,42 @@ func (e *OPEV) WriteLoadControlLimits(
}
return internal.WriteLoadControlPhaseLimits(e.LocalEntity, entity, filter, limits, resultCB)
}

// Scenario 2

// start sending heartbeat from the local CEM entity
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
func (e *OPEV) StartHeartbeat() {
if hm := e.LocalEntity.HeartbeatManager(); hm != nil {
_ = hm.StartHeartbeat()
}
}

// stop sending heartbeat from the local CEM entity
func (e *OPEV) StopHeartbeat() {
if hm := e.LocalEntity.HeartbeatManager(); hm != nil {
hm.StopHeartbeat()
}
}

// Scenario 3

// set the local operating state of the local cem entity
//
// parameters:
// - failureState: if true, the operating state is set to failure, otherwise to normal
func (e *OPEV) SetOperatingState(failureState bool) error {
lf, err := server.NewDeviceDiagnosis(e.LocalEntity)
if err != nil {
return err
}

state := model.DeviceDiagnosisOperatingStateTypeNormalOperation
if failureState {
state = model.DeviceDiagnosisOperatingStateTypeFailure
}
lf.SetLocalOperatingState(state)

return nil
}
6 changes: 6 additions & 0 deletions usecases/cem/opev/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ func (s *CemOPEVSuite) Test_Public() {

_, err = s.sut.WriteLoadControlLimits(s.evEntity, []ucapi.LoadLimitsPhase{}, nil)
assert.NotNil(s.T(), err)

s.sut.StopHeartbeat()
s.sut.StartHeartbeat()

err = s.sut.SetOperatingState(true)
assert.Nil(s.T(), err)
}
40 changes: 40 additions & 0 deletions usecases/cem/oscev/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package oscev
import (
"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features/client"
"github.com/enbility/eebus-go/features/server"
ucapi "github.com/enbility/eebus-go/usecases/api"
"github.com/enbility/eebus-go/usecases/internal"
spineapi "github.com/enbility/spine-go/api"
Expand Down Expand Up @@ -99,3 +100,42 @@ func (e *OSCEV) WriteLoadControlLimits(
}
return internal.WriteLoadControlPhaseLimits(e.LocalEntity, entity, filter, limits, resultCB)
}

// Scenario 2

// start sending heartbeat from the local CEM entity
//
// the heartbeat is started by default when a non 0 timeout is set in the service configuration
func (e *OSCEV) StartHeartbeat() {
if hm := e.LocalEntity.HeartbeatManager(); hm != nil {
_ = hm.StartHeartbeat()
}
}

// stop sending heartbeat from the local CEM entity
func (e *OSCEV) StopHeartbeat() {
if hm := e.LocalEntity.HeartbeatManager(); hm != nil {
hm.StopHeartbeat()
}
}

// Scenario 3

// set the local operating state of the local cem entity
//
// parameters:
// - failureState: if true, the operating state is set to failure, otherwise to normal
func (e *OSCEV) SetOperatingState(failureState bool) error {
lf, err := server.NewDeviceDiagnosis(e.LocalEntity)
if err != nil {
return err
}

state := model.DeviceDiagnosisOperatingStateTypeNormalOperation
if failureState {
state = model.DeviceDiagnosisOperatingStateTypeFailure
}
lf.SetLocalOperatingState(state)

return nil
}
Loading

0 comments on commit 087f015

Please sign in to comment.