Loading...
Searching...
No Matches
irrecord.h
Go to the documentation of this file.
/****************************************************************************
** irrecord.h **************************************************************
****************************************************************************
*
* irrecord.h - base library for irrrecord.
*
* Copyright (C) 1998,99 Christoph Bartelmus <lirc@bartelmus.de>
*
*/
#ifndef IRRECORD_H
#define IRRECORD_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include <syslog.h>
#include <unistd.h>
#include "lirc_private.h"
#define min(a, b) (a > b ? b : a)
#define max(a, b) (a > b ? a : b)
#define BUTTON (80 + 1)
#define RETRIES 10
/* the longest signal I've seen up to now was 48-bit signal with header */
#define MAX_SIGNALS 200
/* some threshold values */
#define TH_SPACE_ENC 80 /* I want less than 20% mismatches */
#define TH_HEADER 90
#define TH_REPEAT 90
#define TH_TRAIL 90
#define TH_LEAD 90
#define TH_IS_BIT 10
#define TH_RC6_SIGNAL 550
#define MIN_GAP 20000
#define MAX_GAP 100000
#define SAMPLES 80
// forwards
struct ir_remote;
struct main_state;
struct opts;
// type declarations
typedef void (*remote_func) (struct ir_remote* remotes);
enum analyse_mode { MODE_GET_GAP, MODE_HAVE_GAP };
enum lengths_status {
STS_LEN_OK,
STS_LEN_FAIL,
STS_LEN_RAW_OK,
STS_LEN_TIMEOUT,
STS_LEN_AGAIN,
STS_LEN_AGAIN_INFO,
STS_LEN_NO_GAP_FOUND,
STS_LEN_TOO_LONG,
};
enum get_gap_status {
STS_GAP_INIT,
STS_GAP_TIMEOUT,
STS_GAP_FOUND,
STS_GAP_GOT_ONE_PRESS,
STS_GAP_AGAIN
};
enum toggle_status {
STS_TGL_TIMEOUT,
STS_TGL_GOT_ONE_PRESS,
STS_TGL_NOT_FOUND,
STS_TGL_FOUND,
STS_TGL_AGAIN
};
enum button_status {
STS_BTN_INIT,
STS_BTN_GET_NAME,
STS_BTN_INIT_DATA,
STS_BTN_GET_RAW_DATA,
STS_BTN_GET_DATA,
STS_BTN_GET_TOGGLE_BITS,
STS_BTN_RECORD_DONE,
STS_BTN_BUTTON_DONE,
STS_BTN_BUTTONS_DONE,
STS_BTN_ALL_DONE,
STS_BTN_SOFT_ERROR,
STS_BTN_HARD_ERROR,
STS_BTN_TIMEOUT,
};
/* analyse stuff */
struct lengths {
unsigned int count;
lirc_t sum, upper_bound, lower_bound, min, max;
struct lengths* next;
};
struct opts {
int dynamic_codes;
int analyse;
int force;
int disable_namespace;
const char* device;
int get_pre;
int get_post;
int test;
int invert;
int trail;
int list_namespace;
int update;
const char* filename;
const char* tmpfile;
const char* backupfile;
const char* driver;
loglevel_t loglevel;
int using_template;
char commandline[128];
};
struct main_state {
FILE* fout;
struct decode_ctx_t decode_ctx;
int started_as_root;
};
struct gap_state {
struct lengths* scan;
struct lengths* gaps;
struct timeval start;
struct timeval end;
struct timeval last;
int flag;
int maxcount;
int lastmaxcount;
lirc_t gap;
};
struct lengths_state {
int keypresses_done;
int keypresses;
int retval;
int count;
lirc_t data;
lirc_t average;
lirc_t maxspace;
lirc_t sum;
lirc_t remaining_gap;
lirc_t header;
int first_signal;
enum analyse_mode mode;
};
struct toggle_state {
struct decode_ctx_t decode_ctx;
int retval;
int retries;
int flag;
int success;
ir_code first;
ir_code last;
int seq;
int repeats;
int found;
int inited;
};
struct button_state {
struct ir_ncode ncode;
char message[128];
int retval;
char buffer[BUTTON];
char* string;
lirc_t data;
lirc_t sum;
unsigned int count;
int flag;
int no_data;
int started_as_root;
};
// Globals
extern struct ir_remote remote;
extern unsigned int eps;
extern lirc_t aeps;
// Functions
ssize_t raw_read(void* buffer, size_t size, unsigned int timeout_us);
void for_each_remote(struct ir_remote* remotes, remote_func func);
void btn_state_set_message(struct button_state* state, const char* fmt, ...);
void flushhw(void);
void gap_state_init(struct gap_state* state);
void lengths_state_init(struct lengths_state* state);
void toggle_state_init(struct toggle_state* state);
void button_state_init(struct button_state* state, int started_as_root);
enum get_gap_status get_gap_length(struct gap_state* state,
struct ir_remote* remote);
enum lengths_status get_lengths(struct lengths_state* state,
struct ir_remote* remote,
int force,
int interactive);
void free_all_lengths(void);
enum toggle_status
get_toggle_bit_mask(struct toggle_state* state, struct ir_remote* remote);
int do_analyse(const struct opts* opts, struct main_state* state);
enum button_status record_buttons(struct button_state* btn_state,
enum button_status last_status,
struct main_state* state,
const struct opts* opts);
void config_file_setup(struct main_state* state, const struct opts* opts);
int config_file_finish(struct main_state* state, const struct opts* opts);
void get_pre_data(struct ir_remote* remote);
void get_post_data(struct ir_remote* remote);
void remove_pre_data(struct ir_remote* remote);
void remove_post_data(struct ir_remote* remote);
void invert_data(struct ir_remote* remote);
void remove_trail(struct ir_remote* remote);
#ifdef __cplusplus
}
#endif
#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
aeps
lirc_t aeps
Error tolerance in per cent.
Definition irrecord.c:63
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
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
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