?? msg.cpp
字號:
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))
{
hr = E_FAIL;
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(g_rppPDDParams->etEncodingTECharset, 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);
CNotificationData* pnd = NULL;
char szCmd[MAX_PATH];
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle)
{
hr = E_FAIL;
goto Error;
}
pnd = new CNotificationData;
if (pnd && !pnd->InitFromDWORDBlob(RIL_NOTIFY_MSGDELETED, dwIndex))
{
delete pnd;
pnd = NULL;
}
(void)_snprintfz(szCmd, MAX_PATH, "AT+CMGD=%u\r", dwIndex);
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_DELETEMSG, NULL, pnd, hr))
{
hr = E_FAIL;
goto Error;
}
pnd = NULL;
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);
CNotificationData* pnd = NULL;
char szCmd[MSG_CMDBUF_LENGTH];
char szCmd2[MSG_CMDBUF_LENGTH];
char szMessage[MSG_MSGBUF_LENGTH];
UINT cbMessage;
UINT nGSMLength;
UINT nValue=0;
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 || cbMessage >= sizeof(szMessage) / sizeof(*szMessage) )
{
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;
}
pnd = new CNotificationData;
if (pnd && !pnd->DelayInitFromRspBlob(RIL_NOTIFY_MSGSTORED))
{
delete pnd;
pnd = NULL;
}
(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, pnd, hr))
{
hr = E_FAIL;
goto Error;
}
pnd = NULL;
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 || cbMessage >= sizeof(szMessage) / sizeof(*szMessage) )
{
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 + -