[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain DrainLinkEstM.nc, 1.22, 1.23

Gilman Tolle gtolle at users.sourceforge.net
Fri Aug 26 13:44:32 PDT 2005


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

Modified Files:
	DrainLinkEstM.nc 
Log Message:
Reordered Drain code for easier readability. Added selectable period to DrainTest. Made Drain able to repeatedly build with a specified period.

Index: DrainLinkEstM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEstM.nc,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** DrainLinkEstM.nc	18 Aug 2005 22:27:41 -0000	1.22
--- DrainLinkEstM.nc	26 Aug 2005 20:44:30 -0000	1.23
***************
*** 194,197 ****
--- 194,241 ----
    }
  
+   DrainRouteEntry* getRoute(uint16_t dest) {
+     DrainRouteEntry* route;
+     uint8_t i;
+ 
+     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
+       route = &routes[i];
+       if (route->dest != DRAIN_INVALID_DEST && route->dest == dest) {
+ 	return route;
+       }
+     }
+     return NULL;
+   }
+ 
+   DrainRouteEntry* getDefaultRoute(uint16_t dest) {
+     DrainRouteEntry* route;
+     uint8_t i;
+ 
+     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
+       route = &routes[i];
+       if (route->dest != DRAIN_INVALID_DEST &&
+ 	  route->defaultRoute == TRUE) {
+ 	return route;
+       }
+     }
+     return NULL;
+   }
+ 
+   bool isGroup(uint16_t dest) {
+     return (dest >= 0xFE00 && dest <= 0xFEFF);
+   }
+ 
+   command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg,
+ 					    result_t success) {
+     
+     DrainMsg* drainMsg = (DrainMsg*) &msg->data[0];
+     DrainRouteEntry* route = getRoute(drainMsg->dest);
+     
+     route->sentPackets++;
+     if (success) {
+       route->successPackets++;
+     }
+     return SUCCESS;
+   }
+ 
    command bool DrainLinkEst.isRoot() {
      return (getRoute(TOS_LOCAL_ADDRESS) != NULL);
***************
*** 233,303 ****
    }
  
-   event result_t Timer.fired() {
-     DrainRouteEntry *route;
- 
-     timerRunning = FALSE;
- 
-     route = getReadyRoute();
-     if (route != NULL) {
-       sendRoute(route);
-     }
- 
-     startTimer();
- 
-     return SUCCESS;
-   }
- 
-   void sendRoute(DrainRouteEntry* route) {
- 
-     TOS_MsgPtr pMsgBuf = &msgBuf;
-     DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
- 
- #ifdef DRAIN_ENDPOINT_ONLY
-     return;
- #endif
- 
-     dbg(DBG_ROUTE, "DrainLinkEstM: sending route update\n");
- 
-     if (route->dest == DRAIN_INVALID_DEST ||
- 	route->destDistance == DRAIN_MAX_TTL) {
-       dbg(DBG_ROUTE, "DrainLinkEstM: couldn't send route (dest=%d, destDistance=%d)\n", 
- 	  route->dest, route->destDistance);
-       route->sendWaiting = FALSE;
-       return;
-     }
- 
-     if (msgBufBusy) {
-       return;
-     }
-     
-     atomic msgBufBusy = TRUE;
-     
-     pRP->linkSource = TOS_LOCAL_ADDRESS;
-     
-     pRP->source = route->dest;
-     pRP->parent = route->nextHop;
-     pRP->cost = route->nextHopCost + route->nextHopLinkEst;
-     pRP->ttl = DRAIN_MAX_TTL - route->destDistance - 1;
-     pRP->treeInstance = route->treeInstance;
-     pRP->beaconSeqno = route->announceSeqno;
-     pRP->beaconDelay = route->announceDelay;
-     pRP->beaconOffset = (route->announceDelay * 1024) - route->announceOffset;
-     pRP->defaultRoute = route->defaultRoute;
- 
-     if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(DrainBeaconMsg), pMsgBuf)) {
- 
-       dbg(DBG_ROUTE,"DrainLinkEstM: 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,
- 	  pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance);
- 
-       route->sendWaiting = FALSE;
- 
-     } else {
-       dbg(DBG_ROUTE, "send DrainBeaconMsg FAILED\n");
-       // how to handle the retries if the radio is busy?
-       atomic msgBufBusy = FALSE;
-     }
-   }
-   
    event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr Msg) {
  
--- 277,280 ----
***************
*** 451,489 ****
    }
  
