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

📄 atcmd.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    }
    return fRet;
}

//
// Place a command into the Command Queue and ignore the response
//
BOOL QueueCmdIgnoreRspWithData(const APIID apiid, const LPCSTR szCmd, const DWORD dwOptions, DWORD dwTimeout, const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, DWORD dwRetries, DWORD dwRetriesOnError, DWORD dwRetryOnErrorDelay, const PFN_CMD_PARSE_DATA pfnParseWithData, const PVOID pParseData)
{
    FUNCTION_TRACE(QueueCmdIgnoreRsp);
    DEBUGCHK(0 != (dwOptions & CMDOPT_NOOP) || NULL != szCmd);

    CCommand* pCmd = NULL;
    BOOL fRet = FALSE;

    // Set up a command to be sent
    pCmd = new CCommand;
    if (!pCmd || !pCmd->Init(NULL, szCmd, NULL, dwOptions | CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, dwTimeout, pnd, NULL, dwRetries, dwRetriesOnError, dwRetryOnErrorDelay, apiid, pfnParseWithData, pParseData))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdIgnoreRsp : Unable to construct or Init CCommand\r\n")));
        goto Error;
    }

#ifdef RIL_RADIO_RESILIENCE
    EnterCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // Place the command into the command queue
    //    (this may block if the queue is full)
    if (!g_pCmdQ->Put(pCmd, INFINITE))
    {
#ifdef RIL_RADIO_RESILIENCE
        LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdIgnoreRsp : Unable to Put CCommand\r\n")));
        goto Error;
    }
#ifdef RIL_RADIO_RESILIENCE
    LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
    pCmd = NULL;
    fRet = TRUE;

    Error:
    if (!fRet)
    {
        delete pCmd;
    }
    return fRet;
}
//
//
//
DWORD WINAPI RequeueThreadProc(LPVOID lpParameter)
{
    FUNCTION_TRACE(RequeueThreadProc);
    REQUEUE_THREAD_DATA* prtd = (REQUEUE_THREAD_DATA*)lpParameter;
    DEBUGCHK(NULL != prtd);
    DEBUGCHK(NULL != prtd->pCmd);

    Sleep(prtd->dwDelay);

#ifdef RIL_RADIO_RESILIENCE
    EnterCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // Place the command into the command queue
    //    (this may block if the queue is full)
    if (!g_pCmdQ->Put(prtd->pCmd, INFINITE))
    {
        delete prtd->pCmd;
    }

#ifdef RIL_RADIO_RESILIENCE
    LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    prtd->pCmd = NULL;
    delete prtd;
    return 0;
}


//
//
//
BOOL RequeueCmdWithDelay(CCommand* pCmd, DWORD dwDelay)
{
    FUNCTION_TRACE(RequeueCmdWithDelay);
    DEBUGCHK(NULL != pCmd);
    DEBUGCHK(TRUE == pCmd->FIgnoreRsp());

    REQUEUE_THREAD_DATA* prtd = NULL;
    CCommand* pCmdNew = NULL;
    DWORD dwThreadID;
    BOOL fRet = FALSE;

    // Allocate parameter structure to be passed to the thread proc
    prtd = new REQUEUE_THREAD_DATA;
    if (!prtd)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RequeueCmdWithDelay : Unable to construct REQUEUE_THREAD_DATA\r\n")));
        goto Error;
    }

    // Set up a command to be sent
    pCmdNew = new CCommand;
    if (!pCmdNew || !pCmdNew->Init(pCmd))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RequeueCmdWithDelay : Unable to construct or Init CCommand\r\n")));
        goto Error;
    }

    prtd->pCmd = pCmdNew;
    prtd->dwDelay = dwDelay;
    if (!CreateThread(NULL, 0, RequeueThreadProc, (LPVOID)prtd, 0, &dwThreadID))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RequeueCmdWithDelay : Unable to CreateThread(RequeueThreadProc)\r\n")));
        goto Error;
    }
    fRet = TRUE;

    Error:
    if (!fRet)
    {
        delete prtd;
        delete pCmd;
    }
    return fRet;
}

//
//
//
BOOL QueueRsp(CRilHandle* pRilDevice, CResponse*& rpRsp)
{
    FUNCTION_TRACE(QueueRsp);
    BOOL fRet = FALSE;

    // Remember that we're not waiting for AT response anymore
    pRilDevice->StopWaitingForRsp();

    // Queue the command response
    if (!g_pRspQ->Put(rpRsp, INFINITE))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueRsp : Unable to Put CResponse\r\n")));
        goto Error;
    }
    rpRsp = NULL;

    fRet = TRUE;

    Error:
    return fRet;
}

