LIRC libraries
LinuxInfraredRemoteControl
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
irrecord.h
1 /****************************************************************************
2 ** irrecord.h **************************************************************
3 ****************************************************************************
4 *
5 * irrecord.h - base library for irrrecord.
6 *
7 * Copyright (C) 1998,99 Christoph Bartelmus <lirc@bartelmus.de>
8 *
9 */
10 
11 #ifndef IRRECORD_H
12 #define IRRECORD_H
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 #ifdef TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # ifdef HAVE_SYS_TIME_H
24 # include <sys/time.h>
25 # else
26 # include <time.h>
27 # endif
28 #endif
29 
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <getopt.h>
33 #include <limits.h>
34 #include <signal.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <sys/socket.h>
40 #include <sys/stat.h>
41 #include <sys/types.h>
42 #include <sys/un.h>
43 #include <syslog.h>
44 #include <unistd.h>
45 
46 #ifdef HAVE_CONFIG_H
47 # include <config.h>
48 #endif
49 
50 #include "lirc_private.h"
51 
52 
53 #define min(a, b) (a > b ? b : a)
54 #define max(a, b) (a > b ? a : b)
55 
56 #define BUTTON (80 + 1)
57 #define RETRIES 10
58 
59 /* the longest signal I've seen up to now was 48-bit signal with header */
60 #define MAX_SIGNALS 200
61 
62 /* some threshold values */
63 #define TH_SPACE_ENC 80 /* I want less than 20% mismatches */
64 #define TH_HEADER 90
65 #define TH_REPEAT 90
66 #define TH_TRAIL 90
67 #define TH_LEAD 90
68 #define TH_IS_BIT 10
69 #define TH_RC6_SIGNAL 550
70 
71 #define MIN_GAP 20000
72 #define MAX_GAP 100000
73 
74 #define SAMPLES 80
75 
76 // forwards
77 
78 struct ir_remote;
79 struct main_state;
80 struct opts;
81 
82 // type declarations
83 
84 typedef void (*remote_func) (struct ir_remote* remotes);
85 
86 enum analyse_mode { MODE_GET_GAP, MODE_HAVE_GAP };
87 
88 
90 enum lengths_status {
91  STS_LEN_OK,
92  STS_LEN_FAIL,
93  STS_LEN_RAW_OK,
94  STS_LEN_TIMEOUT,
95  STS_LEN_AGAIN,
96  STS_LEN_AGAIN_INFO,
97  STS_LEN_NO_GAP_FOUND,
98  STS_LEN_TOO_LONG,
99 };
100 
101 
103 enum get_gap_status {
104  STS_GAP_INIT,
105  STS_GAP_TIMEOUT,
106  STS_GAP_FOUND,
107  STS_GAP_GOT_ONE_PRESS,
108  STS_GAP_AGAIN
109 };
110 
111 
113 enum toggle_status {
114  STS_TGL_TIMEOUT,
115  STS_TGL_GOT_ONE_PRESS,
116  STS_TGL_NOT_FOUND,
117  STS_TGL_FOUND,
118  STS_TGL_AGAIN
119 };
120 
121 
123 enum button_status {
124  STS_BTN_INIT,
125  STS_BTN_GET_NAME,
126  STS_BTN_INIT_DATA,
127  STS_BTN_GET_RAW_DATA,
128  STS_BTN_GET_DATA,
129  STS_BTN_GET_TOGGLE_BITS,
130  STS_BTN_RECORD_DONE,
131  STS_BTN_BUTTON_DONE,
132  STS_BTN_BUTTONS_DONE,
133  STS_BTN_ALL_DONE,
134  STS_BTN_SOFT_ERROR,
135  STS_BTN_HARD_ERROR,
136  STS_BTN_TIMEOUT,
137 };
138 
139 
140 /* analyse stuff */
141 struct lengths {
142  unsigned int count;
143  lirc_t sum, upper_bound, lower_bound, min, max;
144  struct lengths* next;
145 };
146 
147 
152 struct opts {
153  int dynamic_codes;
154  int analyse;
155  int force;
156  int disable_namespace;
157  const char* device;
158  int get_pre;
159  int get_post;
160  int test;
161  int invert;
162  int trail;
163  int list_namespace;
164  int update;
165  const char* filename;
166  const char* tmpfile;
167  const char* backupfile;
168  const char* driver;
169  loglevel_t loglevel;
170  int using_template;
171  char commandline[128];
172 };
173 
174 
176 struct main_state {
177  FILE* fout;
178  struct decode_ctx_t decode_ctx;
179 };
180 
181 
183 struct gap_state {
184  struct lengths* scan;
185  struct lengths* gaps;
186  struct timeval start;
187  struct timeval end;
188  struct timeval last;
189  int flag;
190  int maxcount;
191  int lastmaxcount;
192  lirc_t gap;
193 };
194 
195 
202  int retval;
203  int count;
204  lirc_t data;
205  lirc_t average;
206  lirc_t maxspace;
207  lirc_t sum;
208  lirc_t remaining_gap;
209  lirc_t header;
210  int first_signal;
211  enum analyse_mode mode;
212 };
213 
214 
216 struct toggle_state {
217  struct decode_ctx_t decode_ctx;
218  int retval;
219  int retries;
220  int flag;
221  int success;
222  ir_code first;
223  ir_code last;
224  int seq;
225  int repeats;
226  int found;
227  int inited;
228 };
229 
230 
232 struct button_state {
234  struct ir_ncode ncode;
236  char message[128];
237  int retval;
238  char buffer[BUTTON];
239  char* string;
240  lirc_t data;
241  lirc_t sum;
242  unsigned int count;
243  int flag;
244  int no_data;
245 };
246 
247 
248 // Globals
249 
250 extern struct ir_remote remote;
251 extern unsigned int eps;
252 extern lirc_t aeps;
255 // Functions
256 
258 ssize_t raw_read(void* buffer, size_t size, unsigned int timeout_us);
259 
261 void for_each_remote(struct ir_remote* remotes, remote_func func);
262 
264 void btn_state_set_message(struct button_state* state, const char* fmt, ...);
265 
267 void flushhw(void);
268 
270 void gap_state_init(struct gap_state* state);
271 
273 void lengths_state_init(struct lengths_state* state);
274 
276 void toggle_state_init(struct toggle_state* state);
277 
279 void button_state_init(struct button_state* state);
280 
282 enum get_gap_status get_gap_length(struct gap_state* state,
283  struct ir_remote* remote);
284 
286 enum lengths_status get_lengths(struct lengths_state* state,
287  struct ir_remote* remote,
288  int force,
289  int interactive);
290 
292 void free_all_lengths(void);
293 
295 enum toggle_status
296 get_toggle_bit_mask(struct toggle_state* state, struct ir_remote* remote);
297 
299 int do_analyse(const struct opts* opts, struct main_state* state);
300 
302 enum button_status record_buttons(struct button_state* btn_state,
303  enum button_status last_status,
304  struct main_state* state,
305  const struct opts* opts);
306 
308 void config_file_setup(struct main_state* state, const struct opts* opts);
309 
311 int config_file_finish(struct main_state* state, const struct opts* opts);
312 
314 void get_pre_data(struct ir_remote* remote);
315 
317 void get_post_data(struct ir_remote* remote);
318 
320 void remove_pre_data(struct ir_remote* remote);
321 
323 void remove_post_data(struct ir_remote* remote);
324 
326 void invert_data(struct ir_remote* remote);
327 
329 void remove_trail(struct ir_remote* remote);
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 #endif
char message[128]
Definition: irrecord.h:236
Definition: irrecord.h:152
int keypresses
Definition: irrecord.h:201
__u64 ir_code
loglevel_t
Definition: lirc_log.h:36
int keypresses_done
Definition: irrecord.h:199
Main include file for lirc applications.
struct ir_ncode ncode
Definition: irrecord.h:234
Definition: driver.h:83
unsigned int aeps