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:23 UTC

[plc4x] 05/08: Slight improvments from Chris and added Test Case from Volker.

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");