BOOL ParseCLCCNotification(CRilHandle *pRilDevice, CCommand* pCmd, CResponse* pRsp)
{
    FUNCTION_TRACE(ParseCLCCNotification);
    BOOL Found=FALSE;
    LPCSTR szRsp;
    UINT nId;
    UINT nDirection;
    UINT nStatus;
    UINT nType;
    UINT nMultiParty;

    szRsp = pRsp->GetData();

    // Parse "+CLCC: "
    while (MatchStringAnywhere(szRsp,"+CLCC: ",szRsp))
    {
        Found=TRUE;

        // Parse "<id>"
        if (!ParseUInt(szRsp, TRUE, nId, szRsp))
        {
            continue;
        }

        // Parse ",<direction>"
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseUInt(szRsp, TRUE, nDirection, szRsp))
        {
            continue;
        }

        // Parse ",<status>"
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseUInt(szRsp, TRUE, nStatus, szRsp))
        {
            continue;
        }

        // Parse ",<type>"
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseUInt(szRsp, TRUE, nType, szRsp))
        {
            continue;
        }

        // Parse ",<multiparty>"
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseUInt(szRsp, TRUE, nMultiParty, szRsp))
        {
            continue;
        }

        if (nStatus==2)
        {
            RILDIALINFO rdi;
            rdi.cbSize = sizeof(rdi);
            rdi.dwParams = RIL_PARAM_DI_ALL;
            rdi.hrCmdId = pCmd->GetID();
            rdi.dwCallId = nId;
            (void)pRilDevice->BroadcastRealBlobNotification(RIL_NOTIFY_DIAL,
                                                &rdi, sizeof(RILDIALINFO));
            break;
        }
    }

    return Found;
}

//
// Thread responsible for sending commands from the Command Queue to COM port
//
DWORD WINAPI CmdThreadProc(LPVOID lpParameter)
{
    FUNCTION_TRACE(CmdThreadProc);
    DEBUGCHK(lpParameter != NULL);
    CRilHandle* pRilDevice = (CRilHandle*)lpParameter;
    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CmdThreadProc : Entering, pRilDevice=0x%x\r\n"),pRilDevice));
    const DWORD dwReturn = pRilDevice->CommandThread();
    DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CmdThreadProc : THREAD IS EXITING, dwReturn=0x%x\r\n"),dwReturn));
    return dwReturn;
}

//
// Thread responsible for reading responses from COM port into the Response Queue
//
DWORD WINAPI ReadThreadProc(LPVOID lpParameter)
{
    FUNCTION_TRACE(ReadThreadProc);
    DEBUGCHK(lpParameter != NULL);
    CRilHandle* pRilDevice = (CRilHandle*)lpParameter;

    // Switch the thread into higher priority (to guarantee that the module's in buffer doesn't get overflown)
    if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : ReadThreadProc : Unable to raise priority of read thread!!\r\n")));
        return 0;
    }

    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : ReadThreadProc : Entering, pRilDevice=0x%x\r\n"),pRilDevice));
    const DWORD dwReturn = pRilDevice->ResponseThread();
    DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : ReadThreadProc : THREAD IS EXITING, dwReturn=0x%x\r\n"),dwReturn));
    return dwReturn;
}

DWORD CRilHandle::CommandThread()
{
    FUNCTION_TRACE(CRilHandle::CommandThread);
    CCommand* pCmd = NULL;
    BOOL fBackToCmdMode = FALSE;
    DWORD dwReferenceTime;
    BOOL fDummy;
    HRESULT hr;

    DEBUGCHK(m_pComDevice != NULL);
    //For the rilgsm  is too late to get the response
#if 0
#if defined(OEM1_DRIVER111) && !defined(OEM2_DRIVER)
    // On this hardware, we need to wait for the radio to send us it's wakeup string before we start
    // sending it commands.
    RETAILMSG(1, (TEXT("[TI]RILDrv : E : start WaitForRadioSignon\r\n")));
    if(!m_pComDevice->WaitForRadioSignon(this))
    {
        RETAILMSG(1, (TEXT("RILDrv : E : CRilHandle::CommandThread : WaitForRadioSignon failed\r\n")));
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::CommandThread : WaitForRadioSignon failed\r\n")));
    }
    RETAILMSG(1, (TEXT("[TI]RILDrv : E : End WaitForRadioSignon\r\n")));
#endif // OEM1_DRIVER
#endif
    // Tell the main thread that we've reached the checkpoint

⌨️ 快捷键说明

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