Skip to content

Commit

Permalink
fix(plc4go/bacnetip): binding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 27, 2024
1 parent 4ba82d6 commit 3c848ad
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 799 deletions.
9 changes: 6 additions & 3 deletions plc4go/internal/bacnetip/ApplicationModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ func (d *DeviceInfoCache) Release(deviceInfo DeviceInfo) error {
return nil
}

type ApplicationRequirements interface {
ApplicationServiceElementRequirements
}
type Application struct {
*ApplicationServiceElement
Collector
Expand All @@ -225,7 +228,7 @@ type Application struct {
log zerolog.Logger
}

func NewApplication(localLog zerolog.Logger, localDevice *LocalDeviceObject, opts ...func(*Application)) (*Application, error) {
func NewApplication(localLog zerolog.Logger, localDevice *LocalDeviceObject, requirements ApplicationRequirements, opts ...func(*Application)) (*Application, error) {
a := &Application{
log: localLog,
}
Expand All @@ -238,7 +241,7 @@ func NewApplication(localLog zerolog.Logger, localDevice *LocalDeviceObject, opt
Interface("aseID", a.argAseID).
Msg("NewApplication")
var err error
a.ApplicationServiceElement, err = NewApplicationServiceElement(localLog, a, func(element *ApplicationServiceElement) {
a.ApplicationServiceElement, err = NewApplicationServiceElement(localLog, requirements, func(element *ApplicationServiceElement) {
element.elementID = a.argAseID
})
if err != nil {
Expand Down Expand Up @@ -473,7 +476,7 @@ func NewApplicationIOController(localLog zerolog.Logger, localDevice *LocalDevic
if err != nil {
return nil, errors.Wrap(err, "error creating io controller")
}
a.Application, err = NewApplication(localLog, localDevice, func(application *Application) {
a.Application, err = NewApplication(localLog, localDevice, a, func(application *Application) {
application.deviceInfoCache = a.argDeviceInfoCache
application.argAseID = a.argAseID
})
Expand Down
2 changes: 1 addition & 1 deletion plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func (b *BIPForeign) Indication(args Args, kwargs KWArgs) error {
b.log.Debug().Stringer("xpdu", xpdu).Msg("xpdu")

// send it downstream
return b.Request(NewArgs(NewPDUFromPDUWithNewMessage(pdu, xpdu)), NoKWArgs)
return b.Request(NewArgs(xpdu), NoKWArgs)
default:
return errors.Errorf("invalid destination address: %s", pdu.GetPDUDestination())
}
Expand Down
28 changes: 19 additions & 9 deletions plc4go/internal/bacnetip/CommunicationsModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ import (

// maps of named clients and servers
var clientMap map[int]*Client

var serverMap map[int]*Server

// maps of named SAPs and ASEs
var serviceMap map[int]*ServiceAccessPoint

var elementMap map[int]*ApplicationServiceElement

func init() {
Expand Down Expand Up @@ -356,12 +358,12 @@ type ServiceAccessPointRequirements interface {
SapRequest(Args, KWArgs) error
SapIndication(Args, KWArgs) error
SapResponse(Args, KWArgs) error
_setServiceElement(serviceElement _ApplicationServiceElement)
_setServiceElement(serviceElement ApplicationServiceElementContract)
}

type ServiceAccessPoint struct {
serviceID *int
serviceElement _ApplicationServiceElement
serviceElement ApplicationServiceElementContract

log zerolog.Logger
}
Expand Down Expand Up @@ -419,6 +421,7 @@ func (s *ServiceAccessPoint) SapRequest(args Args, kwargs KWArgs) error {
}

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

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

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

func (s *ServiceAccessPoint) _setServiceElement(serviceElement _ApplicationServiceElement) {
func (s *ServiceAccessPoint) _setServiceElement(serviceElement ApplicationServiceElementContract) {
s.serviceElement = serviceElement
}

// _ApplicationServiceElement is an interface used for documentation
type _ApplicationServiceElement interface {
type ApplicationServiceElementRequirements interface {
Confirmation(args Args, kwargs KWArgs) error
}

// ApplicationServiceElementContract is an interface used for documentation
type ApplicationServiceElementContract interface {
Request(args Args, kwargs KWArgs) error
Indication(args Args, kwargs KWArgs) error
Response(args Args, kwargs KWArgs) error
Expand All @@ -455,7 +463,7 @@ type ApplicationServiceElement struct {
log zerolog.Logger
}

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

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

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

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

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

Expand Down Expand Up @@ -608,7 +618,7 @@ func Bind(localLog zerolog.Logger, args ...any) error {
// make sure we're binding clients and servers
clientCast, okClient := left.(_Client)
serverCast, okServer := right.(_Server)
elementServiceCast, okElementService := left.(_ApplicationServiceElement)
elementServiceCast, okElementService := left.(ApplicationServiceElementContract)
serviceAccessPointCast, okServiceAccessPoint := right.(ServiceAccessPointRequirements)
if okClient && okServer {
localLog.Trace().Msg("linking client-server")
Expand Down
98 changes: 98 additions & 0 deletions plc4go/internal/bacnetip/mock_ApplicationRequirements_test.go

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

Loading

0 comments on commit 3c848ad

Please sign in to comment.