| LIRC libraries LinuxInfraredRemoteControl

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 int started_as_root;
180 };
181
182
184 struct gap_state {
185 struct lengths* scan;
186 struct lengths* gaps;
187 struct timeval start;
188 struct timeval end;
189 struct timeval last;
190 int flag;
191 int maxcount;
192 int lastmaxcount;
193 lirc_t gap;
194 };
195
196
198 struct lengths_state {
200 int keypresses_done;
202 int keypresses;
203 int retval;
205 int count;
206 lirc_t data;
207 lirc_t average;
208 lirc_t maxspace;
210 lirc_t sum;
211 lirc_t remaining_gap;
212 lirc_t header;
213 int first_signal;
214 enum analyse_mode mode;
215 };
216
217
219 struct toggle_state {
220 struct decode_ctx_t decode_ctx;
221 int retval;
222 int retries;
223 int flag;
224 int success;
225 ir_code first;
226 ir_code last;
227 int seq;
228 int repeats;
229 int found;
230 int inited;
231 };
232
233
235 struct button_state {
237 struct ir_ncode ncode;
239 char message[128];
240 int retval;
241 char buffer[BUTTON];
242 char* string;
243 lirc_t data;
244 lirc_t sum;
245 unsigned int count;
246 int flag;
247 int no_data;
248 int started_as_root;
249 };
250
251
252 // Globals
253
254 extern struct ir_remote remote;
255 extern unsigned int eps;
256 extern lirc_t aeps;
259 // Functions
260
262 ssize_t raw_read(void* buffer, size_t size, unsigned int timeout_us);
263
265 void for_each_remote(struct ir_remote* remotes, remote_func func);
266
268 void btn_state_set_message(struct button_state* state, const char* fmt, ...);
269
271 void flushhw(void);
272
274 void gap_state_init(struct gap_state* state);
275
277 void lengths_state_init(struct lengths_state* state);
278
280 void toggle_state_init(struct toggle_state* state);
281
283 void button_state_init(struct button_state* state, int started_as_root);
284
286 enum get_gap_status get_gap_length(struct gap_state* state,
287 struct ir_remote* remote);
288
290 enum lengths_status get_lengths(struct lengths_state* state,
291 struct ir_remote* remote,
292 int force,
293 int interactive);
294
296 void free_all_lengths(void);
297
299 enum toggle_status
300 get_toggle_bit_mask(struct toggle_state* state, struct ir_remote* remote);
301
303 int do_analyse(const struct opts* opts, struct main_state* state);
304
306 enum button_status record_buttons(struct button_state* btn_state,
307 enum button_status last_status,
308 struct main_state* state,
309 const struct opts* opts);
310
312 void config_file_setup(struct main_state* state, const struct opts* opts);
313
315 int config_file_finish(struct main_state* state, const struct opts* opts);
316
318 void get_pre_data(struct ir_remote* remote);
319
321 void get_post_data(struct ir_remote* remote);
322
324 void remove_pre_data(struct ir_remote* remote);
325
327 void remove_post_data(struct ir_remote* remote);
328
330 void invert_data(struct ir_remote* remote);
331
333 void remove_trail(struct ir_remote* remote);
334
335 #ifdef __cplusplus
336 }
337 #endif
338
339 #endif
ir_remote
Definition: ir_remote_types.h:167
toggle_state
Definition: irrecord.h:219
opts
Definition: irrecord.h:152
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
ir_remote::eps
int eps
Definition: ir_remote_types.h:173
lengths_state::keypresses
int keypresses
Definition: irrecord.h:202
gap_state
Definition: irrecord.h:184
button_state
Definition: irrecord.h:235
ir_code
__u64 ir_code
Definition: ir_remote_types.h:59
loglevel_t
loglevel_t
Definition: lirc_log.h:36
lengths_state::keypresses_done
int keypresses_done
Definition: irrecord.h:200
lirc_private.h
Main include file for lirc applications.
lengths_state::sum
lirc_t sum
Definition: irrecord.h:210
driver
Definition: driver.h:127
main_state
Definition: irrecord.h:176
ir_ncode
Definition: ir_remote_types.h:76
lengths
Definition: irrecord.h:141
ir_remote::aeps
unsigned int aeps
Definition: ir_remote_types.h:174
decode_ctx_t
Definition: ir_remote_types.h:154
lengths_state::count
int count
Definition: irrecord.h:205
lengths_state
Definition: irrecord.h:198