LIRC libraries Linux Infrared Remote Control

Loading...
Searching...
No Matches
irrecord.h
Go to the documentation of this file.
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
16#ifndef IRRECORD_H
17#define IRRECORD_H
18
19#ifdef __cplusplus
20 extern "C" {
21#endif
22
23
24#ifdef TIME_WITH_SYS_TIME
25# include <sys/time.h>
26# include <time.h>
27#else
28# ifdef HAVE_SYS_TIME_H
29# include <sys/time.h>
30# else
31# include <time.h>
32# endif
33#endif
34
35#include <errno.h>
36#include <fcntl.h>
37#include <getopt.h>
38#include <limits.h>
39#include <signal.h>
40#include <stdarg.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <sys/socket.h>
45#include <sys/stat.h>
46#include <sys/types.h>
47#include <sys/un.h>
48#include <syslog.h>
49#include <unistd.h>
50
51#include "lirc_private.h"
52
53
54#define min(a, b) (a > b ? b : a)
55#define max(a, b) (a > b ? a : b)
56
57#define BUTTON (80 + 1)
58#define RETRIES 10
59
60/* the longest signal I've seen up to now was 48-bit signal with header */
61#define MAX_SIGNALS 200
62
63/* some threshold values */
64#define TH_SPACE_ENC 80 /* I want less than 20% mismatches */
65#define TH_HEADER 90
66#define TH_REPEAT 90
67#define TH_TRAIL 90
68#define TH_LEAD 90
69#define TH_IS_BIT 10
70#define TH_RC6_SIGNAL 550
71
72#define MIN_GAP 20000
73#define MAX_GAP 100000
74
75#define SAMPLES 80
76
77// forwards
78
79 struct ir_remote;
80 struct main_state;
81 struct opts;
82
83// type declarations
84
85 typedef void (*remote_func) (struct ir_remote* remotes);
86
87 enum analyse_mode { MODE_GET_GAP, MODE_HAVE_GAP };
88
89
91 enum lengths_status {
92 STS_LEN_OK,
93 STS_LEN_FAIL,
94 STS_LEN_RAW_OK,
95 STS_LEN_TIMEOUT,
96 STS_LEN_AGAIN,
97 STS_LEN_AGAIN_INFO,
98 STS_LEN_NO_GAP_FOUND,
99 STS_LEN_TOO_LONG,
100};
101
102
104 enum get_gap_status {
105 STS_GAP_INIT,
106 STS_GAP_TIMEOUT,
107 STS_GAP_FOUND,
108 STS_GAP_GOT_ONE_PRESS,
109 STS_GAP_AGAIN
110};
111
112
114 enum toggle_status {
115 STS_TGL_TIMEOUT,
116 STS_TGL_GOT_ONE_PRESS,
117 STS_TGL_NOT_FOUND,
118 STS_TGL_FOUND,
119 STS_TGL_AGAIN
120};
121
122
124 enum button_status {
125 STS_BTN_INIT,
126 STS_BTN_GET_NAME,
127 STS_BTN_INIT_DATA,
128 STS_BTN_GET_RAW_DATA,
129 STS_BTN_GET_DATA,
130 STS_BTN_GET_TOGGLE_BITS,
131 STS_BTN_RECORD_DONE,
132 STS_BTN_BUTTON_DONE,
133 STS_BTN_BUTTONS_DONE,
134 STS_BTN_ALL_DONE,
135 STS_BTN_SOFT_ERROR,
136 STS_BTN_HARD_ERROR,
137 STS_BTN_TIMEOUT,
138};
139
140
141/* analyse stuff */
142 struct lengths {
143 unsigned int count;
144 lirc_t sum, upper_bound, lower_bound, min, max;
145 struct lengths* next;
146};
147
148
153 struct opts {
154 int dynamic_codes;
155 int analyse;
156 int force;
157 int disable_namespace;
158 const char* device;
159 int get_pre;
160 int get_post;
161 int test;
162 int invert;
163 int trail;
164 int list_namespace;
165 int update;
166 const char* filename;
167 const char* tmpfile;
168 const char* backupfile;
169 const char* driver;
170 loglevel_t loglevel;
171 int using_template;
172 char commandline[128];
173};
174
175
177 struct main_state {
178 FILE* fout;
179 struct decode_ctx_t decode_ctx;
180 int started_as_root;
181};
182
183
185 struct gap_state {
186 struct lengths* scan;
187 struct lengths* gaps;
188 struct timeval start;
189 struct timeval end;
190 struct timeval last;
191 int flag;
192 int maxcount;
193 int lastmaxcount;
194 lirc_t gap;
195};
196
197
199 struct lengths_state {
201 int keypresses_done;
203 int keypresses;
204 int retval;
206 int count;
207 lirc_t data;
208 lirc_t average;
209 lirc_t maxspace;
211 lirc_t sum;
212 lirc_t remaining_gap;
213 lirc_t header;
214 int first_signal;
215 enum analyse_mode mode;
216};
217
218
220 struct toggle_state {
221 struct decode_ctx_t decode_ctx;
222 int retval;
223 int retries;
224 int flag;
225 int success;
226 ir_code first;
227 ir_code last;
228 int seq;
229 int repeats;
230 int found;
231 int inited;
232};
233
234
236 struct button_state {
238 struct ir_ncode ncode;
240 char message[128];
241 int retval;
242 char buffer[BUTTON];
243 char* string;
244 lirc_t data;
245 lirc_t sum;
246 unsigned int count;
247 int flag;
248 int no_data;
249 int started_as_root;
250};
251
252
253// Globals
254
255 extern struct ir_remote remote;
256 extern unsigned int eps;
257 extern lirc_t aeps;
260// Functions
261
263ssize_t raw_read(void* buffer, size_t size, unsigned int timeout_us);
264
266 void for_each_remote(struct ir_remote* remotes, remote_func func);
267
269 void btn_state_set_message(struct button_state* state, const char* fmt, ...);
270
272 void flushhw(void);
273
275 void gap_state_init(struct gap_state* state);
276
278 void lengths_state_init(struct lengths_state* state);
279
281 void toggle_state_init(struct toggle_state* state);
282
284 void button_state_init(struct button_state* state, int started_as_root);
285
287 enum get_gap_status get_gap_length(struct gap_state* state,
288 struct ir_remote* remote);
289
291 enum lengths_status get_lengths(struct lengths_state* state,
292 struct ir_remote* remote,
293 int force,
294 int interactive);
295
297 void free_all_lengths(void);
298
300 enum toggle_status
301 get_toggle_bit_mask(struct toggle_state* state, struct ir_remote* remote);
302
304 int do_analyse(const struct opts* opts, struct main_state* state);
305
307 enum button_status record_buttons(struct button_state* btn_state,
308 enum button_status last_status,
309 struct main_state* state,
310 const struct opts* opts);
311
313 void config_file_setup(struct main_state* state, const struct opts* opts);
314
316 int config_file_finish(struct main_state* state, const struct opts* opts);
317
319 void get_pre_data(struct ir_remote* remote);
320
322 void get_post_data(struct ir_remote* remote);
323
325 void remove_pre_data(struct ir_remote* remote);
326
328 void remove_post_data(struct ir_remote* remote);
329
331 void invert_data(struct ir_remote* remote);
332
334 void remove_trail(struct ir_remote* remote);
335
336#ifdef __cplusplus
337}
338#endif
339
340#endif
ir_code
uint64_t ir_code
Denotes an internal coded representation for an IR transmission.
Definition ir_remote_types.h:43
eps
unsigned int eps
Shared list of remotes.
Definition irrecord.c:62
flushhw
void flushhw(void)
Clear the driver input buffers.
Definition irrecord.c:139
get_lengths
enum lengths_status get_lengths(struct lengths_state *state, struct ir_remote *remote, int force, int interactive)
Try to find out pre/post etc.
Definition irrecord.c:1387
button_status
button_status
Return from one pass in record_buttons().
Definition irrecord.h:124
record_buttons
enum button_status record_buttons(struct button_state *btn_state, enum button_status last_status, struct main_state *state, const struct opts *opts)
Try to record one button, returning button_status.
Definition irrecord.c:1848
config_file_finish
int config_file_finish(struct main_state *state, const struct opts *opts)
Write the final config file.
Definition irrecord.c:2119
lengths_status
lengths_status
Return from one attempt to determine lengths in get_lengths().
Definition irrecord.h:91
get_gap_status
get_gap_status
Return form one attempt to get gap in get_gap().
Definition irrecord.h:104
get_toggle_bit_mask
enum toggle_status get_toggle_bit_mask(struct toggle_state *state, struct ir_remote *remote)
Try to find out toggle_bit_mask, returning toggle_status.
Definition irrecord.c:1556
config_file_setup
void config_file_setup(struct main_state *state, const struct opts *opts)
Write the provisionary config file.
Definition irrecord.c:2102
button_state_init
void button_state_init(struct button_state *state, int started_as_root)
Initiate a pristine button_state.
Definition irrecord.c:219
toggle_status
toggle_status
Return from one attempt in get_toggle_bit_mask().
Definition irrecord.h:114
raw_read
ssize_t raw_read(void *buffer, size_t size, unsigned int timeout_us)
Absolute error tolerance (us).
Definition irrecord.c:1815
remove_pre_data
void remove_pre_data(struct ir_remote *remote)
Test hook: Move remote->pre_data into remote->bits.
Definition irrecord.c:383
remove_post_data
void remove_post_data(struct ir_remote *remote)
Test hook: Move remote->post_data into remote->bits.
Definition irrecord.c:403
invert_data
void invert_data(struct ir_remote *remote)
Test hook: Invert all data items in remote.
Definition irrecord.c:424
get_gap_length
enum get_gap_status get_gap_length(struct gap_state *state, struct ir_remote *remote)
Try to find out gap length, returning gap_status.
Definition irrecord.c:1207
free_all_lengths
void free_all_lengths(void)
Free heap data allocated by get_lengths().
Definition irrecord.c:664
gap_state_init
void gap_state_init(struct gap_state *state)
Initiate a pristine gap_state.
Definition irrecord.c:189
remove_trail
void remove_trail(struct ir_remote *remote)
Test hook: Move remote->trail into remote->bits.
Definition irrecord.c:463
do_analyse
int do_analyse(const struct opts *opts, struct main_state *state)
The –analyse wrapper, returns boolean ok/fail.
Definition irrecord.c:1787
get_post_data
void get_post_data(struct ir_remote *remote)
Test hook: Extract remote->post_data and post_data_bits from bits.
Definition irrecord.c:327
aeps
lirc_t aeps
Error tolerance in per cent.
Definition irrecord.c:63
btn_state_set_message
void btn_state_set_message(struct button_state *state, const char *fmt,...)
sprintf-style message formatting into state->message.
Definition irrecord.c:97
lengths_state_init
void lengths_state_init(struct lengths_state *state)
Initiate a pristine lengths_state.
Definition irrecord.c:195
toggle_state_init
void toggle_state_init(struct toggle_state *state)
Initiate a pristine toggle_state.
Definition irrecord.c:211
for_each_remote
void for_each_remote(struct ir_remote *remotes, remote_func func)
Unconditionally apply func(remote) for all items in remotes list.
Definition irrecord.c:491
get_pre_data
void get_pre_data(struct ir_remote *remote)
Test hook: Extract remote->pre_data from remote->bits.
Definition irrecord.c:269
loglevel_t
loglevel_t
The defined loglevels.
Definition lirc_log.h:36
lirc_private.h
Main include file for lirc applications.
button_state
State while recording buttons, privates besides commented.
Definition irrecord.h:236
button_state::message
char message[128]
Error message, valid on STS_BTN_*_ERROR.
Definition irrecord.h:240
button_state::ncode
struct ir_ncode ncode
Recorded button, valid on STS_BTN_BUTTON_DONE.
Definition irrecord.h:238
decode_ctx_t
State describing code, pre, post + gap and repeat state.
Definition ir_remote_types.h:137
driver
The data the driver exports i.
Definition driver.h:132
gap_state
Private state in get_gap_length().
Definition irrecord.h:185
ir_ncode
IR Command, corresponding to one (command defining) line of the configuration file.
Definition ir_remote_types.h:60
ir_remote
One remote as represented in the configuration file.
Definition ir_remote_types.h:150
lengths_state
State in get_lengths(), private besides commented.
Definition irrecord.h:199
lengths_state::keypresses_done
int keypresses_done
Number of printed keypresses.
Definition irrecord.h:201
lengths_state::count
int count
Number of processed data items.
Definition irrecord.h:206
lengths_state::keypresses
int keypresses
Number of counted button presses.
Definition irrecord.h:203
lengths_state::sum
lirc_t sum
Number of bits accounted for in signal.
Definition irrecord.h:211
lengths
Definition irrecord.h:142
main_state
Overall state in main.
Definition irrecord.h:177
opts
Parsed run-time options, reflects long_options and the command line, mostly a const object.
Definition irrecord.h:153
toggle_state
Private state in get_togggle_bit_mask().
Definition irrecord.h:220