citroen.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. info->start_off = off;
  19. off += sync_len; /* Skip preamble + sync. */
  20. uint8_t raw[10];
  21. uint32_t decoded =
  22. convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
  23. "01","10"); /* Manchester. */
  24. FURI_LOG_E(TAG, "Citroen TPMS decoded bits: %lu", decoded);
  25. if (decoded < 8*10) return false; /* Require the full 10 bytes. */
  26. /* Check the CRC. It's a simple XOR of bytes 1-9, the first byte
  27. * is not included. The meaning of the first byte is unknown and
  28. * we don't display it. */
  29. uint8_t crc = 0;
  30. for (int j = 1; j < 10; j++) crc ^= raw[j];
  31. if (crc != 0) return false; /* Require sane checksum. */
  32. info->pulses_count = (off+8*10*2) - info->start_off;
  33. int repeat = raw[5] & 0xf;
  34. float kpa = (float)raw[6]*1.364;
  35. int temp = raw[7]-50;
  36. int battery = raw[8]; /* This may be the battery. It's not clear. */
  37. fieldset_add_bytes(info->fieldset,"Tire ID",raw+1,4*2);
  38. fieldset_add_float(info->fieldset,"Pressure kpa",kpa,2);
  39. fieldset_add_int(info->fieldset,"Temperature C",temp,8);
  40. fieldset_add_uint(info->fieldset,"Repeat",repeat,4);
  41. fieldset_add_uint(info->fieldset,"Battery",battery,8);
  42. return true;
  43. }
  44. ProtoViewDecoder CitroenTPMSDecoder = {
  45. .name = "Citroen TPMS",
  46. .decode = decode,
  47. .get_fields = NULL,
  48. .build_message = NULL
  49. };