⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpsguider1v0doc.cpp

📁 gps信号测试程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
						//::GPSInfo.CanBeRead=1;	//GPSInfo数据读使能
						//Sleep(1000);
						i++;
						j=0;
						break;
					default:
						RecieveBuffer[j++]=temp;
						if(j>nMax-1)
							j=nMax-1;
					}
				}
				break;
			default :
				;
			}
		default :
			;
		}
	}
	//AfxMessageBox(_T("err"));
	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0Doc

IMPLEMENT_DYNCREATE(CGPSGuider1V0Doc, CDocument)

BEGIN_MESSAGE_MAP(CGPSGuider1V0Doc, CDocument)
	//{{AFX_MSG_MAP(CGPSGuider1V0Doc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0Doc construction/destruction

CGPSGuider1V0Doc::CGPSGuider1V0Doc()
{
	// TODO: add one-time construction code here
	WORD i;
	::ShowMap=0;
/////////////////////////////////////////////////////////////////////////////////////////
// Initialize GPSInfo which is used to record the the information including:
// position,time,port,rate and so on.
//	InitializeCriticalSection(&cs);
	::Fixed=FALSE;
	::Time.hour=_T("00");
	::Time.minute=_T("00");
	::Time.second=_T("00");
	::Date.date=_T("00");
	::Date.month=_T("00");
	::Date.year=_T("00");
	::Longitude.direction=_T("0");	//经度
	::Longitude.degree=0;
	::Longitude.minute=0;
	::Longitude.secondinteger=0;
	::Longitude.secondportion=0;
	::Longitude.totalsecond=0;
	::Latitude.direction=_T("0");	//纬度
	::Latitude.degree=0;
	::Latitude.minute=0;
	::Latitude.secondinteger=0;
	::Latitude.secondportion=0;
	::Latitude.totalsecond=0;
	::Satellite.satellitenum=12;
	for(i=0;i<12;i++)
	{
		::Satellite.satelliteinfoarray[i].id=i;
		::Satellite.satelliteinfoarray[i].elevation=i+1;
		::Satellite.satelliteinfoarray[i].azimuth=i*10;
		::Satellite.satelliteinfoarray[i].snr=0;
	}
/////////////////////////////////////////////////////////////////////////////////////////
// Open the file named config.gps to initialize m_CommPara which is used to record 
// the the information including:
// port,rate and so on.
	m_ConfigFile.Open(_T("config.gps"),CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
	CArchive ar(&m_ConfigFile,CArchive::load);
	if(m_ConfigFile.GetLength())
	{
		ar>>m_CommPara.NeedConfigAtOpen>>m_CommPara.PortIndex>>m_CommPara.BaudRateIndex>>m_strMapFilePath;
	}
	else
	{
		m_CommPara.NeedConfigAtOpen=1;	//TRUE
		m_CommPara.PortIndex=0;
		m_CommPara.BaudRateIndex=4;
		m_strMapFilePath.Empty();
	}
	ar.Close();
	m_ConfigFile.Close();
/////////////////////////////////////////////////////////////////////////////////////////
// Open the map file
	m_PelsNew=TRUE;
	if(m_strMapFilePath.GetLength())
	{
		m_MapFile.Open(m_strMapFilePath,CFile::modeRead);
		CArchive ar(&m_MapFile,CArchive::load);
		Serialize(ar);	//Serialize()代码中的变量应定义为DWORD类型,否则打开大文件时会出错
		ar.Close();
		m_MapFile.Close();
		m_PelsNew=FALSE;
	}
	else
	{
		m_BitMapInfo.bmiHeader.biWidth=100;
		m_BitMapInfo.bmiHeader.biHeight=100;
	}
/////////////////////////////////////////////////////////////////////////////////////////
// Open the configuration dialog box to allow the user to set m_CommPara which 
// is used to record the the information including:
// port,rate and so on.
	for(i=0;i<8;i++)
	{
		m_PortArray[i].Format(_T("COM%d"),i+1);
	}
	for(i=0;i<8;i++)
	{
		m_BaudRateArray[i]=300*exp2(i);
	}
	if(m_CommPara.NeedConfigAtOpen)
	{
		CString ComboRateShow;
		ComboRateShow.Format(_T("%5d"),m_BaudRateArray[m_CommPara.BaudRateIndex]);
		CSettingDialog SettingDialog(m_CommPara.NeedConfigAtOpen,m_PortArray[m_CommPara.PortIndex],
			m_CommPara.PortIndex,ComboRateShow,m_CommPara.BaudRateIndex);
		int nRet=SettingDialog.DoModal();
		if(nRet==IDOK)
		{
			m_CommPara.NeedConfigAtOpen=SettingDialog.m_ConfigOnOpen;
			m_CommPara.PortIndex=SettingDialog.m_PortIndex;
			m_CommPara.BaudRateIndex=SettingDialog.m_RateIndex;
		}
	}
/////////////////////////////////////////////////////////////////////////////////////////
// Open the serial port
	DCB dcb;
	COMMTIMEOUTS cto;
	CString port;
	port.Format(_T("%s:"),m_PortArray[m_CommPara.PortIndex]);
	m_SerialFile.Open(port,CFile::modeRead);
	HANDLE hSerialFile=(HANDLE)m_SerialFile.m_hFile;

	GetCommState(hSerialFile,&dcb);
	dcb.DCBlength = sizeof(DCB);
	dcb.BaudRate = m_BaudRateArray[m_CommPara.BaudRateIndex];
	dcb.fBinary = TRUE;
	dcb.fParity = FALSE;
	dcb.fOutxCtsFlow = FALSE;
	dcb.fOutxDsrFlow = FALSE;
	dcb.fDtrControl = DTR_CONTROL_DISABLE;
	dcb.fDsrSensitivity = FALSE;
	dcb.fTXContinueOnXoff = FALSE;
	dcb.fOutX = FALSE;
	dcb.fInX = FALSE;
	dcb.fErrorChar = FALSE;
	dcb.fNull = FALSE;
	dcb.fRtsControl = RTS_CONTROL_DISABLE;
	dcb.fAbortOnError = FALSE;
	dcb.wReserved = 0;
	dcb.ByteSize = 8;
	dcb.Parity = NOPARITY;
	dcb.StopBits = ONESTOPBIT;
		
	if (!SetCommState( hSerialFile, &dcb )) 
	{
		::MessageBox(NULL,_T("SetCommState failed!"),_T("Message"),NULL);
		exit( 1 );
	}

	GetCommTimeouts( hSerialFile, &cto );
	cto.ReadIntervalTimeout = 3000;
	cto.ReadTotalTimeoutMultiplier = 100;
	cto.ReadTotalTimeoutConstant = 1000;
	cto.WriteTotalTimeoutMultiplier = 100;
	cto.WriteTotalTimeoutConstant = 1000;
	if (!SetCommTimeouts( hSerialFile, &cto )) 
	{
		::MessageBox(NULL,_T("SetCommTimeouts Failed!"),_T("Message"),NULL);
		exit( 1 );
	}

/////////////////////////////////////////////////////////////////////////////////////////
// Start the recieve thread
	::pSerialFile=&m_SerialFile;
	m_pCommThread=AfxBeginThread(CommThreadFunc,NULL);
}

CGPSGuider1V0Doc::~CGPSGuider1V0Doc()
{
	m_ConfigFile.Open(_T("config.gps"),CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&m_ConfigFile,CArchive::store);
	ar<<m_CommPara.NeedConfigAtOpen<<m_CommPara.PortIndex<<m_CommPara.BaudRateIndex<<m_strMapFilePath;
	ar.Flush();
	ar.Close();
	m_ConfigFile.Close();
}

/////////////////////////////////////////////////////////////////////////////////////////
// CCOMM4V0Doc exp2
DWORD CGPSGuider1V0Doc::exp2(DWORD i)
{
	DWORD result=1;
	for(DWORD j=0;j<i;j++)
	{
		result=2*result;
	}
	return result;
}

BOOL CGPSGuider1V0Doc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0Doc serialization

void CGPSGuider1V0Doc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
		DWORD temp,i;
		//ar>>m_BitMapFileHeader.bfType>>m_BitMapFileHeader.bfSize>>m_BitMapFileHeader.bfReserved1>>m_BitMapFileHeader.bfReserved2>>m_BitMapFileHeader.bfOffBits;
		ar.Read(&m_BitMapFileHeader,sizeof(BITMAPFILEHEADER));	//直接读一个数据块,效率高且不存在地址对齐问题(上句会提示desaligned,原因是第二个读的是DWORD,其地址应为4的倍数,而此处由于第一个数据为WORD,使得第二个数据的地址为2的倍数)
		ar.Read(&m_BitMapInfo,sizeof(BITMAPINFO)-4);
		//ar>>m_BitMapInfo.bmiColors[0].rgbBlue>>m_BitMapInfo.bmiColors[0].rgbRed
		//	>>m_BitMapInfo.bmiColors[0].rgbGreen>>m_BitMapInfo.bmiColors[0].rgbReserved;
		switch(m_BitMapInfo.bmiHeader.biBitCount)
		{
			case 0:
				::MessageBox(NULL,_T("Not supported(0)!"),_T("message"),NULL);
				break;
			case 1:
				::MessageBox(NULL,_T("Not supported(1)!"),_T("message"),NULL);
				break;
			case 4:
				::MessageBox(NULL,_T("Not supported(4)!"),_T("message"),NULL);
				break;
			case 8:
				::MessageBox(NULL,_T("Not supported(8)!"),_T("message"),NULL);
				break;
			case 16:
				::MessageBox(NULL,_T("Not supported(16)!"),_T("message"),NULL);
				break;
			case 24:
				m_RowNum=3*m_BitMapInfo.bmiHeader.biWidth;
				temp=m_RowNum%4;
				if(temp)
					m_RowNum=m_RowNum-temp+4;
				m_TotalNum=m_RowNum*m_BitMapInfo.bmiHeader.biHeight;
				m_pPels=new BYTE[m_TotalNum];
				for(i=0;i<m_TotalNum;i++)
				{
					ar>>m_pPels[i];
				}
				m_PelsNew=FALSE;
				break;
			case 32:
				::MessageBox(NULL,_T("Not supported(32)!"),_T("message"),NULL);
				break;
			default:
				::MessageBox(NULL,_T("Not a BMP file!"),_T("message"),NULL);
		}
		m_strMapFilePath=ar.m_strFileName;
		UpdateAllViews(NULL);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0Doc diagnostics

#ifdef _DEBUG
void CGPSGuider1V0Doc::AssertValid() const
{
	CDocument::AssertValid();
}

void CGPSGuider1V0Doc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0Doc commands

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -