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/05/27 15:58:38 UTC

[plc4x] branch develop updated: fix(bacnet): fix apdu unknown not consuming enough bits

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 1f7bed5881 fix(bacnet): fix apdu unknown not consuming enough bits
1f7bed5881 is described below

commit 1f7bed58814debcc996ba18ae816b581e236958d
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri May 27 17:58:31 2022 +0200

    fix(bacnet): fix apdu unknown not consuming enough bits
---
 .../bacnetip/readwrite/model/APDUUnknown.go        | 38 ++++++++++++++++++----
 .../resources/protocols/bacnetip/bacnetip.mspec    |  1 +
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/plc4go/protocols/bacnetip/readwrite/model/APDUUnknown.go b/plc4go/protocols/bacnetip/readwrite/model/APDUUnknown.go
index f7f4e8bde1..2a6bee7c66 100644
--- a/plc4go/protocols/bacnetip/readwrite/model/APDUUnknown.go
+++ b/plc4go/protocols/bacnetip/readwrite/model/APDUUnknown.go
@@ -29,7 +29,8 @@ import (
 // APDUUnknown is the data-structure of this message
 type APDUUnknown struct {
 	*APDU
-	UnknownBytes []byte
+	UnknownTypeRest uint8
+	UnknownBytes    []byte
 
 	// Arguments.
 	ApduLength uint16
@@ -38,6 +39,8 @@ type APDUUnknown struct {
 // IAPDUUnknown is the corresponding interface of APDUUnknown
 type IAPDUUnknown interface {
 	IAPDU
+	// GetUnknownTypeRest returns UnknownTypeRest (property field)
+	GetUnknownTypeRest() uint8
 	// GetUnknownBytes returns UnknownBytes (property field)
 	GetUnknownBytes() []byte
 	// GetLengthInBytes returns the length in bytes
@@ -73,6 +76,10 @@ func (m *APDUUnknown) GetParent() *APDU {
 /////////////////////// Accessors for property fields.
 ///////////////////////
 
+func (m *APDUUnknown) GetUnknownTypeRest() uint8 {
+	return m.UnknownTypeRest
+}
+
 func (m *APDUUnknown) GetUnknownBytes() []byte {
 	return m.UnknownBytes
 }
@@ -83,10 +90,11 @@ func (m *APDUUnknown) GetUnknownBytes() []byte {
 ///////////////////////////////////////////////////////////
 
 // NewAPDUUnknown factory function for APDUUnknown
-func NewAPDUUnknown(unknownBytes []byte, apduLength uint16) *APDUUnknown {
+func NewAPDUUnknown(unknownTypeRest uint8, unknownBytes []byte, apduLength uint16) *APDUUnknown {
 	_result := &APDUUnknown{
-		UnknownBytes: unknownBytes,
-		APDU:         NewAPDU(apduLength),
+		UnknownTypeRest: unknownTypeRest,
+		UnknownBytes:    unknownBytes,
+		APDU:            NewAPDU(apduLength),
 	}
 	_result.Child = _result
 	return _result
@@ -119,6 +127,9 @@ func (m *APDUUnknown) GetLengthInBits() uint16 {
 func (m *APDUUnknown) GetLengthInBitsConditional(lastItem bool) uint16 {
 	lengthInBits := uint16(m.GetParentLengthInBits())
 
+	// Simple field (unknownTypeRest)
+	lengthInBits += 4
+
 	// Array field
 	if len(m.UnknownBytes) > 0 {
 		lengthInBits += 8 * uint16(len(m.UnknownBytes))
@@ -139,6 +150,13 @@ func APDUUnknownParse(readBuffer utils.ReadBuffer, apduLength uint16) (*APDUUnkn
 	}
 	currentPos := positionAware.GetPos()
 	_ = currentPos
+
+	// Simple Field (unknownTypeRest)
+	_unknownTypeRest, _unknownTypeRestErr := readBuffer.ReadUint8("unknownTypeRest", 4)
+	if _unknownTypeRestErr != nil {
+		return nil, errors.Wrap(_unknownTypeRestErr, "Error parsing 'unknownTypeRest' field")
+	}
+	unknownTypeRest := _unknownTypeRest
 	// Byte Array field (unknownBytes)
 	numberOfBytesunknownBytes := int(utils.InlineIf(bool(bool((apduLength) > (0))), func() interface{} { return uint16(uint16(uint16(apduLength) - uint16(uint16(1)))) }, func() interface{} { return uint16(uint16(0)) }).(uint16))
 	unknownBytes, _readArrayErr := readBuffer.ReadByteArray("unknownBytes", numberOfBytesunknownBytes)
@@ -152,8 +170,9 @@ func APDUUnknownParse(readBuffer utils.ReadBuffer, apduLength uint16) (*APDUUnkn
 
 	// Create a partially initialized instance
 	_child := &APDUUnknown{
-		UnknownBytes: unknownBytes,
-		APDU:         &APDU{},
+		UnknownTypeRest: unknownTypeRest,
+		UnknownBytes:    unknownBytes,
+		APDU:            &APDU{},
 	}
 	_child.APDU.Child = _child
 	return _child, nil
@@ -167,6 +186,13 @@ func (m *APDUUnknown) Serialize(writeBuffer utils.WriteBuffer) error {
 			return pushErr
 		}
 
+		// Simple Field (unknownTypeRest)
+		unknownTypeRest := uint8(m.UnknownTypeRest)
+		_unknownTypeRestErr := writeBuffer.WriteUint8("unknownTypeRest", 4, (unknownTypeRest))
+		if _unknownTypeRestErr != nil {
+			return errors.Wrap(_unknownTypeRestErr, "Error serializing 'unknownTypeRest' field")
+		}
+
 		// Array Field (unknownBytes)
 		if m.UnknownBytes != nil {
 			// Byte Array field (unknownBytes)
diff --git a/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec b/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
index 56baef96e8..cd5cd38a6e 100644
--- a/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
+++ b/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
@@ -259,6 +259,7 @@
                                 abortReason                             ]
         ]
         [APDUUnknown
+            [simple   uint 4    unknownTypeRest                         ]
             [array    byte      unknownBytes length '(apduLength>0)?(apduLength - 1):0'    ]
         ]
     ]