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 ecf4443893 feat(plc4go/bacnetip): WriteBroadcastDistributionTable
ecf4443893 is described below

commit ecf4443893badfa40362d32f4b5f4abcbddc7d57
Author: Sebastian Rühl <[email protected]>
AuthorDate: Thu Aug 22 17:25:14 2024 +0200

    feat(plc4go/bacnetip): WriteBroadcastDistributionTable
---
 .../bacnetip/BACnetVirtualLinkLayerService.go      |  1 -
 plc4go/internal/bacnetip/bvll.go                   | 39 ++++++++++++++++++----
 plc4go/internal/bacnetip/tests/state_machine.go    |  4 +--
 .../bacnetip/tests/test_bvll/test_codec_test.go    |  1 -
 4 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go 
b/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go
index a195173140..384bfc53ba 100644
--- a/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go
+++ b/plc4go/internal/bacnetip/BACnetVirtualLinkLayerService.go
@@ -329,7 +329,6 @@ func (b *AnnexJCodec) Indication(args Args, kwargs KWArgs) 
error {
 
        // encode it as a generic BVLL PDU
        bvlpdu := NewBVLPDU(nil)
-       // TODO: runtime cast might be dangerous
        if err := rpdu.(interface{ Encode(Arg) error }).Encode(bvlpdu); err != 
nil {
                return errors.Wrap(err, "error encoding PDU")
        }
diff --git a/plc4go/internal/bacnetip/bvll.go b/plc4go/internal/bacnetip/bvll.go
index fd6f23b5a7..2ba8277165 100644
--- a/plc4go/internal/bacnetip/bvll.go
+++ b/plc4go/internal/bacnetip/bvll.go
@@ -21,6 +21,7 @@ package bacnetip
 
 import (
        "context"
+       "encoding/binary"
        "fmt"
 
        readWriteModel 
"github.com/apache/plc4x/plc4go/protocols/bacnetip/readwrite/model"
@@ -109,7 +110,6 @@ func NewBVLPDU(bvlc readWriteModel.BVLC) BVLPDU {
        b := &_BVLPDU{
                bvlc: bvlc,
        }
-       //b.bvlc = readWriteModel.NewBVLC() // TODO: using this function leads 
to a npe
        b._BVLCI = NewBVLCI(bvlc).(*_BVLCI)
        b._PDUData = newPDUData(b)
        return b
@@ -282,7 +282,7 @@ func NewWriteBroadcastDistributionTable(opts 
...func(*WriteBroadcastDistribution
        for _, opt := range opts {
                opt(b)
        }
-       b._BVLPDU = NewBVLPDU(nil).(*_BVLPDU)
+       b._BVLPDU = 
NewBVLPDU(readWriteModel.NewBVLCWriteBroadcastDistributionTable(b.produceBroadcastDistributionTable(),
 0)).(*_BVLPDU)
        return b, nil
 }
 
@@ -296,6 +296,35 @@ func (w *WriteBroadcastDistributionTable) GetBvlciBDT() 
[]*Address {
        return w.bvlciBDT
 }
 
+func (w *WriteBroadcastDistributionTable) produceBroadcastDistributionTable() 
(entries []readWriteModel.BVLCBroadcastDistributionTableEntry) {
+       for _, address := range w.bvlciBDT {
+               addr := address.AddrAddress[:4]
+               port := uint16(47808)
+               if address.AddrPort != nil {
+                       port = *address.AddrPort
+               }
+               mask := make([]byte, 4)
+               if address.AddrMask != nil {
+                       binary.BigEndian.PutUint32(mask, *address.AddrMask)
+               }
+               entries = append(entries, 
readWriteModel.NewBVLCBroadcastDistributionTableEntry(addr, port, mask))
+       }
+       return
+}
+
+func (w *WriteBroadcastDistributionTable) produceBvlciBDT(entries 
[]readWriteModel.BVLCBroadcastDistributionTableEntry) (bvlciBDT []*Address) {
+       for _, entry := range entries {
+               addr := entry.GetIp()
+               port := entry.GetPort()
+               var portArray = make([]byte, 2)
+               binary.BigEndian.PutUint16(portArray, port)
+               address, _ := NewAddress(zerolog.Nop(), append(addr, 
portArray...))
+               mask := 
binary.BigEndian.Uint32(entry.GetBroadcastDistributionMap())
+               address.AddrMask = &mask
+               bvlciBDT = append(bvlciBDT, address)
+       }
+       return
+}
 func (w *WriteBroadcastDistributionTable) Encode(bvlpdu Arg) error {
        switch bvlpdu := bvlpdu.(type) {
        case BVLPDU:
@@ -324,11 +353,7 @@ func (w *WriteBroadcastDistributionTable) Decode(bvlpdu 
Arg) error {
                        switch bvlc := pduUserData.(type) {
                        case readWriteModel.BVLCWriteBroadcastDistributionTable:
                                w.setBVLC(bvlc)
-                               for _, entry := range bvlc.GetTable() {
-                                       // TODO: what is with port and the map??
-                                       address, _ := NewAddress(zerolog.Nop(), 
entry.GetIp())
-                                       w.bvlciBDT = append(w.bvlciBDT, address)
-                               }
+                               w.bvlciBDT = w.produceBvlciBDT(bvlc.GetTable())
                        }
                }
                return nil
diff --git a/plc4go/internal/bacnetip/tests/state_machine.go 
b/plc4go/internal/bacnetip/tests/state_machine.go
index c3f702de81..dae5d478bc 100644
--- a/plc4go/internal/bacnetip/tests/state_machine.go
+++ b/plc4go/internal/bacnetip/tests/state_machine.go
@@ -146,9 +146,9 @@ func MatchPdu(localLog zerolog.Logger, pdu bacnetip.PDU, 
pduType any, pduAttrs m
                        if !equal {
                                switch want := want.(type) {
                                case []byte:
-                                       localLog.Debug().Bytes("got", 
got).Bytes("want", want).Msg("mismatch")
+                                       localLog.Debug().Hex("got", 
got).Hex("want", want).Msg("mismatch")
                                default:
-                                       localLog.Debug().Bytes("got", 
got).Interface("want", want).Msg("mismatch")
+                                       localLog.Debug().Hex("got", 
got).Interface("want", want).Msg("mismatch")
                                }
                        }
                        return equal
diff --git a/plc4go/internal/bacnetip/tests/test_bvll/test_codec_test.go 
b/plc4go/internal/bacnetip/tests/test_bvll/test_codec_test.go
index e38f2cb46f..a3ab26ca59 100644
--- a/plc4go/internal/bacnetip/tests/test_bvll/test_codec_test.go
+++ b/plc4go/internal/bacnetip/tests/test_bvll/test_codec_test.go
@@ -154,7 +154,6 @@ func (suite *TestAnnexJCodecSuite) TestResult() {
 }
 
 func (suite *TestAnnexJCodecSuite) TestWriteBroadcastDistributionTable() {
-       suite.T().Skip("something is odd here") // TODO: check what is going on 
with the output...
        // write an empty table
        pduBytes, err := bacnetip.Xtob("81.01.0004")
        suite.Require().NoError(err)

Reply via email to