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/01/12 19:14:49 UTC

[plc4x] 02/05: feat(bacnet): added ADPU unknown

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

commit e208e62f22ca0000658f30be8324d156e1ad5b84
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jan 12 12:57:14 2022 +0100

    feat(bacnet): added ADPU unknown
---
 .../plc4go/bacnetip/readwrite/model/APDU.go        |   2 +
 .../plc4go/bacnetip/readwrite/model/APDUUnknown.go | 133 +++++++++++++++++++++
 .../resources/protocols/bacnetip/bacnetip.mspec    |   3 +
 3 files changed, 138 insertions(+)

diff --git a/plc4go/internal/plc4go/bacnetip/readwrite/model/APDU.go b/plc4go/internal/plc4go/bacnetip/readwrite/model/APDU.go
index 7917d46..03d5336 100644
--- a/plc4go/internal/plc4go/bacnetip/readwrite/model/APDU.go
+++ b/plc4go/internal/plc4go/bacnetip/readwrite/model/APDU.go
@@ -123,6 +123,8 @@ func APDUParse(readBuffer utils.ReadBuffer, apduLength uint16) (*APDU, error) {
 		_parent, typeSwitchError = APDURejectParse(readBuffer, apduLength)
 	case apduType == 0x7: // APDUAbort
 		_parent, typeSwitchError = APDUAbortParse(readBuffer, apduLength)
+	case true: // APDUUnknown
+		_parent, typeSwitchError = APDUUnknownParse(readBuffer, apduLength)
 	default:
 		// TODO: return actual type
 		typeSwitchError = errors.New("Unmapped type")
diff --git a/plc4go/internal/plc4go/bacnetip/readwrite/model/APDUUnknown.go b/plc4go/internal/plc4go/bacnetip/readwrite/model/APDUUnknown.go
new file mode 100644
index 0000000..dcf89f4
--- /dev/null
+++ b/plc4go/internal/plc4go/bacnetip/readwrite/model/APDUUnknown.go
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package model
+
+import (
+	"github.com/apache/plc4x/plc4go/internal/plc4go/spi/utils"
+)
+
+// Code generated by code-generation. DO NOT EDIT.
+
+// The data-structure of this message
+type APDUUnknown struct {
+	*APDU
+}
+
+// The corresponding interface
+type IAPDUUnknown interface {
+	LengthInBytes() uint16
+	LengthInBits() uint16
+	Serialize(writeBuffer utils.WriteBuffer) error
+}
+
+///////////////////////////////////////////////////////////
+// Accessors for discriminator values.
+///////////////////////////////////////////////////////////
+func (m *APDUUnknown) ApduType() uint8 {
+	return 0
+}
+
+func (m *APDUUnknown) InitializeParent(parent *APDU) {
+}
+
+func NewAPDUUnknown() *APDU {
+	child := &APDUUnknown{
+		APDU: NewAPDU(),
+	}
+	child.Child = child
+	return child.APDU
+}
+
+func CastAPDUUnknown(structType interface{}) *APDUUnknown {
+	castFunc := func(typ interface{}) *APDUUnknown {
+		if casted, ok := typ.(APDUUnknown); ok {
+			return &casted
+		}
+		if casted, ok := typ.(*APDUUnknown); ok {
+			return casted
+		}
+		if casted, ok := typ.(APDU); ok {
+			return CastAPDUUnknown(casted.Child)
+		}
+		if casted, ok := typ.(*APDU); ok {
+			return CastAPDUUnknown(casted.Child)
+		}
+		return nil
+	}
+	return castFunc(structType)
+}
+
+func (m *APDUUnknown) GetTypeName() string {
+	return "APDUUnknown"
+}
+
+func (m *APDUUnknown) LengthInBits() uint16 {
+	return m.LengthInBitsConditional(false)
+}
+
+func (m *APDUUnknown) LengthInBitsConditional(lastItem bool) uint16 {
+	lengthInBits := uint16(m.ParentLengthInBits())
+
+	return lengthInBits
+}
+
+func (m *APDUUnknown) LengthInBytes() uint16 {
+	return m.LengthInBits() / 8
+}
+
+func APDUUnknownParse(readBuffer utils.ReadBuffer, apduLength uint16) (*APDU, error) {
+	if pullErr := readBuffer.PullContext("APDUUnknown"); pullErr != nil {
+		return nil, pullErr
+	}
+
+	if closeErr := readBuffer.CloseContext("APDUUnknown"); closeErr != nil {
+		return nil, closeErr
+	}
+
+	// Create a partially initialized instance
+	_child := &APDUUnknown{
+		APDU: &APDU{},
+	}
+	_child.APDU.Child = _child
+	return _child.APDU, nil
+}
+
+func (m *APDUUnknown) Serialize(writeBuffer utils.WriteBuffer) error {
+	ser := func() error {
+		if pushErr := writeBuffer.PushContext("APDUUnknown"); pushErr != nil {
+			return pushErr
+		}
+
+		if popErr := writeBuffer.PopContext("APDUUnknown"); popErr != nil {
+			return popErr
+		}
+		return nil
+	}
+	return m.SerializeParent(writeBuffer, m, ser)
+}
+
+func (m *APDUUnknown) String() string {
+	if m == nil {
+		return "<nil>"
+	}
+	buffer := utils.NewBoxedWriteBufferWithOptions(true, true)
+	m.Serialize(buffer)
+	return buffer.GetBox().String()
+}
diff --git a/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec b/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
index 2859ab5..39b9c4d 100644
--- a/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
+++ b/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
@@ -211,6 +211,9 @@
             [simple   uint 8 originalInvokeId       ]
             [simple   uint 8 abortReason            ]
         ]
+        [APDUUnknown
+            // TODO: find a way to slurp all remaining bytes for analysis
+        ]
     ]
 ]