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

📄 gpsinterface_gpsd.cpp

📁 Powerful and Portable GPS application -- support Linux, Windows, Windows CE GPS navigation and Map m
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}		psockGPSD->Read(szBuf, 63);				if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Read error"));			return wxT("gpsd read error");		}				iRead = psockGPSD->LastCount();		LibRoadnavDebug1(wxT("gpsd"), wxT("Got %d bytes from server"), iRead);		if (iRead < 1)			return wxT("gpsd socket error");				wxASSERT(iRead <= 63);		if (iRead > 63)			iRead = 63;				szBuf[iRead] = 0;		LibRoadnavDebug1(wxT("gpsd"), wxT("szBuf = %hs"), szBuf);				// tokenize version string from gpsd server		wxString strInfo(szBuf, wxConvUTF8);		wxStringTokenizer tkz(strInfo, wxT(" ,=\r\n"));		wxString strPrefix = tkz.GetNextToken();		if (strPrefix.Left(5) != wxT("GPSD"))			return wxT("This does not appear to be a gpsd 2.x server (wrong prefix)");		wxString strResponseType = tkz.GetNextToken();		if (strResponseType.Lower() != wxT("p"))			return wxT("This does not appear to be a gpsd 2.x server (does not understand p command)");		if (!tkz.HasMoreTokens())			return wxT("This does not appear to be a gpsd 2.x server (no position report)");					wxString strLat = tkz.GetNextToken();				if (strLat == wxT("?"))		{			wxThread::Sleep(1000);						continue;		}					pptGPS->m_fLat = 0;		strLat.ToDouble(&pptGPS->m_fLat);		if (!tkz.HasMoreTokens())			return wxT("This does not appear to be a gpsd 2.x server (no longitude)");		wxString strLong = tkz.GetNextToken();				if (strLong == wxT("?"))		{			if (iAttemptsLeft)				wxThread::Sleep(1000);			continue;		}					pptGPS->m_fLong = 0;		strLong.ToDouble(&pptGPS->m_fLong);				return wxT("");	}	LibRoadnavDebug0(wxT("gpsd"), wxT("Timeout requesting position"));	return wxT("No data");}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieves the gps heading from the gpsd server.////// \param psockGPSD			Socket connected to gpsd server./// \param iProtocolVersion		Protocol version used by gpsd server./// \param pfHeading			Returns the heading from the gpsd server./// \return						Empty string on success, or error message on error./////////////////////////////////////////////////////////////////////////////////wxString GPSInterface_GPSD::GPSDGetHeading(wxSocketBase * psockGPSD, int iProtocolVersion, double * pfHeading){	char szBuf[64];	int iRead = 0;	int iAttemptsLeft = 1;		*pfHeading = 0;		while (iAttemptsLeft--)	{		LibRoadnavDebug0(wxT("gpsd"), wxT("Requesting heading from server"));		psockGPSD->Write("t\n", 2);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Write error"));			return wxT("gpsd write error");		}		psockGPSD->Read(szBuf, 63);				if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Read error"));			return wxT("gpsd read error");		}		iRead = psockGPSD->LastCount();		LibRoadnavDebug1(wxT("gpsd"), wxT("Got %d bytes from server"), iRead);				if (iRead < 1)			return wxT("gpsd socket error");		wxASSERT(iRead <= 63);		if (iRead > 63)			iRead = 63;				szBuf[iRead] = 0;		LibRoadnavDebug1(wxT("gpsd"), wxT("szBuf = %hs"), szBuf);				// tokenize version string from gpsd server		wxString strInfo(szBuf, wxConvUTF8);		wxStringTokenizer tkz(strInfo, wxT(" ,=\r\n"));		wxString strPrefix = tkz.GetNextToken();		if (strPrefix.Left(5) != wxT("GPSD"))			return wxT("This does not appear to be a gpsd 2.x server (wrong prefix)");		wxString strResponseType = tkz.GetNextToken();		if (strResponseType.Lower() != wxT("t"))			return wxT("This does not appear to be a gpsd 2.x server (does not understand t command)");		if (!tkz.HasMoreTokens())			return wxT("This does not appear to be a gpsd 2.x server (no track)");					wxString strHeading = tkz.GetNextToken();				if (strHeading == wxT("?"))		{			if (iAttemptsLeft)				wxThread::Sleep(1000);			continue;		}					*pfHeading = 0;		strHeading.ToDouble(pfHeading);		return wxT("");	}	LibRoadnavDebug0(wxT("gpsd"), wxT("Timeout requesting heading"));	return wxT("No data");}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieves the gps speed from the gpsd server.////// \param psockGPSD			Socket connected to gpsd server./// \param iProtocolVersion		Protocol version used by gpsd server./// \param pfSpeed				Returns the gps speed from the gpsd server./// \return						Empty string on success, or error message on error./////////////////////////////////////////////////////////////////////////////////wxString GPSInterface_GPSD::GPSDGetSpeed(wxSocketBase * psockGPSD, int iProtocolVersion, double * pfSpeed){	char szBuf[64];	int iRead = 0;	int iAttemptsLeft = 1;		*pfSpeed = 0;		while (iAttemptsLeft--)	{		LibRoadnavDebug0(wxT("gpsd"), wxT("Requesting speed from server"));		psockGPSD->Write("v\n", 2);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Write error"));			return wxT("gpsd write error");		}		psockGPSD->Read(szBuf, 63);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Read error"));			return wxT("gpsd read error");		}				iRead = psockGPSD->LastCount();		LibRoadnavDebug1(wxT("gpsd"), wxT("Got %d bytes from server"), iRead);		if (iRead < 1)			return wxT("gpsd socket error");		wxASSERT(iRead <= 63);		if (iRead > 63)			iRead = 63;				szBuf[iRead] = 0;		LibRoadnavDebug1(wxT("gpsd"), wxT("szBuf = %hs"), szBuf);		// tokenize version string from gpsd server		wxString strInfo(szBuf, wxConvUTF8);		wxStringTokenizer tkz(strInfo, wxT(" ,=\r\n"));		wxString strPrefix = tkz.GetNextToken();		if (strPrefix.Left(5) != wxT("GPSD"))			return wxT("This does not appear to be a gpsd 2.x server (wrong prefix)");		wxString strResponseType = tkz.GetNextToken();		if (strResponseType.Lower() != wxT("v"))			return wxT("This does not appear to be a gpsd 2.x server (does not understand v command)");		if (!tkz.HasMoreTokens())			return wxT("This does not appear to be a gpsd 2.x server (no speed)");					wxString strSpeed = tkz.GetNextToken();				if (strSpeed == wxT("?"))		{			if (iAttemptsLeft)				wxThread::Sleep(1000);			continue;		}					*pfSpeed = 0;		strSpeed.ToDouble(pfSpeed);		// convert to MPH		*pfSpeed *= 1.151;		return wxT("");	}	LibRoadnavDebug0(wxT("gpsd"), wxT("Timeout requesting speed"));	return wxT("No data");}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieves the gps lock type from the gpsd server.////// \param psockGPSD			Socket connected to gpsd server./// \param iProtocolVersion		Protocol version used by gpsd server./// \param piLockType			Returns the lock type from the gpsd server./// \return						Empty string on success, or error message on error./////////////////////////////////////////////////////////////////////////////////wxString GPSInterface_GPSD::GPSDGetLockType(wxSocketBase * psockGPSD, int iProtocolVersion, int * piLockType){	char szBuf[64];	int iRead = 0;	int iAttemptsLeft = 1;		*piLockType = 0;		while (iAttemptsLeft--)	{		LibRoadnavDebug0(wxT("gpsd"), wxT("Requesting lock type from server"));		psockGPSD->Write("s\n", 2);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Write error"));			return wxT("gpsd write error");		}		psockGPSD->Read(szBuf, 63);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Read error"));			return wxT("gpsd read error");		}				iRead = psockGPSD->LastCount();		LibRoadnavDebug1(wxT("gpsd"), wxT("Got %d bytes from server"), iRead);				if (iRead < 1)			return wxT("gpsd socket error");		wxASSERT(iRead <= 63);		if (iRead > 63)			iRead = 63;				szBuf[iRead] = 0;		LibRoadnavDebug1(wxT("gpsd"), wxT("szBuf = %hs"), szBuf);				// tokenize version string from gpsd server		wxString strInfo(szBuf, wxConvUTF8);		wxStringTokenizer tkz(strInfo, wxT(" ,=\r\n"));		wxString strPrefix = tkz.GetNextToken();		if (strPrefix.Left(5) != wxT("GPSD"))			return wxT("This does not appear to be a gpsd 2.x server (wrong prefix)");		wxString strResponseType = tkz.GetNextToken();		if (strResponseType.Lower() != wxT("s"))			return wxT("This does not appear to be a gpsd 2.x server (does not understand s command)");		if (!tkz.HasMoreTokens())			return wxT("This does not appear to be a gpsd 2.x server (no lock type)");					wxString strLockType = tkz.GetNextToken();				if (strLockType == wxT("?"))		{			if (iAttemptsLeft)				wxThread::Sleep(1000);			continue;		}					long lLockType = -1;		strLockType.ToLong(&lLockType);				*piLockType = lLockType;		return wxT("");	}		LibRoadnavDebug0(wxT("gpsd"), wxT("Timeout requesting lock type"));		return wxT("No data");}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieves the visible gps satellites from the gpsd server.////// \param psockGPSD			Socket connected to gpsd server./// \param iProtocolVersion		Protocol version used by gpsd server./// \param pvSatInfo			Returns information about the visible satellites./// \param pnSatellitesUsed		Returns the number of satellites used for the lock./// \return						Empty string on success, or error message on error./////////////////////////////////////////////////////////////////////////////////wxString GPSInterface_GPSD::GPSDGetSatelliteInfo(wxSocketBase * psockGPSD, int iProtocolVersion, vector<SSatelliteInfo> * pvSatInfo, int * pnSatellitesUsed){	char szBuf[512];	int iRead = 0;	int iAttemptsLeft = 1;		pvSatInfo->clear();	*pnSatellitesUsed = 0;		while (iAttemptsLeft--)	{		LibRoadnavDebug0(wxT("gpsd"), wxT("Requesting satellite info from server"));		psockGPSD->Write("y\n", 2);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Write error"));			return wxT("gpsd write error");		}		psockGPSD->Read(szBuf, 511);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Read error"));			return wxT("gpsd read error");		}				iRead = psockGPSD->LastCount();		LibRoadnavDebug1(wxT("gpsd"), wxT("Got %d bytes from server"), iRead);				if (iRead < 1)			return wxT("gpsd socket error");		wxASSERT(iRead <= 511);		if (iRead > 511)			iRead = 511;				szBuf[iRead] = 0;		LibRoadnavDebug1(wxT("gpsd"), wxT("szBuf = %hs"), szBuf);				// tokenize version string from gpsd server		wxString strInfo(szBuf, wxConvUTF8);		wxStringTokenizer tkz(strInfo, wxT(" ,:=\r\n"));		wxString strPrefix = tkz.GetNextToken();		if (strPrefix.Left(5) != wxT("GPSD"))			return wxT("This does not appear to be a gpsd 2.x server (wrong prefix)");		wxString strResponseType = tkz.GetNextToken();		if (strResponseType.Lower() != wxT("y"))			return wxT("This does not appear to be a gpsd 2.x server (does not understand y command)");		if (!tkz.HasMoreTokens())			return wxT("This does not appear to be a gpsd 2.x server (no satellite info)");				if (iProtocolVersion >= 2)		{				wxString strTag = tkz.GetNextToken();						if (strTag == wxT("?"))			{				if (iAttemptsLeft)					wxThread::Sleep(1000);				continue;			}			wxString strTimestamp = tkz.GetNextToken();			// don't care about timestamp		}				wxString strCount = tkz.GetNextToken();		// don't trust the count .. go by how many 5-tuples are really there		if (strCount == wxT("?"))		{			if (iAttemptsLeft)				wxThread::Sleep(1000);			continue;		}				pvSatInfo->clear();		*pnSatellitesUsed = 0;				while (tkz.HasMoreTokens())		{			SSatelliteInfo sInfo;			long lTmp;						tkz.GetNextToken().ToLong(&lTmp);						sInfo.m_iID = lTmp;						tkz.GetNextToken().ToDouble(&sInfo.m_fElevation);			tkz.GetNextToken().ToDouble(&sInfo.m_fAzimuth);			tkz.GetNextToken().ToDouble(&sInfo.m_fSNR);						if (sInfo.m_fSNR > 100)				sInfo.m_fSNR = 100;						if (tkz.HasMoreTokens())			{				long lUsed = 0;								tkz.GetNextToken().ToLong(&lUsed);								if (lUsed)					(*pnSatellitesUsed)++;								pvSatInfo->push_back(sInfo);			}		}		return wxT("");	}		LibRoadnavDebug0(wxT("gpsd"), wxT("Timeout requesting satellite info"));	// it's okay if there's no satellite data	return wxT("No data");}//////////////////////////////////////////////////////////////////////////////////// \brief Retrieves the timestamp of the last lock.////// \param psockGPSD			Socket connected to gpsd server./// \param iProtocolVersion		Protocol version used by gpsd server./// \param pfTimestamp			Returns the timestamp of the last lock./// \return						Empty string on success, or error message on error./////////////////////////////////////////////////////////////////////////////////wxString GPSInterface_GPSD::GPSDGetLastTimestamp(wxSocketBase * psockGPSD, int iProtocolVersion, double * pfTimestamp){	char szBuf[64];	int iRead = 0;	int iAttemptsLeft = 5;		*pfTimestamp = 0;		while (iAttemptsLeft--)	{		LibRoadnavDebug0(wxT("gpsd"), wxT("Requesting timestamp from server"));		psockGPSD->Write("x\n", 2);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Write error"));			return wxT("gpsd write error");		}		psockGPSD->Read(szBuf, 63);		if (psockGPSD->Error())		{			LibRoadnavDebug0(wxT("gpsd"), wxT("Read error"));			return wxT("gpsd read error");		}				iRead = psockGPSD->LastCount();		LibRoadnavDebug1(wxT("gpsd"), wxT("Got %d bytes from server"), iRead);				if (iRead < 1)			return wxT("gpsd socket error");		wxASSERT(iRead <= 63);		if (iRead > 63)			iRead = 63;				szBuf[iRead] = 0;		LibRoadnavDebug1(wxT("gpsd"), wxT("szBuf = %hs"), szBuf);				// tokenize version string from gpsd server		wxString strInfo(szBuf, wxConvUTF8);		wxStringTokenizer tkz(strInfo, wxT(" ,=\r\n"));		wxString strPrefix = tkz.GetNextToken();		if (strPrefix.Left(5) != wxT("GPSD"))			return wxT("This does not appear to be a gpsd 2.x server (wrong prefix)");		wxString strResponseType = tkz.GetNextToken();		if (strResponseType.Lower() != wxT("x"))			return wxT("This does not appear to be a gpsd 2.x server (does not understand x command)");		if (!tkz.HasMoreTokens())			return wxT("This does not appear to be a gpsd 2.x server (no timestamp)");					wxString strTimestamp = tkz.GetNextToken();				if (strTimestamp == wxT("?"))		{			if (iAttemptsLeft)				wxThread::Sleep(1000);			continue;		}					*pfTimestamp = 0;		strTimestamp.ToDouble(pfTimestamp);		return wxT("");	}	LibRoadnavDebug0(wxT("gpsd"), wxT("Timeout requesting timestamp"));	return wxT("No data");}#endif

⌨️ 快捷键说明

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