author Ferry Huberts Wed, 27 Jun 2012 12:01:49 +0000 (14:01 +0200) committer Ferry Huberts Wed, 27 Jun 2012 12:56:04 +0000 (14:56 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>

index 7442fdc..1638949 100644 (file)
@@ -284,6 +284,52 @@ static void determineCumulativeSmaskSigFix(
}

/**
+ * Adjust the range of the direction 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
+ */
+       assert(direction >= (double)0.0);
+       assert(direction < (double)360.0);
+
+       if (direction >= (double)180.0) {
+               printf("  getAdjustedDirectionForAveraging=%f (exit)\n", direction - (double)360.0);
+               return (direction - (double)360.0);
+       }
+
+       return direction;
+}
+
+/**
+ * Adjust the range of the direction after averaging: the reverse of getAdjustedDirectionForAveraging
+ * <pre>
+ * [-180,   0) --> [ 180, 360)
+ * [   0, 180) --> [   0, 180)
+ * </pre>
+ * @param direction the direction to adjust
+ * @return the adjusted direction
+ */
+       assert(direction >= (double)-180.0);
+       assert(direction < (double)180.0);
+
+       if (direction < (double)0.0) {
+               printf("  getAdjustedDirectionAfterAveraging=%f (exit)\n", direction + (double)360.0);
+               return (direction + (double)360.0);
+       }
+
+       return direction;
+}
+
+/**
the counters, adjusts the entriesCount and redetermines the cumulative
@@ -300,6 +346,7 @@ static void addOrRemoveEntryToFromCumulativeAverage(
PositionUpdateEntry * cumulative =
&positionAverageList->positionAverageCumulative;

assert(positionAverageList->entriesCount >= positionAverageList->entriesMaxCount);
@@ -348,8 +395,8 @@ static void addOrRemoveEntryToFromCumulativeAverage(
: -entry->nmeaInfo.elv;
: -entry->nmeaInfo.speed;
-       cumulative->nmeaInfo.direction += add ? entry->nmeaInfo.direction
-                       : -entry->nmeaInfo.direction;