PUD: nmeaTools functions are now part of nmealib
authorFerry Huberts <f.huberts@mindef.nl>
Wed, 20 Jul 2011 11:20:48 +0000 (12:20 +0100)
committerFerry Huberts <f.huberts@mindef.nl>
Mon, 25 Jul 2011 06:16:24 +0000 (08:16 +0200)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/configuration.c
lib/pud/src/gpsConversion.c
lib/pud/src/nmeaTools.c [deleted file]
lib/pud/src/nmeaTools.h [deleted file]
lib/pud/src/nodeIdConversion.c
lib/pud/src/posAvg.c
lib/pud/src/receiver.c

index 0046bdf..5252888 100644 (file)
@@ -3,7 +3,6 @@
 /* Plugin includes */
 #include "pud.h"
 #include "netTools.h"
-#include "nmeaTools.h"
 #include "nodeIdConversion.h"
 #include "networkInterfaces.h"
 
@@ -21,6 +20,7 @@
 #include <arpa/inet.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <nmea/util.h>
 
 /*
  * Utility functions
@@ -927,6 +927,8 @@ int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)
                set_plugin_parameter_addon addon __attribute__ ((unused))) {
        static const char * valueName = PUD_TX_NMEAMESSAGEPREFIX_NAME;
        size_t valueLength;
+       bool invalidChars;
+       char report[256];
 
        assert (value != NULL);
 
@@ -937,7 +939,10 @@ int setTxNmeaMessagePrefix(const char *value, void *data __attribute__ ((unused)
                return true;
        }
 
-       if (hasInvalidNmeaChars(value, valueName)) {
+       invalidChars = nmea_string_has_invalid_chars(value, valueName, &report[0],
+                       sizeof(report));
+       if (invalidChars) {
+               pudError(false, &report[0]);
                return true;
        }
 
index 347c708..7abe06e 100644 (file)
@@ -5,7 +5,6 @@
 #include "pud.h"
 #include "nodeIdConversion.h"
 #include "configuration.h"
-#include "nmeaTools.h"
 
 /* OLSR includes */
 #include "olsr.h"
@@ -13,6 +12,7 @@
 /* System includes */
 #include <nmea/gmath.h>
 #include <nmea/tok.h>
+#include <nmea/info.h>
 #include <netinet/in.h>
 #include <stdio.h>
 
@@ -74,7 +74,7 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
        /* time is ALWAYS present so we can just use it */
        getTimeFromOlsr(gpsMessage->time, &timeStruct);
 
-       if (likely(nmeaInfoHasField(olsrGpsMessage->smask, LAT))) {
+       if (likely(nmea_INFO_has_field(olsrGpsMessage->smask, LAT))) {
                int chars;
                double latitude = getLatitudeFromOlsr(gpsMessage->lat);
 
@@ -98,7 +98,7 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
                latitudeString[0] = '\0';
        }
 
-       if (likely(nmeaInfoHasField(olsrGpsMessage->smask, LON))) {
+       if (likely(nmea_INFO_has_field(olsrGpsMessage->smask, LON))) {
                int chars;
                double longitude = getLongitudeFromOlsr(gpsMessage->lon);
 
@@ -122,7 +122,7 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
                longitudeString[0] = '\0';
        }
 
-       if (likely(nmeaInfoHasField(olsrGpsMessage->smask, ELV))) {
+       if (likely(nmea_INFO_has_field(olsrGpsMessage->smask, ELV))) {
                int chars = snprintf(&altitudeString[0], PUD_TX_ALTITUDE_DIGITS, "%ld",
                                getAltitudeFromOlsr(gpsMessage->alt));
                if (likely(chars < PUD_TX_ALTITUDE_DIGITS)) {
@@ -134,7 +134,7 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
                altitudeString[0] = '\0';
        }
 
-       if (likely(nmeaInfoHasField(olsrGpsMessage->smask, SPEED))) {
+       if (likely(nmea_INFO_has_field(olsrGpsMessage->smask, SPEED))) {
                int chars = snprintf(&speedString[0], PUD_TX_SPEED_DIGITS, "%lu",
                                getSpeedFromOlsr(gpsMessage->speed));
                if (likely(chars < PUD_TX_SPEED_DIGITS)) {
@@ -146,7 +146,7 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
                speedString[0] = '\0';
        }
 
-       if (likely(nmeaInfoHasField(olsrGpsMessage->smask, DIRECTION))) {
+       if (likely(nmea_INFO_has_field(olsrGpsMessage->smask, DIRECTION))) {
                int chars = snprintf(&trackString[0], PUD_TX_TRACK_DIGITS, "%lu",
                                getTrackFromOlsr(gpsMessage->track));
                if (likely(chars < PUD_TX_TRACK_DIGITS)) {
@@ -158,7 +158,7 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
                trackString[0] = '\0';
        }
 
-       if (likely(nmeaInfoHasField(olsrGpsMessage->smask, HDOP))) {
+       if (likely(nmea_INFO_has_field(olsrGpsMessage->smask, HDOP))) {
                int chars = snprintf(&hdopString[0], PUD_TX_HDOP_DIGITS,
                                "%." PUD_TX_HDOP_DECIMALS "f", nmea_meters2dop(getHdopFromOlsr(
                                                gpsMessage->hdop)));
@@ -255,37 +255,37 @@ unsigned int gpsToOlsr(nmeaINFO *nmeaInfo, union olsr_message *olsrMessage,
        olsrGpsMessage->gpsInfo.time = getTimeForOlsr(nmeaInfo->utc.hour,
                        nmeaInfo->utc.min, nmeaInfo->utc.sec);
 
-       if (likely(nmeaInfoHasField(nmeaInfo->smask, LAT))) {
+       if (likely(nmea_INFO_has_field(nmeaInfo->smask, LAT))) {
                olsrGpsMessage->gpsInfo.lat = getLatitudeForOlsr(nmeaInfo->lat);
        } else {
                olsrGpsMessage->gpsInfo.lat = (1 << (PUD_LATITUDE_BITS - 1));
        }
 
-       if (likely(nmeaInfoHasField(nmeaInfo->smask, LON))) {
+       if (likely(nmea_INFO_has_field(nmeaInfo->smask, LON))) {
                olsrGpsMessage->gpsInfo.lon = getLongitudeForOlsr(nmeaInfo->lon);
        } else {
                olsrGpsMessage->gpsInfo.lon = (1 << (PUD_LONGITUDE_BITS - 1));
        }
 
-       if (likely(nmeaInfoHasField(nmeaInfo->smask, ELV))) {
+       if (likely(nmea_INFO_has_field(nmeaInfo->smask, ELV))) {
                olsrGpsMessage->gpsInfo.alt = getAltitudeForOlsr(nmeaInfo->elv);
        } else {
                olsrGpsMessage->gpsInfo.alt = -PUD_ALTITUDE_MIN;
        }
 
-       if (likely(nmeaInfoHasField(nmeaInfo->smask, SPEED))) {
+       if (likely(nmea_INFO_has_field(nmeaInfo->smask, SPEED))) {
                olsrGpsMessage->gpsInfo.speed = getSpeedForOlsr(nmeaInfo->speed);
        } else {
                olsrGpsMessage->gpsInfo.speed = 0;
        }
 
-       if (likely(nmeaInfoHasField(nmeaInfo->smask, DIRECTION))) {
+       if (likely(nmea_INFO_has_field(nmeaInfo->smask, DIRECTION))) {
                olsrGpsMessage->gpsInfo.track = getTrackForOlsr(nmeaInfo->direction);
        } else {
                olsrGpsMessage->gpsInfo.track = 0;
        }
 
-       if (likely(nmeaInfoHasField(nmeaInfo->smask, HDOP))) {
+       if (likely(nmea_INFO_has_field(nmeaInfo->smask, HDOP))) {
                olsrGpsMessage->gpsInfo.hdop = getHdopForOlsr(nmeaInfo->HDOP);
        } else {
                olsrGpsMessage->gpsInfo.hdop = PUD_HDOP_MAX;
diff --git a/lib/pud/src/nmeaTools.c b/lib/pud/src/nmeaTools.c
deleted file mode 100644 (file)
index 39aac02..0000000
+++ /dev/null
@@ -1,374 +0,0 @@
-#include "nmeaTools.h"
-
-/* Plugin includes */
-
-/* OLSR includes */
-#include "pud.h"
-
-/* System includes */
-#include <nmea/sentence.h>
-#include <nmea/gmath.h>
-#include <string.h>
-#include <assert.h>
-#include <stddef.h>
-#include <time.h>
-#include <sys/timeb.h>
-#include <math.h>
-
-/**
- Determine whether a given nmeaINFO structure has a certain field.
-
- nmeaINFO dependencies:
- 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
-
- @param smask
- the smask of a nmeaINFO structure
- @param fieldName
- the field name
-
- @return
- - true when the nmeaINFO structure has the field
- - false otherwise
- */
-bool nmeaInfoHasField(int smask, NmeaInfoFieldName 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;
-       }
-}
-
-/**
- Determine whether the given string contains characters that are not allowed in
- an NMEA string.
-
- @param str
- The string to check
- @param strName
- The name of the string to report when invalid characters are encountered
-
- @return
- - true when the string has invalid characters
- - false otherwise
- */
-bool hasInvalidNmeaChars(const char * str, const char * strName) {
-       static const unsigned char invalidChars[] = { '\n', '\r', '$', '*', ',',
-                       '!', '\\', '^', '~' };
-       static const char * invalidCharsNames[] = { "line feed (\\n)",
-                       "carriage return (\\r)", "sentence delimiter ($)",
-                       "checksum field delimiter (*)", "comma (,)",
-                       "exclamation mark (!)", "backslash (\\)", "^ (^)", "tilde (~)" };
-
-       size_t i;
-       size_t j;
-
-       for (i = 0; i < strlen(str); i++) {
-               unsigned char c = str[i];
-
-               if ((c < 32) || (c > 126)) {
-                       pudError(false, "Configured %s (%s) can not contain non-printable"
-                               " characters (codes [32, 126])", strName, str);
-                       return true;
-               }
-
-               for (j = 0; j < sizeof(invalidChars); j++) {
-                       if (c == invalidChars[j]) {
-                               pudError(false,
-                                               "Configured %s (%s) can not contain %s characters",
-                                               strName, str, invalidCharsNames[j]);
-                               return true;
-                       }
-               }
-       }
-
-       return false;
-}
-
-/**
- Converts the position entry fields to degrees and DOP entry fields to meters.
- We use only these units internally.
-
- @param nmeaInfo
- the position entry
- */
-void nmeaInfoUnitConversion(nmeaINFO * nmeaInfo) {
-       assert (nmeaInfo != NULL);
-
-       /* smask (already in correct format) */
-
-       /* utc (already in correct format) */
-
-       /* sig (already in correct format) */
-       /* fix (already in correct format) */
-
-       if (nmeaInfoHasField(nmeaInfo->smask, PDOP)) {
-               nmeaInfo->PDOP = nmea_dop2meters(nmeaInfo->PDOP);
-       }
-
-       if (nmeaInfoHasField(nmeaInfo->smask, HDOP)) {
-               nmeaInfo->HDOP = nmea_dop2meters(nmeaInfo->HDOP);
-       }
-
-       if (nmeaInfoHasField(nmeaInfo->smask, VDOP)) {
-               nmeaInfo->VDOP = nmea_dop2meters(nmeaInfo->VDOP);
-       }
-
-       if (nmeaInfoHasField(nmeaInfo->smask, LAT)) {
-               nmeaInfo->lat = nmea_ndeg2degree(nmeaInfo->lat);
-       }
-
-       if (nmeaInfoHasField(nmeaInfo->smask, LON)) {
-               nmeaInfo->lon = nmea_ndeg2degree(nmeaInfo->lon);
-       }
-
-       /* elv (already in correct format) */
-       /* speed (already in correct format) */
-       /* direction (already in correct format) */
-       /* declination (already in correct format) */
-
-       /* satinfo (not used) */
-}
-
-/**
- Sanitise the NMEA info: makes sure that latitude is in the range [-90, 90],
- longitude is in the range [-180, 180], speed is positive, direction is in the
- range [0, 360>. The NMEA info must already have undergone unit conversion by
- means of the nmeaInfoUnitConversion function.
-
- @param nmeaInfo
- the NMEA info structure in which to adjust the latitude and longitude
- */
-void sanitiseNmeaInfo(nmeaINFO *nmeaInfo) {
-       double lat = 0;
-       double lon = 0;
-       double speed = 0;
-       double direction = 0;
-       bool latAdjusted = false;
-       bool lonAdjusted = false;
-       bool speedAdjusted = false;
-       bool directionAdjusted = false;
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, UTC)) {
-               /* we ensure that we ALWAYS have utc */
-               struct timeb tp;
-               struct tm nowStruct;
-
-               (void) ftime(&tp);
-               gmtime_r(&tp.time, &nowStruct);
-
-               nmeaInfo->utc.year = nowStruct.tm_year;
-               nmeaInfo->utc.mon = nowStruct.tm_mon;
-               nmeaInfo->utc.day = nowStruct.tm_mday;
-               nmeaInfo->utc.hour = nowStruct.tm_hour;
-               nmeaInfo->utc.min = nowStruct.tm_min;
-               nmeaInfo->utc.sec = nowStruct.tm_sec;
-               nmeaInfo->utc.hsec = (tp.millitm / 10);
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, SIG)) {
-               nmeaInfo->sig = NMEA_SIG_BAD;
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, FIX)) {
-               nmeaInfo->fix = NMEA_FIX_BAD;
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, PDOP)) {
-               nmeaInfo->PDOP = 0;
-       } else {
-               nmeaInfo->PDOP = fabs(nmeaInfo->PDOP);
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, HDOP)) {
-               nmeaInfo->HDOP = 0;
-       } else {
-               nmeaInfo->HDOP = fabs(nmeaInfo->HDOP);
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, VDOP)) {
-               nmeaInfo->VDOP = 0;
-       } else {
-               nmeaInfo->VDOP = fabs(nmeaInfo->VDOP);
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, LAT)) {
-               nmeaInfo->lat = 0;
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, LON)) {
-               nmeaInfo->lon = 0;
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, ELV)) {
-               nmeaInfo->elv = 0;
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, SPEED)) {
-               nmeaInfo->speed = 0;
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, DIRECTION)) {
-               nmeaInfo->direction = 0;
-       }
-
-       if (!nmeaInfoHasField(nmeaInfo->smask, DECLINATION)) {
-               nmeaInfo->declination = 0;
-       }
-
-       /* satinfo is not used */
-
-       /*
-        * lat
-        */
-
-       lat = nmeaInfo->lat;
-       lon = nmeaInfo->lon;
-
-       /* force lat in [-180, 180] */
-       while (unlikely(lat < -180.0)) {
-               lat += 360.0;
-               latAdjusted = true;
-       }
-       while (unlikely(lat > 180.0)) {
-               lat -= 360.0;
-               latAdjusted = true;
-       }
-
-       /* lat is now in [-180, 180] */
-       assert (lat >= -180.0);
-       assert (lat <= 180.0);
-
-       /* force lat from <90, 180] in [90, 0] */
-       if (unlikely(lat > 90.0)) {
-               lat = 180.0 - lat;
-               lon += 180.0;
-               latAdjusted = true;
-               lonAdjusted = true;
-       }
-
-       /* force lat from [-180, -90> in [0, -90] */
-       if (unlikely(lat < -90.0)) {
-               lat = -180.0 - lat;
-               lon += 180.0;
-               latAdjusted = true;
-               lonAdjusted = true;
-       }
-
-       /* lat is now in [-90, 90] */
-       assert (lat >= -90.0);
-       assert (lat <= 90.0);
-
-       if (latAdjusted) {
-               nmeaInfo->lat = lat;
-       }
-
-       /*
-        * lon
-        */
-
-       /* force lon in [-180, 180] */
-       while (unlikely(lon < -180.0)) {
-               lon += 360.0;
-               lonAdjusted = true;
-       }
-       while (unlikely(lon > 180.0)) {
-               lon -= 360.0;
-               lonAdjusted = true;
-       }
-
-       /* lon is now in [-180, 180] */
-       assert (lon >= -180.0);
-       assert (lon <= 180.0);
-
-       if (lonAdjusted) {
-               nmeaInfo->lon = lon;
-       }
-
-       /*
-        * speed
-        */
-
-       speed = nmeaInfo->speed;
-       direction = nmeaInfo->direction;
-
-       if (unlikely(speed < 0.0)) {
-               speed = -speed;
-               direction += 180.0;
-               speedAdjusted = true;
-               directionAdjusted = true;
-       }
-
-       /* speed is now in [0, max> */
-       assert (speed >= 0.0);
-
-       if (speedAdjusted) {
-               nmeaInfo->speed = speed;
-       }
-
-       /*
-        * direction
-        */
-
-       /* force direction in [0, 360> */
-       while (unlikely(direction < 0.0)) {
-               direction += 360.0;
-               directionAdjusted = true;
-       }
-       while (unlikely(direction >= 360.0)) {
-               direction -= 360.0;
-               directionAdjusted = true;
-       }
-
-       /* direction is now in [0, 360> */
-       assert (direction >= 0.0);
-       assert (direction < 360.0);
-
-       if (directionAdjusted) {
-               nmeaInfo->direction = direction;
-       }
-}
diff --git a/lib/pud/src/nmeaTools.h b/lib/pud/src/nmeaTools.h
deleted file mode 100644 (file)
index ba1397d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef _PUD_NMEATOOLS_H_
-#define _PUD_NMEATOOLS_H_
-
-/* Plugin includes */
-
-/* OLSR includes */
-
-/* System includes */
-#include <stdbool.h>
-#include <nmea/info.h>
-
-/**
- Enumeration for the fields names of a nmeaINFO structure
- */
-typedef enum _NmeaInfoFieldName {
-       SMASK, UTC, SIG, FIX, PDOP, HDOP, VDOP, LAT, LON, ELV, SPEED, DIRECTION,
-       DECLINATION, SATINFO
-} NmeaInfoFieldName;
-
-bool nmeaInfoHasField(int smask, NmeaInfoFieldName fieldName);
-
-bool hasInvalidNmeaChars(const char * str, const char * strName);
-
-void nmeaInfoUnitConversion(nmeaINFO * nmeaInfo);
-
-void sanitiseNmeaInfo(nmeaINFO *nmeaInfo);
-
-#endif /* _PUD_NMEATOOLS_H_ */
index 4ef9ffd..0bc60d5 100644 (file)
@@ -2,7 +2,6 @@
 
 /* Plugin includes */
 #include "pud.h"
-#include "nmeaTools.h"
 #include "configuration.h"
 #include "networkInterfaces.h"
 
@@ -11,6 +10,7 @@
 /* System includes */
 #include <assert.h>
 #include <arpa/inet.h>
+#include <nmea/util.h>
 #include <net/if.h>
 
 /* ************************************************************************
@@ -96,7 +96,17 @@ bool validateNodeId(NodeIdType nodeIdTypeNumber) {
                        return setupNodeIdNumberForOlsr(0LL, 99999999999999999LL, 8);
 
                case PUD_NODEIDTYPE_DNS: /* DNS name */
-                       return !hasInvalidNmeaChars((char *) getNodeId(), PUD_NODE_ID_NAME);
+               {
+                       bool invalidChars;
+                       char report[256];
+
+                       invalidChars = nmea_string_has_invalid_chars((char *) getNodeId(),
+                                       PUD_NODE_ID_NAME, &report[0], sizeof(report));
+                       if (invalidChars) {
+                               pudError(false, &report[0]);
+                       }
+                       return !invalidChars;
+               }
 
                case PUD_NODEIDTYPE_192:
                        return setupNodeIdNumberForOlsr(0LL, 9999999LL, 3);
index be8ed31..d1d5ac8 100644 (file)
@@ -1,7 +1,6 @@
 #include "posAvg.h"
 
 /* Plugin includes */
-#include "nmeaTools.h"
 #include "dump.h"
 
 /* OLSR includes */
@@ -12,6 +11,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <nmea/sentence.h>
+#include <nmea/info.h>
 
 /* Defines */
 
@@ -214,7 +214,7 @@ static void updateCounters(PositionAverageList * positionAverageList,
        }
 
        /* sig */
-       if (nmeaInfoHasField(entry->nmeaInfo.smask, SIG)) {
+       if (nmea_INFO_has_field(entry->nmeaInfo.smask, SIG)) {
                if (entry->nmeaInfo.sig == NMEA_SIG_HIGH) {
                        assert(add ? (counters->sigHigh < maxCount):(counters->sigHigh > 0));
                        counters->sigHigh += amount;
@@ -231,7 +231,7 @@ static void updateCounters(PositionAverageList * positionAverageList,
        }
 
        /* fix */
-       if (nmeaInfoHasField(entry->nmeaInfo.smask, FIX)) {
+       if (nmea_INFO_has_field(entry->nmeaInfo.smask, FIX)) {
                if (entry->nmeaInfo.fix == NMEA_FIX_3D) {
                        assert(add ? (counters->fix3d < maxCount):(counters->fix3d > 0));
                        counters->fix3d += amount;
@@ -287,7 +287,7 @@ static void determineCumulativeSmaskSigFix(
 
        /* sig */
        cumulative->nmeaInfo.sig = NMEA_SIG_BAD;
-       if (nmeaInfoHasField(cumulative->nmeaInfo.smask, SIG)) {
+       if (nmea_INFO_has_field(cumulative->nmeaInfo.smask, SIG)) {
                if (counters->sigBad == 0) {
                        if (counters->sigHigh >= count) {
                                cumulative->nmeaInfo.sig = NMEA_SIG_HIGH;
@@ -301,7 +301,7 @@ static void determineCumulativeSmaskSigFix(
 
        /* fix */
        cumulative->nmeaInfo.fix = NMEA_FIX_BAD;
-       if (nmeaInfoHasField(cumulative->nmeaInfo.smask, FIX)) {
+       if (nmea_INFO_has_field(cumulative->nmeaInfo.smask, FIX)) {
                if (counters->fixBad == 0) {
                        if (counters->fix3d >= count) {
                                cumulative->nmeaInfo.fix = NMEA_FIX_3D;
index 8abe129..e1f744e 100644 (file)
@@ -6,7 +6,6 @@
 #include "configuration.h"
 #include "dump.h"
 #include "timers.h"
-#include "nmeaTools.h"
 #include "posAvg.h"
 #include "networkInterfaces.h"
 
@@ -16,6 +15,7 @@
 /* System includes */
 #include <stddef.h>
 #include <nmea/parser.h>
+#include <nmea/info.h>
 #include <pthread.h>
 #include <nmea/info.h>
 #include <string.h>
@@ -165,7 +165,7 @@ static void nodeIdPreTransmitHook(union olsr_message *olsrMessage,
  - false otherwise
  */
 static bool positionValid(PositionUpdateEntry * position){
-       return (nmeaInfoHasField(position->nmeaInfo.smask, FIX)
+       return (nmea_INFO_has_field(position->nmeaInfo.smask, FIX)
                        && (position->nmeaInfo.fix != NMEA_FIX_BAD));
 }
 
@@ -323,19 +323,19 @@ static void detemineMoving(PositionUpdateEntry * avg,
        /* both avg and lastTx are valid here */
 
        /* avg field presence booleans */
-       avgHasSpeed = nmeaInfoHasField(avg->nmeaInfo.smask, SPEED);
-       avgHasPos = nmeaInfoHasField(avg->nmeaInfo.smask, LAT)
-                       && nmeaInfoHasField(avg->nmeaInfo.smask, LON);
-       avgHasHdop = nmeaInfoHasField(avg->nmeaInfo.smask, HDOP);
-       avgHasElv = nmeaInfoHasField(avg->nmeaInfo.smask, ELV);
-       avgHasVdop = nmeaInfoHasField(avg->nmeaInfo.smask, VDOP);
+       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);
 
        /* lastTx field presence booleans */
-       lastTxHasPos = nmeaInfoHasField(lastTx->nmeaInfo.smask, LAT)
-                       && nmeaInfoHasField(lastTx->nmeaInfo.smask, LON);
-       lastTxHasHdop = nmeaInfoHasField(lastTx->nmeaInfo.smask, HDOP);
-       lastTxHasElv = nmeaInfoHasField(lastTx->nmeaInfo.smask, ELV);
-       lastTxHasVdop = nmeaInfoHasField(lastTx->nmeaInfo.smask, VDOP);
+       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);
 
        /* fill in some values _or_ defaults */
        dopMultiplier = getDopMultiplier();
@@ -587,19 +587,19 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
                goto end;
        }
 
-       /* we always work with latitude, longitude in degrees and DOPs in meters */
-       nmeaInfoUnitConversion(&incomingEntry->nmeaInfo);
+       nmea_INFO_sanitise(&incomingEntry->nmeaInfo);
 
 #if defined(PUD_DUMP_AVERAGING)
        dump_nmeaInfo(&incomingEntry->nmeaInfo,
-                       "receiverUpdateGpsInformation: incoming entry after unit conversion");
+                       "receiverUpdateGpsInformation: incoming entry after sanitise");
 #endif /* PUD_DUMP_AVERAGING */
 
-       sanitiseNmeaInfo(&incomingEntry->nmeaInfo);
+       /* we always work with latitude, longitude in degrees and DOPs in meters */
+       nmea_INFO_unit_conversion(&incomingEntry->nmeaInfo);
 
 #if defined(PUD_DUMP_AVERAGING)
        dump_nmeaInfo(&incomingEntry->nmeaInfo,
-                       "receiverUpdateGpsInformation: incoming entry after sanitise");
+                       "receiverUpdateGpsInformation: incoming entry after unit conversion");
 #endif /* PUD_DUMP_AVERAGING */
 
        /*