ford.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Ford tires TPMS. Usually 443.92 Mhz FSK (in Europe).
  2. *
  3. * 52 us short pules
  4. * Preamble: 0101010101010101010101010101
  5. * Sync: 0110 (that is 52 us gap + 104 us pulse + 52 us gap)
  6. * Data: 8 bytes Manchester encoded
  7. * 01 = zero
  8. * 10 = one
  9. */
  10. #include "../../app.h"
  11. static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
  12. const char *sync_pattern = "010101010101" "0110";
  13. uint8_t sync_len = 12+4; /* We just use 12 preamble symbols + sync. */
  14. if (numbits-sync_len < 8*8) return false;
  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, "Fort TPMS preamble+sync found");
  18. off += sync_len; /* Skip preamble and sync. */
  19. uint8_t raw[8];
  20. uint32_t decoded =
  21. convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
  22. "01","10"); /* Manchester. */
  23. FURI_LOG_E(TAG, "Ford TPMS decoded bits: %lu", decoded);
  24. if (decoded < 8*8) return false; /* Require the full 8 bytes. */
  25. /* CRC is just the sum of the first 7 bytes MOD 256. */
  26. uint8_t crc = 0;
  27. for (int j = 0; j < 7; j++) crc += raw[j];
  28. if (crc != raw[7]) return false; /* Require sane CRC. */
  29. float psi = 0.25 * (((raw[6]&0x20)<<3)|raw[4]);
  30. /* Temperature apperas to be valid only if the most significant
  31. * bit of the value is not set. Otherwise its meaning is unknown.
  32. * Likely useful to alternatively send temperature or other info. */
  33. int temp = raw[5] & 0x80 ? 0 : raw[5]-56;
  34. int flags = raw[5] & 0x7f;
  35. int car_moving = (raw[6] & 0x44) == 0x44;
  36. snprintf(info->name,sizeof(info->name),"%s","Ford TPMS");
  37. snprintf(info->raw,sizeof(info->raw),"%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]);
  40. snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X%02X",
  41. raw[0],raw[1],raw[2],raw[3]);
  42. snprintf(info->info2,sizeof(info->info2),"Pressure %.2f psi", (double)psi);
  43. if (temp)
  44. snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
  45. else
  46. snprintf(info->info3,sizeof(info->info3),"Flags %d", flags);
  47. snprintf(info->info4,sizeof(info->info4),"Moving %s", car_moving ? "yes" : "no");
  48. return true;
  49. }
  50. ProtoViewDecoder FordTPMSDecoder = {
  51. "Ford TPMS", decode
  52. };