!   command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg,
! 					    result_t success) {
!     
!     DrainMsg* drainMsg = (DrainMsg*) &msg->data[0];
!     DrainRouteEntry* route = getRoute(drainMsg->dest);
!     
!     route->sentPackets++;
!     if (success) {
!       route->successPackets++;
      }
-     return SUCCESS;
    }
  
!   event result_t SendMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
!     if (pMsg == &msgBuf) {
!       atomic msgBufBusy = FALSE;
      }
      return SUCCESS;
    }
  
!   void clearRoute(DrainRouteEntry* route) {
  
!     route->dest = DRAIN_INVALID_DEST;
!     route->nextHop = TOS_BCAST_ADDR;
      
!     route->nextHopCost = 0xFFFF;
!     route->nextHopLinkEst = 0xFFFF;
      
!     route->destDistance = 0;
!     route->treeInstance = 0;
  
!     route->announceSeqno = 1;
!     route->announceDelay = 0;
  
!     route->defaultRoute = 0;
    }
  
--- 428,563 ----
    }
  
!   void startTimer() {
!     DrainRouteEntry* route;
!     uint16_t minCountdown = 0xFFFF;
!     uint8_t i;
! 
!     if (timerRunning) {
!       dbg(DBG_ROUTE, "startTimer() - timer running. Returning.\n");
!       return;
!     }
! 
!     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
!       route = &routes[i];
! 
!       dbg(DBG_ROUTE, "route[%d] 0x%x - dest=%d, sendWaiting=%d\n", i, route, route->dest, route->sendWaiting);
! 
!       if (route->dest != DRAIN_INVALID_DEST &&
! 	  route->sendWaiting == TRUE) {
! 
! 	dbg(DBG_ROUTE, "route[%d] fires in %d ms\n", i, route->announceCountdown);
! 	if (route->announceCountdown < minCountdown) {
! 	  minCountdown = route->announceCountdown;
! 	}
!       }
!     }
! 
!     if (minCountdown < 0xFFFF) {
! 
!       timerRunning = TRUE;
!       
!       for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
! 	route = &routes[i];
! 	if (route->dest != DRAIN_INVALID_DEST &&
! 	    route->sendWaiting == TRUE) {
! 	  route->announceCountdown -= minCountdown;
! 	}
!       }
!       
!       if (minCountdown == 0) {
! 	minCountdown = 5;
!       }
! 
!       call Timer.start(TIMER_ONE_SHOT, minCountdown);
      }
    }
  
!   event result_t Timer.fired() {
!     DrainRouteEntry *route;
! 
!     timerRunning = FALSE;
! 
!     route = getReadyRoute();
!     if (route != NULL) {
!       sendRoute(route);
      }
+ 
+     startTimer();
+ 
      return SUCCESS;
    }
  
!   DrainRouteEntry* getReadyRoute() {
!     DrainRouteEntry* route;
!     uint8_t i;
  
!     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
!       route = &routes[i];
!       if (route->dest != DRAIN_INVALID_DEST && 
! 	  route->sendWaiting == TRUE &&
! 	  route->announceCountdown == 0) {
! 	return route;
!       }
!     }
!     return NULL;
!   }
! 
!   void sendRoute(DrainRouteEntry* route) {
! 
!     TOS_MsgPtr pMsgBuf = &msgBuf;
!     DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
! 
! #ifdef DRAIN_ENDPOINT_ONLY
!     return;
! #endif
! 
!     dbg(DBG_ROUTE, "DrainLinkEstM: sending route update\n");
! 
!     if (route->dest == DRAIN_INVALID_DEST ||
! 	route->destDistance == DRAIN_MAX_TTL) {
!       dbg(DBG_ROUTE, "DrainLinkEstM: couldn't send route (dest=%d, destDistance=%d)\n", 
! 	  route->dest, route->destDistance);
!       route->sendWaiting = FALSE;
!       return;
!     }
! 
!     if (msgBufBusy) {
!       return;
!     }
      
!     atomic msgBufBusy = TRUE;
      
!     pRP->linkSource = TOS_LOCAL_ADDRESS;
!     
!     pRP->source = route->dest;
!     pRP->parent = route->nextHop;
!     pRP->cost = route->nextHopCost + route->nextHopLinkEst;
!     pRP->ttl = DRAIN_MAX_TTL - route->destDistance - 1;
!     pRP->treeInstance = route->treeInstance;
!     pRP->beaconSeqno = route->announceSeqno;
!     pRP->beaconDelay = route->announceDelay;
!     pRP->beaconOffset = (route->announceDelay * 1024) - route->announceOffset;
!     pRP->defaultRoute = route->defaultRoute;
  
!     if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(DrainBeaconMsg), pMsgBuf)) {
  
!       dbg(DBG_ROUTE,"DrainLinkEstM: 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,
! 	  pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance);
! 
!       route->sendWaiting = FALSE;
! 
!     } else {
!       dbg(DBG_ROUTE, "send DrainBeaconMsg FAILED\n");
!       // how to handle the retries if the radio is busy?
!       atomic msgBufBusy = FALSE;
!     }
!   }
!   
!   event result_t SendMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
!     if (pMsg == &msgBuf) {
!       atomic msgBufBusy = FALSE;
!     }
!     return SUCCESS;
    }
  
***************
*** 539,631 ****
    }
  
!   DrainRouteEntry* getRoute(uint16_t dest) {
!     DrainRouteEntry* route;
!     uint8_t i;
! 
!     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
!       route = &routes[i];
!       if (route->dest != DRAIN_INVALID_DEST && route->dest == dest) {
! 	return route;
!       }
!     }
!     return NULL;
!   }
! 
!   DrainRouteEntry* getDefaultRoute(uint16_t dest) {
!     DrainRouteEntry* route;
!     uint8_t i;
! 
!     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
!       route = &routes[i];
!       if (route->dest != DRAIN_INVALID_DEST &&
! 	  route->defaultRoute == TRUE) {
! 	return route;
!       }
!     }
!     return NULL;
!   }
! 
!   DrainRouteEntry* getReadyRoute() {
!     DrainRouteEntry* route;
!     uint8_t i;
! 
!     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
!       route = &routes[i];
!       if (route->dest != DRAIN_INVALID_DEST && 
! 	  route->sendWaiting == TRUE &&
! 	  route->announceCountdown == 0) {
! 	return route;
!       }
!     }
!     return NULL;
!   }
! 
!   bool isGroup(uint16_t dest) {
!     return (dest >= 0xFE00 && dest <= 0xFEFF);
!   }
! 
!   void startTimer() {
!     DrainRouteEntry* route;
!     uint16_t minCountdown = 0xFFFF;
!     uint8_t i;
! 
!     if (timerRunning) {
!       dbg(DBG_ROUTE, "startTimer() - timer running. Returning.\n");
!       return;
!     }
! 
!     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
!       route = &routes[i];
! 
!       dbg(DBG_ROUTE, "route[%d] 0x%x - dest=%d, sendWaiting=%d\n", i, route, route->dest, route->sendWaiting);
! 
!       if (route->dest != DRAIN_INVALID_DEST &&
! 	  route->sendWaiting == TRUE) {
! 
! 	dbg(DBG_ROUTE, "route[%d] fires in %d ms\n", i, route->announceCountdown);
! 	if (route->announceCountdown < minCountdown) {
! 	  minCountdown = route->announceCountdown;
! 	}
!       }
!     }
  
!     if (minCountdown < 0xFFFF) {
  
!       timerRunning = TRUE;
!       
!       for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
! 	route = &routes[i];
! 	if (route->dest != DRAIN_INVALID_DEST &&
! 	    route->sendWaiting == TRUE) {
! 	  route->announceCountdown -= minCountdown;
! 	}
!       }
!       
!       if (minCountdown == 0) {
! 	minCountdown = 5;
!       }
  
!       call Timer.start(TIMER_ONE_SHOT, minCountdown);
!     }
    }
  
--- 613,631 ----
    }
  
!   void clearRoute(DrainRouteEntry* route) {
  
!     route->dest = DRAIN_INVALID_DEST;
!     route->nextHop = TOS_BCAST_ADDR;
!     
!     route->nextHopCost = 0xFFFF;
!     route->nextHopLinkEst = 0xFFFF;
!     
!     route->destDistance = 0;
!     route->treeInstance = 0;
  
!     route->announceSeqno = 1;
!     route->announceDelay = 0;
  
!     route->defaultRoute = 0;
    }
  



More information about the Tinyos-beta-commits mailing list