pud: adjust to new nmealib
authorFerry Huberts <ferry.huberts@pelagic.nl>
Sat, 14 Jul 2012 11:21:37 +0000 (13:21 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Sun, 15 Jul 2012 20:58:41 +0000 (22:58 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/httpinfo/src/olsrd_httpinfo.c
lib/pud/resources/olsrd.pud.position.conf
lib/pud/src/configuration.c
lib/pud/src/gpsConversion.c
lib/pud/src/posAvg.c
lib/pud/src/posAvg.h
lib/pud/src/posFile.c
lib/pud/src/posFile.h
lib/pud/src/receiver.c

index 1021fdc..7414e15 100644 (file)
@@ -1107,74 +1107,15 @@ build_all_body(struct autobuf *abuf)
 
 #ifdef HTTPINFO_PUD
 /**
- * Determine whether a given nmeaINFO structure has a certain field.
- * Note: this is duplicated from nmealib to avoid depending on that library
+ * Determine if a nmeaINFO structure has a certain field.
+ * We need this function locally because nmealib might not be loaded.
  *
- * nmeaINFO dependencies:
- <pre>
- field/sentence GPGGA   GPGSA   GPGSV   GPRMC   GPVTG
- smask:         x       x       x       x       x
- utc:           x                       x
- sig:           x                       x
- fix:                   x               x
- PDOP:                  x
- HDOP:          x       x
- VDOP:                  x
- lat:           x                       x
- lon:           x                       x
- elv:           x
- speed:                                 x       x
- direction:                             x       x
- declination:                                   x
- satinfo:               x       x
- </pre>
- *
- * @param smask
- * the smask of a nmeaINFO structure
- * @param fieldName
- * the field name
- *
- * @return
- * - true when the nmeaINFO structure has the field
- * - false otherwise
+ * @param present the presence field
+ * @param fieldName use a name from nmeaINFO_FIELD
+ * @return a boolean, true when the structure has the requested field
  */
-static bool nmea_INFO_has_field_local(int smask, nmeaINFO_FIELD fieldName) {
-       switch (fieldName) {
-               case SMASK:
-                       return true;
-
-               case UTC:
-               case SIG:
-               case LAT:
-               case LON:
-                       return ((smask & (GPGGA | GPRMC)) != 0);
-
-               case FIX:
-                       return ((smask & (GPGSA | GPRMC)) != 0);
-
-               case PDOP:
-               case VDOP:
-                       return ((smask & GPGSA) != 0);
-
-               case HDOP:
-                       return ((smask & (GPGGA | GPGSA)) != 0);
-
-               case ELV:
-                       return ((smask & GPGGA) != 0);
-
-               case SPEED:
-               case DIRECTION:
-                       return ((smask & (GPRMC | GPVTG)) != 0);
-
-               case DECLINATION:
-                       return ((smask & GPVTG) != 0);
-
-               case SATINFO:
-                       return ((smask & (GPGSA | GPGSV)) != 0);
-
-               default:
-                       return false;
-       }
+static inline bool nmea_INFO_has_field_local(uint32_t present, nmeaINFO_FIELD fieldName) {
+       return ((present & fieldName) != 0);
 }
 
 static const char * NA_STRING = "N.A.";
@@ -1183,6 +1124,8 @@ static void build_pud_body(struct autobuf *abuf) {
        TransmitGpsInformation * txGpsInfo = olsr_cnf->pud_position;
        char * nodeId;
        char nodeIdString[256];
+       bool datePresent;
+       bool timePresent;
 
        abuf_puts(abuf, "<h2>Position</h2>");
 
@@ -1212,16 +1155,25 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* utc */
        abuf_puts(abuf, "<tr><td>Date / Time</td><td></td><td>UTC</td><td></td><td id=\"utc\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, UTC)) {
-               abuf_appendf(abuf, "%04d%02d%02d %02d:%02d:%02d.%02d",
-                       txGpsInfo->txPosition.nmeaInfo.utc.year + 1900,
-                       txGpsInfo->txPosition.nmeaInfo.utc.mon,
-                       txGpsInfo->txPosition.nmeaInfo.utc.day,
-                       txGpsInfo->txPosition.nmeaInfo.utc.hour,
-                       txGpsInfo->txPosition.nmeaInfo.utc.min,
-                       txGpsInfo->txPosition.nmeaInfo.utc.sec,
-                       txGpsInfo->txPosition.nmeaInfo.utc.hsec
-               );
+       datePresent = nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, UTCDATE);
+       timePresent = nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, UTCTIME);
+       if (datePresent || timePresent) {
+               if (datePresent) {
+                       abuf_appendf(abuf, "%04d%02d%02d",
+                               txGpsInfo->txPosition.nmeaInfo.utc.year + 1900,
+                               txGpsInfo->txPosition.nmeaInfo.utc.mon,
+                               txGpsInfo->txPosition.nmeaInfo.utc.day);
+               }
+               if (datePresent && timePresent) {
+                       abuf_puts(abuf, " ");
+               }
+               if (timePresent) {
+                       abuf_appendf(abuf, "%02d:%02d:%02d.%02d",
+                               txGpsInfo->txPosition.nmeaInfo.utc.hour,
+                               txGpsInfo->txPosition.nmeaInfo.utc.min,
+                               txGpsInfo->txPosition.nmeaInfo.utc.sec,
+                               txGpsInfo->txPosition.nmeaInfo.utc.hsec);
+               }
        } else {
                abuf_puts(abuf, NA_STRING);
        }
@@ -1229,7 +1181,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* smask */
        abuf_puts(abuf, "<tr><td>Input Sentences</td><td></td><td></td><td></td><td id=\"smask\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, SMASK)
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, SMASK)
                        && (txGpsInfo->txPosition.nmeaInfo.smask != GPNON)) {
                const int id[] = { GPGGA, GPGSA, GPGSV, GPRMC, GPVTG, GPNON };
                const char * ids[] = { "GPGGA", "GPGSA", "GPGSV", "GPRMC", "GPVTG" };
@@ -1252,7 +1204,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* sig */
        abuf_puts(abuf, "<tr><td>Signal Strength</td><td></td><td></td><td></td><td id=\"sig\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, SIG)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, SIG)) {
                const char * s;
                switch (txGpsInfo->txPosition.nmeaInfo.sig) {
                        case NMEA_SIG_BAD:
@@ -1267,6 +1219,21 @@ static void build_pud_body(struct autobuf *abuf) {
                        case NMEA_SIG_HIGH:
                                s = "Sensitive";
                                break;
+                       case NMEA_SIG_RTKIN:
+                               s = "Real Time Kinematic";
+                               break;
+                       case NMEA_SIG_FLRTK:
+                               s = "Float RTK";
+                               break;
+                       case NMEA_SIG_ESTIM:
+                               s = "Estimated (Dead Reckoning)";
+                               break;
+                       case NMEA_SIG_MAN:
+                               s = "Manual Input Mode";
+                               break;
+                       case NMEA_SIG_SIM:
+                               s = "Simulation Mode";
+                               break;
                        default:
                                s = "Unknown";
                                break;
@@ -1279,7 +1246,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* fix */
        abuf_puts(abuf, "<tr><td>Fix</td><td></td><td></td><td></td><td id=\"fix\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, FIX)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, FIX)) {
                const char * s;
                switch (txGpsInfo->txPosition.nmeaInfo.fix) {
                        case NMEA_FIX_BAD:
@@ -1303,7 +1270,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* PDOP */
        abuf_puts(abuf, "<tr><td>PDOP</td><td></td><td></td><td></td><td id=\"pdop\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, PDOP)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, PDOP)) {
                abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.PDOP);
        } else {
                abuf_puts(abuf, NA_STRING);
@@ -1312,7 +1279,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* HDOP */
        abuf_puts(abuf, "<tr><td>HDOP</td><td></td><td></td><td></td><td id=\"hdop\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, HDOP)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, HDOP)) {
                abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.HDOP);
        } else {
                abuf_puts(abuf, NA_STRING);
@@ -1321,7 +1288,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* VDOP */
        abuf_puts(abuf, "<tr><td>VDOP</td><td></td><td></td><td></td><td id=\"vdop\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, VDOP)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, VDOP)) {
                abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.VDOP);
        } else {
                abuf_puts(abuf, NA_STRING);
@@ -1330,7 +1297,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* lat */
        abuf_puts(abuf, "<tr><td>Latitude</td><td></td><td>degrees</td><td></td><td id=\"lat\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, LAT)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, LAT)) {
                abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.lat);
        } else {
                abuf_puts(abuf, NA_STRING);
@@ -1339,7 +1306,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* lon */
        abuf_puts(abuf, "<tr><td>Longitude</td><td></td><td>degrees</td><td></td><td id=\"lon\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, LON)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, LON)) {
                abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.lon);
        } else {
                abuf_puts(abuf, NA_STRING);
@@ -1348,7 +1315,7 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* elv */
        abuf_puts(abuf, "<tr><td>Elevation</td><td></td><td>m</td><td></td><td id=\"elv\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, ELV)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, ELV)) {
                abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.elv);
        } else {
                abuf_puts(abuf, NA_STRING);
@@ -1357,26 +1324,35 @@ static void build_pud_body(struct autobuf *abuf) {
 
        /* speed */
        abuf_puts(abuf, "<tr><td>Speed</td><td></td><td>kph</td><td></td><td id=\"speed\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, SPEED)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, SPEED)) {
                abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.speed);
        } else {
                abuf_puts(abuf, NA_STRING);
        }
        abuf_puts(abuf, "</td></tr>\n");
 
-       /* direction */
-       abuf_puts(abuf, "<tr><td>Direction</td><td></td><td>degrees</td><td></td><td id=\"direction\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, DIRECTION)) {
-               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.direction);
+       /* track */
+       abuf_puts(abuf, "<tr><td>Track</td><td></td><td>degrees</td><td></td><td id=\"track\">");
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, TRACK)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.track);
+       } else {
+               abuf_puts(abuf, NA_STRING);
+       }
+       abuf_puts(abuf, "</td></tr>\n");
+
+       /* mtrack */
+       abuf_puts(abuf, "<tr><td>Magnetic Track</td><td></td><td>degrees</td><td></td><td id=\"mtrack\">");
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, MTRACK)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.mtrack);
        } else {
                abuf_puts(abuf, NA_STRING);
        }
        abuf_puts(abuf, "</td></tr>\n");
 
-       /* declination */
-       abuf_puts(abuf, "<tr><td>Declination</td><td></td><td>degrees</td><td></td><td id=\"declination\">");
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, DECLINATION)) {
-               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.declination);
+       /* magvar */
+       abuf_puts(abuf, "<tr><td>Magnetic Variance</td><td></td><td>degrees</td><td></td><td id=\"magvar\">");
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, MAGVAR)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.magvar);
        } else {
                abuf_puts(abuf, NA_STRING);
        }
