citroen.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Citroen TPMS. Usually 443.92 Mhz FSK.
  2. *
  3. * Preamble of ~14 high/low 52 us pulses
  4. * Sync of high 100us pulse then 50us low
  5. * Then Manchester bits, 10 bytes total.
  6. * Simple XOR checksum. */
  7. #include "../../app.h"
  8. static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
  9. /* We consider a preamble of 17 symbols. They are more, but the decoding
  10. * is more likely to happen if we don't pretend to receive from the
  11. * very start of the message. */
  12. uint32_t sync_len = 17;
  13. const char *sync_pattern = "10101010101010110";
  14. if (numbits-sync_len < 8*10) return false; /* Expect 10 bytes. */
  15. uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
  16. if (off == BITMAP_SEEK_NOT_FOUND) return false;
  17. FURI_LOG_E(TAG, "Renault TPMS preamble+sync found");
  18. off += sync_len; /* Skip preamble + sync. */
  19. uint8_t raw[10];
  20. uint32_t decoded =
  21. convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
  22. "01","10"); /* Manchester. */
  23. FURI_LOG_E(TAG, "Citroen TPMS decoded bits: %lu", decoded);
  24. if (decoded < 8*10) return false; /* Require the full 10 bytes. */
  25. /* Check the CRC. It's a simple XOR of bytes 1-9, the first byte
  26. * is not included. The meaning of the first byte is unknown and
  27. * we don't display it. */
  28. uint8_t crc = 0;
  29. for (int j = 1; j < 10; j++) crc ^= raw[j];
  30. if (crc != 0) return false; /* Require sane checksum. */
  31. int repeat = raw[5] & 0xf;
  32. float kpa = (float)raw[6]*1.364;
  33. int temp = raw[7]-50;
  34. int battery = raw[8]; /* This may be the battery. It's not clear. */
  35. snprintf(info->name,sizeof(info->name),"%s","Citroen TPMS");
  36. snprintf(info->raw,sizeof(info->raw),
  37. "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  38. raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
  39. raw[6],raw[7],raw[8],raw[9],raw[10]);
  40. snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X%02X",
  41. raw[1],raw[2],raw[3],raw[4]);
  42. snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
  43. snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
  44. snprintf(info->info4,sizeof(info->info4),"Repeat %d, Bat %d", repeat, battery);
  45. return true;
  46. }
  47. ProtoViewDecoder CitroenTPMSDecoder = {
  48. "Citroen TPMS", decode
  49. };