PUD: pull txPosition out of PositionAverageList
authorFerry Huberts <f.huberts@mindef.nl>
Tue, 28 Jun 2011 11:33:46 +0000 (13:33 +0200)
committerFerry Huberts <f.huberts@mindef.nl>
Tue, 28 Jun 2011 11:41:07 +0000 (13:41 +0200)
It doesn't belong there

Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/posAvg.c
lib/pud/src/posAvg.h
lib/pud/src/receiver.c

index 025b35c..9381135 100644 (file)
@@ -94,10 +94,6 @@ bool initPositionAverageList(PositionAverageList * positionAverageList,
        positionAverageList->entries = p;
        positionAverageList->newestEntryIndex = 0;
 
-       positionAverageList->txPosition.nmeaInfo.smask = GPNON;
-       positionAverageList->txPosition.nmeaInfo.fix = NMEA_FIX_BAD;
-       positionAverageList->txPosition.nmeaInfo.sig = NMEA_SIG_BAD;
-
        flushPositionAverageList(positionAverageList);
 
        return true;
@@ -168,10 +164,6 @@ PositionUpdateEntry * getPositionAverageEntry(
                        r = &positionAvgList->positionAverage;
                        break;
 
-               case LASTTX:
-                       r = &positionAvgList->txPosition;
-                       break;
-
                default:
                        r = NULL;
                        break;
index 8c65446..875fea6 100644 (file)
@@ -70,15 +70,13 @@ typedef struct {
 
                PositionUpdateEntry positionAverageCumulative; /**< the average position with cumulative values */
                PositionUpdateEntry positionAverage; /**< the average position */
-
-               PositionUpdateEntry txPosition; /**< the last transmitted position */
 } PositionAverageList;
 
 /**
  Enumeration describing the type of an entry position in the average list
  */
 typedef enum {
-       OLDEST, NEWEST, INCOMING, AVERAGECUMULATIVE, AVERAGE, LASTTX
+       OLDEST, NEWEST, INCOMING, AVERAGECUMULATIVE, AVERAGE
 } AverageEntryPositionType;
 
 bool initPositionAverageList(PositionAverageList * positionAverageList,
index e5dcd7f..f3a45b2 100644 (file)
@@ -90,6 +90,12 @@ typedef struct {
 /** The latest position information that is transmitted */
 TransmitGpsInformation transmitGpsInformation;
 
+/** The last transmitted position.
+ * The same as transmitGpsInformation.txPosition.
+ * We keep this because then we can access the information without locking
+ * mutexes. */
+PositionUpdateEntry txPosition;
+
 /** The size of the buffer in which the OLSR message is assembled */
 #define TX_BUFFER_SIZE_FOR_OLSR 512
 
@@ -424,7 +430,6 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
        MovementState currentState = state.state;
        MovementState newState = MOVING;
        PositionUpdateEntry * posAvgEntry;
-       PositionUpdateEntry * lastTxEntry;
        TristateBoolean movingNow;
 
        /* do not process when the message does not start with $GP */
@@ -476,9 +481,8 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
        addNewPositionToAverage(&positionAverageList, incomingEntry);
 
        posAvgEntry = getPositionAverageEntry(&positionAverageList, AVERAGE);
-       lastTxEntry = getPositionAverageEntry(&positionAverageList, LASTTX);
 
-       movingNow = detemineMoving(posAvgEntry, lastTxEntry);
+       movingNow = detemineMoving(posAvgEntry, &txPosition);
 
 #if defined(PUD_DUMP_AVERAGING)
        olsr_printf(0, "receiverUpdateGpsInformation: currentState = %s\n",
@@ -572,8 +576,8 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
                         * transmitGpsInformation when we consider ourselves as moving
                         * (independent of the state) or when we are in the INIT or
                         * MOVING state */
-                       memcpy(&positionAverageList.txPosition.nmeaInfo,
-                                       &posAvgEntry->nmeaInfo, sizeof(nmeaINFO));
+                       memcpy(&txPosition.nmeaInfo,
+                                       &posAvgEntry->nmeaInfo, sizeof(nmeaINFO));
                        memcpy(&transmitGpsInformation.nmeaInfo, &posAvgEntry->nmeaInfo,
                                        sizeof(nmeaINFO));
                        transmitGpsInformation.updated = true;
@@ -703,6 +707,10 @@ bool startReceiver(void) {
 
        initPositionAverageList(&positionAverageList, getAverageDepth());
 
+       txPosition.nmeaInfo.smask = GPNON;
+       txPosition.nmeaInfo.fix = NMEA_FIX_BAD;
+       txPosition.nmeaInfo.sig = NMEA_SIG_BAD;
+
        if (pud_receiver_timer_cookie == NULL) {
                pud_receiver_timer_cookie = olsr_alloc_cookie(
                                PUD_PLUGIN_ABBR ": receiver", OLSR_COOKIE_TYPE_TIMER);
@@ -726,6 +734,10 @@ void stopReceiver(void) {
                pud_receiver_timer_cookie = NULL;
        }
 
+       txPosition.nmeaInfo.sig = NMEA_SIG_BAD;
+       txPosition.nmeaInfo.fix = NMEA_FIX_BAD;
+       txPosition.nmeaInfo.smask = GPNON;
+
        destroyPositionAverageList(&positionAverageList);
 
        state.hysteresisCounter = 0;