Skip to content

Commit

Permalink
Only send heartbeats if the feature supports it
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 28, 2024
1 parent 92f4e9d commit bb01f02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 11 additions & 3 deletions spine/heartbeat_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ func (c *HeartbeatManager) UpdateHeartbeatOnSubscriptions() {
return
}

featureAddr := c.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
if featureAddr == nil {
feature := c.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
if feature == nil {
return
}

subscriptions := c.subscriptionManager.SubscriptionsOnFeature(*featureAddr.Address())
// check if the local device diagnosis server feature, supports the heartbeat function
ops, ok := feature.Operations()[model.FunctionTypeDeviceDiagnosisHeartbeatData]
if !ok || !ops.Read() {
return
}

subscriptions := c.subscriptionManager.SubscriptionsOnFeature(*feature.Address())
// check if any subscription address supports Heartbeat function

if len(subscriptions) == 0 {
// stop creating heartbeats
c.StopHeartbeat()
Expand Down
14 changes: 13 additions & 1 deletion spine/heartbeat_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (suite *HeartBeatManagerSuite) Test_HeartbeatSuccess() {
suite.localDevice.AddEntity(entity)

localFeature := entity.GetOrAddFeature(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
localFeature.AddFunctionType(model.FunctionTypeDeviceDiagnosisHeartbeatData, false, false)
entity.AddFeature(localFeature)

remoteEntity := NewEntityRemote(suite.remoteDevice, model.EntityTypeTypeEVSE, []model.AddressEntityType{1})
Expand Down Expand Up @@ -94,7 +95,18 @@ func (suite *HeartBeatManagerSuite) Test_HeartbeatSuccess() {
assert.Nil(suite.T(), data)

running := suite.sut.IsHeartbeatRunning()
assert.Equal(suite.T(), true, running)
assert.Equal(suite.T(), false, running)

suite.localDevice.RemoveEntity(entity)
entity = NewEntityLocal(suite.localDevice, model.EntityTypeTypeCEM, []model.AddressEntityType{1})
suite.localDevice.AddEntity(entity)

localFeature = entity.GetOrAddFeature(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer)
localFeature.AddFunctionType(model.FunctionTypeDeviceDiagnosisHeartbeatData, true, false)
entity.AddFeature(localFeature)

err = suite.localDevice.ProcessCmd(datagram, suite.remoteDevice)
assert.Nil(suite.T(), err)

err = suite.sut.StartHeartbeat()
assert.Nil(suite.T(), err)
Expand Down

0 comments on commit bb01f02

Please sign in to comment.