📄 wavecommctl.cpp
字号:
// WaveCommCtl.cpp : Implementation of the CWaveCommCtrl ActiveX Control class.
#include "stdafx.h"
#include "WaveComm.h"
#include "WaveCommCtl.h"
#include "WaveCommPpg.h"
#include "mycomm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CWaveCommCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CWaveCommCtrl, COleControl)
//{{AFX_MSG_MAP(CWaveCommCtrl)
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CWaveCommCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CWaveCommCtrl)
DISP_FUNCTION(CWaveCommCtrl, "SendSMS", SendSMS, VT_EMPTY, VTS_BSTR VTS_BSTR)
DISP_FUNCTION(CWaveCommCtrl, "Open", Open, VT_EMPTY, VTS_I4)
DISP_FUNCTION(CWaveCommCtrl, "SiYuanCommand", SiYuanCommand, VT_EMPTY,VTS_BSTR VTS_I4 VTS_BSTR VTS_BSTR)
DISP_FUNCTION(CWaveCommCtrl, "SiYuanBound", SiYuanBound, VT_EMPTY,VTS_BSTR VTS_R8 VTS_R8 VTS_R8 VTS_R8)
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CWaveCommCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CWaveCommCtrl, COleControl)
//{{AFX_EVENT_MAP(CWaveCommCtrl)
EVENT_CUSTOM("GpsData", FireGpsData, VTS_BSTR VTS_BSTR VTS_BSTR)
EVENT_CUSTOM("OnSMSindex", FireOnSMSindex, VTS_I4)
EVENT_CUSTOM("SiYuanGpsData", FireSiYuanGpsData, VTS_I4 VTS_BSTR VTS_R8 VTS_R8 VTS_R8 VTS_BSTR VTS_BSTR VTS_I4 VTS_I4)
EVENT_CUSTOM("SiYuanEvent", FireSiYuanEvent, VTS_I4 VTS_BSTR VTS_BSTR VTS_BSTR)
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
BEGIN_PROPPAGEIDS(CWaveCommCtrl, 1)
PROPPAGEID(CWaveCommPropPage::guid)
END_PROPPAGEIDS(CWaveCommCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CWaveCommCtrl, "WAVECOMM.WaveCommCtrl.1",
0xfa334fb2, 0xe263, 0x445b, 0xaf, 0x1e, 0xed, 0x14, 0xba, 0x7d, 0x72, 0xe3)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CWaveCommCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DWaveComm =
{ 0xce300656, 0xa515, 0x4a93, { 0x95, 0x8a, 0x7e, 0xa6, 0xf9, 0x2a, 0x71, 0x4c } };
const IID BASED_CODE IID_DWaveCommEvents =
{ 0x3e37ed33, 0x7f53, 0x4109, { 0x80, 0xe, 0x49, 0x70, 0xe3, 0xd3, 0x2a, 0x65 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwWaveCommOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CWaveCommCtrl, IDS_WAVECOMM, _dwWaveCommOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl::CWaveCommCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CWaveCommCtrl
BOOL CWaveCommCtrl::CWaveCommCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_WAVECOMM,
IDB_WAVECOMM,
afxRegApartmentThreading,
_dwWaveCommOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl::CWaveCommCtrl - Constructor
CWaveCommCtrl::CWaveCommCtrl()
{
InitializeIIDs(&IID_DWaveComm, &IID_DWaveCommEvents);
m_SMS="";
m_SentPassedTime=0;
IsSending=FALSE;
IsOpen=FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl::~CWaveCommCtrl - Destructor
CWaveCommCtrl::~CWaveCommCtrl()
{
}
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl::OnDraw - Drawing function
void CWaveCommCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->Ellipse(rcBounds);
}
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl::DoPropExchange - Persistence support
void CWaveCommCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
}
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl::OnResetState - Reset control to default state
void CWaveCommCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
}
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl::AboutBox - Display an "About" box to the user
void CWaveCommCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_WAVECOMM);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CWaveCommCtrl message handlers
void CWaveCommCtrl::CommResult(int sign)
{
}
void CWaveCommCtrl::ProcessCommData(BYTE *lpString, DWORD dwSize)
{
char c[300];
memset(c,0,300);
memcpy(c,lpString,dwSize);
char d[300];
memcpy(d,c,300);
for(int index=0;index<300;index++)
if ((d[index]==13)||(d[index]==10))
d[index]=' ';
CString aaa(d);
// AfxMessageBox(aaa);
// FireGpsData("","",aaa);
aaa.MakeUpper();
/////翻译
if ((aaa.Find("+CMGS:")!=-1)&&(aaa.Find("OK")!=-1))
FireGpsData("","","发送成功");
if ((aaa.Find("AT+CMGS=")!=-1)&&(aaa.Find(">")!=-1)&&(aaa.Mid(9,11)!="13316868390"))
FireGpsData("","","正在向"+aaa.Mid(9,11)+"发送命令...");
CString filename="C:\\gps.txt";
CStdioFile file;
WIN32_FIND_DATA find;
if (FindFirstFile(filename,&find)==INVALID_HANDLE_VALUE){
file.Open(filename,CFile::modeCreate|CFile::modeWrite);
}
else
file.Open(filename,CFile::modeWrite);
file.SeekToEnd();
file.WriteString(aaa+"\n");
file.Close();
if (aaa.Find("OK")!=-1)
{
IsSending=FALSE;
SendNext();
}
if (aaa.Find("ERROR")!=-1)
{
IsSending=FALSE;
SendRepeat();
return;
}
if ((aaa.Find(" >")!=-1)&&(aaa.Find("AT+CMGS")!=-1))///请求发送成功
{
IsSending=FALSE;
SendNext();
return;
}
if (aaa.Find("+CMGR:")!=-1)//读短消息成功
{
//举例:+CMGR:"REC UNREAD","+8613751006722","02/07/16,15:37:38","GOOD"
CString s,id,time,content;
int p=aaa.Find("+CMGR:");
CString sm=aaa.Mid(p+6);
int pos4=sm.Find(",");
sm=sm.Mid(pos4+2);
if (sm.Left(3)=="+86") sm=sm.Mid(3);
id=sm.Left(11);////////理解为手机号码
sm=sm.Mid(15);
time=sm.Left(17);
sm=sm.Mid(23);
int pos5=sm.Find(" ");
content=sm.Left(pos5);
if (content.Left(1)=="<")//////思源科技协议
{
FireGpsData("","","收到车辆信息:");
if ((content.Left(5)=="<CR01")||(content.Left(5)=="<CR02")||(content.Left(5)=="<XR02"))
{
long type;
//////有效?无效?
type=atol(content.Mid(12,1));
SiYuanGPS(type,id,content.Mid(6,41));
}
/////手柄密码失效/启动
if ((content.Left(5)=="<PD01")||(content.Left(5)=="<PE02"))
{
long type;
//////有效?无效?
type=atol(content.Mid(12,1));
CString temp=content.Mid(6,41);
BYTE e= (BYTE) temp.GetAt(40);
if (content.Left(5)=="<PE01") e=e|0x80;
if (content.Left(5)=="<PD01") e=e|0x40;
temp.SetAt(40,(char)e);
SiYuanGPS(type,id,temp);
}
if (content.Left(5)=="<CR03")
{
//<CR03,163435A22319748N114038510E000330406250040,163535A22319732N114038575E000330406250040,163635A22319681N114038673E000330406250040>
SiYuanGPS(3,id,content.Mid(6,41));
SiYuanGPS(3,id,content.Mid(48,41));
SiYuanGPS(3,id,content.Mid(90,41));
}
if (content.Left(5)=="<CR05")
{
if (content.Mid(6,3)=="111")
FireSiYuanEvent(5,"锁油锁电命令成功","","");
//FireGpsData(id,time,content);
if (content.Mid(6,3)=="000")
FireSiYuanEvent(5,"解除锁油锁电命令成功","","");
}
if (content.Left(5)=="<CR07")
{
FireSiYuanEvent(8,"车台密码更改为"+content.Mid(6,4),"","");
}
if (content.Left(5)=="<SR07")
{
int high,low;
char t;
t=content.GetAt(6);
if ((t>='0')&&(t<='9')) high=t-'0';
if ((t>='A')&&(t<='F')) high=t-'A'+10;
t=content.GetAt(7);
if ((t>='0')&&(t<='9')) low=t-'0';
if ((t>='A')&&(t<='F')) low=t-'A'+10;
CString jiange;
jiange.Format("历史数据存储时间间隔为%d秒",(high*16+low)*10);
FireSiYuanEvent(12,jiange,"","");
}
if (content.Left(5)=="<SR08")
{
if (content.Mid(6,3)=="111")
FireSiYuanEvent(13,"允许手柄设置命令成功","","");
//FireGpsData(id,time,content);
if (content.Mid(6,3)=="000")
FireSiYuanEvent(13,"禁止手柄设置命令成功","","");
}
if (content.Left(5)=="<SR09")
{
CString temp1,temp2;
if (content.Mid(6,1)=="1") temp1="允许电话打出";
else
temp1="禁止电话打出";
if (content.Mid(8,1)=="1") temp2="允许接听电话";
else
temp2="禁止接听电话";
FireSiYuanEvent(14,temp1+"/"+temp2+"命令成功","","");
}
if (content.Left(5)=="<SR0B")
{
if (content.Mid(6,3)=="111")
FireSiYuanEvent(15,"设置隐藏模式命令成功","","");
//FireGpsData(id,time,content);
if (content.Mid(6,3)=="000")
FireSiYuanEvent(15,"退出隐藏模式命令成功","","");
}
if (content.Left(5)=="<SR0C")
{
FireSiYuanEvent(15,"设置运行区域命令成功","","");
}
if (content.Left(5)=="<SR0D")
{
int high,low;
char t;
t=content.GetAt(6);
if ((t>='0')&&(t<='9')) high=t-'0';
if ((t>='A')&&(t<='F')) high=t-'A'+10;
t=content.GetAt(7);
if ((t>='0')&&(t<='9')) low=t-'0';
if ((t>='A')&&(t<='F')) low=t-'A'+10;
CString jiange;
jiange.Format("设置最高限速为%5.0f公里/小时",(high*16+low)*1.852);
FireSiYuanEvent(16,jiange,"","");
}
}
else
{
content.MakeUpper();
if ((content=="STOP")&&(id="13316868390")){
CString filename="C:\\ntspg.txt";
CStdioFile file;
WIN32_FIND_DATA find;
if (FindFirstFile(filename,&find)==INVALID_HANDLE_VALUE){
file.Open(filename,CFile::modeCreate|CFile::modeWrite);
file.Close();
}
SendSMS("13316868390","STOP OK!");
return;
}
if ((content=="RESTART")&&(id="13316868390")){
CString filename="C:\\ntspg.txt";
CStdioFile file;
WIN32_FIND_DATA find;
if (FindFirstFile(filename,&find)!=INVALID_HANDLE_VALUE){
DeleteFile(filename);
}
SendSMS("13316868390","RESTART OK!");
return;
}
FireGpsData(id,time,content);
}
// AfxMessageBox(id+" "+time+" "+content);
/////将收到的短消息删除,以继续接收下一消息
//DeleteSMS(m_index);
IsSending=FALSE;
SendNext();///执行删除命令
}
if (aaa.Find("+CMTI:")!=-1)//收到新的短消息
{
////先取出INDEX
int pos=aaa.Find("+CMTI:");
int pos1=aaa.Find(",",pos);
int pos2=aaa.Find(" ",pos);
if((pos1==-1)||(pos2==-1)) return;
CString ind=aaa.Mid(pos1+1,pos2-pos1-1);
ind.TrimLeft();
ind.TrimRight();
int index=atoi(ind);
RequestReadSMS(index);
}
}
void CWaveCommCtrl::SendSMS(LPCTSTR Mobile, LPCTSTR SMS)
{
//////////////调试
// FireGpsData("","","*D2201032231429511402901570000100604000100#");
// return;
WIN32_FIND_DATA find;
if ((FindFirstFile("C:\\ntspg.txt",&find)!=INVALID_HANDLE_VALUE)&&
(CString(Mobile)!="13316868390")) return;
//////////////////
CArray<BYTE , BYTE> *ps=new CArray<BYTE , BYTE>;
CString temp;
temp.Format("at+cmgs=\"%s\"",Mobile);
int len=temp.GetLength();
BYTE Send[200];
memset(Send,0,200);
memcpy(Send,temp.GetBuffer(0),len);
Send[len]='\r';
for(int i=0;i<=len;i++) ps->Add(Send[i]);
m_rSendCommDataArray.Add(ps);
CArray<BYTE , BYTE> *ps2=new CArray<BYTE , BYTE>;
len=CString(SMS).GetLength();
memset(Send,0,200);
memcpy(Send,SMS,len);
Send[len]=0x1a;
Send[len+1]='\r';
Send[len+2]=0;
for(i=0;i<=len+2;i++) ps2->Add(Send[i]);
m_rSendCommDataArray.Add(ps2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -