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

📄 probe_com.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif


/*
*********************************************************************************************************
*                                     ProbeCom_TerminalExecSet()
*
* Description : Set the handler that will be invoked to process a terminal command.
*
* Argument(s) : handler         The handler that will be invoked.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : (1) The handler should be a function with the following prototype:
*
*	                    void  App_TerminalExecFnct (CPU_CHAR    *pstr,
*                                                   CPU_SIZE_T   len);
*
*                   where 'pstr' is a pointer to the command string, and 'len' is the length of the
*                   command string (in characters) excluding the final NULL byte.  The command string
*                   will NOT include a terminating new line or line feed.
*********************************************************************************************************
*/

#if (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
void  ProbeCom_TerminalExecSet (PROBE_COM_TERMINAL_EXEC_FNCT  handler)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


    CPU_CRITICAL_ENTER();
    ProbeCom_TerminalExecHandler = handler;
    CPU_CRITICAL_EXIT();
}
#endif


/*
*********************************************************************************************************
*                                      ProbeCom_TerminalInSet()
*
* Description : Set the handler that will be invoked to process terminal input.
*
* Argument(s) : handler         The handler that will be invoked.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : (1) The handler should be a function with the following prototype:
*
*	                    void  App_TerminalInFnct (CPU_CHAR    *pstr,
*                                                 CPU_SIZE_T   len);
*
*                   where 'pstr' is a pointer to the input string, and 'len' is the length of the input
*                   string (in characters) excluding the final NULL byte.  The input string will NOT
*                   include a terminating new line or line feed.
*********************************************************************************************************
*/

#if (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
void  ProbeCom_TerminalInSet (PROBE_COM_TERMINAL_IN_FNCT  handler)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


    CPU_CRITICAL_ENTER();
    ProbeCom_TerminalInHandler = handler;
    CPU_CRITICAL_EXIT();
}
#endif


/*
*********************************************************************************************************
*                                        ProbeCom_ParseRxPkt()
*
* Description : Parse a packet & formulate a response.
*
* Argument(s) : prx_pkt         Pointer to the receive  packet buffer
*
*               ptx_pkt         Pointer to the transmit packet buffer
*
*               rx_pkt_size     Size of the received packet
*
*               tx_pkt_size     Size of the transmit packet buffer
*
* Return(s)   : The number of bytes in the data segment of the packet to transmit in response.
*
* Caller(s)   : Tasks/receive handlers in communications-specific drivers, (e.g., probe_rs232,
*               probe_usb, probe_tcpip, etc.).
*
* Note(s)     : none.
*********************************************************************************************************
*/

