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

📄 simtool.cpp

📁 代码为windows下的无线猫的应用程序(对AT指令的操作)。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SIMTOOL.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "SIMTOOL.h"
#include "SIMTOOLDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSIMTOOLApp

BEGIN_MESSAGE_MAP(CSIMTOOLApp, CWinApp)
	//{{AFX_MSG_MAP(CSIMTOOLApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSIMTOOLApp construction

CSIMTOOLApp::CSIMTOOLApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSIMTOOLApp object

CSIMTOOLApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSIMTOOLApp initialization

BOOL CSIMTOOLApp::InitInstance()
{
	HKEY hKey;
	DWORD dwDisp;
	char sn[20], sncode[255], vl[20], volumevalue[5];
	DWORD sType,Reserved;

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

	SetRegistryKey(_T("Angus Software Solutions"));

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	InitCommonControls();

	pPerf[PERF_ConnectSpeed] = new CAlexfPerf(ALEXF_PERF_DIALUP_CONNECTSPEED);
	pPerf[PERF_BytesRecvd]   = new CAlexfPerf(ALEXF_PERF_DIALUP_BYTESRECVD);
	pPerf[PERF_BytesXmit]    = new CAlexfPerf(ALEXF_PERF_DIALUP_BYTESXMIT);
	for (int i = 0; i < PERF_ARRAY; i++) if (NULL == pPerf[i]) return FALSE;

	// Create the tray icon
	if (!m_TrayIcon.Create(WM_ICON_NOTIFY,					// Icon notify message to use
					_T("安得邦无线网络管理系统 3.0 版"),	// tooltip
					LoadIcon(IDR_MAINFRAME),				// Icon
					IDR_POPUP_MENU))						// ID of tray icon
		return -1;

	int nLogLevel = GetProfileInt("Settings", "LogLevel" , 1);

	memset(sn, 0, 20);
	memset(sncode, 0, 255);
	memset(vl, 0, 20);
	memset(volumevalue, 0, 5);

	sprintf(sn, "modemsn");
	sprintf(vl, "volumevalue");
	Reserved = 0;
	sType=REG_SZ;
	RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ADBON\\SN",
   				   0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,
				   &hKey,&dwDisp);
    if (dwDisp==REG_CREATED_NEW_KEY)
	   RegSetValueEx(hKey,sn,Reserved,sType,(BYTE *)sncode,strlen(sncode));

	RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ADBON\\VOLUME",
   				   0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,
				   &hKey,&dwDisp);
    if (dwDisp==REG_CREATED_NEW_KEY)
	   RegSetValueEx(hKey,vl,Reserved,sType,(BYTE *)volumevalue,strlen(sncode));

	RegCloseKey(hKey);
/*
	if (nLogLevel)
	{
		// create configuration filename
		CString strFileName;

		GetAppDir(strFileName);
		strFileName += "simtooltrace.txt";

		m_LogFile.SetLogLevel(nLogLevel);

		// open log file
		m_LogFile.Open((LPCTSTR)strFileName);
	}
*/
	m_pRas = new CRasClient;
	m_bConnected = FALSE;

	CSIMTOOLDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	for (i = 0; i < PERF_ARRAY; i++) delete pPerf[i];

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

int CSIMTOOLApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	CFile tmpfile;
	CString strAppPath;
	char cTmpPath[MAX_PATH];

	memset(cTmpPath, 0, MAX_PATH);

	strAppPath = theApp.GetAppPath();
	sprintf(cTmpPath, "%s\\tmp.txt", strAppPath);

	if (tmpfile.Open(cTmpPath, CFile::modeRead) != 0)
	{
		tmpfile.Close();
		tmpfile.Remove(cTmpPath);
	}
	
	return CWinApp::ExitInstance();
}

void CSIMTOOLApp::NewRAS()
{
	m_pRas = new CRasClient;
}

void CSIMTOOLApp::DelRAS()
{
	delete m_pRas;
}

BOOL CSIMTOOLApp::CreateDialUpEntry()
{
	CString strEntry = "China Mobile GPRS";
	CString strWinVer;

	strWinVer = GetWinVer();
	// win95/98	use netbeui/ppp protocal
	/*
	if(m_pRas->CreateNewEntry(strEntry, "modem",
		m_strModemName, RASNP_NetBEUI, RASFP_Ppp, m_strPhone)
		!= ERROR_ALREADY_EXISTS)
	*/
	if (strWinVer == "Win98")
	{
		if(m_pRas->CreateNewEntry(strEntry, "modem",
		   m_strModemName, RASNP_Ip, RASFP_Ppp, m_phonenum/*"*99***1#"*/)
		   != ERROR_ALREADY_EXISTS)
		{
			DWORD dwfOptions = RASEO_SwCompression | 
				  RASEO_RequireEncryptedPw | RASEO_RequireMsEncryptedPw |
				  RASEO_UseLogonCredentials | RASEO_ModemLights 
				  | RASEO_IpHeaderCompression | RASEO_RemoteDefaultGateway;
			if(m_pRas->SetEntryOption(strEntry, dwfOptions, TRUE) != 0) 
			{
			}
		}
	}
	else
	{
		if (strWinVer == "WinNT")
		{
			if(m_pRas->CreateNewEntry(strEntry, "modem",
				m_strModemName, RASNP_Ip, /*RASFP_Ppp*/RASFP_Ras, m_phonenum/*"*99***1#"*/)
				!= ERROR_ALREADY_EXISTS)
			{
				DWORD dwfOptions = RASEO_SwCompression | 
					RASEO_RequireEncryptedPw | RASEO_RequireMsEncryptedPw |
					RASEO_UseLogonCredentials | RASEO_ModemLights;
				if(m_pRas->SetEntryOption(strEntry, dwfOptions, TRUE) != 0) 
				{
					/*
					m_strStatus = "Fail to Set adbon GPRS/GSM Modem Entry!";
					UpdateData(FALSE);
					return FALSE;
					*/
				}
			}
		}
	}
	return TRUE;
}


BOOL CSIMTOOLApp::GetRasConnection(CString strEntry, HRASCONN hrasConn)
{
	return m_pRas->GetRasConnection(strEntry, hrasConn);
}

BOOL CSIMTOOLApp::DialUpNetwork(CStatusDlg * pStatusDlg)
{
	m_dwError = 0;
	CString strEntry = "China Mobile GPRS";

	DWORD dwError = m_pRas->RasDialAsynCallback1(strEntry, 
		rasCallback1, m_phonenum/*"*99***1#"*/, m_username/*""*/, m_password/*""*/);

	BOOL bLoop = TRUE;
	BOOL bConnected = FALSE;

	while(bLoop)
	{
		CtrlYield();
		if(m_bUserCancel)
			return FALSE;

		bLoop = !(m_pRas->GetRasStatusString(m_strStatus, bConnected));
		pStatusDlg->SetStatus(m_strStatus);
		::Sleep(100);

		if(m_dwError != 0)
		{
			m_pRas->GetRasErrorStringByErrorCode(m_dwError, m_dwExtendError,
				m_strStatus);
			pStatusDlg->SetStatus(m_strStatus);
			m_pRas->HangUpConnection(strEntry);	
			return FALSE; 
		} 
	}

	if(bConnected)
		return TRUE;
	else
		return FALSE;
}

BOOL CSIMTOOLApp::HandUpConn()
{
	m_bUserCancel = TRUE;
	m_bConnected = FALSE;
	
	CString strEntry = "China Mobile GPRS";
	m_pRas->HangUpConnection(strEntry);
	
	mobile.CloseComm();

	return TRUE;
}

void CSIMTOOLApp::CtrlYield()
{
	MSG Msg;
	if(::PeekMessage (&Msg, NULL, 0, 0, PM_REMOVE))
	{
		::TranslateMessage(&Msg);
		::DispatchMessage(&Msg);
	}
}

CString CSIMTOOLApp::L2S(LONG l)
{
	CString ret;
	sprintf(ret.GetBuffer(512), "%ld", l);
	ret.ReleaseBuffer();
	return ret;
}

void CSIMTOOLApp::SetUserName(CString strUserName)
{
	m_username = strUserName;
}

void CSIMTOOLApp::SetPassWord(CString strPassWord)
{
	m_password = strPassWord;
}

void CSIMTOOLApp::SetPhoneNum(CString strPhoneNum)
{
	m_phonenum = strPhoneNum;
}

void CSIMTOOLApp::SetModemName(CString strModemName)
{
	m_strModemName = strModemName;
}

