gps_query issue

View: New views
3 Messages — Rating Filter:   Alert me  

gps_query issue

by Don Weeks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Not sure if this goes to the developers list or the users list but I have
the following code listed towards the end of this message. And while the
program works while doing the poll, it does not work for the query. In the
failed case, lat, long, time and alt are all NaN.  However, if the commented
out section is run through the debugger, the query succeeds and values are
set. For the software I ultimately need to write, another application will
periodically grab from me the latitude/long/alt. So I really don't want to
implement it with gps poll.  I only want to query as needed.
           Don


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "gps.h"

static struct gps_data_t *gpsdata;
int main(int argc, char *argv[])
{
      char *err_str = NULL;
    char server[16];
char port[5];
strcpy(server, "127.0.0.1\0");
strcpy(port, "2947\0");

printf("Opening GPSd....\n");
gpsdata = gps_open(server, port);

/*    gpsdata = gps_open("localhost", "2947"); */
    if (!&gpsdata) {
        switch ( errno ) {
            case NL_NOSERVICE:  err_str = "can't get service entry"; break;
            case NL_NOHOST:     err_str = "can't get host entry"; break;
            case NL_NOPROTO:    err_str = "can't get protocol entry"; break;
            case NL_NOSOCK:     err_str = "can't create socket"; break;
            case NL_NOSOCKOPT:  err_str = "error SETSOCKOPT SO_REUSEADDR";
break;
            case NL_NOCONNECT:  err_str = "can't connect to host"; break;
            default:            err_str = "Unknown"; break;
        }
        (void)fprintf( stderr,
                "cgps: no gpsd running or network error: %d, %s\n",
                errno, err_str);
        exit(2);
      }
/*    printf("status = %d\n", gpsdata->status);
    int i=gps_query(gpsdata, "i\n");
    printf("Query Status = %d\n", i);
    i=gps_query(gpsdata, "o\n");
    printf("Query Status = %d\n", i);
    printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
gpsdata->fix.time);
    i=gps_query(gpsdata, "o\n");
    printf("Query Status = %d\n", i);
    printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
gpsdata->fix.time);
    i=gps_query(gpsdata, "o\n");
    printf("Query Status = %d\n", i);
    printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
gpsdata->fix.time);
    i=gps_query(gpsdata, "o\n");
    printf("Query Status = %d\n", i);
    printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
gpsdata->fix.time);
*/
    gps_query(gpsdata, "w\n");
    while (1) {
        gps_poll(gpsdata);
        printf("Fix Status = %d Latitiude=%lg Longitude=%lg Altitude=%f
Time=%f\n\n", gpsdata->fix.mode, gpsdata->fix.latitude,
gpsdata->fix.longitude, gpsdata->fix.altitude, gpsdata->fix.time);
    }
}
_______________________________________________
Gpsd-users mailing list
Gpsd-users@...
https://lists.berlios.de/mailman/listinfo/gpsd-users

Re: gps_query issue

by Don Weeks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Output from a good run and a bad run.

Fix Status = 3 Latitiude=32.988 Longitude=-96.7274 Altitude=206.000000
Time=1247178779.000000

Fix Status = 3 Latitiude=32.988 Longitude=-96.7274 Altitude=206.000000
Time=1247178780.000000

Fix Status = 3 Latitiude=32.988 Longitude=-96.7274 Altitude=206.000000
Time=1247178780.000000

Fix Status = 3 Latitiude=32.988 Longitude=-96.7274 Altitude=206.000000
Time=1247178781.000000

Fix Status = 3 Latitiude=32.988 Longitude=-96.7274 Altitude=206.000000
Time=1247178781.000000


dweeks@n5skt-deb:~/gpsd_query/src$ gcc -g -o gpsd_query gpsd_query.c -lgps
-I /usr/local/include
dweeks@n5skt-deb:~/gpsd_query/src$ ./gpsd_query
Opening GPSd....
status = 0
Query Status = 0
Query Status = 0
Fix Status = 0 Latitiude=nan Longitude=nan Time=nan

Query Status = 0
Fix Status = 0 Latitiude=nan Longitude=nan Time=nan

Query Status = 0
Fix Status = 0 Latitiude=nan Longitude=nan Time=nan

Query Status = 0
Fix Status = 0 Latitiude=nan Longitude=nan Time=nan


