📄 mainfrm.cpp
字号:
sTemp.Format(_T("%4d\t"),ha.Date_yy);
sLine+=sTemp;
sTemp.Format(_T("%2d:"),ha.Time_h);
sLine+=sTemp;
sTemp.Format(_T("%2d:"),ha.Time_m);
sLine+=sTemp;
sTemp.Format(_T("%7.4f\t\t"),ha.Time_s+ha.Time_ffff/1000000000.);
sLine+=sTemp;
sTemp.Format(_T("%-14.6f\t"),coor_x);
sLine+=sTemp;
sTemp.Format(_T("%-13.6f\t\t"),coor_y);
sLine+=sTemp;
sTemp.Format(_T("%-10.6f\t"),H);
sLine+=sTemp;
sTemp.Format(_T("%-2d"),ha.Satellite_Data_t);
sLine+=sTemp;
sLine+="\r\n";
if(pLogFile!=NULL)
{
pLogFile->Write(sLine,sLine.GetLength());
}
result.flag=true;
result.Time.Format(_T("%4d年%d月%d日\r\n\t%d:%d:%.4lf"),ha.Date_yy,ha.Date_m,ha.Date_d,ha.Time_h,ha.Time_m,ha.Time_s+ha.Time_ffff/1000000000.);
result.X=coor_x;
result.Y=coor_y;
result.H=H;
result.Speed2D=ha.Speed_vv/100.;
result.Speed3D=ha.Speed_VV/100.;
result.dmsLat=Rad2Dms(radLat);
result.dmsLon=Rad2Dms(radLon);
result.Lon0=6*index-3;
result.LonIndex=index;
result.Temperature=ha.Cscillator_ClockPara_TT/2.;
result.ClockBias=ha.Cscillator_ClockPara_cc;
memcpy(result.ID,ha.GMTOffset_v,6);
result.Satellite_Data_n=ha.Satellite_Data_n;
result.Satellite_Data_t=ha.Satellite_Data_t;
return result;
}
double CMainFrame::NavelMer(double lon,int base,int &index)
{
double na=0;
int n=0;
if(lon<0)
lon+=360.;
switch(base)
{
case 3:
n=int ((lon+1.5)/3.+0.5);
index=n;
na=index*3;
break;
case 6:
n=int ((lon)/6.+1);
index=n;
na=index*6-3;
break;
default :
na=index=-1;
}
na/=P2;
return na;
}
CPoint CoordTranstport(double x,double y)
{
CPoint pa;
double X0=3390000.0,
Y0=20244000.0;
pa.x=(y-Y0)/10.;
pa.y=(X0-x)/10.;
return pa;
}
void AddText(HWND hwnd, char * pszFormat)
{
va_list argList;
va_start(argList, pszFormat);
TCHAR sz[500* 1024];
GetWindowText(hwnd, sz, sizeof(sz));
_vstprintf(_tcschr(sz, 0), pszFormat, argList);
char *pdest;
int result[LINE];
int i;
pdest=strstr(sz,"\r\n");
result[0]=(int)(pdest-sz+1);
for(i=1;pdest!=NULL&&i<LINE;i++)
{
pdest=strstr(sz+result[i-1],"\r\n");
result[i]=(int)(pdest-sz+1);
}
if(i>=LINE)
{
memmove(sz,sz+result[0],strlen(sz)-result[0]+1);
}
SetWindowText(hwnd, sz);
va_end(argList);
}
void Marker(LONG x, LONG y, HDC hdc)
{
HPEN hPen, hPenOld;
LOGBRUSH lb;
UINT uHatch[] = {
HS_BDIAGONAL,
HS_CROSS,
HS_DIAGCROSS,
HS_FDIAGONAL,
HS_HORIZONTAL,
HS_VERTICAL
};
DWORD dwPenStyle[] = {
PS_DASH,
PS_DASHDOT,
PS_DOT,
PS_INSIDEFRAME,
PS_NULL,
PS_SOLID
};
lb.lbStyle = BS_SOLID;//BS_HATCHED;
lb.lbColor = RGB(255,125,0);
lb.lbHatch = 0;//uHatch[5];
hPen = ExtCreatePen(PS_GEOMETRIC,3,&lb, 0, NULL);
hPenOld =(HPEN) SelectObject(hdc, hPen);
MoveToEx(hdc, (int) x - 6, (int) y, (LPPOINT) NULL);
LineTo(hdc, (int) x + 6, (int) y);
MoveToEx(hdc, (int) x, (int) y - 6, (LPPOINT) NULL);
LineTo(hdc, (int) x, (int) y + 6);
SelectObject(hdc, hPenOld);
}
void CMainFrame::OnMenustart()
{
// TODO: Add your command handler code here
if(bOpen)
{
m_pPort->StartMonitoring();
bStart=true;
return;
}
if(!OnMENUsetup())
{
return;
}
CString pLogFileName="";
CInfoDlg dlg;
dlg.m_Info="请输入解算文件的文件名:";
dlg.m_FileName="GPS.log";
if(dlg.DoModal()==IDOK)
{
pLogFileName=dlg.m_FileName;
TRY
{
pLogFile = new CFile(pLogFileName,CFile::modeCreate|CFile::modeReadWrite|CFile::shareDenyRead);
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e->m_cause << "\n";
#endif
AfxMessageBox("Log文件打开出错!");
return ;
}
END_CATCH
}
else
{
}
if (m_pPort->InitPort(this,nPort,9600))
{
m_pPort->StartMonitoring();
bStart=true;
bOpen=true;
return;
}
else
{
AfxMessageBox("端口打开错误!");// port not found
bStart=false;
bOpen=false;
return;
}
}
CString CMainFrame::ToStr(const unsigned char *szBuf,int nRet)
{
CString str="";
CString sTemp="";
int i;
unsigned long ul=0;
char ch[80]="";
char p[80]="";
for(i=0;i<nRet;i++)
{
if(szBuf[i]!='@')
continue;
else if(szBuf[i+1]!='@')
continue;
str+="@@";
i+=2;
sTemp.Format(_T("%c"),szBuf[i++]);
str+=sTemp;
sTemp.Format(_T("%c"),szBuf[i++]);
str+=sTemp;
while(i<nRet-2&&!(szBuf[i]=='\r'&&szBuf[i+1]=='\n'))
{
sTemp.Format(_T("%x"),szBuf[i++]);
if(sTemp.GetLength()==1)
{
sTemp="0"+sTemp;
}
str+=sTemp;
}
//if(i<nRet-2)
{
str+="\r\n";
i+=2;
}
}
return str;
}
void CMainFrame::OnMenumot()
{
// TODO: Add your command handler code here
if(!bStart)
{
CString str="请先开始测量!";
pMyFormView->GetDlgItem(IDC_EDITzuobiao)->SetWindowText(str);
return;
}
if(pMotFile!=NULL)
{
bWrite=!bWrite;
return;
}
/*
if(bWrite)
{
CString str="已经开始记录!";
pMyFormView->GetDlgItem(IDC_EDITzuobiao)->SetWindowText(str);
return;
}
*/
CString pModFileName="";
CInfoDlg dlg;
dlg.m_Info="请输入二进制文件的文件名:";
dlg.m_FileName="GPS.mot";
if(dlg.DoModal()==IDOK&&dlg.m_FileName.GetLength()>0)
{
pModFileName=dlg.m_FileName;
TRY
{
pMotFile = new CFile(pModFileName,CFile::modeCreate|CFile::modeReadWrite|CFile::shareDenyRead);
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e->m_cause << "\n";
#endif
AfxMessageBox("Mot文件打开出错!");
return ;
}
END_CATCH
bWrite=true;
}
else
{
return;
}
}
int CMainFrame::OnMENUsetup()
{
// TODO: Add your command handler code here
if(bOpen)
{
CString str="端口已经打开了!";
pMyFormView->GetDlgItem(IDC_EDITzuobiao)->SetWindowText(str);
return 0;
}
CSetupDlg dlg;
dlg.m_ncom=0;
if(dlg.DoModal()==IDOK)
{
nPort=dlg.m_ncom==1?2:1;
return 1;
}
return 0;
}
void CMainFrame::OnMENUstop()
{
// TODO: Add your command handler code here
if(!bOpen)
{
CString str="端口还没有打开!";
pMyFormView->GetDlgItem(IDC_EDITzuobiao)->SetWindowText(str);
return;
}
if(bStart)
{
m_pPort->StopMonitoring();
bStart=false;
}
CString str="暂停!";
pMyFormView->GetDlgItem(IDC_EDITzuobiao)->SetWindowText(str);
return;
}
LONG CMainFrame::OnCommunication(WPARAM ch, LPARAM port)//UINT, LONG
{
if (port <= 0 || port > 4)
return -1;
CString string="";
char szBuf[N]="";
char p[N]="";
int i;
if (ch == '\n' &&m_strReceived[index-1]== '\r')
{
m_strReceived[index++]= (unsigned char)ch;
string=ToStr(m_strReceived,index);
strcpy(p,string);
wsprintf (szBuf, "%s",p);
AddText(pMyView->pMyEditView->m_hWnd,szBuf);
pMyView->pMyEditView->SendMessage(WM_VSCROLL,SB_BOTTOM,0);//将滚动条滚动到最下
for(i=0;i<index;i++)
{
if(m_strReceived[i]!='@')
continue;
else if(m_strReceived[i+1]!='@')
continue;
else if(m_strReceived[i+2]!='H')
continue;
else if(m_strReceived[i+3]!='a')
continue;
else if(!CheckOut(m_strReceived,i))
{
/*
*/
}
else
{
double a[2];
double alfa[2];
a[0]=A0,a[1]=A1;
alfa[0]=ALFA0,alfa[1]=ALFA1;
Ha ha;
POSITION po=AfxGetApp()->GetFirstDocTemplatePosition();
CDocTemplate *pDocTem=AfxGetApp()->GetNextDocTemplate(po);
po=pDocTem->GetFirstDocPosition();
CMyGpsNavDoc *pDoc=(CMyGpsNavDoc *)pDocTem->GetNextDoc(po);
ReadHa(m_strReceived,i,ha);
RESULT re=ProcessHa(ha,a,alfa,pLogFile);
CPoint point=CoordTranstport(re.X,re.Y);
pDoc->pt=point;
//将第一个点加入新线条的m_pointArray
pDoc->m_pStrokeCur->m_pointArray.Add(point);
pMyView->pMyScrollView->Invalidate();
CString str=Result2Str(re);
pMyFormView->GetDlgItem(IDC_EDITzuobiao)->SetWindowText(str);
i+=M;
}
}
if(bWrite)
{
//write mod file
pMotFile->Write(m_strReceived,index);
}
index=0;
memset(m_strReceived,0,N);
}
else if (index<N)
{
m_strReceived[index++]= (unsigned char)ch;
}
else
{
index=0;
return 0;
}
return 0;
}
LONG CMainFrame::OnCTSDetected(WPARAM, LPARAM port)
{
if (port <= 0 || port > 4)
return -1;
//CString string;
//string = "Clear To Send";
//m_ListBox[port-1].AddString(string);
//m_ListBox[port-1].SetSel(m_ListBox[port-1].GetCount()-1, TRUE);
return 0;
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(MessageBox("确定要退出吗?","退出",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
{
OnAppExit();
}
}
void CMainFrame::OnAppExit()
{
// TODO: Add your command handler code here
BeginWaitCursor( );
m_pPort->SetNoneAlive();
Sleep(500);
EndWaitCursor();
CFrameWnd::OnClose();
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
CRect rectWindow;
GetWindowRect(&rectWindow);
CRect rectClient;
GetClientRect(&rectClient);
// get offset of toolbars, scrollbars, etc.
int nWidthOffset = rectWindow.Width() - rectClient.Width();
int nHeightOffset = rectWindow.Height() - rectClient.Height();
lpMMI->ptMinTrackSize.x = MINX + nWidthOffset;
lpMMI->ptMinTrackSize.y = MINY + nHeightOffset;
lpMMI->ptMaxTrackSize.x = MAXX + nWidthOffset;
lpMMI->ptMaxTrackSize.y = MAXY + nHeightOffset;
//CFrameWnd::OnGetMinMaxInfo(lpMMI);
}
double Rad2Dms(double rad)//角度的化算
{
double dms=rad/PI*180.0;
int du,fen;
double miao;
du=int (dms+0.0001);
fen=int ((dms-du)*60+0.0001);
miao=(dms-(du+fen/60.0))*3600;
return du+fen/100.0+miao/10000;
}
CString Result2Str(RESULT re)
{
CString
str="",
sTemp="";
sTemp.Format(_T("GPS时间:\r\n\t"));
str=sTemp+re.Time+"\r\n";
sTemp.Format(_T("位置:\r\n\tX=%-16.6f\r\n\tY=%-16.6f\r\n\tH=%-16.6f\r\n"),re.X,re.Y,re.H);
str+=sTemp;
sTemp.Format(_T("\r\n\t纬度=%-.8f\r\n\t纬度=%-.8f\r\n\t中央经度=%-d\r\n\t6度带=%-d\r\n"),re.dmsLat,re.dmsLon,re.Lon0,re.LonIndex);
str+=sTemp;
sTemp.Format(_T("速度:\r\n\t3D=%-.6fm/s\r\n\t2D=%-.6fm/s\r\n"),re.Speed3D,re.Speed2D);
str+=sTemp;
sTemp.Format(_T("温度:\r\n\t%-.3fC\r\n"),re.Temperature);
str+=sTemp;
sTemp.Format(_T("钟差:\r\n\t%-dns\r\n"),re.ClockBias);
str+=sTemp;
sTemp.Format(_T("ID:\r\n\t%s\r\n"),re.ID);
str+=sTemp;
sTemp.Format(_T("卫星数:\r\n\t可见:%d\r\n\t可观测:%d\r\n"),re.Satellite_Data_n,re.Satellite_Data_t);
str+=sTemp;
return str;
}
void AddCheckChar(const CString str,char *szBuf)
{
char *stopstring;
int i;
unsigned long
ul1=0,
ul2=0;
CString sTemp="";
for(i=0;i<str.GetLength();i++)
{
sTemp.Format(_T("%x"),str.GetAt(i));
ul2 = strtoul(sTemp, &stopstring, 16);
szBuf[i]=ul2;
if(i<2)
continue;
ul1^=ul2;
}
szBuf[i]=ul1;
szBuf[i+1]='\r';
szBuf[i+2]='\n';
return ;
}
CString Format(const CString str)
{
CString res=str;
CString sTemp="";
int i=0;
int j=0;
char ch;
char *stopstring;
while(i<str.GetLength())
{
ch=str.GetAt(i);
if(ch==' ')
{
i++;
continue;
}
while(i<str.GetLength()&&isdigit(ch=str.GetAt(i)))
{
sTemp+=ch;
i++;
}
if(sTemp.GetLength()>0)
{
LPTSTR lpsz = new TCHAR[sTemp.GetLength()+1];
_tcscpy(lpsz, sTemp);
unsigned long ul=strtoul(lpsz, &stopstring, 10);
res.SetAt(j,ul);
j++;
continue;
}
res.SetAt(j,str.GetAt(i));
j++;
i++;
}
CString ss="";
for(int m=0;m<j;m++)
{
ss+=' ';
ss.SetAt(m,res.GetAt(m));
}
return ss;
}
void CMainFrame::OnUpdateMenumot(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(bStart);
pCmdUI->SetCheck(bWrite);
}
void CMainFrame::OnUpdateMENUstop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(bStart);
}
void CMainFrame::OnUpdateMenustart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!bStart);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -