📄 simtool.cpp
字号:
memset(d_sn,0,255);
memset(d_valuename,0,30);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ADBON\\SN",0,KEY_ALL_ACCESS,&d_hKey)==ERROR_SUCCESS)
RegEnumValue(d_hKey,0,d_valuename,&d_cbKeyName,0,&d_Type,(LPBYTE)d_sn,&d_cbdata);
RegCloseKey(d_hKey);
strRet = d_sn;
return strRet;
}
CString CSIMTOOLApp::GetVolume()
{
DWORD d_Reserved=0,d_cbdata,d_Type,d_cbKeyName;
char d_vl[255],d_value[30];
CString strRet;
HKEY d_hKey;
// TODO: Add extra initialization here
d_Type=REG_DWORD;
d_cbdata=MAX_PATH;
d_cbKeyName=30;
memset(d_vl,0,255);
memset(d_value,0,30);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ADBON\\VOLUME",0,KEY_ALL_ACCESS,&d_hKey)==ERROR_SUCCESS)
RegEnumValue(d_hKey,0,d_value,&d_cbKeyName,0,&d_Type,(LPBYTE)d_vl,&d_cbdata);
RegCloseKey(d_hKey);
strRet = d_vl;
return strRet;
}
BOOL CSIMTOOLApp::GPRSInit()
{
CString RetInfo, sDevComm, sStatus, sAppComm;
char comm[20];
memset(comm, 0, 20);
sAppComm = GetAppComm();
sDevComm = OpenDev(comm, 9600);
sprintf(comm, "%s", sAppComm);
if (sDevComm.GetLength() == 0)
{
sDevComm = MultiBautOpenDev(comm);
if (sDevComm.GetLength() == 0)
{
mobile.CloseComm();
return FALSE;
}
else
{
sDevComm = OpenDev(comm, 9600);
}
}
if (GetDevType() == "WAVECOM")
{
// WAVECOM
// 将波特率设置为 auto
mobile.IPR(0);
Sleep(10);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CGCLASS("B"); // 置为"B"模式
Sleep(10);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CGDCONT(1, "IP", "cmnet"); // 设置APN
Sleep(10);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CSQ(); // 检查信号
Sleep(10);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CGACT(1, 1);
Sleep(10);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.SETCGREG(0);
Sleep(10);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CGREG();
Sleep(10);
RetInfo = mobile.ReceiveInfo();
mobile.CloseComm();
}
if (GetDevType() == "BENQ")
{
// BENQ
RetInfo = mobile.CFUN();
Sleep(2);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.COPS();
Sleep(2);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.QCOPS();
Sleep(2);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CGDCONT(1, "IP", "CMNET"); // 设置APN
Sleep(2);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CGATT(1);
Sleep(2);
RetInfo = mobile.ReceiveInfo();
RetInfo = mobile.CGREG();
Sleep(2);
RetInfo = mobile.ReceiveInfo();
// 将波特率设置为 auto
mobile.IPR(0);
Sleep(2);
RetInfo = mobile.ReceiveInfo();
mobile.CloseComm();
}
if (theApp.GetDevType() == "SAGEM MO1xx")
{
// SAGEM MO1xx
mobile.SetModuleType("SAGEM MO1xx");
}
return TRUE;
}
void CSIMTOOLApp::SetStatusText(char * cStatus)
{
m_wndStatusBar.SetPaneText(0, cStatus, TRUE);
}
void CSIMTOOLApp::SetDevText(char * cDev)
{
m_wndStatusBar.SetPaneText(1, cDev, TRUE);
}
CString CSIMTOOLApp::ResearchDev(int iBautrate)
{
HKEY hKey;
LONG ret;
OSVERSIONINFO osvi;
BOOL bOsVersionInfoEx, bComisOK;
char keyinfo[100],comm_name[40],ValueName[200], CommPort[20];
int i;
DWORD sType,Reserved,cbData,cbValueName;
CString sDevComm(_T("")), RetInfo(_T(""));
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
memset(ValueName, 0, 200);
memset(keyinfo,0,100);
memset(CommPort, 0, 20);
strcpy(keyinfo,"HARDWARE\\DEVICEMAP\\SERIALCOMM");
i=0; sType=REG_SZ;Reserved=0;
bOsVersionInfoEx =GetVersionEx(&osvi);
ret=RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyinfo,0,KEY_ALL_ACCESS,&hKey);
if (ret==ERROR_SUCCESS){
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
SetWinVer("Win98");
for(i=1;i<=12;i++)
{
sprintf(comm_name,"COM%d",i);
strcpy(CommPort,"\\\\.\\");
strcat(CommPort,comm_name);
bComisOK = mobile.OpenComm(CommPort, iBautrate);
if (!bComisOK)
{}
else
{
mobile.GetDevInfo();
//Sleep(10);
RetInfo = mobile.ReceiveInfo();
if (RetInfo.GetLength() != 0)
{
// WAVECOM
if (RetInfo.Find("WAVECOM")!=-1 &&
RetInfo.Find("OK") != -1)
{
RegCloseKey(hKey);
sprintf(m_CommPort, "%s", CommPort);
sDevComm = comm_name;
m_DevStyle = "WAVECOM";
return sDevComm;
}
// SAGEM
if (RetInfo.Find("MO1xx")!=-1 &&
RetInfo.Find("GPRS")!=-1 &&
RetInfo.Find("OK") != -1)
{
RegCloseKey(hKey);
sprintf(m_CommPort, "%s", CommPort);
sDevComm = comm_name;
m_DevStyle = "SAGEM MO1xx";
return sDevComm;
}
// BENQ
if (RetInfo.Find("<manufacturer1>")!=-1 &&
RetInfo.Find("OK") != -1)
{
RegCloseKey(hKey);
sprintf(m_CommPort, "%s", CommPort);
sDevComm = comm_name;
m_DevStyle = "BENQ";
return sDevComm;
}
// 不是以上三种模块
mobile.CloseComm();
}
else
{
mobile.CloseComm();
}
}
}
}
else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
SetWinVer("WinNT");
do
{
cbData=40;cbValueName=40;
memset(comm_name,0,40);
memset(ValueName,0,40);
ret=RegEnumValue(hKey,i,ValueName,&cbValueName,NULL,&sType,(LPBYTE)comm_name,&cbData);
i++;
strcpy(CommPort,"\\\\.\\");
strcat(CommPort,comm_name);
bComisOK = mobile.OpenComm(CommPort, iBautrate);
if (!bComisOK)
{}
else
{
mobile.GetDevInfo();
//Sleep(10);
RetInfo = mobile.ReceiveInfo();
if (RetInfo.GetLength() != 0)
{
// WAVECOM
if (RetInfo.Find("WAVECOM")!=-1 &&
RetInfo.Find("OK") != -1)
{
RegCloseKey(hKey);
sprintf(m_CommPort, "%s", CommPort);
sDevComm = comm_name;
m_DevStyle = "WAVECOM";
return sDevComm;
}
// SAGEM
if (RetInfo.Find("MO1xx")!=-1 &&
RetInfo.Find("GPRS")!=-1 &&
RetInfo.Find("OK") != -1)
{
RegCloseKey(hKey);
sprintf(m_CommPort, "%s", CommPort);
sDevComm = comm_name;
m_DevStyle = "SAGEM MO1xx";
return sDevComm;
}
// BENQ
if (RetInfo.Find("OK") != -1
&& RetInfo.Find("<manufacturer1>")!=-1)
{
RegCloseKey(hKey);
sprintf(m_CommPort, "%s", CommPort);
sDevComm = comm_name;
m_DevStyle = "BENQ";
return sDevComm;
}
// 不是以上三种模块
mobile.CloseComm();
}
else
{
mobile.CloseComm();
}
}
}while (ret==ERROR_SUCCESS);
}
}
RegCloseKey(hKey);
return sDevComm;
}
CString CSIMTOOLApp::MultiBautResearch()
{
CString sDevComm, RetInfo;
int i, iBaut[] = {/*2400, 4800,*/ 9600, 14400, 19200, 38400, 57600, 115200};
i = 0;
do
{
sDevComm = ResearchDev(iBaut[i]);
i++;
}
while(sDevComm.GetLength() == 0 && i<6);
if (sDevComm.GetLength() == 0)
{
mobile.CloseComm();
}
else
{
mobile.IPR(0);
RetInfo = mobile.ReceiveInfo();
mobile.CloseComm();
}
return sDevComm;
}
CString CSIMTOOLApp::OpenDev(char * pComm, int iBautrate)
{
char CommPort[20];
BOOL bComisOK;
CString sDevComm, RetInfo;
memset(CommPort, 0, 20);
strcpy(CommPort,"\\\\.\\");
strcat(CommPort,pComm);
bComisOK = mobile.OpenComm(CommPort, iBautrate);
if (!bComisOK)
{}
else
{
mobile.GetDevInfo();
//Sleep(10);
RetInfo = mobile.ReceiveInfo();
if (RetInfo.GetLength() != 0)
{
// WAVECOM
if (RetInfo.Find("WAVECOM")!=-1 &&
RetInfo.Find("OK") != -1)
{
sprintf(m_CommPort, "%s", CommPort);
sDevComm = pComm;
m_DevStyle = "WAVECOM";
return sDevComm;
}
// SAGEM
if (RetInfo.Find("MO1xx")!=-1 &&
RetInfo.Find("GPRS")!=-1 &&
RetInfo.Find("OK") != -1)
{
sprintf(m_CommPort, "%s", CommPort);
sDevComm = pComm;
m_DevStyle = "SAGEM MO1xx";
return sDevComm;
}
// BENQ
if (RetInfo.Find("<manufacturer1>")!=-1 &&
RetInfo.Find("OK") != -1)
{
sprintf(m_CommPort, "%s", CommPort);
sDevComm = pComm;
m_DevStyle = "BENQ";
return sDevComm;
}
// 不是以上三种模块
mobile.CloseComm();
}
else
{
mobile.CloseComm();
}
}
return "";
}
CString CSIMTOOLApp::MultiBautOpenDev(char * pComm)
{
CString sDevComm, RetInfo;
int i, iBaut[] = {/*2400, 4800,*/ 9600, /*14400,*/ 19200, /*38400,*/ 57600, 115200};
i = 0;
do
{
sDevComm = OpenDev(pComm, iBaut[i]);
i++;
}
while(sDevComm.GetLength() == 0 && i<4);
if (sDevComm.GetLength() == 0)
{
mobile.CloseComm();
}
else
{
mobile.IPR(0);
RetInfo = mobile.ReceiveInfo();
mobile.CloseComm();
}
return sDevComm;
}
BOOL CSIMTOOLApp::CheckSN(char * pSN)
{
CString strSN, RegSN, strBuf;
char key[]={0,2,0,0,9,3,5,1,9,8,0,0,9,1,7}, buf[255], sn[20], dsn[255];
memset(sn, 0, 20);
memset(buf, 0, 255);
memset(dsn, 0, 255);
RegSN = pSN;
strSN = GetDevSN();
sprintf(sn, "%s", strSN);
m_encrypt.Des_Go(buf, sn, sizeof(sn), key, sizeof(key), ENCRYPT);
mobile.gsmBytes2String((unsigned char *)buf, dsn, strlen(buf));
strBuf = dsn;
strSN = // first group
strBuf.Left(1) +
strBuf.Right(1) +
strBuf.Left(3).Right(1) +
strBuf.Right(3).Left(1) +
strBuf.Left(5).Right(1) +
// second group
strBuf.Right(5).Left(1) +
strBuf.Left(7).Right(1) +
strBuf.Right(7).Left(1) +
strBuf.Left(9).Right(1) +
strBuf.Right(9).Left(1) +
// third group
strBuf.Right(11).Left(1) +
strBuf.Left(11).Right(1) +
strBuf.Right(13).Left(1) +
strBuf.Left(13).Right(1) +
strBuf.Right(15).Left(1) +
// fourth group
strBuf.Right(15).Left(1) +
strBuf.Left(16).Right(1) +
strBuf.Right(16).Left(1) +
strBuf.Left(17).Right(1) +
strBuf.Right(17).Left(1) +
// forth group
strBuf.Right(19).Left(1) +
strBuf.Left(19).Right(1) +
strBuf.Right(21).Left(1) +
strBuf.Left(21).Right(1) +
strBuf.Right(23).Left(1);
if (RegSN == strSN)
{
return TRUE;
}
else
{
return FALSE;
}
}
BOOL CSIMTOOLApp::CreateModem(char * pDevComm, char * pInfName)
{
BOOL bRet;
bRet = TRUE;
m_Modem.InstallSuntekModem(pDevComm, pInfName);
return bRet;
}
void CALLBACK rasCallback1(HRASCONN hrasconn, UINT unMsg, RASCONNSTATE rascs,
DWORD dwError, DWORD dwExtendedError)
{
if(m_dwError == 0 && dwError != 0)
{
m_dwError = dwError;
m_dwExtendError = dwExtendedError;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -