LIRC libraries
LinuxInfraredRemoteControl
User-space driver API

Basic interface for user-space drivers, aimed to be included in each driver. More...

Files

file  driver.h
 Interface to the userspace drivers.
 
file  drv_enum.c
 Implemenents drv_enum.h.
 
file  drv_enum.h
 dynamic drivers device enumeration support
 
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.
 

Classes

struct  option_t
 Argument for DRV_SET_OPTION. More...
 
struct  driver
 The data the driver exports i. More...
 

Macros

#define MAXPATHLEN   4096
 
#define HAVE_SERVER_VERSION   1
 Testable flag for get_server_version() presence. More...
 
#define DRV_ERR_NOT_IMPLEMENTED   1
 drvctl definitions More...
 
#define DRV_ERR_NOT_IMPLEMENTED   1
 drvctl definitions More...
 
#define DRVCTL_GET_STATE   1
 Drvctl cmd: return current state as an int in *arg. More...
 
#define DRVCTL_SEND_SPACE   2
 Drvctl cmd: Send long space. More...
 
#define DRVCTL_SET_OPTION   3
 Drvctl cmd: Set driver options. More...
 
#define DRVCTL_GET_RAW_CODELENGTH   4
 Drvctl cmd: get raw length to read, if different than codelength. More...
 
#define DRVCTL_GET_DEVICES   5
 Drvctl cmd: get list of possible devices. More...
 
#define DRVCTL_FREE_DEVICES   6
 drvctl cmd: Free memory in argument obtained using DRVCTL_GET_DEVICES. More...
 
#define DRVCTL_NOTIFY_DECODE   7
 The former LIRC_NOTIFY_DECODE, informs drier that signal is successfully decoded e. More...
 
#define DRVCTL_MAX   128
 Last well-known command. More...
 
#define DRV_ERR_BAD_STATE   2
 drvctl error: cmd and arg is OK, but other errors. More...
 
#define DRV_ERR_BAD_OPTION   3
 drvctl error: cmd is bad
 
#define DRV_ERR_BAD_VALUE   4
 drvctl error: arg is bad
 
#define DRV_ERR_ENUM_EMPTY   5
 No requested data available. More...
 
#define DRV_ERR_INTERNAL   6
 drvctl error: "Should not happen" type of errors. More...
 
#define MIN_RECEIVE_TIMEOUT   100000
 Min value returned by receive_timeout. More...
 
#define WBUF_SIZE   256
 

Functions

int get_server_version (void)
 Return numeric server version, m.v.r => 10000 * m + 100 * v + r. More...
 
int default_open (const char *path)
 Stores path in drv.device if non-null. More...
 
int default_close (void)
 For now, a placeholder. More...
 
int default_drvctl (unsigned int cmd, void *arg)
 Return DRV_ERR_NOTIMPLEMENTED. More...
 
int drv_handle_options (const char *options)
 Parse an option string "key:value;key:value..." and invoke drvctl DRV_SET_OPTION as appropriate.
 
struct ir_ncodencode_dup (struct ir_ncode *ncode)
 Create a malloc'd, deep copy of ncode. More...
 
void ncode_free (struct ir_ncode *ncode)
 Dispose an ir_ncode instance obtained from ncode_dup(). More...
 
const struct ir_remoteis_in_remotes (const struct ir_remote *remotes, const struct ir_remote *remote)
 Test if a given remote is in a list of remotes. More...
 
struct ir_remoteget_ir_remote (const struct ir_remote *remotes, const char *name)
 Return ir_remote with given name in remotes list, or NULL if not found. More...
 
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)
 Return code with given name in remote's list of codes or NULL. More...
 
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. More...
 
char * decode_all (struct ir_remote *remotes)
 Tries to decode current signal trying all known remotes. More...
 
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. More...
 
void ir_remote_init (int use_dyncodes)
 Initiate: define if dynamic codes should be used. More...
 
const struct ir_remoteget_decoding (void)
 Return pointer to currently decoded remote. More...
 
void rec_set_update_mode (int mode)
 Set update mode, where recorded pre_data is verified to match the template pre_data. More...
 
void rec_buffer_set_logfile (FILE *f)
 Set a file logging input from driver in same format as mode2(1). More...
 
int waitfordata (uint32_t maxusec)
 If set_waitfordata(func) is called, invoke and return function set this way. More...
 
