📄 msgcom.cpp
字号:
// MsgCom.cpp: implementation of the CMsgCom class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MDF.h"
#include "MsgCom.h"
#include "Sms.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMsgCom::CMsgCom()
{
m_unPort = 2 ;
m_ulTime = 0 ;
}
CMsgCom::~CMsgCom()
{
}
void CMsgCom::DataProcess(UCHAR *buf, DWORD len)
{
static i = 0 ;
i++ ;
CString strRecv ;
CString temp ;
strRecv = buf ;
strRecv.TrimLeft() ;
strRecv.TrimRight() ;
//i = strRecv.Find("+CMGR:") ;
temp.Format( "%d" , i ) ;
//AfxMessageBox(temp) ;
//AfxMessageBox(strRecv) ;
/*
SM_PARAM param ;
if( i >= 0 )
{
i = strRecv.Find("\r\n",i) ;
gsmDecodePdu((char*)buf+i+2,¶m) ;
}
*/
}
BOOL CMsgCom::InitGSM()
{
/*
CString strError ;
CString strRecv ;
//SM_PARAM para;
if(OpenCom())
{
AT("\r\n") ; //清楚GSM残留命令
if(!AT("AT\r")) // 测试GSM-MODEM的存在性
{
AfxMessageBox("AT ERROR") ;
return FALSE ;
}
if(!AT("ATE0\r")) //ECHO OFF
{
AfxMessageBox("ATE0 ERROR") ;
return FALSE ;
}
if(!AT("AT+CMGF=0\r")) //PDU模式
{
AfxMessageBox("AT+CMGF=0 ERROR") ;
return FALSE ;
}
if(!AT("AT+CSCA=+8613800755500\r")) //短信中心设置
{
AfxMessageBox("AT+CSCA=+8613800755500 ERROR") ;
return FALSE ;
}
//m_pReadThread=::AfxBeginThread(SCThd, this); //启动读串口线程
//Write("ATD13622345659;\r") ;
Write("AT+CMGL=4\r") ;
Sleep(100) ;
Read(strRecv,4096) ;
strRecv.TrimLeft() ;
Write("AT+CMGR=5\r") ;
Sleep(100) ;
Read(strRecv,4096) ;
strRecv.TrimLeft() ;
if( strRecv.Find("OK") >= 0 )
{
char* buf ;
int iPos ;
iPos = strRecv.Find("\r\n") ;
buf = strRecv.GetBuffer(0) ;
buf += iPos + 2 ;
gsmDecodePdu(buf,¶) ;
}
return TRUE ;
}
else
return FALSE ;
*/
return TRUE ;
}
BOOL CMsgCom::AT(CString strCMD)
{
CString strError ;
Write(strCMD) ;
Read(strError,128) ;
if( strError.Find("OK") >= 0 )
return TRUE ;
else
return FALSE ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -