Example #1
0
static void display_speed(struct termios *mode, int fancy)
{
	if (cfgetispeed(mode) == 0 || cfgetispeed(mode) == cfgetospeed(mode))
		wrapf(fancy ? "speed %lu baud;" : "%lu\n",
			  baud_to_value(cfgetospeed(mode)));
	else
		wrapf(fancy ? "ispeed %lu baud; ospeed %lu baud;" : "%lu %lu\n",
			  baud_to_value(cfgetispeed(mode)),
			  baud_to_value(cfgetospeed(mode)));
	if (!fancy)
		current_col = 0;
}
Example #2
0
File: init.c Project: Fyleo/rtems
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 );
  }
}
Example #3
0
/**
 * 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");
}
Example #4
0
File: init.c Project: gedare/rtems
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 );
  }
}
Example #5
0
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;
}
Example #6
0
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
}
Example #7
0
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;
}
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);
        }
    }
}
Example #9
0
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 )) ;
}
Example #10
0
/*
 * 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;
}
Example #11
0
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;
}
Example #12
0
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);
}
Example #13
0
static BOOL _get_baud_rate(WINPR_COMM *pComm, SERIAL_BAUD_RATE *pBaudRate)
{
	int i;
	speed_t currentSpeed;
	struct termios currentState;

	ZeroMemory(&currentState, sizeof(struct termios));
	if (tcgetattr(pComm->fd, &currentState) < 0)
	{
		SetLastError(ERROR_IO_DEVICE);
		return FALSE;
	}

	currentSpeed = cfgetispeed(&currentState);

	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;
}
Example #14
0
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 */
}
Example #15
0
/*
 *  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;
}
Example #16
0
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)));
        }
    }
Example #17
0
File: stty.c Project: gzg1984/APUE
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;
}
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);
}
Example #19
0
/*
 * 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);
}
unsigned
TTYPort::GetBaudrate() const
{
  struct termios attr;
  if (tcgetattr(fd, &attr) < 0)
    return 0;

  return speed_t_to_baud_rate(cfgetispeed(&attr));
}
Example #21
0
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);
	
}
Example #22
0
/**
 * Compare termios structures in a structure-correct and portable way. This
 * function tries to be portable and thus may not compare all structure fields.
 *
 * @param term1					first termios structure
 * @param term2					second termios structure
 *
 * @return						True if term1 is equal to term2, false otherwise
 */
