You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by er...@apache.org on 2020/04/06 14:27:15 UTC

[plc4x] branch eip updated: Update EIP Driver -able to read elements from DataStruct (Counter, UserDefined) but not the Struct itself (to get all element) -Example : ACC Valuer of Counter C1 : %C1.ACC

This is an automated email from the ASF dual-hosted git repository.

erobinet pushed a commit to branch eip
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/eip by this push:
     new f1f1756  Update EIP Driver -able to read elements from DataStruct (Counter, UserDefined) but not the Struct itself (to get all element) -Example : ACC Valuer of Counter C1 : %C1.ACC
f1f1756 is described below

commit f1f1756c1145082414fb4a664ba558a1455881ed
Author: Etienne Robinet <et...@gmail.com>
AuthorDate: Mon Apr 6 16:26:56 2020 +0200

    Update EIP Driver
    -able to read elements from DataStruct (Counter, UserDefined) but not the Struct itself (to get all element)
    -Example : ACC Valuer of Counter C1 : %C1.ACC
---
 .../plc4x/java/eip/readwrite/field/EipField.java   |  2 +-
 .../eip/readwrite/protocol/EipProtocolLogic.java   | 59 +++++++++++++++-------
 2 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/field/EipField.java b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/field/EipField.java
index 3f29095..4a8abbc 100644
--- a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/field/EipField.java
+++ b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/field/EipField.java
@@ -27,7 +27,7 @@ import java.util.regex.Pattern;
 public class EipField implements PlcField {
 
     private static final Pattern ADDRESS_PATTERN =
-        Pattern.compile("^%(?<tag>[a-zA-Z_]+\\[?[0-9]*\\]?):?(?<dataType>[A-Z]*):?(?<elementNb>[0-9]*)");
+        Pattern.compile("^%(?<tag>[a-zA-Z_.0-9]+\\[?[0-9]*\\]?):?(?<dataType>[A-Z]*):?(?<elementNb>[0-9]*)");
 
     private static final String TAG="tag";
     private static final String ELEMENTS="elementNb";
diff --git a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/protocol/EipProtocolLogic.java b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/protocol/EipProtocolLogic.java
index e776e5c..b97dcf8 100644
--- a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/protocol/EipProtocolLogic.java
+++ b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/readwrite/protocol/EipProtocolLogic.java
@@ -105,42 +105,62 @@ public class EipProtocolLogic extends Plc4xProtocolBase<EipPacket> implements Ha
             if (plcField.getElementNb() > 1) {
                 elements = plcField.getElementNb();
             }
-
-            //We need the size of the request in words (0x91, tagLength, ... tag + possible pad)
-            // Taking half to get word size
-            boolean isArray = false;
-            String tagIsolated = tag;
-            if (tag.contains("[")) {
-                isArray = true;
-                tagIsolated = tag.substring(0, tag.indexOf("["));
-            }
-            int dataLength = (tagIsolated.length() + 2 + (tagIsolated.length() % 2) + (isArray ? 2 : 0));
-            byte requestPathSize = (byte) (dataLength / 2);
-            CipReadRequest req = new CipReadRequest(requestPathSize, toAnsi(tag), elements);
+            CipReadRequest req = new CipReadRequest(getRequestSize(tag), toAnsi(tag), elements);
             requests.add(req);
         }
         return toPlcReadResponse((InternalPlcReadRequest) readRequest, readInternal(requests));
     }
 
+    private byte getRequestSize(String tag){
+        //We need the size of the request in words (0x91, tagLength, ... tag + possible pad)
+        // Taking half to get word size
+        boolean isArray = false;
+        boolean isStruct=false;
+        String tagIsolated = tag;
+        if (tag.contains("[")) {
+            isArray = true;
+            tagIsolated = tag.substring(0, tag.indexOf("["));
+        }
+
+        if(tag.contains(".")){
+            isStruct=true;
+            tagIsolated= tagIsolated.replace(".","");
+        }
+        int dataLength = (tagIsolated.length() + 2)
+            + (tagIsolated.length() % 2)
+            + (isArray ? 2 : 0)
+            + (isStruct? 2:0);
+        byte requestPathSize = (byte) (dataLength / 2);
+        return requestPathSize;
+    }
+
     private byte[] toAnsi(String tag) {
         int arrayIndex = 0;
         boolean isArray = false;
+        boolean isStruct = false;
+        String tagFinal=tag;
         if (tag.contains("[")) {
             isArray = true;
             String index = tag.substring(tag.indexOf("[") + 1, tag.indexOf("]"));
             arrayIndex = Integer.parseInt(index);
-            tag = tag.substring(0, tag.indexOf("["));
+            tagFinal = tag.substring(0, tag.indexOf("["));
         }
-
-        boolean isPadded = tag.length() % 2 != 0;
-        int dataSegLength = 2 + tag.length() + (isPadded ? 1 : 0) + (isArray ? 2 : 0);
+        if(tag.contains(".")){
+            tagFinal = tag.substring(0, tag.indexOf("."));
+            isStruct=true;
+        }
+        boolean isPadded = tagFinal.length() % 2 != 0;
+        int dataSegLength = 2 + tagFinal.length()
+            + (isPadded ? 1 : 0)
+            + (isArray ? 2 : 0 )
+            + (isStruct ? tag.substring(tag.indexOf(".")+1,tag.length()).length()+2 + tag.substring(tag.indexOf(".")+1,tag.length()).length()%2:0);
 
         ByteBuffer buffer = ByteBuffer.allocate(dataSegLength).order(ByteOrder.LITTLE_ENDIAN);
 
         buffer.put((byte) 0x91);
-        buffer.put((byte) tag.length());
+        buffer.put((byte) tagFinal.length());
         byte[] tagBytes = null;
-        tagBytes = tag.getBytes(StandardCharsets.US_ASCII);
+        tagBytes = tagFinal.getBytes(StandardCharsets.US_ASCII);
 
         buffer.put(tagBytes);
         buffer.position(2 + tagBytes.length);
@@ -154,6 +174,9 @@ public class EipProtocolLogic extends Plc4xProtocolBase<EipPacket> implements Ha
             buffer.put((byte) 0x28);
             buffer.put((byte) arrayIndex);
         }
+        if(isStruct){
+            buffer.put(toAnsi(tag.substring(tag.indexOf(".")+1,tag.length())));
+        }
         return buffer.array();
     }