Loading...
Searching...
No Matches
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.
#define | DRV_ERR_NOT_IMPLEMENTED 1
| drvctl definitions
#define | DRV_ERR_NOT_IMPLEMENTED 1
| drvctl definitions
#define | DRVCTL_GET_STATE 1
| Drvctl cmd: return current state as an int in *arg.
#define | DRVCTL_SEND_SPACE 2
| Drvctl cmd: Send long space.
#define | DRVCTL_SET_OPTION 3
| Drvctl cmd: Set driver options.
#define | DRVCTL_GET_RAW_CODELENGTH 4
| Drvctl cmd: get raw length to read, if different than codelength.
#define | DRVCTL_GET_DEVICES 5
| Drvctl cmd: get list of possible devices.
#define | DRVCTL_FREE_DEVICES 6
| drvctl cmd: Free memory in argument obtained using DRVCTL_GET_DEVICES.
#define | DRVCTL_NOTIFY_DECODE 7
| The former LIRC_NOTIFY_DECODE, informs drier that signal is successfully decoded e.
#define | DRVCTL_MAX 128
| Last well-known command.
#define | DRV_ERR_BAD_STATE 2
| drvctl error: cmd and arg is OK, but other errors.
#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.
#define | DRV_ERR_INTERNAL 6
| drvctl error: "Should not happen" type of errors.
#define | MIN_RECEIVE_TIMEOUT 100000
| Min value returned by receive_timeout.
#define | WBUF_SIZE 256

## Functions

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

## Variables

struct ir_remote * | last_remote
| TODO.
struct ir_remote * | repeat_remote
| Global pointer to the remote that contains the code currently repeating.
struct ir_ncode * | repeat_code
| Global pointer to the code currently repeating.

## 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

## DRV_ERR_BAD_OPTION

#define DRV_ERR_BAD_OPTION 3

drvctl error: cmd is bad

Definition at line 117 of file driver.h.

## DRV_ERR_BAD_STATE

#define DRV_ERR_BAD_STATE 2

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

Definition at line 114 of file driver.h.

## DRV_ERR_BAD_VALUE

#define DRV_ERR_BAD_VALUE 4

drvctl error: arg is bad

Definition at line 120 of file driver.h.

## DRV_ERR_ENUM_EMPTY

#define DRV_ERR_ENUM_EMPTY 5

No requested data available.

Definition at line 123 of file driver.h.

## DRV_ERR_INTERNAL

#define DRV_ERR_INTERNAL 6

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

Definition at line 126 of file driver.h.

## DRV_ERR_NOT_IMPLEMENTED [1/2]

#define DRV_ERR_NOT_IMPLEMENTED 1

drvctl definitions

drvctl error.

Definition at line 47 of file driver.h.

## DRV_ERR_NOT_IMPLEMENTED [2/2]

#define DRV_ERR_NOT_IMPLEMENTED 1

drvctl definitions

drvctl error.

Definition at line 47 of file driver.h.

## DRVCTL_FREE_DEVICES

#define DRVCTL_FREE_DEVICES 6

drvctl cmd: Free memory in argument obtained using DRVCTL_GET_DEVICES.

Definition at line 98 of file driver.h.

## DRVCTL_GET_DEVICES

#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 95 of file driver.h.

## DRVCTL_GET_RAW_CODELENGTH

#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 84 of file driver.h.

## DRVCTL_GET_STATE

#define DRVCTL_GET_STATE 1

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

Definition at line 72 of file driver.h.

## DRVCTL_MAX

#define DRVCTL_MAX 128

Last well-known command.

Remaining is used in driver-specific controls.

Definition at line 108 of file driver.h.

## DRVCTL_NOTIFY_DECODE

#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 105 of file driver.h.

## DRVCTL_SEND_SPACE

#define DRVCTL_SEND_SPACE 2

Drvctl cmd: Send long space.

Arg is pulselength (us, an int).

Definition at line 75 of file driver.h.

## DRVCTL_SET_OPTION

#define DRVCTL_SET_OPTION 3

Drvctl cmd: Set driver options.

Arg is *struct option_t.

Definition at line 78 of file driver.h.

## HAVE_SERVER_VERSION

#define HAVE_SERVER_VERSION 1

Testable flag for get_server_version() presence.

Definition at line 36 of file driver.h.

## MAXPATHLEN

#define MAXPATHLEN 4096

Definition at line 32 of file driver.h.

## MIN_RECEIVE_TIMEOUT

#define MIN_RECEIVE_TIMEOUT 100000

Min value returned by receive_timeout.

Definition at line 35 of file receive.h.

## WBUF_SIZE

#define WBUF_SIZE 256

Definition at line 35 of file transmit.h.

## Function Documentation

## decode_all()

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

  remotes | Parsed 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 729 of file ir_remote.c.

## default_close()

int default_close | ( | void |  | ) |

For now, a placeholder.

Definition at line 52 of file driver.c.

## default_drvctl()

int default_drvctl | ( | unsigned int | cmd,
|  | void * | arg )

Return DRV_ERR_NOTIMPLEMENTED.

Definition at line 57 of file driver.c.

## default_open()

int default_open | ( | const char * | path | ) |

Stores path in drv.device if non-null.

Definition at line 37 of file driver.c.

## drv_handle_options()

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 63 of file driver.c.

## get_code_by_name()

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 393 of file ir_remote.c.

## get_decoding()

const struct ir_remote * get_decoding | ( | void |  | ) |

Return pointer to currently decoded remote.

Definition at line 850 of file ir_remote.c.

## get_filter_parameters()

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 189 of file ir_remote.c.

## get_frequency_range()

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 152 of file ir_remote.c.

## get_ir_remote()

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 247 of file ir_remote.c.

## get_server_version()

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.

## ir_remote_init()

void ir_remote_init | ( | int | use_dyncodes | ) |

Initiate: define if dynamic codes should be used.

Parameters

  use_dyncodes | Should normally reflect "lircd:dynamic-codes" option.

Definition at line 120 of file ir_remote.c.

## is_in_remotes()

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

  remotes | Head of linked list of remotes (using remote.next).
  remote | Pointer to remote to check

Returns
  1 if remote exists in remotes list, else 0

Parameters

  remotes |
  remote |

Returns

Definition at line 235 of file ir_remote.c.

## map_code()

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 279 of file ir_remote.c.

## map_gap()

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 325 of file ir_remote.c.

## ncode_dup()

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 65 of file ir_remote.c.

## ncode_free()

void ncode_free | ( | struct ir_ncode * | ncode | ) |

Dispose an ir_ncode instance obtained from ncode_dup().

Definition at line 100 of file ir_remote.c.

## rec_buffer_clear()

int rec_buffer_clear | ( | void |  | ) |

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

Definition at line 233 of file receive.c.

## rec_buffer_init()

void rec_buffer_init | ( | void |  | ) |

Clear internal buffer to pristine state.

Definition at line 213 of file receive.c.

## rec_buffer_reset_wptr()

void rec_buffer_reset_wptr | ( | void |  | ) |

Reset internal fifo's write pointer.

Definition at line 228 of file receive.c.

## rec_buffer_rewind()

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 218 of file receive.c.

## rec_buffer_set_logfile()

void rec_buffer_set_logfile | ( | FILE * | f | ) |

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

Parameters

  f | Open file to write on or NULL to disable logging.

Definition at line 200 of file receive.c.

## rec_set_update_mode()

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 65 of file receive.c.

## receive_decode()

int receive_decode | ( | struct ir_remote * | remote,
|  | struct decode_ctx_t * | ctx )

Decode data from remote.

Parameters

  ctx | Undefined on enter. On exit, the fields in the structure are defined.

Definition at line 1038 of file receive.c.

## send_buffer_data()

const lirc_t * send_buffer_data | ( | void |  | ) |

Returns
  Pointer to timing data in microseconds for pulses/spaces.

Definition at line 375 of file transmit.c.

## send_buffer_init()

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 58 of file transmit.c.

## send_buffer_length()

int send_buffer_length | ( | void |  | ) |

Do not document this function.

Returns
  Number of items accessible in array send_buffer_data().

Definition at line 369 of file transmit.c.

## send_buffer_put()

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

  remote | ir_remote containing code to send.
  code | ir_ncode to send.

