You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2020/10/21 13:42:18 UTC
[plc4x] branch rel/0.6 updated (86d783b -> b6ee161)
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a change to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git.
from 86d783b Fixed Bug in S7 Driver which always uses 0/0 as rack / slot hardcoded. Thanks to Tim for the fix!
new f3f5f79 Cherry Picked SIMOTION support to rel/0.6 and adapted to "native" works (without generated mspec).
new 09585ba Cherry Picked commit to add Simotion Syntax to S7 Driver. Migrated everything to "native" decoding without mspec.
new edcd9fd Fixed "native" parsing and added Tests to fully support SIMOTION Syntax in S7 Driver.
new 2cca1fb Fixed modules in pom.
new 1e4f8b2 Slight improvments from Chris and added Test Case from Volker.
new 73a9f69 Additional Test Case.
new c815c73 Added hashCode and equals to S7Field. Added Comparison Test.
new b6ee161 Simotion String
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
plc4j/drivers/s7/pom.xml | 1 -
.../base/messages/items/BaseDefaultFieldItem.java | 9 +
...ieldItem.java => DefaultDurationFieldItem.java} | 17 +-
plc4j/protocols/s7/pom.xml | 9 +
.../org/apache/plc4x/java/s7/model/S7Field.java | 61 +++++-
.../plc4x/java/s7/netty/Plc4XS7Protocol.java | 30 ++-
.../org/apache/plc4x/java/s7/netty/S7Protocol.java | 3 +-
.../s7/netty/model/types/DataTransportSize.java | 3 +-
.../java/s7/netty/model/types/TransportSize.java | 5 +-
.../apache/plc4x/java/s7/model/S7FieldTests.java | 30 ++-
.../s7/src/main/resources/protocols/s7/s7.mspec | 233 ++++++++++++++++-----
11 files changed, 326 insertions(+), 75 deletions(-)
copy plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/{DefaultLocalTimeFieldItem.java => DefaultDurationFieldItem.java} (75%)
[plc4x] 01/08: Cherry Picked SIMOTION support to rel/0.6 and
adapted to "native" works (without generated mspec).
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit f3f5f79b0942d978f3805e0836a21044d8f73966
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Mon Aug 10 10:11:28 2020 +0200
Cherry Picked SIMOTION support to rel/0.6 and adapted to "native" works (without generated mspec).
---
.../src/main/java/org/apache/plc4x/java/s7/model/S7Field.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
index c256d79..8f7f63c 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
@@ -18,11 +18,15 @@ under the License.
*/
package org.apache.plc4x.java.s7.model;
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
import org.apache.plc4x.java.api.model.PlcField;
import org.apache.plc4x.java.s7.netty.model.types.MemoryArea;
import org.apache.plc4x.java.s7.netty.model.types.TransportSize;
+import org.apache.plc4x.java.utils.ParseException;
+import org.apache.plc4x.java.utils.ReadBuffer;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -202,14 +206,14 @@ public class S7Field implements PlcField {
short bitOffset = 0;
if(matcher.group(BIT_OFFSET) != null) {
bitOffset = Short.parseShort(matcher.group(BIT_OFFSET));
- } else if(dataType == TransportSize.BOOL) {
+ } else if (dataType == TransportSize.BOOL) {
throw new PlcInvalidFieldException("Expected bit offset for BOOL parameters.");
}
int numElements = 1;
- if(matcher.group(NUM_ELEMENTS) != null) {
+ if (matcher.group(NUM_ELEMENTS) != null) {
numElements = Integer.parseInt(matcher.group(NUM_ELEMENTS));
}
- numElements = calcNumberOfElementsForIndividualTypes(numElements,dataType);
+ numElements = calcNumberOfElementsForIndividualTypes(numElements, dataType);
return new S7Field(dataType, memoryArea, blockNumber, byteOffset, bitOffset, numElements);
}
throw new PlcInvalidFieldException("Unable to parse address: " + fieldString);
[plc4x] 08/08: Simotion String
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit b6ee1613c5bbf08e7e912c5a2f540dcfd0d0f819
Author: vemmert <v....@pragmaticminds.de>
AuthorDate: Wed Oct 21 15:27:27 2020 +0200
Simotion String
---
.../base/messages/items/BaseDefaultFieldItem.java | 9 +++++
.../messages/items/DefaultDurationFieldItem.java | 47 ++++++++++++++++++++++
.../org/apache/plc4x/java/s7/model/S7Field.java | 5 +--
.../plc4x/java/s7/netty/Plc4XS7Protocol.java | 30 +++++++++++---
.../org/apache/plc4x/java/s7/netty/S7Protocol.java | 3 +-
.../s7/netty/model/types/DataTransportSize.java | 3 +-
.../java/s7/netty/model/types/TransportSize.java | 5 ++-
7 files changed, 90 insertions(+), 12 deletions(-)
diff --git a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/BaseDefaultFieldItem.java b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/BaseDefaultFieldItem.java
index 4abcda5..f09495e 100644
--- a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/BaseDefaultFieldItem.java
+++ b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/BaseDefaultFieldItem.java
@@ -23,6 +23,7 @@ import org.apache.plc4x.java.api.exceptions.PlcIncompatibleDatatypeException;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -139,6 +140,14 @@ public abstract class BaseDefaultFieldItem<T> {
throw new PlcIncompatibleDatatypeException(LocalDate.class, index);
}
+ public boolean isValidDuration(int index) {
+ return false;
+ }
+
+ public Duration getDuration(int index) {
+ throw new PlcIncompatibleDatatypeException(Duration.class, index);
+ }
+
public boolean isValidDateTime(int index) {
return false;
}
diff --git a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/DefaultDurationFieldItem.java b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/DefaultDurationFieldItem.java
new file mode 100644
index 0000000..8e44819
--- /dev/null
+++ b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/items/DefaultDurationFieldItem.java
@@ -0,0 +1,47 @@
+/*
+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.base.messages.items;
+
+import org.apache.plc4x.java.api.exceptions.PlcIncompatibleDatatypeException;
+
+import java.time.Duration;
+
+public class DefaultDurationFieldItem extends BaseDefaultFieldItem<Duration> {
+ public DefaultDurationFieldItem(Duration[] values) {
+ super(values);
+ }
+
+ @Override
+ public Object getObject(int index) {
+ return getValue(index);
+ }
+
+ @Override
+ public boolean isValidDuration(int index) {
+ return getValue(index) != null;
+ }
+
+ @Override
+ public Duration getDuration(int index) {
+ if (!isValidDuration(index)) {
+ throw new PlcIncompatibleDatatypeException(Duration.class, index);
+ }
+ return getValue(index);
+ }
+}
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
index 6662615..c5eb11f 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
@@ -238,12 +238,11 @@ public class S7Field implements PlcField {
final short numberOfElements = (short)rb.readUnsignedInt(16);
final short dbNumber = (short)rb.readUnsignedInt(16);
final MemoryArea memoryArea = MemoryArea.valueOf(rb.readByte(8));
- assert 0x00 == rb.readUnsignedShort(5);
+ rb.readUnsignedShort(5);
final short byteAddress = (short)rb.readUnsignedInt(16);
final byte bitAddress = rb.readUnsignedByte(3);
- return new S7Field(transportSize, memoryArea, dbNumber, byteAddress, bitAddress,
- numberOfElements);
+ return new S7Field(transportSize, memoryArea, dbNumber, byteAddress, bitAddress, numberOfElements);
} catch (ParseException | DecoderException e) {
throw new PlcInvalidFieldException("Unable to parse address: " + fieldString);
}
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
index 6c789dd..42b5096 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
@@ -53,6 +53,7 @@ import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
+import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -526,11 +527,15 @@ public class Plc4XS7Protocol extends PlcMessageToMessageCodec<S7Message, PlcRequ
fieldItem = decodeReadResponseFixedLengthStringField(1, true, data);
break;
case STRING:
- fieldItem = decodeReadResponseVarLengthStringField(false, data);
+ fieldItem = decodeReadResponseVarLengthStringField(false, false, data);
break;
case WSTRING:
- fieldItem = decodeReadResponseVarLengthStringField(true, data);
+ fieldItem = decodeReadResponseVarLengthStringField(true, false, data);
break;
+ case SIMOTIONSTRING:
+ fieldItem = decodeReadResponseVarLengthStringField(false, true, data);
+ break;
+
// -----------------------------------------
// TIA Date-Formats
// -----------------------------------------
@@ -543,6 +548,9 @@ public class Plc4XS7Protocol extends PlcMessageToMessageCodec<S7Message, PlcRequ
case DATE:
fieldItem = decodeReadResponseDate(field, data);
break;
+ case TIME:
+ fieldItem = decodeReadResponseTime(field, data);
+ break;
default:
throw new PlcProtocolException("Unsupported type " + field.getDataType());
}
@@ -659,9 +667,11 @@ public class Plc4XS7Protocol extends PlcMessageToMessageCodec<S7Message, PlcRequ
return new DefaultStringFieldItem(stringValue);
}
- BaseDefaultFieldItem decodeReadResponseVarLengthStringField(boolean isUtf16, ByteBuf data) {
- // Max length ... ignored.
- data.skipBytes(1);
+ BaseDefaultFieldItem decodeReadResponseVarLengthStringField(boolean isUtf16, boolean isSimotion, ByteBuf data) {
+ // In standard S7 the first byte contains the max length, Simotion string doesn't
+ if (!isSimotion) {
+ data.skipBytes(1);
+ }
//reading out byte and transforming that to an unsigned byte within an integer, otherwise longer strings are failing
byte currentLengthByte = data.readByte();
@@ -684,6 +694,11 @@ public class Plc4XS7Protocol extends PlcMessageToMessageCodec<S7Message, PlcRequ
return new DefaultLocalDateFieldItem(localTimes);
}
+ BaseDefaultFieldItem decodeReadResponseTime(S7Field field, ByteBuf data) {
+ Duration[] duration = readAllValues(Duration.class,field, i -> readDuration(data));;
+ return new DefaultDurationFieldItem(duration);
+ }
+
// Returns a 32 bit unsigned value : from 0 to 4294967295 (2^32-1)
public static int getUDIntAt(byte[] buffer, int pos) {
int result;
@@ -831,6 +846,11 @@ public class Plc4XS7Protocol extends PlcMessageToMessageCodec<S7Message, PlcRequ
}
+ Duration readDuration(ByteBuf data) {
+ // 4 bytes, duration in milliseconds
+ return Duration.ofMillis(data.readInt());
+ }
+
/**
* converts incoming byte to an integer regarding used BCD format
* @param incomingByte
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
index f8a670a..85f3a00 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
@@ -647,7 +647,8 @@ public class S7Protocol extends ChannelDuplexHandler {
}
// This is a response to a READ_VAR request.
else if ((readWriteVarParameter.getType() == ParameterType.READ_VAR) && isResponse) {
- DataTransportSize dataTransportSize = DataTransportSize.valueOf(userData.readByte());
+ byte bbb = userData.readByte();
+ DataTransportSize dataTransportSize = DataTransportSize.valueOf(bbb);
short length = dataTransportSize.isSizeInBits() ?
(short) Math.ceil(userData.readShort() / 8.0) : userData.readShort();
byte[] data = new byte[length];
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java
index e93a34e..0d8f9d0 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java
@@ -31,7 +31,8 @@ public enum DataTransportSize {
INTEGER((byte) 0x05, true),
DINTEGER((byte) 0x06, false),
REAL((byte) 0x07, false),
- OCTET_STRING((byte) 0x09, false);
+ OCTET_STRING((byte) 0x09, false),
+ TIME((byte) 0x32, false);
private static final Map<Byte, DataTransportSize> map;
static {
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/TransportSize.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/TransportSize.java
index 2f806ed..8ecfc46 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/TransportSize.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/TransportSize.java
@@ -108,8 +108,9 @@ public enum TransportSize {
STRING(0x03, "X", 1, null, DataTransportSize.BYTE_WORD_DWORD, S7ControllerType.ANY),
// Variable-length double-byte character string
// TODO: Find the code (Perhaps 0x13)
- WSTRING(0x00, "X", 1, null, null, S7ControllerType.S7_1200, S7ControllerType.S7_1500);
-
+ WSTRING(0x00, "X", 1, null, null, S7ControllerType.S7_1200, S7ControllerType.S7_1500),
+ // String in Simotion PLCs
+ SIMOTIONSTRING(0x33, "X", 1, null, DataTransportSize.BYTE_WORD_DWORD, S7ControllerType.ANY);
/* TO BE CONTINUED */
// Codes and their types:
[plc4x] 02/08: Cherry Picked commit to add Simotion Syntax to S7
Driver. Migrated everything to "native" decoding without mspec.
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 09585ba5ebe5b5f9f953ac8ef2e2cdffd209bd09
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Tue Jul 28 20:53:13 2020 +0200
Cherry Picked commit to add Simotion Syntax to S7 Driver.
Migrated everything to "native" decoding without mspec.
---
plc4j/drivers/s7/pom.xml | 1 -
.../org/apache/plc4x/java/s7/model/S7Field.java | 29 ++-
.../s7/src/main/resources/protocols/s7/s7.mspec | 233 ++++++++++++++++-----
3 files changed, 212 insertions(+), 51 deletions(-)
diff --git a/plc4j/drivers/s7/pom.xml b/plc4j/drivers/s7/pom.xml
index 7a87d0c..02f12ca 100644
--- a/plc4j/drivers/s7/pom.xml
+++ b/plc4j/drivers/s7/pom.xml
@@ -116,7 +116,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.12</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
index 8f7f63c..d539bdf 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
@@ -47,6 +47,9 @@ public class S7Field implements PlcField {
private static final Pattern DATA_BLOCK_SHORT_PATTERN =
Pattern.compile("^%DB(?<blockNumber>\\d{1,5}):(?<byteOffset>\\d{1,7})(.(?<bitOffset>[0-7]))?:(?<dataType>[a-zA-Z_]+)(\\[(?<numElements>\\d+)])?");
+ private static final Pattern SIMOTION_ADDRESS_PATTERN =
+ Pattern.compile("[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}");
+
private static final String DATA_TYPE = "dataType";
private static final String TRANSFER_SIZE_CODE = "transferSizeCode";
private static final String BLOCK_NUMBER = "blockNumber";
@@ -98,7 +101,8 @@ public class S7Field implements PlcField {
public static boolean matches(String fieldString) {
return DATA_BLOCK_ADDRESS_PATTERN.matcher(fieldString).matches() ||
ADDRESS_PATTERN.matcher(fieldString).matches() ||
- DATA_BLOCK_SHORT_PATTERN.matcher(fieldString).matches();
+ DATA_BLOCK_SHORT_PATTERN.matcher(fieldString).matches() ||
+ SIMOTION_ADDRESS_PATTERN.matcher(fieldString).matches();
}
/**
@@ -215,6 +219,29 @@ public class S7Field implements PlcField {
}
numElements = calcNumberOfElementsForIndividualTypes(numElements, dataType);
return new S7Field(dataType, memoryArea, blockNumber, byteOffset, bitOffset, numElements);
+ } else if (SIMOTION_ADDRESS_PATTERN.matcher(fieldString).matches()) {
+ matcher = SIMOTION_ADDRESS_PATTERN.matcher(fieldString);
+
+ boolean matches = matcher.matches();
+ assert matches;
+
+ try {
+ byte[] addressData = Hex.decodeHex(fieldString.replaceAll("[-]", ""));
+ ReadBuffer rb = new ReadBuffer(addressData);
+ // Read out values according to definition in mspec
+ final TransportSize transportSize = TransportSize.valueOf(rb.readByte(8));
+ final short numberOfElements = rb.readShort(16);
+ final short dbNumber = rb.readShort(16);
+ final MemoryArea memoryArea = MemoryArea.valueOf(rb.readByte(8));
+ assert 0x00 == rb.readByte(5);
+ final short byteAddress = rb.readShort(16);
+ final byte bitAddress = rb.readByte(3);
+
+ return new S7Field(transportSize, memoryArea, dbNumber, byteAddress, bitAddress,
+ numberOfElements);
+ } catch (ParseException | DecoderException e) {
+ throw new PlcInvalidFieldException("Unable to parse address: " + fieldString);
+ }
}
throw new PlcInvalidFieldException("Unable to parse address: " + fieldString);
}
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 31b588c..e428620 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -99,20 +99,24 @@
[discriminator uint 8 'messageType']
[reserved uint 16 '0x0000']
[simple uint 16 'tpduReference']
- [implicit uint 16 'parameterLength' 'parameter.lengthInBytes']
- [implicit uint 16 'payloadLength' 'payload.lengthInBytes']
+ [implicit uint 16 'parameterLength' 'parameter != null ? parameter.lengthInBytes : 0']
+ [implicit uint 16 'payloadLength' 'payload != null ? payload.lengthInBytes : 0']
[typeSwitch 'messageType'
['0x01' S7MessageRequest
]
- ['0x03' S7MessageResponse
+ ['0x02' S7MessageResponse
+ [simple uint 8 'errorClass']
+ [simple uint 8 'errorCode']
+ ]
+ ['0x03' S7MessageResponseData
[simple uint 8 'errorClass']
[simple uint 8 'errorCode']
]
['0x07' S7MessageUserData
]
]
- [simple S7Parameter 'parameter' ['messageType']]
- [simple S7Payload 'payload' ['messageType', 'parameter']]
+ [optional S7Parameter 'parameter' 'parameterLength > 0' ['messageType']]
+ [optional S7Payload 'payload' 'payloadLength > 0' ['messageType', 'parameter']]
]
////////////////////////////////////////////////////////////////
@@ -208,14 +212,12 @@
// Payloads
[discriminatedType 'S7Payload' [uint 8 'messageType', S7Parameter 'parameter']
- [typeSwitch 'parameter.discriminatorValues[0]', 'messageType'
- ['0xF0' S7PayloadSetupCommunication]
- ['0x04','0x01' S7PayloadReadVarRequest]
+ [typeSwitch 'parameter.parameterType', 'messageType'
['0x04','0x03' S7PayloadReadVarResponse
- [array S7VarPayloadDataItem 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems']
+ [array S7VarPayloadDataItem 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems' ['lastItem']]
]
['0x05','0x01' S7PayloadWriteVarRequest
- [array S7VarPayloadDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)']
+ [array S7VarPayloadDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)' ['lastItem']]
]
['0x05','0x03' S7PayloadWriteVarResponse
[array S7VarPayloadStatusItem 'items' count 'CAST(parameter, S7ParameterWriteVarResponse).numItems']
@@ -227,24 +229,24 @@
]
// This is actually not quite correct as depending pon the transportSize the length is either defined in bits or bytes.
-[type 'S7VarPayloadDataItem'
- [simple uint 8 'returnCode']
- [enum DataTransportSize 'transportSize']
- [simple uint 16 'dataLength']
- [array uint 8 'data' count 'dataLength / 8']
- [padding uint 8 'pad' '0x00' '(dataLength / 8) % 2 == 1']
+[type 'S7VarPayloadDataItem' [bit 'lastItem']
+ [enum DataTransportErrorCode 'returnCode']
+ [enum DataTransportSize 'transportSize']
+ [implicit uint 16 'dataLength' 'COUNT(data) * ((transportSize == DataTransportSize.BIT) ? 1 : (transportSize.sizeInBits ? 8 : 1))']
+ [array int 8 'data' count 'transportSize.sizeInBits ? CEIL(dataLength / 8.0) : dataLength']
+ [padding uint 8 'pad' '0x00' '!lastItem && ((COUNT(data) % 2) == 1)']
]
[type 'S7VarPayloadStatusItem'
- [simple uint 8 'returnCode']
+ [enum DataTransportErrorCode 'returnCode']
]
[discriminatedType 'S7PayloadUserDataItem' [uint 4 'cpuFunctionType']
- [simple uint 8 'returnCode']
- [enum DataTransportSize 'transportSize']
- [implicit uint 16 'dataLength' 'lengthInBytes - 4']
- [simple SzlId 'szlId']
- [simple uint 16 'szlIndex']
+ [enum DataTransportErrorCode 'returnCode']
+ [enum DataTransportSize 'transportSize']
+ [implicit uint 16 'dataLength' 'lengthInBytes - 4']
+ [simple SzlId 'szlId']
+ [simple uint 16 'szlIndex']
[typeSwitch 'cpuFunctionType'
['0x04' S7PayloadUserDataItemCpuFunctionReadSzlRequest
]
@@ -256,8 +258,115 @@
]
]
+[dataIo 'DataItem' [uint 8 'dataProtocolId']
+ [typeSwitch 'dataProtocolId'
+ // -----------------------------------------
+ // Bit
+ // -----------------------------------------
+ ['01' Boolean
+ [reserved uint 7 '0x00']
+ [simple bit 'value']
+ ]
+
+ // -----------------------------------------
+ // Bit-strings
+ // -----------------------------------------
+ // 1 byte
+ ['11' List
+ [array bit 'value' count '8']
+ ]
+ // 2 byte (16 bit)
+ ['12' List
+ [array bit 'value' count '16']
+ ]
+ // 4 byte (32 bit)
+ ['13' List
+ [array bit 'value' count '32']
+ ]
+ // 8 byte (64 bit)
+ ['14' List
+ [array bit 'value' count '64']
+ ]
+
+ // -----------------------------------------
+ // Integers
+ // -----------------------------------------
+ // 8 bit:
+ ['21' Integer
+ [simple int 8 'value']
+ ]
+ ['22' Integer
+ [simple uint 8 'value']
+ ]
+ // 16 bit:
+ ['23' Integer
+ [simple int 16 'value']
+ ]
+ ['24' Integer
+ [simple uint 16 'value']
+ ]
+ // 32 bit:
+ ['25' Integer
+ [simple int 32 'value']
+ ]
+ ['26' Long
+ [simple uint 32 'value']
+ ]
+ // 64 bit:
+ ['27' Long
+ [simple int 64 'value']
+ ]
+ ['28' BigInteger
+ [simple uint 64 'value']
+ ]
+
+ // -----------------------------------------
+ // Floating point values
+ // -----------------------------------------
+ ['31' Float
+ [simple float 8.23 'value']
+ ]
+ ['32' Double
+ [simple float 11.52 'value']
+ ]
+
+ // -----------------------------------------
+ // Characters & Strings
+ // -----------------------------------------
+ ['41' String
+ ]
+ ['42' String
+ ]
+ ['43' String
+ [manual string 'UTF-8' 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", io, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", io, _value, _type.encoding)' '_value.length + 2']
+ ]
+ ['44' String
+ [manual string 'UTF-16' 'value''STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", io, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", io, _value, _type.encoding)' '(_value.length * 2) + 2']
+ ]
-[enum int 8 'COTPTpduSize' [uint 8 'sizeInBytes']
+ // -----------------------------------------
+ // TIA Date-Formats
+ // -----------------------------------------
+ ['51' Time
+ [manual time 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseTiaTime", io)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaTime", io, _value)' '4']
+ ]
+ // TODO: Check if this is really 8 bytes
+ ['52' Time
+ [manual time 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseTiaLTime", io)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaLTime", io, _value)' '8']
+ ]
+ ['53' Date
+ [manual date 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseTiaDate", io)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaDate", io, _value)' '2']
+ ]
+ ['54' Time
+ [manual time 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseTiaTimeOfDay", io)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaTimeOfDay", io, _value)' '4']
+ ]
+ ['55' DateTime
+ [manual dateTime 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseTiaDateTime", io)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaDateTime", io, _value)' '8']
+ ]
+ ]
+]
+
+[enum int 8 'COTPTpduSize' [uint 16 'sizeInBytes']
['0x07' SIZE_128 ['128']]
['0x08' SIZE_256 ['256']]
['0x09' SIZE_512 ['512']]
@@ -285,34 +394,51 @@
['0x09' OCTET_STRING ['false']]
]
-[enum int 8 'TransportSize' [uint 8 'sizeCode', uint 8 'sizeInBytes', TransportSize 'baseType', DataTransportSize 'dataTransportSize']
- ['0x01' BOOL ['X' , '1' , 'null' , 'DataTransportSize.BIT']]
- ['0x02' BYTE ['B' , '1' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x04' WORD ['W' , '2' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x06' DWORD ['D' , '4' , 'WORD' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x00' LWORD ['X' , '8' , 'null' , 'null']]
- ['0x05' INT ['W' , '2' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x05' UINT ['W' , '2' , 'INT' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x02' SINT ['B' , '1' , 'INT' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x02' USINT ['B' , '1' , 'INT' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x07' DINT ['D' , '4' , 'INT' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x07' UDINT ['D' , '4' , 'INT' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x00' LINT ['X' , '8' , 'INT' , 'null']]
- ['0x00' ULINT ['X' , '16' , 'INT' , 'null']]
- ['0x08' REAL ['D' , '4' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x00' LREAL ['X' , '8' , 'REAL' , 'null']]
- ['0x0B' TIME ['X' , '4' , 'null' , 'null']]
- ['0x00' LTIME ['X' , '8' , 'TIME' , 'null']]
- ['0x02' DATE ['X' , '2' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x02' TIME_OF_DAY ['X' , '4' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x02' DATE_AND_TIME ['X' , '8' , 'null' , 'null']]
- ['0x03' CHAR ['B' , '1' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x13' WCHAR ['X' , '2' , 'null' , 'null']]
- ['0x03' STRING ['X' , '1' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD']]
- ['0x00' WSTRING ['X' , '1' , 'null' , 'null']]
+[enum int 8 'DeviceGroup'
+ ['0x01' PG_OR_PC]
+ ['0x02' OS ]
+ ['0x03' OTHERS ]
+]
+
+[enum int 8 'TransportSize' [uint 8 'sizeCode', uint 8 'sizeInBytes', TransportSize 'baseType', DataTransportSize 'dataTransportSize', uint 8 'dataProtocolId', bit 'supported_S7_300', bit 'supported_S7_400', bit 'supported_S7_1200', bit 'supported_S7_1500', bit 'supported_LOGO']
+ // Bit Strings
+ ['0x01' BOOL ['X' , '1' , 'null' , 'DataTransportSize.BIT' , '01' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x02' BYTE ['B' , '1' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD' , '11' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x04' WORD ['W' , '2' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD' , '12' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x06' DWORD ['D' , '4' , 'TransportSize.WORD' , 'DataTransportSize.BYTE_WORD_DWORD' , '13' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x00' LWORD ['X' , '8' , 'null' , 'null' , '14' , 'false' , 'false' , 'false' , 'true' , 'false' ]]
+
+ // Integer values
+ // INT and UINT moved out of order as the enum constant INT needs to be generated before it's used in java
+ ['0x05' INT ['W' , '2' , 'null' , 'DataTransportSize.INTEGER' , '23' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x05' UINT ['W' , '2' , 'TransportSize.INT' , 'DataTransportSize.INTEGER' , '24' , 'false' , 'false' , 'true' , 'true' , 'true' ]]
+ // ...
+ ['0x02' SINT ['B' , '1' , 'TransportSize.INT' , 'DataTransportSize.BYTE_WORD_DWORD' , '21' , 'false' , 'false' , 'true' , 'true' , 'true' ]]
+ ['0x02' USINT ['B' , '1' , 'TransportSize.INT' , 'DataTransportSize.BYTE_WORD_DWORD' , '22' , 'false' , 'false' , 'true' , 'true' , 'true' ]]
+ ['0x07' DINT ['D' , '4' , 'TransportSize.INT' , 'DataTransportSize.INTEGER' , '25' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x07' UDINT ['D' , '4' , 'TransportSize.INT' , 'DataTransportSize.INTEGER' , '26' , 'false' , 'false' , 'true' , 'true' , 'true' ]]
+ ['0x00' LINT ['X' , '8' , 'TransportSize.INT' , 'null' , '27' , 'false' , 'false' , 'false' , 'true' , 'false' ]]
+ ['0x00' ULINT ['X' , '16' , 'TransportSize.INT' , 'null' , '28' , 'false' , 'false' , 'false' , 'true' , 'false' ]]
+
+ // Floating point values
+ ['0x08' REAL ['D' , '4' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD' , '31' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x30' LREAL ['X' , '8' , 'TransportSize.REAL' , 'null' , '32' , 'false' , 'false' , 'true' , 'true' , 'false' ]]
+
+ // Characters and Strings
+ ['0x03' CHAR ['B' , '1' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD' , '41' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x13' WCHAR ['X' , '2' , 'null' , 'null' , '42' , 'false' , 'false' , 'true' , 'true' , 'true' ]]
+ ['0x03' STRING ['X' , '1' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD' , '43' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x00' WSTRING ['X' , '1' , 'null' , 'null' , '44' , 'false' , 'false' , 'true' , 'true' , 'true' ]]
+
+ // Dates and time values
+ ['0x0B' TIME ['X' , '4' , 'null' , 'null' , '51' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x00' LTIME ['X' , '8' , 'TransportSize.TIME' , 'null' , '52' , 'false' , 'false' , 'false' , 'true' , 'false' ]]
+ ['0x02' DATE ['X' , '2' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD' , '53' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x02' TIME_OF_DAY ['X' , '4' , 'null' , 'DataTransportSize.BYTE_WORD_DWORD' , '54' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
+ ['0x02' DATE_AND_TIME ['X' , '8' , 'null' , 'null' , '55' , 'true' , 'true' , 'false' , 'true' , 'false' ]]
]
-[enum int 8 'MemoryArea' [string 'shortName']
+[enum int 8 'MemoryArea' [string 24 'utf8' 'shortName']
['0x1C' COUNTERS ['C']]
['0x1D' TIMERS ['T']]
['0x80' DIRECT_PERIPHERAL_ACCESS ['D']]
@@ -334,6 +460,15 @@
['0x09' OCTET_STRING ['false']]
]
+[enum int 8 'DataTransportErrorCode'
+ ['0x00' RESERVED ]
+ ['0xFF' OK ]
+ ['0x03' ACCESS_DENIED ]
+ ['0x05' INVALID_ADDRESS ]
+ ['0x06' DATA_TYPE_NOT_SUPPORTED]
+ ['0x0A' NOT_FOUND ]
+]
+
[enum int 4 'SzlModuleTypeClass'
['0x0' CPU]
['0x4' IM]
[plc4x] 03/08: Fixed "native" parsing and added Tests to fully
support SIMOTION Syntax in S7 Driver.
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit edcd9fd4063ec36ae4afb5e6110463e875bf0547
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Mon Aug 10 10:36:58 2020 +0200
Fixed "native" parsing and added Tests to fully support SIMOTION Syntax in S7 Driver.
---
.../org/apache/plc4x/java/s7/model/S7Field.java | 18 ++++++++++------
.../apache/plc4x/java/s7/model/S7FieldTests.java | 25 +++++++++++++++++++++-
2 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
index d539bdf..ef5dff4 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
@@ -229,13 +229,17 @@ public class S7Field implements PlcField {
byte[] addressData = Hex.decodeHex(fieldString.replaceAll("[-]", ""));
ReadBuffer rb = new ReadBuffer(addressData);
// Read out values according to definition in mspec
- final TransportSize transportSize = TransportSize.valueOf(rb.readByte(8));
- final short numberOfElements = rb.readShort(16);
- final short dbNumber = rb.readShort(16);
- final MemoryArea memoryArea = MemoryArea.valueOf(rb.readByte(8));
- assert 0x00 == rb.readByte(5);
- final short byteAddress = rb.readShort(16);
- final byte bitAddress = rb.readByte(3);
+ final short resvd = rb.readUnsignedShort(8);
+ if (0x10 != resvd) {
+ throw new PlcInvalidFieldException("Unsupported Field Type to parse!");
+ }
+ final TransportSize transportSize = TransportSize.valueOf((byte)rb.readUnsignedShort(8));
+ final short numberOfElements = (short)rb.readUnsignedInt(16);
+ final short dbNumber = (short)rb.readUnsignedInt(16);
+ final MemoryArea memoryArea = MemoryArea.valueOf((byte)rb.readUnsignedShort(8));
+ assert 0x00 == rb.readUnsignedShort(5);
+ final short byteAddress = (short)rb.readUnsignedInt(16);
+ final byte bitAddress = (byte)rb.readUnsignedShort(3);
return new S7Field(transportSize, memoryArea, dbNumber, byteAddress, bitAddress,
numberOfElements);
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
index 3d4cb35..089dc09 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
@@ -19,12 +19,14 @@ under the License.
package org.apache.plc4x.java.s7.model;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.apache.plc4x.java.api.model.PlcField;
import org.apache.plc4x.java.s7.netty.model.types.MemoryArea;
import org.apache.plc4x.java.s7.netty.model.types.TransportSize;
import org.apache.plc4x.test.FastTests;
import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -34,7 +36,10 @@ import java.util.stream.Stream;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
class S7FieldTests {
@@ -105,4 +110,22 @@ class S7FieldTests {
assertEquals(25, field.getNumElements());
}
+
+ @Test
+ public void testSimotionAddres() {
+ final S7Field s7Field = S7Field.of("10-01-00-01-00-2D-84-00-00-08");
+ Assertions.assertEquals(TransportSize.BOOL, s7Field.getDataType());
+ Assertions.assertEquals(1, s7Field.getNumElements());
+ Assertions.assertEquals(45, s7Field.getBlockNumber());
+ Assertions.assertEquals(MemoryArea.DATA_BLOCKS, s7Field.getMemoryArea());
+ Assertions.assertEquals(1, s7Field.getByteOffset());
+ Assertions.assertEquals(0, s7Field.getBitOffset());
+ }
+
+ @Test
+ public void testSimotionAddres_wrongMemoryArea_fails() {
+ assertThrows(PlcInvalidFieldException.class, () -> {
+ final S7Field s7Field = S7Field.of("A0-01-00-01-00-2D-84-00-00-08");
+ });
+ }
}
\ No newline at end of file
[plc4x] 07/08: Added hashCode and equals to S7Field. Added
Comparison Test.
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit c815c734b88871938a51c8bafdaa4962db574bf2
Author: julian <j....@pragmaticminds.de>
AuthorDate: Wed Aug 19 15:26:26 2020 +0200
Added hashCode and equals to S7Field. Added Comparison Test.
---
.../java/org/apache/plc4x/java/s7/model/S7Field.java | 19 +++++++++++++++++++
.../org/apache/plc4x/java/s7/model/S7FieldTests.java | 9 +++++++++
2 files changed, 28 insertions(+)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
index eba0e1b..6662615 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
@@ -31,6 +31,7 @@ import org.apache.plc4x.java.utils.ReadBuffer;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -297,6 +298,24 @@ public class S7Field implements PlcField {
}
@Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ S7Field s7Field = (S7Field) o;
+ return getBlockNumber() == s7Field.getBlockNumber() &&
+ getByteOffset() == s7Field.getByteOffset() &&
+ getBitOffset() == s7Field.getBitOffset() &&
+ getNumElements() == s7Field.getNumElements() &&
+ getDataType() == s7Field.getDataType() &&
+ getMemoryArea() == s7Field.getMemoryArea();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getDataType(), getMemoryArea(), getBlockNumber(), getByteOffset(), getBitOffset(), getNumElements());
+ }
+
+ @Override
public String toString() {
return "S7Field{" +
"dataType=" + dataType +
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
index 0c5d9cc..1ee51c3 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
@@ -56,6 +56,7 @@ class S7FieldTests {
Arguments.of("%DB444:14.0:BOOL", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 444, 14, 0),
// Simotion
Arguments.of("10-01-00-01-00-2D-84-00-00-08", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 45, 1, 0),
+ Arguments.of("%DB45:16.0:REAL", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 45, 16, 0),
Arguments.of("10-08-00-01-00-2D-84-00-00-80", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 45, 16, 0),
Arguments.of("10-07-00-01-00-98-84-00-06-C0", TransportSize.UDINT, MemoryArea.DATA_BLOCKS, 152, 216, 0)
/*,
@@ -122,4 +123,12 @@ class S7FieldTests {
final S7Field s7Field = S7Field.of("A0-01-00-01-00-2D-84-00-00-08");
});
}
+
+ @Test
+ void testSimotionadressEqualsRegularAdress() {
+ S7Field simotion = S7Field.of("10-08-00-01-00-2D-84-00-00-80");
+ S7Field regular = S7Field.of("%DB45:16.0:REAL");
+
+ assertEquals(regular, simotion);
+ }
}
\ No newline at end of file
[plc4x] 06/08: Additional Test Case.
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 73a9f691d8a9ec4d6198fe8b6d865507244c37e3
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Mon Aug 10 13:37:00 2020 +0200
Additional Test Case.
---
.../s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
index 22fc5ba..0c5d9cc 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
@@ -56,7 +56,8 @@ class S7FieldTests {
Arguments.of("%DB444:14.0:BOOL", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 444, 14, 0),
// Simotion
Arguments.of("10-01-00-01-00-2D-84-00-00-08", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 45, 1, 0),
- Arguments.of("10-08-00-01-00-2D-84-00-00-80", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 45, 16, 0)
+ Arguments.of("10-08-00-01-00-2D-84-00-00-80", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 45, 16, 0),
+ Arguments.of("10-07-00-01-00-98-84-00-06-C0", TransportSize.UDINT, MemoryArea.DATA_BLOCKS, 152, 216, 0)
/*,
// Not quite sure about how Data Block addresses look like, in my TIA portal they all have the prefix "DB".
Arguments.of("%DB3.DX4.1:BOOL", S7DataType.BOOL, MemoryArea.DATA_BLOCKS, 3, 4, 1),
[plc4x] 05/08: Slight improvments from Chris and added Test Case
from Volker.
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 1e4f8b2ff0e82fe3edfa64c93bf89155865e8465
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Mon Aug 10 12:33:40 2020 +0200
Slight improvments from Chris and added Test Case from Volker.
---
.../java/org/apache/plc4x/java/s7/model/S7Field.java | 4 ++--
.../org/apache/plc4x/java/s7/model/S7FieldTests.java | 17 +++++------------
2 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
index ef5dff4..eba0e1b 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
@@ -236,10 +236,10 @@ public class S7Field implements PlcField {
final TransportSize transportSize = TransportSize.valueOf((byte)rb.readUnsignedShort(8));
final short numberOfElements = (short)rb.readUnsignedInt(16);
final short dbNumber = (short)rb.readUnsignedInt(16);
- final MemoryArea memoryArea = MemoryArea.valueOf((byte)rb.readUnsignedShort(8));
+ final MemoryArea memoryArea = MemoryArea.valueOf(rb.readByte(8));
assert 0x00 == rb.readUnsignedShort(5);
final short byteAddress = (short)rb.readUnsignedInt(16);
- final byte bitAddress = (byte)rb.readUnsignedShort(3);
+ final byte bitAddress = rb.readUnsignedByte(3);
return new S7Field(transportSize, memoryArea, dbNumber, byteAddress, bitAddress,
numberOfElements);
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
index 089dc09..22fc5ba 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
@@ -53,7 +53,11 @@ class S7FieldTests {
Arguments.of("%DB1:38.1:BOOL", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 1, 38, 1),
Arguments.of("%DB1:8.0:REAL", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 1, 8, 0),
Arguments.of("%DB400:8.0:REAL", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 400, 8, 0),
- Arguments.of("%DB444:14.0:BOOL", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 444, 14, 0)/*,
+ Arguments.of("%DB444:14.0:BOOL", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 444, 14, 0),
+ // Simotion
+ Arguments.of("10-01-00-01-00-2D-84-00-00-08", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 45, 1, 0),
+ Arguments.of("10-08-00-01-00-2D-84-00-00-80", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 45, 16, 0)
+ /*,
// Not quite sure about how Data Block addresses look like, in my TIA portal they all have the prefix "DB".
Arguments.of("%DB3.DX4.1:BOOL", S7DataType.BOOL, MemoryArea.DATA_BLOCKS, 3, 4, 1),
Arguments.of("%DB3.DB4:INT", S7DataType.INT, MemoryArea.DATA_BLOCKS, 3, 4, 0),
@@ -112,17 +116,6 @@ class S7FieldTests {
}
@Test
- public void testSimotionAddres() {
- final S7Field s7Field = S7Field.of("10-01-00-01-00-2D-84-00-00-08");
- Assertions.assertEquals(TransportSize.BOOL, s7Field.getDataType());
- Assertions.assertEquals(1, s7Field.getNumElements());
- Assertions.assertEquals(45, s7Field.getBlockNumber());
- Assertions.assertEquals(MemoryArea.DATA_BLOCKS, s7Field.getMemoryArea());
- Assertions.assertEquals(1, s7Field.getByteOffset());
- Assertions.assertEquals(0, s7Field.getBitOffset());
- }
-
- @Test
public void testSimotionAddres_wrongMemoryArea_fails() {
assertThrows(PlcInvalidFieldException.class, () -> {
final S7Field s7Field = S7Field.of("A0-01-00-01-00-2D-84-00-00-08");
[plc4x] 04/08: Fixed modules in pom.
Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 2cca1fbeeb9ace53b81510b404fe74326a42cd42
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Mon Aug 10 11:02:42 2020 +0200
Fixed modules in pom.
---
plc4j/protocols/s7/pom.xml | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/plc4j/protocols/s7/pom.xml b/plc4j/protocols/s7/pom.xml
index 5be3893..fa53f09 100644
--- a/plc4j/protocols/s7/pom.xml
+++ b/plc4j/protocols/s7/pom.xml
@@ -44,6 +44,11 @@
</dependency>
<dependency>
<groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-utils-driver-base-java</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-protocol-iso-tp</artifactId>
<version>0.6.1-SNAPSHOT</version>
</dependency>
@@ -69,6 +74,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
<dependency>
<groupId>commons-io</groupId>