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

📄 atcmd.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    GetCheckPoint()->Reached();


    while (1)
    {
        // Make sure the module is prepared to handle the command before sending it (except for init commands)
        if (!WaitForCommandOrCancel())
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::CommandThread : Cancel was set\r\n")));
            goto Error;
        }

        // Get the next command from the Queue
        hr = g_pCmdQ->Get(pCmd, INFINITE);
        if (RIL_E_CANCELLED == hr)
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::CommandThread : Get returned RIL_E_CANCELLED\r\n")));
            goto Error;
        }
        DEBUGCHK(FALSE == FAILED(hr));

        // If we failed initialization, ignore any non-init commands in the queue
        if (m_fFailedInit && !pCmd->FInit())
        {
            HRESULT dwError = RIL_E_RADIOFAILEDINIT;
            pCmd->SendResponse(RIL_RESULT_ERROR, &dwError, sizeof(HRESULT));
            //add by qinxuetao
            delete pCmd;
            pCmd = NULL;
            RETAILMSG(1, (TEXT("[TI]CommandThread: warning, memory leak 1\r\n")));
            continue;
        }

#if defined(OEM1_DRIVER) || defined(OEM2_DRIVER)
        if (g_dwUnlocked)
        {
            DWORD dwTimeSinceUnlock = GetTickCount() - g_dwUnlocked;
            
// this number was picked by guesswork/experimentation
#define WAIT_FOR_MODULE_TO_SETTLE 500
            if (dwTimeSinceUnlock < WAIT_FOR_MODULE_TO_SETTLE)
            {
                // certain commands like COPS need to wait for the module to
                // "settle" after it's been unlocked.
                Sleep(WAIT_FOR_MODULE_TO_SETTLE - dwTimeSinceUnlock);
            }
            g_dwUnlocked = 0;
        }
#endif

        // Send the command to comm port
        if (!m_pComDevice->SendRILCmdHandleRsp(this, pCmd, fDummy, fDummy))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::CommandThread : SendRILCmdHandleRsp failed\r\n")));
            if(pCmd)
            {
                delete pCmd;
                pCmd = NULL;
                RETAILMSG(1, (TEXT("[TI]CommandThread: warning, memory leak 2\r\n")));
            }
            // Don't give up and exit, just try again
            continue;
        }
        DEBUGCHK(NULL == pCmd);

        // If this command dropped the modem into the data mode, switch to data-mode operation
        if (m_pComDevice->FDataMode())
        {
            RETAILMSG(1, (TEXT("[TI] error, TI should not run following codes\r\n")));
            fBackToCmdMode = FALSE;
            dwReferenceTime = GetTickCount();
            ResetEvent(m_hDataEvent);

            while (!fBackToCmdMode)
            {
                BOOL fSentCommands = FALSE;

                // Sleep for a timeout
                WaitForSingleObject(m_hDataEvent, GetDataModeCmdDelay());

                // If there is a pending command in the queue, send it through the VSP backdoor
                if (!g_pCmdQ->FEmpty() &&
                    m_pComDevice->SendRILCmdsInDataMode(this, fBackToCmdMode))
                {
                    fSentCommands = TRUE;
                }

                // See if there's a command pending
                if (!fSentCommands &&
                    GetMaxDataModeTimeWithoutCmd() < GetTickCount() - dwReferenceTime)
                {
                    // The command queue is empty and we haven't sent a command for too long -- queue a no-op command
                    (void)QueueCmdIgnoreRsp(APIID_NONE, "AT\r", CMDOPT_NONE, g_TimeoutCmdNoOp,NULL, NULL,0,0,0);

                    (void)m_pComDevice->SendRILCmdsInDataMode(this, fBackToCmdMode);

                    fSentCommands = TRUE;
                }

                if (fSentCommands)
                {
                    // Update the reference time
                    dwReferenceTime = GetTickCount();
                }

                if (fBackToCmdMode || FCancelSet())
                {
                    break;
                }
#ifndef NO_RLSD_SUPPORT
                DWORD dwStatus;
                if (m_pComDevice->VirtGetCommModemStatus(&dwStatus) && !(dwStatus & MS_RLSD_ON))
                {
                    // RLSD is OFF, which means that data connection has been dropped
                    DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : CRilHandle::CommandThread : Detected remote disconnect due to loss of RLSD\r\n")));

                    // Exit out of the data mode
                    (void)m_pComDevice->ExitDataMode();

                    // Notify all clients
                    (void)BroadcastRealBlobNotification(RIL_NOTIFY_CALLSTATECHANGED, NULL, 0);
                    fBackToCmdMode = TRUE;
                }
#endif
            }
        }
    }

    Error:
    delete pCmd;
    g_RilLog.LogEvent(RILLOG_ZONE_CMD, RILLOG_EVENT_COMMANDTHREADEXIT);
    return 0;
}

