[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-users] Valid data in gps_data_t struct
From: |
Gary E. Miller |
Subject: |
Re: [gpsd-users] Valid data in gps_data_t struct |
Date: |
Sat, 25 May 2019 13:38:43 -0700 |
Yo Massimiliano!
On Sat, 25 May 2019 22:15:47 +0200
Massimiliano Fago <address@hidden> wrote:
> in some example I see this:
>
> if (newdata->set & ONLINE_SET)
> (void)fprintf(stdout, "ONLINE: %lf\n", newdata->online);
Notice that is in the gpsd daemon, not in a client!
I assume you are working on a client, not on a driver for the daemon?
If you are working on a client then you need to look at libgps_json
and some of the example clients.
> if (newdata->set & DOP_SET)
> (void)fprintf(stdout,
> "DOP: satellites %d, pdop=%lf, hdop=%lf, vdop=%lf\n",
> newdata->satellites_used, newdata->dop.pdop,
> newdata->dop.hdop, newdata->dop.vdop);
Notice that there are seven different DOP in struct dop_t. Not all
GPS provide all of them. gpsd tries to fill in the missing ones, but may
not have sufficient data to do that.
> it is correct to check "newdata->set & DOP_SET" before use the data?
Too coarse a check. Look at each one individually.
Look in gpsd_json.c starting at line 329:
if (isfinite(datap->dop.xdop) != 0)
str_appendf(reply, replylen, "\"xdop\":%.2f,", datap->dop.xdop);
if (isfinite(datap->dop.ydop) != 0)
str_appendf(reply, replylen, "\"ydop\":%.2f,", datap->dop.ydop);
[...]
Note the check for isfinite(). That is not a check for isnan(). A
subtle details that breaks a lot of software.
Here is an example, generic, but basically correct in any language
purporting IEEE 754 compliance:
a = 1.0 / 0.0
b = -1.0 / 0.0
You can divide 1.0, and -1.0, by 0.0 an infinite number of times. So the
IEEE 754 Floating Point Math says the answers are:
a == +INF
b == -INF
+INF, and -INF, are NANs, but for weird historical reasons lost in
time they both test as:
0 == isnan(+INF)
0 == isnan(-INF)
Similar to:
0 == isnan(1.0)
0 == isnan(-1.0)
There are many different NANs and one must be careful using them.
In gpsd, what we want to know is if the value is a representable
plain number. isfinite() is the test for that. Like this:
0 == isfinite(+INF)
0 == isfinite(-INF)
1 == isfinite(1.0)
1 == isfinite(-1.0)
Very few programmers understand IEEE 754. Learning and using it as
intended can seriously speed up, and improve, floating point code.
> For example if my gps is not receving data, how I can know if pps
> subtracted themselves is valid?
The answer is in your question: if you are not receiving data then it is
not only not-valid, but non-existent. The problem is that one person's
"fresh enough" is another persons "stale". So check the fix time depending
on your freshness needs.
> The data is set to nan?
Mixing apples and oranges. NAN is for floats and doubles. timespec is
integers.
RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
address@hidden Tel:+1 541 382 8588
Veritas liberabit vos. -- Quid est veritas?
"If you can’t measure it, you can’t improve it." - Lord Kelvin
pgpBSegeXJHb7.pgp
Description: OpenPGP digital signature