On Thu, Jul 9, 2009 at 5:30 PM, Don Weeks <don.l.weeks.jr@...> wrote:

> Not sure if this goes to the developers list or the users list but I have
> the following code listed towards the end of this message. And while the
> program works while doing the poll, it does not work for the query. In the
> failed case, lat, long, time and alt are all NaN.  However, if the commented
> out section is run through the debugger, the query succeeds and values are
> set. For the software I ultimately need to write, another application will
> periodically grab from me the latitude/long/alt. So I really don't want to
> implement it with gps poll.  I only want to query as needed.
>            Don
>
>
> #ifdef HAVE_CONFIG_H
> #include <config.h>
> #endif
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <errno.h>
> #include "gps.h"
>
> static struct gps_data_t *gpsdata;
> int main(int argc, char *argv[])
> {
>       char *err_str = NULL;
>     char server[16];
> char port[5];
> strcpy(server, "127.0.0.1\0");
> strcpy(port, "2947\0");
>
> printf("Opening GPSd....\n");
> gpsdata = gps_open(server, port);
>
> /*    gpsdata = gps_open("localhost", "2947"); */
>     if (!&gpsdata) {
>         switch ( errno ) {
>             case NL_NOSERVICE:  err_str = "can't get service entry"; break;
>             case NL_NOHOST:     err_str = "can't get host entry"; break;
>             case NL_NOPROTO:    err_str = "can't get protocol entry";
> break;
>             case NL_NOSOCK:     err_str = "can't create socket"; break;
>             case NL_NOSOCKOPT:  err_str = "error SETSOCKOPT SO_REUSEADDR";
> break;
>             case NL_NOCONNECT:  err_str = "can't connect to host"; break;
>             default:            err_str = "Unknown"; break;
>         }
>         (void)fprintf( stderr,
>                 "cgps: no gpsd running or network error: %d, %s\n",
>                 errno, err_str);
>         exit(2);
>       }
> /*    printf("status = %d\n", gpsdata->status);
>     int i=gps_query(gpsdata, "i\n");
>     printf("Query Status = %d\n", i);
>     i=gps_query(gpsdata, "o\n");
>     printf("Query Status = %d\n", i);
>     printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
> gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
> gpsdata->fix.time);
>     i=gps_query(gpsdata, "o\n");
>     printf("Query Status = %d\n", i);
>     printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
> gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
> gpsdata->fix.time);
>     i=gps_query(gpsdata, "o\n");
>     printf("Query Status = %d\n", i);
>     printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
> gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
> gpsdata->fix.time);
>     i=gps_query(gpsdata, "o\n");
>     printf("Query Status = %d\n", i);
>     printf("Fix Status = %d Latitiude=%lg Longitude=%lg Time=%lg\n\n",
> gpsdata->fix.mode, gpsdata->fix.latitude, gpsdata->fix.longitude,
> gpsdata->fix.time);
> */
>     gps_query(gpsdata, "w\n");
>     while (1) {
>         gps_poll(gpsdata);
>         printf("Fix Status = %d Latitiude=%lg Longitude=%lg Altitude=%f
> Time=%f\n\n", gpsdata->fix.mode, gpsdata->fix.latitude,
> gpsdata->fix.longitude, gpsdata->fix.altitude, gpsdata->fix.time);
>     }
> }
>
_______________________________________________
Gpsd-users mailing list
Gpsd-users@...
https://lists.berlios.de/mailman/listinfo/gpsd-users

Re: gps_query issue

by Eric Raymond-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Don Weeks <don.l.weeks.jr@...>:
> Not sure if this goes to the developers list or the users list but I have
> the following code listed towards the end of this message. And while the
> program works while doing the poll, it does not work for the query. In the
> failed case, lat, long, time and alt are all NaN.  However, if the commented
> out section is run through the debugger, the query succeeds and values are
> set. For the software I ultimately need to write, another application will
> periodically grab from me the latitude/long/alt. So I really don't want to
> implement it with gps poll.  I only want to query as needed.

It won't work that way.

See the FAQ entry http://gpsd.berlios.de/faq.html#singleshot for
explanation.
--
                <a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
_______________________________________________
Gpsd-users mailing list
Gpsd-users@...
https://lists.berlios.de/mailman/listinfo/gpsd-users