Przeglądaj źródła

Check checksum in Schrader TPMS.

antirez 3 lat temu
rodzic
commit
86ca7ffe02
1 zmienionych plików z 7 dodań i 0 usunięć
  1. 7 0
      protocols/schrader_tpms.c

+ 7 - 0
protocols/schrader_tpms.c

@@ -39,6 +39,13 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
 
 
     if (decoded < 64) return false; /* Require the full 8 bytes. */
     if (decoded < 64) return false; /* Require the full 8 bytes. */
 
 
+    raw[0] |= 0xf0; // Fix the preamble nibble for checksum computation.
+    uint8_t cksum = crc8(raw,sizeof(raw)-1,0xf0,0x7);
+    if (cksum != raw[7]) {
+        FURI_LOG_E(TAG, "Schrader TPMS checksum mismatch");
+        return false;
+    }
+
     float kpa = (float)raw[5]*2.5;
     float kpa = (float)raw[5]*2.5;
     int temp = raw[6]-50;
     int temp = raw[6]-50;