Some code cleanup
This commit is contained in:
parent
c17e696566
commit
b934bb120c
11 changed files with 122 additions and 112 deletions
39
tty.h
39
tty.h
|
@ -1,43 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
/* Handles communication with a tty device. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <common.h>
|
||||
#include <client.h>
|
||||
#include <termios.h>
|
||||
|
||||
#define DEV_PATH 128
|
||||
#define TTY_DEV_PATH_LEN 128
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fd; /* tty file descriptor */
|
||||
struct termios ttysetdef; /* default tty termios settings */
|
||||
struct termios ttyset; /* tty termios settings */
|
||||
char path[DEV_PATH]; /* tty device path */
|
||||
char data[DATABUF_LEN]; /* buffer for data received from tty */
|
||||
int fd; /* tty device file descriptor */
|
||||
struct termios ttysetold; /* previous termios settings */
|
||||
struct termios ttyset; /* current termios settings */
|
||||
char path[TTY_DEV_PATH_LEN]; /* tty device path */
|
||||
char data[BUFFER_LEN]; /* buffer for received data */
|
||||
} tty_t;
|
||||
|
||||
/**
|
||||
* Opens the tty device and configures it.
|
||||
* The old device settings are saved.
|
||||
*
|
||||
* Returns:
|
||||
* - 0 on success
|
||||
* - negative errno value if an error occurred
|
||||
*/
|
||||
int tty_open(tty_t *tty_dev);
|
||||
|
||||
/**
|
||||
* Closes the tty device.
|
||||
* Closes the tty device connection.
|
||||
* Also applies the old device settings.
|
||||
*
|
||||
* Returns:
|
||||
* - 0 on success
|
||||
* - negative errno value if an error occurred
|
||||
*/
|
||||
int tty_close(tty_t *tty_dev);
|
||||
|
||||
/**
|
||||
* Reconfigures the tty device.
|
||||
*/
|
||||
int tty_reconfigure(tty_t *tty_dev, struct termios newttyset);
|
||||
|
||||
/**
|
||||
* Reads incoming data from tty device to tty data buffer.
|
||||
*
|
||||
* Returns:
|
||||
* - number of read bytes on success,
|
||||
* - negative errno value set by an error while readin
|
||||
* - negative errno value set by an error while reading
|
||||
*/
|
||||
int tty_read(tty_t *tty_dev);
|
||||
|
||||
|
@ -51,8 +56,8 @@ int tty_read(tty_t *tty_dev);
|
|||
int tty_write(tty_t *tty_dev, char *databuf, int datalen);
|
||||
|
||||
/**
|
||||
* Converts POSIX speed_t to a baud rate. The values of the
|
||||
* constants for speed_t are not themselves portable.
|
||||
* Converts POSIX speed_t to a baud rate.
|
||||
* The values of the constants for speed_t are not themselves portable.
|
||||
*/
|
||||
int speed_to_baud(speed_t speed);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue