LIRC libraries
LinuxInfraredRemoteControl
User-space driver API

User-space driver API. More...

Files

file  driver.h
 Interface to the userspace drivers.
 
file  ir_remote.h
 Describes and decodes the signals from IR remotes.
 
file  lirc_config.h
 Local configuration constants not managed by autotools.
 
file  lirc_log.h
 Logging functionality.
 
file  receive.h
 Functions that decode IR codes.
 
file  serial.h
 Common routines for hw that uses the standard serial port driver.
 
file  transmit.h
 Functions that prepare IR codes for transmitting.
 

Data Structures

struct  option_t
 
struct  driver
 

Macros

#define DRV_ERR_NOT_IMPLEMENTED   1
 
#define DRV_ERR_NOT_IMPLEMENTED   1
 
#define DRVCTL_GET_STATE   1
 
#define DRVCTL_SEND_SPACE   2
 
#define DRVCTL_SET_OPTION   3
 
#define DRVCTL_MAX   128
 
#define DRV_ERR_BAD_STATE   2
 
#define DRV_ERR_BAD_OPTION   3
 
#define MIN_RECEIVE_TIMEOUT   100000
 
#define WBUF_SIZE   256
 

Functions

int default_open (const char *path)
 
int default_close (void)
 
int default_drvctl (unsigned int cmd, void *arg)
 
int drv_handle_options (const char *options)
 
const struct ir_remoteis_in_remotes (const struct ir_remote *remotes, const struct ir_remote *remote)
 
struct ir_remoteget_ir_remote (const struct ir_remote *remotes, const char *name)
 
void get_frequency_range (const struct ir_remote *remotes, unsigned int *min_freq, unsigned int *max_freq)
 
void get_filter_parameters (const struct ir_remote *remotes, lirc_t *max_gap_lengthp, lirc_t *min_pulse_lengthp, lirc_t *min_space_lengthp, lirc_t *max_pulse_lengthp, lirc_t *max_space_lengthp)
 
int map_code (const struct ir_remote *remote, struct decode_ctx_t *ctx, int pre_bits, ir_code pre, int bits, ir_code code, int post_bits, ir_code post)
 
void map_gap (const struct ir_remote *remote, struct decode_ctx_t *ctx, const struct timeval *start, const struct timeval *last, lirc_t signal_length)
 
struct ir_ncodeget_code_by_name (const struct ir_remote *remote, const char *name)
 
int write_message (char *buffer, size_t size, const char *remote_name, const char *button_name, const char *button_suffix, ir_code code, int reps)
 
char * decode_all (struct ir_remote *remotes)
 
int send_ir_ncode (struct ir_remote *remote, struct ir_ncode *code, int delay)
 
void ir_remote_init (int use_dyncodes)
 
void rec_buffer_set_logfile (FILE *f)
 
int waitfordata (__u32 maxusec)
 
void rec_buffer_init ()
 
int rec_buffer_clear (void)
 
int receive_decode (struct ir_remote *remote, struct decode_ctx_t *ctx)
 
void rec_buffer_rewind (void)
 
void rec_buffer_reset_wptr (void)
 
int tty_reset (int fd)
 
int tty_setrtscts (int fd, int enable)
 
int tty_setdtr (int fd, int enable)
 
int tty_setbaud (int fd, int baud)
 
int tty_setcsize (int fd, int csize)
 
int tty_create_lock (const char *name)
 
int tty_delete_lock (void)
 
int tty_set (int fd, int rts, int dtr)
 
int tty_clear (int fd, int rts, int dtr)
 
int tty_write (int fd, char byte)
 
int tty_read (int fd, char *byte)
 
int tty_write_echo (int fd, char byte)
 
void send_buffer_init (void)
 
int send_buffer_put (struct ir_remote *remote, struct ir_ncode *code)
 
int send_buffer_length ()
 
const lirc_t * send_buffer_data ()
 
lirc_t send_buffer_sum ()
 

Variables

struct ir_remotelast_remote
 
struct ir_remoterepeat_remote
 
struct ir_ncoderepeat_code
 

Detailed Description

User-space driver API.

Basic interface for user-space drivers, aimed to be included in each driver. It provides basic functionality for sending, receiving and logging.

Macro Definition Documentation

#define DRV_ERR_BAD_OPTION   3

drvctl error:

Definition at line 75 of file driver.h.

#define DRV_ERR_BAD_STATE   2

drvctl error:

Definition at line 72 of file driver.h.

#define DRV_ERR_NOT_IMPLEMENTED   1

drvctl definitions

drvctl error.

Definition at line 69 of file driver.h.

#define DRV_ERR_NOT_IMPLEMENTED   1

drvctl definitions

drvctl error.

Definition at line 69 of file driver.h.

#define DRVCTL_GET_STATE   1

Drvctl cmd: return current state as an int in *arg.

Definition at line 57 of file driver.h.

#define DRVCTL_MAX   128

Last well-known command. Remaining is used in driver-specific controls.

Definition at line 66 of file driver.h.

#define DRVCTL_SEND_SPACE   2

Drvctl cmd: Send long space. Arg is pulselength (us, an int).

Definition at line 60 of file driver.h.

#define DRVCTL_SET_OPTION   3

Drvctl cmd: Set driver options. Arg is *struct option_t.

Definition at line 63 of file driver.h.

#define MIN_RECEIVE_TIMEOUT   100000

Min value returned by receive_timeout.

Definition at line 35 of file receive.h.

Function Documentation

char* decode_all ( struct ir_remote remotes)

Tries to decode current signal trying all known remotes. This is non-blocking, failures could be retried later when more data is available.

Parameters
remotesParsed lircd.conf file as returned by read_config()
Returns
NULL on errors or no data available. Else a dynamically allocated string like "000000000000fad3 00 KEY_POWER apple". Caller owns string and eventually de-allocates it.

Tries to decode current signal trying all known remotes.

Parameters
remotes
Returns

Definition at line 617 of file ir_remote.c.

int default_close ( void  )

For now, a placeholder.

Definition at line 34 of file driver.c.

int default_drvctl ( unsigned int  cmd,
void *  arg 
)

Return DRVCTL_ERR_NOTIMPLEMENTED.

Definition at line 39 of file driver.c.

int default_open ( const char *  path)

Stores path in drv.device.

Definition at line 26 of file driver.c.

int drv_handle_options ( const char *  options)

Parse an option string "key:value;key:value..." and invoke drvctl DRV_SET_OPTION as appropriate.

Definition at line 45 of file driver.c.

struct ir_ncode* get_code_by_name ( const struct ir_remote remote,
const char *  name 
)
Parameters
remote
name
Returns

Definition at line 331 of file ir_remote.c.

void get_filter_parameters ( const struct ir_remote remotes,
lirc_t *  max_gap_lengthp,
lirc_t *  min_pulse_lengthp,
lirc_t *  min_space_lengthp,
lirc_t *  max_pulse_lengthp,
lirc_t *  max_space_lengthp 
)
Parameters
remotes
max_gap_lengthp
min_pulse_lengthp
min_space_lengthp
max_pulse_lengthp
max_space_lengthp

Definition at line 122 of file ir_remote.c.

void get_frequency_range ( const struct ir_remote remotes,
unsigned int *  min_freq,
unsigned int *  max_freq 
)
Parameters
remotes
min_freq
max_freq

Definition at line 87 of file ir_remote.c.

struct ir_remote* get_ir_remote ( const struct ir_remote remotes,
const char *  name 
)
Parameters
remotes
name
Returns

Definition at line 185 of file ir_remote.c.

void ir_remote_init ( int  use_dyncodes)

Initiate: define if dynamic codes should be used.

Parameters
use_dyncodesShould normally reflect "lircd:dynamic-codes" option.

Definition at line 59 of file ir_remote.c.

const struct ir_remote* is_in_remotes ( const struct ir_remote remotes,
const struct ir_remote remote 
)

Test if a given remote is in a list of remotes.

Parameters
remotesHead of linked list of remotes (using remote.next).
remotePointer to remote to check
Returns
1 if remote exists in remotes list, else 0
Parameters
remotes
remote
Returns

Definition at line 167 of file ir_remote.c.

