本文整理汇总了C++中cfgetispeed函数的典型用法代码示例。如果您正苦于以下问题:C++ cfgetispeed函数的具体用法?C++ cfgetispeed怎么用?C++ cfgetispeed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cfgetispeed函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test_termios_cfsetspeed
static void test_termios_cfsetspeed(void)
{
int i;
int status;
speed_t speed;
struct termios term;
tcflag_t bad;
bad = CBAUD << 1;
memset( &term, '\0', sizeof(term) );
puts( "cfsetspeed(BAD BAUD) - EINVAL" );
status = cfsetspeed( &term, bad );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == EINVAL );
for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) {
memset( &term, '\0', sizeof(term) );
printf(
"cfsetspeed(B%" PRIdrtems_termios_baud_t ") - OK\n",
baud_table[i].baud
);
status = cfsetspeed( &term, baud_table[i].constant );
rtems_test_assert( !status );
printf(
"cfgetspeed(B%" PRIdrtems_termios_baud_t ") - checking both inspeed and outspeed - OK\n",
baud_table[i].baud
);
speed = cfgetispeed( &term );
rtems_test_assert( speed == baud_table[i].constant );
speed = cfgetospeed( &term );
rtems_test_assert( speed == baud_table[i].constant );
}
}
开发者ID:Fyleo,项目名称:rtems,代码行数:35,代码来源:init.c
示例2: switch
/**
* Get the baud rate of the serial device.
*
* @exception std::logic_error This exception should never occur. It is thrown
* when the device somehow entered a mode that is
* not valid according to the <termios.h>
*
* @return baud rate
*/
unsigned int Serial::Baud() const {
switch(cfgetispeed(&mode)) {
case B50: return 50;
case B75: return 75;;
case B110: return 110;
case B134: return 134;
case B150: return 150;
case B200: return 200;
case B300: return 300;
case B600: return 600;
case B1200: return 1200;
case B1800: return 1800;
case B2400: return 2400;
case B4800: return 4800;
case B9600: return 9600;
case B19200: return 19200;
case B38400: return 38400;
case B57600: return 57600;
case B115200: return 115200;
case B230400: return 230400;
};
// should be impossible (can happen if there are errors in termios code)
throw std::logic_error("Device mode corrupt");
}
开发者ID:ivannavarrete,项目名称:satori,代码行数:34,代码来源:serial_u.cpp
示例3: test_termios_cfinspeed
static void test_termios_cfinspeed(void)
{
int i;
int sc;
speed_t speed;
struct termios term;
speed_t bad;
bad = B921600 << 1;
memset( &term, '\0', sizeof(term) );
puts( "cfsetispeed(BAD BAUD) - EINVAL" );
sc = cfsetispeed( &term, bad );
rtems_test_assert( sc == -1 );
rtems_test_assert( errno == EINVAL );
for (i=0 ; baud_table[i].constant != INVALID_CONSTANT ; i++ ) {
memset( &term, '\0', sizeof(term) );
printf(
"cfsetispeed(B%" PRIdrtems_termios_baud_t ") - OK\n",
baud_table[i].baud
);
sc = cfsetispeed( &term, baud_table[i].constant );
rtems_test_assert( !sc );
printf(
"cfgetispeed(B%" PRIdrtems_termios_baud_t ") - OK\n",
baud_table[i].baud
);
speed = cfgetispeed( &term );
rtems_test_assert( speed == baud_table[i].constant );
}
}
开发者ID:gedare,项目名称:rtems,代码行数:32,代码来源:init.c
示例4: gc_free_termios
size_t
gc_free_termios (SCM x)
{
struct termios *gp;
scm_assert_smob_type (termios_tag, x);
gp = (struct termios *) SCM_SMOB_DATA (x);
assert (gp != NULL);
if (0)
{
fprintf (stderr, "Freeing termios at %p\n", gp);
fprintf (stderr, "Flags: I %u O %u C %u L %u\n", gp->c_iflag,
gp->c_oflag, gp->c_cflag, gp->c_lflag);
fprintf (stderr, "Speed: O %u I %u\n", cfgetospeed(gp),
cfgetispeed(gp));
fflush (stderr);
sleep (1);
}
scm_gc_free (gp, sizeof (struct termios), "termios");
SCM_SET_SMOB_DATA (x, NULL);
return 0;
}
开发者ID:guildhall,项目名称:guile-ncurses,代码行数:27,代码来源:extra_type.c
示例5: TerminalSpeeds
void TerminalSpeeds(long *ispeed, long *ospeed) {
#ifdef __WIN32__
*ispeed = B9600;
*ospeed = B9600;
#else
register struct termspeeds *tp;
register long in, out;
out = cfgetospeed(&old_tc);
in = cfgetispeed(&old_tc);
if (in == 0)
in = out;
tp = termspeeds;
while ((tp->speed != -1) && (tp->value < in))
tp++;
*ispeed = tp->speed;
tp = termspeeds;
while ((tp->speed != -1) && (tp->value < out))
tp++;
*ospeed = tp->speed;
#endif
}
开发者ID:gordonchaffee,项目名称:expectnt,代码行数:25,代码来源:terminal.cpp
示例6: getbaud
int getbaud(int fd) {
struct termios termAttr;
int inputSpeed = -1;
speed_t baudRate;
tcgetattr(fd, &termAttr);
/* Get the input speed. */
baudRate = cfgetispeed(&termAttr);
switch (baudRate) {
case B0: inputSpeed = 0; break;
case B50: inputSpeed = 50; break;
case B110: inputSpeed = 110; break;
case B134: inputSpeed = 134; break;
case B150: inputSpeed = 150; break;
case B200: inputSpeed = 200; break;
case B300: inputSpeed = 300; break;
case B600: inputSpeed = 600; break;
case B1200: inputSpeed = 1200; break;
case B1800: inputSpeed = 1800; break;
case B2400: inputSpeed = 2400; break;
case B4800: inputSpeed = 4800; break;
case B9600: inputSpeed = 9600; break;
case B19200: inputSpeed = 19200; break;
case B38400: inputSpeed = 38400; break;
case B115200: inputSpeed = 115200; break;
}
return inputSpeed;
}
开发者ID:gcapiel,项目名称:LED-Print,代码行数:27,代码来源:serprt.c
示例7: strerror
void
TtyElmoConnection::_setBaud(speed_t baudValue) {
if (baudValue != B9600 && baudValue != B19200 && baudValue != B38400 &&
baudValue != B57600) {
ELOG << __PRETTY_FUNCTION__ << ": bad baud value 0" << std::oct <<
baudValue << std::dec << " (octal), using B9600";
baudValue = B9600;
}
// Get current settings, change the port speed, and send the new settings.
struct termios ios;
if (tcgetattr(_fd, &ios) == -1) {
ELOG << __PRETTY_FUNCTION__ << ": error getting " << _ttyDev <<
" attributes: " << strerror(errno);
exit(1);
}
// Change speed if the current speed is not the same as the requested one
if (cfgetispeed(&ios) == baudValue && cfgetospeed(&ios) == baudValue) {
DLOG << __PRETTY_FUNCTION__ << ": requested baud rate matches current";
} else {
ILOG << "Changing speed on " << _ttyDev << " to " << _BaudToText(baudValue);
cfsetspeed(&ios, baudValue);
// Send new I/O settings
if (tcsetattr(_fd, TCSAFLUSH, &ios) == -1) {
ELOG << __PRETTY_FUNCTION__ << ": error setting " << _ttyDev <<
" attributes: " << strerror(errno);
exit(1);
}
}
}
开发者ID:NCAR,项目名称:HCR_instrument,代码行数:31,代码来源:TtyElmoConnection.cpp
示例8: throw
inline
SerialPort::BaudRate
SerialPort::SerialPortImpl::GetBaudRate() const
throw( SerialPort::NotOpen,
std::runtime_error )
{
//
// Make sure that the serial port is open.
//
if ( ! this->IsOpen() )
{
throw SerialPort::NotOpen( ERR_MSG_PORT_NOT_OPEN ) ;
}
//
// Read the current serial port settings.
//
termios port_settings ;
if ( tcgetattr( mFileDescriptor,
&port_settings ) < 0 )
{
throw std::runtime_error( strerror(errno) ) ;
}
//
// Obtain the input baud rate from the current settings.
//
return SerialPort::BaudRate(cfgetispeed( &port_settings )) ;
}
开发者ID:Nolan330,项目名称:CS292,代码行数:27,代码来源:SerialPort.cpp
示例9: uarthandler_getBaud
/*
* uarthandler_getBaud(): Function to get the Baud rate
*/
int uarthandler_getBaud(int fd)
{
struct termios termAttr;
int inRate = -1;
speed_t baudRate;
tcgetattr(fd, &termAttr);
baudRate = cfgetispeed(&termAttr); //get the input speed
switch (baudRate)
{
case B0: inRate = 0; break;
case B50: inRate = 50; break;
case B110: inRate = 110; break;
case B134: inRate = 134; break;
case B150: inRate = 150; break;
case B200: inRate = 200; break;
case B300: inRate = 300; break;
case B600: inRate = 600; break;
case B1200: inRate = 1200; break;
case B1800: inRate = 1800; break;
case B2400: inRate = 2400; break;
case B4800: inRate = 4800; break;
case B9600: inRate = 9600; break;
case B19200: inRate = 19200; break;
case B38400: inRate = 38400; break;
case B115200: inRate = 115200; break;
}
return inRate;
}
开发者ID:owalch,项目名称:oliver,代码行数:31,代码来源:uartHandler.c
示例10: _lib7_P_TTY_tcgetattr
Val _lib7_P_TTY_tcgetattr (Task* task, Val arg) {
//=====================
//
// Mythryl type: Int -> (Unt, Unt, Unt, Unt, String, Unt, Unt)
//
// Get parameters associated with tty.
//
// NOTE: the calls to cfget[io] speed by making the code more OS-dependent
// and using the package of struct termios.
//
// This fn gets bound as tcgetattr in:
//
// src/lib/std/src/psx/posix-tty.pkg
ENTER_MYTHRYL_CALLABLE_C_FN(__func__);
int fd = TAGGED_INT_TO_C_INT( arg );
struct termios data;
RELEASE_MYTHRYL_HEAP( task->hostthread, __func__, NULL);
//
int status = tcgetattr( fd, &data );
//
RECOVER_MYTHRYL_HEAP( task->hostthread, __func__ );
if (status < 0) return RAISE_SYSERR__MAY_HEAPCLEAN(task, status, NULL);
Val iflag = make_one_word_unt(task, data.c_iflag ); Roots roots1 = { &iflag, NULL };
Val oflag = make_one_word_unt(task, data.c_oflag ); Roots roots2 = { &oflag, &roots1 };
Val cflag = make_one_word_unt(task, data.c_cflag ); Roots roots3 = { &cflag, &roots2 };
Val lflag = make_one_word_unt(task, data.c_lflag ); Roots roots4 = { &lflag, &roots3 };
Val ispeed = make_one_word_unt(task, cfgetispeed (&data) ); Roots roots5 = { &ispeed, &roots4 };
Val ospeed = make_one_word_unt(task, cfgetospeed (&data) ); Roots roots6 = { &ospeed, &roots5 };
Val cc = allocate_nonempty_ascii_string__may_heapclean (task, NCCS, &roots6 );
memcpy(
GET_VECTOR_DATACHUNK_AS( void*, cc ),
data.c_cc,
NCCS
);
// Construct the result vector:
//
set_slot_in_nascent_heapchunk (task, 0, MAKE_TAGWORD(PAIRS_AND_RECORDS_BTAG, 7));
set_slot_in_nascent_heapchunk (task, 1, iflag);
set_slot_in_nascent_heapchunk (task, 2, oflag);
set_slot_in_nascent_heapchunk (task, 3, cflag);
set_slot_in_nascent_heapchunk (task, 4, lflag);
set_slot_in_nascent_heapchunk (task, 5, cc);
set_slot_in_nascent_heapchunk (task, 6, ispeed);
set_slot_in_nascent_heapchunk (task, 7, ospeed);
Val result = commit_nascent_heapchunk (task, 7);
EXIT_MYTHRYL_CALLABLE_C_FN(__func__);
return result;
}
开发者ID:rev22,项目名称:mythryl-1,代码行数:60,代码来源:tcgetattr.c
示例11: mod_termios_tcgetattr
STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) {
struct termios term;
int fd = mp_obj_get_int(fd_in);
int res = tcgetattr(fd, &term);
RAISE_ERRNO(res, errno);
mp_obj_list_t *r = MP_OBJ_TO_PTR(mp_obj_new_list(7, NULL));
r->items[0] = MP_OBJ_NEW_SMALL_INT(term.c_iflag);
r->items[1] = MP_OBJ_NEW_SMALL_INT(term.c_oflag);
r->items[2] = MP_OBJ_NEW_SMALL_INT(term.c_cflag);
r->items[3] = MP_OBJ_NEW_SMALL_INT(term.c_lflag);
r->items[4] = MP_OBJ_NEW_SMALL_INT(cfgetispeed(&term));
r->items[5] = MP_OBJ_NEW_SMALL_INT(cfgetospeed(&term));
mp_obj_list_t *cc = MP_OBJ_TO_PTR(mp_obj_new_list(NCCS, NULL));
r->items[6] = MP_OBJ_FROM_PTR(cc);
for (int i = 0; i < NCCS; i++) {
if (i == VMIN || i == VTIME) {
cc->items[i] = MP_OBJ_NEW_SMALL_INT(term.c_cc[i]);
} else {
// https://docs.python.org/3/library/termios.html says value is *string*,
// but no way unicode chars could be there, if c_cc is defined to be a
// a "char". But it's type is actually cc_t, which can be anything.
// TODO: For now, we still deal with it like that.
cc->items[i] = mp_obj_new_bytes((byte*)&term.c_cc[i], 1);
}
}
return MP_OBJ_FROM_PTR(r);
}
开发者ID:fabaff,项目名称:micropython,代码行数:30,代码来源:modtermios.c
示例12: _get_baud_rate
static BOOL _get_baud_rate(WINPR_COMM *pComm, SERIAL_BAUD_RATE *pBaudRate)
{
int i;
speed_t currentSpeed;
struct termios currentState;
ZeroMemory(¤tState, sizeof(struct termios));
if (tcgetattr(pComm->fd, ¤tState) < 0)
{
SetLastError(ERROR_IO_DEVICE);
return FALSE;
}
currentSpeed = cfgetispeed(¤tState);
for (i=0; _BAUD_TABLE[i][0]<_BAUD_TABLE_END; i++)
{
if (_BAUD_TABLE[i][0] == currentSpeed)
{
pBaudRate->BaudRate = _BAUD_TABLE[i][1];
return TRUE;
}
}
CommLog_Print(WLOG_WARN, "could not find a matching baud rate for the speed 0x%x", currentSpeed);
SetLastError(ERROR_INVALID_DATA);
return FALSE;
}
开发者ID:FreeRDP,项目名称:FreeRDP,代码行数:28,代码来源:comm_serial_sys.c
示例13: TerminalSpeeds
void
TerminalSpeeds (long *ispeed, long *ospeed)
{
#ifdef DECODE_BAUD
struct termspeeds *tp;
#endif /* DECODE_BAUD */
long in, out;
out = cfgetospeed (&old_tc);
in = cfgetispeed (&old_tc);
if (in == 0)
in = out;
#ifdef DECODE_BAUD
tp = termspeeds;
while ((tp->speed != -1) && (tp->value < in))
tp++;
*ispeed = tp->speed;
tp = termspeeds;
while ((tp->speed != -1) && (tp->value < out))
tp++;
*ospeed = tp->speed;
#else /* DECODE_BAUD */
*ispeed = in;
*ospeed = out;
#endif /* DECODE_BAUD */
}
开发者ID:a5216652166,项目名称:rcp100,代码行数:28,代码来源:sys_bsd.c
示例14: PXFCFGETISPEED
/*
* PXFCFGETISPEED -- get input baud rate
* PXFCFSETISPEED -- set input baud rate
* PXFCFGETOSPEED -- get output baud rate
* PXFCFSETOSPEED -- set output baud rate
* (section 7.1.3 of Posix 1003.9-1992)
*
* Synopsis:
*
* SUBROUTINE PXFCFGETISPEED(jtermios, iospeed, ierror)
* INTEGER jtermios, iospeed, ierror
*
* SUBROUTINE PXFCFSETISPEED(jtermios, ispeed, ierror)
* INTEGER jtermios, ispeed, ierror
*
* SUBROUTINE PXFCFGETOSPEED(jtermios, iospeed, ierror)
* INTEGER jtermios, iospeed, ierror
*
* SUBROUTINE PXFCFSETOSPEED(jtermios, ispeed, ierror)
* INTEGER jtermios, ispeed, ierror
*
* Description:
*
* The PXFCF...SPEED routines use the c functions to get or set the
* baud rates in the termios structure. Symbolic names for the baud
* rates can be obtained through calls to PXFCONST.
*
* The arguments are:
*
* jtermios - default integer input variable containing a handle
* created by PXFSTRUCTCREATE('termios',...).
* ispeed - default input integer variable for a baud rate.
* iospeed - default output integer variable specifying a baud
* rate.
* ierror - default integer output variable that contains zero
* if the operation was successful or nonzero if the
* operation was not successful.
*
* PXFCF...SPEED routines may return one of the following error values:
* No errors are returned for bad baud rates. The PXFCFSETISPEED and
* PXFCFSETOSPEED return 0 if successful; otherwise, they return -1.
*
* EBADHANDLE The jtermios argument is invalid.
*
* EINVAL Problems occurred with the baud rate.
*
*/
#include <fortran.h>
#include <liberrno.h>
#include <string.h>
#include <sys/termios.h>
#include <termios.h>
#include "pxfstruct.h"
#include "table.h"
#ifdef _UNICOS
void
PXFCFGETISPEED(
#else /* _UNICOS */
void
pxfcfgetispeed_(
#endif /* _UNICOS */
_f_int *jtermios,
_f_int *iospeed,
_f_int *ierror)
{
speed_t stat;
struct pxfhandle pxfhand;
struct termios *trmios;
*ierror = 0;
*iospeed = 0;
pxfhand = _pxfhandle_table_lookup(&_pxfhandle_table, *jtermios);
if (pxfhand.pxfstructptr == NULL || pxfhand.pxftype != PXF_TERMIOS) {
*ierror = EBADHANDLE;
return;
}
trmios = pxfhand.pxfstructptr;
if (stat = cfgetispeed(trmios) == -1)
*ierror = EINVAL;
else
*iospeed = stat;
return;
}
开发者ID:manojxantony,项目名称:compiler,代码行数:85,代码来源:pxfcfgetospeed.c
示例15: auxShiftBaud
void auxShiftBaud(char* cmd)
{
int newBaud = parseBaudRates(cmd);
/* Save the current serial port settings */
struct termios newtio;
tcgetattr(serialfd, &newtio);
/* Set the input/output baud rates for this device */
cfsetispeed(&newtio, newBaud);
cfsetospeed(&newtio, newBaud);
/* Clean the modem line and activate new port settings */
tcflush(serialfd, TCIOFLUSH);
tcsetattr(serialfd, TCSANOW, &newtio);
if (tcgetattr(serialfd, &newtio) != 0)
{
printf("ERROR: Bad termoios; Rate change may have failed?\n");
return;
}
if (OUTDEBUG)
{
printf("DEBUG: changed to %s\n",see_speed(cfgetispeed(&newtio)));
}
}
开发者ID:e-p-katz,项目名称:create.clj,代码行数:27,代码来源:serialdaemon.c
示例16: main
int main(int argc,char** argv)
{
struct termios ts;
tcgetattr(0,&ts);
printf("input speed %d \n",cfgetispeed(&ts));
printf("ouput speed %d \n",cfgetospeed(&ts));
return 0;
}
开发者ID:gzg1984,项目名称:APUE,代码行数:8,代码来源:stty.c
示例17: cfgetispeed_intrin
static void cfgetispeed_intrin (struct termios *t)
{
unsigned int speed, bspeed;
bspeed = cfgetispeed (t);
if (0 == map_bspeed_to_speed (bspeed, &speed))
(void) SLang_push_uint (speed);
}
开发者ID:kernelzilla,项目名称:android_external_libslang,代码行数:8,代码来源:termios-module.c
示例18: ssh_tty_make_modes
/*
* Encodes terminal modes for the terminal referenced by fd
* or tiop in a portable manner, and appends the modes to a packet
* being constructed.
*/
void
ssh_tty_make_modes(struct ssh *ssh, int fd, struct termios *tiop)
{
struct termios tio;
struct sshbuf *buf;
int r, ibaud, obaud;
if ((buf = sshbuf_new()) == NULL)
fatal("%s: sshbuf_new failed", __func__);
if (tiop == NULL) {
if (fd == -1) {
debug("%s: no fd or tio", __func__);
goto end;
}
if (tcgetattr(fd, &tio) == -1) {
logit("tcgetattr: %.100s", strerror(errno));
goto end;
}
} else
tio = *tiop;
/* Store input and output baud rates. */
obaud = speed_to_baud(cfgetospeed(&tio));
ibaud = speed_to_baud(cfgetispeed(&tio));
if ((r = sshbuf_put_u8(buf, TTY_OP_OSPEED)) != 0 ||
(r = sshbuf_put_u32(buf, obaud)) != 0 ||
(r = sshbuf_put_u8(buf, TTY_OP_ISPEED)) != 0 ||
(r = sshbuf_put_u32(buf, ibaud)) != 0)
fatal("%s: buffer error: %s", __func__, ssh_err(r));
/* Store values of mode flags. */
#define TTYCHAR(NAME, OP) \
if ((r = sshbuf_put_u8(buf, OP)) != 0 || \
(r = sshbuf_put_u32(buf, tio.c_cc[NAME])) != 0) \
fatal("%s: buffer error: %s", __func__, ssh_err(r)); \
#define SSH_TTYMODE_IUTF8 42 /* for SSH_BUG_UTF8TTYMODE */
#define TTYMODE(NAME, FIELD, OP) \
if (OP == SSH_TTYMODE_IUTF8 && (datafellows & SSH_BUG_UTF8TTYMODE)) { \
debug3("%s: SSH_BUG_UTF8TTYMODE", __func__); \
} else if ((r = sshbuf_put_u8(buf, OP)) != 0 || \
(r = sshbuf_put_u32(buf, ((tio.FIELD & NAME) != 0))) != 0) \
fatal("%s: buffer error: %s", __func__, ssh_err(r)); \
#include "ttymodes.h"
#undef TTYCHAR
#undef TTYMODE
end:
/* Mark end of mode data. */
if ((r = sshbuf_put_u8(buf, TTY_OP_END)) != 0 ||
(r = sshpkt_put_stringb(ssh, buf)) != 0)
fatal("%s: packet error: %s", __func__, ssh_err(r));
sshbuf_free(buf);
}
开发者ID:mfriedl,项目名称:openssh,代码行数:63,代码来源:ttymodes.c
示例19: speed_t_to_baud_rate
unsigned
TTYPort::GetBaudrate() const
{
struct termios attr;
if (tcgetattr(fd, &attr) < 0)
return 0;
return speed_t_to_baud_rate(cfgetispeed(&attr));
}
开发者ID:joachimwieland,项目名称:xcsoar-jwieland,代码行数:9,代码来源:TTYPort.cpp
示例20: getBaudRate
speed_t getBaudRate(int fd){
struct termios options;
if(tcgetattr(fd, &options)<0){
do_log("getBaudRate","Couldn't load Options",LOG_LEVEL_ERROR,LOG_TYPE_SIGNAL);
return -1;
}
return cfgetispeed(&options);
}
开发者ID:Doeme,项目名称:MySmartUSB-MK3-Interface,代码行数:9,代码来源:dev.c
注:本文中的cfgetispeed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论