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/03 15:42:45 UTC

[plc4x] branch develop updated: feat(protocol/bacnet): introduced new c-bus constant

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 a63ebe1ba feat(protocol/bacnet): introduced new c-bus constant
a63ebe1ba is described below

commit a63ebe1ba2536e85c26cf12cc5e0d1f59e2e3755
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Nov 3 16:42:37 2022 +0100

    feat(protocol/bacnet): introduced new c-bus constant
---
 plc4go/internal/bacnetip/Driver.go                 |   3 +-
 .../protocols/bacnetip/readwrite/ParserHelper.go   |   2 +
 .../bacnetip/readwrite/XmlParserHelper.go          |   2 +
 .../bacnetip/readwrite/model/BacnetConstants.go    | 172 +++++++++++++++++++++
 .../apache/plc4x/java/bacnetip/BacNetIpDriver.java |   2 -
 .../configuration/BacNetIpConfiguration.java       |   9 +-
 .../resources/protocols/bacnetip/bacnetip.mspec    |   4 +
 7 files changed, 187 insertions(+), 7 deletions(-)

diff --git a/plc4go/internal/bacnetip/Driver.go b/plc4go/internal/bacnetip/Driver.go
index fd181cad7..6e554e4b9 100644
--- a/plc4go/internal/bacnetip/Driver.go
+++ b/plc4go/internal/bacnetip/Driver.go
@@ -24,6 +24,7 @@ import (
 	"fmt"
 	"github.com/apache/plc4x/plc4go/pkg/api"
 	apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
+	"github.com/apache/plc4x/plc4go/protocols/bacnetip/readwrite/model"
 	"github.com/apache/plc4x/plc4go/spi"
 	_default "github.com/apache/plc4x/plc4go/spi/default"
 	"github.com/apache/plc4x/plc4go/spi/options"
@@ -67,7 +68,7 @@ func (m *Driver) GetConnection(transportUrl url.URL, transports map[string]trans
 		return ch
 	}
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
-	options["defaultUdpPort"] = []string{"47808"}
+	options["defaultUdpPort"] = []string{strconv.Itoa(int(model.BacnetConstants_BACNETUDPDEFAULTPORT))}
 	// Set so_reuse by default
 	if _, ok := options["so-reuse"]; !ok {
 		options["so-reuse"] = []string{"true"}
diff --git a/plc4go/protocols/bacnetip/readwrite/ParserHelper.go b/plc4go/protocols/bacnetip/readwrite/ParserHelper.go
index b9260da28..17cdd1390 100644
--- a/plc4go/protocols/bacnetip/readwrite/ParserHelper.go
+++ b/plc4go/protocols/bacnetip/readwrite/ParserHelper.go
@@ -1186,6 +1186,8 @@ func (m BacnetipParserHelper) Parse(typeName string, arguments []string, io util
 		}
 		tagClass, _ := model.TagClassByName(arguments[1])
 		return model.ErrorCodeTaggedParseWithBuffer(io, tagNumber, tagClass)
+	case "BacnetConstants":
+		return model.BacnetConstantsParseWithBuffer(io)
 	case "BACnetPolarityTagged":
 		tagNumber, err := utils.StrToUint8(arguments[0])
 		if err != nil {
diff --git a/plc4go/protocols/bacnetip/readwrite/XmlParserHelper.go b/plc4go/protocols/bacnetip/readwrite/XmlParserHelper.go
index 38784678e..c6247990a 100644
--- a/plc4go/protocols/bacnetip/readwrite/XmlParserHelper.go
+++ b/plc4go/protocols/bacnetip/readwrite/XmlParserHelper.go
@@ -1345,6 +1345,8 @@ func (m BacnetipXmlParserHelper) Parse(typeName string, xmlString string, parser
 		tagNumber := uint8(parsedUint0)
 		tagClass, _ := model.TagClassByName(parserArguments[1])
 		return model.ErrorCodeTaggedParseWithBuffer(utils.NewXmlReadBuffer(strings.NewReader(xmlString)), tagNumber, tagClass)
+	case "BacnetConstants":
+		return model.BacnetConstantsParseWithBuffer(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
 	case "BACnetPolarityTagged":
 		parsedUint0, err := strconv.ParseUint(parserArguments[0], 10, 8)
 		if err != nil {
diff --git a/plc4go/protocols/bacnetip/readwrite/model/BacnetConstants.go b/plc4go/protocols/bacnetip/readwrite/model/BacnetConstants.go
new file mode 100644
index 000000000..37b772e71
--- /dev/null
+++ b/plc4go/protocols/bacnetip/readwrite/model/BacnetConstants.go
@@ -0,0 +1,172 @@
+/*
+ * 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
+ *
+ *   https://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 (
+	"encoding/binary"
+	"fmt"
+	"github.com/apache/plc4x/plc4go/spi/utils"
+	"github.com/pkg/errors"
+)
+
+// Code generated by code-generation. DO NOT EDIT.
+
+// Constant values.
+const BacnetConstants_BACNETUDPDEFAULTPORT uint16 = uint16(47808)
+
+// BacnetConstants is the corresponding interface of BacnetConstants
+type BacnetConstants interface {
+	utils.LengthAware
+	utils.Serializable
+}
+
+// BacnetConstantsExactly can be used when we want exactly this type and not a type which fulfills BacnetConstants.
+// This is useful for switch cases.
+type BacnetConstantsExactly interface {
+	BacnetConstants
+	isBacnetConstants() bool
+}
+
+// _BacnetConstants is the data-structure of this message
+type _BacnetConstants struct {
+}
+
+///////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////
+/////////////////////// Accessors for const fields.
+///////////////////////
+
+func (m *_BacnetConstants) GetBacnetUdpDefaultPort() uint16 {
+	return BacnetConstants_BACNETUDPDEFAULTPORT
+}
+
+///////////////////////
+///////////////////////
+///////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////
+
+// NewBacnetConstants factory function for _BacnetConstants
+func NewBacnetConstants() *_BacnetConstants {
+	return &_BacnetConstants{}
+}
+
+// Deprecated: use the interface for direct cast
+func CastBacnetConstants(structType interface{}) BacnetConstants {
+	if casted, ok := structType.(BacnetConstants); ok {
+		return casted
+	}
+	if casted, ok := structType.(*BacnetConstants); ok {
+		return *casted
+	}
+	return nil
+}
+
+func (m *_BacnetConstants) GetTypeName() string {
+	return "BacnetConstants"
+}
+
+func (m *_BacnetConstants) GetLengthInBits() uint16 {
+	return m.GetLengthInBitsConditional(false)
+}
+
+func (m *_BacnetConstants) GetLengthInBitsConditional(lastItem bool) uint16 {
+	lengthInBits := uint16(0)
+
+	// Const Field (bacnetUdpDefaultPort)
+	lengthInBits += 16
+
+	return lengthInBits
+}
+
+func (m *_BacnetConstants) GetLengthInBytes() uint16 {
+	return m.GetLengthInBits() / 8
+}
+
+func BacnetConstantsParse(theBytes []byte) (BacnetConstants, error) {
+	return BacnetConstantsParseWithBuffer(utils.NewReadBufferByteBased(theBytes, utils.WithByteOrderForReadBufferByteBased(binary.BigEndian))) // TODO: get endianness from mspec
+}
+
+func BacnetConstantsParseWithBuffer(readBuffer utils.ReadBuffer) (BacnetConstants, error) {
+	positionAware := readBuffer
+	_ = positionAware
+	if pullErr := readBuffer.PullContext("BacnetConstants"); pullErr != nil {
+		return nil, errors.Wrap(pullErr, "Error pulling for BacnetConstants")
+	}
+	currentPos := positionAware.GetPos()
+	_ = currentPos
+
+	// Const Field (bacnetUdpDefaultPort)
+	bacnetUdpDefaultPort, _bacnetUdpDefaultPortErr := readBuffer.ReadUint16("bacnetUdpDefaultPort", 16)
+	if _bacnetUdpDefaultPortErr != nil {
+		return nil, errors.Wrap(_bacnetUdpDefaultPortErr, "Error parsing 'bacnetUdpDefaultPort' field of BacnetConstants")
+	}
+	if bacnetUdpDefaultPort != BacnetConstants_BACNETUDPDEFAULTPORT {
+		return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", BacnetConstants_BACNETUDPDEFAULTPORT) + " but got " + fmt.Sprintf("%d", bacnetUdpDefaultPort))
+	}
+
+	if closeErr := readBuffer.CloseContext("BacnetConstants"); closeErr != nil {
+		return nil, errors.Wrap(closeErr, "Error closing for BacnetConstants")
+	}
+
+	// Create the instance
+	return &_BacnetConstants{}, nil
+}
+
+func (m *_BacnetConstants) Serialize() ([]byte, error) {
+	wb := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.BigEndian), utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes()))) // TODO: get endianness from mspec
+	if err := m.SerializeWithWriteBuffer(wb); err != nil {
+		return nil, err
+	}
+	return wb.GetBytes(), nil
+}
+
+func (m *_BacnetConstants) SerializeWithWriteBuffer(writeBuffer utils.WriteBuffer) error {
+	positionAware := writeBuffer
+	_ = positionAware
+	if pushErr := writeBuffer.PushContext("BacnetConstants"); pushErr != nil {
+		return errors.Wrap(pushErr, "Error pushing for BacnetConstants")
+	}
+
+	// Const Field (bacnetUdpDefaultPort)
+	_bacnetUdpDefaultPortErr := writeBuffer.WriteUint16("bacnetUdpDefaultPort", 16, 47808)
+	if _bacnetUdpDefaultPortErr != nil {
+		return errors.Wrap(_bacnetUdpDefaultPortErr, "Error serializing 'bacnetUdpDefaultPort' field")
+	}
+
+	if popErr := writeBuffer.PopContext("BacnetConstants"); popErr != nil {
+		return errors.Wrap(popErr, "Error popping for BacnetConstants")
+	}
+	return nil
+}
+
+func (m *_BacnetConstants) isBacnetConstants() bool {
+	return true
+}
+
+func (m *_BacnetConstants) String() string {
+	if m == nil {
+		return "<nil>"
+	}
+	writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true)
+	if err := writeBuffer.WriteSerializable(m); err != nil {
+		return err.Error()
+	}
+	return writeBuffer.GetBox().String()
+}
diff --git a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/BacNetIpDriver.java b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/BacNetIpDriver.java
index 61af1b4d6..a405103d4 100644
--- a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/BacNetIpDriver.java
+++ b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/BacNetIpDriver.java
@@ -35,8 +35,6 @@ import java.util.function.ToIntFunction;
 
 public class BacNetIpDriver extends GeneratedDriverBase<BVLC> {
 
-    public static final int BACNET_IP_PORT = 47808;
-
     @Override
     public String getProtocolCode() {
         return "bacnet-ip";
diff --git a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/configuration/BacNetIpConfiguration.java b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/configuration/BacNetIpConfiguration.java
index 9a08e9ee5..46cfab679 100644
--- a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/configuration/BacNetIpConfiguration.java
+++ b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/configuration/BacNetIpConfiguration.java
@@ -18,7 +18,7 @@
  */
 package org.apache.plc4x.java.bacnetip.configuration;
 
-import org.apache.plc4x.java.bacnetip.BacNetIpDriver;
+import org.apache.plc4x.java.bacnetip.readwrite.BacnetConstants;
 import org.apache.plc4x.java.spi.configuration.Configuration;
 import org.apache.plc4x.java.spi.configuration.annotations.ConfigurationParameter;
 import org.apache.plc4x.java.spi.configuration.annotations.defaults.DoubleDefaultValue;
@@ -84,7 +84,7 @@ public class BacNetIpConfiguration implements Configuration, UdpTransportConfigu
 
     @Override
     public int getDefaultPort() {
-        return BacNetIpDriver.BACNET_IP_PORT;
+        return BacnetConstants.BACNETUDPDEFAULTPORT;
     }
 
     @Override
@@ -105,18 +105,19 @@ public class BacNetIpConfiguration implements Configuration, UdpTransportConfigu
      * Packet handler to use when running in PCAP mode.
      * In this case all packets are Ethernet frames and we need to first get the
      * IP packet and then the UDP packet and then the raw data from that.
+     *
      * @return payload of the packet.
      */
     @Override
     public PacketHandler getPcapPacketHandler() {
         return packet -> {
             // If it's a VLan packet, we need to go one level deeper.
-            if(packet.getPayload() instanceof Dot1qVlanTagPacket) {
+            if (packet.getPayload() instanceof Dot1qVlanTagPacket) {
                 return packet.getPayload().getPayload().getPayload().getPayload().getRawData();
             }
             // This is a normal udp packet.
             else {
-                if((packet.getPayload() != null) && (packet.getPayload().getPayload() != null) && (packet.getPayload().getPayload().getPayload() != null)) {
+                if ((packet.getPayload() != null) && (packet.getPayload().getPayload() != null) && (packet.getPayload().getPayload().getPayload() != null)) {
                     return packet.getPayload().getPayload().getPayload().getRawData();
                 }
             }
diff --git a/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec b/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
index cac28b62a..91149d796 100644
--- a/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
+++ b/protocols/bacnetip/src/main/resources/protocols/bacnetip/bacnetip.mspec
@@ -17,6 +17,10 @@
  * under the License.
  */
 
+[type BacnetConstants
+    [const    uint 16     bacnetUdpDefaultPort 47808]
+]
+
 [discriminatedType BVLC byteOrder='BIG_ENDIAN'
     [const         uint 8   bacnetType   0x81                   ]
     [discriminator uint 8   bvlcFunction                        ]