Редизайн на основе текущей ветки мейнстрима + новые устройства.
[rtl-433.git] / src / devices / hondaremote.c
1 /* Honda Car Key
2  *
3  * Identifies button event, but does not attempt to decrypt rolling code...
4  *
5  * Copyright (C) 2016 Adrian Stevenson
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11 #include "rtl_433.h"
12 #include "data.h"
13 #include "util.h"
14
15 static const char* command_code[] ={"boot", "unlock" , "lock",};
16
17 static const char* get_command_codes(const uint8_t* bytes) {
18         return command_code[bytes[46] - 0xAA];
19         }
20
21 static int hondaremote_callback(bitbuffer_t *bitbuffer) {
22         bitrow_t *bb = bitbuffer->bb;
23         uint8_t *bytes = bitbuffer->bb[0];
24         char time_str[LOCAL_TIME_BUFLEN];
25         data_t *data;
26         uint16_t device_id;
27
28  for (int i = 0; i < bitbuffer->num_rows; i++)
29 {
30         // Validate package
31                 if (((bitbuffer->bits_per_row[i] >385) && (bitbuffer->bits_per_row[i] <=394)) &&
32          ((bytes[0] == 0xFF ) && (bytes[38] == 0xFF))) 
33          {
34
35         if (debug_output) {
36         fprintf (stdout,"passed validation bits per row %02d\n",(bitbuffer->bits_per_row[i]));
37                         for (unsigned n=40; n<(50); ++n) 
38                                 {
39                                 fprintf(stdout,"Byte %02d", n);
40                                 fprintf(stdout,"= %02X\n", bytes[n]);
41                                 }
42                         }
43
44 //call function to lookup what button was pressed       
45         const char* code = get_command_codes(bytes);
46         device_id = (bytes[44]>>8|bytes[45]);
47         
48  /* Get time now */
49         local_time_str(0, time_str);
50      data = data_make(
51                         "time",         "",     DATA_STRING, time_str,
52                         "model",        "",     DATA_STRING, "Honda Remote",
53                         "device id",    "",    DATA_INT, device_id,
54                         "code",         "",    DATA_STRING, code,
55                       NULL);
56
57        data_acquired_handler(data);
58        return 1;
59         }
60 return 0;
61 }
62 return 0;
63 }
64 static char *output_fields[] = {
65         "time",
66         "model",
67         "device id",
68         "code",
69         NULL
70         };
71
72
73 r_device hondaremote = {
74         .name                   = "Honda Car Key",
75         .modulation             = FSK_PULSE_PWM_RAW,
76         .short_limit    = 300,
77         .long_limit             = 800,  // Not used
78         .reset_limit    = 2000,
79         .json_callback  = &hondaremote_callback,
80         .disabled               = 0,
81         .demod_arg              = 0,
82         .fields         = output_fields 
83 };