0

先感谢您,

这是如何从 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 );
    }
4

1 回答 1

0

这适用于新的 gpsd 版本吗?因为他们转移到 JSON 接口来与 gpsd 通信。

如果您正在使用旧版本,请尝试查看 libgps.c 和 gps_unpack 函数。

gps_unpack 将格式化消息到应用程序。尝试 grepping hdop 信息,必须是卫星信息结构之一。

于 2013-10-18T11:31:51.943 回答