[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-users] retrieve data from gpsd without waiting

From: Felipe Gutierrez
Subject: [gpsd-users] retrieve data from gpsd without waiting
Date: Mon, 27 Aug 2018 16:56:48 +0200

Hi everyone,

I am newbie using gpsd with C. I implemented my first client which uses gps_stream function. If I understood correctly, it is like a pub/sub function that you can read gps data using gps_read. I want to retrieve the data as soon as it is available. The only way I found is to decrease the time on the gps_waiting function. I wonder if there is a way to not use the gps_waiting function and retrieve as soon as possible. Here below is my code.

int runGpsStreamClient() {
int rc;
int count = 0;
clock_t t;

struct gps_data_t gps_data;
t = clock();
if ((rc = gps_open("localhost", "2947", &gps_data)) == -1) {
printf("code: %d, reason: %s\n", rc, gps_errstr(rc));
get_metric(t, "gps_open");

t = clock();
gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
get_metric(t, "gps_stream");

while (count < 60) {
/* wait for 0.1 second to receive data */
if (gps_waiting(&gps_data, 100000)) {

t = clock();
int rc = gps_read(&gps_data);
get_metric(t, "gps_read");

/* read data */
if (rc == -1) {
printf("error occurred reading gps data. code: %d, reason: %s\n", rc, gps_errstr(rc));
} else {
/* Display data from the GPS receiver. */
double lat = gps_data.fix.latitude;
double lon = gps_data.fix.longitude;
double alt = gps_data.fix.altitude;
double speed = gps_data.fix.speed;
double climb = gps_data.fix.climb;
time_t seconds = (time_t) gps_data.fix.time;
int status = gps_data.status;
int mode = gps_data.fix.mode;

printf("status[%d], ", status);
printf("mode[%d], ", mode);
printf("latitude[%f], ", lat);
printf("longitude[%f], ", lon);
printf("altitude[%f], ", alt);
printf("speed[%f], ", speed);
printf("v speed[%f], ", climb);
printf("Time[%s].", ctime(&seconds));

if ((status == STATUS_FIX)
&& (mode == MODE_2D || mode == MODE_3D)
&& !isnan(lat) && !isnan(lon)) {
printf(" GPS data OK.\n");
} else {
printf(" GPS data NOK.\n");
} else {
printf("counter[%d]. Timeout to retrieve data from gpsd. Maybe increase gps_waiting.\n", count);
/* When you are done... */
gps_stream(&gps_data, WATCH_DISABLE, NULL);



-- Felipe Gutierrez
-- skype: felipe.o.gutierrez

reply via email to

[Prev in Thread] Current Thread [Next in Thread]