You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/12/29 00:25:01 UTC
[plc4x] branch next-gen-core updated: - Fixed an issue in the S7
protocol initializing the transaction manager with the initial values and
not the negotiated ones. - Added some documentation to the driver.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch next-gen-core
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/next-gen-core by this push:
new 0cbf247 - Fixed an issue in the S7 protocol initializing the transaction manager with the initial values and not the negotiated ones. - Added some documentation to the driver.
0cbf247 is described below
commit 0cbf247d74753c34267a4a67e26811975a86aac4
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Dec 29 01:24:54 2019 +0100
- Fixed an issue in the S7 protocol initializing the transaction manager with the initial values and not the negotiated ones.
- Added some documentation to the driver.
---
.../s7/readwrite/protocol/S7ProtocolLogic.java | 34 ++++++++++++++++++++--
.../ets5/Ets5DataEnrichmentController.java | 1 -
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
index 3b7c457..c03ef5e 100644
--- a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
@@ -83,17 +83,30 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
@Override public void setConfiguration(S7Configuration configuration) {
this.callingTsapId = S7TsapIdEncoder.encodeS7TsapId(DeviceGroup.PG_OR_PC, configuration.rack, configuration.slot);
this.calledTsapId = S7TsapIdEncoder.encodeS7TsapId(DeviceGroup.OS, 0, 0);
+
this.controllerType = configuration.controllerType == null ? S7ControllerType.ANY : S7ControllerType.valueOf(configuration.controllerType);
+ // The Siemens LOGO device seems to only work with very limited settings,
+ // so we're overriding some of the defaults.
if (this.controllerType == S7ControllerType.LOGO && configuration.pduSize == 1024) {
configuration.pduSize = 480;
}
+
+ // Initialize the parameters with initial version (Will be updated during the login process)
this.cotpTpduSize = getNearestMatchingTpduSize((short) configuration.getPduSize());
+ // The PDU size is theoretically not bound by the COTP TPDU size, however having a larger
+ // PDU size would make the code extremely complex. But even if the protocol would allow this
+ // I have never seen this happen in reality. Making is smaller would unnecessarily limit the
+ // size, so we're setting it to the maximum that can be included.
this.pduSize = cotpTpduSize.getSizeInBytes() - 16;
this.maxAmqCaller = configuration.maxAmqCaller;
this.maxAmqCallee = configuration.maxAmqCallee;
- // Initialize Transaction Manager
- this.tm = new RequestTransactionManager(Math.min(this.maxAmqCallee, this.maxAmqCaller));
+ // Initialize Transaction Manager.
+ // Until the number of concurrent requests is successfully negotiated we set it to a
+ // maximum of only one request being able to be sent at a time. During the login process
+ // No concurrent requests can be sent anyway. It will be updated when receiving the
+ // S7ParameterSetupCommunication response.
+ this.tm = new RequestTransactionManager(1);
}
@Override
@@ -124,13 +137,23 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
maxAmqCallee = setupCommunication.getMaxAmqCallee();
pduSize = setupCommunication.getPduLength();
- // Only if the controller type is set to "ANY", then try to identify the PLC type.
+ // Update the number of concurrent requests to the negotiated number.
+ // I have never seen anything else than equal values for caller and
+ // callee, but if they were different, we're only limiting the outgoing
+ // requests.
+ tm.setNumberOfConcurrentRequests(maxAmqCaller);
+
+ // If the controller type is explicitly set, were finished with the login
+ // process. If it's set to ANY, we have to query the serial number information
+ // in order to detect the type of PLC.
if (controllerType != S7ControllerType.ANY) {
// Send an event that connection setup is complete.
context.fireConnected();
return;
}
+
// Prepare a message to request the remote to identify itself.
+ logger.debug("Sending S7 Identification Request");
TPKTPacket tpktPacket = createIdentifyRemoteMessage();
context.sendRequest(tpktPacket)
.expectResponse(TPKTPacket.class, REQUEST_TIMEOUT)
@@ -140,6 +163,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
.unwrap(p -> ((S7MessageUserData) p.getPayload()))
.check(p -> p.getPayload() instanceof S7PayloadUserData)
.handle(messageUserData -> {
+ logger.debug("Got S7 Identification Response");
S7PayloadUserData payloadUserData = (S7PayloadUserData) messageUserData.getPayload();
extractControllerTypeAndFireConnected(context, payloadUserData);
});
@@ -162,6 +186,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
new S7PayloadReadVarRequest()),
true, (short) tpduId));
+ // Start a new request-transaction (Is ended in the response-handler)
RequestTransactionManager.RequestTransaction transaction = tm.startRequest();
transaction.submit(() -> {
context.sendRequest(tpktPacket)
@@ -180,6 +205,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
} catch (PlcProtocolException e) {
logger.warn(String.format("Error sending 'read' message: '%s'", e.getMessage()), e);
}
+ // Finish the request-transaction.
transaction.endRequest();
});
});
@@ -205,6 +231,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
new S7PayloadWriteVarRequest(payloadItems.toArray(new S7VarPayloadDataItem[0]))),
true, (short) tpduId));
+ // Start a new request-transaction (Is ended in the response-handler)
RequestTransactionManager.RequestTransaction transaction = tm.startRequest();
transaction.submit(() -> {
context.sendRequest(tpktPacket)
@@ -223,6 +250,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> implements Ha
} catch (PlcProtocolException e) {
logger.warn(String.format("Error sending 'write' message: '%s'", e.getMessage()), e);
}
+ // Finish the request-transaction.
transaction.endRequest();
});
});
diff --git a/sandbox/test-streampipes-plc4x-processors/src/main/java/org/apache/plc4x/java/streampipes/processors/enrich/knxnetip/ets5/Ets5DataEnrichmentController.java b/sandbox/test-streampipes-plc4x-processors/src/main/java/org/apache/plc4x/java/streampipes/processors/enrich/knxnetip/ets5/Ets5DataEnrichmentController.java
index c8e4755..294bab2 100644
--- a/sandbox/test-streampipes-plc4x-processors/src/main/java/org/apache/plc4x/java/streampipes/processors/enrich/knxnetip/ets5/Ets5DataEnrichmentController.java
+++ b/sandbox/test-streampipes-plc4x-processors/src/main/java/org/apache/plc4x/java/streampipes/processors/enrich/knxnetip/ets5/Ets5DataEnrichmentController.java
@@ -31,7 +31,6 @@ import org.streampipes.sdk.helpers.EpRequirements;
import org.streampipes.sdk.helpers.Labels;
import org.streampipes.sdk.helpers.Locales;
import org.streampipes.sdk.helpers.OutputStrategies;
-import org.streampipes.sdk.utils.Assets;
import org.streampipes.sdk.utils.Datatypes;
import org.streampipes.wrapper.standalone.ConfiguredEventProcessor;
import org.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;