schrader_eg53ma4.c 2.3 KB

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