7 static int rev_nibble(int nib)
11 revnib += (nib >> 3) & 0x1;
12 revnib += (nib >> 1) & 0x2;
13 revnib += (nib << 1) & 0x4;
14 revnib += (nib << 3) & 0x8;
19 static int oregon_scientific_callback_v1(bitbuffer_t *bitbuffer) {
21 char time_str[LOCAL_TIME_BUFLEN];
25 int nibble[OSV1_BITS/4];
26 int sid, channel, uk1;
28 int battery, uk2, sign, uk3, checksum;
31 local_time_str(0, time_str);
33 for(row = 0; row < bitbuffer->num_rows; row++) {
34 if(bitbuffer->bits_per_row[row] == OSV1_BITS) {
36 for(i = 0; i < OSV1_BITS / 8; i++) {
37 nibble[i * 2 ] = rev_nibble((bitbuffer->bb[row][i] >> 4));
38 nibble[i * 2 + 1] = rev_nibble((bitbuffer->bb[row][i] & 0x0f));
39 if(i < ((OSV1_BITS / 8) - 1))
40 cs += nibble[i * 2] + 16 * nibble[i * 2 + 1];
42 cs = (cs & 0xFF) + (cs >> 8);
43 checksum = nibble[6] + (nibble[7] << 4);
46 channel = ((nibble[1] >> 2) & 0x03) + 1;
47 uk1 = (nibble[1] >> 0) & 0x03; /* unknown. Seen change every 60 minutes */
48 tempC = nibble[2] / 10. + nibble[3] + nibble[4] * 10.;
49 battery = (nibble[5] >> 3) & 0x01;
50 uk2 = (nibble[5] >> 2) & 0x01; /* unknown. Always zero? */
51 sign = (nibble[5] >> 1) & 0x01;
52 uk3 = (nibble[5] >> 0) & 0x01; /* unknown. Always zero? */
54 if(sign) tempC = -tempC;
57 "time", "", DATA_STRING, time_str,
58 "model", "", DATA_STRING, "OSv1 Temperature Sensor",
59 "sid", "SID", DATA_INT, sid,
60 "channel", "Channel", DATA_INT, channel,
61 "battery", "Battery", DATA_STRING, battery ? "LOW" : "OK",
62 "temperature_C","Temperature", DATA_FORMAT, "%.01f C", DATA_DOUBLE, tempC,
64 data_acquired_handler(data);
72 static char *output_fields[] = {
82 r_device oregon_scientific_v1 = {
83 .name = "OSv1 Temperature Sensor",
84 .modulation = OOK_PULSE_PWM_OSV1,
88 .json_callback = &oregon_scientific_callback_v1,
91 .fields = output_fields