You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/01/18 14:07:32 UTC
[plc4x] branch develop updated: feat(plc4go/bacnet): implement BIPNetworkApplication
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 1860ffef47 feat(plc4go/bacnet): implement BIPNetworkApplication
1860ffef47 is described below
commit 1860ffef4734aa8c47fb393e62450bdf3673a68c
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jan 18 15:07:23 2023 +0100
feat(plc4go/bacnet): implement BIPNetworkApplication
---
plc4go/internal/bacnetip/ApplicationModule.go | 69 ++++++++++++++++++++++++++-
1 file changed, 67 insertions(+), 2 deletions(-)
diff --git a/plc4go/internal/bacnetip/ApplicationModule.go b/plc4go/internal/bacnetip/ApplicationModule.go
index 2089a63552..f4cbcf00dc 100644
--- a/plc4go/internal/bacnetip/ApplicationModule.go
+++ b/plc4go/internal/bacnetip/ApplicationModule.go
@@ -580,7 +580,7 @@ func NewBIPSimpleApplication(localDevice *LocalDeviceObject, localAddress Addres
// bind the top layers
if err := bind(b, b.asap, b.smap, b.nsap); err != nil {
- return nil, errors.New("error binding top layers")
+ return nil, errors.Wrap(err, "error binding top layers")
}
// create a generic BIP stack, bound to the Annex J server on the UDP multiplexer
@@ -681,7 +681,7 @@ func NewBIPForeignApplication(localDevice *LocalDeviceObject, localAddress Addre
// bind the top layers
if err := bind(b, b.asap, b.smap, b.nsap); err != nil {
- return nil, errors.New("error binding top layers")
+ return nil, errors.Wrap(err, "error binding top layers")
}
// create a generic BIP stack, bound to the Annex J server on the UDP multiplexer
@@ -717,3 +717,68 @@ func (b *BIPForeignApplication) Close() error {
// pass to the multiplexer, then down to the sockets
return b.mux.Close()
}
+
+type BIPNetworkApplication struct {
+ *NetworkServiceElement
+ localAddress Address
+ nsap *NetworkServiceAccessPoint
+ bip any // BIPSimple or BIPForeign
+ annexj *AnnexJCodec
+ mux *UDPMultiplexer
+}
+
+func NewBIPNetworkApplication(localAddress Address, bbmdAddress *Address, bbmdTTL *int, eID *int) (*BIPNetworkApplication, error) {
+ n := &BIPNetworkApplication{}
+ var err error
+ n.NetworkServiceElement, err = NewNetworkServiceElement(eID)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating new network service element")
+ }
+
+ n.localAddress = localAddress
+
+ // a network service access point will be needed
+ n.nsap, err = NewNetworkServiceAccessPoint(nil, nil, nil)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating network service access point")
+ }
+
+ // give the NSAP a generic network layer service element
+ if err := bind(n, n.nsap); err != nil {
+ return nil, errors.New("error binding network layer")
+ }
+
+ // create a generic BIP stack, bound to the Annex J server
+ // on the UDP multiplexer
+ if bbmdAddress == nil && bbmdTTL == nil {
+ n.bip, err = NewBIPSimple(nil, nil, nil)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating BIPSimple")
+ }
+ } else {
+ n.bip, err = NewBIPForeign(bbmdAddress, bbmdTTL, nil, nil, nil)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating BIPForeign")
+ }
+ }
+ n.annexj, err = NewAnnexJCodec(nil, nil)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating new annex j codec")
+ }
+ n.mux, err = NewUDPMultiplexer(n.localAddress, true)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating new udp multiplexer")
+ }
+
+ // bind the bottom layers
+ if err := bind(n.bip, n.annexj, n.mux.annexJ); err != nil {
+ return nil, errors.Wrap(err, "error binding bottom layers")
+ }
+
+ // bind the BIP stack to the network, no network number
+ if err := n.nsap.bind(n.bip.(_Server), nil, &n.localAddress); err != nil {
+ return nil, err
+ }
+
+ return n, nil
+}