Skip to content

Commit

Permalink
Check CRC for TPMS protocols.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antirez committed Jan 12, 2023
1 parent a631025 commit cf2fdc6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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.
File renamed without changes.
1 change: 1 addition & 0 deletions protocols/renault_tpms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions protocols/toyota_tpms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cf2fdc6

Please sign in to comment.