void set_waitfordata_func (int(*func)(uint32_t maxusec))
 Set the function used by waitfordata(). More...
 
void rec_buffer_init (void)
 Clear internal buffer to pristine state. More...
 
int rec_buffer_clear (void)
 Flush the internal fifo and store a single code read from the driver in it.
 
int receive_decode (struct ir_remote *remote, struct decode_ctx_t *ctx)
 Decode data from remote. More...
 
void rec_buffer_rewind (void)
 Reset the modules's internal fifo's read state to initial values where the nothing is read. More...
 
void rec_buffer_reset_wptr (void)
 Reset internal fifo's write pointer. More...
 
int tty_reset (int fd)
 Set the cfmakeraw termio options. More...
 
int tty_setrtscts (int fd, int enable)
 Set/clear CTS control line. More...
 
int tty_setdtr (int fd, int enable)
 Set/clear DTR control line. More...
 
int tty_setbaud (int fd, int baud)
 Set the speed a. More...
 
int tty_setcsize (int fd, int csize)
 Set the character size. More...
 
int tty_create_lock (const char *name)
 Creates a lock file of the type /var/local/LCK. More...
 
int tty_delete_lock (void)
 Delete any legacy lock(s) owned by this process. More...
 
int tty_set (int fd, int rts, int dtr)
 Set RTS and DTR control lines. More...
 
int tty_clear (int fd, int rts, int dtr)
 Clear RTS and DTR control lines. More...
 
int tty_write (int fd, char byte)
 Write a single byte to serial device. More...
 
int tty_read (int fd, char *byte)
 Read a single byte from serial device. More...
 
int tty_write_echo (int fd, char byte)
 Write a single byte and check the echo from remote party. More...
 
void send_buffer_init (void)
 Clear and re-initiate the buffer. More...
 
int send_buffer_put (struct ir_remote *remote, struct ir_ncode *code)
 Initializes the global send buffer for transmitting the code in the second argument, residing in the remote in the first. More...
 
int send_buffer_length (void)
 Do not document this function. More...
 
const lirc_t * send_buffer_data (void)
 
lirc_t send_buffer_sum (void)
 

Variables

struct ir_remotelast_remote
 TODO.
 
struct ir_remoterepeat_remote
 Global pointer to the remote that contains the code currently repeating. More...
 
struct ir_ncoderepeat_code
 Global pointer to the code currently repeating. More...
 

Detailed Description

Basic interface for user-space drivers, aimed to be included in each driver.

User-space driver API.

It provides basic functionality for sending, receiving and logging.

Macro Definition Documentation

#define DRV_ERR_BAD_STATE   2

drvctl error: cmd and arg is OK, but other errors.

Definition at line 118 of file driver.h.

#define DRV_ERR_ENUM_EMPTY   5

No requested data available.

Definition at line 127 of file driver.h.

#define DRV_ERR_INTERNAL   6

drvctl error: "Should not happen" type of errors.

Definition at line 130 of file driver.h.

#define DRV_ERR_NOT_IMPLEMENTED   1

drvctl definitions

drvctl error.

Definition at line 115 of file driver.h.

#define DRV_ERR_NOT_IMPLEMENTED   1

drvctl definitions

drvctl error.

Definition at line 115 of file driver.h.

#define DRVCTL_FREE_DEVICES   6

drvctl cmd: Free memory in argument obtained using DRVCTL_GET_DEVICES.

Definition at line 102 of file driver.h.

#define DRVCTL_GET_DEVICES   5

Drvctl cmd: get list of possible devices.

Argument is a *glob_t as defined in <glob.h>. The returned memory is owned by driver and should be free()'d using DRVCTL_FREE_DEVICES.

Each string in glob is a space-separated list of words. The first word is the mandatory device path, the optional reminder is information about the device suitable in user interfaces.

Definition at line 99 of file driver.h.

#define DRVCTL_GET_RAW_CODELENGTH   4

Drvctl cmd: get raw length to read, if different than codelength.

Arg is an unsigned int* which is updated on successfull return.

Definition at line 88 of file driver.h.

#define DRVCTL_GET_STATE   1

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

Definition at line 76 of file driver.h.

#define DRVCTL_MAX   128

Last well-known command.

Remaining is used in driver-specific controls.

Definition at line 112 of file driver.h.

#define DRVCTL_NOTIFY_DECODE   7

