renault.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Renault tires TPMS. Usually 443.92 Mhz FSK.
  2. *
  3. * Preamble + sync + Manchester bits. ~48us short pulse.
  4. * 9 Bytes in total not counting the preamble. */
  5. #include "../../app.h"
  6. #define USE_TEST_VECTOR 0
  7. static const char *test_vector =
  8. "...01010101010101010110" // Preamble + sync
  9. /* The following is Marshal encoded, so each two characters are
  10. * actaully one bit. 01 = 0, 10 = 1. */
  11. "010110010110" // Flags.
  12. "10011001101010011001" // Pressure, multiply by 0.75 to obtain kpa.
  13. // 244 kpa here.
  14. "1010010110011010" // Temperature, subtract 30 to obtain celsius. 22C here.
  15. "1001010101101001"
  16. "0101100110010101"
  17. "1001010101100110" // Tire ID. 0x7AD779 here.
  18. "0101010101010101"
  19. "0101010101010101" // Two FF bytes (usually). Unknown.
  20. "0110010101010101"; // CRC8 with (poly 7, initialization 0).
  21. static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
  22. if (USE_TEST_VECTOR) { /* Test vector to check that decoding works. */
  23. bitmap_set_pattern(bits,numbytes,test_vector);
  24. numbits = strlen(test_vector);
  25. }
  26. if (numbits-12 < 9*8) return false;
  27. const char *sync_pattern = "01010101010101010110";
  28. uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
  29. if (off == BITMAP_SEEK_NOT_FOUND) return false;
  30. FURI_LOG_E(TAG, "Renault TPMS preamble+sync found");
  31. off += 20; /* Skip preamble. */
  32. uint8_t raw[9];
  33. uint32_t decoded =
  34. convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
  35. "01","10"); /* Manchester. */
  36. FURI_LOG_E(TAG, "Renault TPMS decoded bits: %lu", decoded);
  37. if (decoded < 8*9) return false; /* Require the full 9 bytes. */
  38. if (crc8(raw,8,0,7) != raw[8]) return false; /* Require sane CRC. */
  39. float kpa = 0.75 *((uint32_t)((raw[0]&3)<<8) | raw[1]);
  40. int temp = raw[2]-30;
  41. snprintf(info->name,sizeof(info->name),"%s","Renault TPMS");
  42. snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  43. raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
  44. raw[6],raw[7],raw[8]);
  45. snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X",
  46. raw[3],raw[4],raw[5]);
  47. snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
  48. snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
  49. return true;
  50. }
  51. ProtoViewDecoder RenaultTPMSDecoder = {
  52. "Renault TPMS", decode
  53. };