Bugfixes
[rtl-433.git] / src / devices / akhan_100F14.c
1 /* Akhan remote keyless entry system
2 *
3 *       This RKE system uses a HS1527 OTP encoder (http://sc-tech.cn/en/hs1527.pdf)
4 *       Each message consists of a preamble, 20 bit id and 4 data bits.
5 *
6 *       (code based on chuango.c and generic_remote.c)
7 */
8 #include "rtl_433.h"
9 #include "pulse_demod.h"
10 #include "util.h"
11 #include "data.h"
12
13 static int akhan_rke_callback(bitbuffer_t *bitbuffer) {
14         bitrow_t *bb = bitbuffer->bb;
15         uint8_t *b = bb[0];
16         
17         //invert bits, short pulse is 0, long pulse is 1
18         b[0] = ~b[0];
19         b[1] = ~b[1];
20         b[2] = ~b[2];
21
22         unsigned bits = bitbuffer->bits_per_row[0];
23
24         if (bits == 25) {
25                 char time_str[LOCAL_TIME_BUFLEN];
26                 local_time_str(0, time_str);
27                 data_t *data;
28
29                 uint32_t ID = (b[0] << 12) | (b[1] << 4) | (b[2] >> 4);
30                 uint32_t dataBits = b[2] & 0x0F;
31                 int isAkhan = 1;
32                 char *CMD;
33
34                 switch (dataBits) {
35                         case 0x1:       CMD = "0x1 (Lock)"; break;
36                         case 0x2:       CMD = "0x2 (Unlock)"; break;
37                         case 0x4:       CMD = "0x4 (Mute)"; break;
38                         case 0x8:       CMD = "0x8 (Alarm)"; break;
39                         default:
40                                 isAkhan = 0;
41                                 break;
42                 }
43
44                 if (isAkhan == 1) {
45                         data = data_make(       "time",         "",                             DATA_STRING,    time_str,
46                                                                         "device",       "",                             DATA_STRING,    "Akhan 100F14 remote keyless entry",
47                                                                         "id",                   "ID (20bit)",   DATA_FORMAT,    "0x%x",         DATA_INT, ID,
48                                                                         "data",         "Data (4bit)",  DATA_STRING,    CMD,
49                                                                         NULL);
50
51                         data_acquired_handler(data);
52                         return 1;
53                 }
54
55         }
56         return 0;
57 }
58
59 static char *output_fields[] = {
60     "time",
61     "device",
62     "id",
63     "data",
64     "other",
65     NULL
66 };
67
68 PWM_Precise_Parameters pwm_precise_parameters_akhan = {
69         .pulse_tolerance        = 20,
70         .pulse_sync_width       = 0,
71 };
72
73 r_device akhan_100F14 = {
74         .name          = "Akhan 100F14 remote keyless entry",
75         .modulation    = OOK_PULSE_PWM_PRECISE, 
76         .short_limit   = 316,
77         .long_limit    = 1020,
78         .reset_limit   = 1800,
79         .json_callback = &akhan_rke_callback,
80         .disabled      = 0,
81         .demod_arg     = (uintptr_t)&pwm_precise_parameters_akhan,
82 };