Click here to Skip to main content
15,891,828 members
Articles / Programming Languages / C++

3G Modem Internet Dialer

Rate me:
Please Sign up or sign in to vote.
4.90/5 (88 votes)
13 Jul 2011CPOL7 min read 776.1K   65.9K   192  
3G Modem Internet Dialer
#pragma once
#include <queue>
#include "MyRAS.h"
#include "Serial.h"


class CModem
{
public:
	enum EModemMode
	{
		eMODE_2G_ONLY,
		eMODE_2G_PREF,
		eMODE_3G_ONLY,
		eMODE_3G_PREF,
		eMODE_ANY
	};

	enum EModemBand
	{
		eBAND_GSM,
		eBAND_EGSM,
		eBAND_PGSM,
		eBAND_DCS,
		eBAND_PCS,
		eBAND_WCDMA,
		eBAND_ANY
	};

	enum EModemEvent
	{
		eMODEM_DURATION,
		eMODEM_UPLOAD_SPEED,
		eMODEM_DOWNLOAD_SPEED,
		eMODEM_DOWNLOADED_DATA,
		eMODEM_UPLOADED_DATA,
		eMODEM_SYS_MODE,
		eMODEM_RSSI,
		eMODEM_PROVIDER,
		eMODEM_APN,
		eMODEM_MANUFACTURER,
		eMODEM_PORT,
		eMODEM_MODEL,
		eMODEM_IMEI,
		eMODEM_FIRMWARE,
		eMODEM_HARDWARE,
		eMODEM_MODEM_MODE,
		eMODEM_MODEM_BAND
	};

	enum EModemSysSubMode
	{
		eMODEM_MODE_NA,
		eMODEM_MODE_GSM,
		eMODEM_MODE_GPRS,
		eMODEM_MODE_EDEG,
		eMODEM_MODE_WCDMA,
		eMODEM_MODE_HSDPA,
		eMODEM_MODE_HSUPA,
		eMODEM_MODE_HSPA,
	};

	CModem(CString sPort);
	virtual ~CModem(void);
	virtual BOOL Initialize(CWnd* pEventWnd) = 0;
	virtual void OnStatisticsTime(void); //Implement this function if u want to do something spicial every 2 sec.
	virtual void ReceivedMessage(char* szMsg, int iSize);
	virtual void ShutDown(void);


	void SetAPN(CString sAPN);
	void EnableStatistics(void);
	void SetMode(EModemMode eMode, EModemBand eBand);

	CString GetEntry(int iIndex);
	CString GetPort(void);

	int GetEntriesCount(void);
	int GetUpdateRate(void);
	int CheckIfAnyExistingConnection(void);

	BOOL HangUp(void);
	BOOL isDialing();
	BOOL isConnected(void);
	BOOL Dial(CString sEntry, CString sUser, CString sPassword);
	BOOL GetDialErrorMsg(DWORD dwError, CString &sMsg);

	//BOOL GetConnectionStatistics(DWORD &dwBytesXmited, DWORD &dwBytesRcved, DWORD &dwConnectDuration);
	//int ConnectionStatus(void);


protected:
	struct ReadOrderItem 
	{
		std::string sATCommand; //The Command needed for selecting the correct function to parse
		int iNumberOfLines; //Expected Number of lines in the reply usually 1 but let keep track just in case
	};

	//std::queue<ReadOrderItem> m_qReadOrderQueue;
	virtual void ParseMessageAndPost(char* szMsg, int iSize);
	virtual void ProcessLine(const char *szLine) = 0;
	virtual void AddToWriteQueue(std::string sBuffer);

	static UINT StatisticsThread(LPVOID pParam);

	int m_iUpdateRate;
	CString m_sPort;
	CMyRAS m_RAS;
	CWnd *m_pEventWnd;
	CSerial m_COMSerial;
	BOOL m_bEnableStatistics;

	HANDLE m_pStatisticsThread;
	OVERLAPPED m_oStatisticsThreadExit;

};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I love coding with C++. I always split my free time between coding and gaming Smile | :)

Comments and Discussions