You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2021/02/05 17:38:59 UTC

[plc4x] branch develop updated: - Made the driver more robust against not 100% compliant devices

This is an automated email from the ASF dual-hosted git repository.

cdutz 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 cedcc5e  - Made the driver more robust against not 100% compliant devices
cedcc5e is described below

commit cedcc5eef66d06808101778eba62e1f1d238353f
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Fri Feb 5 18:38:51 2021 +0100

    - Made the driver more robust against not 100% compliant devices
---
 plc4go/cmd/main/drivers/knxnetip_test.go                 | 16 ++++++++++++++++
 .../knxnetip/readwrite/model/DIBSuppSvcFamilies.go       | 12 +++++++-----
 .../src/main/resources/protocols/knxnetip/knxnetip.mspec |  2 +-
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/plc4go/cmd/main/drivers/knxnetip_test.go b/plc4go/cmd/main/drivers/knxnetip_test.go
index 21a2a97..6e8cbde 100644
--- a/plc4go/cmd/main/drivers/knxnetip_test.go
+++ b/plc4go/cmd/main/drivers/knxnetip_test.go
@@ -24,6 +24,7 @@ import (
 	"github.com/apache/plc4x/plc4go/internal/plc4go/knxnetip"
 	driverModel "github.com/apache/plc4x/plc4go/internal/plc4go/knxnetip/readwrite/model"
 	"github.com/apache/plc4x/plc4go/internal/plc4go/spi/transports/udp"
+	"github.com/apache/plc4x/plc4go/internal/plc4go/spi/utils"
 	"github.com/apache/plc4x/plc4go/pkg/plc4go"
 	apiModel "github.com/apache/plc4x/plc4go/pkg/plc4go/model"
 	"github.com/apache/plc4x/plc4go/pkg/plc4go/values"
@@ -39,6 +40,21 @@ func Init() {
 	log.SetLevel(log.DebugLevel)
 }
 
+func TestParser(t *testing.T) {
+	request, err := hex.DecodeString("06100202004a0801c0a8031b0e573601020000000000000000000000e000170c000000000000656962640000000000000000000000000000000000000000000000000000060202010401")
+	if err != nil {
+		// Output an error ...
+	}
+	rb := utils.NewReadBuffer(request)
+	knxMessage, err := driverModel.KnxNetIpMessageParse(rb)
+	if err != nil {
+		fmt.Printf("Got error parsing message: %s\n", err.Error())
+		// TODO: Possibly clean up ...
+		return
+	}
+	print(knxMessage)
+}
+
 func TestKnxNetIpPlc4goBrowse(t *testing.T) {
 	Init()
 
diff --git a/plc4go/internal/plc4go/knxnetip/readwrite/model/DIBSuppSvcFamilies.go b/plc4go/internal/plc4go/knxnetip/readwrite/model/DIBSuppSvcFamilies.go
index 200629c..50935d6 100644
--- a/plc4go/internal/plc4go/knxnetip/readwrite/model/DIBSuppSvcFamilies.go
+++ b/plc4go/internal/plc4go/knxnetip/readwrite/model/DIBSuppSvcFamilies.go
@@ -87,7 +87,7 @@ func (m *DIBSuppSvcFamilies) LengthInBytes() uint16 {
 func DIBSuppSvcFamiliesParse(io *utils.ReadBuffer) (*DIBSuppSvcFamilies, error) {
 
     // Implicit Field (structureLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content)
-    _, _structureLengthErr := io.ReadUint8(8)
+    structureLength, _structureLengthErr := io.ReadUint8(8)
     if _structureLengthErr != nil {
         return nil, errors.New("Error parsing 'structureLength' field " + _structureLengthErr.Error())
     }
@@ -99,14 +99,16 @@ func DIBSuppSvcFamiliesParse(io *utils.ReadBuffer) (*DIBSuppSvcFamilies, error)
     }
 
     // Array field (serviceIds)
-    // Count array
-    serviceIds := make([]*ServiceId, uint16(3))
-    for curItem := uint16(0); curItem < uint16(uint16(3)); curItem++ {
+    // Length array
+    serviceIds := make([]*ServiceId, 0)
+    _serviceIdsLength := uint16(structureLength) - uint16(uint16(2))
+    _serviceIdsEndPos := io.GetPos() + uint16(_serviceIdsLength)
+    for ;io.GetPos() < _serviceIdsEndPos; {
         _item, _err := ServiceIdParse(io)
         if _err != nil {
             return nil, errors.New("Error parsing 'serviceIds' field " + _err.Error())
         }
-        serviceIds[curItem] = _item
+        serviceIds = append(serviceIds, _item)
     }
 
     // Create the instance
diff --git a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
index 534f310..cbe4d81 100644
--- a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
+++ b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
@@ -119,7 +119,7 @@
 [type 'DIBSuppSvcFamilies'
     [implicit uint 8       'structureLength' 'lengthInBytes']
     [simple   uint 8       'descriptionType']
-    [array    ServiceId    'serviceIds' count '3']
+    [array    ServiceId    'serviceIds' length 'structureLength - 2']
 ]
 
 [type 'HPAIDataEndpoint'