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

jfeinauer pushed a commit to branch feature/plc-simulator
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit b75671247bf0a8f5a830d02777f8f1be5a5b777c
Author: Christofer Dutz <christofer.d...@c-ware.de>
AuthorDate: Fri Oct 18 13:17:59 2019 +0200

    - Continued implemting the functionality to read DBs in the simulator
---
 .../server/s7/protocol/S7Step7ServerAdapter.java   | 34 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git 
a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerAdapter.java
 
b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerAdapter.java
index 9f7a34d..f4f6ddb 100644
--- 
a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerAdapter.java
+++ 
b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerAdapter.java
@@ -25,6 +25,7 @@ import org.apache.plc4x.simulator.model.Context;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.nio.ByteOrder;
 import java.util.Arrays;
 import java.util.BitSet;
 import java.util.List;
@@ -241,13 +242,40 @@ public class S7Step7ServerAdapter extends 
ChannelInboundHandlerAdapter {
                                             S7AddressAny addressAny = 
(S7AddressAny) address1;
                                             switch (addressAny.getArea()) {
                                                 case DATA_BLOCKS: {
-
+                                                    final int dataBlockNumber 
= addressAny.getDbNumber();
+                                                    if(dataBlockNumber != 1) {
+                                                        // TODO: Return 
unknown object.
+                                                    }
+                                                    final int numberOfElements 
= addressAny.getNumberOfElements();
+                                                    if(numberOfElements != 1) {
+                                                        // TODO: Return 
invalid address.
+                                                    }
+                                                    final int byteAddress = 
addressAny.getByteAddress();
+                                                    if(byteAddress != 0) {
+                                                        // TODO: Return 
invalid address.
+                                                    }
+                                                    final byte bitAddress = 
addressAny.getBitAddress();
+                                                    switch 
(addressAny.getTransportSize()) {
+                                                        case INT: {
+                                                            String firstKey = 
context.getMemory().keySet().iterator().next();
+                                                            Object value = 
context.getMemory().get(firstKey);
+                                                            short shortValue = 
((Number) value).shortValue();
+                                                            byte[] data = new 
byte[2];
+                                                            data[0] = (byte) 
(shortValue & 0xff);
+                                                            data[1] = (byte) 
((shortValue >> 8) & 0xff);
+                                                            payloadItems[i] = 
new S7VarPayloadDataItem((short) 0xFF, PayloadSize.BYTE_WORD_DWORD, 
data.length, data);
+                                                            break;
+                                                        }
+                                                        default: {
+                                                            // TODO: Return 
invalid address.
+                                                        }
+                                                    }
                                                     break;
                                                 }
                                                 case INPUTS:
                                                 case OUTPUTS: {
-                                                    int ioNumber = 
(addressAny.getByteAddress() * 8) + addressAny.getBitAddress();
-                                                    int numElements = 
(addressAny.getTransportSize() == ParameterSize.BOOL) ?
+                                                    final int ioNumber = 
(addressAny.getByteAddress() * 8) + addressAny.getBitAddress();
+                                                    final int numElements = 
(addressAny.getTransportSize() == ParameterSize.BOOL) ?
                                                         
addressAny.getNumberOfElements() : 
addressAny.getTransportSize().getSizeInBytes() * 8;
                                                     final BitSet bitSet = 
toBitSet(context.getDigitalInputs(), ioNumber, numElements);
                                                     final byte[] data = 
Arrays.copyOf(bitSet.toByteArray(), (numElements + 7) / 8);

Reply via email to