int map_code ( const struct ir_remote remote,
struct decode_ctx_t ctx,
int  pre_bits,
ir_code  pre,
int  bits,
ir_code  code,
int  post_bits,
ir_code  post 
)
Parameters
remote
prep
codep
postp
pre_bits
pre
bits
code
post_bits
post
Returns

Definition at line 218 of file ir_remote.c.

void map_gap ( const struct ir_remote remote,
struct decode_ctx_t ctx,
const struct timeval *  start,
const struct timeval *  last,
lirc_t  signal_length 
)
Parameters
remote
start
last
signal_length
repeat_flagp
min_remaining_gapp
max_remaining_gapp

Definition at line 263 of file ir_remote.c.

int rec_buffer_clear ( void  )

Flush the internal fifo and store a single code read from the driver in it.

Definition at line 239 of file receive.c.

void rec_buffer_init ( )

Clear internal buffer to pristine state.

Definition at line 219 of file receive.c.

void rec_buffer_reset_wptr ( void  )

Reset internal fifo's write pointer.

Definition at line 234 of file receive.c.

void rec_buffer_rewind ( void  )

Reset the modules's internal fifo's read state to initial values where the nothing is read. The write pointer is not affected.

Definition at line 224 of file receive.c.

void rec_buffer_set_logfile ( FILE *  f)

Set a file logging input from driver in same format as mode2(1).

Parameters
fOpen file to write on or NULL to disable logging.

Definition at line 205 of file receive.c.

int receive_decode ( struct ir_remote remote,
struct decode_ctx_t ctx 
)

Decode data from remote

Parameters
ctxUndefined on enter. On exit, the fields in the structure are defined.

Definition at line 1050 of file receive.c.

const lirc_t* send_buffer_data ( )
Returns
Pointer to timing data in microseconds for pulses/spaces.

Definition at line 385 of file transmit.c.

void send_buffer_init ( void  )

Clear and re-initiate the buffer.

Initializes the global sending buffer. (Just fills it with zeros.)

Definition at line 56 of file transmit.c.

int send_buffer_length ( )
Returns
Number of items accessible in array send_buffer_data().

Do not document this function

Definition at line 379 of file transmit.c.

int send_buffer_put ( struct ir_remote remote,
struct ir_ncode code 
)

Prepare the buffer.

Parameters
remoteParsed lircd.conf data.
codeData item to be represented in buff.
Returns
0 on errors, else 1

Initializes the global sending buffer for transmitting the code int the second argument, residing in the remote in the first.

Parameters
remoteir_remote containing code to send
codeir_ncode to send.
Returns
Success of operation.

Definition at line 364 of file transmit.c.

lirc_t send_buffer_sum ( )
Returns
Total length of buffer in microseconds.

Definition at line 390 of file transmit.c.

int send_ir_ncode ( struct ir_remote remote,
struct ir_ncode code,
int  delay 
)

Transmits the actual code in the second argument by calling the current hardware driver. The processing depends on global repeat-remote. If this is not-NULL, the codes are sent using repeat formatting if the remote supports it.

Parameters
remoteCurrently active remote, used as database for timing, and as keeper of an internal state.
codeIR code to be transmitted
delayIf true (normal case), generate a delay corresponding to the time it takes to send the code. If not (test case), don't.
Returns
Non-zero if success.

Transmits the actual code in the second argument by calling the current hardware driver.

Parameters
remoteCurrently active remote, used as data base for timing, and as keeper of an internal state.
codeIR code to be transmitted
Returns
nonzero if success

Definition at line 693 of file ir_remote.c.

int tty_clear ( int  fd,
int  rts,
int  dtr 
)

Clear RTS and DTR control lines.

Parameters
fdFile opened on a serial device.
rtsIf 0 ignored, else clears RTS.
ctsIf 0 ignored, else clears CTS.
Returns
0 on errors, else 1.

Definition at line 534 of file serial.c.

int tty_create_lock ( const char *  name)

Create a legacy file lock for a serial device.

Parameters
fdFile opened on a serial device.
nameBasename of device to be locked
Returns
1 if successfull lock, else 0.

Creates a lock file of the type /var/local/LCK.. + name

Parameters
nameName of the device
Returns
non-zero if successful
See also
http://www.pathname.com/fhs/2.2/fhs-5.9.html

Definition at line 304 of file serial.c.

