Skip to content

Commit 3c848ad

Browse files
committed
fix(plc4go/bacnetip): binding errors
1 parent 4ba82d6 commit 3c848ad

15 files changed

+521
-799
lines changed

plc4go/internal/bacnetip/ApplicationModule.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ func (d *DeviceInfoCache) Release(deviceInfo DeviceInfo) error {
206206
return nil
207207
}
208208

209+
type ApplicationRequirements interface {
210+
ApplicationServiceElementRequirements
211+
}
209212
type Application struct {
210213
*ApplicationServiceElement
211214
Collector
@@ -225,7 +228,7 @@ type Application struct {
225228
log zerolog.Logger
226229
}
227230

228-
func NewApplication(localLog zerolog.Logger, localDevice *LocalDeviceObject, opts ...func(*Application)) (*Application, error) {
231+
func NewApplication(localLog zerolog.Logger, localDevice *LocalDeviceObject, requirements ApplicationRequirements, opts ...func(*Application)) (*Application, error) {
229232
a := &Application{
230233
log: localLog,
231234
}
@@ -238,7 +241,7 @@ func NewApplication(localLog zerolog.Logger, localDevice *LocalDeviceObject, opt
238241
Interface("aseID", a.argAseID).
239242
Msg("NewApplication")
240243
var err error
241-
a.ApplicationServiceElement, err = NewApplicationServiceElement(localLog, a, func(element *ApplicationServiceElement) {
244+
a.ApplicationServiceElement, err = NewApplicationServiceElement(localLog, requirements, func(element *ApplicationServiceElement) {
242245
element.elementID = a.argAseID
243246
})
244247
if err != nil {
@@ -473,7 +476,7 @@ func NewApplicationIOController(localLog zerolog.Logger, localDevice *LocalDevic
473476
if err != nil {
474477
return nil, errors.Wrap(err, "error creating io controller")
475478
}
476-
a.Application, err = NewApplication(localLog, localDevice, func(application *Application) {
479+
a.Application, err = NewApplication(localLog, localDevice, a, func(application *Application) {
477480
application.deviceInfoCache = a.argDeviceInfoCache
478481
application.argAseID = a.argAseID
479482
})

plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ func (b *BIPForeign) Indication(args Args, kwargs KWArgs) error {
755755
b.log.Debug().Stringer("xpdu", xpdu).Msg("xpdu")
756756

757757
// send it downstream
758-
return b.Request(NewArgs(NewPDUFromPDUWithNewMessage(pdu, xpdu)), NoKWArgs)
758+
return b.Request(NewArgs(xpdu), NoKWArgs)
759759
default:
760760
return errors.Errorf("invalid destination address: %s", pdu.GetPDUDestination())
761761
}

plc4go/internal/bacnetip/CommunicationsModule.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ import (
3535

3636
// maps of named clients and servers
3737
var clientMap map[int]*Client
38+
3839
var serverMap map[int]*Server
3940

4041
// maps of named SAPs and ASEs
4142
var serviceMap map[int]*ServiceAccessPoint
43+
4244
var elementMap map[int]*ApplicationServiceElement
4345

4446
func init() {
@@ -356,12 +358,12 @@ type ServiceAccessPointRequirements interface {
356358
SapRequest(Args, KWArgs) error
357359
SapIndication(Args, KWArgs) error
358360
SapResponse(Args, KWArgs) error
359-
_setServiceElement(serviceElement _ApplicationServiceElement)
361+
_setServiceElement(serviceElement ApplicationServiceElementContract)
360362
}
361363

362364
type ServiceAccessPoint struct {
363365
serviceID *int
364-
serviceElement _ApplicationServiceElement
366+
serviceElement ApplicationServiceElementContract
365367

366368
log zerolog.Logger
367369
}
@@ -419,6 +421,7 @@ func (s *ServiceAccessPoint) SapRequest(args Args, kwargs KWArgs) error {
419421
}
420422

421423
func (s *ServiceAccessPoint) SapIndication(Args, KWArgs) error {
424+
// TODO: we should remove this asap to check where we have actual caps because we can compile here
422425
panic("this should be implemented by outer struct")
423426
}
424427

@@ -432,15 +435,20 @@ func (s *ServiceAccessPoint) SapResponse(args Args, kwargs KWArgs) error {
432435
}
433436

434437
func (s *ServiceAccessPoint) SapConfirmation(Args, KWArgs) error {
438+
// TODO: we should remove this asap to check where we have actual caps because we can compile here
435439
panic("this should be implemented by outer struct")
436440
}
437441

438-
func (s *ServiceAccessPoint) _setServiceElement(serviceElement _ApplicationServiceElement) {
442+
func (s *ServiceAccessPoint) _setServiceElement(serviceElement ApplicationServiceElementContract) {
439443
s.serviceElement = serviceElement
440444
}
441445

442-
// _ApplicationServiceElement is an interface used for documentation
443-
type _ApplicationServiceElement interface {
446+
type ApplicationServiceElementRequirements interface {
447+
Confirmation(args Args, kwargs KWArgs) error
448+
}
449+
450+
// ApplicationServiceElementContract is an interface used for documentation
451+
type ApplicationServiceElementContract interface {
444452
Request(args Args, kwargs KWArgs) error
445453
Indication(args Args, kwargs KWArgs) error
446454
Response(args Args, kwargs KWArgs) error
@@ -455,7 +463,7 @@ type ApplicationServiceElement struct {
455463
log zerolog.Logger
456464
}
457465

458-
func NewApplicationServiceElement(localLog zerolog.Logger, rootStruct _ApplicationServiceElement, opts ...func(*ApplicationServiceElement)) (*ApplicationServiceElement, error) {
466+
func NewApplicationServiceElement(localLog zerolog.Logger, requirements ApplicationServiceElementRequirements, opts ...func(*ApplicationServiceElement)) (*ApplicationServiceElement, error) {
459467
a := &ApplicationServiceElement{
460468
log: localLog,
461469
}
@@ -476,8 +484,8 @@ func NewApplicationServiceElement(localLog zerolog.Logger, rootStruct _Applicati
476484
return nil, errors.Errorf("service access point %d already bound", aseID)
477485
}
478486

479-
// Note: we need to pass the rootStruct (which should contain a as delegate) here
480-
if err := Bind(localLog, rootStruct, service); err != nil {
487+
// Note: we need to pass the requirements (which should contain us as a delegate) here
488+
if err := Bind(localLog, requirements, service); err != nil {
481489
return nil, errors.Wrap(err, "error binding")
482490
}
483491
}
@@ -502,6 +510,7 @@ func (a *ApplicationServiceElement) Request(args Args, kwargs KWArgs) error {
502510
}
503511

504512
func (a *ApplicationServiceElement) Indication(Args, KWArgs) error {
513+
// TODO: we should remove this asap to check where we have actual caps because we can compile here
505514
panic("this should be implemented by outer struct")
506515
}
507516

@@ -516,6 +525,7 @@ func (a *ApplicationServiceElement) Response(args Args, kwargs KWArgs) error {
516525
}
517526

518527
func (a *ApplicationServiceElement) Confirmation(Args, KWArgs) error {
528+
// TODO: we should remove this asap to check where we have actual caps because we can compile here
519529
panic("this should be implemented by outer struct")
520530
}
521531

@@ -608,7 +618,7 @@ func Bind(localLog zerolog.Logger, args ...any) error {
608618
// make sure we're binding clients and servers
609619
clientCast, okClient := left.(_Client)
610620
serverCast, okServer := right.(_Server)
611-
elementServiceCast, okElementService := left.(_ApplicationServiceElement)
621+
elementServiceCast, okElementService := left.(ApplicationServiceElementContract)
612622
serviceAccessPointCast, okServiceAccessPoint := right.(ServiceAccessPointRequirements)
613623
if okClient && okServer {
614624
localLog.Trace().Msg("linking client-server")

plc4go/internal/bacnetip/mock_ApplicationRequirements_test.go

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)