]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/le/LinkEstimatorP.nc
fix the get link quality interfaces to return 16 bit eetx values
[tinyos-2.x.git] / tos / lib / net / le / LinkEstimatorP.nc
index ebfa4430fa6741a593fbbcbeafce36b732fd75e3..6e60234718041637b0b74db212d7e1dd1a8c175f 100644 (file)
@@ -91,12 +91,13 @@ implementation {
 
   // get the link estimation header in the packet
   linkest_header_t* getHeader(message_t* m) {
-    return (linkest_header_t*)call SubPacket.getPayload(m, NULL);
+    return (linkest_header_t*)call SubPacket.getPayload(m, sizeof(linkest_header_t));
   }
 
   // get the link estimation footer (neighbor entries) in the packet
   linkest_footer_t* getFooter(message_t* m, uint8_t len) {
-    return (linkest_footer_t*)(len + (uint8_t *)call Packet.getPayload(m,NULL));
+    // To get a footer at offset "len", the payload must be len + sizeof large.
+    return (linkest_footer_t*)(len + (uint8_t *)call Packet.getPayload(m,len + sizeof(linkest_footer_t)));
   }
 
   // add the link estimation header (seq no) and link estimation
@@ -429,7 +430,7 @@ implementation {
   }
 
   // return bi-directional link quality to the neighbor
-  command uint8_t LinkEstimator.getLinkQuality(am_addr_t neighbor) {
+  command uint16_t LinkEstimator.getLinkQuality(am_addr_t neighbor) {
     uint8_t idx;
     idx = findIdx(neighbor);
     if (idx == INVALID_RVAL) {
@@ -440,7 +441,7 @@ implementation {
   }
 
   // return the quality of the link: neighor->self
-  command uint8_t LinkEstimator.getReverseQuality(am_addr_t neighbor) {
+  command uint16_t LinkEstimator.getReverseQuality(am_addr_t neighbor) {
     uint8_t idx;
     idx = findIdx(neighbor);
     if (idx == INVALID_RVAL) {
@@ -451,7 +452,7 @@ implementation {
   }
 
   // return the quality of the link: self->neighbor
-  command uint8_t LinkEstimator.getForwardQuality(am_addr_t neighbor) {
+  command uint16_t LinkEstimator.getForwardQuality(am_addr_t neighbor) {
     uint8_t idx;
     idx = findIdx(neighbor);
     if (idx == INVALID_RVAL) {
@@ -585,8 +586,8 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* Send.getPayload(message_t* msg) {
-    return call Packet.getPayload(msg, NULL);
+  command void* Send.getPayload(message_t* msg, uint8_t len) {
+    return call Packet.getPayload(msg, len);
   }
 
   // called when link estimator generator packet or
@@ -648,13 +649,30 @@ implementation {
        }
       }
 
+
+      /* Graphical explanation of how we get to the head of the
+       * footer in the following code 
+       * <---------------------- payloadLen ------------------->
+       * -------------------------------------------------------
+       * linkest_header_t  | payload  | linkest_footer_t* ...|
+       * -------------------------------------------------------
+       * ^                              ^                      ^
+       * |                              |                      |
+       * subpayload                     |                      payloadEnd
+       *                                |
+       *                                payloadEnd - footersize*num footers
+      */
+
       if ((nidx != INVALID_RVAL) && (num_entries > 0)) {
+       uint8_t payloadLen = call SubPacket.payloadLength(msg);
+       void* subPayload = call SubPacket.getPayload(msg, payloadLen);
+       void* payloadEnd = subPayload + payloadLen;
        dbg("LI", "Number of footer entries: %d\n", num_entries);
-       footer = (linkest_footer_t*) ((uint8_t *)call SubPacket.getPayload(msg, NULL)
-                                     + call SubPacket.payloadLength(msg)
-                                     - num_entries*sizeof(linkest_footer_t));
+       
+       footer = (linkest_footer_t*) (payloadEnd - (num_entries*sizeof(linkest_footer_t)));
        {
-         uint8_t i, my_ll_addr;
+         uint8_t i;
+         am_addr_t my_ll_addr;
          my_ll_addr = call SubAMPacket.address();
          for (i = 0; i < num_entries; i++) {
            dbg("LI", "%d %d %d\n", i, footer->neighborList[i].ll_addr,
@@ -681,18 +699,10 @@ implementation {
     dbg("LI", "Received upper packet. Will signal up\n");
     processReceivedMessage(msg, payload, len);
     return signal Receive.receive(msg,
-                                 call Packet.getPayload(msg, NULL),
+                                 call Packet.getPayload(msg, call Packet.payloadLength(msg)),
                                  call Packet.payloadLength(msg));
   }
 
-  command void* Receive.getPayload(message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-
-  command uint8_t Receive.payloadLength(message_t* msg) {
-    return call Packet.payloadLength(msg);
-  }
-
   command void Packet.clear(message_t* msg) {
     call SubPacket.clear(msg);
   }
@@ -723,14 +733,13 @@ implementation {
   }
 
   // application payload pointer is just past the link estimation header
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    uint8_t* payload = call SubPacket.getPayload(msg, len);
-    linkest_header_t *hdr;
-    hdr = getHeader(msg);
-    if (len != NULL) {
-      *len = *len - sizeof(linkest_header_t) - sizeof(linkest_footer_t)*(NUM_ENTRIES_FLAG & hdr->flags);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    linkest_header_t *hdr = getHeader(msg);
+    void* payload = call SubPacket.getPayload(msg, len +  sizeof(linkest_header_t));
+    if (payload != NULL) {
+      payload += sizeof(linkest_header_t);
     }
-    return payload + sizeof(linkest_header_t);
+    return payload;
   }
 }