You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jm...@apache.org on 2018/01/10 05:26:33 UTC
[incubator-plc4x] branch master updated: support for multiple
strings
This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push:
new 5378c4a support for multiple strings
5378c4a is described below
commit 5378c4a97d6dfb97734283d6df761acd98da6dce
Author: Justin Mclean <jm...@apache.org>
AuthorDate: Wed Jan 10 16:26:25 2018 +1100
support for multiple strings
---
.../org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java | 15 +++++++++------
.../apache/plc4x/java/s7/netty/Plc4XS7ProtocolTest.java | 2 +-
2 files changed, 10 insertions(+), 7 deletions(-)
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 11a5fdf..c58f171 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
@@ -334,18 +334,18 @@ public class Plc4XS7Protocol extends MessageToMessageCodec<S7Message, PlcRequest
result[(i * 4) + 3] = (byte) (intValue & 0xff);
}
} else if (valueType == String.class) {
- // TOOD probably need to add a terminating character so you know where each string ends
int size = 0;
for (Object value : values) {
size = size + ((String) value).length();
}
- result = new byte[size];
+ result = new byte[size + length];
int j = 0;
for (Object value : values) {
String str = (String) value;
for (int i = 0; i < str.length(); i++) {
result[j++] = (byte) str.charAt(i);
}
+ result[j++] = (byte) 0x0;
}
}
return result;
@@ -399,10 +399,13 @@ public class Plc4XS7Protocol extends MessageToMessageCodec<S7Message, PlcRequest
result.add(Float.intBitsToFloat(intValue));
i+=4;
} else if (datatype == String.class) {
- // FIXME Assumes there's only a single string and no other data
- String str = new String(s7Data);
- result.add(str);
- i += length;
+ StringBuilder builder = new StringBuilder();
+ while (s7Data[i] != (byte) 0x0) {
+ builder.append(s7Data[i]);
+ i++;
+ }
+ i++; // skip terminating character
+ result.add(builder.toString());
} else {
throw new PlcProtocolException("Unsupported datatype " + datatype.getSimpleName());
}
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/Plc4XS7ProtocolTest.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/Plc4XS7ProtocolTest.java
index 786e14c..82c5568 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/Plc4XS7ProtocolTest.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/Plc4XS7ProtocolTest.java
@@ -196,7 +196,7 @@ public class Plc4XS7ProtocolTest extends NettyTestBase {
data = new byte[]{(byte) 0b0000_0000, (byte) 0b0000_0000, (byte) 0b0000_0000, (byte) 0b0000_0000};
} else if (type == String.class) {
size = DataTransportSize.BYTE_WORD_DWORD;
- data = new byte[]{(byte) 'S', (byte) 't', (byte) 'r', (byte) 'i' ,(byte) 'n', (byte) 'g'};
+ data = new byte[]{(byte) 'S', (byte) 't', (byte) 'r', (byte) 'i' ,(byte) 'n', (byte) 'g', (byte) 0x0};
} else {
throw new IllegalArgumentException("Type t not supported " + type);
}
--
To stop receiving notification emails like this one, please contact
['"commits@plc4x.apache.org" <co...@plc4x.apache.org>'].