Просмотр исходного кода

Check CRC for TPMS protocols.

They have very weak preamble / sync and are easily confused. Moreover in
case of errors better to don't show the info to the user at all: they
are about tires pressure, so it's better to show safe data.
antirez 3 лет назад
Родитель
Сommit
cf2fdc6a80
4 измененных файлов с 4 добавлено и 4 удалено
  1. 0 2
      TODO
  2. 0 0
      data_feed.c
  3. 1 0
      protocols/renault_tpms.c
  4. 3 2
      protocols/toyota_tpms.c

+ 0 - 2
TODO

@@ -7,5 +7,3 @@ Core improvements
   sub files with modified signal and so forth.
 - Optimize memory usage storing raw samples in a bitfield: 15 bits
   duration, 1 bit level.
-- Implement checksum for all TPMS protocols. They have very weak
-  preamble/sync discrimination.

+ 0 - 0
proto.c → data_feed.c


+ 1 - 0
protocols/renault_tpms.c

@@ -45,6 +45,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     FURI_LOG_E(TAG, "Renault TPMS decoded bits: %lu", decoded);
 
     if (decoded < 8*9) return false; /* Require the full 9 bytes. */
+    if (crc8(raw,8,0,7) != raw[8]) return false; /* Require sane CRC. */
 
     float kpa = 0.75 *((uint32_t)((raw[0]&3)<<8) | raw[1]);
     int temp = raw[2]-30;

+ 3 - 2
protocols/toyota_tpms.c

@@ -50,12 +50,13 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
 
     FURI_LOG_E(TAG, "Toyota TPMS sync[%s] found", sync[j]);
 
-    uint8_t raw[8];
+    uint8_t raw[9];
     uint32_t decoded =
         convert_from_diff_manchester(raw,sizeof(raw),bits,numbytes,off,true);
     FURI_LOG_E(TAG, "Toyota TPMS decoded bits: %lu", decoded);
 
-    if (decoded < 64) return false; /* Require the full 8 bytes. */
+    if (decoded < 8*9) return false; /* Require the full 8 bytes. */
+    if (crc8(raw,8,0x80,7) != raw[8]) return false; /* Require sane CRC. */
 
     float kpa = (float)((raw[4]&0x7f)<<1 | raw[5]>>7) * 0.25 - 7;
     int temp = ((raw[5]&0x7f)<<1 | raw[6]>>7) - 40;