CPU_SIZE_T  ProbeCom_ParseRxPkt (void        *prx_pkt,
                                 void        *ptx_pkt,
                                 CPU_SIZE_T   rx_pkt_size,
                                 CPU_SIZE_T   tx_buf_size)
{
    CPU_SIZE_T   tx_buf_wr;
    CPU_INT16U   format;
    CPU_INT08U  *prx_pkt_08;
    CPU_INT08U  *ptx_pkt_08;


    if (rx_pkt_size < 2) {
        return (0);
    }

    prx_pkt_08  = (CPU_INT08U *)prx_pkt;
    ptx_pkt_08  = (CPU_INT08U *)ptx_pkt;
    format      = (prx_pkt_08[1] << 8) + prx_pkt_08[0];
    prx_pkt_08 += 2;

#if (PROBE_COM_CFG_STAT_EN == DEF_ENABLED)
    ProbeCom_RxPktCtr++;
    ProbeCom_TxPktCtr++;
#endif

    switch (format) {
        case PROBE_COM_FMT_RX_QUERY:
             tx_buf_wr = ProbeCom_ReqQuery(       prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_RD:
             tx_buf_wr = ProbeCom_ReqRd(          prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_RD_MULTI:
             tx_buf_wr = ProbeCom_ReqRdMulti(     prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

#if (PROBE_COM_CFG_WR_REQ_EN == DEF_ENABLED)
        case PROBE_COM_FMT_RX_WR:
             tx_buf_wr = ProbeCom_ReqWr(          prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_WR_MULTI:
             tx_buf_wr = ProbeCom_ReqWrMulti(     prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;
#endif

#if (PROBE_COM_CFG_STR_REQ_EN == DEF_ENABLED)
        case PROBE_COM_FMT_RX_STR_IN:
             tx_buf_wr = ProbeCom_ReqStrIn(       prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_STR_OUT:
             tx_buf_wr = ProbeCom_ReqStrOut(      prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;
#endif

#if (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
        case PROBE_COM_FMT_RX_TERMINAL_EXEC:
             tx_buf_wr = ProbeCom_ReqTerminalExec(prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_TERMINAL_IN:
             tx_buf_wr = ProbeCom_ReqTerminalIn(  prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_TERMINAL_OUT:
             tx_buf_wr = ProbeCom_ReqTerminalOut( prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;
#endif

        default:
             tx_buf_wr = ProbeCom_ReqErr(                     ptx_pkt_08, PROBE_COM_STATUS_UNKNOWN_REQUEST);
             break;
    }

    return (tx_buf_wr);
}


/*
*********************************************************************************************************
*********************************************************************************************************
*                                           LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                       ProbeCom_StrOutAvail()
*
* Description : Check if string output is waiting for transmission.
*
* Argument(s) : none.
*
* Return(s)   : DEF_TRUE   if a  string output is waiting for transmission.
*               DEF_FALSE  if no string output is waiting for transmission.
*
* Caller(s)   : ProbeCom_PktModifier().
*
* Note(s)     : (1) See Notes for 'ProbeCom_StrWr()'.
*********************************************************************************************************
*/

#if (PROBE_COM_CFG_STR_REQ_EN == DEF_ENABLED)
static  CPU_BOOLEAN  ProbeCom_StrOutAvail (void)
{
    CPU_BOOLEAN  avail;
    CPU_BOOLEAN  empty;


    empty = ProbeCom_BufIsEmpty(&ProbeCom_StrOutBuf);
    avail = (empty == DEF_YES) ? (DEF_FALSE) : (DEF_TRUE);

    return (avail);
}
#endif



/*
*********************************************************************************************************
*                                     ProbeCom_TerminalOutAvail()
*
* Description : Check if terminal output is waiting for transmission.
*
* Argument(s) : none.
*
* Return(s)   : DEF_TRUE   if a  terminal output is waiting for transmission.
*               DEF_FALSE  if no terminal output is waiting for transmission.
*
* Caller(s)   : ProbeCom_PktModifier().
*
* Note(s)     : (1) See Notes for 'ProbeCom_TerminalOut()'.
*********************************************************************************************************
*/

#if (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
static  CPU_BOOLEAN  ProbeCom_TerminalOutAvail (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR       cpu_sr;
#endif
    CPU_SIZE_T   buf_len;
    CPU_BOOLEAN  avail;


    CPU_CRITICAL_ENTER();
    buf_len = ProbeCom_TerminalOutBufLen;
    CPU_CRITICAL_EXIT();

    avail   = (buf_len == 0) ? (DEF_FALSE) : (DEF_TRUE);

    return (avail);
}
#endif



/*
*********************************************************************************************************
*                                     ProbeCom_TerminalExecDone()
*
* Description : Check if terminal execution is done.
*
* Argument(s) : none.
*
* Return(s)   : DEF_TRUE   if terminal command execution is     done.
*               DEF_FALSE  if terminal command execution is NOT done.
*
* Caller(s)   : ProbeCom_PktModifier().
*
* Note(s)     : (1) See Notes for 'ProbeCom_TerminalOut()'.
*********************************************************************************************************
*/

#if (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
static  CPU_BOOLEAN  ProbeCom_TerminalExecDone (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR       cpu_sr;
#endif
    CPU_BOOLEAN  executing;
    CPU_BOOLEAN  done;


    CPU_CRITICAL_ENTER();
    executing = ProbeCom_TerminalExecuting;
    CPU_CRITICAL_EXIT();

    done = (executing == DEF_YES) ? (DEF_FALSE) : (DEF_TRUE);

    return (done);
}
#endif


/*

⌨️ 快捷键说明

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