先感谢您,
这是正确的方法如何从gpsd(版本gpsd-2.37)的观察者模式中获取hdop和其他数据吗?
下面的代码可以正常工作,但是我没有gpsd的经验,并且不确定是否调用函数的方式:
gps_query(gpsHandle,“ w + \ n”);
gps_query(gpsHandle,“ q \ n”);
gpsProcess(&newGpsData)-> gps_poll(&newGpsData)
是适当的。
编辑#1:
我为gpsd内部流添加了日志记录,所以我弄清楚了,当我运行时
“ gps_query(gpsHandle,” q \ n“);”
它将增加一行
“ GPSD,Q = 9 0.00 3.73 1.89 2.82 6.52”
到它,“ gps_unpack”将解析为
sscanf(sp, "Q=%d %lf %lf %lf %lf %lf",
&gpsdata->satellites_used,
&gpsdata->pdop,
&gpsdata->hdop,
&gpsdata->vdop,
&gpsdata->tdop,
&gpsdata->gdop);
谢谢
一月
gps_query(gpsHandle, "w+\n"); // Place in watcher mode
for (;;)
{
if ( gpsProcess( &newGpsData ) )
{
syslog( LOG_INFO, "jlazar gpsProcess reported event, "
"online = %d, status = %d, sats = %d, used = %d",
(int)newGpsData.online, newGpsData.status, newGpsData.satellites, newGpsData.satellites_used );
syslog( LOG_INFO, "jlazar gpsProcess if pdop=%f, hdop=%f, vdop=%f, tdop=%f, gdop=%f",
newGpsData.pdop, newGpsData.hdop, newGpsData.vdop, newGpsData.tdop, newGpsData.gdop );
// double pdop, hdop, vdop, tdop, gdop; /* Dilution of precision */
pthread_mutex_lock( &gpsInfo_mutex );
gpsInfoCache.online = (newGpsData.online != 0);
gpsInfoCache.status = newGpsData.status; // Assumes GPS_SERVICE_STATUS_* constants in gps_services.h match STATUS_* constants in gps.h
gpsInfoCache.satellites_used = newGpsData.satellites_used;
gpsInfoCache.satellites = newGpsData.satellites;
gpsInfoCache.ROCCorrection = getAverageROCCorrection( getROCCorrection( newGpsData.hdop ) );
if ( gpsInfoCache.status != GPS_SERVICE_STATUS_NO_FIX )
{
time_t gpsTime;
struct tm tmTime;
/* Convert latitude */
latlon = newGpsData.fix.latitude;
latlon *= DEG_TO_MSEC; /* convert to milliseconds */
gpsInfoCache.lat_msec = (int)(latlon);
/* Convert longitude */
latlon = newGpsData.fix.longitude;
latlon *= DEG_TO_MSEC; /* convert to milliseconds */
gpsInfoCache.lon_msec = (int)(latlon);
gpsInfoCache.heading = (int)newGpsData.fix.track;
gpsInfoCache.velocity = (int)(newGpsData.fix.speed * MPS_TO_KNOTS * 1000);
gpsInfoCache.avgVelocity = getAverageSpeed(gpsInfoCache.velocity);
gpsTime = (time_t)newGpsData.fix.time;
gmtime_r(&gpsTime, &tmTime);
// syslog( LOG_INFO, "pollGpsd() Got Fix %d, %d", gpsInfoCache.lat_msec, gpsInfoCache.lon_msec );
}
else
{
gpsInfoCache.lat_msec = 0;
gpsInfoCache.lon_msec = 0;
gpsInfoCache.avgVelocity = getAverageSpeed(0);
// syslog( LOG_INFO, "pollGpsd() Got No Fix" );
}
pthread_mutex_unlock( &gpsInfo_mutex );
}
gps_query( gpsHandle, "q\n" ); // a count of satellites used in the last fix, and five dimensionless dilution-of-precision (DOP) numbers -- spherical, horizontal, vertical, time, and total geometric
sleepMs( 1000 );
}
最佳答案
这对新的gpsd版本有效吗?因为他们移至JSON接口以与gpsd通信。
如果您正在使用旧版本,请尝试查看libgps.c和gps_unpack函数。
gps_unpack会将消息格式化为应用程序。尝试grep处理hdop信息,该信息必须是卫星信息结构之一。