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

📄 pppchat.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
            /*---------------------------------------------------------*/            /* Continue with next command.                             */            /*---------------------------------------------------------*/            Ppp->chat.minor_state = INTERPRETING;            Ppp->chat.script = Ppp->chat.saved;            return 1;          }          /*-----------------------------------------------------------*/          /* Else return from substring to main send string.           */          /*-----------------------------------------------------------*/          else if (Ppp->chat.saved)          {            Ppp->chat.send = Ppp->chat.saved;            Ppp->chat.saved = NULL;            return 1;          }          /*-----------------------------------------------------------*/          /* Else NULL found in main send string.                      */          /*-----------------------------------------------------------*/          else          {            fatal_error("NULL in send string");            return 0;          }        }        /*-------------------------------------------------------------*/        /* Output the character, returning if buffer is full.          */        /*-------------------------------------------------------------*/        if (put_char(ch))          return 0;      }      /*---------------------------------------------------------------*/      /* Process switch back to INTERPRETING.                          */      /*---------------------------------------------------------------*/      Ppp->chat.minor_state = INTERPRETING;      Ppp->chat.script = Ppp->chat.send + 1;      return 1;    case EXPECTING:      /*---------------------------------------------------------------*/      /* Process receive buffer, looking for match.                    */      /*---------------------------------------------------------------*/      for (;;)      {        /*-------------------------------------------------------------*/        /* Record where next received character will be written.       */        /*-------------------------------------------------------------*/        cp = (char *)Ppp->chat.uart_put;        /*-------------------------------------------------------------*/        /* Break if receive buffer matches expected script string.     */        /*-------------------------------------------------------------*/        if (received(&Ppp->chat.match))          break;        /*-------------------------------------------------------------*/        /* Return if receive buffer matches an abort string.           */        /*-------------------------------------------------------------*/        for (i = 0; i < CHAT_ABORTS; ++i)        {          if (Ppp->chat.abort[i].string && received(&Ppp->chat.abort[i]))          {#if PPP_TRACE            pppLogn("CHAT received abort string \'%s",                    string(Ppp->chat.abort[i].string));#endif            chat_retry();            return 0;          }        }        /*-------------------------------------------------------------*/        /* If all received characters have been checked, wait for more.*/        /*-------------------------------------------------------------*/        isrMask();        if (cp == Ppp->chat.uart_put)        {          Ppp->chat.minor_state = WAIT_FOR_CHAR;          isrUnmask();          return 0;        }        isrUnmask();      }#if PPP_TRACE      /*---------------------------------------------------------------*/      /* Log that expectation succeeded if trace is enabled.           */      /*---------------------------------------------------------------*/      pppLogn("CHAT -- got it");#endif      /*---------------------------------------------------------------*/      /* Stop timer and switch back to INTERPRETING.                   */      /*---------------------------------------------------------------*/      NetTimerStop(&Ppp->chat.timer);      Ppp->chat.minor_state = INTERPRETING;      Ppp->chat.script += Ppp->chat.match.length + 1;      return 1;    case WAIT_FOR_IDLE:      /*---------------------------------------------------------------*/      /* Transmitter now idle, complete bringup or shutdown.           */      /*---------------------------------------------------------------*/      if (Ppp->chat.major_state == FINISHING)        pppFinish();      else        chat_up();      return 0;  }  return 0;}/***********************************************************************//*    received: Compares receive buffer contents with string           *//*                                                                     *//*       Input: match = pointer to data for expect or abort string     *//*                                                                     *//*     Returns: TRUE iff match is found                                *//*                                                                     *//***********************************************************************/static int received(Match *match){  int i;  char *rp, *ep;  /*-------------------------------------------------------------------*/  /* Loop while the receive buffer holds untested substrings.          */  /*-------------------------------------------------------------------*/  for (;;)  {    /*-----------------------------------------------------------------*/    /* Calculate number of untested characters.                        */    /*-----------------------------------------------------------------*/    isrMask();    i = Ppp->chat.uart_put - match->compare;    if (i < 0) i += RBUF_LEN;    isrUnmask();    /*-----------------------------------------------------------------*/    /* Return if not enough characters received.                       */    /*-----------------------------------------------------------------*/    if (i < match->length)      return FALSE;    /*-----------------------------------------------------------------*/    /* Loop to test match string one character at a time.              */    /*-----------------------------------------------------------------*/    rp = match->compare;    ep = match->string;    for (;; ++ep)    {      /*---------------------------------------------------------------*/      /* If expected pointer equals '\'', we have a match.             */      /*---------------------------------------------------------------*/      if (*ep == '\'')      {        match->compare = rp;  /* update compare pointer */        return TRUE;      }      /*---------------------------------------------------------------*/      /* Break if a mismatch is found.                                 */      /*---------------------------------------------------------------*/      if (*rp != *ep)        break;      /*---------------------------------------------------------------*/      /* Advance receive buffer pointer, wrapping around if necessary. */      /*---------------------------------------------------------------*/      if (rp == &Ppp->chat.rcv_buf[RBUF_LEN - 1])        rp = Ppp->chat.rcv_buf;      else        ++rp;    }    /*-----------------------------------------------------------------*/    /* Enough characters there, but no match. Advance compare pointer. */    /*-----------------------------------------------------------------*/    if (Ppp->chat.match.compare == &Ppp->chat.rcv_buf[RBUF_LEN - 1])      match->compare = Ppp->chat.rcv_buf;    else      ++match->compare;  }}/***********************************************************************//*    put_char: called by CHAT to output one character                 *//*                                                                     *//*     Returns: -1 if error, else 0                                    *//*                                                                     *//***********************************************************************/static int put_char(int ch){  /*-------------------------------------------------------------------*/  /* Ensure a space is available.                                      */  /*-------------------------------------------------------------------*/  isrMask();  if (Ppp->chat.sb_count == SBUF_LEN)  {    isrUnmask();    Ppp->chat.minor_state = WAIT_FOR_SPACE;    return -1;  }  /*-------------------------------------------------------------------*/  /* Increment character count and write next character.               */  /*-------------------------------------------------------------------*/  ++Ppp->chat.sb_count;  *Ppp->chat.output = ch;  /*-------------------------------------------------------------------*/  /* Start transmitter if idle.                                        */  /*-------------------------------------------------------------------*/  if (Ppp->uart.idle)  {    Ppp->uart.idle = FALSE;    isrUnmask();    Ppp->public.start_tx();  }  else    isrUnmask();  /*-------------------------------------------------------------------*/  /* Advance CHAT's "put" pointer, wrapping around as necessary.       */  /*-------------------------------------------------------------------*/  if (Ppp->chat.output == &Ppp->chat.snd_buf[SBUF_LEN - 1])    Ppp->chat.output = Ppp->chat.snd_buf;  else    ++Ppp->chat.output;  return 0;}/***********************************************************************//*    data_req: Called by serial driver to get data to transmit        *//*                                                                     *//*      Inputs: handle = pointer to PPP control block                  *//*              dst = pointer to driver's transmit buffer              *//*              room = amount of room left in transmit buffer          *//*              increment = 0 if to FIFO, 1 if to buffer               *//*                                                                     *//*        Note: May be called by either the TCP/IP task or an ISR      *//*                                                                     *//*     Returns: Number of characters placed in transmit buffer         *//*                                                                     *//***********************************************************************/static int data_req(void *handle, ui8 *dst, int room, int increment){  PPP ppp = handle;  int initial_room = room;  /*-------------------------------------------------------------------*/  /* Check if there is nothing to send right now.                      */  /*-------------------------------------------------------------------*/  if (ppp->chat.sb_count == 0)  {    /*-----------------------------------------------------------------*/    /* Mark that transmitter is idle.                                  */    /*-----------------------------------------------------------------*/    ppp->uart.idle = TRUE;    /*-----------------------------------------------------------------*/    /* If CHAT is waiting for output to finish, it can now come up.    */    /*-----------------------------------------------------------------*/    if (ppp->chat.minor_state == WAIT_FOR_IDLE)      pppAttnReq(do_chat, ppp);    return 0;  }  /*-------------------------------------------------------------------*/  /* Loop until out of data to send or room in driver.                 */  /*-------------------------------------------------------------------*/  do  {    /*-----------------------------------------------------------------*/    /* Copy CHAT character. Update destination address and room.       */    /*-----------------------------------------------------------------*/    *dst = *ppp->chat.uart_get;    dst += increment;    /*-----------------------------------------------------------------*/    /* Advance driver's "get" pointer, wrapping around as necessary.   */    /*-----------------------------------------------------------------*/    if (ppp->chat.uart_get == &ppp->chat.snd_buf[SBUF_LEN - 1])      ppp->chat.uart_get = ppp->chat.snd_buf;    else      ++ppp->chat.uart_get;    /*-----------------------------------------------------------------*/    /* Decrement data and room counts. Break if either is zero.        */    /*-----------------------------------------------------------------*/    --room;    --ppp->chat.sb_count;  }  while (ppp->chat.sb_count && room);  /*-------------------------------------------------------------------*/  /* If interpreter is waiting for send buffer space, release it.      */  /*-------------------------------------------------------------------*/  if (ppp->chat.minor_state == WAIT_FOR_SPACE)  {    ppp->chat.minor_state = SENDING;    pppAttnReq(do_chat, ppp);  }  /*-------------------------------------------------------------------*/

⌨️ 快捷键说明

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