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/08/23 12:46:12 UTC

[incubator-plc4x] 01/02: [ADS] fixed subscription ignores subscription type

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

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

commit ff4e8959aefe3bd12a23cf29af9c9b4b8a7631ec
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Aug 23 14:39:48 2018 +0200

    [ADS] fixed subscription ignores subscription type
---
 .../plc4x/java/ads/connection/AdsTcpPlcConnection.java     | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java
index 12fc9cf..e9032d8 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java
@@ -174,6 +174,18 @@ public class AdsTcpPlcConnection extends AdsAbstractPlcConnection implements Plc
             throw new IllegalArgumentException("Unsupported address type " + address.getClass());
         }
 
+        final TransmissionMode transmissionMode;
+        switch (subscriptionRequestItem.getSubscriptionType()) {
+            case CYCLIC:
+                transmissionMode = TransmissionMode.DefinedValues.ADSTRANS_SERVERCYCLE;
+                break;
+            case CHANGE_OF_STATE:
+                transmissionMode = TransmissionMode.DefinedValues.ADSTRANS_SERVERONCHA;
+                break;
+            default:
+                throw new PlcRuntimeException("Unmapped type " + subscriptionRequestItem.getSubscriptionType());
+        }
+
         // Prepare the subscription request itself.
         AdsAddDeviceNotificationRequest adsAddDeviceNotificationRequest = AdsAddDeviceNotificationRequest.of(
             targetAmsNetId,
@@ -184,7 +196,7 @@ public class AdsTcpPlcConnection extends AdsAbstractPlcConnection implements Plc
             indexGroup,
             indexOffset,
             LittleEndianDecoder.getLengthFor(datatype, 1),
-            TransmissionMode.DefinedValues.ADSTRANS_SERVERCYCLE,
+            transmissionMode,
             MaxDelay.of(0),
             CycleTime.of(4000000)
         );