Skip to content

Commit 3b039de

Browse files
committed
Make sure the device name address is spec conform
If the vendor code is a number, only then use the “d:_i:” notation, otherwise use “d:_n:” notation
1 parent 5f91b10 commit 3b039de

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

service/service.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/x509"
55
"errors"
66
"fmt"
7+
"strconv"
78
"sync"
89

910
"github.com/enbility/eebus-go/api"
@@ -96,15 +97,20 @@ func (s *Service) Setup() error {
9697
}
9798

9899
// Create the SPINE device address, according to Protocol Specification 7.1.1.2
99-
deviceAdress := fmt.Sprintf("d:_i:%s_%s%s", vendor, sd.DeviceModel(), serial)
100+
var deviceAddress string
101+
vendorType := "i"
102+
if _, err := strconv.Atoi(vendor); err != nil {
103+
vendorType = "n"
104+
}
105+
deviceAddress = fmt.Sprintf("d:_%s:%s_%s%s", vendorType, vendor, sd.DeviceModel(), serial)
100106

101107
// Create the local SPINE device
102108
s.spineLocalDevice = spine.NewDeviceLocal(
103109
sd.DeviceBrand(),
104110
sd.DeviceModel(),
105111
sd.DeviceSerialNumber(),
106112
sd.Identifier(),
107-
deviceAdress,
113+
deviceAddress,
108114
sd.DeviceType(),
109115
sd.FeatureSet(),
110116
sd.HeartbeatTimeout(),

service/service_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,45 @@ func (s *ServiceSuite) Test_Setup() {
158158
err = s.sut.Setup()
159159
assert.Nil(s.T(), err)
160160

161+
address := s.sut.LocalDevice().Address()
162+
assert.Equal(s.T(), "d:_n:vendor_model-serial", string(*address))
163+
164+
s.sut.connectionsHub = s.conHub
165+
s.conHub.EXPECT().Start()
166+
s.sut.Start()
167+
168+
time.Sleep(time.Millisecond * 200)
169+
170+
s.conHub.EXPECT().Shutdown()
171+
s.sut.Shutdown()
172+
173+
device := s.sut.LocalDevice()
174+
assert.NotNil(s.T(), device)
175+
}
176+
177+
func (s *ServiceSuite) Test_Setup_IANA() {
178+
var err error
179+
certificate := tls.Certificate{}
180+
s.config, err = api.NewConfiguration(
181+
"12345", "brand", "model", "serial", model.DeviceTypeTypeEnergyManagementSystem,
182+
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, 230.0, time.Second*4)
183+
assert.Nil(s.T(), nil, err)
184+
185+
s.sut = NewService(s.config, s.serviceReader)
186+
187+
err = s.sut.Setup()
188+
assert.NotNil(s.T(), err)
189+
190+
certificate, err = cert.CreateCertificate("unit", "org", "de", "cn")
191+
assert.Nil(s.T(), err)
192+
s.config.SetCertificate(certificate)
193+
194+
err = s.sut.Setup()
195+
assert.Nil(s.T(), err)
196+
197+
address := s.sut.LocalDevice().Address()
198+
assert.Equal(s.T(), "d:_i:12345_model-serial", string(*address))
199+
161200
s.sut.connectionsHub = s.conHub
162201
s.conHub.EXPECT().Start()
163202
s.sut.Start()

0 commit comments

Comments
 (0)