b4b1.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* PT/SC remotes. Usually 443.92 Mhz OOK.
  2. *
  3. * This line code is used in many remotes such as Princeton chips
  4. * named PT2262, Silian Microelectronics SC5262 and others.
  5. * Basically every 4 pulsee represent a bit, where 1000 means 0, and
  6. * 1110 means 1. Usually we can read 24 bits of data.
  7. * In this specific implementation we check for a prelude that is
  8. * 1 bit high, 31 bits low, but the check is relaxed. */
  9. #include "../app.h"
  10. static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
  11. if (numbits < 30) return false;
  12. const char *sync_patterns[3] = {
  13. "10000000000000000000000000000001", /* 30 zero bits. */
  14. "100000000000000000000000000000001", /* 31 zero bits. */
  15. "1000000000000000000000000000000001", /* 32 zero bits. */
  16. };
  17. uint32_t off, start;
  18. int j;
  19. for (j = 0; j < 3; j++) {
  20. off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_patterns[j]);
  21. if (off != BITMAP_SEEK_NOT_FOUND) break;
  22. }
  23. if (off == BITMAP_SEEK_NOT_FOUND) return false;
  24. if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 preamble at: %lu",off);
  25. start = off;
  26. off += strlen(sync_patterns[j])-1;
  27. uint8_t d[3]; /* 24 bits of data. */
  28. uint32_t decoded =
  29. convert_from_line_code(d,sizeof(d),bits,numbytes,off,"1000","1110");
  30. if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 decoded: %lu",decoded);
  31. if (decoded != 24) return false;
  32. snprintf(info->name,PROTOVIEW_MSG_STR_LEN,"PT/SC remote");
  33. snprintf(info->raw,PROTOVIEW_MSG_STR_LEN,"%02X%02X%02X",d[0],d[1],d[2]);
  34. info->start_off = start;
  35. info->pulses_len = 4*24;
  36. return true;
  37. }
  38. ProtoViewDecoder B4B1Decoder = {
  39. "B4B1", decode
  40. };