Exemplo n.º 1
0
/* Update the timer display. This can also be called from updown.c */
void timer_update(void)
{
  static time_t t1, start;
  int dcd_support = P_HASDCD[0] == 'Y';

  /* See if we're online. */
  if ((!dcd_support && bogus_dcd)
      || (dcd_support && m_getdcd(portfd) == 1)) {
    /* We are online at the moment. */
    if (online < 0) {
      /* This was a transition from off to online */
      time(&start);
      t1 = start;
      online = 0;
#ifdef _DCDFLOW
      /* DCD has gotten high, we can turn on hw flow control */
      if (P_HASRTS[0] == 'Y')
        m_sethwf(portfd, 1);
#endif
    }
  } else {
    /* We are offline at the moment. */
#ifdef _DCDFLOW
    if (online >= 0) {
      /* DCD has dropped, turn off hw flow control. */
      m_sethwf(portfd, 0);
    }
#endif
    if (online >= 0 && old_online >= 0) {
      /* First update the timer for call duration.. */
      time(&t1);
      online = t1 - start;
    }
    /* ..and THEN notify that we are now offline */
    online = -1;
  }

  /* Update online time */
  if (online >= 0) {
    time(&t1);
    online = t1 - start;
  }

  update_status_time();
}
Exemplo n.º 2
0
/*
 * Set baudrate, parity and number of bits.
 */
void m_setparms(int fd, int baudr, char *par, int bit, int stopb,
                int hwf, int swf)
{
  int spd = -1;
  struct termios tty;
  tcgetattr(fd, &tty);

  switch (baudr) {
  case 9600:	spd = B9600;	break;
  case 19200:	spd = B19200;	break;
  case 38400:	spd = B38400;	break;
  default:	spd = B9600;	break;
  }

  if (spd != -1) {
    cfsetospeed(&tty, (speed_t)spd);
    cfsetispeed(&tty, (speed_t)spd);
  }

  switch (bit) {
    case 5:
      tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5;
      break;
    case 6:
      tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6;
      break;
    case 7:
      tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7;
      break;
    case 8:
    default:
      tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
      break;
  }
  /* Set into raw, no echo mode */
  tty.c_iflag =  IGNBRK;
  tty.c_lflag = 0;
  tty.c_oflag = 0;
  tty.c_cflag |= CLOCAL | CREAD;
//#ifdef _DCDFLOW
//  tty.c_cflag &= ~CRTSCTS;
//#endif
  tty.c_cc[VMIN] = 1;
  tty.c_cc[VTIME] = 5;

  if (swf)
    tty.c_iflag |= IXON | IXOFF;
  else
    tty.c_iflag &= ~(IXON|IXOFF|IXANY);

  tty.c_cflag &= ~(PARENB | PARODD);

 if (par[0] == 1) //输入和输出是奇校验
    tty.c_cflag |= (PARENB | PARODD);
 else  if (par[0] == 2)//输入和输出是偶校验
     tty.c_cflag |= PARENB;

  if (stopb == 2)
    tty.c_cflag |= CSTOPB;
  else
    tty.c_cflag &= ~CSTOPB;

  tcsetattr(fd, TCSANOW, &tty);

  //m_setrts(fd);

  m_sethwf(fd, hwf);

}