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 2022/11/22 14:09:48 UTC
[plc4x] branch develop updated: feat(plc4go/bacnet): implemented BIPSimple
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 198882b039 feat(plc4go/bacnet): implemented BIPSimple
198882b039 is described below
commit 198882b0399ba4e1d57094d7ebabdf889b9f102e
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Nov 22 15:09:21 2022 +0100
feat(plc4go/bacnet): implemented BIPSimple
---
.../bacnetip/BACnetVirtualLinkLayerService.go | 120 +++++++++++++++++++--
1 file changed, 114 insertions(+), 6 deletions(-)
diff --git a/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go b/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go
index 9e7212872a..9a467b43cb 100644
--- a/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go
+++ b/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go
@@ -20,6 +20,7 @@
package bacnetip
import (
+ readWriteModel "github.com/apache/plc4x/plc4go/protocols/bacnetip/readwrite/model"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)
@@ -234,11 +235,11 @@ func NewAnnexJCodec(cid *int, sid *int) (*AnnexJCodec, error) {
return a, nil
}
-func (b *AnnexJCodec) Indication(apdu _PDU) error {
+func (b *AnnexJCodec) Indication(pdu _PDU) error {
panic("not implemented yet")
}
-func (b *AnnexJCodec) Confirmation(apdu _PDU) error {
+func (b *AnnexJCodec) Confirmation(pdu _PDU) error {
panic("not implemented yet")
}
@@ -303,10 +304,117 @@ func NewBIPSimple(sapID *int, cid *int, sid *int) (*BIPSimple, error) {
return b, nil
}
-func (b *BIPSimple) Indication(apdu _PDU) error {
- panic("not implemented yet")
+func (b *BIPSimple) Indication(pdu _PDU) error {
+ log.Debug().Msgf("Indication %s", pdu)
+
+ // check for local stations
+ switch pdu.GetPDUDestination().AddrType {
+ case LOCAL_STATION_ADDRESS:
+ // make an original unicast PDU
+ xpdu := readWriteModel.NewBVLCOriginalUnicastNPDU(pdu.GetMessage().(readWriteModel.NPDU), 0)
+ log.Debug().Msgf("xpdu:\n%s", xpdu)
+
+ // send it downstream
+ return b.Request(NewPDUFromPDUWithNewMessage(pdu, xpdu))
+ case LOCAL_BROADCAST_ADDRESS:
+ // make an original broadcast PDU
+ xpdu := readWriteModel.NewBVLCOriginalBroadcastNPDU(pdu.GetMessage().(readWriteModel.NPDU), 0)
+
+ log.Debug().Msgf("xpdu:\n%s", xpdu)
+
+ // send it downstream
+ return b.Request(NewPDUFromPDUWithNewMessage(pdu, xpdu))
+ default:
+ return errors.Errorf("invalid destination address: %s", pdu.GetPDUDestination())
+ }
}
-func (b *BIPSimple) Response(apdu _PDU) error {
- panic("not implemented yet")
+func (b *BIPSimple) Confirmation(pdu _PDU) error {
+ log.Debug().Msgf("Confirmation %s", pdu)
+
+ switch msg := pdu.GetMessage().(type) {
+ // some kind of response to a request
+ case readWriteModel.BVLCResultExactly:
+ // send this to the service access point
+ return b.SapRequest(pdu)
+ case readWriteModel.BVLCReadBroadcastDistributionTableAckExactly:
+ // send this to the service access point
+ return b.SapRequest(pdu)
+ case readWriteModel.BVLCReadForeignDeviceTableAckExactly:
+ // send this to the service access point
+ return b.SapRequest(pdu)
+ case readWriteModel.BVLCOriginalUnicastNPDUExactly:
+ // build a vanilla PDU
+ xpdu := NewPDU(msg, WithPDUSource(pdu.GetPDUSource()), WithPDUDestination(pdu.GetPDUDestination()))
+ log.Debug().Msgf("xpdu: %s", xpdu)
+
+ // send it upstream
+ return b.Response(xpdu)
+ case readWriteModel.BVLCOriginalBroadcastNPDUExactly:
+ // build a PDU with a local broadcast address
+ xpdu := NewPDU(msg, WithPDUSource(pdu.GetPDUSource()), WithPDUDestination(NewLocalBroadcast(nil)))
+ log.Debug().Msgf("xpdu: %s", xpdu)
+
+ // send it upstream
+ return b.Response(xpdu)
+ case readWriteModel.BVLCForwardedNPDUExactly:
+ // build a PDU with the source from the real source
+ ip := msg.GetIp()
+ port := msg.GetPort()
+ source, err := NewAddress(append(ip, uint16ToPort(port)...))
+ if err != nil {
+ return errors.Wrap(err, "error building a ip")
+ }
+ xpdu := NewPDU(msg, WithPDUSource(source), WithPDUDestination(NewLocalBroadcast(nil)))
+ log.Debug().Msgf("xpdu: %s", xpdu)
+
+ // send it upstream
+ return b.Response(xpdu)
+ case readWriteModel.BVLCWriteBroadcastDistributionTableExactly:
+ // build a response
+ result := readWriteModel.NewBVLCResult(readWriteModel.BVLCResultCode_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK)
+ xpdu := NewPDU(result, WithPDUDestination(pdu.GetPDUSource()))
+
+ // send it downstream
+ return b.Request(xpdu)
+ case readWriteModel.BVLCReadBroadcastDistributionTableExactly:
+ // build a response
+ result := readWriteModel.NewBVLCResult(readWriteModel.BVLCResultCode_READ_BROADCAST_DISTRIBUTION_TABLE_NAK)
+ xpdu := NewPDU(result, WithPDUDestination(pdu.GetPDUSource()))
+
+ // send it downstream
+ return b.Request(xpdu)
+ // build a response
+ case readWriteModel.BVLCRegisterForeignDeviceExactly:
+ // build a response
+ result := readWriteModel.NewBVLCResult(readWriteModel.BVLCResultCode_REGISTER_FOREIGN_DEVICE_NAK)
+ xpdu := NewPDU(result, WithPDUDestination(pdu.GetPDUSource()))
+
+ // send it downstream
+ return b.Request(xpdu)
+ case readWriteModel.BVLCReadForeignDeviceTableExactly:
+ // build a response
+ result := readWriteModel.NewBVLCResult(readWriteModel.BVLCResultCode_READ_FOREIGN_DEVICE_TABLE_NAK)
+ xpdu := NewPDU(result, WithPDUDestination(pdu.GetPDUSource()))
+
+ // send it downstream
+ return b.Request(xpdu)
+ case readWriteModel.BVLCDeleteForeignDeviceTableEntryExactly:
+ // build a response
+ result := readWriteModel.NewBVLCResult(readWriteModel.BVLCResultCode_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK)
+ xpdu := NewPDU(result, WithPDUDestination(pdu.GetPDUSource()))
+
+ // send it downstream
+ return b.Request(xpdu)
+ case readWriteModel.BVLCDistributeBroadcastToNetworkExactly:
+ // build a response
+ result := readWriteModel.NewBVLCResult(readWriteModel.BVLCResultCode_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK)
+ xpdu := NewPDU(result, WithPDUDestination(pdu.GetPDUSource()))
+
+ // send it downstream
+ return b.Request(xpdu)
+ default:
+ log.Warn().Msgf("invalid pdu type %T", msg)
+ return nil
+ }
}