]> git.basschouten.com Git - openhab-addons.git/commitdiff
[novafinedust] Fix measurement parsing overflow (#12543)
authorStefan Triller <t2000@users.noreply.github.com>
Tue, 29 Mar 2022 16:54:21 +0000 (18:54 +0200)
committerGitHub <noreply@github.com>
Tue, 29 Mar 2022 16:54:21 +0000 (18:54 +0200)
Fixes #12542

Signed-off-by: Stefan Triller <github@stefantriller.de>
bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/SDS011Communicator.java
bundles/org.openhab.binding.novafinedust/src/main/java/org/openhab/binding/novafinedust/internal/sds011protocol/messages/SensorMeasuredDataReply.java

index 391fe641a8e8b97f40907d8e899e8856a6bfec32..48de763cfc7959de93bbb8becc348a2808a4d068 100644 (file)
@@ -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);
         }
index b11dfc9c5825343d572a4ec61ad58ab2503f8213..566c6bc3566cce2353e48de37b8d3fa7f4348dcc 100644 (file)
@@ -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;
     }