📄 irdamobiledlg.cpp
字号:
return;
}
GetDlgItem(IDC_MODEL)->SetWindowText(strModel);
GetDlgItem(IDC_MODEL)->UpdateWindow();
///////////////////////////////////////////////////////////////////////////
//
// Select the phonebook memory storage where phonebook commands operate.
//
// Command : AT+CPBS=storage<CR>
//
// storage ... memory where phonebook commands operate
//
// "FD" ... SIM fixdialling-phonebook
// "LD" ... SIM last-dialling-phonebook
// "ME" ... ME phonebook
// "MT" ... combined ME and SIM phonebook
// "SM" ... SIM phonebook
// "TA" ... TA phonebook
//
// Valid response: <CR><LF>OK<CR><LF>
//
// Error response: <CR><LF>ERROR<CR><LF>
//
// <CR> ... Carriage return
// <LF> ... Line feed
//
if (!port.Send(_T("AT+CPBS=\"SM\""), TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Failed to write request to device."));
return;
}
if (!port.WaitForResponse(strResponse, TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Timeout, no response."));
return;
}
strResponse.MakeUpper();
if (strResponse.Find(_T("ERROR")) > -1)
{
port.Close();
AfxMessageBox(_T("Invalid command."));
return;
}
else if (strResponse.Find(_T("OK")) == -1)
{
port.Close();
AfxMessageBox(_T("Wrong response."));
return;
}
///////////////////////////////////////////////////////////////////////////
//
// Read the size of the selected phonebook memory.
//
// Command : AT+CPBR=?<CR>
//
// Valid response: <CR><LF>+CPBR: (index-list),nlength,tlength<CR><LF>
// <CR><LF>OK<CR><LF>
//
// index ..... integer type values in the range of
// location numbers of phonebook memory
// list ...... integer type value indicating the size of
// the selected phonebook memory
// nlength ... integer type value indicating the maximum
// length of the number field
// tlength ... integer type value indicating the maximum
// length of name field
//
// Error response: <CR><LF>ERROR<CR><LF>
//
// <CR> ... Carriage return
// <LF> ... Line feed
//
if (!port.Send(_T("AT+CPBR=?"), TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Failed to write request to device."));
return;
}
if (!port.WaitForResponse(strResponse, TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Timeout, no response."));
return;
}
const CString strMemory(strResponse);
strResponse.MakeUpper();
// Check the response
int nPhoneBookSize = 0;
if (strResponse.Find(_T("CPBR")) > -1)
{
if (!port.WaitForResponse(strResponse, TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Timeout, no response."));
return;
}
strResponse.MakeUpper();
if (strResponse.Find(_T("OK")) > -1)
{
// Get the size of the phonebook memory
const int nStart = strMemory.Find(_T('-'));
const int nEnd = strMemory.Find(_T(')'), nStart + 1);
nPhoneBookSize = _ttoi((LPCTSTR) strMemory.Mid(nStart + 1, nEnd - nStart - 1));
ASSERT(nPhoneBookSize >= 0);
// AfxMessageBox(strMemory.Mid(nStart + 1, nEnd - nStart - 1));
}
else
{
port.Close();
AfxMessageBox(_T("Wrong response."));
return;
}
}
else if (strResponse.Find(_T("ERROR")) > -1)
{
port.Close();
AfxMessageBox(_T("Invalid command."));
return;
}
else
{
port.Close();
AfxMessageBox(_T("Wrong response."));
return;
}
///////////////////////////////////////////////////////////////////////////
//
// Read all phonebook entries.
//
// Command : AT+CPBR=index<CR>
//
// index ... integer type values in the range of
// location numbers of phonebook memory
//
// Valid response: <CR><LF>+CPBR: index, "number", type, "name"<CR><LF>
// <CR><LF>OK<CR><LF>
//
// index .... integer type values in the range of
// location numbers of phonebook memory
// number ... string type phone number of format type
// type ..... type of address octet in integer format
// name ..... the name of the phonebook entry
//
// Response for
// an empty entry: <CR><LF>OK<CR><LF>
//
// Error response: <CR><LF>ERROR<CR><LF>
//
// <CR> ... Carriage return
// <LF> ... Line feed
//
int nNumberOfEntries = 0;
for (int n = 1; n <= nPhoneBookSize; n++)
{
CString strCommand;
strCommand.Format(_T("AT+CPBR=%d"), n);
if (!port.Send(strCommand, TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Failed to write request to device."));
return;
}
// Wait for response
if (!port.WaitForResponse(strResponse, TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Timeout, no response."));
return;
}
const CString strEntry(strResponse);
strResponse.MakeUpper();
// Check the response
if (strResponse.Find(_T("CPBR")) > -1)
{
if (!port.WaitForResponse(strResponse, TIMEOUT))
{
port.Close();
AfxMessageBox(_T("Timeout, no response."));
return;
}
strResponse.MakeUpper();
if (strResponse.Find(_T("OK")) > -1)
{
// Insert the name and the number in the list box
int nStart = strEntry.Find(_T('\"'));
int nEnd = strEntry.Find(_T('\"'), nStart + 1);
const CString strNumber = strEntry.Mid(nStart + 1, nEnd - nStart - 1);
// AfxMessageBox(strNumber);
nStart = strEntry.Find(_T('\"'), nEnd + 1);
nEnd = strEntry.Find(_T('\"'), nStart + 1);
const CString strName = strEntry.Mid(nStart + 1, nEnd - nStart - 1);
// AfxMessageBox(strName);
m_ctrlList.InsertItem(0, strName);
m_ctrlList.SetItemText(0, 1, strNumber);
m_ctrlList.Update(n);
CString strEntries;
strEntries.Format(_T("%d Entries"), ++nNumberOfEntries);
GetDlgItem(IDC_ENTRIES)->SetWindowText(strEntries);
GetDlgItem(IDC_ENTRIES)->UpdateWindow();
}
else
{
port.Close();
AfxMessageBox(_T("Wrong response."));
return;
}
}
else if (strResponse.Find(_T("OK")) > -1)
{
continue; // empty phonebook entry
}
else if (strResponse.Find(_T("ERROR")) > -1)
{
port.Close();
AfxMessageBox(_T("Invalid command."));
return;
}
else
{
port.Close();
AfxMessageBox(_T("Wrong response."));
return;
}
}
///////////////////////////////////////////////////////////////////////////
//
// Close the IRDA port.
//
port.Close();
}
HBRUSH CIrdaMobileDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
switch (pWnd->GetDlgCtrlID())
{
case IDC_PHONE:
case IDC_MODEL:
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0, 0, 0));
return CreateSolidBrush(RGB(255, 255, 255));
break;
}
if (nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
hbr = CreateSolidBrush(RGB(192, 192, 192));
}
else if (pWnd == this)
{
hbr = CreateSolidBrush(RGB(192, 192, 192));
}
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -