Skip to content

Commit

Permalink
Merge branch 'release/v0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Dec 10, 2022
2 parents d142ee7 + 79b5b41 commit 213258f
Show file tree
Hide file tree
Showing 40 changed files with 2,448 additions and 217 deletions.
3 changes: 0 additions & 3 deletions service/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ func (h *connectionsHub) connectionForSKI(ski string) *ship.ShipConnection {

// close all connections
func (h *connectionsHub) shutdown() {
h.muxCon.Lock()
defer h.muxCon.Unlock()

h.mdns.ShutdownMdnsService()
for _, c := range h.connections {
c.CloseConnection(false, "")
Expand Down
5 changes: 5 additions & 0 deletions service/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"syscall"

"github.com/enbility/eebus-go/logging"
"github.com/enbility/eebus-go/util"
"github.com/godbus/dbus/v5"
"github.com/holoplot/go-avahi"
"github.com/libp2p/zeroconf/v2"
Expand Down Expand Up @@ -365,6 +366,10 @@ func (m *mdns) resolveEntries() {
// stop searching for mDNS entries
func (m *mdns) stopResolvingEntries() {
if m.cancelChan != nil {
if util.IsChannelClosed(m.cancelChan) {
return
}

logging.Log.Debug("mdns: stop search")

m.cancelChan <- true
Expand Down
2 changes: 1 addition & 1 deletion ship/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (w *websocketConnection) readShipPump() {

message, err := w.readWebsocketMessage()
if err != nil {
logging.Log.Error(w.remoteSki, "websocket read error: ", err)
logging.Log.Debug(w.remoteSki, "websocket read error: ", err)
w.close()
w.dataProcessing.ReportConnectionError(err)
return
Expand Down
161 changes: 161 additions & 0 deletions spine/device_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ var _ spine.SpineDataConnection = (*DeviceLocalTestSuite)(nil)

func (d *DeviceLocalTestSuite) WriteSpineMessage([]byte) {}

func (d *DeviceLocalTestSuite) Test_RemoveRemoteDevice() {
sut := spine.NewDeviceLocalImpl("brand", "model", "serial", "code", "address", model.DeviceTypeTypeEnergyManagementSystem, model.NetworkManagementFeatureSetTypeSmart)

ski := "test"
sut.AddRemoteDevice(ski, d)
rDevice := sut.RemoteDeviceForSki(ski)
assert.NotNil(d.T(), rDevice)

sut.RemoveRemoteDeviceConnection(ski)

rDevice = sut.RemoteDeviceForSki(ski)
assert.Nil(d.T(), rDevice)
}

func (d *DeviceLocalTestSuite) Test_RemoteDevice() {
sut := spine.NewDeviceLocalImpl("brand", "model", "serial", "code", "address", model.DeviceTypeTypeEnergyManagementSystem, model.NetworkManagementFeatureSetTypeSmart)
localEntity := spine.NewEntityLocalImpl(sut, model.EntityTypeTypeCEM, spine.NewAddressEntityType([]uint{1}))
Expand Down Expand Up @@ -73,3 +87,150 @@ func (d *DeviceLocalTestSuite) Test_RemoteDevice() {
remote = sut.RemoteDeviceForSki(ski)
assert.Nil(d.T(), remote)
}

func (d *DeviceLocalTestSuite) Test_ProcessCmd_Errors() {
sut := spine.NewDeviceLocalImpl("brand", "model", "serial", "code", "address", model.DeviceTypeTypeEnergyManagementSystem, model.NetworkManagementFeatureSetTypeSmart)
localEntity := spine.NewEntityLocalImpl(sut, model.EntityTypeTypeCEM, spine.NewAddressEntityType([]uint{1}))
sut.AddEntity(localEntity)

ski := "test"
sut.AddRemoteDevice(ski, d)
remote := sut.RemoteDeviceForSki(ski)
assert.NotNil(d.T(), remote)

datagram := model.DatagramType{
Header: model.HeaderType{
AddressSource: &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("localdevice")),
},
AddressDestination: &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("localdevice")),
},
MsgCounter: util.Ptr(model.MsgCounterType(1)),
CmdClassifier: util.Ptr(model.CmdClassifierTypeRead),
},
Payload: model.PayloadType{
Cmd: []model.CmdType{},
},
}

err := sut.ProcessCmd(datagram, remote)
assert.NotNil(d.T(), err)

datagram = model.DatagramType{
Header: model.HeaderType{
AddressSource: &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("localdevice")),
},
AddressDestination: &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("localdevice")),
},
MsgCounter: util.Ptr(model.MsgCounterType(1)),
CmdClassifier: util.Ptr(model.CmdClassifierTypeRead),
},
Payload: model.PayloadType{
Cmd: []model.CmdType{
{},
},
},
}

err = sut.ProcessCmd(datagram, remote)
assert.NotNil(d.T(), err)
}

func (d *DeviceLocalTestSuite) Test_ProcessCmd() {
sut := spine.NewDeviceLocalImpl("brand", "model", "serial", "code", "address", model.DeviceTypeTypeEnergyManagementSystem, model.NetworkManagementFeatureSetTypeSmart)
localEntity := spine.NewEntityLocalImpl(sut, model.EntityTypeTypeCEM, spine.NewAddressEntityType([]uint{1}))
sut.AddEntity(localEntity)

f := spine.NewFeatureLocalImpl(1, localEntity, model.FeatureTypeTypeElectricalConnection, model.RoleTypeClient)
localEntity.AddFeature(f)
f = spine.NewFeatureLocalImpl(2, localEntity, model.FeatureTypeTypeMeasurement, model.RoleTypeClient)
localEntity.AddFeature(f)
f = spine.NewFeatureLocalImpl(3, localEntity, model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer)
localEntity.AddFeature(f)

ski := "test"
remoteDeviceName := "remote"
sut.AddRemoteDevice(ski, d)
remote := sut.RemoteDeviceForSki(ski)
assert.NotNil(d.T(), remote)

detailedData := &model.NodeManagementDetailedDiscoveryDataType{
DeviceInformation: &model.NodeManagementDetailedDiscoveryDeviceInformationType{
Description: &model.NetworkManagementDeviceDescriptionDataType{
DeviceAddress: &model.DeviceAddressType{
Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)),
},
},
},
EntityInformation: []model.NodeManagementDetailedDiscoveryEntityInformationType{
{
Description: &model.NetworkManagementEntityDescriptionDataType{
EntityAddress: &model.EntityAddressType{
Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)),
Entity: []model.AddressEntityType{1},
},
EntityType: util.Ptr(model.EntityTypeTypeEVSE),
},
},
},
FeatureInformation: []model.NodeManagementDetailedDiscoveryFeatureInformationType{
{
Description: &model.NetworkManagementFeatureDescriptionDataType{
FeatureAddress: &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)),
Entity: []model.AddressEntityType{1},
Feature: util.Ptr(model.AddressFeatureType(1)),
},
FeatureType: util.Ptr(model.FeatureTypeTypeElectricalConnection),
Role: util.Ptr(model.RoleTypeServer),
},
},
},
}
_, err := remote.AddEntityAndFeatures(true, detailedData)
assert.Nil(d.T(), err)

datagram := model.DatagramType{
Header: model.HeaderType{
AddressSource: &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)),
Entity: []model.AddressEntityType{1},
Feature: util.Ptr(model.AddressFeatureType(1)),
},
AddressDestination: &model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("localdevice")),
Entity: []model.AddressEntityType{1},
},
MsgCounter: util.Ptr(model.MsgCounterType(1)),
CmdClassifier: util.Ptr(model.CmdClassifierTypeRead),
},
Payload: model.PayloadType{
Cmd: []model.CmdType{},
},
}

err = sut.ProcessCmd(datagram, remote)
assert.NotNil(d.T(), err)

cmd := model.CmdType{
ElectricalConnectionParameterDescriptionListData: &model.ElectricalConnectionParameterDescriptionListDataType{},
}

datagram.Payload.Cmd = append(datagram.Payload.Cmd, cmd)

err = sut.ProcessCmd(datagram, remote)
assert.NotNil(d.T(), err)

datagram.Header.AddressDestination.Feature = util.Ptr(model.AddressFeatureType(1))

err = sut.ProcessCmd(datagram, remote)
assert.NotNil(d.T(), err)

datagram.Header.AddressDestination.Feature = util.Ptr(model.AddressFeatureType(3))

err = sut.ProcessCmd(datagram, remote)
assert.Nil(d.T(), err)
}
2 changes: 1 addition & 1 deletion spine/device_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (d *DeviceRemoteImpl) HandleIncomingSpineMesssage(message []byte) (*model.M
}
err := d.localDevice.ProcessCmd(datagram.Datagram, d)
if err != nil {
logging.Log.Error(err)
logging.Log.Trace(err)
}

return datagram.Datagram.Header.MsgCounter, nil
Expand Down
3 changes: 3 additions & 0 deletions spine/entity_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (r *EntityLocalImpl) Features() []FeatureLocal {
}

func (r *EntityLocalImpl) Feature(addressFeature *model.AddressFeatureType) FeatureLocal {
if addressFeature == nil {
return nil
}
for _, f := range r.features {
if *f.Address().Feature == *addressFeature {
return f
Expand Down
Loading

0 comments on commit 213258f

Please sign in to comment.