From: Stefan Triller Date: Tue, 29 Mar 2022 16:54:21 +0000 (+0200) Subject: [novafinedust] Fix measurement parsing overflow (#12543) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=3c0d27dad8e0051b9d20333688749cd4eaf4e0b1;p=openhab-addons.git [novafinedust] Fix measurement parsing overflow (#12543) Fixes #12542 Signed-off-by: Stefan Triller --- diff --git a/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/SDS011Communicator.java b/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/SDS011Communicator.java index 391fe641a8..48de763cfc 100644 --- a/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/SDS011Communicator.java +++ b/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/SDS011Communicator.java @@ -227,6 +227,7 @@ public class SDS011Communicator { if (logger.isDebugEnabled()) { logger.debug("Read remaining bytes: {}, full reply={}", remainingBytesRead, HexUtils.bytesToHex(readBuffer)); + logger.trace("Read bytes as numbers: {}", Arrays.toString(readBuffer)); } return ReplyFactory.create(readBuffer); } diff --git a/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/messages/SensorMeasuredDataReply.java b/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/messages/SensorMeasuredDataReply.java index b11dfc9c58..566c6bc356 100644 --- a/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/messages/SensorMeasuredDataReply.java +++ b/bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/messages/SensorMeasuredDataReply.java @@ -54,7 +54,7 @@ public class SensorMeasuredDataReply extends SensorReply { * @return the measured PM2.5 value */ public float getPm25() { - int shiftedValue = (pm25highByte << 8 & 0xFF) | pm25lowByte & 0xFF; + int shiftedValue = ((pm25highByte & 0xFF) << 8) | pm25lowByte & 0xFF; return ((float) shiftedValue) / 10; } @@ -64,7 +64,7 @@ public class SensorMeasuredDataReply extends SensorReply { * @return the measured PM10 value */ public float getPm10() { - int shiftedValue = (pm10highByte << 8 & 0xFF) | pm10lowByte & 0xFF; + int shiftedValue = ((pm10highByte & 0xFF) << 8) | pm10lowByte & 0xFF; return ((float) shiftedValue) / 10; }