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 2020/01/26 17:14:08 UTC
[plc4x] branch develop updated: - Created a IEE 764 standard
compliant float parsing code - Created a helper for KNX that uses KNX's
special half-precision floating-point encoding - Fixed the
GeneratedDriverByteToMessageCodec to only add a maximum of 16 messages to
the out queue - Fixed the replay speed of the PcapSocketChannel - Changed
the used type for fields referencing dataIo types to PlcValue - Added
support for Abstract types
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 c8c07bb - Created a IEE 764 standard compliant float parsing code - Created a helper for KNX that uses KNX's special half-precision floating-point encoding - Fixed the GeneratedDriverByteToMessageCodec to only add a maximum of 16 messages to the out queue - Fixed the replay speed of the PcapSocketChannel - Changed the used type for fields referencing dataIo types to PlcValue - Added support for Abstract types
c8c07bb is described below
commit c8c07bb788e74be8af14a6cbf05dec1b30cebf6c
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Jan 26 18:13:51 2020 +0100
- Created a IEE 764 standard compliant float parsing code
- Created a helper for KNX that uses KNX's special half-precision floating-point encoding
- Fixed the GeneratedDriverByteToMessageCodec to only add a maximum of 16 messages to the out queue
- Fixed the replay speed of the PcapSocketChannel
- Changed the used type for fields referencing dataIo types to PlcValue
- Added support for Abstract types
---
.../language/java/JavaLanguageTemplateHelper.java | 31 +++++++----
.../resources/templates/java/data-io-template.ftlh | 4 +-
.../main/resources/templates/java/io-template.ftlh | 11 ++--
.../resources/templates/java/pojo-template.ftlh | 4 ++
.../plugins/codegenerator/language/mspec/MSpec.g4 | 7 ++-
.../mspec/model/fields/DefaultAbstractField.java | 52 +++++++++++++++++
.../mspec/parser/MessageFormatListener.java | 11 ++++
.../knxnetip/protocol/KnxNetIpProtocolLogic.java | 16 ++++--
.../plc4x/java/knxnetip/utils/KnxHelper.java | 65 ++++++++++++++++++++++
.../spi/GeneratedDriverByteToMessageCodec.java | 6 ++
.../plc4x/java/spi/generation/StaticHelper.java | 42 ++++++++++++++
.../pcapsockets/netty/PcapSocketChannelConfig.java | 2 +-
pom.xml | 2 +-
.../resources/protocols/knxnetip/knxnetip.mspec | 2 +-
14 files changed, 228 insertions(+), 27 deletions(-)
diff --git a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
index 5d3cc4e..ad867e0 100644
--- a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
+++ b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
@@ -49,6 +49,17 @@ public class JavaLanguageTemplateHelper implements FreemarkerLanguageTemplateHel
public String getLanguageTypeNameForField(TypedField field) {
boolean optional = field instanceof OptionalField;
+ // If the referenced type is a DataIo type, the value is of type PlcValue.
+ if(field instanceof PropertyField) {
+ PropertyField propertyField = (PropertyField) field;
+ if(propertyField.getType() instanceof ComplexTypeReference) {
+ ComplexTypeReference complexTypeReference = (ComplexTypeReference) propertyField.getType();
+ final TypeDefinition typeDefinition = types.get(complexTypeReference.getName());
+ if(typeDefinition instanceof DataIoTypeDefinition) {
+ return "PlcValue";
+ }
+ }
+ }
return getLanguageTypeNameForField(field, !optional);
}
@@ -267,18 +278,10 @@ public class JavaLanguageTemplateHelper implements FreemarkerLanguageTemplateHel
String typeCast = (floatTypeReference.getSizeInBits() <= 32) ? "float" : "double";
String defaultNull = (floatTypeReference.getSizeInBits() <= 32) ? "0.0f" : "0.0";
StringBuilder sb = new StringBuilder("((Supplier<").append(type).append(">) (() -> {");
- sb.append("\n try {");
- if (floatTypeReference.getBaseType() == SimpleTypeReference.SimpleBaseType.FLOAT) {
- sb.append("\n boolean negative = io.readBit();");
- } else {
- sb.append("\n boolean negative = false;");
- }
- sb.append("\n long exponent = io.readUnsignedLong(").append(floatTypeReference.getExponent()).append(");");
- sb.append("\n long mantissa = io.readUnsignedLong(").append(floatTypeReference.getMantissa()).append(");");
- sb.append("\n return (").append(typeCast).append(") ((negative ? -1 : 1) * (0.01 * mantissa) * Math.pow(2, exponent));");
- sb.append("\n } catch(ParseException e) {");
- sb.append("\n return ").append(defaultNull).append(";");
- sb.append("\n }");
+ sb.append("\n return (").append(typeCast).append(") toFloat(io, ").append(
+ (floatTypeReference.getBaseType() == SimpleTypeReference.SimpleBaseType.FLOAT) ? "true" : "false")
+ .append(", ").append(floatTypeReference.getExponent()).append(", ")
+ .append(floatTypeReference.getMantissa()).append(");");
sb.append("\n })).get()");
return sb.toString();
}
@@ -425,6 +428,10 @@ public class JavaLanguageTemplateHelper implements FreemarkerLanguageTemplateHel
return typeDefinition instanceof DiscriminatedComplexTypeDefinition;
}
+ public boolean isAbstractField(Field field) {
+ return field instanceof AbstractField;
+ }
+
public boolean isCountArray(ArrayField arrayField) {
return arrayField.getLoopType() == ArrayField.LoopType.COUNT;
}
diff --git a/build-utils/language-java/src/main/resources/templates/java/data-io-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/data-io-template.ftlh
index ede70bc..d9a5a49 100644
--- a/build-utils/language-java/src/main/resources/templates/java/data-io-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/data-io-template.ftlh
@@ -64,8 +64,8 @@ public class ${typeName}IO {
public static PlcValue staticParse(ReadBuffer io<#if type.parserArguments?has_content>, <#list type.parserArguments as parserArgument>${helper.getLanguageTypeName(parserArgument.type, false)} ${parserArgument.name}<#sep>, </#sep></#list></#if>) throws ParseException {
<#list type.switchField.cases as case><#if case.discriminatorValues?has_content>if(<#list case.discriminatorValues as discriminatorValue>EvaluationHelper.equals(${helper.toSwitchExpression(type.switchField.discriminatorNames[discriminatorValue?index])}, ${discriminatorValue})<#sep> && </#sep></#list>) </#if>{ // ${case.name}
+ <#assign skipReturn=false>
<#list case.fields as field>
- <#assign skipReturn=false>
<#switch field.typeName>
<#case "array">
@@ -227,7 +227,7 @@ public class ${typeName}IO {
<#if outputFlavor != "passive">
public static WriteBuffer staticSerialize(PlcValue _value<#if type.parserArguments?has_content>, <#list type.parserArguments as parserArgument>${helper.getLanguageTypeName(parserArgument.type, false)} ${parserArgument.name}<#sep>, </#sep></#list></#if>) throws ParseException {
<#list type.switchField.cases as case><#if case.discriminatorValues?has_content>if(<#list case.discriminatorValues as discriminatorValue>EvaluationHelper.equals(${helper.toSwitchExpression(type.switchField.discriminatorNames[discriminatorValue?index])}, ${discriminatorValue})<#sep> && </#sep></#list>) </#if>{ // ${case.name}
- WriteBuffer io = new WriteBuffer(${helper.getSizeInBits(case)});
+ WriteBuffer io = new WriteBuffer(${helper.getSizeInBits(case)} / 8 );
<#list case.fields as field>
<#switch field.typeName>
<#case "array">
diff --git a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
index ade6dd2..98fecb3 100644
--- a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
@@ -45,6 +45,7 @@ import ${helper.packageName(protocolName, languageName, outputFlavor)}.*;
import ${helper.packageName(protocolName, languageName, outputFlavor)}.types.*;
import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.apache.plc4x.java.spi.generation.*;
+import org.apache.plc4x.java.api.value.PlcValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -362,7 +363,7 @@ public class ${typeName}IO <#if !helper.isDiscriminatedType(type)>implements <#i
{
// Create an array of all the bytes written in this message element so far.
byte[] checksumRawData = io.getBytes(startPos, io.getPos());
- ${field.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field, field.checksumExpression, type.parserArguments)});
+ ${field.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field, field.checksumExpression, type.parserArguments)?no_esc});
${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")?no_esc};
}
<#break>
@@ -386,7 +387,7 @@ public class ${typeName}IO <#if !helper.isDiscriminatedType(type)>implements <#i
<#case "implicit">
// Implicit Field (${field.name}) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content)
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field, field.serializeExpression, type.parserArguments)});
+ ${helper.getLanguageTypeNameForField(field)} ${field.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field, field.serializeExpression, type.parserArguments)?no_esc});
${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")?no_esc};
<#break>
<#case "manualArray">
@@ -394,14 +395,14 @@ public class ${typeName}IO <#if !helper.isDiscriminatedType(type)>implements <#i
// Manual Array Field (${field.name})
if(_value.get${field.name?cap_first}() != null) {
for(${helper.getLanguageTypeNameForField(field)} element : _value.get${field.name?cap_first}()) {
- ${helper.toSerializationExpression(field ,field.serializeExpression, type.parserArguments)};
+ ${helper.toSerializationExpression(field ,field.serializeExpression, type.parserArguments)?no_esc};
}
}
<#break>
<#case "manual">
// Manual Field (${field.name})
- ${helper.toSerializationExpression(field ,field.serializeExpression, type.parserArguments)};
+ ${helper.toSerializationExpression(field ,field.serializeExpression, type.parserArguments)?no_esc};
<#break>
<#case "optional">
@@ -421,7 +422,7 @@ public class ${typeName}IO <#if !helper.isDiscriminatedType(type)>implements <#i
// Padding Field (${field.name})
boolean _${field.name}NeedsPadding = (boolean) (${helper.toSerializationExpression(field, field.paddingCondition, type.parserArguments)?no_esc});
if(_${field.name}NeedsPadding) {
- ${helper.getLanguageTypeNameForField(field)} _${field.name}PaddingValue = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field, field.paddingValue, type.parserArguments)});
+ ${helper.getLanguageTypeNameForField(field)} _${field.name}PaddingValue = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field, field.paddingValue, type.parserArguments)?no_esc});
${helper.getWriteBufferReadMethodCall(field.type, "(_" + field.name + "PaddingValue)")?no_esc};
}
<#break>
diff --git a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
index 967da92..5713f50 100644
--- a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
@@ -104,9 +104,13 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
</#if>
<#list type.propertyFields as field>
+ <#if helper.isAbstractField(field)>
+ public ${helper.getLanguageTypeNameForField(field)}<#if field.loopType??>[]</#if> abstract get${field.name?cap_first}();
+ <#else>
public ${helper.getLanguageTypeNameForField(field)}<#if field.loopType??>[]</#if> get${field.name?cap_first}() {
return ${field.name};
}
+ </#if>
</#list>
<#list type.virtualFields as field>
diff --git a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4 b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
index 06f5433..1e51322 100644
--- a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
+++ b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
@@ -42,7 +42,8 @@ dataIoDefinition
;
field
- : arrayField
+ : abstractField
+ | arrayField
| checksumField
| constField
| discriminatorField
@@ -58,6 +59,10 @@ field
| virtualField
;
+abstractField
+ : 'abstract' type=typeReference name=idExpression
+ ;
+
arrayField
: 'array' type=typeReference name=idExpression loopType=arrayType loopExpression=expression
;
diff --git a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultAbstractField.java b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultAbstractField.java
new file mode 100644
index 0000000..79d017f
--- /dev/null
+++ b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultAbstractField.java
@@ -0,0 +1,52 @@
+/*
+ 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 org.apache.plc4x.plugins.codegenerator.language.mspec.model.fields;
+
+import org.apache.plc4x.plugins.codegenerator.types.fields.AbstractField;
+import org.apache.plc4x.plugins.codegenerator.types.fields.SimpleField;
+import org.apache.plc4x.plugins.codegenerator.types.references.TypeReference;
+import org.apache.plc4x.plugins.codegenerator.types.terms.Term;
+
+public class DefaultAbstractField extends DefaultTaggedField implements AbstractField {
+
+ private final TypeReference type;
+ private final String name;
+ private final Term[] params;
+
+ public DefaultAbstractField(String[] tags, TypeReference type, String name, Term[] params) {
+ super(tags);
+ this.type = type;
+ this.name = name;
+ this.params = params;
+ }
+
+ public TypeReference getType() {
+ return type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Term[] getParams() {
+ return params;
+ }
+
+}
diff --git a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
index c7b8379..62c701c 100644
--- a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
+++ b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
@@ -139,6 +139,17 @@ public class MessageFormatListener extends MSpecBaseListener {
}
@Override
+ public void enterAbstractField(MSpecParser.AbstractFieldContext ctx) {
+ TypeReference type = getTypeReference(ctx.type);
+ String name = ctx.name.id.getText();
+ Term[] params = getFieldParams((MSpecParser.FieldDefinitionContext) ctx.parent.parent);
+ Field field = new DefaultAbstractField(null, type, name, params);
+ if (parserContexts.peek() != null) {
+ parserContexts.peek().add(field);
+ }
+ }
+
+ @Override
public void enterArrayField(MSpecParser.ArrayFieldContext ctx) {
TypeReference type = getTypeReference(ctx.type);
String name = ctx.name.id.getText();
diff --git a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
index 0a232ac..82109b9 100644
--- a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
+++ b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
@@ -39,6 +39,7 @@ import org.apache.plc4x.java.knxnetip.readwrite.KNXGroupAddress;
import org.apache.plc4x.java.knxnetip.readwrite.KNXGroupAddress2Level;
import org.apache.plc4x.java.knxnetip.readwrite.KNXGroupAddress3Level;
import org.apache.plc4x.java.knxnetip.readwrite.KNXGroupAddressFreeLevel;
+import org.apache.plc4x.java.knxnetip.readwrite.io.KNXGroupAddressIO;
import org.apache.plc4x.java.knxnetip.readwrite.io.KnxDatapointIO;
import org.apache.plc4x.java.spi.ConversationContext;
import org.apache.plc4x.java.spi.Plc4xProtocolBase;
@@ -248,8 +249,10 @@ public class KnxNetIpProtocolLogic extends Plc4xProtocolBase<KNXNetIPMessage> im
final byte[] destinationGroupAddress = cemiDataFrame.getDestinationAddress();
// Decode the group address depending on the project settings.
- final String destinationAddress =
- Ets5Model.parseGroupAddress(groupAddressType, destinationGroupAddress);
+ ReadBuffer addressBuffer = new ReadBuffer(destinationGroupAddress);
+ final KNXGroupAddress knxGroupAddress =
+ KNXGroupAddressIO.staticParse(addressBuffer, groupAddressType);
+ final String destinationAddress = toString(knxGroupAddress);
// If there is an ETS5 model provided, continue decoding the payload.
if(ets5Model != null) {
@@ -268,8 +271,13 @@ public class KnxNetIpProtocolLogic extends Plc4xProtocolBase<KNXNetIPMessage> im
Map<String, PlcValue> dataPointMap = new HashMap<>();
dataPointMap.put("sourceAddress", new PlcString(toString(sourceAddress)));
dataPointMap.put("targetAddress", new PlcString(groupAddress.getGroupAddress()));
- dataPointMap.put("location", new PlcString(groupAddress.getFunction().getSpaceName()));
- dataPointMap.put("function", new PlcString(groupAddress.getFunction().getName()));
+ if(groupAddress.getFunction() != null) {
+ dataPointMap.put("location", new PlcString(groupAddress.getFunction().getSpaceName()));
+ dataPointMap.put("function", new PlcString(groupAddress.getFunction().getName()));
+ } else {
+ dataPointMap.put("location", null);
+ dataPointMap.put("function", null);
+ }
dataPointMap.put("description", new PlcString(groupAddress.getName()));
dataPointMap.put("unitOfMeasurement", new PlcString(groupAddress.getType().getName()));
dataPointMap.put("value", value);
diff --git a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/utils/KnxHelper.java b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/utils/KnxHelper.java
new file mode 100644
index 0000000..157aa7c
--- /dev/null
+++ b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/utils/KnxHelper.java
@@ -0,0 +1,65 @@
+/*
+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 org.apache.plc4x.java.knxnetip.utils;
+
+import org.apache.commons.codec.binary.Hex;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.spi.generation.ParseException;
+import org.apache.plc4x.java.spi.generation.ReadBuffer;
+import org.apache.plc4x.java.spi.generation.WriteBuffer;
+
+public class KnxHelper {
+
+ public static float bytesToF16(ReadBuffer io) {
+ try {
+ boolean negative = io.readBit();
+ long exponent = io.readUnsignedLong(4);
+ long mantissa = io.readUnsignedLong(11);
+ return (float) ((negative ? -1 : 1) * (0.01 * mantissa) * Math.pow(2, exponent));
+ } catch(ParseException e) {
+ throw new PlcRuntimeException("Error parsing F16 value", e);
+ }
+ }
+
+ public static void f16toBytes(WriteBuffer io, Object param) {
+ if(!(param instanceof Float)) {
+ throw new PlcRuntimeException("Invalid datatype");
+ }
+ try {
+ float value = (float) param;
+ boolean negative = value < 0;
+ final int exponent = Math.getExponent(value);
+ final double mantissa = value / Math.pow(2, exponent);
+ io.writeBit(negative);
+ io.writeInt(4, exponent);
+ io.writeDouble(11, mantissa);
+ } catch(ParseException e) {
+ throw new PlcRuntimeException("Error serializing F16 value", e);
+ }
+ }
+
+
+ public static void main(String[] args) throws Exception {
+ final byte[] bytes = Hex.decodeHex("0C65");
+ ReadBuffer io = new ReadBuffer(bytes);
+ final double v = bytesToF16(io);
+ System.out.println(v);
+ }
+
+}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java
index d853440..3f9cc10 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java
@@ -76,6 +76,12 @@ public abstract class GeneratedDriverByteToMessageCodec<T extends Message> exten
// Pass the packet to the pipeline.
out.add(packet);
+
+ // It seems that one batch of 16 messages is the maximum, so we have to give up
+ // and process the rest next time.
+ if(out.size() >= 16) {
+ return;
+ }
} catch (Exception e) {
logger.warn("Error decoding package with content [" + Hex.encodeHexString(bytes) + "]: "
+ e.getMessage(), e);
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
index 696e83a..858e516 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
@@ -18,6 +18,8 @@
*/
package org.apache.plc4x.java.spi.generation;
+import org.apache.commons.codec.binary.Hex;
+
import java.util.Collection;
public class StaticHelper {
@@ -93,4 +95,44 @@ public class StaticHelper {
return (int) Math.ceil(value);
}
+ public static double toFloat(ReadBuffer io, boolean signed, int bitsExponent, int bitsMantissa) {
+ try {
+ boolean negative = (signed) && io.readBit();
+ long exponent = io.readUnsignedLong(bitsExponent) - (((long) Math.pow(2, bitsExponent) / 2) - 1);
+ double mantissa = 1D;
+ for(int i = 1; i < bitsMantissa; i++) {
+ if(io.readBit()) {
+ mantissa += Math.pow(2, (double) i * -1);
+ }
+ }
+ return ((negative) ? -1 : 1) * mantissa * Math.pow(2, exponent);
+ } catch(ParseException e) {
+ return 0.0f;
+ }
+ }
+
+ public static boolean fromFloatSign(double value) {
+ return value < 0;
+ }
+
+ public static long fromFloatExponent(double value, int bitsExponent) {
+ return 0;
+ }
+
+ public static long fromFloatMantissa(double value, int bitsMantissa) {
+ return 0;
+ }
+
+ public static void main(String[] args) throws Exception {
+ /*final byte[] bytes = Hex.decodeHex("420B9000");
+ ReadBuffer io = new ReadBuffer(bytes);
+ final double v = toFloat(io, true, 8, 23);
+ System.out.println(v);*/
+
+ final byte[] bytes = Hex.decodeHex("0C65");
+ ReadBuffer io = new ReadBuffer(bytes);
+ final double v = toFloat(io, true, 4, 11);
+ System.out.println(v);
+ }
+
}
diff --git a/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannelConfig.java b/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannelConfig.java
index 61a426f..2b53a23 100644
--- a/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannelConfig.java
+++ b/plc4j/utils/pcap-sockets/src/main/java/org/apache/plc4x/java/utils/pcapsockets/netty/PcapSocketChannelConfig.java
@@ -30,7 +30,7 @@ import java.util.Map;
public class PcapSocketChannelConfig extends DefaultChannelConfig implements ChannelConfig {
public static float SPEED_SLOW_HALF = 2f;
- public static float SPEED_REALTIME = -1f;
+ public static float SPEED_REALTIME = 1f;
public static float SPEED_FAST_DOUBLE = 0.5f;
public static float SPEED_FAST_FULL = 0f;
diff --git a/pom.xml b/pom.xml
index 063801f..07826aa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,7 +103,7 @@
<!-- Exclude all generated code -->
<sonar.exclusions>**/generated-sources</sonar.exclusions>
- <plc4x-code-generation.version>1.1.0</plc4x-code-generation.version>
+ <plc4x-code-generation.version>1.2.0-SNAPSHOT</plc4x-code-generation.version>
<antlr.version>4.7.2</antlr.version>
<asm.version>5.0.4</asm.version>
diff --git a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
index 9a717c9..a8a335b 100644
--- a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
+++ b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
@@ -424,7 +424,7 @@
]
['9' Float
[reserved uint 8 '0x0']
- [simple float 4.11 'value']
+ [manual float 4.11 'value' 'STATIC_CALL("org.apache.plc4x.java.knxnetip.utils.KnxHelper.bytesToF16", io)' 'STATIC_CALL("org.apache.plc4x.java.knxnetip.utils.KnxHelper.f16toBytes", io, object)' '16']
]
['14' Float
[reserved uint 8 '0x0']