📄 mobilemodule.cpp
字号:
// MobileModule.cpp: implementation of the CMobileModule class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MobileModule.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMobileModule::CMobileModule()
{
smsmode = (_T(""));
smscenter = (_T("+8613800100500"));
m_ModuleType = (_T("WAVECOM"));
}
CMobileModule::~CMobileModule()
{
}
BOOL CMobileModule::OpenComm(char * cpport, int baudrate)
{
// 异步打开串口
if (m_comm.open(cpport, baudrate, 0)!=1){
return FALSE;
}
return TRUE;
}
void CMobileModule::CloseComm()
{
m_comm.Close();
}
void CMobileModule::Purge()
{
m_comm.Purge();
}
void CMobileModule::RepeatLastCommand()
{
CString code("A/");
code += "\r";
m_comm.SendStrCommand(code);
}
CString CMobileModule::CSCS(CString sFont)
{
CString code("AT+CSCS=");
code += sFont;
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::IPR(int baudrate)
{
CString code("AT+IPR=");
char tmp[10];
memset(tmp,0,10);
sprintf(tmp, "%d", baudrate);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::SaveSetted()
{
CString code("AT&W");
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
void CMobileModule::SetTimeOut(DWORD ReadIntervalTimeout,
DWORD ReadTotalTimeoutMultiplier,
DWORD ReadTotalTimeoutConstant)
{
m_comm.SetTimeOut(ReadIntervalTimeout,
ReadTotalTimeoutMultiplier,
ReadTotalTimeoutConstant);
}
BOOL CMobileModule::DialUp(CString phonecode)
{
CString code("ATD");
code += phonecode;
code += ";\r";
if (!m_comm.SendStrCommand(code))
{
return FALSE;
}
return TRUE;
}
void CMobileModule::HandUp(CString mode)
{
CString code("ATH");
code += mode;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::Answer()
{
CString code("ATA");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CEER()
{
CString code("ATDL");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::DIALLAST()
{
CString code("AT+CEER");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::AutoAnswer(CString value)
{
CString code("ATS0=");
code += value;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::Speaker(int ActiveSpkMic)
{
char tmp[2];
CString code("AT+SPEAKER=");
memset(tmp,0,2);
sprintf(tmp, "%d", ActiveSpkMic);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CLVL(int iLevel)
{
char tmp[4];
CString code("AT+CLVL=");
memset(tmp,0,4);
sprintf(tmp, "%d", iLevel);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::QCLVL()
{
CString code("AT+CLVL?");
code += "\r";
m_comm.SendStrCommand(code);
}
CString CMobileModule::ReceiveInfo()
{
CString ret;
ret = m_comm.ReceiveATInfo();
return ret;
}
CString CMobileModule::ReadSMS()
{
int iRet;
char buf[1024];
CString sRet;
memset(buf, 0, 1024);
iRet = m_comm.ReadString(buf, 1024);
sRet = buf;
return sRet;
}
void CMobileModule::CMEE(CString mode)
{
CString code("AT+CMEE=");
code += mode;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::WIND(CString lndlevel)
{
CString code("AT+WIND=");
code += lndlevel;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::ECHO(int e)
{
CString code("ATE");
char tmp[2];
memset(tmp,0,2);
sprintf(tmp, "%d", e);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CGSN()
{
CString code("AT+CGSN");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CNMI(int mode, int mt, int bm, int ds, int bfr)
{
CString tmp1("AT+CNMI="), code("");
char tmp2[50];
memset(tmp2, 0, 50);
sprintf(tmp2, "%s%d,%d,%d,%d,%d\r", tmp1, mode, mt, bm, ds, bfr);
code = tmp2;
m_comm.SendStrCommand(code);
}
void CMobileModule::CSMP(int fo, int vp, int pid, int dcs)
{
CString tmp1("AT+CSMP="), code("");
char tmp2[50];
memset(tmp2, 0, 50);
sprintf(tmp2, "%s%d,%d,%d,%d\r", tmp1, fo, vp, pid, dcs);
code = tmp2;
m_comm.SendStrCommand(code);
}
void CMobileModule::CMGF(CString mode)
{
CString code("AT+CMGF=");
code += mode;
code += "\r";
smsmode = mode;
m_comm.SendStrCommand(code);
}
void CMobileModule::CSCA(CString smcenter)
{
CString code("AT+CSCA=\"");
code += smcenter;
code += "\"\r";
smscenter = smcenter;
m_comm.SendStrCommand(code);
}
void CMobileModule::CMGS(CString ad, CString contact)
{
CString code("AT+CMGS=");
int r, f, smslen, ret, iFind;
char csca[20], adto[20], text[200], sms[1000], pdulen[10];
memset(csca,0,20);
memset(adto,0,20);
memset(text,0,200);
memset(sms,0,1000);
memset(pdulen,0,10);
iFind = smscenter.Find("+");
if (iFind != -1)
{
sprintf(csca, "%s", smscenter.Right(smscenter.GetLength()-1));
}
else
{
sprintf(csca, "%s", smscenter);
}
sprintf(adto, "%s", ad);
sprintf(text, "%s", contact);
r = 0;
f = 0;
smslen = 0;
if (smsmode == "") return;
if (smsmode == "1")
{
code += ad;
code += "\r";
code += contact;
code += 0x1A;
}
if (smsmode == "0")
{
ret = TextToSms(csca, adto, text, f, r, &smslen, sms);
smslen = strlen(sms);
sprintf(pdulen, "%d", smslen);
sprintf(pdulen, "%d", 54);
code += pdulen;
//code += "18";
code += "\r";
code += sms;
//code += "0011000A813119213321F70008A9044F60597D";
code += 0x1A;
}
m_comm.SendStrCommand(code);
}
void CMobileModule::CMGR(int index)
{
CString code("AT+CMGR=");
char tmp[2];
memset(tmp,0,2);
sprintf(tmp, "%d", index);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CPMS(CString rmem, CString wmem)
{
CString code("AT+CPMS=\"");
code += rmem;
code += "\",\"";
code += wmem;
code += "\"\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CMGL(int stat)
{
CString code("AT+CMGL=");
char tmp[2];
memset(tmp,0,2);
sprintf(tmp, "%d", stat);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CMGLFORBENQ(char * cflag)
{
CString code("AT+CMGL=");
code += cflag;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CMGD(int iNum)
{
char buf[5];
memset(buf, 0, 5);
sprintf(buf, "%d", iNum);
CString code("AT+CMGD=");
code += buf;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CNMA(int n, CString PDU)
{
CString code("AT+CNMA=");
char tmp[2];
memset(tmp,0,2);
sprintf(tmp, "%d", n);
code += tmp;
code += PDU;
//code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::STSF(int mode, CString config, int timeout, int autoresponse)
{
CString code("AT+STSF=");
char tmp[50];
memset(tmp,0,50);
sprintf(tmp, "%d,%s,%d,%d", mode, config, timeout, autoresponse);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::STSFEX(int mode)
{
CString code("AT+STSF=");
char tmp[2];
memset(tmp,0,2);
sprintf(tmp, "%d", mode);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::STSFQ()
{
CString code("AT+STSF?");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::STIN()
{
CString code("AT+STIN?");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::STGIQ()
{
CString code("AT+STGI=?");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::STGI(int cmdtype)
{
CString code("AT+STGI=");
char tmp[2];
memset(tmp,0,2);
sprintf(tmp, "%d", cmdtype);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::STGR(int cmdtype, CString result, CString data)
{
CString code("AT+STGR=");
char tmp[3];
memset(tmp,0,3);
sprintf(tmp, "%d", cmdtype);
if (cmdtype ==3) // get input
{
code += tmp;
code += ",";
code += result;
code += "\r";
code += data;
code += 0x1A;
}
else
{
code += tmp;
code += ",";
code += result;
code += ",";
code += data;
code += "\r";
}
}
void CMobileModule::CPBSQ()
{
CString code("AT+CPBS=?");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CPBS(CString storage)
{
CString code("AT+CPBS=");
code += storage;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CPBRQ()
{
CString code("AT+CPBR=?");
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CPBR(int index)
{
CString code("AT+CPBR=");
char tmp[5];
memset(tmp,0,5);
sprintf(tmp, "%d", index);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CPBF(CString str)
{
CString code("AT+CPBF=\"");
code += str;
code += "\"\r";
m_comm.SendStrCommand(code);
}
void CMobileModule::CPBW(CString index, CString num, CString type, CString text)
{
CString code("AT+CPBW=");
code += index;
code += ",\"";
code += num;
code += "\",";
code += type;
code += ",\"";
code += text;
code += "\"\r";
m_comm.SendStrCommand(code);
}
CString CMobileModule::CGCLASS(CString mode)
{
CString code("AT+CGCLASS=\"");
code += mode;
code += "\"\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::CGDCONT(int cid, CString pdp_type, CString APN)
{
CString code("AT+CGDCONT=");
char tmp[50];
memset(tmp,0,50);
sprintf(tmp, "%d,\"%s\",\"%s\"", cid, pdp_type, APN);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::CSQ()
{
CString code("AT+CSQ");
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::CGACT(int cid, int state)
{
CString code("AT+CGACT=");
char tmp[5];
memset(tmp,0,5);
sprintf(tmp, "%d,%d", cid, state);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::CGATT(int state)
{
CString code("AT+CGATT=");
char tmp[5];
memset(tmp,0,5);
sprintf(tmp, "%d", state);
code += tmp;
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::CGACTQ()
{
CString code("AT+CGATT=?");
code += "\r";
m_comm.SendStrCommand(code);
return code;
}
CString CMobileModule::SETCGREG(int n)
{
CString code("AT+CGREG=");
char tmp[5];
memset(tmp,0,5);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -