schrader_eg53ma4.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. info->start_off = off;
  24. off += sync_len-8; /* Skip preamble, not sync that is part of the data. */
  25. uint8_t raw[10];
  26. uint32_t decoded =
  27. convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
  28. "01","10"); /* Manchester code. */
  29. FURI_LOG_E(TAG, "Schrader EG53MA4 TPMS decoded bits: %lu", decoded);
  30. if (decoded < 10*8) return false; /* Require the full 10 bytes. */
  31. /* CRC is just all bytes added mod 256. */
  32. uint8_t crc = 0;
  33. for (int j = 0; j < 9; j++) crc += raw[j];
  34. if (crc != raw[9]) return false; /* Require sane CRC. */
  35. info->pulses_count = (off+10*8*2) - info->start_off;
  36. /* To convert the raw pressure to kPa, RTL433 uses 2.5, but is likely
  37. * wrong. Searching on Google for users experimenting with the value
  38. * reported, the value appears to be 2.75. */
  39. float kpa = (float)raw[7]*2.75;
  40. int temp_f = raw[8];
  41. int temp_c = (temp_f-32)*5/9; /* Convert Fahrenheit to Celsius. */
  42. fieldset_add_bytes(info->fieldset,"Tire ID",raw+4,3*2);
  43. fieldset_add_float(info->fieldset,"Pressure kpa",kpa,2);
  44. fieldset_add_int(info->fieldset,"Temperature C",temp_c,8);
  45. return true;
  46. }
  47. ProtoViewDecoder SchraderEG53MA4TPMSDecoder = {
  48. .name = "Schrader EG53MA4 TPMS",
  49. .decode = decode,
  50. .get_fields = NULL,
  51. .build_message = NULL
  52. };