@@ -1388,8 +1364,8 @@ static void build_pud_body(struct autobuf *abuf) {
        abuf_puts(abuf, "</table></p>\n");
 
        /* add Google Maps and OpenStreetMap links when we have both lat and lon */
-       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, LAT)
-                       && nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.smask, LON)) {
+       if (nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, LAT)
+                       && nmea_INFO_has_field_local(txGpsInfo->txPosition.nmeaInfo.present, LON)) {
                const char * c = nodeId;
 
                abuf_appendf(abuf,
index 0ab0fb7..d8e56c5 100644 (file)
 # Default: 0.0
 #speed = 0.0
 
-# Direction/Track
+# Track
 # Values: floating point value
 #         Unit is (compass) degrees
 # Default: 0.0
-#direction = 0.0
+#track = 0.0
+
+# Magnetic Track
+# Values: floating point value
+#         Unit is (compass) degrees
+# Default: 0.0
+#mtrack = 0.0
+
+# Magnetic Variance
+# Values: floating point value
+#         Unit is (compass) degrees
+# Default: 0.0
+#magvar = 0.0
index 968045c..721b097 100644 (file)
@@ -12,7 +12,7 @@
 
 /* System includes */
 #include <unistd.h>
-#include <nmea/util.h>
+#include <nmea/parse.h>
 #include <OlsrdPudWireFormat/nodeIdConversion.h>
 #include <limits.h>
 
@@ -202,7 +202,7 @@ static bool intSetupNodeIdBinaryString(void) {
        size_t nodeidlength;
        char * nodeid = (char *)getNodeIdWithLength(&nodeidlength);
 
-       if (nmea_string_has_invalid_chars(nodeid, PUD_NODE_ID_NAME, &report[0], sizeof(report))) {
+       if (nmea_parse_sentence_has_invalid_chars(nodeid, nodeidlength, PUD_NODE_ID_NAME, &report[0], sizeof(report))) {
                pudError(false, "%s", &report[0]);
                return false;
        }
@@ -782,7 +782,7 @@ int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)
                return true;
        }
 
-       if (nmea_string_has_invalid_chars(value, valueName, &report[0], sizeof(report))) {
+       if (nmea_parse_sentence_has_invalid_chars(value, valueLength, valueName, &report[0], sizeof(report))) {
                pudError(false, "%s", &report[0]);
                return true;
        }
index 5960d91..15d2210 100644 (file)
@@ -9,6 +9,7 @@
 #include "olsr.h"
 
 /* System includes */
+#include <nmea/info.h>
 #include <nmea/tok.h>
 #include <nmea/gmath.h>
 #include <arpa/inet.h>
@@ -88,7 +89,7 @@ unsigned int gpsFromOlsr(union olsr_message *olsrMessage,
        /* time is ALWAYS present so we can just use it */
        getPositionUpdateTime(olsrGpsMessage, time(NULL), &timeStruct);
 
-       if (likely(nmea_INFO_has_field(smask, LAT))) {
+       if (likely(nmea_INFO_is_present_smask(smask, LAT))) {
                double latitude = getPositionUpdateLatitude(olsrGpsMessage);
 
                if (latitude >= 0) {
@@ -105,7 +106,7 @@ unsigned int gpsFromOlsr(union olsr_message *olsrMessage,
                latitudeString[0] = '\0';
        }
 
-       if (likely(nmea_INFO_has_field(smask, LON))) {
+       if (likely(nmea_INFO_is_present_smask(smask, LON))) {
                double longitude = getPositionUpdateLongitude(olsrGpsMessage);
 
                if (longitude >= 0) {
@@ -122,25 +123,25 @@ unsigned int gpsFromOlsr(union olsr_message *olsrMessage,
                longitudeString[0] = '\0';
        }
 
-       if (likely(nmea_INFO_has_field(smask, ELV))) {
+       if (likely(nmea_INFO_is_present_smask(smask, ELV))) {
                snprintf(&altitudeString[0], PUD_TX_ALTITUDE_DIGITS, "%ld", getPositionUpdateAltitude(olsrGpsMessage));
        } else {
                altitudeString[0] = '\0';
        }
 
-       if (likely(nmea_INFO_has_field(smask, SPEED))) {
+       if (likely(nmea_INFO_is_present_smask(smask, SPEED))) {
                snprintf(&speedString[0], PUD_TX_SPEED_DIGITS, "%lu", getPositionUpdateSpeed(olsrGpsMessage));
        } else {
                speedString[0] = '\0';
        }
 
-       if (likely(nmea_INFO_has_field(smask, DIRECTION))) {
+       if (likely(nmea_INFO_is_present_smask(smask, TRACK))) {
                snprintf(&trackString[0], PUD_TX_TRACK_DIGITS, "%lu", getPositionUpdateTrack(olsrGpsMessage));
        } else {
                trackString[0] = '\0';
        }
 
-       if (likely(nmea_INFO_has_field(smask, HDOP))) {
+       if (likely(nmea_INFO_is_present_smask(smask, HDOP))) {
                snprintf(&hdopString[0], PUD_TX_HDOP_DIGITS, "%." PUD_TX_HDOP_DECIMALS "f",
                                nmea_meters2dop(getPositionUpdateHdop(olsrGpsMessage)));
        } else {
@@ -236,37 +237,37 @@ unsigned int gpsToOlsr(nmeaINFO *nmeaInfo, union olsr_message *olsrMessage,
        setPositionUpdateTime(olsrGpsMessage, nmeaInfo->utc.hour, nmeaInfo->utc.min,
                        nmeaInfo->utc.sec);
 
-       if (likely(nmea_INFO_has_field(nmeaInfo->smask, LAT))) {
+       if (likely(nmea_INFO_is_present(nmeaInfo->present, LAT))) {
                setPositionUpdateLatitude(olsrGpsMessage, nmeaInfo->lat);
        } else {
                setPositionUpdateLatitude(olsrGpsMessage, 0.0);
        }
 
-       if (likely(nmea_INFO_has_field(nmeaInfo->smask, LON))) {
+       if (likely(nmea_INFO_is_present(nmeaInfo->present, LON))) {
                setPositionUpdateLongitude(olsrGpsMessage, nmeaInfo->lon);
        } else {
                setPositionUpdateLongitude(olsrGpsMessage, 0.0);
        }
 
-       if (likely(nmea_INFO_has_field(nmeaInfo->smask, ELV))) {
+       if (likely(nmea_INFO_is_present(nmeaInfo->present, ELV))) {
                setPositionUpdateAltitude(olsrGpsMessage, nmeaInfo->elv);
        } else {
                setPositionUpdateAltitude(olsrGpsMessage, 0.0);
        }
 
-       if (likely(nmea_INFO_has_field(nmeaInfo->smask, SPEED))) {
+       if (likely(nmea_INFO_is_present(nmeaInfo->present, SPEED))) {
                setPositionUpdateSpeed(olsrGpsMessage, nmeaInfo->speed);
        } else {
                setPositionUpdateSpeed(olsrGpsMessage, 0.0);
        }
 
-       if (likely(nmea_INFO_has_field(nmeaInfo->smask, DIRECTION))) {
-               setPositionUpdateTrack(olsrGpsMessage, nmeaInfo->direction);
+       if (likely(nmea_INFO_is_present(nmeaInfo->present, TRACK))) {
+               setPositionUpdateTrack(olsrGpsMessage, nmeaInfo->track);
        } else {
                setPositionUpdateTrack(olsrGpsMessage, 0);
        }
 
-       if (likely(nmea_INFO_has_field(nmeaInfo->smask, HDOP))) {
+       if (likely(nmea_INFO_is_present(nmeaInfo->present, HDOP))) {
                setPositionUpdateHdop(olsrGpsMessage, nmeaInfo->HDOP);
        } else {
                setPositionUpdateHdop(olsrGpsMessage, PUD_HDOP_MAX);
index 1dc4542..b6f954f 100644 (file)
@@ -7,6 +7,7 @@
 
 /* System includes */
 #include <assert.h>
+#include <nmea/info.h>
 #include <nmea/sentence.h>
 
 /* Defines */
@@ -141,10 +142,10 @@ PositionUpdateEntry * getPositionAverageEntry(
 }
 
 /**
- Update position average mask and fix counters for a new entry or for an entry
- that is/will be removed. Update the respective counters when the smask of the
- entry has the corresponding flag set. The fix counters count the fix values
- separately.
+ Update position average present, smask and fix counters for a new entry or for
+ an entry that is/will be removed. Update the respective counters when the smask
+ of the entry has the corresponding flag set. The fix counters count the fix
values separately.
 
  @param positionAverageList
  The position average list
@@ -157,12 +158,87 @@ PositionUpdateEntry * getPositionAverageEntry(
 static void updateCounters(PositionAverageList * positionAverageList,
                PositionUpdateEntry * entry, bool add) {
        PositionUpdateCounters * counters = &positionAverageList->counters;
+       uint32_t present = entry->nmeaInfo.present;
        int smask = entry->nmeaInfo.smask;
 #ifndef NDEBUG
        unsigned long long maxCount = positionAverageList->entriesMaxCount;
 #endif
        int amount = (add ? 1 : -1);
 
+       /* present */
+       if ((present & SMASK) != 0) {
+               assert(add ? (counters->smask < maxCount):(counters->smask > 0));
+               counters->smask += amount;
+       }
+       if ((present & UTCDATE) != 0) {
+               assert(add ? (counters->utcdate < maxCount):(counters->utcdate > 0));
+               counters->utcdate += amount;
+       }
+       if ((present & UTCTIME) != 0) {
+               assert(add ? (counters->utctime < maxCount):(counters->utctime > 0));
+               counters->utctime += amount;
+       }
+       if ((present & SIG) != 0) {
+               assert(add ? (counters->sig < maxCount):(counters->sig > 0));
+               counters->sig += amount;
+       }
+       if ((present & FIX) != 0) {
+               assert(add ? (counters->fix < maxCount):(counters->fix > 0));
+               counters->fix += amount;
+       }
+       if ((present & PDOP) != 0) {
+               assert(add ? (counters->pdop < maxCount):(counters->pdop > 0));
+               counters->pdop += amount;
+       }
+       if ((present & HDOP) != 0) {
+               assert(add ? (counters->hdop < maxCount):(counters->hdop > 0));
+               counters->hdop += amount;
+       }
+       if ((present & VDOP) != 0) {
+               assert(add ? (counters->vdop < maxCount):(counters->vdop > 0));
+               counters->vdop += amount;
+       }
+       if ((present & LAT) != 0) {
+               assert(add ? (counters->lat < maxCount):(counters->lat > 0));
+               counters->lat += amount;
+       }
+       if ((present & LON) != 0) {
+               assert(add ? (counters->lon < maxCount):(counters->lon > 0));
+               counters->lon += amount;
+       }
+       if ((present & ELV) != 0) {
+               assert(add ? (counters->elv < maxCount):(counters->elv > 0));
+               counters->elv += amount;
+       }
+       if ((present & SPEED) != 0) {
+               assert(add ? (counters->speed < maxCount):(counters->speed > 0));
+               counters->speed += amount;
+       }
+       if ((present & TRACK) != 0) {
+               assert(add ? (counters->track < maxCount):(counters->track > 0));
+               counters->track += amount;
+       }
+       if ((present & MTRACK) != 0) {
+               assert(add ? (counters->mtrack < maxCount):(counters->mtrack > 0));
+               counters->mtrack += amount;
+       }
+       if ((present & MAGVAR) != 0) {
+               assert(add ? (counters->magvar < maxCount):(counters->magvar > 0));
+               counters->magvar += amount;
+       }
+       if ((present & SATINUSECOUNT) != 0) {
+               assert(add ? (counters->satinusecount < maxCount):(counters->satinusecount > 0));
+               counters->satinusecount += amount;
+       }
+       if ((present & SATINUSE) != 0) {
+               assert(add ? (counters->satinuse < maxCount):(counters->satinuse > 0));
+               counters->satinuse += amount;
+       }
+       if ((present & SATINVIEW) != 0) {
+               assert(add ? (counters->satinview < maxCount):(counters->satinview > 0));
+               counters->satinview += amount;
+       }
+
        /* smask */
        if ((smask & GPGGA) != 0) {
                assert(add ? (counters->gpgga < maxCount):(counters->gpgga > 0));
@@ -186,7 +262,7 @@ static void updateCounters(PositionAverageList * positionAverageList,
        }
 
        /* sig */
-       if (nmea_INFO_has_field(smask, SIG)) {
+       if (nmea_INFO_is_present(present, SIG)) {
                if (entry->nmeaInfo.sig == NMEA_SIG_HIGH) {
                        assert(add ? (counters->sigHigh < maxCount):(counters->sigHigh > 0));
                        counters->sigHigh += amount;
@@ -203,7 +279,7 @@ static void updateCounters(PositionAverageList * positionAverageList,
        }
 
        /* fix */
-       if (nmea_INFO_has_field(smask, FIX)) {
+       if (nmea_INFO_is_present(present, FIX)) {
                if (entry->nmeaInfo.fix == NMEA_FIX_3D) {
                        assert(add ? (counters->fix3d < maxCount):(counters->fix3d > 0));
                        counters->fix3d += amount;
@@ -227,39 +303,93 @@ static void updateCounters(PositionAverageList * positionAverageList,
  @param positionAverageList
  The position average list
  */
-static void determineCumulativeSmaskSigFix(
+static void determineCumulativePresentSmaskSigFix(
                PositionAverageList * positionAverageList) {
        PositionUpdateEntry * cumulative =
                        &positionAverageList->positionAverageCumulative;
        PositionUpdateCounters * counters = &positionAverageList->counters;
        unsigned long long count = positionAverageList->entriesCount;
 
+       /* present */
+       cumulative->nmeaInfo.present = 0;
+
+       if (counters->smask >= count) {
+               cumulative->nmeaInfo.present |= SMASK;
+       }
+       if (counters->utcdate >= count) {
+               cumulative->nmeaInfo.present |= UTCDATE;
+       }
+       if (counters->utctime >= count) {
+               cumulative->nmeaInfo.present |= UTCTIME;
+       }
+       if (counters->sig >= count) {
+               cumulative->nmeaInfo.present |= SIG;
+       }
+       if (counters->fix >= count) {
+               cumulative->nmeaInfo.present |= FIX;
+       }
+       if (counters->pdop >= count) {
+               cumulative->nmeaInfo.present |= PDOP;
+       }
+       if (counters->hdop >= count) {
+               cumulative->nmeaInfo.present |= HDOP;
+       }
+       if (counters->vdop >= count) {
+               cumulative->nmeaInfo.present |= VDOP;
+       }
+       if (counters->lat >= count) {
+               cumulative->nmeaInfo.present |= LAT;
+       }
+       if (counters->lon >= count) {
+               cumulative->nmeaInfo.present |= LON;
+       }
+       if (counters->elv >= count) {
+               cumulative->nmeaInfo.present |= ELV;
+       }
+       if (counters->speed >= count) {
+               cumulative->nmeaInfo.present |= SPEED;
+       }
+       if (counters->track >= count) {
+               cumulative->nmeaInfo.present |= TRACK;
+       }
+       if (counters->mtrack >= count) {
+               cumulative->nmeaInfo.present |= MTRACK;
+       }
+       if (counters->magvar >= count) {
+               cumulative->nmeaInfo.present |= MAGVAR;
+       }
+       if (counters->satinusecount >= count) {
+               cumulative->nmeaInfo.present |= SATINUSECOUNT;
+       }
+       if (counters->satinuse >= count) {
+               cumulative->nmeaInfo.present |= SATINUSE;
+       }
+       if (counters->satinview >= count) {
+               cumulative->nmeaInfo.present |= SATINVIEW;
+       }
+
        /* smask */
        cumulative->nmeaInfo.smask = 0;
 
        if (counters->gpgga >= count) {
                cumulative->nmeaInfo.smask |= GPGGA;
        }
-
        if (counters->gpgsa >= count) {
                cumulative->nmeaInfo.smask |= GPGSA;
        }
-
        if (counters->gpgsv >= count) {
                cumulative->nmeaInfo.smask |= GPGSV;
        }
-
        if (counters->gprmc >= count) {
                cumulative->nmeaInfo.smask |= GPRMC;
        }
-
        if (counters->gpvtg >= count) {
                cumulative->nmeaInfo.smask |= GPVTG;
        }
 
        /* sig */
        cumulative->nmeaInfo.sig = NMEA_SIG_BAD;
-       if (nmea_INFO_has_field(cumulative->nmeaInfo.smask, SIG)) {
+       if (nmea_INFO_is_present(cumulative->nmeaInfo.present, SIG)) {
                if (counters->sigBad == 0) {
                        if (counters->sigHigh >= count) {
                                cumulative->nmeaInfo.sig = NMEA_SIG_HIGH;
@@ -273,7 +403,7 @@ static void determineCumulativeSmaskSigFix(
 
        /* fix */
        cumulative->nmeaInfo.fix = NMEA_FIX_BAD;
-       if (nmea_INFO_has_field(cumulative->nmeaInfo.smask, FIX)) {
+       if (nmea_INFO_is_present(cumulative->nmeaInfo.present, FIX)) {
                if (counters->fixBad == 0) {
                        if (counters->fix3d >= count) {
                                cumulative->nmeaInfo.fix = NMEA_FIX_3D;
@@ -285,43 +415,43 @@ static void determineCumulativeSmaskSigFix(
 }
 
 /**
- * Adjust the range of the direction so that we can correctly average it:
+ * Adjust the range of the track so that we can correctly average it:
  * <pre>
  * [   0, 180) --> [   0, 180)
  * [ 180, 360) --> [-180,   0)
  * </pre>
- * @param direction the direction to adjust
- * @return the adjusted direction
+ * @param track the track to adjust
+ * @return the adjusted track
  */
-static double getAdjustedDirectionForAveraging(double direction) {
-       assert(direction >= (double)0.0);
-       assert(direction < (double)360.0);
+static double getAdjustedTrackForAveraging(double track) {
+       assert(track >= (double)0.0);
+       assert(track < (double)360.0);
 
-       if (direction >= (double)180.0) {
-               return (direction - (double)360.0);
+       if (track >= (double)180.0) {
+               return (track - (double)360.0);
        }
 
-       return direction;
+       return track;
 }
 
 /**
- * Adjust the range of the direction after averaging: the reverse of getAdjustedDirectionForAveraging
+ * Adjust the range of the track after averaging: the reverse of getAdjustedTrackForAveraging
  * <pre>
  * [-180,   0) --> [ 180, 360)
  * [   0, 180) --> [   0, 180)
  * </pre>
- * @param direction the direction to adjust
- * @return the adjusted direction
+ * @param track the track to adjust
+ * @return the adjusted track
  */
-static double getAdjustedDirectionAfterAveraging(double direction) {
-       assert(direction >= (double)-180.0);
-       assert(direction < (double)180.0);
+static double getAdjustedTrackAfterAveraging(double track) {
+       assert(track >= (double)-180.0);
+       assert(track < (double)180.0);
 
-       if (direction < (double)0.0) {
-               return (direction + (double)360.0);
+       if (track < (double)0.0) {
+               return (track + (double)360.0);
        }
 
-       return direction;
+       return track;
 }
 
 /**
@@ -341,12 +471,14 @@ static void addOrRemoveEntryToFromCumulativeAverage(
                bool add) {
        PositionUpdateEntry * cumulative =
                        &positionAverageList->positionAverageCumulative;
-       double  adjustedDirection = getAdjustedDirectionForAveraging(entry->nmeaInfo.direction);
+       double  adjustedTrack = getAdjustedTrackForAveraging(entry->nmeaInfo.track);
+       double  adjustedMTrack = getAdjustedTrackForAveraging(entry->nmeaInfo.mtrack);
 
        if (!add) {
                assert(positionAverageList->entriesCount >= positionAverageList->entriesMaxCount);
                assert(entry == getPositionAverageEntry(positionAverageList, OLDEST));
 
+               /* do not touch present */
                /* do not touch smask */
 
                /* do not touch utc */
@@ -359,6 +491,7 @@ static void addOrRemoveEntryToFromCumulativeAverage(
                assert(positionAverageList->entriesCount < positionAverageList->entriesMaxCount);
                assert(entry == getPositionAverageEntry(positionAverageList, INCOMING));
 
+               /* present at the end */
                /* smask at the end */
 
                /* use the latest utc */
@@ -385,20 +518,22 @@ static void addOrRemoveEntryToFromCumulativeAverage(
        cumulative->nmeaInfo.lon += add ? entry->nmeaInfo.lon
                        : -entry->nmeaInfo.lon;
 
-       /* elv, speed, direction, declination */
+       /* elv, speed, track, mtrack, magvar */
        cumulative->nmeaInfo.elv += add ? entry->nmeaInfo.elv
                        : -entry->nmeaInfo.elv;
        cumulative->nmeaInfo.speed += add ? entry->nmeaInfo.speed
                        : -entry->nmeaInfo.speed;
-       cumulative->nmeaInfo.direction += add ? adjustedDirection
-                       : -adjustedDirection;
-       cumulative->nmeaInfo.declination += add ? entry->nmeaInfo.declination
-                       : -entry->nmeaInfo.declination;
+       cumulative->nmeaInfo.track += add ? adjustedTrack
+                       : -adjustedTrack;
+       cumulative->nmeaInfo.mtrack += add ? adjustedMTrack
+                       : -adjustedMTrack;
+       cumulative->nmeaInfo.magvar += add ? entry->nmeaInfo.magvar
+                       : -entry->nmeaInfo.magvar;
 
        positionAverageList->entriesCount += (add ? 1 : -1);
 
        updateCounters(positionAverageList, entry, add);
-       determineCumulativeSmaskSigFix(positionAverageList);
+       determineCumulativePresentSmaskSigFix(positionAverageList);
 }
 
 /**
@@ -431,11 +566,13 @@ static void updatePositionAverageFromCumulative(
 
                positionAverageList->positionAverage.nmeaInfo.elv /= divider;
                positionAverageList->positionAverage.nmeaInfo.speed /= divider;
-               positionAverageList->positionAverage.nmeaInfo.direction /= divider;
-               positionAverageList->positionAverage.nmeaInfo.declination /= divider;
+               positionAverageList->positionAverage.nmeaInfo.track /= divider;
+               positionAverageList->positionAverage.nmeaInfo.mtrack /= divider;
+               positionAverageList->positionAverage.nmeaInfo.magvar /= divider;
        }
 
-       positionAverageList->positionAverage.nmeaInfo.direction = getAdjustedDirectionAfterAveraging(positionAverageList->positionAverage.nmeaInfo.direction);
+       positionAverageList->positionAverage.nmeaInfo.track = getAdjustedTrackAfterAveraging(positionAverageList->positionAverage.nmeaInfo.track);
+       positionAverageList->positionAverage.nmeaInfo.mtrack = getAdjustedTrackAfterAveraging(positionAverageList->positionAverage.nmeaInfo.mtrack);
 
        /* satinfo: use from average */
 }
index baaf3c6..daf92c0 100644 (file)
@@ -21,6 +21,26 @@ typedef struct _PositionUpdateEntry {
  Also counts the fix values.
  */
 typedef struct _PositionUpdateCounters {
+               /* present */
+               unsigned long long smask; /**< the number of entries with SMASK present */
+               unsigned long long utcdate; /**< the number of entries with UTCDATE present */
+               unsigned long long utctime; /**< the number of entries with UTCTIME present */
+               unsigned long long sig; /**< the number of entries with SIG present */
+               unsigned long long fix; /**< the number of entries with FIX present */
+               unsigned long long pdop; /**< the number of entries with PDOP present */
+               unsigned long long hdop; /**< the number of entries with HDOP present */
+               unsigned long long vdop; /**< the number of entries with VDOP present */
+               unsigned long long lat; /**< the number of entries with LAT present */
+               unsigned long long lon; /**< the number of entries with LON present */
+               unsigned long long elv; /**< the number of entries with ELV present */
+               unsigned long long speed; /**< the number of entries with SPEED present */
+               unsigned long long track; /**< the number of entries with TRACK present */
+               unsigned long long mtrack; /**< the number of entries with MTRACK present */
+               unsigned long long magvar; /**< the number of entries with MAGVAR present */
+               unsigned long long satinusecount; /**< the number of entries with SATINUSECOUNT present */
+               unsigned long long satinuse; /**< the number of entries with SATINUSE present */
+               unsigned long long satinview; /**< the number of entries with SATINVIEW present */
+
                /* smask */
                unsigned long long gpgga; /**< the number of GPGGA based entries */
                unsigned long long gpgsa; /**< the number of GPGSA based entries */
index 0eb590c..12e0987 100644 (file)
@@ -148,7 +148,9 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
        result.lon = POSFILE_DEFAULT_LON;
        result.elv = POSFILE_DEFAULT_ELV;
        result.speed = POSFILE_DEFAULT_SPEED;
-       result.direction = POSFILE_DEFAULT_DIRECTION;
+       result.track = POSFILE_DEFAULT_TRACK;
+       result.mtrack = POSFILE_DEFAULT_MTRACK;
+       result.magvar = POSFILE_DEFAULT_MAGVAR;
 
        memcpy(&cachedStat.timeStamp, &statBuf.st_mtime, sizeof(cachedStat.timeStamp));
 
@@ -187,6 +189,7 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                                                POSFILE_VALUE_SIG_BAD, POSFILE_VALUE_SIG_LOW, POSFILE_VALUE_SIG_MID, POSFILE_VALUE_SIG_HIGH);
                                goto out;
                        }
+                       nmea_INFO_set_present(&result.present, SIG);
                } else if (!strncasecmp(POSFILE_NAME_FIX, name, sizeof(line))) {
                        if (!strncasecmp(POSFILE_VALUE_FIX_BAD, value, sizeof(line))) {
                                result.fix = NMEA_FIX_BAD;
@@ -200,6 +203,7 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                                                POSFILE_VALUE_FIX_2D, POSFILE_VALUE_FIX_3D);
                                goto out;
                        }
+                       nmea_INFO_set_present(&result.present, FIX);
                } else if (!strncasecmp(POSFILE_NAME_HDOP, name, sizeof(line))) {
                        double val;
                        if (!readDouble(POSFILE_NAME_HDOP, value, &val)) {
@@ -209,6 +213,9 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                        result.HDOP = val;
                        result.VDOP = POSFILE_CALCULATED_VDOP(result.HDOP);
                        result.PDOP = POSFILE_CALCULATED_PDOP(result.HDOP);
+                       nmea_INFO_set_present(&result.present, HDOP);
+                       nmea_INFO_set_present(&result.present, VDOP);
+                       nmea_INFO_set_present(&result.present, PDOP);
                } else if (!strncasecmp(POSFILE_NAME_LAT, name, sizeof(line))) {
                        double val;
                        if (!readDouble(POSFILE_NAME_LAT, value, &val)) {
@@ -216,6 +223,7 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                        }
 
                        result.lat = val;
+                       nmea_INFO_set_present(&result.present, LAT);
                } else if (!strncasecmp(POSFILE_NAME_LON, name, sizeof(line))) {
                        double val;
                        if (!readDouble(POSFILE_NAME_LON, value, &val)) {
@@ -223,6 +231,7 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                        }
 
                        result.lon = val;
+                       nmea_INFO_set_present(&result.present, LON);
                } else if (!strncasecmp(POSFILE_NAME_ELV, name, sizeof(line))) {
                        double val;
                        if (!readDouble(POSFILE_NAME_ELV, value, &val)) {
@@ -230,6 +239,7 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                        }
 
                        result.elv = val;
+                       nmea_INFO_set_present(&result.present, ELV);
                } else if (!strncasecmp(POSFILE_NAME_SPEED, name, sizeof(line))) {
                        double val;
                        if (!readDouble(POSFILE_NAME_SPEED, value, &val)) {
@@ -237,32 +247,47 @@ bool readPositionFile(char * fileName, nmeaINFO * nmeaInfo) {
                        }
 
                        result.speed = val;
-               } else if (!strncasecmp(POSFILE_NAME_DIRECTION, name, sizeof(line))) {
+                       nmea_INFO_set_present(&result.present, SPEED);
+               } else if (!strncasecmp(POSFILE_NAME_TRACK, name, sizeof(line))) {
                        double val;
-                       if (!readDouble(POSFILE_NAME_DIRECTION, value, &val)) {
+                       if (!readDouble(POSFILE_NAME_TRACK, value, &val)) {
                                goto out;
                        }
 
-                       result.direction = val;
+                       result.track = val;
+                       nmea_INFO_set_present(&result.present, TRACK);
+               } else if (!strncasecmp(POSFILE_NAME_MTRACK, name, sizeof(line))) {
+                       double val;
+                       if (!readDouble(POSFILE_NAME_MTRACK, value, &val)) {
+                               goto out;
+                       }
+
+                       result.mtrack = val;
+                       nmea_INFO_set_present(&result.present, MTRACK);
+               } else if (!strncasecmp(POSFILE_NAME_MAGVAR, name, sizeof(line))) {
+                       double val;
+                       if (!readDouble(POSFILE_NAME_MAGVAR, value, &val)) {
+                               goto out;
+                       }
+
+                       result.magvar = val;
+                       nmea_INFO_set_present(&result.present, MAGVAR);
                } else {
                        pudError(false, "Position file \"%s\", line %d uses an invalid option \"%s\","
-                                       " valid options are [%s|%s|%s|%s|%s|%s|%s|%s]", fileName, lineNumber, name, POSFILE_NAME_SIG,
+                                       " valid options are [%s|%s|%s|%s|%s|%s|%s|%s|%s|%s]", fileName, lineNumber, name, POSFILE_NAME_SIG,
                                        POSFILE_NAME_FIX, POSFILE_NAME_HDOP, POSFILE_NAME_LAT, POSFILE_NAME_LON, POSFILE_NAME_ELV,
-                                       POSFILE_NAME_SPEED, POSFILE_NAME_DIRECTION);
+                                       POSFILE_NAME_SPEED, POSFILE_NAME_TRACK, POSFILE_NAME_MTRACK, POSFILE_NAME_MAGVAR);
                        goto out;
                }
        }
 
        fclose(fd);
 
-       result.smask = POSFILE_SANITISE_SMASK;
+       result.smask = POSFILE_DEFAULT_SMASK;
+       nmea_INFO_set_present(&result.present, SMASK);
+
        nmea_INFO_sanitise(&result);
        nmea_INFO_unit_conversion(&result);
-       if (result.fix == NMEA_FIX_BAD) {
-               result.smask = 0;
-       } else {
-               result.smask = POSFILE_DEFAULT_SMASK;
-       }
 
        memcpy(nmeaInfo, &result, sizeof(result));
        retval = true;
index 0beb1cc..28c43c9 100644 (file)
 
 /**
  <pre>
- field/sentence GPGGA   GPRMC
- utc:           x       x
- sig:           x       x
- fix:                   x
- PDOP:                          =sqrt(2)*HDOP  (GPGSA)
- HDOP:          x
- VDOP:                          =HDOP          (GPGSA)
- lat:           x       x
- lon:           x       x
- elv:           x
- speed:                 x
- direction:             x
+ field/sentence       GPGGA   GPGSA   GPGSV   GPRMC   GPVTG
+ present:               x       x       x       x       x
+ smask:                 x       x       x       x       x
+ utc (date):                                    x
+ utc (time):            x                       x
+ sig:                   x                       x1
+ fix:                           x               x1
+ PDOP:                          x                           =sqrt(2)*HDOP  (GPGSA)
+ HDOP:                  x       x
+ VDOP:                          x                           =HDOP          (GPGSA)
+ lat:                   x                       x
+ lon:                   x                       x
+ elv:                   x
+ speed:                                         x       x
+ track:                                         x       x
+ mtrack:                                                x
+ magvar:                                        x
+ satinfo (inuse count): x       x1
+ satinfo (inuse):               x
+ satinfo (inview):                      x
+
+ x1 = not present in the sentence but the library sets it up.
  </pre>
  */
-#define POSFILE_DEFAULT_SMASK           (GPGGA | GPRMC)
-#define POSFILE_SANITISE_SMASK          (GPGGA | GPRMC | GPGSA)
+#define POSFILE_DEFAULT_SMASK           (GPGGA | GPGSA | GPRMC | GPVTG)
 
 /* no default utc: current time is always used */
 #define POSFILE_DEFAULT_SIG             (NMEA_SIG_HIGH)
@@ -37,7 +46,9 @@
 #define POSFILE_DEFAULT_LON             (0.0)
 #define POSFILE_DEFAULT_ELV             (0.0)
 #define POSFILE_DEFAULT_SPEED           (0.0)
-#define POSFILE_DEFAULT_DIRECTION       (0.0)
+#define POSFILE_DEFAULT_TRACK           (0.0)
+#define POSFILE_DEFAULT_MTRACK          (0.0)
+#define POSFILE_DEFAULT_MAGVAR          (0.0)
 
 #define POSFILE_CALCULATED_VDOP(hdop)   (hdop)
 #define POSFILE_CALCULATED_PDOP(hdop)   (hdop * 1.414213562)
@@ -49,7 +60,9 @@
 #define POSFILE_NAME_LON                "lon"
 #define POSFILE_NAME_ELV                "elv"
 #define POSFILE_NAME_SPEED              "speed"
-#define POSFILE_NAME_DIRECTION          "direction"
+#define POSFILE_NAME_TRACK              "track"
+#define POSFILE_NAME_MTRACK             "mtrack"
+#define POSFILE_NAME_MAGVAR             "magvar"
 
 #define POSFILE_VALUE_SIG_BAD           "bad"
 #define POSFILE_VALUE_SIG_LOW           "low"
index 8762e11..d777ef0 100644 (file)
@@ -104,7 +104,7 @@ static void clearMovementType(MovementType * result) {
  - false otherwise
  */
 static bool positionValid(PositionUpdateEntry * position) {
-       return (nmea_INFO_has_field(position->nmeaInfo.smask, FIX)
+       return (nmea_INFO_is_present(position->nmeaInfo.present, FIX)
                        && (position->nmeaInfo.fix != NMEA_FIX_BAD));
 }
 
@@ -141,7 +141,7 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) {
 
        /* only fixup timestamp when the position is valid _and_ when the position was not updated */
        if (positionValid(&transmitGpsInformation.txPosition) && !transmitGpsInformation.positionUpdated) {
-               nmea_time_now(&transmitGpsInformation.txPosition.nmeaInfo.utc);
+               nmea_time_now(&transmitGpsInformation.txPosition.nmeaInfo.utc, &transmitGpsInformation.txPosition.nmeaInfo.present);
        }
 
        nmeaInfo = transmitGpsInformation.txPosition.nmeaInfo;
@@ -427,19 +427,19 @@ static void detemineMovingFromPosition(PositionUpdateEntry * avg, PositionUpdate
        /* both avg and lastTx are valid here */
 
        /* avg field presence booleans */
-       avgHasSpeed = nmea_INFO_has_field(avg->nmeaInfo.smask, SPEED);
-       avgHasPos = nmea_INFO_has_field(avg->nmeaInfo.smask, LAT)
-                       && nmea_INFO_has_field(avg->nmeaInfo.smask, LON);
-       avgHasHdop = nmea_INFO_has_field(avg->nmeaInfo.smask, HDOP);
-       avgHasElv = nmea_INFO_has_field(avg->nmeaInfo.smask, ELV);
-       avgHasVdop = nmea_INFO_has_field(avg->nmeaInfo.smask, VDOP);
+       avgHasSpeed = nmea_INFO_is_present(avg->nmeaInfo.present, SPEED);
+       avgHasPos = nmea_INFO_is_present(avg->nmeaInfo.present, LAT)
+                       && nmea_INFO_is_present(avg->nmeaInfo.present, LON);
+       avgHasHdop = nmea_INFO_is_present(avg->nmeaInfo.present, HDOP);
+       avgHasElv = nmea_INFO_is_present(avg->nmeaInfo.present, ELV);
+       avgHasVdop = nmea_INFO_is_present(avg->nmeaInfo.present, VDOP);
 
        /* lastTx field presence booleans */
-       lastTxHasPos = nmea_INFO_has_field(lastTx->nmeaInfo.smask, LAT)
-                       && nmea_INFO_has_field(lastTx->nmeaInfo.smask, LON);
-       lastTxHasHdop = nmea_INFO_has_field(lastTx->nmeaInfo.smask, HDOP);
-       lastTxHasElv = nmea_INFO_has_field(lastTx->nmeaInfo.smask, ELV);
-       lastTxHasVdop = nmea_INFO_has_field(lastTx->nmeaInfo.smask, VDOP);
+       lastTxHasPos = nmea_INFO_is_present(lastTx->nmeaInfo.present, LAT)
+                       && nmea_INFO_is_present(lastTx->nmeaInfo.present, LON);
+       lastTxHasHdop = nmea_INFO_is_present(lastTx->nmeaInfo.present, HDOP);
+       lastTxHasElv = nmea_INFO_is_present(lastTx->nmeaInfo.present, ELV);
+       lastTxHasVdop = nmea_INFO_is_present(lastTx->nmeaInfo.present, VDOP);
 
        /* fill in some values _or_ defaults */
        dopMultiplier = getDopMultiplier();
@@ -731,13 +731,13 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
 
                /*
                 * When we're stationary:
-                * - the direction is not reliable or even invalid, so we must clear it.
+                * - the track is not reliable or even invalid, so we must clear it.
                 * - to avoid confusion in consumers of the data, we must clear the speed
                 *   because it is possible to have a very low speed while moving.
                 */
                if (externalState == MOVEMENT_STATE_STATIONARY) {
                        transmitGpsInformation.txPosition.nmeaInfo.speed = (double)0.0;
-                       transmitGpsInformation.txPosition.nmeaInfo.direction = (double)0.0;
+                       transmitGpsInformation.txPosition.nmeaInfo.track = (double)0.0;
                }
        }