⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 term.h

📁 picocom-1.4,linux下的串口程序,类似与minicom.
💻 H
📖 第 1 页 / 共 2 页
字号:
/* vi: set sw=4 ts=4: * * term.h * * Simple terminal management library. Wraps termios(3), and * simplifies the logistics required for the reliable management and * control of terminals. * * Principles of operation: * * After the library is initialized one or more file-descriptors, can * be added to (and latter removed from) the list managed by the * library (framework). These file descriptos must be opened on * terminal devices. For every fd, the original settings of the * associated terminal device are saved by the library. These settings * are restored when the fd is removed from the framework, or at * porgram termination [by means of an atexit(3) handler installed by * the library], or at user request. The library maintains three * structures for every fd in the framework: The original settings * structure ("origtermios"), keeping the setings of the terminal * device when the respective filedes was added to the framework. The * current settings structure ("currtermios"), keeping the current * setings of the associated terminal device; and the next settings * structure ("nexttermios") which keeps settings to be applied to the * associated terminal device at a latter time, upon user request. * The "term_set_*" functions can be used to modify the device * settings stored in the nexttermios structure. Using functions * provided by the library the user can: Apply the nexttermios * settings to the device. Revert all changes made on nexttermios by * copying the currtermios structure to nexttermios. Reset the device, * by configuring it to the original settings, and copying origtermios * to currtermios and nexttermios. Refresh the device by rereading the * current settings from it and updating currtermios (to catch up with * changes made to the device by means outside of this framework). * * Interface summary: * * F term_lib_init  - library initialization * F term_add - add a filedes to the framework * F term_remove - remove a filedes from the framework * F term_erase - remove a filedes from the framework without reset * F term_replace - replace a fd w/o affecting the settings stuctures * F term_reset - revert a device to the settings in "origtermios" * F term_apply - configure a device to the settings in "nexttermios" * F term_revert - discard "nexttermios" by copying-over "currtermios" * F term_refresh - update "currtermios" from the device * F term_set_raw - set "nexttermios" to raw mode * F term_set_baudrate - set the baudrate in "nexttermios" * F term_set_parity - set the parity mode in "nexttermios" * F term_set_databits - set the databits in "nexttermios" * F term_set_flowcntrl - set the flowcntl mode in "nexttermios" * F term_set_hupcl - enable or disable hupcl in "nexttermios" * F term_set_local - set "nexttermios" to local or non-local mode * F term_set - set all params of "nexttermios" in a single stroke * F term_pulse_dtr - pulse the DTR line a device * F term_lower_dtr - lower the DTR line of a device * F term_raise_dtr - raise the DTR line of a device * F term_drain - drain the output from the terminal buffer * F term_flush - discard terminal input and output queue contents * F term_break - generate a break condition on a device * F term_strerror - return a string describing current error condition * F term_perror - print a string describing the current error condition * G term_errno - current error condition of the library * E term_errno_e - error condition codes * E parity_t - library supported parity types * E flocntrl_t - library supported folw-control modes * M MAX_TERM - maximum number of fds that can be managed * * by Nick Patavalis (npat@inaccessnetworks.com) * * originaly by Pantelis Antoniou (panto@intranet.gr), Nick Patavalis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA  * * $Id: term.h,v 1.1 2003/05/07 18:00:05 npat Exp $ */#ifndef TERM_H#define TERM_H/* M MAX_TERMS * * Maximum nuber of terminals that can be managed by the library. Keep * relatively low, since linear searches are used. Reasonable values * would be: 16, 32, 64, etc. */#define MAX_TERMS 16/* * E term_errno_e * * Library error-condition codes. These marked with "see errno" * correspond to system errors, so it makes sense to also check the * system's error-condition code (errno) in order to fully determine * what went wrong. * * See the error strings in "term.c" for a description of each. */enum term_errno_e {	TERM_EOK = 0,	TERM_ENOINIT,	TERM_EFULL,    TERM_ENOTFOUND,    TERM_EEXISTS,    TERM_EATEXIT,    TERM_EISATTY,    TERM_EFLUSH,     /* see errno */	TERM_EGETATTR,   /* see errno */	TERM_ESETATTR,   /* see errno */	TERM_EBAUD,	TERM_ESETOSPEED,	TERM_ESETISPEED,	TERM_EPARITY,	TERM_EDATABITS,	TERM_EFLOW,	TERM_EDTRDOWN,	TERM_EDTRUP,	TERM_EDRAIN,     /* see errno */	TERM_EBREAK};/* E parity_e * * Parity modes supported by the library: * * P_NONE - no patiry * P_EVEN - even parity * P_ODD  - odd parity */enum parity_e {	P_NONE, 	P_EVEN, 	P_ODD};/*  * E flowcntrl_e * * Flow control modes, supported by the library. * * FC_NONE - no flow control * FC_RTSCTS - RTS/CTS handshaking, also known as hardware  *     flow-control. * FC_XONXOFF  - xon/xoff flow control.  */enum flowcntrl_e {	FC_NONE, 	FC_RTSCTS, 	FC_XONXOFF};/***************************************************************************//* * G term_errno * * Keeps the current library error-condtion code */extern int term_errno;/***************************************************************************//* * F term_strerror * * Return a string descibing the current library error condition.  If * the error condition reflects a system error, then the respective * system-error description is appended at the end of the returned * string. The returned string points to a statically allocated buffer * that is overwritten with every call to term_strerror() * * Returns a string describing the current library (and possibly * system) error condition. */const char *term_strerror (int terrnum, int errnum);/* * F term_perror * * Emit a description of the current library (and possibly system) * error condition to the standard-error stream. The description is * prefixed by a user-supplied string. What is actually emmited is: *  *     <prefix><space><description>\n * * The description emitted is the string returned by term_strerror(). * * Returns the number of characters emmited to the standard-error * stream or a neagative on failure. */int term_perror (const char *prefix);/* F term_lib_init * * Initialize the library * * Initialize the library. This function must be called before any * attemt to use the library. If this function is called and the * library is already initialized, all terminals associated with the * file-descriptors in the framework will be reset to their original * settings, and the file-descriptors will be removed from the * framework. An atexit(3) handler is installed by the library which * resets and removes all managed terminals. * * Returns negative on failure, non-negative on success. This function * will only fail if the atexit(3) handler cannot be * installed. Failure to reset a terminal to the original settings is * not considered an error. */int term_lib_init (void);/* F term_add * * Add the filedes "fd" to the framework. The filedes must be opened * on a terminal device or else the addition will fail. The settings * of the terminal device associated with the filedes are read and * stored in the origtermios structure. * * Returns negative on failure, non-negative on success. */int term_add (int fd);/* F term_remove * * Remove the filedes "fd" from the framework. The device associated * with the filedes is reset to its original settings (those it had * when it was added to the framework) * * Return negative on failure, non-negative on success. The filedes is * always removed form the framework even if this function returns * failure, indicating that the device reset failed. */int term_remove (int fd);/* F term_erase * * Remove the filedes "fd" from the framework. The device associated * with the filedes is *not* reset to its original settings. * * Return negative on failure, non-negative on success. The only * reason for failure is the filedes not to be found. */int term_erase (int fd);/* F term_replace * * Replace a managed filedes without affecting the associated settings * structures. The "newfd" takes the place of "oldfd". "oldfd" is * removed from the framework without the associated device beign * reset (it is most-likely no longer connected to a device anyway, * and reset would fail). The device associated with "newfd" is * configured with "oldfd"s current settings. * * Returns negative on failure, non-negative on success. In case of * failure "oldfd" is not removed from the framework, and no * replacement takes place. * * The usual reason to replace the filedes of a managed terminal is

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -