PUD: better definition for UplinkWireFormat
authorFerry Huberts <f.huberts@mindef.nl>
Tue, 2 Aug 2011 12:08:55 +0000 (14:08 +0200)
committerFerry Huberts <f.huberts@mindef.nl>
Tue, 18 Oct 2011 10:08:27 +0000 (12:08 +0200)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/receiver.c
lib/pud/src/wireFormat.h

index 705d875..4e300c7 100644 (file)
@@ -182,7 +182,7 @@ static bool positionValid(PositionUpdateEntry * position){
  */
 static void txToAllOlsrInterfaces(TimedTxInterface interfaces) {
        UplinkWireFormat uplinkWireFormat;
-       union olsr_message * olsrMessage = (union olsr_message *)&uplinkWireFormat.txBuffer[0];
+       union olsr_message * olsrMessage = (union olsr_message *)&uplinkWireFormat.msg.olsrMessage;
        unsigned int aligned_size = 0;
 
        /* convert nmeaINFO to wireformat olsr message */
@@ -192,7 +192,7 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) {
                nmea_time_now(&transmitGpsInformation.txPosition.nmeaInfo.utc);
        }
        aligned_size = gpsToOlsr(&transmitGpsInformation.txPosition.nmeaInfo,
-                       olsrMessage, sizeof(uplinkWireFormat.txBuffer),
+                       olsrMessage, sizeof(uplinkWireFormat.msg),
                        ((state.externalState == MOVING) ? getUpdateIntervalMoving()
                                                : getUpdateIntervalStationary()));
        transmitGpsInformation.updated = false;
@@ -247,7 +247,7 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) {
 
                                errno = 0;
                                if (sendto(fd, &uplinkWireFormat, (sizeof(uplinkWireFormat) -
-                                               sizeof(uplinkWireFormat.txBuffer)) + aligned_size, 0,
+                                               sizeof(uplinkWireFormat.msg)) + aligned_size, 0,
                                                (struct sockaddr *) &address->in,
                                                sizeof(address->in)) < 0) {
                                        pudError(true, "Could not send to uplink"
@@ -259,7 +259,7 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) {
                                                        PUD_PLUGIN_ABBR, aligned_size);
                                        dump_packet((unsigned char *)&uplinkWireFormat,
                                                        (sizeof(uplinkWireFormat) -
-                                                        sizeof(uplinkWireFormat.txBuffer)) + aligned_size);
+                                                        sizeof(uplinkWireFormat.msg)) + aligned_size);
                                }
 #endif
                        }
index 3159378..310fd02 100644 (file)
@@ -9,6 +9,8 @@
 #include <time.h>
 #include <net/if.h>
 
+#include "olsr_protocol.h"
+
 /** The size of the buffer in which the OLSR message is assembled */
 #define TX_BUFFER_SIZE_FOR_OLSR 512
 
@@ -235,7 +237,10 @@ typedef struct _UplinkWireFormat {
                uint8_t type; /**< stores a UplinkMessageType */
                uint16_t length; /**< the length of the payload in txBuffer */
                uint8_t pad; /**< padding to align to 4 bytes */
-               unsigned char txBuffer[TX_BUFFER_SIZE_FOR_OLSR]; /**< payload */
+               union _msg {
+                       union olsr_message olsrMessage; /**< the olsr message */
+                       unsigned char txBuffer[TX_BUFFER_SIZE_FOR_OLSR]; /**< payload */
+               } msg;
 }__attribute__((__packed__)) UplinkWireFormat;
 
 /* ************************************************************************