[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.3, 1.4 DrainC.nc, 1.3, 1.4 DrainLinkEstM.nc, 1.3, 1.4 DrainM.nc, 1.3, 1.4

Gilman Tolle gtolle at users.sourceforge.net
Thu Mar 3 19:13:59 PST 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16031

Modified Files:
	Drain.h DrainC.nc DrainLinkEstM.nc DrainM.nc 
Log Message:
Working on a reverse-routing system over the Drain tree...initial success, but still a ways to go before it's really usable.

Index: Drain.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/Drain.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Drain.h	3 Mar 2005 02:04:12 -0000	1.3
--- Drain.h	4 Mar 2005 03:13:56 -0000	1.4
***************
*** 41,44 ****
--- 41,45 ----
    AM_DRAINMSG = 4,
    AM_DRAINBEACONMSG = 7,
+   AM_DRAINREGISTERMSG = 8,
  };
  
***************
*** 47,56 ****
    DRAIN_MAX_RETRANSMITS = 0, // does nothing, for now.
    DRAIN_MAX_MISSED_BEACONS = 5,
    DRAIN_UNKNOWN_ACK_EST = 127,
    DRAIN_MAX_ROUTES = 1,
    DRAIN_MAX_TTL = 16,
-   DRAIN_OP_CREATE = 1,
-   DRAIN_OP_DESTROY = 2,
    DRAIN_INVALID_DEST = 0,
  };
  
--- 48,66 ----
    DRAIN_MAX_RETRANSMITS = 0, // does nothing, for now.
    DRAIN_MAX_MISSED_BEACONS = 5,
+   DRAIN_MAX_BACKOFF = 16,
    DRAIN_UNKNOWN_ACK_EST = 127,
    DRAIN_MAX_ROUTES = 1,
    DRAIN_MAX_TTL = 16,
    DRAIN_INVALID_DEST = 0,
+   DRAIN_MAX_CHILDREN = 4,
+   DRAIN_DIRECTION_UP = 0,
+   DRAIN_DIRECTION_DOWN = 1,
+ };
+ 
+ enum {
+   DRAIN_REGISTER_OP_JOIN = 1,
+   DRAIN_REGISTER_OP_JOINED = 2,
+   DRAIN_REGISTER_OP_FULL = 3,
+   DRAIN_REGISTER_OP_TOOFAR = 4,
  };
  
***************
*** 61,65 ****
  typedef struct DrainMsg {
    uint8_t type;
!   uint8_t ttl;
    uint16_t source;
    uint16_t dest;
--- 71,76 ----
  typedef struct DrainMsg {
    uint8_t type;
!   uint8_t dir:1;
!   uint8_t ttl:7;
    uint16_t source;
    uint16_t dest;
***************
*** 81,84 ****
--- 92,101 ----
  } DrainBeaconMsg;
  
+ typedef struct DrainRegisterMsg {
+   uint16_t linkSource;
+   uint16_t destAddr;
+   uint8_t  op;
+ } DrainRegisterMsg;
+ 
  typedef struct DrainRouteEntry {
    uint16_t dest;
***************
*** 94,97 ****
--- 111,115 ----
    uint8_t  announceDelay;
    uint16_t announceOffset;
+   bool     sentRoute;
  } DrainRouteEntry;
  

Index: DrainC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainC.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DrainC.nc	3 Mar 2005 02:04:13 -0000	1.3
--- DrainC.nc	4 Mar 2005 03:13:56 -0000	1.4
***************
*** 24,27 ****
--- 24,31 ----
      LedsC;
  
+ #ifdef _CC2420CONST_H
+   components CC2420RadioC;
+ #endif
+ 
    StdControl = DrainM.StdControl;
    Receive = DrainM.Receive;
***************
*** 41,44 ****
--- 45,50 ----
    DrainM.LinkReceiveMsg -> GenericComm.ReceiveMsg[AM_DRAINMSG];
  
+   DrainM.Timer -> TimerC.Timer[unique("Timer")];
+ 
    DrainLinkEstM.Timer -> TimerC.Timer[unique("Timer")];
    //  DrainLinkEstM.AgingTimer -> TimerC.Timer[unique("Timer")];  
***************
*** 49,51 ****
--- 55,64 ----
    DrainLinkEstM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_DRAINBEACONMSG];
    DrainLinkEstM.Leds -> LedsC;
+ 
+   DrainLinkEstM.SendRegisterMsg -> GenericComm.SendMsg[AM_DRAINREGISTERMSG];
+   DrainLinkEstM.ReceiveRegisterMsg -> GenericComm.ReceiveMsg[AM_DRAINREGISTERMSG];
+ 
+ #ifdef _CC2420CONST_H
+   DrainM.MacControl -> CC2420RadioC;
+ #endif
  }

Index: DrainLinkEstM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEstM.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DrainLinkEstM.nc	3 Mar 2005 02:04:13 -0000	1.3
--- DrainLinkEstM.nc	4 Mar 2005 03:13:56 -0000	1.4
***************
*** 42,45 ****
--- 42,48 ----
      interface Attr<uint16_t> as DrainNextHopCost @nucleusAttr();
      interface Attr<uint16_t> as DrainNextHopLinkEst @nucleusAttr();
+     interface AttrList<uint16_t> as DrainChildren @nucleusAttr();
+     interface Attr<uint8_t> as DrainChildrenCount @nucleusAttr();
+     interface Attr<uint16_t> as DrainMyAddr @nucleusAttr();
    }
  
***************
*** 52,55 ****
--- 55,62 ----
      interface SendMsg;
      interface ReceiveMsg;
+ 
+     interface SendMsg as SendRegisterMsg;
+     interface ReceiveMsg as ReceiveRegisterMsg;
+ 
      interface Leds;
    }
***************
*** 60,63 ****
--- 67,74 ----
    DrainRouteEntry routes[DRAIN_MAX_ROUTES];
  
+   uint16_t myAddr;
+   uint16_t children[DRAIN_MAX_CHILDREN];
+   uint8_t  childrenToNotify;
+ 
    bool msgBufBusy;
    TOS_Msg msgBuf;
***************
*** 65,68 ****
--- 76,82 ----
  #define MAX(a_,b_) (a_ > b_ ? a_ : b_)
  #define MIN(a_,b_) (a_ < b_ ? a_ : b_)
+ #define BIT_GET(x, i) ((x) & (1 << (i)))
+ #define BIT_SET(x, i) ((x) | (1 << (i)))
+ #define BIT_CLEAR(x, i) ((x) & ~(1 << (i)))
  
    uint16_t adjustLQI(uint8_t val);
***************
*** 72,75 ****
--- 86,91 ----
  
    task void SendRouteTask();
+   task void SendRegisterTask();
+   task void NotifyChildrenTask();
  
    command result_t StdControl.init() {
***************
*** 123,126 ****
--- 139,150 ----
    }
  
+   void clearChildren() {
+     uint8_t i;
+     myAddr = 0;
+     for(i = 0; i < DRAIN_MAX_CHILDREN; i++) {
+       children[i] = 0;
+     }
+   }
+ 
    command result_t StdControl.start() {
  #ifdef PLATFORM_PC
***************
*** 140,144 ****
        route->announceDelay = 4;
        
!       call Timer.start(TIMER_REPEAT, 16384);
      }
  #endif
--- 164,168 ----
        route->announceDelay = 4;
        
!       call Timer.start(TIMER_ONE_SHOT, 16384);
      }
  #endif
***************
*** 159,165 ****
  
      pMHMsg->type = id;
      pMHMsg->ttl = DRAIN_MAX_TTL - 1;
      pMHMsg->source = TOS_LOCAL_ADDRESS;
! 
      if (dest == TOS_DEFAULT_ADDR) {
        pMHMsg->dest = routes[0].dest;
--- 183,190 ----
  
      pMHMsg->type = id;
+     pMHMsg->dir = DRAIN_DIRECTION_UP;
      pMHMsg->ttl = DRAIN_MAX_TTL - 1;
      pMHMsg->source = TOS_LOCAL_ADDRESS;
!     
      if (dest == TOS_DEFAULT_ADDR) {
        pMHMsg->dest = routes[0].dest;
***************
*** 190,207 ****
      DrainMsg* pMHMsg = (DrainMsg *)&Msg->data[0];
      DrainRouteEntry* route;
-     
-     if (pMHMsg->dest == TOS_BCAST_ADDR) {
-       Msg->addr = TOS_BCAST_ADDR;
- 
-     } else {
  
!       route = getRoute(pMHMsg->dest);
  
!       if (route != NULL) {
! 	Msg->addr = route->nextHop;
!       } else {
  	Msg->addr = TOS_BCAST_ADDR;
        }
        
      }
  
--- 215,243 ----
      DrainMsg* pMHMsg = (DrainMsg *)&Msg->data[0];
      DrainRouteEntry* route;
  
!     if (pMHMsg->dir == DRAIN_DIRECTION_UP) {
  
!       if (pMHMsg->dest == TOS_BCAST_ADDR) {
! 	
  	Msg->addr = TOS_BCAST_ADDR;
+ 	
+       } else {
+ 	
+ 	route = getRoute(pMHMsg->dest);
+ 	
+ 	if (route != NULL) {
+ 	  Msg->addr = route->nextHop;
+ 	} else {
+ 	  Msg->addr = TOS_BCAST_ADDR;
+ 	}
        }
+ 
+     } else {
+       
+       uint8_t pos = pMHMsg->dest & 0x3; // Assumes 2 bits per hop
+       uint16_t dest = children[pos];
        
+       Msg->addr = dest;
+       pMHMsg->dest = pMHMsg->dest >> 2;
      }
  
***************
*** 218,222 ****
      uint16_t linkEst = 0;
  
! #if defined(CC2420_DEF_CHANNEL)
      linkEst = adjustLQI(Msg->lqi);
  #elif defined(PLATFORM_PC)
--- 254,258 ----
      uint16_t linkEst = 0;
  
! #if defined(_CC2420CONST_H)
      linkEst = adjustLQI(Msg->lqi);
  #elif defined(PLATFORM_PC)
***************
*** 232,235 ****
--- 268,272 ----
      if (route == NULL) {
        route = newRoute(pRP->source);
+       clearChildren();
      }
  
***************
*** 257,279 ****
        }
  
-       /*      
-       if (pRP->beaconPeriod != route->announcePeriod) {
- 	
- 	route->announcePeriod = pRP->beaconPeriod;
- 	
- 	call AgingTimer.stop();
- 	
- 	if (route->announcePeriod > 0) {
- 	  call AgingTimer.start(TIMER_ONE_SHOT,
- 				1024 * route->announcePeriod);
- 	}
-       }
-       */
-       
        route->announceDelay = pRP->beaconDelay;
        route->announceOffset = 
  	(call Random.rand() % 
  	 (1024 * route->announceDelay)) + 1;
!       
        call Timer.start(TIMER_ONE_SHOT, 
  		       pRP->beaconOffset + route->announceOffset);
--- 294,303 ----
        }
  
        route->announceDelay = pRP->beaconDelay;
        route->announceOffset = 
  	(call Random.rand() % 
  	 (1024 * route->announceDelay)) + 1;
! 
!       route->sentRoute = FALSE;
        call Timer.start(TIMER_ONE_SHOT, 
  		       pRP->beaconOffset + route->announceOffset);
***************
*** 284,291 ****
  #endif
  
!     if (route == NULL || 
! 	pRP->treeInstance != route->treeInstance ||
  	pRP->linkSource == route->nextHop) {
! 
        /* 
  	 if no route exists, 
--- 308,314 ----
  #endif
  
!     if (pRP->treeInstance != route->treeInstance ||
  	pRP->linkSource == route->nextHop) {
!       
        /* 
  	 if no route exists, 
***************
*** 305,309 ****
  
        //      route->announceMissed = 0;
!       
      } else {
        
--- 328,334 ----
  
        //      route->announceMissed = 0;
! 
!       clearChildren();
! 
      } else {
        
***************
*** 326,331 ****
  	  route->nextHopLinkEst = linkEst;
  	  route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
- 	}
  
      }
  
--- 351,357 ----
  	  route->nextHopLinkEst = linkEst;
  	  route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
  
+ 	  clearChildren();
+ 	}
      }
  
***************
*** 340,344 ****
  
    event result_t Timer.fired() {
!     post SendRouteTask();
      return SUCCESS;
    }
--- 366,382 ----
  
    event result_t Timer.fired() {
!     DrainRouteEntry *route = &routes[0];
!     
!     if (route->sentRoute == FALSE) {
!       route->sentRoute = TRUE;
!       post SendRouteTask();
!       call Timer.start(TIMER_ONE_SHOT, 1024 * 2 * route->announceDelay);
!     } else {
! #ifdef PLATFORM_PC
!       if (TOS_LOCAL_ADDRESS != 0)
! #endif
! 	post SendRegisterTask();
!     }
! 
      return SUCCESS;
    }
***************
*** 377,381 ****
      pRP->beaconOffset = (route->announceDelay * 1024) - route->announceOffset;
      
!     if (call SendMsg.send(TOS_BCAST_ADDR, 12, pMsgBuf)) {
        dbg(DBG_ROUTE,"send DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d)\n",
  	  pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
--- 415,419 ----
      pRP->beaconOffset = (route->announceDelay * 1024) - route->announceOffset;
      
!     if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(DrainBeaconMsg), pMsgBuf)) {
        dbg(DBG_ROUTE,"send DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d)\n",
  	  pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
***************
*** 391,421 ****
    }
  
! #if 0
!   event result_t AgingTimer.fired() {
  
      DrainRouteEntry *route = &routes[0];
      
!     if (successCounter + failCounter > 0) {
!       currentParentAckEst = (255 - (255 * successCounter) / (successCounter + failCounter));
!       successCounter = failCounter = 0;
      }
  
!     if (route->announceMissed > DRAIN_MAX_MISSED_BEACONS) {
!       if (route->nextHopLinkEst << 1 < 0xffff) {
! 	route->nextHopLinkEst <<= 1;
!       } else {
! 	clearRoute(route);
        }
      }
  
!     if (route->announceMissed < 0xff) {
!       route->announceMissed++;
      }
      
!     call AgingTimer.start(TIMER_ONE_SHOT, (1024 * route->announcePeriod));
  
!     return SUCCESS;
!   }
  #endif
  
    command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg, uint8_t id, 
--- 429,556 ----
    }
  
!   task void SendRegisterTask() {
  
+     TOS_MsgPtr pMsgBuf = &msgBuf;
+     DrainRegisterMsg *pRM = (DrainRegisterMsg *)&pMsgBuf->data[0];
      DrainRouteEntry *route = &routes[0];
      
!     dbg(DBG_ROUTE,"DrainLinkEstM: Sending Registration Msg\n");
!     
!     if (msgBufBusy) {
! #ifndef PLATFORM_PC
!       post SendRouteTask();
! #endif
!       return;
      }
  
!     atomic msgBufBusy = TRUE;
! 
!     pRM->linkSource = TOS_LOCAL_ADDRESS;
!     pRM->destAddr = 0;
!     pRM->op = DRAIN_REGISTER_OP_JOIN;
! 
!     if (call SendRegisterMsg.send(route->nextHop, sizeof(DrainRegisterMsg), pMsgBuf)) {
!       dbg(DBG_ROUTE,"to %d, send DrainRegisterMsg(linkSource=%d,destAddr=%d,op=%d)\n",
! 	  route->nextHop, pRM->linkSource, pRM->destAddr, pRM->op);
!     } else {
!       dbg(DBG_ROUTE, "send DrainRegisterMsg FAILED\n");
! #ifndef PLATFORM_PC
!       post SendRegisterTask();
! #else
!       atomic msgBufBusy = FALSE;
! #endif
!     }
!   }
! 
!   event TOS_MsgPtr ReceiveRegisterMsg.receive(TOS_MsgPtr Msg) {
! 
!     DrainRegisterMsg *pRM = (DrainRegisterMsg *)&Msg->data[0];
!     uint8_t i;
!     DrainRouteEntry *route = &routes[0];
! 
!     dbg(DBG_ROUTE,"receive DrainRegisterMsg(linkSource=%d,destAddr=%d,op=%d)\n",
! 	pRM->linkSource, pRM->destAddr, pRM->op);
! 
!     if (pRM->op == DRAIN_REGISTER_OP_JOIN) {
! 
!       for(i = 1; i < DRAIN_MAX_CHILDREN; i++) {
! 	if (children[i] == DRAIN_INVALID_DEST) {
! 	  children[i] = pRM->linkSource;
! 	  childrenToNotify = BIT_SET(childrenToNotify, i);
! 	  dbg(DBG_ROUTE, "new child: index=%d, address=%d\n",
! 	      i, children[i]);
! 	  break;
! 	}
!       }
! 
!     } else if (pRM->op == DRAIN_REGISTER_OP_JOINED) {
!       if (pRM->linkSource == route->nextHop) {
! 	myAddr = pRM->destAddr;
        }
      }
  
!     post NotifyChildrenTask();
! 
!     return Msg;
!   }
! 
!   task void NotifyChildrenTask() {
! 
!     TOS_MsgPtr pMsgBuf = &msgBuf;
!     DrainRegisterMsg *pRM = (DrainRegisterMsg *)&pMsgBuf->data[0];
!     uint8_t i;
! 
!     dbg(DBG_ROUTE,"DrainLinkEstM: Sending Registration Msg\n");
!     
!     if (myAddr == 0) {
!       return;
!     }
! 
!     if (childrenToNotify == 0) {
!       return;
      }
      
!     if (msgBufBusy) {
! #ifndef PLATFORM_PC
!       post NotifyChildrenTask();
! #endif
!       return;
!     }
!     
!     atomic msgBufBusy = TRUE;
  
!     for(i = 0; i < DRAIN_MAX_CHILDREN; i++) {
! 
!       if (BIT_GET(childrenToNotify, i)) {
! 
! 	pRM->linkSource = TOS_LOCAL_ADDRESS;
! 	pRM->destAddr = (myAddr << 2) + i; //assumes 2 bits per hop
! 	pRM->op = DRAIN_REGISTER_OP_JOINED;
! 
! 	if (call SendRegisterMsg.send(children[i], 
! 				      sizeof(DrainRegisterMsg), 
! 				      pMsgBuf)) {
! 	  
! 	  dbg(DBG_ROUTE,"to %d, send DrainRegisterMsg(linkSource=%d,destAddr=%d,op=%d)\n",
! 	      children[i], pRM->linkSource, pRM->destAddr, pRM->op);
! 	  
! 	  childrenToNotify = BIT_CLEAR(childrenToNotify, i);
! 	  break;
! 	  
! 	} else {
! 	  
! 	  dbg(DBG_ROUTE, "send DrainRegisterMsg FAILED\n");
! 	  
! #ifndef PLATFORM_PC
! 	  post NotifyChildrenTask();
! #else
! 	  atomic msgBufBusy = FALSE;
  #endif
+ 	}
+       }
+     }
+ 
+     return;
+   }
  
    command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg, uint8_t id, 
***************
*** 440,443 ****
--- 575,586 ----
    }
  
+   event result_t SendRegisterMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
+     if (pMsg == &msgBuf) {
+       atomic msgBufBusy = FALSE;
+       post NotifyChildrenTask();
+     }
+     return SUCCESS;
+   }
+ 
    command result_t DrainNextHop.get(uint16_t* buf) {
      memcpy(buf, &routes[0].nextHop, sizeof(uint16_t));
***************
*** 457,460 ****
--- 600,627 ----
      return SUCCESS;
    }
+ 
+   command result_t DrainChildren.get(uint16_t* buf, uint8_t pos) {
+     memcpy(buf, &children[pos], sizeof(uint16_t));
+     signal DrainChildren.getDone(buf);
+     return SUCCESS;
+   }
+ 
+   command result_t DrainChildrenCount.get(uint8_t* buf) {
+     uint8_t i;
+     uint8_t count = 0;
+     for (i = 0; i < DRAIN_MAX_CHILDREN; i++) {
+       if (children[i] != 0)
+ 	count++;
+     }
+     memcpy(buf, &count, sizeof(uint8_t));
+     signal DrainChildrenCount.getDone(buf);
+     return SUCCESS;
+   }
+ 
+   command result_t DrainMyAddr.get(uint16_t* buf) {
+     memcpy(buf, &myAddr, sizeof(uint16_t));
+     signal DrainMyAddr.getDone(buf);
+     return SUCCESS;
+   }
  }
  

Index: DrainM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainM.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DrainM.nc	3 Mar 2005 02:04:13 -0000	1.3
--- DrainM.nc	4 Mar 2005 03:13:56 -0000	1.4
***************
*** 52,55 ****
--- 52,61 ----
  
      interface DrainLinkEst;
+ 
+     interface Timer;
+ 
+ #ifdef _CC2420CONST_H
+     interface MacControl;
+ #endif
    }
  }
***************
*** 75,87 ****
    bool queuesBusy;
  
!   uint8_t maxRetransmits;
!   uint8_t currentFailCount;
  
!   uint8_t sendDrops;
!   uint8_t forwardDrops;
  
    uint16_t sendPackets;
    uint16_t forwardPackets;
  
    task void QueueServiceTask();
  
--- 81,97 ----
    bool queuesBusy;
  
!   uint8_t backoff;
  
!   // STATISTICS
  
    uint16_t sendPackets;
    uint16_t forwardPackets;
  
+   uint16_t ackedPackets;
+   uint16_t unackedPackets;
+ 
+   uint8_t sendDrops;
+   uint8_t forwardDrops;
+ 
    task void QueueServiceTask();
  
***************
*** 102,107 ****
    command result_t StdControl.init() {
      initializeBufs();
!     maxRetransmits = DRAIN_MAX_RETRANSMITS;
!     currentFailCount = 0;
      return call SubControl.init();
    }
--- 112,116 ----
    command result_t StdControl.init() {
      initializeBufs();
!     backoff = 0;
      return call SubControl.init();
    }
***************
*** 124,127 ****
--- 133,139 ----
  
    command result_t StdControl.start() {
+ #ifdef _CC2420CONST_H
+     call MacControl.enableAck();
+ #endif
      return call SubControl.start();
    }
***************
*** 226,229 ****
--- 238,246 ----
  					  payloadLen)) == SUCCESS) {
  
+ 	if (pMHMsg->dest == 0) {
+ 	  call Leds.yellowToggle();
+ 	  return signal Receive.receive[id](pMsg, &pMHMsg->data[0], payloadLen);
+ 	}
+ 
  	dbg(DBG_ROUTE, "Drain: forward(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
  	    pMHMsg->source, pMHMsg->dest);
***************
*** 234,238 ****
  	  return pMsg;
  	}
! 
  	if (call DrainLinkEst.forwardFields(pMsg)) {
  	  pMsg = enqueueForward(pMsg);
--- 251,255 ----
  	  return pMsg;
  	}
! 	
  	if (call DrainLinkEst.forwardFields(pMsg)) {
  	  pMsg = enqueueForward(pMsg);
***************
*** 317,320 ****
--- 334,342 ----
    }
  
+   event result_t Timer.fired() {
+     post QueueServiceTask();
+     return SUCCESS;
+   }
+ 
    event result_t LinkSendMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
  
***************
*** 336,345 ****
      }
  
      if (pMsg->addr == TOS_BCAST_ADDR) {
-       // It didn't have a destination. Don't try retransmitting.
  
!     } else if (maxRetransmits == 0) {
  
!       // We don't care if it got there. Don't try retransmitting.
  
      } else {
--- 358,379 ----
      }
  
+     if (pMsg->ack == 1) {
+       ackedPackets++;
+     } else {
+       unackedPackets++;
+     }
+ 
      if (pMsg->addr == TOS_BCAST_ADDR) {
  
!       // It didn't have a destination.
  
! #ifndef DRAIN_BASE_ACKS
! 
!     } else if (mhMsg->dest == pMsg->addr) {
!       
!       // It's for the destination. This might be a TOSBase. TOSBase
!       // does not currently do acks. This ugliness will go away.
!       
! #endif
  
      } else {
***************
*** 351,370 ****
  	// It wasn't acked.
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, FAIL);
- 	currentFailCount++;
- 
- 	if (currentFailCount < maxRetransmits) {
- 
- 	  post QueueServiceTask();
- 	  return SUCCESS;
- 	  
- 	} else {
  
! 	  // We've tried to retransmit too many times. Give up.
! 	  forwardResultVal = FAIL;
  	}
  
        } else {
  	
  	// It was acked.
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, SUCCESS);
        }
--- 385,403 ----
  	// It wasn't acked.
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, FAIL);
  
! 	if (backoff < DRAIN_MAX_BACKOFF) {
! 	  backoff++;
  	}
  
+ 	call Timer.start(TIMER_ONE_SHOT, 1 << backoff);
+ 
+ 	return SUCCESS;
+ 	
        } else {
  	
  	// It was acked.
+ 
+ 	backoff = 0;
+ 
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, SUCCESS);
        }
***************
*** 383,387 ****
        if (sendQueueFull)
  	sendQueueFull = FALSE;
-       currentFailCount = 0;
        post QueueServiceTask();
  
--- 416,419 ----
***************
*** 393,397 ****
        if (fwdQueueFull)
  	fwdQueueFull = FALSE;
-       currentFailCount = 0;
        post QueueServiceTask();
  
--- 425,428 ----
***************
*** 425,428 ****
--- 456,465 ----
      return SUCCESS;
    }
+ 
+   default event TOS_MsgPtr Receive.receive[uint8_t id](TOS_MsgPtr pMsg, 
+ 						       void* payload, 
+ 						       uint16_t payloadLen) {
+     return pMsg;
+   }
  }
  



More information about the Tinyos-beta-commits mailing list