Returns
  0 on failures, else 1.

Definition at line 351 of file transmit.c.

## send_buffer_sum()

lirc_t send_buffer_sum | ( | void |  | ) |

Returns
  Total length of send buffer in microseconds.

Definition at line 380 of file transmit.c.

## send_ir_ncode()

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

  remote | Currently active remote, used as database for timing, and as keeper of an internal state.
  code | IR code to be transmitted
  delay | If 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 819 of file ir_remote.c.

## set_waitfordata_func()

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

Set the function used by waitfordata().

Definition at line 165 of file receive.c.

## tty_clear()

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

Clear RTS and DTR control lines.

Parameters

  fd | File opened on a serial device.
  rts | If 0 ignored, else clears RTS.
  cts | If 0 ignored, else clears CTS.

Returns
  0 on errors, else 1.

Definition at line 525 of file serial.c.

## tty_create_lock()

int tty_create_lock | ( | const char * | name | ) |

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

. + name

Parameters

  name | Name 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.

## tty_delete_lock()

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.

## tty_read()

int tty_read | ( | int | fd,
|  | char * | byte )

Read a single byte from serial device.

Parameters

  fd | File opened on a serial device.
  byte | Pointer to byte to be read.

Returns
  -1 on errors, else 1 and data stored in *byte.

Definition at line 557 of file serial.c.

## tty_reset()

int tty_reset | ( | int | fd | ) |

Set the cfmakeraw termio options.

Parameters

  fd | File opened on a serial device.

Returns
  0 on errors, else 1.

Definition at line 54 of file serial.c.

## tty_set()

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

Set RTS and DTR control lines.

Parameters

  fd | File opened on a serial device.
  rts | If 0 ignored, else sets RTS.
  cts | If 0 ignored, else sets CTS.

Returns
  0 on errors, else 1.

Definition at line 511 of file serial.c.

## tty_setbaud()

int tty_setbaud | ( | int | fd,
|  | int | baud )

Set the speed a.

k. a. baudrate.

Parameters

  fd | File opened on a serial device.
  baud | Speed constant as defined for termios cfsetospeed e.g., B19200

Returns
  0 on errors, else 1.

Definition at line 120 of file serial.c.

## tty_setcsize()

int tty_setcsize | ( | int | fd,
|  | int | csize )

Set the character size.

Parameters

  fd | File opened on a serial device.
  Number | of data bits: CS5, CS6, CS7, or CS8.

Returns
  0 on errors, else 1.

Definition at line 265 of file serial.c.

## tty_setdtr()

int tty_setdtr | ( | int | fd,
|  | int | enable )

Set/clear DTR control line.

Parameters

  fd | File opened on a serial device.
  enable | If true sets DTR, else clears it.

Returns
  0 on errors, else 1.

Definition at line 93 of file serial.c.

## tty_setrtscts()

int tty_setrtscts | ( | int | fd,
|  | int | enable )

Set/clear CTS control line.

Parameters

  enable | If true sets CTS, else clears it.

Returns
  0 on errors, else 1.

Definition at line 72 of file serial.c.

## tty_write()

int tty_write | ( | int | fd,
|  | char | byte )

Write a single byte to serial device.

Parameters

  fd | File opened on a serial device.
  byte | Item to write.

Returns
  -1 on errors, else 1.

Definition at line 539 of file serial.c.

## tty_write_echo()

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

  fd | File opened on a serial device.
  byte | Byte 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.

## waitfordata()

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

  maxusec | timeout 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 171 of file receive.c.

## write_message()

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

  buffer | Formatted string on exit.
  size | Size 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 709 of file ir_remote.c.

## Variable Documentation

## last_remote

struct ir_remote* last_remote

extern

TODO.

Definition at line 55 of file ir_remote.c.

## repeat_code

struct ir_ncode* repeat_code

extern

Global pointer to the code currently repeating.

Defined in ir_remote.c.

Definition at line 59 of file ir_remote.c.

## repeat_remote

struct ir_remote* repeat_remote

extern

Global pointer to the remote that contains the code currently repeating.

Defined in ir_remote.c.

Definition at line 57 of file ir_remote.c.