oregon2.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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,numbits,sync_pattern);
  11. if (off == BITMAP_SEEK_NOT_FOUND) return false;
  12. FURI_LOG_E(TAG, "Oregon2 preamble+sync found");
  13. info->start_off = off;
  14. off += 32; /* Skip preamble. */
  15. uint8_t buffer[8], raw[8] = {0};
  16. uint32_t decoded =
  17. convert_from_line_code(buffer,sizeof(buffer),bits,numbytes,off,"1001","0110");
  18. FURI_LOG_E(TAG, "Oregon2 decoded bits: %lu", decoded);
  19. if (decoded < 11*4) return false; /* Minimum len to extract some data. */
  20. info->pulses_count = (off+11*4*4) - info->start_off;
  21. char temp[3] = {0}, hum[2] = {0};
  22. uint8_t deviceid[2];
  23. for (int j = 0; j < 64; j += 4) {
  24. uint8_t nib[1];
  25. nib[0] = (bitmap_get(buffer,8,j+0) |
  26. bitmap_get(buffer,8,j+1) << 1 |
  27. bitmap_get(buffer,8,j+2) << 2 |
  28. bitmap_get(buffer,8,j+3) << 3);
  29. if (DEBUG_MSG) FURI_LOG_E(TAG, "Not inverted nibble[%d]: %x", j/4, (unsigned int)nib[0]);
  30. raw[j/8] |= nib[0] << (4-(j%4));
  31. switch(j/4) {
  32. case 1: deviceid[0] |= nib[0]; break;
  33. case 0: deviceid[0] |= nib[0] << 4; break;
  34. case 3: deviceid[1] |= nib[0]; break;
  35. case 2: deviceid[1] |= nib[0] << 4; break;
  36. case 10: temp[0] = nib[0]; break;
  37. /* Fixme: take the temperature sign from nibble 11. */
  38. case 9: temp[1] = nib[0]; break;
  39. case 8: temp[2] = nib[0]; break;
  40. case 13: hum[0] = nib[0]; break;
  41. case 12: hum[1] = nib[0]; break;
  42. }
  43. }
  44. float tempval = ((temp[0]-'0')*10) +
  45. (temp[1]-'0') +
  46. ((float)(temp[2]-'0')*0.1);
  47. int humval = (hum[0]-'0')*10 + (hum[1]-'0');
  48. fieldset_add_bytes(info->fieldset,"Sensor ID",deviceid,4);
  49. fieldset_add_float(info->fieldset,"Temperature",tempval,1);
  50. fieldset_add_uint(info->fieldset,"Humidity",humval,7);
  51. return true;
  52. }
  53. ProtoViewDecoder Oregon2Decoder = {
  54. .name = "Oregon2",
  55. .decode = decode,
  56. .get_fields = NULL,
  57. .build_message = NULL
  58. };