forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schrader TPMS implementation + CRC8 implementation.
- Loading branch information
Showing
7 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
/* CRC8 with the specified initialization value 'init' and | ||
* polynomial 'poly'. */ | ||
uint8_t crc8(const uint8_t *data, size_t len, uint8_t init, uint8_t poly) | ||
{ | ||
uint8_t crc = init; | ||
size_t i, j; | ||
for (i = 0; i < len; i++) { | ||
crc ^= data[i]; | ||
for (j = 0; j < 8; j++) { | ||
if ((crc & 0x80) != 0) | ||
crc = (uint8_t)((crc << 1) ^ poly); | ||
else | ||
crc <<= 1; | ||
} | ||
} | ||
return crc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Schrader TPMS. Usually 443.92 Mhz OOK, 120us pulse len. | ||
* | ||
* 500us high pulse + Preamble + Manchester coded bits where: | ||
* 1 = 10 | ||
* 0 = 01 | ||
* | ||
* 60 bits of data total (first 4 nibbles is the preamble, 0xF). | ||
* | ||
* Used in FIAT-Chrysler, Mercedes, ... */ | ||
|
||
#include "../app.h" | ||
|
||
#define USE_TEST_VECTOR 0 | ||
static const char *test_vector = "000000111101010101011010010110010110101001010110100110011001100101010101011010100110100110011010101010101010101010101010101010101010101010101010"; | ||
|
||
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) { | ||
|
||
if (USE_TEST_VECTOR) { /* Test vector to check that decoding works. */ | ||
bitmap_set_pattern(bits,numbytes,test_vector); | ||
numbits = strlen(test_vector); | ||
} | ||
|
||
if (numbits < 64) return false; /* Preamble + data. */ | ||
|
||
const char *sync_pattern = "1111010101" "01011010"; | ||
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern); | ||
if (off == BITMAP_SEEK_NOT_FOUND) return false; | ||
FURI_LOG_E(TAG, "Schrader TPMS gap+preamble found"); | ||
|
||
off += 10; /* Skip just the long pulse and the first 3 bits of sync, so | ||
that we have the first byte of data with the sync nibble | ||
0011 = 0x3. */ | ||
|
||
uint8_t raw[8]; | ||
uint32_t decoded = | ||
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off, | ||
"01","10"); /* Manchester code. */ | ||
FURI_LOG_E(TAG, "Schrader TPMS decoded bits: %lu", decoded); | ||
|
||
if (decoded < 64) return false; /* Require the full 8 bytes. */ | ||
|
||
float kpa = (float)raw[5]*2.5; | ||
int temp = raw[6]-50; | ||
|
||
snprintf(info->name,sizeof(info->name),"%s","Schrader TPMS"); | ||
snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X", | ||
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5], | ||
raw[6],raw[7]); | ||
snprintf(info->info1,sizeof(info->info1),"Tire ID %01X%02X%02X%02X", | ||
raw[1]&7,raw[2],raw[3],raw[4]); /* Only 28 bits of ID, not 32. */ | ||
snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa); | ||
snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp); | ||
return true; | ||
} | ||
|
||
ProtoViewDecoder SchraderTPMSDecoder = { | ||
"Schrader TPMS", decode | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters