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 2024/08/13 14:52:30 UTC

(plc4x) branch develop updated: fix: Made sure the KNX driver emits the DisconnectedEvent

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 77dfb25ad1 fix: Made sure the KNX driver emits the DisconnectedEvent
77dfb25ad1 is described below

commit 77dfb25ad11c508d2e6f6d5234196227afaa4dcc
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Tue Aug 13 16:52:23 2024 +0200

    fix: Made sure the KNX driver emits the DisconnectedEvent
---
 .../knxnetip/protocol/KnxNetIpProtocolLogic.java   | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
index f5ef3ac7c8..962cbeb06d 100644
--- a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
+++ b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
@@ -227,24 +227,23 @@ public class KnxNetIpProtocolLogic extends Plc4xProtocolBase<KnxNetIpMessage> im
         // Cancel the timer for sending connection state requests.
         connectionStateTimer.cancel();
 
+        // Just send out the disconnect request message, in most cases the remote will not respond.
+        // So in this case we'll just fire out the message and treat the connection as closed.
         DisconnectRequest disconnectRequest = new DisconnectRequest(knxNetIpDriverContext.getCommunicationChannelId(),
             new HPAIControlEndpoint(HostProtocolCode.IPV4_UDP,
                 knxNetIpDriverContext.getLocalIPAddress(), knxNetIpDriverContext.getLocalPort()));
-        context.sendRequest(disconnectRequest)
-            .expectResponse(KnxNetIpMessage.class, Duration.ofMillis(1000))
-            .only(DisconnectResponse.class)
-            .handle(disconnectResponse -> {
-                // In general, we should probably check if the disconnect was successful, but in
-                // the end we couldn't do much if the disconnect would fail.
-                final String gatewayName = knxNetIpDriverContext.getGatewayName();
-                final KnxAddress gatewayAddress = knxNetIpDriverContext.getGatewayAddress();
-                LOGGER.info(String.format("Disconnected from KNX Gateway '%s' with KNX address '%d.%d.%d'", gatewayName,
-                    gatewayAddress.getMainGroup(), gatewayAddress.getMiddleGroup(), gatewayAddress.getSubGroup()));
-
-                // Send an event that connection disconnect is complete.
-                context.fireDisconnected();
-                LOGGER.debug("Disconnected event fired from KNX protocol");
-            });
+        context.sendToWire(disconnectRequest);
+
+        // In general, we should probably check if the disconnect was successful, but in
+        // the end we couldn't do much if the disconnect would fail.
+        final String gatewayName = knxNetIpDriverContext.getGatewayName();
+        final KnxAddress gatewayAddress = knxNetIpDriverContext.getGatewayAddress();
+        LOGGER.info("Disconnected from KNX Gateway '{}' with KNX address '{}.{}.{}'",
+            gatewayName, gatewayAddress.getMainGroup(), gatewayAddress.getMiddleGroup(), gatewayAddress.getSubGroup());
+
+        // Send an event that connection disconnect is complete.
+        context.fireDisconnected();
+        LOGGER.debug("Disconnected event fired from KNX protocol");
     }
 
     @Override