0

Thank you in advance,

Is this proper way how to get hdop and other data from watcher mode from gpsd (version gpsd-2.37)?

Code below works fine, but I have no experience with gpsd and I'm not sure if the way I'm calling functions:

  • gps_query(gpsHandle, "w+\n");

  • gps_query( gpsHandle, "q\n" );

  • gpsProcess( &newGpsData ) -> gps_poll( &newGpsData )

is proper.

Edit #1: I added loging for gpsd internal stream so I figured out, that when I run "gps_query( gpsHandle, "q\n" );" it will add one line "GPSD,Q=9 0.00 3.73 1.89 2.82 6.52" to it and "gps_unpack" will parse it out with

sscanf(sp, "Q=%d %lf %lf %lf %lf %lf",
               &gpsdata->satellites_used,
               &gpsdata->pdop,
               &gpsdata->hdop,
               &gpsdata->vdop,
               &gpsdata->tdop,
               &gpsdata->gdop);

Thank you
Jan

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 );
    }
Ján Lazár
  • 491
  • 5
  • 8

1 Answers1

0

Does this work on new gpsd releases? because they moved to JSON interface to communicate with gpsd.

If you are working on older release, try seeing the libgps.c and gps_unpack function.

gps_unpack will format the message to the application program. try grepping the hdop info, must be one of satellite info structures.