Редизайн на основе текущей ветки мейнстрима + новые устройства.
[rtl-433.git] / src / devices / rftech.c
1 /* RF-tech decoder
2  * Also marked INFRA 217S34
3  * Ewig Industries Macao
4  *
5  * Copyright © 2016 Erik Johannessen
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  */
12
13
14 #include "rtl_433.h"
15 #include "pulse_demod.h"
16 #include "util.h"
17
18
19 static int rftech_callback(bitbuffer_t *bitbuffer) {
20     char time_str[LOCAL_TIME_BUFLEN];
21     bitrow_t *bb = bitbuffer->bb;
22     uint16_t sensor_id = 0;
23     uint8_t button;
24     uint8_t battery;
25     double value;
26     data_t *data;
27     int r;
28
29     local_time_str(0, time_str);
30
31     r = bitbuffer_find_repeated_row(bitbuffer, 3, 24);
32
33     if(r >= 0 && bitbuffer->bits_per_row[r] == 24) {
34         /* Example of message:
35          * 01001001 00011010 00000100
36          *
37          * First byte is unknown, but probably id.
38          * Second byte is the integer part of the temperature.
39          * Third byte bits 0-3 is the fraction/tenths of the temperature.
40          * Third byte bit 7 is 1 with fresh batteries.
41          * Third byte bit 6 is 1 on button press.
42          *
43          * More sample messages:
44          * {24} ad 18 09 : 10101101 00011000 00001001
45          * {24} 3e 17 09 : 00111110 00010111 00001001
46          * {24} 70 17 03 : 01110000 00010111 00000011
47          * {24} 09 17 01 : 00001001 00010111 00000001
48          *
49          * With fresh batteries and button pressed:
50          * {24} c5 16 c5 : 11000101 00010110 11000101
51          *
52          */
53         sensor_id = bb[r][0];
54         value = (bb[r][1] & 0x7f) + (bb[r][2] & 0x0f) / 10.0;
55         if(bb[r][1] & 0x80) value = -value;
56
57         battery = (bb[r][2] & 0x80) == 0x80;
58         button = (bb[r][2] & 0x60) != 0;
59
60         data = data_make("time", "", DATA_STRING, time_str,
61                          "model", "", DATA_STRING, "RF-tech",
62                          "id", "Id", DATA_INT, sensor_id,
63                          "battery", "Battery", DATA_STRING, battery ? "OK" : "LOW",
64                          "button", "Button", DATA_INT, button,
65                          "temperature", "Temperature", DATA_FORMAT, "%.01f C", DATA_DOUBLE, value,
66                          NULL);
67
68         data_acquired_handler(data);
69
70         return 1;
71     }
72
73     return 0;
74 }
75
76 /*
77  * List of fields to output when using CSV
78  *
79  * Used to determine what fields will be output in what
80  * order for this devince when using -F csv.
81  *
82  */
83 static char *csv_output_fields[] = {
84         "time",
85         "model",
86         "id",
87         "battery",
88         "button",
89         "temperature",
90         NULL
91 };
92
93 /*
94  * r_device - registers device/callback. see rtl_433_devices.h
95  *
96  */
97
98 r_device rftech = {
99         .name           = "RF-tech",
100         .modulation     = OOK_PULSE_PPM_RAW,
101         .short_limit    = 3500,
102         .long_limit     = 5000,
103         .reset_limit    = 10000,
104         .json_callback  = &rftech_callback,
105         .disabled       = 1,
106         .demod_arg      = 0,
107         .fields         = csv_output_fields,
108 };