LIRC libraries
LinuxInfraredRemoteControl
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Modules 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  const char* filename;
165  const char* tmpfile;
166  const char* backupfile;
167  const char* driver;
168  loglevel_t loglevel;
169  int using_template;
170  char commandline[128];
171 };
172 
173 
175 struct main_state {
176  FILE* fout;
177  struct decode_ctx_t decode_ctx;
178 };
179 
180 
182 struct gap_state {
183  struct lengths* scan;
184  struct lengths* gaps;
185  struct timeval start;
186  struct timeval end;
187  struct timeval last;
188  int flag;
189  int maxcount;
190  int lastmaxcount;
191  lirc_t gap;
192 };
193 
194 
201  int retval;
202  int count;
203  lirc_t data;
204  lirc_t average;
205  lirc_t maxspace;
206  lirc_t sum;
207  lirc_t remaining_gap;
208  lirc_t header;
209  int first_signal;
210  enum analyse_mode mode;
211 };
212 
213 
215 struct toggle_state {
216  struct decode_ctx_t decode_ctx;
217  int retval;
218  int retries;
219  int flag;
220  int success;
221  ir_code first;
222  ir_code last;
223  int seq;
224  int repeats;
225  int found;
226  int inited;
227 };
228 
229 
231 struct button_state {
233  struct ir_ncode ncode;
235  char message[128];
236  int retval;
237  char buffer[BUTTON];
238  char* string;
239  lirc_t data;
240  lirc_t sum;
241  unsigned int count;
242  int flag;
243  int no_data;
244 };
245 
246 
247 // Globals
248 
249 extern struct ir_remote remote;
250 extern unsigned int eps;
251 extern lirc_t aeps;
254 // Functions
255 
257 ssize_t raw_read(void* buffer, size_t size, unsigned int timeout_us);
258 
260 void for_each_remote(struct ir_remote* remotes, remote_func func);
261 
263 void btn_state_set_message(struct button_state* state, const char* fmt, ...);
264 
266 void flushhw(void);
267 
269 void gap_state_init(struct gap_state* state);
270 
272 void lengths_state_init(struct lengths_state* state);
273 
275 void toggle_state_init(struct toggle_state* state);
276 
278 void button_state_init(struct button_state* state);
279 
281 enum get_gap_status get_gap_length(struct gap_state* state,
282  struct ir_remote* remote);
283 
285 enum lengths_status get_lengths(struct lengths_state* state,
286  struct ir_remote* remote,
287  int force,
288  int interactive);
289 
291 void free_all_lengths(void);
292 
294 enum toggle_status
295 get_toggle_bit_mask(struct toggle_state* state, struct ir_remote* remote);
296 
298 int do_analyse(const struct opts* opts, struct main_state* state);
299 
301 enum button_status record_buttons(struct button_state* btn_state,
302  enum button_status last_status,
303  struct main_state* state,
304  const struct opts* opts);
305 
307 void config_file_setup(struct main_state* state, const struct opts* opts);
308 
310 int config_file_finish(struct main_state* state, const struct opts* opts);
311 
313 void get_pre_data(struct ir_remote* remote);
314 
316 void get_post_data(struct ir_remote* remote);
317 
319 void remove_pre_data(struct ir_remote* remote);
320 
322 void remove_post_data(struct ir_remote* remote);
323 
325 void invert_data(struct ir_remote* remote);
326 
328 void remove_trail(struct ir_remote* remote);
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #endif
char message[128]
Definition: irrecord.h:235
Definition: irrecord.h:152
int keypresses
Definition: irrecord.h:200
__u64 ir_code
loglevel_t
Definition: lirc_log.h:36
int keypresses_done
Definition: irrecord.h:198
Main include file for lirc applications.
struct ir_ncode ncode
Definition: irrecord.h:233
Definition: driver.h:83
unsigned int aeps