pud: split a function
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 28 Jul 2016 17:57:48 +0000 (19:57 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 29 Jul 2016 11:40:01 +0000 (13:40 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/receiver.c

index 0dc22c0..8926576 100644 (file)
@@ -66,6 +66,8 @@
 #include <OlsrdPudWireFormat/wireFormat.h>
 #include <unistd.h>
 
+static void receiverProcessIncomingEntry(PositionUpdateEntry * incomingEntry);
+
 /*
  * NMEA parser
  */
@@ -847,21 +849,10 @@ static void detemineMovingFromPosition(PositionUpdateEntry * avg, PositionUpdate
  - true otherwise
  */
 bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
-       static bool gpnonPrev = false;
-
        static const char * rxBufferPrefix = "$GP";
        static const size_t rxBufferPrefixLength = 3;
 
-       bool retval = false;
        PositionUpdateEntry * incomingEntry;
-       PositionUpdateEntry * posAvgEntry;
-       MovementType movementResult;
-       bool subStateExternalStateChange;
-       bool externalStateChange;
-       bool updateTransmitGpsInformation = false;
-       MovementState externalState;
-       bool gpnon;
-       bool gpnonChanged;
 
        /* do not process when the message does not start with $GP */
        if ((rxCount < rxBufferPrefixLength) || (strncmp((char *) rxBuffer,
@@ -874,16 +865,31 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
        nmeaInfoClear(&incomingEntry->nmeaInfo);
        nmeaTimeSet(&incomingEntry->nmeaInfo.utc, &incomingEntry->nmeaInfo.present, NULL);
        nmeaParserParse(&nmeaParser, (char *) rxBuffer, rxCount, &incomingEntry->nmeaInfo);
+       nmeaInfoSanitise(&incomingEntry->nmeaInfo);
 
-       gpnon = !nmeaInfoIsPresentAll(incomingEntry->nmeaInfo.present, NMEALIB_PRESENT_SMASK) || (incomingEntry->nmeaInfo.smask == NMEALIB_SENTENCE_GPNON);
-       gpnonChanged = gpnon != gpnonPrev;
-       gpnonPrev = gpnon;
+       receiverProcessIncomingEntry(incomingEntry);
+       return true;
+}
 
-       nmeaInfoSanitise(&incomingEntry->nmeaInfo);
+static void receiverProcessIncomingEntry(PositionUpdateEntry * incomingEntry) {
+       static bool gpnonPrev = false;
+
+       PositionUpdateEntry * posAvgEntry;
+       MovementType movementResult;
+       bool subStateExternalStateChange;
+       bool externalStateChange;
+       bool updateTransmitGpsInformation = false;
+       MovementState externalState;
+       bool gpnon;
+       bool gpnonChanged;
 
        /* we always work with latitude, longitude in degrees and DOPs in meters */
        nmeaInfoUnitConversion(&incomingEntry->nmeaInfo, true);
 
+       gpnon = !nmeaInfoIsPresentAll(incomingEntry->nmeaInfo.present, NMEALIB_PRESENT_SMASK) || (incomingEntry->nmeaInfo.smask == NMEALIB_SENTENCE_GPNON);
+       gpnonChanged = gpnon != gpnonPrev;
+       gpnonPrev = gpnon;
+
        /*
         * Averaging
         */
@@ -937,10 +943,6 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
        if (externalStateChange) {
                doImmediateTransmit(externalState);
        }
-
-       retval = true;
-
-       return retval;
 }
 
 /**