PUD: push olsrMessagePayload determination down into gpsFromOlsr
authorFerry Huberts <f.huberts@mindef.nl>
Wed, 3 Aug 2011 14:13:10 +0000 (16:13 +0200)
committerFerry Huberts <f.huberts@mindef.nl>
Thu, 18 Aug 2011 13:04:11 +0000 (15:04 +0200)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/gpsConversion.c
lib/pud/src/gpsConversion.h
lib/pud/src/pud.c

index 7abe06e..72feb03 100644 (file)
@@ -25,8 +25,6 @@
 
  @param olsrMessage
  A pointer to the OLSR message
- @param olsrMessagePayload
- A pointer to the GPS message in the OLSR message
  @param txGpsBuffer
  A pointer to the buffer in which the transmit string can be written
  @param txGpsBufferSize
  - the length of the transmit string placed in the txGpsBuffer
  - 0 (zero) in case of an error
  */
-unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
-               unsigned char *olsrMessagePayload, unsigned char * txGpsBuffer,
-               unsigned int txGpsBufferSize) {
-       PudOlsrWireFormat *olsrGpsMessage =
-                       (PudOlsrWireFormat *) olsrMessagePayload;
-       const GpsInfo* gpsMessage = &olsrGpsMessage->gpsInfo;
-
+unsigned int gpsFromOlsr(union olsr_message *olsrMessage,
+               unsigned char * txGpsBuffer, unsigned int txGpsBufferSize) {
        unsigned long validityTime;
 
        struct tm timeStruct;
@@ -61,6 +54,16 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
 
        unsigned int transmitStringLength;
 
+       PudOlsrWireFormat *olsrGpsMessage;
+       GpsInfo* gpsMessage;
+
+       /* determine the originator of the message */
+       if (olsr_cnf->ip_version == AF_INET) {
+               olsrGpsMessage = (PudOlsrWireFormat *) &olsrMessage->v4.message;
+       } else {
+               olsrGpsMessage = (PudOlsrWireFormat *) &olsrMessage->v6.message;
+       }
+
        if (unlikely(olsrGpsMessage->version != PUD_WIRE_FORMAT_VERSION)) {
                /* currently we can only handle our own version */
                pudError(false, "Can not handle version %u OLSR PUD messages"
@@ -71,6 +74,8 @@ unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
 
        validityTime = getValidityTimeFromOlsr(olsrGpsMessage->validityTime);
 
+       gpsMessage = &olsrGpsMessage->gpsInfo;
+
        /* time is ALWAYS present so we can just use it */
        getTimeFromOlsr(gpsMessage->time, &timeStruct);
 
index ea6e214..fd8046d 100644 (file)
@@ -26,8 +26,7 @@
 unsigned int gpsToOlsr(nmeaINFO *nmeaInfo, union olsr_message *olsrMessage,
                unsigned int olsrMessageSize, unsigned long long validityTime);
 
-unsigned int gpsFromOlsr(const union olsr_message *olsrMessage,
-               unsigned char *olsrMessagePayload, unsigned char * txGpsBuffer,
-               unsigned int txGpsBufferSize);
+unsigned int gpsFromOlsr(union olsr_message *olsrMessage,
+               unsigned char * txGpsBuffer, unsigned int txGpsBufferSize);
 
 #endif /* _PUD_GPSCONVERSION_H_ */
index 4f617d0..88d0d83 100644 (file)
@@ -119,7 +119,6 @@ static void sendToAllTxInterfaces(unsigned char *buffer,
 bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
                struct interface *in_if __attribute__ ((unused)), union olsr_ip_addr *ipaddr __attribute__ ((unused))) {
        const union olsr_ip_addr * originator;
-       unsigned char *olsrMessagePayload;
        unsigned int transmitStringLength;
        unsigned char buffer[BUFFER_SIZE_FROM_OLSR];
 
@@ -130,13 +129,11 @@ bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
        /* determine the originator of the messsage */
        if (olsr_cnf->ip_version == AF_INET) {
                originator = (const union olsr_ip_addr *) &olsrMessage->v4.originator;
-               olsrMessagePayload = (unsigned char *) &olsrMessage->v4.message;
 #ifdef PUD_DUMP_GPS_PACKETS_RX_OLSR
                olsrMessageSize = ntohs(olsrMessage->v4.olsr_msgsize);
 #endif
        } else {
                originator = (const union olsr_ip_addr *) &olsrMessage->v6.originator;
-               olsrMessagePayload = (unsigned char *) &olsrMessage->v6.message;
 #ifdef PUD_DUMP_GPS_PACKETS_RX_OLSR
                olsrMessageSize = ntohs(olsrMessage->v6.olsr_msgsize);
 #endif
@@ -164,8 +161,7 @@ bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
        dump_packet((unsigned char *) olsrMessage, olsrMessageSize);
 #endif
 
-       transmitStringLength = gpsFromOlsr(olsrMessage, olsrMessagePayload,
-                       &buffer[0], sizeof(buffer));
+       transmitStringLength = gpsFromOlsr(olsrMessage, &buffer[0], sizeof(buffer));
        if (unlikely(transmitStringLength == 0)) {
                return false;
        }