From abd3172cb5ac81bc60c2ff25b6237c86063594e9 Mon Sep 17 00:00:00 2001 From: Uellington Damasceno Date: Thu, 8 Feb 2024 09:07:29 -0300 Subject: [PATCH] If applied, this commit will update the latency log registration. --- .../device/fot/virtual/controller/DefaultFlowCallback.java | 2 +- src/main/java/com/device/fot/virtual/model/FoTSensor.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/device/fot/virtual/controller/DefaultFlowCallback.java b/src/main/java/com/device/fot/virtual/controller/DefaultFlowCallback.java index d74bd64..48dc2fc 100644 --- a/src/main/java/com/device/fot/virtual/controller/DefaultFlowCallback.java +++ b/src/main/java/com/device/fot/virtual/controller/DefaultFlowCallback.java @@ -99,7 +99,7 @@ public void deliveryComplete(IMqttDeliveryToken imdt) { MqttMessage deliveredMessage; try { deliveredMessage = imdt.getMessage(); - if(deliveredMessage.getPayload().length == 0){ + if(deliveredMessage == null || deliveredMessage.getPayload().length == 0){ return; } String messageContent = new String(deliveredMessage.getPayload()); diff --git a/src/main/java/com/device/fot/virtual/model/FoTSensor.java b/src/main/java/com/device/fot/virtual/model/FoTSensor.java index ca7970f..d718fe1 100644 --- a/src/main/java/com/device/fot/virtual/model/FoTSensor.java +++ b/src/main/java/com/device/fot/virtual/model/FoTSensor.java @@ -50,7 +50,7 @@ public FoTSensor(String deviceId, this.flow = false; this.running = false; this.random = new Random(); - this.lastValue = minValue + random.nextInt() * (maxValue - minValue); + this.lastValue = (minValue <= 0 && maxValue <= 0) ? 0 : random.nextInt(minValue, maxValue); this.flowThreadName = this.buildFlowThreadName(deviceId, id); } @@ -139,8 +139,8 @@ private Data getDataFlow() throws InterruptedException { } public Integer getCurrentValue() { - //Integer variation = random.nextInt()* delta * (random.nextBoolean() ? 1 : -1); - //this.lastValue = Math.min(maxValue, Math.max(minValue, lastValue + variation)); + Integer variation = delta * (random.nextBoolean() ? 1 : -1); + this.lastValue = Math.min(maxValue, Math.max(minValue, lastValue + variation)); return lastValue; }