Bugfixes
[rtl-433.git] / src / devices / tfa_pool_thermometer.c
1 /* TFA pool temperature sensor
2  *
3  * Copyright (C) 2015 Alexandre Coffignal
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  */
10 #include "data.h"
11 #include "rtl_433.h"
12 #include "util.h"
13
14
15 static int pool_temperature_sensor_callback(bitbuffer_t *bitbuffer) {
16         bitrow_t *bb = bitbuffer->bb;
17         data_t *data;
18         char time_str[LOCAL_TIME_BUFLEN];
19     local_time_str(0, time_str);
20         int i,device,channel;
21         int iTemp;
22         float fTemp;
23
24
25         for(i=1;i<8;i++){
26                 if(bitbuffer->bits_per_row[i]!=28){
27                         /*10 24 bits frame*/
28                         return 0;
29                 }
30         }
31
32 /*
33 AAAABBBB BBBBCCCC CCCCCCCC DDEE
34
35 A: ?
36 B: device id (changing only after reset)
37 C: templerature
38 D: channel number
39 E: ?
40 */
41
42         device=(((bb[1][0]&0xF)<<4)+((bb[1][1]&0xF0)>>4));
43         iTemp=((bb[1][1]&0xF)<<8)+bb[1][2];
44         fTemp=(iTemp > 2048 ? iTemp - 4096 : iTemp) / 10.0;
45         channel=(signed short)((bb[1][3]&0xC0)>>6);
46
47         data = data_make("time",        "",                     DATA_STRING,                                    time_str,
48                      "model",           "",                     DATA_STRING,    "TFA pool temperature sensor",
49                      "id",              "Id",                   DATA_FORMAT,    "\t %d",        DATA_INT,       device,
50                      "channel",         "Channel number",       DATA_FORMAT,    "\t %d",        DATA_INT,       channel,
51                      "temperature_C",   "Temperature",          DATA_FORMAT,    "%.01f C",      DATA_DOUBLE,    fTemp,
52                      NULL);
53     data_acquired_handler(data);
54         
55     return 1; 
56         
57 }
58
59 static char *output_fields[] = {
60         "time",
61         "model",
62         "id",
63         "channel",
64         "temperature_C",
65         NULL
66 };
67
68 r_device tfa_pool_thermometer = {
69
70   .name          = "TFA pool temperature sensor",
71   .modulation    = OOK_PULSE_PPM_RAW,
72   .short_limit   = 3500,
73   .long_limit    = 7800,
74   .reset_limit   = 10000,
75   .json_callback = &pool_temperature_sensor_callback,
76   .disabled      = 0,
77   .demod_arg     = 0,
78   .fields        = output_fields,
79 };
80