[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
✘example
From: |
Gary E. Miller |
Subject: |
✘example |
Date: |
Sat, 6 Mar 2021 18:06:25 -0800 |
Yo All!
This issue keeps coming up:
https://gitlab.com/gpsd/gpsd/-/issues/126
I think the source is several Stackoverflow answers that totally
misunderstand gpsd. Looking at one of them, they make the valid
complaint that the libgps man page does not have a working example.
I think I have a minimal one. I include in inline below, and as an
attachment for anyone that gets it munge by email.
I started to add comments, and it became way too large for a man page.
So I'm considering puting this in the libgps man page, and then
writing a more detailed white paper on the subject.
Comments?
RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
gem@rellim.com Tel:+1 541 382 8588
Veritas liberabit vos. -- Quid est veritas?
"If you can't measure it, you can't improve it." - Lord Kelvin
// example gpsd client
// compile this way:
// gcc example .c -o example -lgps -lm
#include <gps.h>
#include <math.h> // for isfinite()
#include <unistd.h> // for sleep()
#define MODE_STR_NUM 4
char *mode_str[MODE_STR_NUM] = {
"n/a",
"None",
"2D",
"3D"
};
int main(int argc, char *argv[])
{
struct gps_data_t gps_data;
if ( 0 != gps_open("localhost", "2947", &gps_data)) {
printf("Open error. Bye, bye\n");
return 1;
}
(void)gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
while (gps_waiting(&gps_data, 5000000)) {
if (gps_read(&gps_data, NULL, 0) == -1) {
printf("Read error. Bye, bye\n");
break;
}
if (MODE_SET != (MODE_SET & gps_data.set)) {
// did not even get mode, nothing to see here
continue;
}
if (0 > gps_data.fix.mode || MODE_STR_NUM <= gps_data.fix.mode) {
gps_data.fix.mode = 0;
}
printf("Fix mode: %s (%d) Time: ",
mode_str[gps_data.fix.mode],
gps_data.fix.mode);
if (TIME_SET == (TIME_SET & gps_data.set)) {
// not 32 bit safe
printf("%ld.%09ld ", gps_data.fix.time.tv_sec,
gps_data.fix.time.tv_nsec);
} else {
puts("n/a ");
}
if (isfinite(gps_data.fix.latitude) &&
isfinite( gps_data.fix.longitude)) {
// Display data from the GPS receiver if valid.
printf("Lat %.6f Lon %.6f\n",
gps_data.fix.latitude, gps_data.fix.longitude);
}
}
/* When you are done... */
(void)gps_stream(&gps_data, WATCH_DISABLE, NULL);
(void)gps_close(&gps_data);
return 0;
}
example.c
Description: Text Data
pgpIKcR7R_Vnd.pgp
Description: OpenPGP digital signature
- ✘example,
Gary E. Miller <=
Re: ✘example, Joshua Judson Rosen, 2021/03/07