schrader_eg53ma4.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Schrader variant EG53MA4 TPMS.
  2. * Usually 443.92 Mhz OOK, 100us pulse len.
  3. *
  4. * Preamble: alternating pulse/gap, 100us.
  5. * Sync (as pulses and gaps): "01100101", already part of the data stream
  6. * (first nibble) corresponding to 0x4
  7. *
  8. * A total of 10 bytes payload, Manchester encoded.
  9. *
  10. * 0 = 01
  11. * 1 = 10
  12. *
  13. * Used in certain Open cars and others.
  14. */
  15. #include "../../app.h"
  16. static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
  17. const char *sync_pattern = "010101010101" "01100101";
  18. uint8_t sync_len = 12+8; /* We just use 12 preamble symbols + sync. */
  19. if (numbits-sync_len+8 < 8*10) return false;
  20. uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
  21. if (off == BITMAP_SEEK_NOT_FOUND) return false;
  22. FURI_LOG_E(TAG, "Schrader EG53MA4 TPMS preamble+sync found");
  23. off += sync_len-8; /* Skip preamble, not sync that is part of the data. */
  24. uint8_t raw[10];
  25. uint32_t decoded =
  26. convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
  27. "01","10"); /* Manchester code. */
  28. FURI_LOG_E(TAG, "Schrader EG53MA4 TPMS decoded bits: %lu", decoded);
  29. if (decoded < 10*8) return false; /* Require the full 10 bytes. */
  30. /* CRC is just all bytes added mod 256. */
  31. uint8_t crc = 0;
  32. for (int j = 0; j < 9; j++) crc += raw[j];
  33. if (crc != raw[9]) return false; /* Require sane CRC. */
  34. /* To convert the raw pressure to kPa, RTL433 uses 2.5, but is likely
  35. * wrong. Searching on Google for users experimenting with the value
  36. * reported, the value appears to be 2.75. */
  37. float kpa = (float)raw[7]*2.75;
  38. int temp_f = raw[8];
  39. int temp_c = (temp_f-32)*5/9; /* Convert Fahrenheit to Celsius. */
  40. snprintf(info->name,sizeof(info->name),"%s","Schrader EG53MA4 TPMS");
  41. snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  42. raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
  43. raw[6],raw[7],raw[8],raw[9]);
  44. snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X",
  45. raw[4],raw[5],raw[6]); /* Only 28 bits of ID, not 32. */
  46. snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
  47. snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp_c);
  48. return true;
  49. }
  50. ProtoViewDecoder SchraderEG53MA4TPMSDecoder = {
  51. "Schrader EG53MA4 TPMS", decode
  52. };