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

📄 msg.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                                szBroadcastMsgIDs,
                                MAX_PATH);

            (void)_snprintfz(szWalk, MAX_PATH, ",\"%s\"", szBroadcastMsgIDs);
            szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
            DEBUGCHK(NULL != szWalk);

        }

        if (lpMsgConfigInfo->dwParams & RIL_PARAM_CBMC_BROADCASTMSGLANGS)
        {
            MakeBroadcastLangRange(lpMsgConfigInfo->dwBroadcastMsgLangs, szCBMsgLangs, MAX_PATH);

            (void)_snprintfz(szWalk, MAX_PATH - (szWalk - szCmd), "%s,\"%s\"", (lpMsgConfigInfo->dwParams & RIL_PARAM_CBMC_BROADCASTMSGIDS)?"":",", szCBMsgLangs);
            szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
            DEBUGCHK(NULL != szWalk);
        }
    }

    (void)_snprintfz(szWalk, MAX_PATH - (szWalk - szCmd), ";+CSAS\r");

    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SETCBMSGCONFIG, NULL, NULL, hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}

//
//
//
static HRESULT ParseReadMsg(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseReadMsg);
    UINT nValue;
    UINT cbMessage;
    BOOL fIncoming;
    RILMESSAGEINFO* prmi = NULL;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    prmi = (RILMESSAGEINFO*)AllocBlob(sizeof(RILMESSAGEINFO));
    if (!prmi)
    {
        hr = E_OUTOFMEMORY;
        goto Error;
    }
    memset(prmi, 0x00, sizeof(RILMESSAGEINFO));
    prmi->cbSize = sizeof(RILMESSAGEINFO);

    // Parse "<prefix>+CMGR: <stat>"
    if (!ParseRspPrefix(szRsp, szRsp)                  ||
        !MatchStringBeginning(szRsp, "+CMGR: ", szRsp) ||
        !ParseUInt(szRsp, TRUE, nValue, szRsp))
    {
#if defined(OEM2_DRIVER)
		hr = RIL_E_INVALIDINDEX;		// OEM1 and Wavecom return +CMS ERROR 321 whereas OEM1 returns OK. Mangle OEM2 response.
#else
		hr = E_FAIL;
#endif
        goto Error;
    }

    if (NUM_MSGSTATS > nValue)
    {
        prmi->dwStatus = g_rgdwMsgStats[nValue];
    }
    else
    {
        prmi->dwStatus = RIL_MSGSTATUS_UNKNOWN;
    }
    prmi->dwParams |= RIL_PARAM_MI_STATUS;

    // Parse",<alpha>" (if present)
    if (!MatchStringBeginning(szRsp, ",", szRsp))
    {
        hr = E_FAIL;
        goto Error;
    }

    // Copy alpha to temp buffer & throw away
    TCHAR szBuf[MAXLENGTH_ADDRESS];
    (void)ParseQuotedEncodedString(ENCODING_TECHARSET, szRsp, szBuf, szBuf + MAXLENGTH_ADDRESS);

    // Parse ",<length><postfix>"
    if (!MatchStringBeginning(szRsp, ",", szRsp)  ||
        !ParseUInt(szRsp, TRUE, nValue, szRsp) ||
        !ParseRspPostfix(szRsp, szRsp))
    {
        hr = E_FAIL;
        goto Error;
    }

    // Calculate the total number of bytes in the message data: (length of the PDU data +
    //    length os SC address (stored in the first 2 bytes) + 1) * 2
    cbMessage = (nValue + 1 + SemiByteCharsToByte(*szRsp, *(szRsp + 1))) * 2;

    // Parse "<pdu>"
    fIncoming = (RIL_MSGSTATUS_RECUNREAD == prmi->dwStatus ||
                 RIL_MSGSTATUS_RECREAD == prmi->dwStatus);
    hr = ParseSMSMessage(szRsp, cbMessage, fIncoming, TRUE, prmi->rmMessage);
    if (FAILED(hr))
    {
        goto Error;
    }
    szRsp += cbMessage;
    prmi->dwParams |= RIL_PARAM_MI_MESSAGE;

    // Parse "<postfix>"
    if (!ParseRspPostfix(szRsp, szRsp))
    {
        hr = E_FAIL;
        goto Error;
    }

    // NOTE: there may be more data in the response (if we also deleted the message),
    //       but we don't care about it

    pBlob = (void*)prmi;
    cbBlob = sizeof(RILMESSAGEINFO);
            
    Error:
    if (FAILED(hr))
    {
        FreeBlob(prmi);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_ReadMsg(DWORD dwParam, DWORD dwIndex)
{
    FUNCTION_TRACE(RILDrv_ReadMsg);
    CNotificationData* pnd = NULL;
    char szCmd[MAX_PATH];
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    
    if (!pHandle)
    {
        hr = E_FAIL;
        goto Error;
    }

    (void)_snprintfz(szCmd, MAX_PATH, "AT+CMGR=%u\r", dwIndex);
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_READMSG, ParseReadMsg, pnd, hr))
    {
        hr = E_FAIL;
        goto Error;
    }
    pnd = NULL;

    Error:
    return hr;
}


//
//
//
HRESULT RILDrv_DeleteMsg(DWORD dwParam, DWORD dwIndex)
{
    FUNCTION_TRACE(RILDrv_DeleteMsg);
    char szCmd[MAX_PATH];
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle)
    {
        hr = E_FAIL;
        goto Error;
    }

    //Begin.   ___added for importing short messages under dual cards condition.
    //does not notify MS the status of short messages, the status is operated by app.
#if 0
    pnd = new CNotificationData;
    if (pnd && !pnd->InitFromDWORDBlob(RIL_NOTIFY_MSGDELETED, dwIndex))
    {
        delete pnd;
        pnd = NULL;
    }
#endif 
    //End.   ___added for importing short messages under dual cards condition.
    
    (void)_snprintfz(szCmd, MAX_PATH, "AT+CMGD=%u\r", dwIndex);
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_DELETEMSG, NULL, NULL, hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}


//
//
//
static HRESULT ParseWriteMsg(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseWriteMsg);
    UINT nValue;
    DWORD* pdwIndex = NULL;
    HRESULT hr = E_FAIL;

    pBlob = NULL;
    cbBlob = 0;

    pdwIndex = (DWORD*)AllocBlob(sizeof(DWORD));
    if (!pdwIndex)
    {
        hr = E_OUTOFMEMORY;
        goto Error;
    }
    memset(pdwIndex, 0x00, sizeof(DWORD));

    // Parse "+CMGW: <index><postfix>"
    if (!MatchStringAnywhere(szRsp, "+CMGW: ", szRsp) ||
        !ParseUInt(szRsp, TRUE, nValue, szRsp)        ||
        !ParseRspPostfix(szRsp, szRsp))
    {
        goto Error;
    }

    *pdwIndex = (DWORD)nValue;

    pBlob = (void*)pdwIndex;
    cbBlob = sizeof(DWORD);
    hr = S_OK;

    Error:
    if (FAILED(hr))
    {
        FreeBlob(pdwIndex);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_WriteMsg(DWORD dwParam, const RILMESSAGE *lpMessage, DWORD dwStatus)
{
    FUNCTION_TRACE(RILDrv_WriteMsg);
    char szCmd[MSG_CMDBUF_LENGTH];
    char szCmd2[MSG_CMDBUF_LENGTH];
    char szMessage[MSG_MSGBUF_LENGTH];
    UINT cbMessage;
    UINT nGSMLength;
    UINT nValue;
    UINT i;
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle || !lpMessage)
    {
        hr = E_FAIL;
        goto Error;
    }

    hr = EncodeSMSMessage(*lpMessage, szMessage, MSG_MSGBUF_LENGTH - 1, cbMessage, nGSMLength);
    if (FAILED(hr))
    {
        goto Error;
    }
    if (!cbMessage)
    {
        hr = E_FAIL;
        goto Error;
    }
    szMessage[cbMessage] = '\0';

    for (i = 0; i < NUM_MSGSTATS; i++)
    {
        if (dwStatus == g_rgdwMsgStats[i])
        {
            nValue = i;
            break;
        }
    }
    if (NUM_MSGSTATS == i)
    {
        hr = E_INVALIDARG;
        goto Error;
    }


   //Begin.   ___added for importing short messages under dual cards condition.
    //does not notify MS the status of short messages, the status is operated by app.
#if 0
    pnd = new CNotificationData;
    if (pnd && !pnd->DelayInitFromRspBlob(RIL_NOTIFY_MSGSTORED))
    {
        delete pnd;
        pnd = NULL;
    }
#endif
    //End.   ___added for importing short messages under dual cards condition.
    
    (void)_snprintfz(szCmd, MSG_CMDBUF_LENGTH, "AT+CMGW=%u,%u\r", nGSMLength, nValue);
    (void)_snprintfz(szCmd2, MSG_CMDBUF_LENGTH,  "%s\x1a", szMessage);
    if (!QueueMultipartCmd(pHandle, szCmd, szCmd2, CMDOPT_INTERMEDIATERESPONSE, APIID_WRITEMSG, ParseWriteMsg, NULL, hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}


//
//
//
static HRESULT ParseSendMsg(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseSendMsg);
    UINT nValue;
    DWORD* pdwMsgRef = NULL;
    HRESULT hr = E_FAIL;

    pBlob = NULL;
    cbBlob = 0;

    pdwMsgRef = (DWORD*)AllocBlob(sizeof(DWORD));
    if (!pdwMsgRef)
    {
        hr = E_OUTOFMEMORY;
        goto Error;
    }
    memset(pdwMsgRef, 0x00, sizeof(DWORD));

    if (!MatchStringAnywhere(szRsp, "+CMGS: ", szRsp) &&
        !MatchStringAnywhere(szRsp, "+CMGC: ", szRsp))
    {
        goto Error;
    }

    // Parse "<msgref><CR><LF>"
    if (!ParseUInt(szRsp, TRUE, nValue, szRsp) ||
        !ParseRspPostfix(szRsp, szRsp))
    {
        goto Error;
    }

    *pdwMsgRef = (DWORD)nValue;

    pBlob = (void*)pdwMsgRef;
    cbBlob = sizeof(DWORD);
    hr = S_OK;

    Error:
    if (FAILED(hr))
    {
        FreeBlob(pdwMsgRef);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_SendMsg(DWORD dwParam, const RILMESSAGE *lpMessage, DWORD dwOptions)
{
    FUNCTION_TRACE(RILDrv_SendMsg);
    char szCmd[MSG_CMDBUF_LENGTH];
    char szCmd2[MSG_CMDBUF_LENGTH];
    LPCSTR szATCmd;
    char szMessage[MSG_MSGBUF_LENGTH];
    UINT cbMessage;
    UINT nGSMLength;
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle || !lpMessage)
    {
        hr = E_FAIL;
        goto Error;
    }

    // We can only send outgoing messages
    if (RIL_MSGCLASS_OUTGOING != MSGCLASS_FROM_MSGTYPE(lpMessage->dwType))
    {
        hr = E_INVALIDARG;
        goto Error;
    }

    hr = EncodeSMSMessage(*lpMessage, szMessage, MSG_MSGBUF_LENGTH - 1, cbMessage, nGSMLength);
    if (FAILED(hr))
    {
        goto Error;
    }
    if (!cbMessage)
    {
        hr = E_FAIL;
        goto Error;
    }
    szMessage[cbMessage] = '\0';

    if ((RIL_MSGTYPE_OUT_SUBMIT == lpMessage->dwType) || (RIL_MSGTYPE_OUT_RAW == lpMessage->dwType))
    {
        szATCmd = "CMGS";
    }
    else if (RIL_MSGTYPE_OUT_COMMAND == lpMessage->dwType)
    {
        szATCmd = "CMGC";
    }
    else
    {
        hr = E_INVALIDARG;
        goto Error;
    }

    if (dwOptions & RIL_SENDOPT_PERSISTLINK)
    {
        (void)_snprintfz(szCmd, MSG_CMDBUF_LENGTH, "AT+CMMS=1;+%s=%u\r", szATCmd, nGSMLength);
    }
    else
    {
        (void)_snprintfz(szCmd, MSG_CMDBUF_LENGTH, "AT+%s=%u\r", szATCmd, nGSMLength);
    }

    (void)_snprintfz(szCmd2, MSG_CMDBUF_LENGTH,  "%s\x1a", szMessage);

    if (!QueueMultipartCmd(pHandle, szCmd, szCmd2, CMDOPT_RETRYONSIMLOCKED | CMDOPT_INTERMEDIATERESPONSE, APIID_SENDMSG, ParseSendMsg, NULL, hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}


//
//
//
static HRESULT ParseSendStoredMsg(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseSendStoredMsg);
    UINT nValue;
    DWORD* pdwMsgRef = NULL;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    pdwMsgRef = (DWORD*)AllocBlob(sizeof(DWORD));
    if (!pdwMsgRef)
    {
        hr = E_OUTOFMEMORY;
        goto Error;
    }
    memset(pdwMsgRef, 0x00, sizeof(DWORD));

    // Parse "<prefix>+CMSS: <msgref><postfix>"
    if (!ParseRspPrefix(szRsp, szRsp)                  ||
        !MatchStringBeginning(szRsp, "+CMSS: ", szRsp) ||
        !ParseUInt(szRsp, TRUE, nValue, szRsp)         ||
        !ParseRspPostfix(szRsp, szRsp))
    {
        hr = E_FAIL;
        goto Error;
    }

    *pdwMsgRef = (DWORD)nValue;

    pBlob = (void*)pdwMsgRef;
    cbBlob = sizeof(DWORD);

    Error:
    if (FAILED(hr))
    {
        FreeBlob(pdwMsgRef);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_SendStoredMsg(DWORD dwParam, DWORD dwIndex, DWORD dwOptions)
{
    FUNCTION_TRACE(RILDrv_SendStoredMsg);
    char szCmd[MAX_PATH];
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle)
    {
        hr = E_FAIL;
        goto Error;
    }

    if (dwOptions & RIL_SENDOPT_PERSISTLINK)
    {
        (void)_snprintfz(szCmd, MAX_PATH, "AT+CMMS=1;+CMSS=%u\r", dwIndex);
    }
    else
    {
        (void)_snprintfz(szCmd, MAX_PATH, "AT+CMSS=%u\r", dwIndex);
    }

    if (!QueueCmd(pHandle, szCmd, CMDOPT_RETRYONSIMLOCKED, APIID_SENDSTOREDMSG, ParseSendStoredMsg, NULL, hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}


//
//
//
HRESULT RILDrv_SendMsgAcknowledgement(DWORD dwParam, BOOL fSuccess)
{
    FUNCTION_TRACE(RILDrv_SendMsgAcknowledgement);
    char szCmd[MAX_PATH];
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle)
    {
        hr = E_FAIL;
        goto Error;
    }

    (void)_snprintfz(szCmd, MAX_PATH, "AT+CNMA=%u\r", fSuccess ? 1 : 2);
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SENDMSGACKNOWLEDGEMENT, NULL, NULL, hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}

⌨️ 快捷键说明

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