LIRC libraries LinuxInfraredRemoteControl

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

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
197 struct lengths_state {
199 int keypresses_done;
201 int keypresses;
202 int retval;
204 int count;
205 lirc_t data;
206 lirc_t average;
207 lirc_t maxspace;
209 lirc_t sum;
210 lirc_t remaining_gap;
211 lirc_t header;
212 int first_signal;
213 enum analyse_mode mode;
214 };
215
216
218 struct toggle_state {
219 struct decode_ctx_t decode_ctx;
220 int retval;
221 int retries;
222 int flag;
223 int success;
224 ir_code first;
225 ir_code last;
226 int seq;
227 int repeats;
228 int found;
229 int inited;
230 };
231
232
234 struct button_state {
236 struct ir_ncode ncode;
238 char message[128];
239 int retval;
240 char buffer[BUTTON];
241 char* string;
242 lirc_t data;
243 lirc_t sum;
244 unsigned int count;
245 int flag;
246 int no_data;
247 };
248
249
250 // Globals
251
252 extern struct ir_remote remote;
253 extern unsigned int eps;
254 extern lirc_t aeps;
257 // Functions
258
260 ssize_t raw_read(void* buffer, size_t size, unsigned int timeout_us);
261
263 void for_each_remote(struct ir_remote* remotes, remote_func func);
264
266 void btn_state_set_message(struct button_state* state, const char* fmt, ...);
267
269 void flushhw(void);
270
272 void gap_state_init(struct gap_state* state);
273
275 void lengths_state_init(struct lengths_state* state);
276
278 void toggle_state_init(struct toggle_state* state);
279
281 void button_state_init(struct button_state* state);
282
284 enum get_gap_status get_gap_length(struct gap_state* state,
285 struct ir_remote* remote);
286
288 enum lengths_status get_lengths(struct lengths_state* state,
289 struct ir_remote* remote,
290 int force,
291 int interactive);
292
294 void free_all_lengths(void);
295
297 enum toggle_status
298 get_toggle_bit_mask(struct toggle_state* state, struct ir_remote* remote);
299
301 int do_analyse(const struct opts* opts, struct main_state* state);
302
304 enum button_status record_buttons(struct button_state* btn_state,
305 enum button_status last_status,
306 struct main_state* state,
307 const struct opts* opts);
308
310 void config_file_setup(struct main_state* state, const struct opts* opts);
311
313 int config_file_finish(struct main_state* state, const struct opts* opts);
314
316 void get_pre_data(struct ir_remote* remote);
317
319 void get_post_data(struct ir_remote* remote);
320
322 void remove_pre_data(struct ir_remote* remote);
323
325 void remove_post_data(struct ir_remote* remote);
326
328 void invert_data(struct ir_remote* remote);
329
331 void remove_trail(struct ir_remote* remote);
332
333 #ifdef __cplusplus
334 }
335 #endif
336
337 #endif
ir_remote
Definition: ir_remote_types.h:163
button_state::message
char message[128]
Definition: irrecord.h:238
toggle_state
Definition: irrecord.h:218
opts
Definition: irrecord.h:152
ir_remote::eps
int eps
Definition: ir_remote_types.h:169
lengths_state::keypresses
int keypresses
Definition: irrecord.h:201
gap_state
Definition: irrecord.h:183
button_state
Definition: irrecord.h:234
ir_code
__u64 ir_code
Definition: ir_remote_types.h:55
loglevel_t
loglevel_t
Definition: lirc_log.h:36
lengths_state::keypresses_done
int keypresses_done
Definition: irrecord.h:199
lirc_private.h
Main include file for lirc applications.
button_state::ncode
struct ir_ncode ncode
Definition: irrecord.h:236
lengths_state::sum
lirc_t sum
Definition: irrecord.h:209
driver
Definition: driver.h:83
main_state
Definition: irrecord.h:176
ir_ncode
Definition: ir_remote_types.h:72
lengths
Definition: irrecord.h:141
ir_remote::aeps
unsigned int aeps
Definition: ir_remote_types.h:170
decode_ctx_t
Definition: ir_remote_types.h:150
lengths_state::count
int count
Definition: irrecord.h:204
lengths_state
Definition: irrecord.h:197