schrader_eg53ma4.c 2.3 KB

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