- Merged with upstream version
[rtl-433.git] / src / devices / prologue.c~
1 /* Prologue sensor protocol
2  *
3  * the sensor sends 36 bits 7 times, before the first packet there is a pulse sent
4  * the packets are pwm modulated
5  *
6  * the data is grouped in 9 nibles
7  * [id0] [rid0] [rid1] [data0] [temp0] [temp1] [temp2] [humi0] [humi1]
8  *
9  * id0 is always 1001,9
10  * rid is a random id that is generated when the sensor starts, could include battery status
11  * the same batteries often generate the same id
12  * data(3) is 0 the battery status, 1 ok, 0 low, first reading always say low
13  * data(2) is 1 when the sensor sends a reading when pressing the button on the sensor
14  * data(1,0)+1 forms the channel number that can be set by the sensor (1-3)
15  * temp is 12 bit signed scaled by 10
16  * humi0 is always 1100,c if no humidity sensor is available
17  * humi1 is always 1100,c if no humidity sensor is available
18  *
19  * The sensor can be bought at Clas Ohlson
20  */
21 #include "rtl_433.h"
22
23 static int prologue_callback(uint8_t bb[BITBUF_ROWS][BITBUF_COLS],int16_t bits_per_row[BITBUF_ROWS]) {
24     int rid;
25
26     int16_t temp2;
27
28     /* FIXME validate the received message better */
29     if (((bb[1][0]&0xF0) == 0x90 && (bb[2][0]&0xF0) == 0x90 && (bb[3][0]&0xF0) == 0x90 && (bb[4][0]&0xF0) == 0x90 &&
30         (bb[5][0]&0xF0) == 0x90 && (bb[6][0]&0xF0) == 0x90) ||
31         ((bb[1][0]&0xF0) == 0x50 && (bb[2][0]&0xF0) == 0x50 && (bb[3][0]&0xF0) == 0x50 && (bb[4][0]&0xF0) == 0x50) &&
32         (bb[1][3] == bb[2][3]) && (bb[1][4] == bb[2][4])) {
33
34         /* Prologue sensor */
35         temp2 = (int16_t)((uint16_t)(bb[1][2] << 8) | (bb[1][3]&0xF0));
36         temp2 = temp2 >> 4;
37         fprintf(stderr, "Sensor temperature event:\n");
38         fprintf(stderr, "protocol      = Prologue, %d bits\n",bits_per_row[1]);
39         fprintf(stderr, "button        = %d\n",bb[1][1]&0x04?1:0);
40         fprintf(stderr, "battery       = %s\n",bb[1][1]&0x08?"Ok":"Low");
41         fprintf(stderr, "temp          = %s%d.%d\n",temp2<0?"-":"",abs((int16_t)temp2/10),abs((int16_t)temp2%10));
42         fprintf(stderr, "humidity      = %d\n", ((bb[1][3]&0x0F)<<4)|(bb[1][4]>>4));
43         fprintf(stderr, "channel       = %d\n",(bb[1][1]&0x03)+1);
44         fprintf(stderr, "id            = %d\n",(bb[1][0]&0xF0)>>4);
45         rid = ((bb[1][0]&0x0F)<<4)|(bb[1][1]&0xF0)>>4;
46         fprintf(stderr, "rid           = %d\n", rid);
47         fprintf(stderr, "hrid          = %02x\n", rid);
48
49         fprintf(stderr, "%02x %02x %02x %02x %02x\n",bb[1][0],bb[1][1],bb[1][2],bb[1][3],bb[1][4]);
50
51         if (debug_output)
52             debug_callback(bb, bits_per_row);
53
54         return 1;
55     }
56     return 0;
57 }
58
59 r_device prologue = {
60     /* .id             = */ 2,
61     /* .name           = */ "Prologue Temperature Sensor",
62     /* .modulation     = */ OOK_PWM_D,
63     /* .short_limit    = */ 3500/4,
64     /* .long_limit     = */ 7000/4,
65     /* .reset_limit    = */ 15000/4,
66     /* .json_callback  = */ &prologue_callback,
67 };