oregon2.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Oregon remote termometers. Usually 443.92 Mhz OOK.
  2. *
  3. * The protocol is described here:
  4. * https://wmrx00.sourceforge.net/Arduino/OregonScientific-RF-Protocols.pdf
  5. * This implementation is not very complete. */
  6. #include "../app.h"
  7. static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
  8. if (numbits < 32) return false;
  9. const char *sync_pattern = "01100110" "01100110" "10010110" "10010110";
  10. uint64_t off = bitmap_seek_bits(bits,numbytes,0,sync_pattern);
  11. if (off == BITMAP_SEEK_NOT_FOUND) return false;
  12. FURI_LOG_E(TAG, "Oregon2 preamble+sync found");
  13. off += 32; /* Skip preamble. */
  14. uint8_t buffer[8], raw[8] = {0};
  15. uint32_t decoded =
  16. convert_from_line_code(buffer,sizeof(buffer),bits,numbytes,off,"1001","0110");
  17. FURI_LOG_E(TAG, "Oregon2 decoded bits: %lu", decoded);
  18. if (decoded < 11*4) return false; /* Minimum len to extract some data. */
  19. char temp[3] = {0}, deviceid[2] = {0}, hum[2] = {0};
  20. for (int j = 0; j < 64; j += 4) {
  21. uint8_t nib[1];
  22. nib[0] = (bitmap_get(buffer,8,j+0) |
  23. bitmap_get(buffer,8,j+1) << 1 |
  24. bitmap_get(buffer,8,j+2) << 2 |
  25. bitmap_get(buffer,8,j+3) << 3);
  26. if (DEBUG_MSG) FURI_LOG_E(TAG, "Not inverted nibble[%d]: %x", j/4, (unsigned int)nib[0]);
  27. raw[j/8] |= nib[0] << (4-(j%4));
  28. switch(j/4) {
  29. case 1: deviceid[0] |= nib[0]; break;
  30. case 0: deviceid[0] |= nib[0] << 4; break;
  31. case 3: deviceid[1] |= nib[0]; break;
  32. case 2: deviceid[1] |= nib[0] << 4; break;
  33. case 10: temp[0] = nib[0]; break;
  34. /* Fixme: take the temperature sign from nibble 11. */
  35. case 9: temp[1] = nib[0]; break;
  36. case 8: temp[2] = nib[0]; break;
  37. case 13: hum[0] = nib[0]; break;
  38. case 12: hum[1] = nib[0]; break;
  39. }
  40. }
  41. snprintf(info->name,sizeof(info->name),"%s","Oregon v2.1");
  42. /* The following line crashes the Flipper because of broken
  43. * snprintf() implementation. */
  44. snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X",
  45. raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
  46. raw[6],raw[7]);
  47. snprintf(info->info1,sizeof(info->info1),"Sensor ID %02X%02X",
  48. deviceid[0], deviceid[1]);
  49. snprintf(info->info2,sizeof(info->info2),"Temperature %d%d.%d",
  50. temp[0],temp[1],temp[2]);
  51. snprintf(info->info3,sizeof(info->info3),"Humidity %d%d",
  52. hum[0],hum[1]);
  53. return true;
  54. }
  55. ProtoViewDecoder Oregon2Decoder = {
  56. "Oregon2", decode
  57. };