bool Serial::TermiosCompare(const struct termios &term1, const struct termios &term2) const {
	// compare input, output, control and local mode flags
	if (term1.c_iflag != term2.c_iflag || term1.c_oflag != term2.c_oflag ||
		term1.c_cflag != term2.c_cflag || term1.c_lflag != term2.c_lflag)
		return false;

	// compare input and output speeds
	if (cfgetispeed(&term1) != cfgetispeed(&term2) ||
		cfgetospeed(&term1) != cfgetospeed(&term2))
		return false;

	// compare control characters
	for (int i=0; i<NCCS; i++)
		if (term1.c_cc[i] != term2.c_cc[i])
			return false;

	return true;
}
Example #23
0
void encode_terminal_status(struct termios *terminal_status, value *dst)
{
    long *pc;
    int i;

    for (pc = terminal_io_descr; *pc != End; dst++) {
        switch (*pc++) {
            case Bool: {
                tcflag_t *src = choose_field(terminal_status, *pc++);
                tcflag_t msk = *pc++;
                *dst = Val_bool(*src & msk);
                break;
            }
            case Enum: {
                tcflag_t *src = choose_field(terminal_status, *pc++);
                int ofs = *pc++;
                int num = *pc++;
                tcflag_t msk = *pc++;
                for (i = 0; i < num; i++) {
                    if ((*src & msk) == pc[i]) {
                        *dst = Val_int(i + ofs);
                        break;
                    }
                }
                pc += num;
                break;
            }
            case Speed: {
                int which = *pc++;
                speed_t speed = 0;
                *dst =
                    Val_int(9600); /* in case no speed in speedtable matches */
                switch (which) {
                    case Output:
                        speed = cfgetospeed(terminal_status);
                        break;
                    case Input:
                        speed = cfgetispeed(terminal_status);
                        break;
                }
                for (i = 0; i < NSPEEDS; i++) {
                    if (speed == speedtable[i].speed) {
                        *dst = Val_int(speedtable[i].baud);
                        break;
                    }
                }
                break;
            }
            case Char: {
                int which = *pc++;
                *dst = Val_int(terminal_status->c_cc[which]);
                break;
            }
        }
    }
}
Example #24
0
/*******************************************************************************
**
** Function        userial_vendor_get_baud
**
** Description     Get current baud rate
**
** Returns         int
**
*******************************************************************************/
int userial_vendor_get_baud(void)
{
    if (vnd_userial.fd == -1)
    {
        ALOGE( "%s: uart port(%s) has not been opened", __FUNCTION__, BT_HS_UART_DEVICE );
        return -1;
    }

    return userial_tcio_baud_to_int(cfgetispeed(&vnd_userial.termios));
}
Example #25
0
File: serial.c Project: vyacht/gpsd
void gpsd_close(struct gps_device_t *session)
{
    if (!BAD_SOCKET(session->gpsdata.gps_fd)) {
	(void)ioctl(session->gpsdata.gps_fd, (unsigned long)TIOCNXCL);
	(void)tcdrain(session->gpsdata.gps_fd);
	if (isatty(session->gpsdata.gps_fd) != 0) {
	    /* force hangup on close on systems that don't do HUPCL properly */
	    /*@ ignore @*/
	    (void)cfsetispeed(&session->ttyset, (speed_t) B0);
	    (void)cfsetospeed(&session->ttyset, (speed_t) B0);
	    /*@ end @*/
	    (void)tcsetattr(session->gpsdata.gps_fd, TCSANOW,
			    &session->ttyset);
	}
	/* this is the clean way to do it */
	session->ttyset_old.c_cflag |= HUPCL;
	/*
	 * Don't revert the serial parameters if we didn't have to mess with
	 * them the first time.  Economical, and avoids tripping over an
	 * obscure Linux 2.6 kernel bug that disables threaded
	 * ioctl(TIOCMWAIT) on a device after tcsetattr() is called.
	 */
	if (cfgetispeed(&session->ttyset_old) != cfgetispeed(&session->ttyset) || (session->ttyset_old.c_cflag & CSTOPB) != (session->ttyset.c_cflag & CSTOPB)) {
	    /*
	     * If we revert, keep the most recent baud rate.
	     * Cuts down on autobaud overhead the next time.
	     */
	    /*@ ignore @*/
	    (void)cfsetispeed(&session->ttyset_old,
			      (speed_t) session->gpsdata.dev.baudrate);
	    (void)cfsetospeed(&session->ttyset_old,
			      (speed_t) session->gpsdata.dev.baudrate);
	    /*@ end @*/
	    (void)tcsetattr(session->gpsdata.gps_fd, TCSANOW,
			    &session->ttyset_old);
	}
	gpsd_report(session->context->debug, LOG_SPIN,
		    "close(%d) in gpsd_close(%s)\n",
		    session->gpsdata.gps_fd, session->gpsdata.dev.path);
	(void)close(session->gpsdata.gps_fd);
	session->gpsdata.gps_fd = -1;
    }
}
Example #26
0
unsigned
TTYPort::GetBaudrate() const
{
  assert(tty.IsDefined());

  struct termios attr;
  if (!tty.GetAttr(attr))
    return 0;

  return speed_t_to_baud_rate(cfgetispeed(&attr));
}
Example #27
0
void
gprint(struct termios *tp)
{
	const struct cchar *cp;

	(void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
	    tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
	for (cp = cchars1; cp->name; ++cp)
		(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
	(void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
}
Example #28
0
File: serial.c Project: biiont/gpsd
void gpsd_assert_sync(struct gps_device_t *session)
/* to be called when we want to register that we've synced with a device */
{
    /*
     * We've achieved first sync with the device. Remember the
     * baudrate so we can try it first next time this device
     * is opened.
     */
    if (session->saved_baud == -1)
	session->saved_baud = (int)cfgetispeed(&session->ttyset);
}
Example #29
0
static ptr_t
Termiorep(struct termios* termios)
{
	val_t fields[6];
	fields[0] = (val_t) termios->c_iflag;
	fields[1] = (val_t) termios->c_oflag;
	fields[2] = (val_t) termios->c_cflag;
	fields[3] = (val_t) termios->c_lflag;
	fields[4] = (val_t) cfgetispeed(termios);
	fields[5] = (val_t) cfgetospeed(termios);
	return alloc_record(fields, arraysize(fields));
}
Example #30
-1
/*
 * jx100_hispeed
 *   switch into a higher baud rate.  Unfortunately, the scanner only
 *   supports 9600, 19200, 57600, 115200, and 172800 baud.  On most Unix
 *   systems this means that the best we can use is 19200.  Linux provides
 *   means to access the UART at a lower level and enable the wierder
 *   rates.
 */
int jx100_hispeed ( int flag )
{
    if ( scanlines )
	return -1;
    if ( flag && cfgetispeed ( &tt ) == B9600 ) {
#ifdef linux
	/* set meaning of 38400 to be 115200 */
	if ( ioctl ( scanfd, TIOCGSERIAL, &serial ) < 0 )
	    return -1;
	serial.flags &= ~ASYNC_SPD_MASK;
	serial.flags |= ASYNC_SPD_VHI;
	if ( ioctl ( scanfd, TIOCSSERIAL, &serial ) < 0 )
	    return -1;
	if ( send_acked ( "I1" "115200,N,8,1" ) < 0 )
	    return -1;
	cfsetispeed ( &tt, B38400 );
	cfsetospeed ( &tt, B38400 );
#else
	if ( send_acked ( "I1" "19200,N,8,1" ) < 0 )
	    return -1;
	cfsetispeed ( &tt, B19200 );
	cfsetospeed ( &tt, B19200 );
#endif
	if ( tcsetattr ( scanfd, TCSANOW, &tt ) < 0 )
	    return -1;
    } else if ( !flag && cfgetispeed ( &tt ) != B9600 ) {
	if ( send_acked ( "I1" "9600,N,8,1" ) < 0 )
	    return -1;
	cfsetispeed ( &tt, B9600 );
	cfsetospeed ( &tt, B9600 );
	if ( tcsetattr ( scanfd, TCSANOW, &tt ) < 0 )
	    return -1;
#ifdef linux
	/* reset meaning of 38400 -- since we have set, assume can reset */
	(void) ioctl ( scanfd, TIOCGSERIAL, &serial );
	serial.flags &= ~ASYNC_SPD_MASK;
	(void) ioctl ( scanfd, TIOCSSERIAL, &serial );
#endif
    }
    return 0;
}