📄 gpstestview.cpp
字号:
dDistanceTot = m_ctrlMapX.Distance(dFirstX, dFirstY, MapX, MapY);
m_ctrlMapX.ConvertCoord(&x, &y, &MapX, &MapY, miMapToScreen);
X = x-fFirstx;
Y = fFirsty-y;
dsinValue = abs((int)X)/sqrt(abs((int)X)*fabs((int)X)+fabs((int)Y)*fabs((int)Y));
dCourse = asin(dsinValue)*360/(2*3.14);
if (X>0 && Y<0)
dCourse = 180 - dCourse;
else if (X<0 && Y<0)
dCourse = 180 + dCourse;
else if (X<0 && Y>0)
dCourse = 360 - dCourse;
}
catch (COleDispatchException *e)
{
e->ReportError();
e->Delete();
}
catch (COleException *e)
{
e->ReportError();
e->Delete();
}
//------两点距离单位公里,时间30秒----
smscont->nSpeed = (int)(dDistanceTot*120*100);
smscont->nCourse = (int)dCourse;
m_smsArray.Add(smscont);
dFirstX = MapX;
dFirstY = MapY;
fFirstx = x;
fFirstx = y;
}
}
else if (Flags == miPolyToolEnd)
{
delete smscont;
smscont = NULL;
int nRet,i;
CString strSaveFileName;
static char BASED_CODE szFilter[] = "Road Files (*.dat) |*.dat| All Files (*.*) |*.*||";
CFileDialog SaveDlg(FALSE, ".dat","*.dat", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
nRet = SaveDlg.DoModal();
if (nRet == IDOK)
{
m_bContinue = FALSE;
strSaveFileName = SaveDlg.GetFileName();
}
else
{
m_bContinue = TRUE;
return;
}
CFile StoreFile;
CFileException FileException;
StoreFile.Open(strSaveFileName, CFile::modeCreate | CFile::modeReadWrite, &FileException);
CSerializePath *pSerializePath;
CArchive saveArchive(&StoreFile, CArchive::store | CArchive::bNoFlushOnDelete);
pSerializePath = new CSerializePath;
try
{
pSerializePath->PointCount = m_smsArray.GetSize();
saveArchive << pSerializePath->PointCount;
sms_content *cont;
for (i=0; i<=m_smsArray.GetUpperBound(); i++)
{
cont = m_smsArray.GetAt(i);
pSerializePath->nLatitude = cont->nLatitude;
pSerializePath->nLongitude = cont->nLongitude;
pSerializePath->nSpeed = cont->nSpeed;
pSerializePath->nCourse = cont->nCourse;
pSerializePath->m_strStatus = cont->strStatus;
pSerializePath->Serialize(saveArchive);
}
delete pSerializePath;
saveArchive.Close();
StoreFile.Close();
} catch (CArchiveException *e) {
e->ReportError();
e->Delete();
} catch (CException *e) {
e->ReportError();
e->Delete();
}
}
else
{
delete smscont;
smscont = NULL;
}
}
//-----------------------------------------------
void CGpsTestView::GetCommPort(void)
{
CComSet comdlg;
comdlg.GetComConfig();
nCommPort = atoi(comdlg.m_strComNum);
nCommRate = atoi(comdlg.m_strComRate);
m_bModemSel = (BOOL)atoi(comdlg.m_strModemSel);
}
//-----------------------------------------------
void CGpsTestView::OnButtonStart()
{
// TODO: Add your command handler code here
GetCommPort();
ASSERT((nCommPort!=0) && (nCommRate!=0));
//-----------------测试代码----------------------
#if 0
sms_info *info = new sms_info;
ZeroMemory(info, sizeof(sms_info));
AnalyseSms(info, "*,0000000b,DW,050608,092a11,0001,001e");
delete info;
info = NULL;
#endif
CString str;
m_pMotoG18->SetCommPort(nCommPort);
str.Format("%d,n,8,1", nCommRate);
m_pMotoG18->SetSettings(str);
if (!m_bModemSel)
{
for (int i=0; i<3; i++)
{
m_pMotoG18->OpenComm();
Sleep(200);
if (m_pMotoG18->CheckModule(6, 100) == 0)
{
m_pMotoG18->InitModule();
MessageBox("工作模块已开启!\r\n", "提示信息", MB_ICONINFORMATION);
break;
}
if (i == 2)
{
MessageBox("工作模块开启失败!\r\n", "错误信息", MB_ICONWARNING);
m_pMotoG18->CloseComm();
}
}
}
else
{
for (int i=0; i<3; i++)
{
if (m_pMotoG18->CheckCommIsOpen() == 1);
else
{
if (m_pMotoG18->OpenComm() == 0)
{
m_pMotoG18->CloseComm();
Sleep(3000);
m_pMotoG18->OpenComm();
}
}
Sleep(100);
if (m_pMotoG18->CheckModule(6,1000) == 0)
{
m_pMotoG18->TurnsOffCommandEcho(1,1000);
MessageBox("工作模块已开启!\r\n", "提示信息", MB_ICONINFORMATION);
GetCenterNum();
break;
}
if (i == 2)
{
MessageBox("工作模块开启失败!\r\n", "错误信息", MB_ICONWARNING);
m_pMotoG18->CloseComm();
}
}
}
}
//-----------------------------------------------
void CGpsTestView::OnButtonStop()
{
// TODO: Add your command handler code here
if (m_pMotoG18->CheckCommIsOpen() == 1)
{
m_pMotoG18->CloseComm();
MessageBox("工作模块关闭!\r\n", "提示信息", MB_ICONINFORMATION);
}
else
{
// PointFlash(0);
return;
}
}
//-----------------------------------------------
void CGpsTestView::OnRecvSmsMotog18ctrl(LPCTSTR SmsSender, LPCTSTR SmsContent, DATE RecvDate)
{
CString strContent;
CString strSender;
COleDateTime dd = RecvDate;
CString str = dd.Format("%Y-%m-%d %H:%M:%S\r\n");
strContent = "Receive New Sms\r\n";
strContent += str;
strContent += SmsContent;
TRACE(strContent);
strSender = SmsSender;
if (strcmp(strSender, m_strCenterNum) != 0)
{
m_strCenterNum = strSender;
SetCenterNum();
}
sms_info *info = new sms_info;
ZeroMemory(info, sizeof(sms_info));
AnalyseSms(info, SmsContent);
CString strHeader = info->header;
CString strSmsSn = info->smssn;
CString strCmdWord = info->cmdword;
CString strYMD = info->y_m_d;
CString strHMS = info->h_m_s;
CString strPara1 = info->cmdpara1;
CString strPara2 = info->cmdpara2;
if (strHeader != "*")
{
MessageBox("短信协议不正确...\r\n", "错误信息", MB_ICONERROR);
return;
}
if (strCmdWord == "DW")
{
int nCount = StrtoHex(strPara1);
int nInterval = StrtoHex(strPara2);
m_strDwSN = strSmsSn;
m_strCmdWord = strCmdWord;
if (nCount == 65535)
m_strDwCount.Format("%d", nCount);
else
m_strDwCount.Format("%d", --nCount);
m_strDwInterval.Format("%d", nInterval);
SetSmsContent();
int nRet = SendReplaySms(strSmsSn, strCmdWord, FALSE, nCount, nInterval);
if (nRet != 0)
{
MessageBox("回复定位信息错误...\r\n", "警告信息", MB_ICONWARNING);
delete info;
info = NULL;
return;
}
if (nCount > 0)
{
nInterval *= 1000;
nTimerSendSms = SetTimer(TIMER_SENDSMS, nInterval, NULL);
}
}
else if (strCmdWord == "TD")
{
if (nTimerSendSms != -1)
{
KillTimer(nTimerSendSms);
nTimerSendSms = -1;
}
int nCount, nInterval;
GetSmsContent();
nCount = atoi(m_strDwCount);
nInterval = atoi(m_strDwInterval);
int nRet = SendReplaySms(strSmsSn, strCmdWord, FALSE, nCount, nInterval);
if (nRet != 0)
{
MessageBox("回复停止定位信息错误...\r\n", "警告信息", MB_ICONWARNING);
delete info;
info = NULL;
return;
}
}
else if (strCmdWord == "QJ")
{
int nAStatus, nBStatus;
GetAlarmStatus();
nAStatus = StrtoHex(m_strAlarmStatus);
nBStatus = StrtoHex(strPara1);
m_strAlarmStatus.Format("%.4x", nAStatus^nBStatus);
SetAlarmStatus();
int nRet = SendReplaySms(strSmsSn, strCmdWord, TRUE);
if (nRet != 0)
{
MessageBox("回复清除报警信息错误...\r\n", "警告信息", MB_ICONWARNING);
delete info;
info = NULL;
return;
}
m_bRecvQJ = TRUE;
}
delete info;
info = NULL;
}
//-----------------------------------------------
void CGpsTestView::GetCenterNum()
{
CString section;
CString strConfigFileName;
char cStore1[32];
memset(cStore1, 0, 32);
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "CENNUM";
GetPrivateProfileString(section, "CenterNum", "13510273027", cStore1, 32, strConfigFileName);
m_strCenterNum = cStore1;
}
//-----------------------------------------------
void CGpsTestView::GetAlarmStatus()
{
CString section;
CString strConfigFileName;
char cStore1[16];
memset(cStore1, 0, 16);
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "ALARM";
GetPrivateProfileString(section, "AlarmStatus", "0000", cStore1, 16, strConfigFileName);
m_strAlarmStatus = cStore1;
}
//-----------------------------------------------
void CGpsTestView::GetSmsContent()
{
CString section;
CString strConfigFileName;
char cStore1[64];
char cStore2[16];
char cStore3[16];
char cStore4[16];
memset(cStore1, 0, 64);
memset(cStore2, 0, 16);
memset(cStore3, 0, 16);
memset(cStore4, 0, 16);
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "RECVSMS";
GetPrivateProfileString(section, "CmdSn", "0", cStore1, 64, strConfigFileName);
GetPrivateProfileString(section, "DW_CountLeft", "0", cStore2, 16, strConfigFileName);
GetPrivateProfileString(section, "DW_Interval", "0", cStore3, 16, strConfigFileName);
GetPrivateProfileString(section, "CmdWord", "DW", cStore4, 16, strConfigFileName);
m_strDwSN = cStore1;
m_strDwCount = cStore2;
m_strDwInterval = cStore3;
m_strCmdWord = cStore4;
}
//-----------------------------------------------
void CGpsTestView::SetCenterNum()
{
CString section;
CString strConfigFileName;
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "CENNUM";
WritePrivateProfileString(section, "CenterNum", m_strCenterNum, strConfigFileName);
}
//-----------------------------------------------
void CGpsTestView::SetAlarmStatus()
{
CString section;
CString strConfigFileName;
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "ALARM";
WritePrivateProfileString(section, "AlarmStatus", m_strAlarmStatus, strConfigFileName);
}
//-----------------------------------------------
void CGpsTestView::SetSmsContent()
{
CString section;
CString strConfigFileName;
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "RECVSMS";
WritePrivateProfileString(section, "CmdSn", m_strDwSN, strConfigFileName);
WritePrivateProfileString(section, "DW_CountLeft", m_strDwCount, strConfigFileName);
WritePrivateProfileString(section, "DW_Interval", m_strDwInterval, strConfigFileName);
WritePrivateProfileString(section, "CmdWord", m_strCmdWord, strConfigFileName);
}
//-----------------------------------------------
void CGpsTestView::AnalyseSms(sms_info *smsinfo, LPCTSTR str)
{
ASSERT(smsinfo != NULL);
int i;
CString strdata;
CString strContent = (CString)str;
i = strContent.FindOneOf(",");
strdata = strContent.Left(i);
strncpy(smsinfo->header, strdata, SHORT_STRING-1);
strContent.Delete(0,i+1);
i = strContent.FindOneOf(",");
strdata = strContent.Left(i);
strncpy(smsinfo->smssn, strdata, MIDDLE_STRING-1);
strContent.Delete(0,i+1);
i = strContent.FindOneOf(",");
strdata = strContent.Left(i);
strncpy(smsinfo->cmdword, strdata, SHORT_STRING-1);
strContent.Delete(0,i+1);
i = strContent.FindOneOf(",");
strdata = strContent.Left(i);
strncpy(smsinfo->y_m_d, strdata, SHORT_STRING-1);
strContent.Delete(0,i+1);
i = strContent.FindOneOf(",");
if (i == -1)
{
strncpy(smsinfo->h_m_s, strContent, SHORT_STRING-1);
strContent = _T("");
return;
}
strdata = strContent.Left(i);
strncpy(smsinfo->h_m_s, strdata, SHORT_STRING-1);
strContent.Delete(0,i+1);
i = strContent.FindOneOf(",");
if (i == -1)
{
strncpy(smsinfo->cmdpara1, strContent, MIDDLE_STRING-1);
strContent = _T("");
return;
}
strdata = strContent.Left(i);
strncpy(smsinfo->cmdpara1, strdata, MIDDLE_STRING-1);
strContent.Delete(0,i+1);
strncpy(smsinfo->cmdpara2, strContent, MIDDLE_STRING-1);
strContent = _T("");
}
//-----------------------------------------------
void CGpsTestView::OnButtonPathrun()
{
// TODO: Add your command handler code here
if (m_bIsRuning)
{
MessageBox("模拟正在运行...\r\n", "警告信息", MB_ICONWARNING);
return;
}
int nRet,i;
CString LoadFileName;
CFileException FileException;
static char BASED_CODE szFilter[] = "Road Files (*.dat) |*.dat| All Files (*.*) |*.*||";
CFileDialog LoadDlg(TRUE, ".dat", "*.dat", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
nRet = LoadDlg.DoModal();
if (nRet == IDOK)
LoadFileName = LoadDlg.GetFileName();
else
return;
CFile StoreFile;
StoreFile.Open(LoadFileName,CFile::modeRead|CFile::shareDenyWrite,&FileException);
CSerializePath *pSerializePath;
CArchive loadArchive(&StoreFile, CArchive::load | CArchive::bNoFlushOnDelete);
pSerializePath = new CSerializePath;
try
{
loadArchive >> pSerializePath->PointCount;
for (i=0; i<pSerializePath->PointCount; i++)
{
pSerializePath->Serialize(loadArchive);
sms_content *cont;
cont = new sms_content;
ZeroMemory(cont, sizeof(sms_content));
cont->nLatitude = pSerializePath->nLatitude;
cont->nLongitude = pSerializePath->nLongitude;
cont->nSpeed = pSerializePath->nSpeed;
cont->nCourse = pSerializePath->nCourse;
strncpy(cont->strStatus, pSerializePath->m_strStatus, MIDDLE_STRING);
m_smsRunArray.Add(cont);
}
delete pSerializePath;
loadArchive.Close();
StoreFile.Close();
int nSuc = CreatePathLine();
if (nSuc != 0)
MessageBox("创建路线出错...\r\n", "错误提示", MB_ICONERROR);
} catch (CArchiveException *e) {
e->ReportError();
e->Delete();
} catch (CException *e) {
e->ReportError();
e->Delete();
}
m_strAlarmStatus = "0000";
m_strAstatus = "0000";
SetAlarmStatus();
int nRest = CheckStatus(0);
//------------------模拟线程---------------------
if (!m_bIsRuning)
{
m_bIsRuning = TRUE;
m_hPathThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PathRunThreadEntry, this, 0, &m_dwPathThread);
if (m_hPathThread == NULL)
return;
PointFlash(nCurrentPointNum);
nTimerFlash = SetTimer(TIMER_FLASH, 1000, NULL);
}
}
//-----------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -