[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.nc, NONE, 1.1 DrainGroup.nc, NONE, 1.1 DrainGroupManagerM.nc, NONE, 1.1 Drain.h, 1.8, 1.9 DrainC.nc, 1.10, 1.11 DrainLinkEst.nc, 1.2, 1.3 DrainLinkEstM.nc, 1.13, 1.14 DrainM.nc, 1.11, 1.12

Gilman Tolle gtolle at users.sourceforge.net
Fri Jun 10 12:38:06 PDT 2005


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

Modified Files:
	Drain.h DrainC.nc DrainLinkEst.nc DrainLinkEstM.nc DrainM.nc 
Added Files:
	Drain.nc DrainGroup.nc DrainGroupManagerM.nc 
Log Message:
Several Drain enhancements: 1. A node can now build a tree from itself. 2. A node can join a Drain group, and the path to that node is saved for later down-tree routing.

--- NEW FILE: Drain.nc ---
interface Drain {
  command result_t buildTree();
}

--- NEW FILE: DrainGroup.nc ---
interface DrainGroup {
  command result_t joinGroup(uint16_t group);
}

--- NEW FILE: DrainGroupManagerM.nc ---
module DrainGroupManagerM {
  provides interface DrainGroup;

  uses interface Intercept;
  uses interface Send;
  uses interface SendMsg;
  uses interface GroupManager;
}
implementation {
  TOS_Msg msgBuf;
  bool msgBufBusy;

  command result_t DrainGroup.joinGroup(uint16_t group) {
    uint16_t length;

    DrainGroupRegisterMsg *regMsg = (DrainGroupRegisterMsg*) 
      call Send.getBuffer(&msgBuf, &length);

    if (msgBufBusy) { return FAIL; }
    msgBufBusy = TRUE;

    regMsg->group = group;
    regMsg->timeout = 4; // XXX: pick something good

    if (call SendMsg.send(TOS_DEFAULT_ADDR,
			  sizeof(DrainGroupRegisterMsg),
			  &msgBuf) == FAIL) {
      msgBufBusy = FALSE;
      dbg(DBG_ROUTE, "DrainGroupManagerM: couldn't send group-join %d\n", group);
      return FAIL;
    } else {
      dbg(DBG_ROUTE, "DrainGroupManagerM: joining group %d\n", group);
      call GroupManager.joinGroup(group);
    }	

    return SUCCESS;
  }

  event result_t Intercept.intercept(TOS_MsgPtr msg, void* payload, 
				     uint16_t payloadLen) {

    DrainGroupRegisterMsg *regMsg = (DrainGroupRegisterMsg*) payload;

    call GroupManager.joinForward(regMsg->group);

    dbg(DBG_ROUTE, "DrainGroupManagerM: becoming forwarder for group %d\n", 
	regMsg->group);

    return SUCCESS;
  }

  event result_t Send.sendDone(TOS_MsgPtr msg, result_t success) {
    // do-nothing
    return SUCCESS;
  }

  event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success) {
    if (msg == &msgBuf) {
      msgBufBusy = FALSE;
    }
    return SUCCESS;
  }
}

Index: Drain.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/Drain.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Drain.h	7 Jun 2005 16:36:23 -0000	1.8
--- Drain.h	10 Jun 2005 19:38:03 -0000	1.9
***************
*** 41,45 ****
    AM_DRAINMSG = 4,
    AM_DRAINBEACONMSG = 7,
!   AM_DRAINREGISTERMSG = 8,
  };
  
--- 41,45 ----
    AM_DRAINMSG = 4,
    AM_DRAINBEACONMSG = 7,
!   AM_DRAINGROUPREGISTERMSG = 89,
  };
  
***************
*** 54,67 ****
    DRAIN_INVALID_DEST = 0,
    DRAIN_MAX_CHILDREN = 8,
-   DRAIN_DIRECTION_UP = 0,
-   DRAIN_DIRECTION_DOWN = 1,
-   DRAIN_MAX_REG_ATTEMPTS = 5,
  };
  
  enum {
!   DRAIN_REGISTER_OP_JOIN = 1,
!   DRAIN_REGISTER_OP_JOINED = 2,
!   DRAIN_REGISTER_OP_FULL = 3,
!   DRAIN_REGISTER_OP_TOOFAR = 4,
  };
  
--- 54,62 ----
    DRAIN_INVALID_DEST = 0,
    DRAIN_MAX_CHILDREN = 8,
  };
  
  enum {
!   DRAIN_GROUP_ALL = 0xFEFFU,
!   DRAIN_GROUP_MULTICAST = 0xFEFEU,
  };
  
***************
*** 72,77 ****
  typedef struct DrainMsg {
    uint8_t type;
!   uint8_t dir:1;
!   uint8_t ttl:7;
    uint16_t source;
    uint16_t dest;
--- 67,71 ----
  typedef struct DrainMsg {
    uint8_t type;
!   uint8_t ttl;
    uint16_t source;
    uint16_t dest;
***************
*** 93,102 ****
  } DrainBeaconMsg;
  
! typedef struct DrainRegisterMsg {
!   uint16_t linkSource;
!   uint16_t destAddr;
!   uint8_t  addrLength;
!   uint8_t  op;
! } DrainRegisterMsg;
  
  typedef struct DrainRouteEntry {
--- 87,94 ----
  } DrainBeaconMsg;
  
! typedef struct DrainGroupRegisterMsg {
!   uint16_t group;
!   uint8_t timeout;
! } DrainGroupRegisterMsg;
  
  typedef struct DrainRouteEntry {

Index: DrainC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainC.nc,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** DrainC.nc	8 Jun 2005 18:39:13 -0000	1.10
--- DrainC.nc	10 Jun 2005 19:38:03 -0000	1.11
***************
*** 62,70 ****
--- 62,75 ----
      interface StdControl;
  
+     interface Drain;
+     interface DrainGroup;
+ 
      interface RouteControl;
  
      interface SendMsg[uint8_t id];
      interface Send[uint8_t id];
+ 
      interface Receive[uint8_t id];
+ 
      interface Intercept[uint8_t id];
      interface Intercept as Snoop[uint8_t id];
***************
*** 77,80 ****
--- 82,87 ----
      DrainM, 
      DrainLinkEstM,
+     DrainGroupManagerM,
+     GroupManagerC,
      GenericComm, 
      RandomLFSR,
***************
*** 91,100 ****
  
    StdControl = DrainM.StdControl;
!   Receive = DrainM.Receive;
    SendMsg = DrainM.SendMsg;
    Send = DrainM.Send;
    Intercept = DrainM.Intercept;
    Snoop = DrainM.Snoop;
!   RouteControl = DrainLinkEstM.RouteControl;
  
    DrainM.SubControl -> GenericComm;
--- 98,112 ----
  
    StdControl = DrainM.StdControl;
! 
    SendMsg = DrainM.SendMsg;
    Send = DrainM.Send;
+ 
    Intercept = DrainM.Intercept;
    Snoop = DrainM.Snoop;
!   Receive = DrainM.Receive;
! 
!   Drain = DrainLinkEstM.Drain;
!   DrainGroup = DrainGroupManagerM.DrainGroup;
!   RouteControl = DrainLinkEstM;
  
    DrainM.SubControl -> GenericComm;
***************
*** 110,113 ****
--- 122,127 ----
    DrainM.Timer -> TimerC.Timer[unique("Timer")];
  
+   DrainM.DrainGroup -> DrainGroupManagerM;
+ 
    DrainLinkEstM.Timer -> TimerC.Timer[unique("Timer")];
  
***************
*** 118,125 ****
    DrainLinkEstM.Leds -> LedsC;
  
! #ifdef DRAIN_DOWN_ROUTE
!   DrainLinkEstM.SendRegisterMsg -> GenericComm.SendMsg[AM_DRAINREGISTERMSG];
!   DrainLinkEstM.ReceiveRegisterMsg -> GenericComm.ReceiveMsg[AM_DRAINREGISTERMSG];
! #endif
  
  #if defined(_CC2420CONST_H)
--- 132,136 ----
    DrainLinkEstM.Leds -> LedsC;
  
!   DrainLinkEstM.DrainGroup -> DrainGroupManagerM;
  
  #if defined(_CC2420CONST_H)
***************
*** 130,132 ****
--- 141,148 ----
    DrainM.MacControl -> CC1000RadioC;
  #endif
+   
+   DrainGroupManagerM.Send -> DrainM.Send[AM_DRAINGROUPREGISTERMSG];
+   DrainGroupManagerM.SendMsg -> DrainM.SendMsg[AM_DRAINGROUPREGISTERMSG];
+   DrainGroupManagerM.Intercept -> DrainM.Intercept[AM_DRAINGROUPREGISTERMSG];
+   DrainGroupManagerM.GroupManager -> GroupManagerC;
  }

Index: DrainLinkEst.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEst.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DrainLinkEst.nc	3 Mar 2005 02:04:13 -0000	1.2
--- DrainLinkEst.nc	10 Jun 2005 19:38:03 -0000	1.3
***************
*** 73,75 ****
--- 73,77 ----
  
    command result_t messageSent(TOS_MsgPtr msg, uint8_t id, result_t success);
+ 
+   command bool isRoot();
  }

Index: DrainLinkEstM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEstM.nc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** DrainLinkEstM.nc	8 Jun 2005 18:39:13 -0000	1.13
--- DrainLinkEstM.nc	10 Jun 2005 19:38:03 -0000	1.14
***************
*** 31,34 ****
--- 31,35 ----
      interface StdControl;
      interface DrainLinkEst;
+     interface Drain;
  
      interface RouteControl;
***************
*** 47,50 ****
--- 48,53 ----
      interface ReceiveMsg;
  
+     interface DrainGroup;
+ 
      interface Leds;
    }
***************
*** 58,61 ****
--- 61,66 ----
    TOS_Msg msgBuf;
  
+   uint8_t disseminateSeqno;
+ 
  #define MAX(a_,b_) (a_ > b_ ? a_ : b_)
  #define MIN(a_,b_) (a_ < b_ ? a_ : b_)
***************
*** 68,71 ****
--- 73,77 ----
    void clearRoute(DrainRouteEntry* route);
    DrainRouteEntry* getRoute(uint16_t dest);
+   bool isGroup(uint16_t dest);
  
    task void SendRouteTask();
***************
*** 103,106 ****
--- 109,116 ----
      uint8_t i;
  
+     if (isGroup(dest)) {
+       return &routes[0];
+     }
+ 
      for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
        route = &routes[i];
***************
*** 121,144 ****
    }
  
    command result_t StdControl.start() {
- #ifdef PLATFORM_PC
-     if (TOS_LOCAL_ADDRESS == 0) {
-       DrainRouteEntry* route = &routes[0];
-       
-       route->dest = TOS_BCAST_ADDR;
-       route->nextHop = TOS_BCAST_ADDR;
-       
-       route->nextHopCost = 0;
-       route->nextHopLinkEst = 0;
-       
-       route->destDistance = 0;
-       route->treeInstance = 128;
-       
-       route->announceSeqno = 0;
-       route->announceDelay = 4;
-       
-       call Timer.start(TIMER_ONE_SHOT, 16384);
-     }
- #endif
      return SUCCESS;
    }
--- 131,139 ----
    }
  
+   bool isGroup(uint16_t dest) {
+     return (dest >= 0xFE00 && dest <= 0xFEFF);
+   }
+ 
    command result_t StdControl.start() {
      return SUCCESS;
    }
***************
*** 157,178 ****
  
      Msg->addr = 0;
  
-     pMHMsg->type = id;
-     pMHMsg->dir = DRAIN_DIRECTION_UP;
-     pMHMsg->ttl = DRAIN_MAX_TTL - 1;
-     pMHMsg->source = TOS_LOCAL_ADDRESS;
-     
      if (dest == TOS_DEFAULT_ADDR) {
        if (routes[0].dest == DRAIN_INVALID_DEST) {
! 	pMHMsg->dest = TOS_BCAST_ADDR;
        } else {
! 	pMHMsg->dest = routes[0].dest;
        }
-     } else {
-       pMHMsg->dest = dest;
      }
  
!     Msg->length = offsetof(DrainMsg,data) + length;
! 
      return SUCCESS;
    }
--- 152,170 ----
  
      Msg->addr = 0;
+     Msg->length = offsetof(DrainMsg,data) + length;
  
      if (dest == TOS_DEFAULT_ADDR) {
        if (routes[0].dest == DRAIN_INVALID_DEST) {
! 	dest = TOS_BCAST_ADDR;
        } else {
! 	dest = routes[0].dest;
        }
      }
  
!     pMHMsg->type = id;
!     pMHMsg->ttl = DRAIN_MAX_TTL - 1;
!     pMHMsg->source = TOS_LOCAL_ADDRESS;
!     pMHMsg->dest = dest;
!       
      return SUCCESS;
    }
***************
*** 185,194 ****
  
      pMHMsg->ttl--;
! 
!     if (pMHMsg->ttl == 0) {
! 	return FAIL;
!     } else {
!       return SUCCESS;
!     }
    }
  
--- 177,185 ----
  
      pMHMsg->ttl--;
!     
!     if (pMHMsg->ttl == 0)
!       return FAIL;
!     
!     return SUCCESS;
    }
  
***************
*** 198,222 ****
      DrainRouteEntry* route;
  
!     if (pMHMsg->dir == DRAIN_DIRECTION_UP) {
! 
!       if (pMHMsg->dest == TOS_BCAST_ADDR) {
! 	
! 	Msg->addr = TOS_BCAST_ADDR;
! 	
!       } else if (pMHMsg->dest == TOS_UART_ADDR) {
! 	
! 	Msg->addr = TOS_UART_ADDR;
  
        } else {
! 
! 	route = getRoute(pMHMsg->dest);
! 	
! 	if (route != NULL) {
! 	  Msg->addr = route->nextHop;
! 	} else {
! 	  Msg->addr = TOS_BCAST_ADDR;
! 	}
        }
- 
      }
  
--- 189,209 ----
      DrainRouteEntry* route;
  
!     if (pMHMsg->dest == TOS_BCAST_ADDR) {
!       
!       Msg->addr = TOS_BCAST_ADDR;
!       
!     } else if (pMHMsg->dest == TOS_UART_ADDR) {
!       
!       Msg->addr = TOS_UART_ADDR;
!       
!     } else {
  
+       route = getRoute(pMHMsg->dest);
+       
+       if (route != NULL) {
+ 	Msg->addr = route->nextHop;
        } else {
! 	Msg->addr = TOS_BCAST_ADDR;
        }
      }
  
***************
*** 226,229 ****
--- 213,304 ----
    }
  
+   command bool DrainLinkEst.isRoot() {
+     return (routes[0].nextHop == TOS_LOCAL_ADDRESS);
+   }
+ 
+   command result_t Drain.buildTree() {
+ 
+     DrainRouteEntry* route = newRoute(TOS_LOCAL_ADDRESS);
+ 
+     if (route == NULL) 
+       return FAIL;
+ 
+     route->treeInstance = call Random.rand() & 0xFF;
+ 
+     dbg(DBG_ROUTE, "DrainLinkEstM: buildTree(instance=%d)\n",
+ 	route->treeInstance);
+ 
+     route->announceSeqno = 0;
+     route->announceDelay = 1;
+ 
+     route->nextHop = TOS_LOCAL_ADDRESS;
+     route->nextHopCost = 0;
+     route->nextHopLinkEst = 0;
+     route->destDistance = 0;
+ 
+     route->sentRoute = FALSE;
+ 
+     post SendRouteTask();
+ 
+     return SUCCESS;
+   }
+ 
+   event result_t Timer.fired() {
+     DrainRouteEntry *route = &routes[0];
+ 
+     if (route->sentRoute == FALSE) {
+       route->sentRoute = TRUE;
+       post SendRouteTask();
+     }
+     
+     return SUCCESS;
+   }
+ 
+   task void SendRouteTask() {
+ 
+     TOS_MsgPtr pMsgBuf = &msgBuf;
+     DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
+     DrainRouteEntry *route = &routes[0];
+ 
+     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);
+       return;
+     }
+ 
+     if (msgBufBusy) {
+ #ifndef PLATFORM_PC
+       post SendRouteTask();
+ #endif
+       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;
+ 
+     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);
+     } else {
+       dbg(DBG_ROUTE, "send DrainBeaconMsg FAILED\n");
+ #ifndef PLATFORM_PC
+       post SendRouteTask();
+ #endif
+       atomic msgBufBusy = FALSE;
+     }
+   }
    
    event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr Msg) {
***************
*** 236,239 ****
--- 311,322 ----
      linkEst = adjustLQI(Msg->lqi);
  #elif defined(PLATFORM_PC)
+     linkEst = 
+       abs(pRP->linkSource % 10 - TOS_LOCAL_ADDRESS % 10) +
+       abs(pRP->linkSource / 10 - TOS_LOCAL_ADDRESS / 10);
+ 
+ //    dbg(DBG_ROUTE, "DrainLinkEstM: source=%d, dest=%d, est=%d\n",
+ //	pRP->linkSource, TOS_LOCAL_ADDRESS, linkEst);
+ 
+ /*      
      if (pRP->linkSource >= TOS_LOCAL_ADDRESS) {
        linkEst = pRP->linkSource - TOS_LOCAL_ADDRESS;
***************
*** 241,244 ****
--- 324,328 ----
        linkEst = TOS_LOCAL_ADDRESS - pRP->linkSource;
      }
+ */
  #else
      linkEst = Msg->strength;
***************
*** 249,261 ****
      }
  
! #if 0
!     dbg(DBG_ROUTE,"receive DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d,linkEst=%d)\n",
  	pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
  	pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance, linkEst);
- #endif
- 
- #ifdef PLATFORM_PC
-     if (TOS_LOCAL_ADDRESS != 0) {
- #endif
  
      if ((int8_t)(pRP->beaconSeqno - route->announceSeqno) > 0 
--- 333,339 ----
      }
  
!     dbg(DBG_ROUTE,"DrainLinkEstM: receive DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d,linkEst=%d)\n",
  	pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
  	pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance, linkEst);
  
      if ((int8_t)(pRP->beaconSeqno - route->announceSeqno) > 0 
***************
*** 282,289 ****
      }
  
- #ifdef PLATFORM_PC
-     }
- #endif
- 
      if (pRP->treeInstance != route->treeInstance ||
  	pRP->linkSource == route->nextHop) {
--- 360,363 ----
***************
*** 293,298 ****
  	 it's from a newly constructed tree,
  	 or the message is from my parent, 
! 	 just copy the cost and link est.
        */
        
        route->dest = pRP->source;
--- 367,378 ----
  	 it's from a newly constructed tree,
  	 or the message is from my parent, 
! 	 just copy the cost and link est. (why just copy from parent?)
        */
+ 
+       if (pRP->treeInstance != route->treeInstance) {
+ 	dbg(DBG_ROUTE, "DrainLinkEstM: joined tree instance %d\n", pRP->treeInstance);
+       } else {
+ 	dbg(DBG_ROUTE, "DrainLinkEstM: updated parent cost in tree instance %d\n", pRP->treeInstance);
+       }
        
        route->dest = pRP->source;
***************
*** 302,308 ****
        route->nextHopCost = pRP->cost;
        route->nextHopLinkEst = linkEst;
! 
        route->treeInstance = pRP->treeInstance;
! 
      } else {
        
--- 382,393 ----
        route->nextHopCost = pRP->cost;
        route->nextHopLinkEst = linkEst;
!       
        route->treeInstance = pRP->treeInstance;
!       
!       dbg(DBG_ROUTE, "DrainLinkEstM: nextHop=%d, pathCost=%d, distance=%d\n",
! 	  route->nextHop,
! 	  route->nextHopCost + route->nextHopLinkEst,
! 	  route->destDistance);
!       
      } else {
        
***************
*** 314,330 ****
        
        uint32_t curQuality = 
! 	  (uint32_t) route->nextHopCost + (uint32_t) route->nextHopLinkEst;
! 	uint32_t newQuality = 
! 	  (uint32_t) pRP->cost + (uint32_t) linkEst;
! 
! 	if (newQuality < curQuality && 
! 	    pRP->parent != TOS_LOCAL_ADDRESS) {
! 	  
! 	  route->nextHop = pRP->linkSource;
! 	  route->nextHopCost = pRP->cost;
! 	  route->nextHopLinkEst = linkEst;
! 	  route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
  
! 	}
      }
  
--- 399,421 ----
        
        uint32_t curQuality = 
! 	(uint32_t) route->nextHopCost + (uint32_t) route->nextHopLinkEst;
!       uint32_t newQuality = 
! 	(uint32_t) pRP->cost + (uint32_t) linkEst;
!       
!       if (newQuality < curQuality && 
! 	  pRP->parent != TOS_LOCAL_ADDRESS) {
! 	
! 	route->nextHop = pRP->linkSource;
! 	route->nextHopCost = pRP->cost;
! 	route->nextHopLinkEst = linkEst;
! 	route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
  
! 	dbg(DBG_ROUTE, "DrainLinkEstM: parent switch in tree instance %d: nextHop=%d, pathCost=%d, distance=%d\n",
! 	    route->treeInstance, route->nextHop,
! 	    route->nextHopCost + route->nextHopLinkEst,
! 	    route->destDistance);
!       } else {
! 	dbg(DBG_ROUTE, "DrainLinkEstM: keeping current next hop\n");
!       }
      }
  
***************
*** 338,409 ****
    }
  
-   event result_t Timer.fired() {
-     DrainRouteEntry *route = &routes[0];
- 
-     if (route->sentRoute == FALSE) {
-       route->sentRoute = TRUE;
-       post SendRouteTask();
-     }
-     
-     return SUCCESS;
-   }
- 
-   task void SendRouteTask() {
- 
-     TOS_MsgPtr pMsgBuf = &msgBuf;
-     DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
-     DrainRouteEntry *route = &routes[0];
-     
-     dbg(DBG_ROUTE,"MultiHopRSSI Sending route update msg.\n");
-     
-     if (route->dest == DRAIN_INVALID_DEST ||
- 	route->destDistance == DRAIN_MAX_TTL) {
-       return;
-     }
- 
-     if (msgBufBusy) {
- #ifndef PLATFORM_PC
-       post SendRouteTask();
- #endif
-       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;
-     
-     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,
- 	  pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance);
-     } else {
-       dbg(DBG_ROUTE, "send DrainBeaconMsg FAILED\n");
- #ifndef PLATFORM_PC
-       post SendRouteTask();
- #endif
-       atomic msgBufBusy = FALSE;
-     }
-   }
- 
    command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg, uint8_t id, 
  					    result_t success) {
- 
- #if 0
-     if (success) {
-       successCounter++; 
-     } else {
-       failCounter++;
-     }
- #endif
- 
      return SUCCESS;
    }
--- 429,434 ----

Index: DrainM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainM.nc,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** DrainM.nc	7 Jun 2005 16:36:23 -0000	1.11
--- DrainM.nc	10 Jun 2005 19:38:03 -0000	1.12
***************
*** 30,34 ****
--- 30,36 ----
      interface SendMsg[uint8_t id];
      interface Send[uint8_t id];
+ 
      interface Receive[uint8_t id];
+ 
      interface Intercept[uint8_t id];
      interface Intercept as Snoop[uint8_t id];
***************
*** 43,46 ****
--- 45,49 ----
  
      interface DrainLinkEst;
+     interface DrainGroup;
  
      interface Timer;
***************
*** 89,97 ****
    uint8_t forwardDrops;
  
-   
    task void QueueServiceTask();
  
    void initializeBufs();
  
    bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen);
    result_t enqueueSend(TOS_MsgPtr pMsg);
--- 92,100 ----
    uint8_t forwardDrops;
  
    task void QueueServiceTask();
  
    void initializeBufs();
  
+   bool tooBig(TOS_MsgPtr pMsg, uint8_t payloadLen);
    bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen);
    result_t enqueueSend(TOS_MsgPtr pMsg);
***************
*** 142,147 ****
--- 145,152 ----
      *length = TOSH_DATA_LENGTH - offsetof(DrainMsg,data);
  
+ #if DRAIN_DEBUG_DETAILED
      dbg(DBG_ROUTE, "Drain: getBuffer(pMsg=0x%x,id=%d,len=%d)\n",
  	pMsg, id, *length);
+ #endif
  
      return (&pMHMsg->data[0]);
***************
*** 156,169 ****
    } 
    
!   command result_t SendMsg.send[uint8_t id](uint16_t dest, uint8_t length, TOS_MsgPtr pMsg) {
  
!     dbg(DBG_ROUTE, "Drain: send(pMsg=0x%x,id=%d,len=%d)\n",
  	pMsg, id, length);
! 
!     if (cantSend(pMsg, length)) {
        sendDrops++;
        return FAIL;
      }
! 
      call DrainLinkEst.initializeFields(pMsg, id, dest, length);
  
--- 161,175 ----
    } 
    
!   command result_t SendMsg.send[uint8_t id](uint16_t dest, uint8_t length, 
! 					    TOS_MsgPtr pMsg) {
  
!     dbg(DBG_ROUTE, "Drain: netSend(pMsg=0x%x,id=%d,len=%d)\n",
  	pMsg, id, length);
!     
!     if (tooBig(pMsg, length) || cantSend(pMsg, length)) {
        sendDrops++;
        return FAIL;
      }
!     
      call DrainLinkEst.initializeFields(pMsg, id, dest, length);
  
***************
*** 171,181 ****
    }
  
!   bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen) {
! 
      uint16_t usMHLength = offsetof(DrainMsg,data) + payloadLen;
! 
      if (usMHLength > TOSH_DATA_LENGTH) {
        return TRUE;
      }
  
      if (sendQueueFull) {
--- 177,190 ----
    }
  
!   bool tooBig(TOS_MsgPtr pMsg, uint8_t payloadLen) {
      uint16_t usMHLength = offsetof(DrainMsg,data) + payloadLen;
!     
      if (usMHLength > TOSH_DATA_LENGTH) {
        return TRUE;
      }
+     return FALSE;
+   }
+ 
+   bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen) {
  
      if (sendQueueFull) {
***************
*** 189,193 ****
  
    result_t enqueueSend(TOS_MsgPtr pMsg) {
!     
      if (!queuesBusy) {
        if (post QueueServiceTask() == FAIL) {
--- 198,202 ----
  
    result_t enqueueSend(TOS_MsgPtr pMsg) {
! 
      if (!queuesBusy) {
        if (post QueueServiceTask() == FAIL) {
***************
*** 199,205 ****
      }
  
      dbg(DBG_ROUTE, "Drain: sendEnterQueue(pMsg=0x%x)\n",
  	pMsg);
!     
      sendQueue[sendQueueIn] = pMsg;
      sendQueueIn = (sendQueueIn + 1) % DRAIN_SEND_QUEUE_SIZE;
--- 208,216 ----
      }
  
+ #if DRAIN_DEBUG_DETAILED
      dbg(DBG_ROUTE, "Drain: sendEnterQueue(pMsg=0x%x)\n",
  	pMsg);
! #endif
! 
      sendQueue[sendQueueIn] = pMsg;
      sendQueueIn = (sendQueueIn + 1) % DRAIN_SEND_QUEUE_SIZE;
***************
*** 212,252 ****
    event TOS_MsgPtr LinkReceiveMsg.receive(TOS_MsgPtr pMsg) {
      
!     DrainMsg *pMHMsg = (DrainMsg *)pMsg->data;
      uint16_t payloadLen = pMsg->length - offsetof(DrainMsg,data);
!     uint8_t id = pMHMsg->type;
      
!     dbg(DBG_ROUTE, "Drain: receive(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
!         pMsg, pMHMsg->source, pMHMsg->dest);
  
!     if (pMsg->addr == TOS_LOCAL_ADDRESS) { // Addressed to local node
  
!       if ((signal Intercept.intercept[id](pMsg, 
! 					  &pMHMsg->data[0], 
! 					  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);
  	
! 	if (fwdQueueFull) {
  	  dbg(DBG_ROUTE, "Drain: forwardQueueFull(pMsg=0x%x)\n", pMsg);
  	  forwardDrops++;
- 	  return pMsg;
- 	}
- 	
- 	if (call DrainLinkEst.forwardFields(pMsg)) {
- 	  pMsg = enqueueForward(pMsg);
  	}
        }
- 
-     } else {
- 
-       signal Snoop.intercept[id](pMsg, &pMHMsg->data[0], payloadLen);
      }
!     
      return pMsg;
    }
--- 223,271 ----
    event TOS_MsgPtr LinkReceiveMsg.receive(TOS_MsgPtr pMsg) {
      
!     DrainMsg *drainMsg = (DrainMsg *)pMsg->data;
      uint16_t payloadLen = pMsg->length - offsetof(DrainMsg,data);
!     uint8_t id = drainMsg->type;
      
!     dbg(DBG_ROUTE, "Drain: linkReceive(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
!         pMsg, drainMsg->source, drainMsg->dest);
  
!     // See if it's for this node.
!     if (pMsg->addr != TOS_LOCAL_ADDRESS) { 
!       signal Snoop.intercept[id](pMsg, &drainMsg->data[0], payloadLen);
!       return pMsg;
!     }
  
!     // Give Intercept a chance
!     if ((signal Intercept.intercept[id](pMsg, &drainMsg->data[0], 
! 					payloadLen)) == FAIL) {
!       // It's not OK to forward.
!       return pMsg;
!     }
  
!     // Pass it up if necessary.
!     if (drainMsg->dest == TOS_LOCAL_ADDRESS ||
! 	call DrainLinkEst.isRoot()) {
  
!       dbg(DBG_ROUTE, "Drain: netReceive(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
! 	  pMsg, drainMsg->source, drainMsg->dest);
! 
!       pMsg = signal Receive.receive[id](pMsg, &drainMsg->data[0], payloadLen);
! 
!     } else { 
! 
!       if (call DrainLinkEst.forwardFields(pMsg)) {
  	
! 	// Enqueue it for forwarding if necessary.
! 	if (!fwdQueueFull) {
! 	  dbg(DBG_ROUTE, "Drain: netForward(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
! 	      pMsg, drainMsg->source, drainMsg->dest);
! 	  pMsg = enqueueForward(pMsg);
! 	} else {
  	  dbg(DBG_ROUTE, "Drain: forwardQueueFull(pMsg=0x%x)\n", pMsg);
  	  forwardDrops++;
  	}
        }
      }
! 
      return pMsg;
    }
***************
*** 265,270 ****
      }
  
      dbg(DBG_ROUTE, "Drain: forwardEnterQueue(pMsg=0x%x)\n", pMsg);
!         
      pNewBuf = fwdQueue[fwdQueueIn];
      fwdQueue[fwdQueueIn] = pMsg;
--- 284,291 ----
      }
  
+ #if DRAIN_DEBUG_DETAILED
      dbg(DBG_ROUTE, "Drain: forwardEnterQueue(pMsg=0x%x)\n", pMsg);
! #endif
! 
      pNewBuf = fwdQueue[fwdQueueIn];
      fwdQueue[fwdQueueIn] = pMsg;
***************
*** 280,284 ****
--- 301,307 ----
      TOS_MsgPtr pMsg;
  
+ #if DRAIN_DEBUG_DETAILED
      dbg(DBG_ROUTE, "Drain: queueServiceTask\n");
+ #endif
  
      // First check send queue. 
***************
*** 286,291 ****
  	(sendQueueIn == sendQueueOut && sendQueueFull == TRUE)) {
  
        dbg(DBG_ROUTE, "Drain: queueServiceTask(servicing=sendQueue)\n");
!       
        // We've got a message in the send queue.
        pMsg = sendQueue[sendQueueOut];
--- 309,316 ----
  	(sendQueueIn == sendQueueOut && sendQueueFull == TRUE)) {
  
+ #if DRAIN_DEBUG_DETAILED
        dbg(DBG_ROUTE, "Drain: queueServiceTask(servicing=sendQueue)\n");
! #endif
! 
        // We've got a message in the send queue.
        pMsg = sendQueue[sendQueueOut];
***************
*** 294,299 ****
  	       (fwdQueueIn == fwdQueueOut && fwdQueueFull == TRUE)) {
  
        dbg(DBG_ROUTE, "Drain: queueServiceTask(servicing=forwardQueue)\n");
!     
        // We've got a message in the forward queue.
        pMsg = fwdQueue[fwdQueueOut];
--- 319,326 ----
  	       (fwdQueueIn == fwdQueueOut && fwdQueueFull == TRUE)) {
  
+ #if DRAIN_DEBUG_DETAILED
        dbg(DBG_ROUTE, "Drain: queueServiceTask(servicing=forwardQueue)\n");
! #endif
! 
        // We've got a message in the forward queue.
        pMsg = fwdQueue[fwdQueueOut];
***************
*** 301,305 ****
--- 328,335 ----
      } else {
  
+ #if DRAIN_DEBUG_DETAILED
        dbg(DBG_ROUTE, "Drain: queueServiceTask(queuesAllEmpty)\n");
+ #endif
+ 
        queuesBusy = FALSE;
        return;
***************
*** 307,310 ****
--- 337,343 ----
      
      call DrainLinkEst.selectRoute(pMsg);
+ 
+     dbg(DBG_ROUTE, "Drain: linkSend(pMsg=0x%x,linkDest=%d,len=%d)\n",
+ 	pMsg, pMsg->addr, pMsg->length);
      
      if (call LinkSendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
***************
*** 312,316 ****
--- 345,351 ----
      } else {
        // The radio didn't accept our message.
+ #ifndef PLATFORM_PC
        post QueueServiceTask();
+ #endif
      }      
    }
***************
*** 326,331 ****
--- 361,368 ----
      DrainMsg* mhMsg = (DrainMsg*) pMsg->data;
  
+ #if DRAIN_DEBUG_DETAILED
      dbg(DBG_ROUTE, "Drain: sendDone(pMsg=0x%x,success=%d)\n", 
  	pMsg, success);  
+ #endif
  
      if (pMsg != sendQueue[sendQueueOut] && 



More information about the Tinyos-beta-commits mailing list