VOS_UINT32 ParseDCmdPreProc( VOS_UINT8 * pData, VOS_UINT16 usLen)
{
    VOS_UINT16 usTmpLen = usLen;
    VOS_UINT8* pTmp = pData;
    VOS_UINT32 ulResult = AT_FAILURE;

    /* 为了规避LINUX下拨号命令中带有引号(ATDT"*99#")的问题,将引号去除 */
    ScanQuateChar(pTmp, &usTmpLen);

#if 0
    if(AT_SUCCESS == atCheckMmiString(pTmp,usTmpLen))              /* 补充业务处理 */
    {
        if(AT_FAILURE == At_CheckCharWell(pTmp[usTmpLen - 1]))      /* 如果不是以#号结尾 */
        {
            atScanDcmdModifier(pTmp,&usTmpLen);                    /* 扫描修饰符 */

            /* 因为要把命令名拷贝到gstATCmdName.usCmdNameLen中以备命令匹配,
            所以,把内容拷贝到参数列表的第一个缓存中*/
            if(ERR_MSP_SUCCESS != atfwParseSaveParam(pTmp, usTmpLen))
            {
                return AT_CME_DIAL_STRING_TOO_LONG;
            }

            g_stATParseCmd.ucCmdFmtType = AT_BASIC_CMD_TYPE;                   /* 设置命令类型 */
            g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_SET_CMD_NO_PARA;          /* 设置命令操作类型 */
            g_stATParseCmd.stCmdName.usCmdNameLen = 1;
            g_stATParseCmd.stCmdName.aucCmdName[0] = 'D';
            ulResult = AT_SUCCESS;
        }
        else
        {
            atScanDmcmdModifier(pTmp,&usTmpLen);                    /* 扫描修饰符 */

            /* 因为要把命令名拷贝到gstATCmdName.usCmdNameLen中以备命令匹配,
            所以,把内容拷贝到参数列表的第一个缓存中*/
            if(ERR_MSP_SUCCESS != atfwParseSaveParam(pTmp, usTmpLen))
            {
                return AT_CME_DIAL_STRING_TOO_LONG;
            }

            ulResult = atParseDMCmd(pTmp,usTmpLen);                /* 如果带分号 */
            if(ulResult == AT_FAILURE)
            {
                return AT_ERROR;
            }
        }
    }
    else
#endif    
    {
        if(AT_SUCCESS == At_CheckCharWell(pTmp[usTmpLen - 1]))      /* 如果不是以#号结尾 */
        {
            atScanDmcmdModifier(pTmp,&usTmpLen);                    /* 扫描修饰符 */

            /* 因为要把命令名拷贝到gstATCmdName.usCmdNameLen中以备命令匹配,
            所以,把内容拷贝到参数列表的第一个缓存中*/
            if(ERR_MSP_SUCCESS != atfwParseSaveParam(pTmp, usTmpLen))
            {
                return AT_CME_DIAL_STRING_TOO_LONG;
            }

            ulResult = atParseDMCmd(pTmp,usTmpLen);                /* 如果带分号 */
            if(ulResult == AT_FAILURE)
            {
                return AT_ERROR;
            }
        }
        else
        {
            if(AT_FAILURE == atCheckRightArrowStr(pTmp,usTmpLen))
            {
                atScanDcmdModifier(pTmp,&usTmpLen);                        /* 扫描修饰符 */
            }

            /* 因为要把命令名拷贝到gstATCmdName.usCmdNameLen中以备命令匹配,
            所以,把内容拷贝到参数列表的第一个缓存中*/
            if(ERR_MSP_SUCCESS != atfwParseSaveParam(pTmp, usTmpLen))
            {
                return AT_CME_DIAL_STRING_TOO_LONG;
            }

            ulResult = atParseDCmd(pTmp,usTmpLen);                       /* D命令 */

            if(ulResult == AT_FAILURE)
            {
                return AT_ERROR;
            }

        }
    }

    return ulResult;
}
Ejemplo n.º 2
0
VOS_UINT32 atParseExtendCmd( VOS_UINT8 * pData, VOS_UINT16 usLen)
{
    AT_STATE_TYPE_ENUM curr_state = AT_NONE_STATE;  /*  设置初始状态 */
    AT_STATE_TYPE_ENUM new_state = AT_NONE_STATE;   /*  设置初始状态 */
    VOS_UINT8 *pucCurrPtr = pData;                  /*  指向当前正在处理的字符*/
    VOS_UINT8 *pucCopyPtr = pData;                  /*  拷贝内容的起始指针 */
    VOS_UINT16 usLength = 0;                        /*  记录当前已经处理的字符个数*/

    /* 依次分析字符串中的每个字符*/
    while(usLength++ < usLen)                  /* 依次比较每个字符 */
    {
        curr_state = new_state;                 /* 当前状态设置为新状态*/

        /*  根据当前处理的字符和当前状态查表得到新状态*/
        new_state = atFindNextMainState(AT_E_CMD_MAIN_STATE_TAB,*pucCurrPtr,curr_state);

        switch(new_state)                       /* 状态处理*/
        {
        case AT_E_CMD_NAME_STATE:               /* 扩展命令名状态*/
            if(curr_state != new_state)         /* 新状态部分不等于当前状态*/
            {
                g_stATParseCmd.ucCmdFmtType = AT_EXTEND_CMD_TYPE;           /* 设置命令类型*/
                g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_SET_CMD_NO_PARA;   /* 设置命令操作类型*/

                pucCopyPtr = pucCurrPtr;            /* 准备接收扩展类型命令名*/
            }
            break;

        case AT_E_CMD_SET_STATE:                /* AT扩展命令等号状态 */
            /* 存储命令名到全局变量中 */
            g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_SET_PARA_CMD;  /* 设置命令操作类型*/
            g_stATParseCmd.stCmdName.usCmdNameLen = (VOS_UINT16)(pucCurrPtr - pucCopyPtr);
            if(g_stATParseCmd.stCmdName.usCmdNameLen < sizeof(g_stATParseCmd.stCmdName.aucCmdName))
            {
                atRangeCopy(g_stATParseCmd.stCmdName.aucCmdName,pucCopyPtr,pucCurrPtr);
            }
            else
            {
                return AT_ERROR;                  /* 返回错误 */
            }
            break;

        case AT_E_CMD_PARA_STATE:               /* AT扩展命令参数状态 */
        case AT_E_CMD_LEFT_QUOT_STATE:          /* AT扩展命令左引号状态 */
            if(curr_state != new_state)         /* 新状态部分不等于当前状态*/
            {
                pucCopyPtr = pucCurrPtr;            /* 准备接收参数内容*/
            }
            break;

        case AT_E_CMD_COLON_STATE:              /* AT扩展命令逗号状态 */
            if((curr_state != new_state) && (AT_E_CMD_SET_STATE != curr_state))         /* 新状态部分不等于当前状态*/
            {
                /* 存储参数到全局变量中 */
                if(ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, (VOS_UINT16)(pucCurrPtr - pucCopyPtr)))
                {
                    return AT_ERROR;
                }

            }
            else
            {
                /*连续两个逗号,参数不存在*/
                if(ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, 0))
                {
                    return AT_ERROR;
                }

            }
            break;

        case AT_E_CMD_READ_STATE:                   /* AT扩展命令查询参数状态 */

            /* 存储命令名到全局变量中 */
            g_stATParseCmd.stCmdName.usCmdNameLen = (VOS_UINT16)(pucCurrPtr - pucCopyPtr);
            if (g_stATParseCmd.stCmdName.usCmdNameLen < sizeof(g_stATParseCmd.stCmdName.aucCmdName))
            {
                atRangeCopy(g_stATParseCmd.stCmdName.aucCmdName,pucCopyPtr,pucCurrPtr);
            }
            else
            {
                return AT_ERROR;                  /* 返回错误 */
            }

            g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_READ_CMD;   /* 设置命令操作类型*/

            break;

        case AT_E_CMD_TEST_STATE:                   /* AT扩展命令测试参数状态 */
            g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_TEST_CMD;   /* 设置命令操作类型*/
            break;

        case AT_BUTT_STATE:                         /* 无效状态 */
            return AT_ERROR;                      /* 返回错误 */

        default:
            break;
        }
        pucCurrPtr++;                                 /* 继续分析下一个字符*/
    }

    switch(new_state)                               /* 根据最后的状态判断*/
    {
    case AT_E_CMD_PARA_STATE:                       /* AT扩展命令参数状态 */
    case AT_E_CMD_RIGHT_QUOT_STATE:                 /* AT扩展命令右引号状态 */

        /* 存储参数到全局变量中 */
        if (ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, (VOS_UINT16)(pucCurrPtr - pucCopyPtr)))
        {
            return AT_ERROR;
        }

        break;

    case AT_E_CMD_NAME_STATE:                   /* AT扩展命令查询参数状态 */

        /* 存储命令名到全局变量中 */
        g_stATParseCmd.stCmdName.usCmdNameLen = (VOS_UINT16)(pucCurrPtr - pucCopyPtr);
        if (g_stATParseCmd.stCmdName.usCmdNameLen < sizeof(g_stATParseCmd.stCmdName.aucCmdName))
        {
            atRangeCopy(g_stATParseCmd.stCmdName.aucCmdName,pucCopyPtr,pucCurrPtr);
        }
        else
        {
            return AT_ERROR;                  /* 返回错误 */
        }

        g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_SET_CMD_NO_PARA;   /* 设置命令操作类型*/

        break;

    case AT_E_CMD_COLON_STATE:                      /* AT命令后面跟有无参的逗号 */

        if (ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, 0))
        {
            return AT_ERROR;
        }

        break;

    case AT_E_CMD_SET_STATE:                        /* AT扩展命令等号状态 */
    case AT_E_CMD_TEST_STATE:                       /* AT扩展命令查询参数状态 */
    case AT_E_CMD_READ_STATE:                       /* AT扩展命令测试参数状态 */
        break;

    default:
        return AT_ERROR;                          /* 返回错误*/
    }
    return AT_SUCCESS;                              /*  返回正确*/
}
static VOS_UINT32 atParseDCmd( VOS_UINT8 * pData, VOS_UINT16 usLen)
{
    AT_STATE_TYPE_ENUM curr_state = AT_NONE_STATE;  /*  设置初始状态 */
    AT_STATE_TYPE_ENUM new_state = AT_NONE_STATE;   /*  设置初始状态 */
    VOS_UINT8 *pucCurrPtr = pData;                  /*  指向当前正在处理的字符*/
    VOS_UINT8 *pucCopyPtr = pData;                  /*  拷贝内容的起始指针 */
    VOS_UINT16 usLength = 0;                        /*  记录当前已经处理的字符个数*/

    /* 依次分析字符串中的每个字符*/
    while( (usLength++ < usLen) && (g_stATParseCmd.ucParaIndex < AT_MAX_PARA_NUMBER))                     /* 依次比较每个字符 */
    {
        curr_state = new_state;                  /* 当前状态设置为新状态*/

        /* 根据当前处理的字符和当前状态查表得到新状态*/
        new_state = atFindNextMainState(AT_D_CMD_MAIN_STATE_TAB,*pucCurrPtr,curr_state);

        switch(new_state)                        /* 状态处理*/
        {
        case AT_D_CMD_NAME_STATE:                /* AT D命令命令名状态 */
            g_stATParseCmd.ucCmdFmtType = AT_BASIC_CMD_TYPE;     /* 设置命令类型*/
            g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_SET_CMD_NO_PARA;   /* 设置命令操作类型*/
            pucCopyPtr = pucCurrPtr;                 /* 准备接收D类型命令名*/
            break;

        case AT_D_CMD_RIGHT_ARROW_STATE:         /* AT D命令右箭头状态 */
        case AT_D_CMD_DIALSTRING_STATE:          /* AT D命令拨号字符串状态 */
            if(curr_state != new_state)          /* 新状态部分不等于当前状态*/
            {
                g_stATParseCmd.stCmdName.usCmdNameLen = (VOS_UINT16)(pucCurrPtr - pucCopyPtr);
                if(g_stATParseCmd.stCmdName.usCmdNameLen < sizeof(g_stATParseCmd.stCmdName.aucCmdName))
                {
                    atRangeCopy(g_stATParseCmd.stCmdName.aucCmdName,pucCopyPtr,pucCurrPtr);
                }
                else
                {
                    return AT_FAILURE;                  /* 返回错误 */
                }
                pucCopyPtr = pucCurrPtr;             /* 准备接收参数*/
            }
            break;

        case AT_D_CMD_DIGIT_STATE:               /* AT D命令数字状态 */
        case AT_D_CMD_LEFT_QUOT_STATE:           /* AT D命令左引号状态 */
        case AT_D_CMD_CHAR_STATE:
            if(curr_state != new_state)          /* 新状态部分不等于当前状态*/
            {
                /* 存储参数到全局变量中 */
                if(ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, (VOS_UINT16)(pucCurrPtr - pucCopyPtr)))
                {
                    return AT_FAILURE;
                }

                pucCopyPtr = pucCurrPtr;                /* 准备接收下一个参数*/
            }
            break;

        case AT_D_CMD_CHAR_I_STATE:              /* AT D命令字符I状态 */
        case AT_D_CMD_CHAR_G_STATE:              /* AT D命令字符G状态 */
        case AT_D_CMD_SEMICOLON_STATE:           /* AT D命令分号状态 */
            /* 存储参数到全局变量中 */
            if(ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, (VOS_UINT16)(pucCurrPtr - pucCopyPtr)))
            {
                return AT_FAILURE;
            }

            pucCopyPtr = pucCurrPtr;                /* 准备接收下一个参数*/
            break;

        case AT_BUTT_STATE:                     /* 无效状态 */
            return AT_FAILURE;                  /* 返回错误 */

        default:
            break;
        }
        pucCurrPtr++;                             /* 继续分析下一个字符*/
    }

    switch(new_state)                           /* 根据最后的状态判断*/
    {
    case AT_D_CMD_SEMICOLON_STATE:              /* AT D命令分号状态 */
        break;

    case AT_D_CMD_DIALSTRING_STATE:             /* AT D命令拨号字符串状态 */
    case AT_D_CMD_DIGIT_STATE:                  /* AT D命令数字状态 */
    case AT_D_CMD_RIGHT_QUOT_STATE:             /* AT D命令右引号状态 */
    case AT_D_CMD_CHAR_G_STATE:                 /* AT D命令字符G状态 */
    case AT_D_CMD_CHAR_I_STATE:                 /* AT D命令字符I状态 */
        /* 存储参数到全局变量中 */
        if(ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, (VOS_UINT16)(pucCurrPtr - pucCopyPtr)))
        {
            return AT_FAILURE;
        }

        break;

    default:
        return AT_FAILURE;                      /* 返回错误*/
    }
    return AT_SUCCESS;                          /* 返回正确*/
}
VOS_UINT32 atParseBasicCmd(VOS_UINT8 * pData, VOS_UINT16 usLen)
{
    AT_STATE_TYPE_ENUM curr_state = AT_NONE_STATE;  /*  设置初始状态 */
    AT_STATE_TYPE_ENUM new_state = AT_NONE_STATE;   /*  设置初始状态 */
    VOS_UINT8 *pucCurrPtr = pData;                  /*  指向当前正在处理的字符*/
    VOS_UINT8 *pucCopyPtr = pData;                  /*  拷贝内容的起始指针 */
    VOS_UINT16 usLength = 0;                        /*  记录当前已经处理的字符个数*/

    if(AT_FAILURE == atCheckBasicCmdName(*pucCurrPtr))
    {
        return AT_ERROR;
    }

    /* 依次分析字符串中的每个字符*/
    while( (usLength++ < usLen) && (g_stATParseCmd.ucParaIndex < AT_MAX_PARA_NUMBER))                    /* 依次比较每个字符 */
    {
        curr_state = new_state;                 /*  当前状态设置为新状态*/

        /*  根据当前处理的字符和当前状态查表得到新状态*/
        new_state = atFindNextMainState(AT_B_CMD_MAIN_STATE_TAB,*pucCurrPtr,curr_state);

        switch(new_state)                       /*  状态处理*/
        {
        case AT_B_CMD_NAME_STATE:               /*  基本命令名状态*/
            if(curr_state != new_state)         /*  新状态部分不等于当前状态*/
            {
                g_stATParseCmd.ucCmdFmtType = AT_BASIC_CMD_TYPE;            /*  设置命令类型*/
                g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_SET_CMD_NO_PARA;   /*  设置命令操作类型*/
                pucCopyPtr = pucCurrPtr;            /*  准备接收基本类型命令名*/
            }
            break;

        case AT_B_CMD_PARA_STATE:               /* AT基本命令参数状态 */
            if(curr_state != new_state)         /* 新状态部分不等于当前状态*/
            {
                /* 存储命令名到全局变量中 */
                g_stATParseCmd.stCmdName.usCmdNameLen = (VOS_UINT16)(pucCurrPtr - pucCopyPtr);
                if(g_stATParseCmd.stCmdName.usCmdNameLen < sizeof(g_stATParseCmd.stCmdName.aucCmdName))
                {
                    atRangeCopy(g_stATParseCmd.stCmdName.aucCmdName,pucCopyPtr,pucCurrPtr);
                }
                else
                {
                    return AT_FAILURE;                      /* 返回错误 */
                }

                g_stATParseCmd.ucCmdOptType = AT_CMD_OPT_SET_PARA_CMD;  /* 设置命令操作类型*/
                pucCopyPtr = pucCurrPtr;                    /* 准备接收参数*/
            }
            break;

        default:
            return AT_FAILURE;                  /* 返回错误 */
        }
        pucCurrPtr++;                           /*  继续分析下一个字符*/
    }

    switch(new_state)                           /*  根据最后的状态判断*/
    {
    case AT_B_CMD_NAME_STATE:                   /*  基本命令名状态*/

        /* 存储命令名到全局变量中 */
        g_stATParseCmd.stCmdName.usCmdNameLen = (VOS_UINT16)(pucCurrPtr - pucCopyPtr);
        if(g_stATParseCmd.stCmdName.usCmdNameLen < sizeof(g_stATParseCmd.stCmdName.aucCmdName))
        {
            atRangeCopy(g_stATParseCmd.stCmdName.aucCmdName,pucCopyPtr,pucCurrPtr);
        }
        else
        {
            return AT_FAILURE;                  /* 返回错误 */
        }
        break;

    case AT_B_CMD_PARA_STATE:                   /*  基本命令名状态*/
        /* 存储参数到全局变量中 */
        if(ERR_MSP_SUCCESS != atfwParseSaveParam(pucCopyPtr, (VOS_UINT16)(pucCurrPtr - pucCopyPtr)))
        {
            return AT_FAILURE;
        }

        break;

    default:                                    /* 其它错误状态*/
        return AT_FAILURE;                      /* 返回错误 */
    }

    return AT_SUCCESS;                          /*  返回正确*/
}