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

📄 comport.cpp

📁 短信猫发送短信,使用PDU编码格式
💻 CPP
字号:
// ComPort.cpp: implementation of the CComPort class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "modem_SMS.h"
#include "ComPort.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CComPort::CComPort()
{
	_bInitOk=false;
	_Counter_CanSend=0;
	_bError=false;
	tLastSend=0;
	
}

CComPort::~CComPort()
{

}

bool CComPort::Init(int port)
{
	if(_bInitOk)return true;

	_port=port;
	_Counter_Total=0;
	_Counter_Fail=0;
	_Counter_CanSend=0;
	_Counter_Succ=0;

	if(InitModem(port, COM_BAUD)==TRUE) _bInitOk=true;

	return _bInitOk;
}

bool CComPort::modem_SendOneSms(char* phone,char* msg)
{
	char Buffer[1204];
	BOOL bSucc=SendSms(_port,COM_BAUD,msg,phone,FALSE,FALSE,TRUE);
	SendAtCommand(_port,COM_BAUD,"AT\r\n",Buffer,sizeof(Buffer));
	_Counter_Total++;//发送次数
	if(bSucc==TRUE)
	{
		_Counter_CanSend--; //可用数减一
		_Counter_Succ++;
		return true;
	}
	else
	{
		_Counter_Fail++;
	}
	return false;
}



bool CComPort::modem_GetSimSN(CString& SN)
{


	bool bSucc=false;
	SN="";
	char* pCmd="AT+CCID\r\n";
	char Buffer[1024];
	memset(Buffer,0x00,sizeof(Buffer));
	if(SendAtCommand(_port,COM_BAUD,pCmd,Buffer,sizeof(Buffer))==TRUE)
	{
		bSucc=true;
	}
	else
	{

		return false;
	}



	SN=Buffer;
	SN.MakeUpper();//+CCID: "89860106040201123320"
	SN.Replace("\r","");
	SN.Replace("\n","");
	SN.Replace("+","");
	SN.Replace("CCID","");
	SN.Replace(":","");
	SN.Replace(" ","");
	SN.Replace("\"","");	
	SN.Replace("ERROR","");
	SN.Replace("OK","");


	SendAtCommand(_port,COM_BAUD,"AT\r\n",Buffer,sizeof(Buffer));

	return bSucc;
}
//获取误码率
void CComPort::modem_GetSimErrorE()
{
	
	CString strReturn="";
	char* pCmd="AT+CSQ\r\n";
	char Buffer[1024];
	memset(Buffer,0x00,sizeof(Buffer));
	if(SendAtCommand(_port,COM_BAUD,pCmd,Buffer,sizeof(Buffer))==TRUE)
	{
		strReturn=Buffer;
		strReturn.MakeUpper();
		strReturn.Replace("\r","");
		strReturn.Replace("\n","");
		strReturn.Replace("+","");
		strReturn.Replace("CSQ","");
		strReturn.Replace(":","");
		strReturn.Replace(" ","");
		strReturn.Replace("\"","");	
		strReturn.Replace("ERROR","");
		strReturn.Replace("OK","");
		
		if(strReturn.Find(",")!=-1)
		{
			CString strMsg[2];
			int iCount=0;
			Tools::CMyTools::SplitString(strReturn,",",strMsg,iCount);
			if(iCount==2)
			{
				iSinal=atoi(strMsg[0]);
				iErrorE=atoi(strMsg[1]);
			}
		}		
	}
	else
	{
		iErrorE=-1;
		iSinal=-1;
	
	}
	SendAtCommand(_port,COM_BAUD,"AT\r\n",Buffer,sizeof(Buffer));
	return ;
}

bool CComPort::modem_SendOneSms(char* phone,char* msg,char* url)
{
	BOOL bSucc=SendWapPush(_port,COM_BAUD,msg,url,phone);
	_Counter_Total++;//发送次数
	if(bSucc==TRUE)
	{
		_Counter_Succ++;
		return true;
	}
	else
	{
		_Counter_Fail++;
	}
	
	return false;
}


void CComPort::ChangeSimCard(CString strSN,int CanSendCount)
{
	_SN=strSN;
	_Counter_CanSend=CanSendCount;
	_Counter_Succ=0;
	_Counter_Fail=0;
	_Counter_Total=0;

}

int CComPort::GetCanUseCount()
{
	return _Counter_CanSend;
}

⌨️ 快捷键说明

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