void CSIMTOOLApp::SetStartTime()
{
	_ftime(&start);
}

void CSIMTOOLApp::SetUserCancel(BOOL uc)
{
	m_bUserCancel = uc;
}

void CSIMTOOLApp::SetConnected(BOOL bConnected)
{
	m_bConnected = bConnected;
}

void CSIMTOOLApp::SetGPRSInited(BOOL bInit)
{
	m_GPRSInited = bInit;
}

void CSIMTOOLApp::SetAppComm(char * pComm)
{
	m_AppComm = pComm;
}

void CSIMTOOLApp::SetWinVer(char * pWinVer)
{
	m_WinVer = pWinVer;
}

void CSIMTOOLApp::SetRegSN(char * pSN)
{
	DWORD Reserved=0,cbvalue,Type;
	HKEY hKey;
	Type=REG_SZ;
	cbvalue=4;

	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ADBON\\SN",0,KEY_ALL_ACCESS,&hKey)==ERROR_SUCCESS) 
		RegSetValueEx(hKey,"modemsn",Reserved,Type,( unsigned char *)pSN,strlen(pSN) + 1); 	
	RegCloseKey(hKey);
}

void CSIMTOOLApp::SetVolume(char * pVL)
{
	DWORD Reserved=0,cbvalue,Type;
	HKEY hKey;
	Type=REG_SZ;
	cbvalue=4;

	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ADBON\\VOLUME",0,KEY_ALL_ACCESS,&hKey)==ERROR_SUCCESS) 
		RegSetValueEx(hKey,"volumevalue",Reserved,Type,( unsigned char *)pVL,strlen(pVL) + 1); 	
	RegCloseKey(hKey);
}

BOOL CSIMTOOLApp::GetGPRSInited()
{
	return m_GPRSInited;
}

BOOL CSIMTOOLApp::GetConnected()
{
	return m_bConnected;
}

CString CSIMTOOLApp::GetConnStatus()
{
	return m_strStatus;
}

long CSIMTOOLApp::GetModemCount()
{
	return m_pRas->GetModemCount();
}

BOOL CSIMTOOLApp::GetModemName()
{
	long iModemCount;
	iModemCount = GetModemCount();
	CString* strName = new CString[iModemCount];
	BOOL bResult = m_pRas->GetModemName(strName);
	strModemEnum = strName;

	return bResult;
}

CString * CSIMTOOLApp::GetModemEnum()
{
	return strModemEnum;
}

double CSIMTOOLApp::GetConnTime()
{
	double  timediff;

	_ftime(&finish);
	timediff = difftime(finish.time, start.time);

	return timediff;
}

char * CSIMTOOLApp::GetCommPort()
{
	return m_CommPort;
}

CString CSIMTOOLApp::GetDevType()
{
	return m_DevStyle;
}

CString CSIMTOOLApp::GetAppComm()
{
	return m_AppComm;
}

CString CSIMTOOLApp::GetWinVer()
{
	return m_WinVer;
}

CString CSIMTOOLApp::GetDevSN()
{
	CString RetInfo, strSN, buf;
	int i, j;

	mobile.SendAT();
	Sleep(10);
	RetInfo = mobile.ReceiveInfo();

	mobile.CGSN();
	Sleep(10);
	RetInfo = mobile.ReceiveInfo();

	i = RetInfo.Find("IMEI:");
	j = RetInfo.Find("IMEISV:");
	buf = RetInfo.Left(j-2);
	strSN = buf.Right(buf.GetLength()-i-5-1);

	return strSN;
}

CString CSIMTOOLApp::GetAppPath()
{
	char exepath[MAX_PATH];
	CString strdir, tmpdir;

	memset(exepath, 0, MAX_PATH);

	GetModuleFileName(NULL, exepath, MAX_PATH);
	tmpdir = exepath;
	strdir = tmpdir.Left(tmpdir.ReverseFind('\\'));

	return strdir;
}

CString CSIMTOOLApp::GetRegSN()
{
	DWORD d_Reserved=0,d_cbdata,d_Type,d_cbKeyName;
    char d_sn[255],d_valuename[30];
	CString strRet;

	HKEY d_hKey;
	// TODO: Add extra initialization here

	d_Type=REG_DWORD;
	d_cbdata=MAX_PATH;
	d_cbKeyName=30;

⌨️ 快捷键说明

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