PUD: pull txPosition out of PositionAverageList
[olsrd.git] / lib / pud / src / receiver.c
index d3c8d82..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
 
@@ -416,14 +422,14 @@ static TristateBoolean detemineMoving(PositionUpdateEntry * posAvgEntry,
  - true otherwise
  */
 bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
-       bool retval = false;
        static const char * rxBufferPrefix = "$GP";
-       size_t rxBufferPrefixLength = strlen(rxBufferPrefix);
+       static const size_t rxBufferPrefixLength = 3;
+
+       bool retval = false;
        PositionUpdateEntry * incomingEntry;
        MovementState currentState = state.state;
        MovementState newState = MOVING;
        PositionUpdateEntry * posAvgEntry;
-       PositionUpdateEntry * lastTxEntry;
        TristateBoolean movingNow;
 
        /* do not process when the message does not start with $GP */
@@ -475,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",
@@ -571,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;
@@ -702,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);
@@ -725,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;