BOOL CRilHandle::HandleRxData(char *szData, DWORD dwRead, bool fDataOnNotificationComPort)
{
    LPSTR szAppend = NULL;
    LPSTR szRemainder = NULL;
    UINT cbAppend = 0;
    UINT cbRemainder = 0;
    void* pBlob = NULL;
    UINT cbBlob = 0;
    CResponse* pRsp = NULL;
    BOOL bSuccess=FALSE;
    BOOL bSendCLIP = FALSE;

    // DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : ResponseThread read %s\r\n"), TString(PrintableString(szData, dwRead))));

    if (!AppendReadBytes(szData, dwRead, fDataOnNotificationComPort))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::ResponseThread : AppendReadBytes failed\r\n")));
        goto Exit;
    }

    while (GiveUpReadBytes(szAppend, cbAppend, fDataOnNotificationComPort))
    {
        if (!cbAppend)
        {
            // Free memory occupied by szAppend
            delete[] szAppend;
            szAppend = NULL;
            break;
        }

        if (!pRsp)
        {
            // Allocate a new response, if we need it
            pRsp = new CResponse;
            if (!pRsp)
            {
                DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::ResponseThread : Unable to construct CResponse\r\n")));
                // Critically low on memory
                SignalCriticalError(RILLOG_EVENT_LOWMEMORY, __LINE__, __FILE__);
                goto Exit;
            }
        }

        if (m_fLastCommandTimedOut)
        {
            pRsp->SetPotentialBogusResponseFlag();
            m_fLastCommandTimedOut = FALSE;
        }

        if (!pRsp->AppendString(szAppend, cbAppend, szRemainder, cbRemainder, fDataOnNotificationComPort))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::ResponseThread : AppendString failed\r\n")));
            // Critically low on memory
            SignalCriticalError(RILLOG_EVENT_LOWMEMORY, __LINE__, __FILE__);
            goto Exit;
        }

        // Does this contain a complete response?
        if (!szRemainder)
        {
            // No -- break out of this loop and wait for more data to come

            // Move the data back to the Read Bytes buffer
            if (!InheritReadBytes(pRsp, fDataOnNotificationComPort))
            {
                DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::ResponseThread : InheritReadBytes failed\r\n")));
                // Critically low on memory
                SignalCriticalError(RILLOG_EVENT_LOWMEMORY, __LINE__, __FILE__);
                goto Exit;
            }

            // Free memory occupied by szAppend
            delete[] szAppend;
            szAppend = NULL;
            cbAppend = 0;
            break;
        }
        else
        {
            // We have complete response. Now is a good time to pass the response on to the logging application if one exists.
            LogATCommand(pRsp->GetData(), pRsp->GetLength(), ATCMD_LOG_RESPONSE);

#ifdef RIL_WATSON_REPORT
            // If the radio was previously hung, Watson logging was reported once and disabled to 
            // prevent duplicate logs reported when the radio hangs.
            // We are receiving data from the radio, so make sure the Watson called flag is reset
            // so subsequent problems will be reported.
            g_fWatsonCalled = FALSE;
#endif // RIL_WATSON_REPORT
            
#if defined(OEM1_DRIVER) || defined(OEM2_SIMTOOLKIT)
            if (g_CachedToolKitNotifs[0] && IsAPIReady(SH_SHELL))
            {
                if( !g_fSTKInit )
                {
                    HANDLE hEventHandle = NULL;
                    hEventHandle = OpenEvent(EVENT_ALL_ACCESS, FALSE, STKINIT_TI);
                    if (NULL != hEventHandle)
                    {  
                        DWORD dwRes = WaitForSingleObject( hEventHandle,  0 );
                        if( WAIT_OBJECT_0 == dwRes )
                        {
                            g_fSTKInit = TRUE;
                            CloseHandle(hEventHandle);
                        }
                    }
                }

                if( g_fSTKInit )
                {
                    UINT i;
                
                    // shell's started.  safe to send toolkit notifications now.
                    for (i = 0; (i < MAX_TOOLKITNOTIFS) && (g_CachedToolKitNotifs[i]); i++)
                    {
                        CResponse *pRspCached = g_CachedToolKitNotifs[i];
                        void* pBlobCached;
                        UINT cbBlobCached;
                        pRspCached->GetBlob(pBlobCached, cbBlobCached);
                        (void)BroadcastRealBlobNotification(pRspCached->GetNotifyCode(), pBlobCached, cbBlobCached);
                        pRspCached->DeleteBlob();
                        pBlobCached = NULL;
                        cbBlobCached = 0;
                        delete pRspCached;
                        g_CachedToolKitNotifs[i] = NULL;
                    }
                }
            }
#endif


//after set AT+CFUN=0, we should broadcast all ME DEACT
          if ( TRUE == g_NotifyMEDeact)
          {
              RETAILMSG(1, (TEXT("[TI]need notify MEDEACT here!!!\r\n")));
              pRsp->GetBlob(pBlob, cbBlob);
              (void)BroadcastRealBlobNotification(pRsp->GetNotifyCode(), pBlob, cbBlob);
              g_NotifyMEDeact = FALSE;
          }

//xiangming add for the G/E icon function at 070718
/*
 The register and the icon just following below: 
 1: G1  2: G2 3: E2 4: G1/E2 5: E1 6: E1/G2 7: E1/E2 0: G1/G2

*/
            if (TRUE == g_fNetworkSystemChanged)
            {   
                BOOL Broadstate = TRUE;
                DWORD g_dwNetworkBroadType = RIL_SYSTEMTYPE_GSM;
                GPRS_REGISTER_STATUS Card1Status = GPRS_SYSTEMTYPE_FLAG_GSM;

⌨️ 快捷键说明

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