int tty_delete_lock ( void  )

Remove all legacy locks owned by running process.

Returns
1 if all locks removed successfully, 0 on errors.

Delete any lock(s) owned by this process.

Returns
0 on errors, else 1.
See also
http://www.pathname.com/fhs/2.2/fhs-5.9.html

Definition at line 452 of file serial.c.

int tty_read ( int  fd,
char *  byte 
)

Read a single byte from serial device.

Parameters
fdFile opened on a serial device.
bytePointer to byte to be read.
Returns
-1 on errors, else 1 and data stored in *byte.

Definition at line 566 of file serial.c.

int tty_reset ( int  fd)

Set the cfmakeraw termio options.

Parameters
fdFile opened on a serial device.
Returns
0 on errors, else 1.

Definition at line 49 of file serial.c.

int tty_set ( int  fd,
int  rts,
int  dtr 
)

Set RTS and DTR control lines.

Parameters
fdFile opened on a serial device.
rtsIf 0 ignored, else sets RTS.
ctsIf 0 ignored, else sets CTS.
Returns
0 on errors, else 1.

Definition at line 520 of file serial.c.

int tty_setbaud ( int  fd,
int  baud 
)

Set the speed a. k. a. baudrate.

Parameters
fdFile opened on a serial device.
baudSpeed constant as defined for termios cfsetospeed e.g., B19200
Returns
0 on errors, else 1.

Definition at line 117 of file serial.c.

int tty_setcsize ( int  fd,
int  csize 
)

Set the character size

Parameters
fdFile opened on a serial device.
Numberof data bits: CS5, CS6, CS7, or CS8.
Returns
0 on errors, else 1.

Definition at line 261 of file serial.c.

int tty_setdtr ( int  fd,
int  enable 
)

Set/clear DTR control line.

Parameters
fdFile opened on a serial device.
enableIf true sets DTR, else clears it.
Returns
0 on errors, else 1.

Definition at line 89 of file serial.c.

int tty_setrtscts ( int  fd,
int  enable 
)

Set/clear CTS control line.

Parameters
enableIf true sets CTS, else clears it.
Returns
0 on errors, else 1.

Definition at line 67 of file serial.c.

int tty_write ( int  fd,
char  byte 
)

Write a single byte to serial device.

Parameters
fdFile opened on a serial device.
byteItem to write.
Returns
-1 on errors, else 1.

Definition at line 548 of file serial.c.

int tty_write_echo ( int  fd,
char  byte 
)

Write a single byte and check the echo from remote party. Makes a log printout if these don't match.

Parameters
fdFile opened on a serial device.
byteByte to be written.
Returns
1 if a byte is susccessfully written and read, else 0. It's thus 1 even if the echo doesn't match.

Definition at line 594 of file serial.c.

int waitfordata ( __u32  maxusec)

Wait until data is available to read, or timeout.

Parameters
maxusecMac number of microseconda to wait.
Returns
non-zero if the driver.fd is ready to read, or 0 indicating timeout

Wait until data is available in drv.fd, timeout or a signal is raised.

Parameters
maxusectimeout in micro seconds, given to select(2). If <= 0, the function will block indefinetaly, until data is available or a sugnal is processed. If positive, a timeout value in microseconds.
Returns
True (1) if there is data available in drv.fd, else 0 indicating timeout.

Definition at line 168 of file receive.c.

int write_message ( char *  buffer,
size_t  size,
const char *  remote_name,
const char *  button_name,
const char *  button_suffix,
ir_code  code,
int  reps 
)

Formats the arguments into a readable string (first argument, size the second argument). The arguments start at the third position.) into a nice

Parameters
buffer
size
remote_name
button_name
button_suffix
code
reps
Returns

Definition at line 601 of file ir_remote.c.

Variable Documentation

struct ir_remote* last_remote

TODO

Definition at line 51 of file ir_remote.c.

struct ir_ncode* repeat_code

Global pointer to the code currently repeating. Defined in ir_remote.c.

Definition at line 55 of file ir_remote.c.

struct ir_remote* repeat_remote

Global pointer to the remote that contains the code currently repeating. Defined in ir_remote.c.

Definition at line 53 of file ir_remote.c.