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 2022/09/07 09:15:12 UTC
[plc4x] branch develop updated: feat(plc-simulator/cbus): pick one of the available units for mmi
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 cf1462e87 feat(plc-simulator/cbus): pick one of the available units for mmi
cf1462e87 is described below
commit cf1462e87bd45089516e5bed97030ed24b44c700
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Sep 7 11:14:59 2022 +0200
feat(plc-simulator/cbus): pick one of the available units for mmi
---
.../plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java | 9 +++++++--
plc4j/utils/raw-sockets/pom.xml | 4 ----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
index 41aee45b2..d61398822 100644
--- a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
+++ b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/protocol/CBusServerAdapter.java
@@ -30,6 +30,7 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -646,6 +647,8 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
return;
}
try {
+ int randomElementIndex = ThreadLocalRandom.current().nextInt(AVAILABLE_UNITS.size()) % AVAILABLE_UNITS.size();
+ byte randomUnit = AVAILABLE_UNITS.get(randomElementIndex);
outputLock.lock();
MonitoredSAL monitoredSAL;
if (cBusOptions.getExstat()) {
@@ -661,7 +664,7 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
lightingData = new LightingDataTerminateRamp(LightingCommandTypeContainer.LightingCommandTerminateRamp, (byte) 0xAF);
}
SALData salData = new SALDataLighting(null, lightingData);
- monitoredSAL = new MonitoredSALLongFormSmartMode((byte) 0x05, (byte) 0x00, new UnitAddress((byte) 0x0), null, ApplicationIdContainer.LIGHTING_38, (byte) 0x00, null, salData, cBusOptions);
+ monitoredSAL = new MonitoredSALLongFormSmartMode((byte) 0x05, (byte) 0x00, new UnitAddress(randomUnit), null, ApplicationIdContainer.LIGHTING_38, (byte) 0x00, null, salData, cBusOptions);
} else {
LightingData lightingData;
double random = Math.random();
@@ -705,6 +708,8 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
}
LOGGER.info("Starting MMI monitor");
mmiMonitorFuture = ctx.executor().scheduleAtFixedRate(() -> {
+ int randomElementIndex = ThreadLocalRandom.current().nextInt(AVAILABLE_UNITS.size()) % AVAILABLE_UNITS.size();
+ byte randomUnit = AVAILABLE_UNITS.get(randomElementIndex);
// TODO: for whatever reason those are not send with a crc
CBusOptions cBusOptions = new CBusOptions(connect, smart, idmon, exstat, monitor, monall, pun, pcn, false);
try {
@@ -717,7 +722,7 @@ public class CBusServerAdapter extends ChannelInboundHandlerAdapter {
statusBytes.add(new StatusByte(GAVState.ON, GAVState.ERROR, GAVState.OFF, GAVState.DOES_NOT_EXIST));
}
CALData calData = new CALDataStatusExtended(CALCommandTypeContainer.CALCommandStatusExtended_25Bytes, null, StatusCoding.BINARY_BY_ELSEWHERE, ApplicationIdContainer.LIGHTING_38, (byte) 0x00, statusBytes, null, requestContext);
- calReply = new CALReplyLong((byte) 0x86, calData, 0x00, new UnitAddress((byte) 0x04), null, new SerialInterfaceAddress((byte) 0x02), (byte) 0x00, null, cBusOptions, requestContext);
+ calReply = new CALReplyLong((byte) 0x86, calData, 0x00, new UnitAddress(randomUnit), null, new SerialInterfaceAddress((byte) 0x02), (byte) 0x00, null, cBusOptions, requestContext);
} else {
List<StatusByte> statusBytes = new LinkedList<>();
// TODO: map actual values from simulator
diff --git a/plc4j/utils/raw-sockets/pom.xml b/plc4j/utils/raw-sockets/pom.xml
index ab33566a4..6b16164c5 100644
--- a/plc4j/utils/raw-sockets/pom.xml
+++ b/plc4j/utils/raw-sockets/pom.xml
@@ -74,10 +74,6 @@
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>