Bugfixes
[rtl-433.git] / src / devices / mebus.c
1 #include "rtl_433.h"
2 #include "util.h"
3
4 static int mebus433_callback(bitbuffer_t *bitbuffer) {
5     bitrow_t *bb = bitbuffer->bb;
6     char    time_str[LOCAL_TIME_BUFLEN];
7     int16_t temp;
8     int8_t  hum;
9     uint8_t address;
10     uint8_t channel;
11     uint8_t battery;
12     uint8_t unknown1;
13     uint8_t unknown2;
14     data_t *data;
15
16     if (bb[0][0] == 0 && bb[1][4] !=0 && (bb[1][0] & 0b01100000) && bb[1][3]==bb[5][3] && bb[1][4] == bb[12][4]){
17         local_time_str(0, time_str);
18
19         address = bb[1][0] & 0b00011111;
20
21         channel = ((bb[1][1] & 0b00110000) >> 4) + 1;
22         // Always 0?
23         unknown1 = (bb[1][1] & 0b01000000) >> 6;
24         battery = bb[1][1] & 0b10000000;
25
26         // Upper 4 bits are stored in nibble 1, lower 8 bits are stored in nibble 2
27         // upper 4 bits of nibble 1 are reserved for other usages.
28         temp = (int16_t)((uint16_t)(bb[1][1] << 12) | bb[1][2] << 4);
29         temp = temp >> 4;
30         // lower 4 bits of nibble 3 and upper 4 bits of nibble 4 contains
31         // humidity as decimal value
32         hum  = (bb[1][3] << 4 | bb[1][4] >> 4);
33
34         // Always 0b1111?
35         unknown2 = (bb[1][3] & 0b11110000) >> 4;
36
37         data = data_make("time",          "",            DATA_STRING, time_str,
38                          "model",         "",            DATA_STRING, "Mebus/433",
39                          "id",            "Address",     DATA_INT, address,
40                          "battery",       "Battery",     DATA_STRING, battery ? "OK" : "LOW",
41                          "channel",       "Channel",     DATA_INT, channel,
42                          "unknown1",      "Unknown 1",   DATA_INT, unknown1,
43                          "unknown2",      "Unknown 2",   DATA_INT, unknown2,
44                          "temperature_C", "Temperature", DATA_FORMAT, "%.02f C", DATA_DOUBLE, temp / 10.0,
45                          "humidity",      "Humidity",    DATA_FORMAT, "%u %%", DATA_INT, hum,
46                          NULL);
47         data_acquired_handler(data);
48
49
50         return 1;
51     }
52     return 0;
53 }
54
55 r_device mebus433 = {
56     .name           = "Mebus 433",
57     .modulation     = OOK_PULSE_PPM_RAW,
58     .short_limit    = 1200,
59     .long_limit     = 2400,
60     .reset_limit    = 6000,
61     .json_callback  = &mebus433_callback,
62     .disabled       = 0,
63     .demod_arg      = 0,
64 };