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 2023/01/16 14:43:16 UTC

[plc4x] branch develop updated: fix(plc-simulator/bacnet): simulator should now respond to the right ip on bacnet

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

sruehl 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 7ff73a2cf6 fix(plc-simulator/bacnet): simulator should now respond to the right ip on bacnet
7ff73a2cf6 is described below

commit 7ff73a2cf63cd1d90fb7d33ee32a329554aa2bb0
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Jan 16 15:43:08 2023 +0100

    fix(plc-simulator/bacnet): simulator should now respond to the right ip on bacnet
---
 .../apache/plc4x/simulator/server/bacnet/BacnetServerModule.java  | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/bacnet/BacnetServerModule.java b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/bacnet/BacnetServerModule.java
index 8c69793edc..6a9b08a170 100644
--- a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/bacnet/BacnetServerModule.java
+++ b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/bacnet/BacnetServerModule.java
@@ -29,6 +29,7 @@ import io.netty.channel.socket.DatagramPacket;
 import io.netty.channel.socket.nio.NioDatagramChannel;
 import io.netty.handler.codec.MessageToMessageDecoder;
 import io.netty.handler.codec.MessageToMessageEncoder;
+import io.netty.util.concurrent.FastThreadLocal;
 import org.apache.plc4x.java.bacnetip.BacNetIpDriver;
 import org.apache.plc4x.java.bacnetip.readwrite.BVLC;
 import org.apache.plc4x.java.bacnetip.readwrite.BacnetConstants;
@@ -50,6 +51,8 @@ public class BacnetServerModule implements ServerModule {
     private Context context;
     private PlcSimulatorConfig config;
 
+    private final FastThreadLocal<String> returnToSender = new FastThreadLocal<>();
+
     @Override
     public String getName() {
         return "Bacnet";
@@ -87,14 +90,15 @@ public class BacnetServerModule implements ServerModule {
                                 protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception {
                                     final ByteBuf content = msg.content();
                                     out.add(content.retain());
+                                    String value = msg.sender().getHostString();
+                                    returnToSender.set(value);
                                 }
                             })
                             .addLast(new MessageToMessageEncoder<ByteBuf>() {
                                 @Override
                                 protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
                                     msg.retain();
-                                    // TODO: find better way to implement request response
-                                    out.add(new DatagramPacket(msg, new InetSocketAddress("192.168.178.102", 47808)));
+                                    out.add(new DatagramPacket(msg, new InetSocketAddress(returnToSender.get(), 47808)));
                                 }
                             })
                             .addLast(new GeneratedProtocolMessageCodec<>(BVLC.class,