The former LIRC_NOTIFY_DECODE, informs drier that signal is successfully decoded e.

g., to initiate some visual feedback through a LED.

Definition at line 109 of file driver.h.

#define DRVCTL_SEND_SPACE   2

Drvctl cmd: Send long space.

Arg is pulselength (us, an int).

Definition at line 79 of file driver.h.

#define DRVCTL_SET_OPTION   3

Drvctl cmd: Set driver options.

Arg is *struct option_t.

Definition at line 82 of file driver.h.

#define HAVE_SERVER_VERSION   1

Testable flag for get_server_version() presence.

Definition at line 40 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.

Definition at line 733 of file ir_remote.c.

int default_close ( void  )

For now, a placeholder.

Definition at line 52 of file driver.c.

int default_drvctl ( unsigned int  cmd,
void *  arg 
)

Return DRV_ERR_NOTIMPLEMENTED.

Definition at line 57 of file driver.c.

int default_open ( const char *  path)

Stores path in drv.device if non-null.

Definition at line 37 of file driver.c.

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

Return code with given name in remote's list of codes or NULL.

Definition at line 397 of file ir_remote.c.

const struct ir_remote* get_decoding ( void  )

Return pointer to currently decoded remote.

Definition at line 854 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 193 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 156 of file ir_remote.c.

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

Return ir_remote with given name in remotes list, or NULL if not found.

Definition at line 251 of file ir_remote.c.

int get_server_version ( void  )

Return numeric server version, m.v.r => 10000 * m + 100 * v + r.

Definition at line 22 of file driver.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 124 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 239 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 283 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 329 of file ir_remote.c.

struct ir_ncode* ncode_dup ( struct ir_ncode ncode)

Create a malloc'd, deep copy of ncode.

Use ncode_free() to dispose().

Use ncode_free() to dispose.

Definition at line 69 of file ir_remote.c.

void ncode_free ( struct ir_ncode ncode)

Dispose an ir_ncode instance obtained from ncode_dup().

Definition at line 104 of file ir_remote.c.

void rec_buffer_init ( void  )

Clear internal buffer to pristine state.

Definition at line 217 of file receive.c.

void rec_buffer_reset_wptr ( void  )

Reset internal fifo's write pointer.

Definition at line 232 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 222 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 204 of file receive.c.

void rec_set_update_mode ( int  mode)

Set update mode, where recorded pre_data is verified to match the template pre_data.

By defaulöt false.

Definition at line 69 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 1054 of file receive.c.

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

Definition at line 379 of file transmit.c.

void send_buffer_init ( void  )

Clear and re-initiate the buffer.

Clear and re-initiate the buffer.

(Just fills it with zeros.)

Definition at line 62 of file transmit.c.

int send_buffer_length ( void  )

Do not document this function.

Returns
Number of items accessible in array send_buffer_data().

Definition at line 373 of file transmit.c.

int send_buffer_put ( struct ir_remote remote,
struct ir_ncode code 
)

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

Parameters
remoteir_remote containing code to send.
codeir_ncode to send.
Returns
0 on failures, else 1.

Definition at line 355 of file transmit.c.

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

Definition at line 384 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.

Definition at line 823 of file ir_remote.c.

void set_waitfordata_func ( int(*)(uint32_t maxusec)  func)

Set the function used by waitfordata().

Definition at line 169 of file receive.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 525 of file serial.c.

int tty_create_lock ( const char *  name)

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 302 of file serial.c.

int tty_delete_lock ( void  )

Delete any legacy 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 445 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 557 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 54 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 511 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 120 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 265 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 93 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 72 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 539 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 successfully written and read, else 0. It's thus 1 even if the echo doesn't match.

Definition at line 577 of file serial.c.

int waitfordata ( uint32_t  maxusec)

If set_waitfordata(func) is called, invoke and return function set this way.

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

Parameters
maxusectimeout in micro seconds, given to poll(2). If <= 0, the function will block indefinitely until data is available or a signal 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 175 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.

Parameters
bufferFormatted string on exit.
sizeSize of buffer.
remote_name
button_name
button_suffix
code
reps
Returns
snprintf(3) result code i. e., number of formatted bytes in buffer.

Definition at line 713 of file ir_remote.c.

Variable Documentation

struct ir_ncode* repeat_code

Global pointer to the code currently repeating.

Defined in ir_remote.c.

Definition at line 63 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 61 of file ir_remote.c.