]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/lqi/LqiForwardingEngineP.nc
because we changed the type for length in Intercept.forward
[tinyos-2.x.git] / tos / lib / net / lqi / LqiForwardingEngineP.nc
index c52e80b412467859b2155afc82445ace9d04cc04..f1382902e82e613585802ab0d00fac251758def0 100644 (file)
@@ -111,7 +111,8 @@ implementation {
 
   enum {
     FWD_QUEUE_SIZE = MHOP_QUEUE_SIZE, // Forwarding Queue
-    EMPTY = 0xff
+    EMPTY = 0xff,
+    MAX_RETRIES = 5
   };
 
   /* Internal storage and scheduling state */
@@ -120,11 +121,12 @@ implementation {
   uint8_t FwdBufBusy[FWD_QUEUE_SIZE];
   uint8_t iFwdBufHead, iFwdBufTail;
   uint16_t sendFailures = 0;
-  uint8_t fail_count = 0;
+  uint8_t fwd_fail_count = 0;
+  uint8_t my_fail_count = 0;
   int fwdbusy = 0;
   
   lqi_header_t* getHeader(message_t* msg) {
-    return (lqi_header_t*) call SubPacket.getPayload(msg, NULL);
+    return (lqi_header_t*) call SubPacket.getPayload(msg, sizeof(lqi_header_t));
   }
   
   /***********************************************************************
@@ -300,7 +302,7 @@ implementation {
     message_t* nextToSend;
     if (!call PacketAcknowledgements.wasAcked(msg) &&
        call AMPacket.destination(msg) != TOS_BCAST_ADDR &&
-       fail_count < 5){
+       fwd_fail_count < MAX_RETRIES){
       call RouteSelect.selectRoute(msg, 1);
       call PacketAcknowledgements.requestAck(msg);
       if (call SubSend.send(call AMPacket.destination(msg),
@@ -311,7 +313,7 @@ implementation {
                                         call CollectionPacket.getSequenceNumber(msg), 
                                         call CollectionPacket.getOrigin(msg), 
                                          call AMPacket.destination(msg));
-       fail_count ++;
+       fwd_fail_count ++;
        return;
       } else {
        call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL, 
@@ -323,7 +325,7 @@ implementation {
        return;
       }
     }
-    else if (fail_count >= 5) {
+    else if (fwd_fail_count >= MAX_RETRIES) {
       call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL_ACK_FWD, 
                                       call CollectionPacket.getSequenceNumber(msg), 
                                       call CollectionPacket.getOrigin(msg), 
@@ -338,7 +340,7 @@ implementation {
                                       call AMPacket.destination(msg));
     }
     
-    fail_count = 0;
+    fwd_fail_count = 0;
     buf = is_ours(msg);
     if (buf != -1) {
       FwdBufBusy[(uint8_t)buf] = 0;
@@ -357,18 +359,18 @@ implementation {
   event void SubSendMine.sendDone(message_t* msg, error_t success) {
     if (!call PacketAcknowledgements.wasAcked(msg) &&
        call AMPacket.destination(msg) != TOS_BCAST_ADDR &&
-       fail_count < 5){
+       my_fail_count < MAX_RETRIES){
       call RouteSelect.selectRoute(msg, 1);
       call PacketAcknowledgements.requestAck(msg);
       if (call SubSendMine.send(call AMPacket.destination(msg),
                            msg,
                            call SubPacket.payloadLength(msg)) == SUCCESS) {
-       dbg("LQI", "Packet not acked, retransmit (%hhu) @%s:\n\t%s\n", fail_count, sim_time_string(), fields(msg));
+       dbg("LQI", "Packet not acked, retransmit (%hhu) @%s:\n\t%s\n", my_fail_count, sim_time_string(), fields(msg));
        call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_WAITACK, 
                                         call CollectionPacket.getSequenceNumber(msg), 
                                         call CollectionPacket.getOrigin(msg), 
                                          call AMPacket.destination(msg));
-       fail_count ++;
+       my_fail_count ++;
        return;
       } else {
        call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL, 
@@ -380,7 +382,7 @@ implementation {
        return;
       }
     }
-    else if (fail_count >= 5) {
+    else if (my_fail_count >= MAX_RETRIES) {
       call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL_ACK_SEND, 
                                       call CollectionPacket.getSequenceNumber(msg), 
                                       call CollectionPacket.getOrigin(msg), 
@@ -395,7 +397,7 @@ implementation {
                                       call AMPacket.destination(msg));
     }
 
-    fail_count = 0;
+    my_fail_count = 0;
     signal Send.sendDone(msg, success);
   }
 
@@ -435,8 +437,8 @@ implementation {
     
   }
 
-  command void* Send.getPayload(message_t* m) {
-    return call Packet.getPayload(m, NULL);
+  command void* Send.getPayload(message_t* m, uint8_t len) {
+    return call Packet.getPayload(m, len);
   }
 
   command uint8_t Send.maxPayloadLength() {
@@ -448,22 +450,6 @@ implementation {
   }
 
   
-  command void* Receive.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-  
-  command uint8_t Receive.payloadLength[collection_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-
-  command void* Snoop.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-  
-  command uint8_t Snoop.payloadLength[collection_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
   command uint8_t Packet.payloadLength(message_t* msg) {
     return call SubPacket.payloadLength(msg) - sizeof(lqi_header_t);
   }
@@ -473,12 +459,11 @@ implementation {
   command uint8_t Packet.maxPayloadLength() {
     return (call SubPacket.maxPayloadLength() - sizeof(lqi_header_t));
   }
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    void* rval = call SubPacket.getPayload(msg, len);
-    if (len != NULL) {
-      *len -= sizeof(lqi_header_t);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    void* rval = call SubPacket.getPayload(msg, len + sizeof(lqi_header_t));
+    if (rval != NULL) {
+      rval += sizeof(lqi_header_t);
     }
-    rval += sizeof(lqi_header_t);
     return rval;
   }
 
@@ -517,8 +502,28 @@ implementation {
  default event message_t* Receive.receive[collection_id_t id](message_t* pMsg, void* payload, uint8_t len) {
    return pMsg;
  }
- default event bool Intercept.forward[collection_id_t id](message_t* pMsg, void* payload, uint16_t len) {
+ default event bool Intercept.forward[collection_id_t id](message_t* pMsg, void* payload, uint8_t len) {
    return 1;
  }
+
+  /* Default implementations for CollectionDebug calls.
+   * These allow CollectionDebug not to be wired to anything if debugging
+   * is not desired. */
+    
+  default command error_t CollectionDebug.logEvent(uint8_t type) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventSimple(uint8_t type, uint16_t arg) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventDbg(uint8_t type, uint16_t arg1, uint16_t arg2, uint16_t arg3) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventMsg(uint8_t type, uint16_t msg, am_addr_t origin, am_addr_t node) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventRoute(uint8_t type, am_addr_t parent, uint8_t hopcount, uint16_t metric) {
+    return SUCCESS;
+  }
 }