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 2018/01/11 08:27:46 UTC

[incubator-plc4x] 02/03: Merge branch 'master' into refactoring/java_generify

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

sruehl pushed a commit to branch refactoring/java_generify
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 2267211e5123dd3033bad13c063750348f44109e
Merge: b86dc42 3e19b41
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jan 11 08:55:33 2018 +0100

    Merge branch 'master' into refactoring/java_generify
    
    # Conflicts:
    #	plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java

 applications/iotree/pom.xml                        |   5 +
 .../plc4x/java/applications/iotree/IoTree.java     |  18 +-
 applications/plclogger/pom.xml                     |   5 +
 .../java/applications/plclogger/PlcLogger.java     |  18 +-
 .../java/org/apache/plc4x/camel/PLC4XProducer.java |   2 +
 plc4j/pom.xml                                      |  31 ---
 .../plc4x/java/isotp/netty/IsoTPProtocol.java      | 152 +++++------
 .../plc4x/java/s7/netty/Plc4XS7Protocol.java       |  85 +++---
 .../org/apache/plc4x/java/s7/netty/S7Protocol.java | 112 ++++----
 .../plc4x/java/isotp/netty/IsoTPProtocolTest.java  | 294 ++++++++++++++++++++-
 .../apache/plc4x/java/s7/S7PlcReaderSample.java    |   2 +-
 .../plc4x/java/s7/netty/Plc4XS7ProtocolTest.java   |   8 +-
 pom.xml                                            |  36 ++-
 13 files changed, 552 insertions(+), 216 deletions(-)

diff --cc plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
index 3ff2e63,b364990..cc1faf1
--- 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
@@@ -295,7 -288,8 +297,8 @@@ public class Plc4XS7Protocol extends Me
      }
  
      private byte[] encodeData(Object[] values) {
-         if (values.length == 0) {
 -        final int length = values.length;
++        final int length =values.length;
+         if (length == 0) {
              return new byte[]{};
          }
          byte[] result = null;
@@@ -350,44 -356,56 +365,54 @@@
      ////////////////////////////////////////////////////////////////////////////////
  
      private ResponseCode decodeResponseCode(DataTransportErrorCode dataTransportErrorCode) {
-         if (dataTransportErrorCode != null) {
-             switch (dataTransportErrorCode) {
-                 case OK:
-                     return ResponseCode.OK;
-                 case NOT_FOUND:
-                     return ResponseCode.NOT_FOUND;
-                 case INVALID_ADDRESS:
-                     return ResponseCode.INVALID_ADDRESS;
-             }
+         if (dataTransportErrorCode == null) {
+             return ResponseCode.INTERNAL_ERROR;
+         }
+         switch (dataTransportErrorCode) {
+             case OK:
+                 return ResponseCode.OK;
+             case NOT_FOUND:
+                 return ResponseCode.NOT_FOUND;
+             case INVALID_ADDRESS:
+                 return ResponseCode.INVALID_ADDRESS;
+             default:
+                 return ResponseCode.INTERNAL_ERROR;
          }
-         return ResponseCode.INTERNAL_ERROR;
      }
  
 -    private List<Object> decodeData(Class<?> datatype, byte[] s7Data) throws PlcProtocolException {
 +    @SuppressWarnings("unchecked")private <T>List<T> decodeData(Class<T> datatype, byte[] s7Data) throws PlcProtocolException {
 +
          List<Object> result = new LinkedList<>();
-         for (int i = 0; i < s7Data.length; ) {
 -        int i = 0;
 -        final int length = s7Data.length;
 -        
 -        while (i < length) {
++        int i = 0; final int length = s7Data.length;while (i < length) {
              if (datatype == Boolean.class) {
                  result.add((s7Data[i] & 0x01) == 0x01);
 -                i+=1;
 +                i += 1;
              } else if (datatype == Byte.class) {
                  result.add(s7Data[i]);
 -                i+=1;
 +                i += 1;
              } else if (datatype == Short.class) {
 -                result.add((short) (((s7Data[i] & 0xff) << 8) | (s7Data[i+1] & 0xff)));
 -                i+=2;
 +                result.add((short) (((s7Data[i] & 0xff) << 8) | (s7Data[i + 1] & 0xff)));
 +                i += 2;
              } else if (datatype == Integer.class) {
-                 result.add((((s7Data[i] & 0xff) << 24) | ((s7Data[i + 1] & 0xff) << 16) |
-                     ((s7Data[i + 2] & 0xff) << 8) | (s7Data[i + 3] & 0xff)));
+                 result.add(((s7Data[i] & 0xff) << 24) | ((s7Data[i + 1] & 0xff) << 16) |
+                     ((s7Data[i + 2] & 0xff) << 8) | (s7Data[i + 3] & 0xff));
 -                i+=4;
 +                i += 4;
              } else if (datatype == Float.class) {
                  // Description of the Real number format:
                  // https://www.sps-lehrgang.de/zahlenformate-step7/#c144
                  // https://de.wikipedia.org/wiki/IEEE_754
-                 int intValue = (((s7Data[i] & 0xff) << 24) | ((s7Data[i + 1] & 0xff) << 16) |
-                     ((s7Data[i + 2] & 0xff) << 8) | (s7Data[i + 3] & 0xff));
+                 int intValue = ((s7Data[i] & 0xff) << 24) | ((s7Data[i + 1] & 0xff) << 16) |
+                     ((s7Data[i + 2] & 0xff) << 8) | (s7Data[i + 3] & 0xff);
                  result.add(Float.intBitsToFloat(intValue));
 -                i+=4;
 +                i += 4;
+             } else if (datatype == String.class) {
+                 StringBuilder builder = new StringBuilder();
+                 while (s7Data[i] != (byte) 0x0 && i < length) {
+                     builder.append((char)s7Data[i]);
+                     i++;
+                 }
+                 i++; // skip terminating character
+                 result.add(builder.toString());
              } else {
                  throw new PlcProtocolException("Unsupported datatype " + datatype.getSimpleName());
              }

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.