Trouble connecting to gpsd

989 views Asked by At

I have a board with Linux Ångström running on it. Now i wan't to get GPS Data in my programm. So i set up a gpsdeamon who gets his gps informations from a modem. The deamon works well and if i telnet to localhost:2947 (which is the standard port for gpsd) i reveive a bunch of json strings from the deamon, like this:

{"class":"TPV","tag":"GGA","device":"/dev/ttyUSB2","mode":3,"lat":51.282822633," lon":11.404333250,"alt":327.500}

So gpsd seems to be set up correctly.

But in my C-Programm i can't get a connection to this port and i don't know why. My Code looks like that:

#include <gps.h>
struct gps_data_t *gpsdata = 0;

int main() {
if(gps_open("localhost", "2947", gpsdata)<0){
        fprintf(stderr,"Could not connect to GPSd\n");
        return(-1);
    }
/* some more stuff */
}

The problem is, that the function gps_open() always return -1. All libraries seems to be installed correctly. Do you have any idea, what i can try to make it work?

1

There are 1 answers

0
Carlo Lobrano On

You can look into the error using gps_errstr function, something like the following

#include <errno.h>
...

int main()
{
    if(gps_open("localhost", "2947", gpsdata)<0){
        fprintf(stderr,"Could not connect to GPSd (error %s)\n",
                gps_errstr(errno));
        return(-1);
    }
    /* some more stuff */ 
}

However, the problem is that gps_open needs a pointer to a valid (not null) gps_data_t structure, something you can have declaring gpsdata this way

struct gps_data_t gpsdata[1];