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 2022/03/31 09:54:33 UTC
[plc4x] branch develop updated: fix(plc4j/s7): communication with LOGO 0AB7 and ISOonTCP tsap configuration (#308)
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new ece4af4 fix(plc4j/s7): communication with LOGO 0AB7 and ISOonTCP tsap configuration (#308)
ece4af4 is described below
commit ece4af4d260cbf4aa4d0884c40e87aa985ffa6fa
Author: Henry <se...@users.noreply.github.com>
AuthorDate: Thu Mar 31 11:54:29 2022 +0200
fix(plc4j/s7): communication with LOGO 0AB7 and ISOonTCP tsap configuration (#308)
* swap tsap around as LOGO 0BA7 need this specific order
* add local-tsap and remote-tsap
add local-tsap and remote-tsap to s7 options because this values can not
generated, they are specific to each ISO connection like port numbers
Co-authored-by: Christofer Dutz <ch...@c-ware.de>
---
.../readwrite/configuration/S7Configuration.java | 30 ++++++++++++++++++++--
.../java/s7/readwrite/context/S7DriverContext.java | 22 +++++++++++-----
.../s7/readwrite/protocol/S7ProtocolLogic.java | 8 +++---
3 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java
index b702d49..385bb97 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java
@@ -1,5 +1,5 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@@ -33,6 +33,10 @@ public class S7Configuration implements Configuration, TcpTransportConfiguration
@ConfigurationParameter("local-slot")
@IntDefaultValue(1)
public int localSlot = 1;
+
+ @ConfigurationParameter("local-tsap")
+ @IntDefaultValue(0)
+ public int localTsap = 0;
@ConfigurationParameter("remote-rack")
@IntDefaultValue(0)
@@ -42,6 +46,10 @@ public class S7Configuration implements Configuration, TcpTransportConfiguration
@IntDefaultValue(0)
public int remoteSlot = 0;
+ @ConfigurationParameter("remote-tsap")
+ @IntDefaultValue(0)
+ public int remoteTsap = 0;
+
@ConfigurationParameter("pdu-size")
@IntDefaultValue(1024)
public int pduSize = 1024;
@@ -73,6 +81,14 @@ public class S7Configuration implements Configuration, TcpTransportConfiguration
this.localSlot = localSlot;
}
+ public int getLocalTsap() {
+ return localTsap;
+ }
+
+ public void setLocalTsap(int localTsap) {
+ this.localTsap = localTsap;
+ }
+
public int getRemoteRack() {
return remoteRack;
}
@@ -89,6 +105,14 @@ public class S7Configuration implements Configuration, TcpTransportConfiguration
this.remoteSlot = remoteSlot;
}
+ public int getRemoteTsap() {
+ return remoteTsap;
+ }
+
+ public void setRemoteTsap(int remoteTsap) {
+ this.remoteTsap = remoteTsap;
+ }
+
public int getPduSize() {
return pduSize;
}
@@ -135,8 +159,10 @@ public class S7Configuration implements Configuration, TcpTransportConfiguration
return "Configuration{" +
"local-rack=" + localRack +
", local-slot=" + localSlot +
+ ", local-tsap=" + localTsap +
", remote-rack=" + remoteRack +
", remot-slot=" + remoteSlot +
+ ", remot-tsap=" + remoteTsap +
", pduSize=" + pduSize +
", maxAmqCaller=" + maxAmqCaller +
", maxAmqCallee=" + maxAmqCallee +
diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java
index e274729..69eb544 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java
@@ -44,20 +44,30 @@ public class S7DriverContext implements DriverContext, HasConfiguration<S7Config
this.calledTsapId = S7TsapIdEncoder.encodeS7TsapId(DeviceGroup.PG_OR_PC,
configuration.remoteRack, configuration.remoteSlot);
+ if (configuration.localTsap > 0) {
+ this.callingTsapId = configuration.localTsap;
+ }
+ if (configuration.remoteTsap > 0) {
+ this.calledTsapId = configuration.remoteTsap;
+ }
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;
+ this.pduSize = 480;
+ } else {
+ // 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;
}
-
+
// 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;
}
diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
index 7b2dd1d..0ab2ced 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
@@ -714,10 +714,10 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
private COTPPacketConnectionRequest createCOTPConnectionRequest(int calledTsapId, int callingTsapId, COTPTpduSize cotpTpduSize) {
return new COTPPacketConnectionRequest(
Arrays.asList(
- new COTPParameterCalledTsap(calledTsapId,null),
- new COTPParameterCallingTsap(callingTsapId,null),
- new COTPParameterTpduSize(cotpTpduSize,null)
- ), null, (short) 0x0000, (short) 0x000F, COTPProtocolClass.CLASS_0,null);
+ new COTPParameterCallingTsap(callingTsapId, null),
+ new COTPParameterCalledTsap(calledTsapId, null),
+ new COTPParameterTpduSize(cotpTpduSize, null)
+ ), null, (short) 0x0000, (short) 0x000F, COTPProtocolClass.CLASS_0, null);
}
private PlcResponse decodeReadResponse(S7Message responseMessage, PlcReadRequest plcReadRequest) throws PlcProtocolException {