[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/wustl/apps/Agilla/components/ContextDiscovery ClusteringI.nc, 1.2, 1.3 NeighborListC.nc, 1.10, 1.11 NeighborListI.nc, 1.4, 1.5 NeighborListM.nc, 1.21, 1.22 NeighborListProxy.nc, 1.2, 1.3

borndigerati borndigerati at users.sourceforge.net
Thu Apr 6 18:15:01 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/ContextDiscovery
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5750/components/ContextDiscovery

Modified Files:
	ClusteringI.nc NeighborListC.nc NeighborListI.nc 
	NeighborListM.nc NeighborListProxy.nc 
Log Message:


Index: ClusteringI.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/ContextDiscovery/ClusteringI.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ClusteringI.nc	5 Apr 2006 18:04:38 -0000	1.2
--- ClusteringI.nc	7 Apr 2006 01:14:44 -0000	1.3
***************
*** 62,66 ****
     * Returns the id of the cluster head of the cluster to which it belongs.
     * Returns its own id if it is the cluster head.
!    */
    command result_t getClusterHead(uint16_t* chID);
  
--- 62,66 ----
     * Returns the id of the cluster head of the cluster to which it belongs.
     * Returns its own id if it is the cluster head.
!    */
    command result_t getClusterHead(uint16_t* chID);
  
***************
*** 72,74 ****
--- 72,84 ----
      //command uint8_t getCommRange();
  
+     /*
+      * Returns if this node is known to belong to the same cluster.
+      */
+     command result_t isClusterMember(uint16_t id);
+ 
+     #if DEBUG_CLUSTERING
+     command void sendClusterDebugMsg();
+     #endif
+ 
+ 
  }

Index: NeighborListC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/ContextDiscovery/NeighborListC.nc,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** NeighborListC.nc	5 Apr 2006 18:04:38 -0000	1.10
--- NeighborListC.nc	7 Apr 2006 01:14:44 -0000	1.11
***************
*** 56,59 ****
--- 56,64 ----
    #endif
  
+   #if ENABLE_EXP_LOGGING
+     components ExpLoggerC;
+   #endif
+ 
+ 
    Main.StdControl -> NeighborListM;
    Main.StdControl -> SimpleTime;
***************
*** 99,104 ****
  
    #if DEBUG_CLUSTERING
!   //NeighborListM.SendClusterMsg -> Comm.SendMsg[AM_AGILLACLUSTERDEBUGMSG];
!   //NeighborListM.RcvClusterMsg -> Comm.ReceiveMsg[AM_AGILLACLUSTERDEBUGMSG];
    #endif
  }
--- 104,113 ----
  
    #if DEBUG_CLUSTERING
!   NeighborListM.SendClusterDebugMsg -> Comm.SendMsg[AM_AGILLACLUSTERDEBUGMSG];
!   NeighborListM.RcvClusterDebugMsg -> Comm.ReceiveMsg[AM_AGILLACLUSTERDEBUGMSG];
!   #endif
! 
!   #if ENABLE_EXP_LOGGING
!     NeighborListM.ExpLoggerI -> ExpLoggerC;
    #endif
  }

Index: NeighborListI.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/ContextDiscovery/NeighborListI.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** NeighborListI.nc	5 Apr 2006 18:04:38 -0000	1.4
--- NeighborListI.nc	7 Apr 2006 01:14:44 -0000	1.5
***************
*** 96,98 ****
--- 96,100 ----
  
  
+ 
+ 
  }

Index: NeighborListM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/ContextDiscovery/NeighborListM.nc,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** NeighborListM.nc	5 Apr 2006 18:04:38 -0000	1.21
--- NeighborListM.nc	7 Apr 2006 01:14:44 -0000	1.22
***************
*** 68,74 ****
  
      #if DEBUG_CLUSTERING
!     // msg sent by cluster member to clusterhead
!     //interface SendMsg as SendClusterMsg;
!     //interface ReceiveMsg as RcvClusterMsg;
      #endif
  
--- 68,74 ----
  
      #if DEBUG_CLUSTERING
!     // debug msg sent over the UART
!     interface SendMsg as SendClusterDebugMsg;
!     interface ReceiveMsg as RcvClusterDebugMsg;
      #endif
  
***************
*** 93,96 ****
--- 93,100 ----
      interface StdControl as CHDirControl;
      #endif
+ 
+     #if ENABLE_EXP_LOGGING
+       interface ExpLoggerI;
+     #endif
    }
  }
***************
*** 136,143 ****
    tos_time_t chSelectTime;  // time when this node selected a clusterhead
    void setCH(uint16_t ch_id);
!   #endif
! 
!   #if DEBUG_CLUSTERING
!   //void sendClusterMsg(int16_t dest);
    #endif
  
--- 140,144 ----
    tos_time_t chSelectTime;  // time when this node selected a clusterhead
    void setCH(uint16_t ch_id);
!   void determineCluster(TOS_MsgPtr m);
    #endif
  
***************
*** 172,177 ****
        for (i = 0; i < numNbrs; i++) {
          #if ENABLE_CLUSTERING
!             dbg(DBG_USR1, "\t%i:\tID = %i\thopsToGW = %i\tlqi = %i\ttimestamp = %i\n", i,
!                         nbrs[i].addr, nbrs[i].hopsToGW, nbrs[i].linkQuality, nbrs[i].timeStamp.low32);
          #else
              dbg(DBG_USR1, "\t%i:\tID = %i\thopsToGW = %i\n", i, nbrs[i].addr, nbrs[i].hopsToGW);
--- 173,178 ----
        for (i = 0; i < numNbrs; i++) {
          #if ENABLE_CLUSTERING
!             dbg(DBG_USR1, "\t%i:\tID = %i\tchId = %i\thopsToGW = %i\tlqi = %i\ttimestamp = %i\n", i,
!                         nbrs[i].addr, nbrs[i].chId, nbrs[i].hopsToGW, nbrs[i].linkQuality, nbrs[i].timeStamp.low32);
          #else
              dbg(DBG_USR1, "\t%i:\tID = %i\thopsToGW = %i\n", i, nbrs[i].addr, nbrs[i].hopsToGW);
***************
*** 239,245 ****
          if (call AddressMgrI.isGW() && chId == -1){
              setCH(TOS_LOCAL_ADDRESS);
!             #if DEBUG_CLUSTERING
!             call Leds.greenToggle();
!             #endif
          }
          bmsg->chId = chId;
--- 240,244 ----
          if (call AddressMgrI.isGW() && chId == -1){
              setCH(TOS_LOCAL_ADDRESS);
! 
          }
          bmsg->chId = chId;
***************
*** 345,359 ****
  
  
!   #if ENABLE_CLUSTERING
!   /**
!    * This method is copied from MultiHopLQI to adjust the link quality.
!    */
! /*
!   uint16_t adjustLQI(uint8_t val) {
!       uint16_t result = (80 - (val - 40));
!       result = (((result * result) >> 3) * result) >> 3;
!       return result;
!   }*/
!   #endif
  
  
--- 344,348 ----
  
  
! 
  
  
***************
*** 368,379 ****
      tos_time_t now = call Time.get();
  
-     #if ENABLE_CLUSTERING
-     uint16_t hopsToGW = NO_GW;
-     int16_t pos = -1;
-     //uint64_t curTime = 0, nbrTS = 0;
-     uint16_t addr, nbrId;
-     uint8_t switchedCH = 0;
-     uint8_t numClusterMembers = 0;
-     #endif
  
  
--- 357,360 ----
***************
*** 425,428 ****
--- 406,410 ----
  
        #if ENABLE_CLUSTERING
+ 
          nbrs[indx].chId = bmsg->chId;
          nbrs[indx].energy = bmsg->energy;
***************
*** 430,445 ****
          //nbrs[indx].range = bmsg->range;
  
!         if(chId == TOS_LOCAL_ADDRESS && bmsg->chId == chId) {
              // this node is a clusterhead and
!             // neighbor belongs to this nodes cluster
!             call CHDir.addClusterMember(bmsg->id/*, bmsg->range*/);
          }
-       #endif
  
!       #if DEBUG_CLUSTERING
!         //dbg(DBG_USR1, "NeighborListM: neighbor: %i hopsToGW=%i chId=%i, energy=%i, linkQuality=%i, range=%i\n",
!         //                        bmsg->id, bmsg->hopsToGW, bmsg->chId, bmsg->energy, nbrs[indx].linkQuality, bmsg->range);
        #endif
  
  //      #if DEBUG_NEIGHBORLIST
  //        dbg(DBG_USR1, "BeaconBasedFinderM: processBeacon(): Timestamp of neighbor %i updated to %i %i\n",
--- 412,445 ----
          //nbrs[indx].range = bmsg->range;
  
!         if(chId == TOS_LOCAL_ADDRESS )
!         {
              // this node is a clusterhead and
!             if(call CHDir.isClusterMember(bmsg->id))
!             {
!                 // received beacon from a clustermember
!                 if(bmsg->chId != chId)
!                 {
!                     // a cluster member has changed clusters; remove it from list
!                     call CHDir.removeClusterMember(bmsg->id);
!                 }
!             } else {
!                 // received beacon from non cluster member
!                 if(bmsg->chId == chId)
!                 {
!                     // neighbor belongs to this nodes cluster but is not in the clustermember list; add it
!                     call CHDir.addClusterMember(bmsg->id/*, bmsg->range*/);
!                 }
!             }
          }
  
!         #if DEBUG_CLUSTERING
!         //dbg(DBG_USR1, "NeighborListM: neighbor: %i hopsToGW=%i chId=%i, energy=%i, linkQuality=%i\n",
!         //                        bmsg->id, bmsg->hopsToGW, bmsg->chId, bmsg->energy, m->lqi);
!         #endif
! 
        #endif
  
+ 
+ 
  //      #if DEBUG_NEIGHBORLIST
  //        dbg(DBG_USR1, "BeaconBasedFinderM: processBeacon(): Timestamp of neighbor %i updated to %i %i\n",
***************
*** 453,645 ****
      #if ENABLE_CLUSTERING
  
!         if(bmsg->hopsToGW == NO_GW){
!             return m;
!         }
! 
!         // Update clusterhead
!         // check if the neighbor is a clusterhead
!         hopsToGW = call NeighborListI.getGW(&addr);
!         if (!call AddressMgrI.isGW()){
!                 hopsToGW++; // add one hop to get to the neighbor
!         }
!         #if DEBUG_CLUSTERING
!         //dbg(DBG_USR1, "NeighborListM: hopsToGW=%i\n", hopsToGW);
!         #endif
!         if(chId == -1){
!             // cluster head not yet set
!             // Determine the number of hops to the base station
! 
!             if (!call AddressMgrI.isGW() && hopsToGW != NO_GW){
!                 if(hopsToGW % 2 == 0){
!                     setCH(TOS_LOCAL_ADDRESS);
!                 }
!             }
! 
!             if(hopsToGW != 0 && bmsg->id == bmsg->chId){
!                 // neighbor is a clusterhead
!                 setCH(bmsg->id);
!             }
! 
!             // if the node has not heard from a clusterhead in a long time
!             // it should become a clusterhead
!             if((now.low32 - initTime.low32) > 5*(BEACON_PERIOD+BEACON_RAND)){
!                 setCH(TOS_LOCAL_ADDRESS);
!             }
! 
!             //for DEBUGING /////////////////
!             #if DEBUG_CLUSTERING
!             if(chId == TOS_LOCAL_ADDRESS){
!                 call Leds.greenToggle();
!             } else if(chId != -1){
!                 //sendClusterMsg(chId);
!             }
!             if(chId != -1) dbg(DBG_USR1, "NeighborListM: [%i] clusterhead set to %i\n", now.low32, chId);
!             #endif
!             /////////////////////////////////
!         } else if(bmsg->id == bmsg->chId){
!             // neighbor is a clusterhead
! 
!             if(chId != TOS_LOCAL_ADDRESS){
!                 // This node is not a cluster head
!                 // Check if it should join some other cluster
!                 // The node should change its clusterhead if it has
!                 // not heard from its current cluster head in time T
!                 // OR if the difference in the link quality of the
!                 // node sending the beacon is more than a threshold
! 
!                 i = 0;
!                 while (i < numNbrs && pos == -1) {
!                       if (nbrs[i].addr == chId)
!                         pos = i;
!                       i++;
!                 }
! 
! 
!                 if(pos == -1 || ((now.low32 - nbrs[pos].timeStamp.low32 ) > 3*(BEACON_PERIOD+BEACON_RAND)) ||
!                             ((m->lqi - nbrs[pos].linkQuality) > 10)){
!                     // if clusterhead entry not found
!                     // or if not heard from clusterhead for a while
!                     // or link quality of neighbor is much better
!                     // than link quality of current cluster head
!                     // set neighbor as cluster head
!                     setCH(bmsg->id);
!                     switchedCH = 1;
!                 }
! 
!             } else {
!                 // this node is a clusterhead
!                 if(!call AddressMgrI.isGW()){
!                     //this node is not the GW
!                     if(hopsToGW == 1){
!                         setCH(addr);
!                         switchedCH = 1;
!                         #if DEBUG_CLUSTERING
!                         call Leds.greenToggle();
!                         #endif
!                     } else {
!                         // if after a time period, I see that I don't have any cluster members
!                         // I should stop being a clusterhead and join the neighbor that is one
!                         i = 0;
!                         while (i < numNbrs ) {
!                           if (nbrs[i].chId == TOS_LOCAL_ADDRESS)
!                             numClusterMembers++;
!                           i++;
!                         }
!                         if(numClusterMembers == 0 &&
!                                 (now.low32 - chSelectTime.low32) > 3*(BEACON_PERIOD+BEACON_RAND)){
! 
!                             // check if there is a clusterhead closer to the GW than
!                             // the node sending the beacon msg
!                             // NOTE: not safe to do this; may cause race conditions
!                             //minHops = bmsg->hopsToGW;
!                             //nbrId = bmsg->id;
!                             //i = 0;
!                             //while (i < numNbrs ) {
!                             //  if (nbrs[i].addr == nbrs[i].chId && nbrs[i].hopsToGW < minHops){
!                             //  nbrId = nbrs[i].addr;
!                             //  minHops = nbrs[i].hopsToGW;
!                             //  }
!                             //  i++;
!                             //}
!                             setCH(bmsg->id);
!                             switchedCH = 1;
!                             #if DEBUG_CLUSTERING
!                             call Leds.greenToggle();
!                             #endif
!                         }
!                     }
!                 }
!             }
!         } else if(bmsg->chId != bmsg->id){
!             if(bmsg->id == chId){
!                 // it should check if its clusterhead is still a cluster head
!                 // if not, then it should switch clusterhead
!                 // find a neighbor that is a clusterhead and from whom
!                 // this node has heard from recently, and join its cluster
!                 // if no such clusterhead is found, set itself as clusterhead
!                 // NOTE: This may be unsafe and lead to race conditions
! 
!                 nbrId = TOS_LOCAL_ADDRESS;
!                 i = 0;
!                 while (i < numNbrs && nbrId != TOS_LOCAL_ADDRESS) {
!                      if (nbrs[i].addr == nbrs[i].chId &&
!                         ((now.low32 - nbrs[i].timeStamp.low32 ) <= 2*(BEACON_PERIOD+BEACON_RAND)))
!                         nbrId = nbrs[i].addr;
!                      i++;
!                 }
!                 setCH(nbrId);
!                 switchedCH = 1;
!                 #if DEBUG_CLUSTERING
!                     if(nbrId == TOS_LOCAL_ADDRESS) call Leds.greenToggle();
!                     //printNbrList();
!                 #endif
!             } else if(chId != TOS_LOCAL_ADDRESS){
!                 // this node is not a clusterhead
!                 // and receives a neighbor msg from another node that is not a clusterhead
!                 // check if clusterhead is alive
!                 // if not, switch clusterhead
!                 i = 0;
!                 pos = -1;
!                 while (i < numNbrs && pos == -1) {
!                       if (nbrs[i].addr == chId)
!                             pos = i;
!                       i++;
!                 }
! 
! 
!                 if(pos == -1 || ((now.low32 - nbrs[pos].timeStamp.low32 ) > 3*(BEACON_PERIOD+BEACON_RAND))){
!                     // if clusterhead entry not found
!                     // or if not heard from clusterhead for a while
!                     // find a neighbor that is a clusterhead and from whom
!                     // this node has heard from recently, and join its cluster
!                     // if no such clusterhead is found, set itself as clusterhead
!                     nbrId = TOS_LOCAL_ADDRESS;
!                     while (i < numNbrs && nbrId != TOS_LOCAL_ADDRESS) {
!                          if (nbrs[i].addr == nbrs[i].chId &&
!                                 ((now.low32 - nbrs[i].timeStamp.low32 ) <= 2*(BEACON_PERIOD+BEACON_RAND)))
!                             nbrId = nbrs[i].addr;
!                          i++;
!                     }
!                     setCH(nbrId);
!                     switchedCH = 1;
!                     #if DEBUG_CLUSTERING
!                         if(nbrId == TOS_LOCAL_ADDRESS) call Leds.greenToggle();
!                         //printNbrList();
!                     #endif
!                 }
!             }
!         }
!         //for DEBUGGING/////////////////
!         #if DEBUG_CLUSTERING
!         if(switchedCH){
!             //sendClusterMsg(chId);
!             dbg(DBG_USR1, "NeighborListM: switching clusterhead to %i\n", chId);
          }
-         #endif
-         ///////////////////////////
  
-         #if DEBUG_CLUSTERING
-             //dbg(DBG_USR1, "NeighborListM: current cluster head is %i\n", chId);
-         #endif
      #endif
  
--- 453,460 ----
      #if ENABLE_CLUSTERING
  
!         if(!call AddressMgrI.isGW()){
!             determineCluster(m);
          }
  
      #endif
  
***************
*** 808,811 ****
--- 623,630 ----
        nextSendCount = sendCount;
  
+       #if DEBUG_CLUSTERING
+       printNbrList();
+       #endif
+ 
        // fill the message with the neighbor information
        for (i = 0; i < AGILLA_NBR_MSG_SIZE && nextSendCount < numNbrs; i++)
***************
*** 969,972 ****
--- 788,795 ----
  
  
+ /**************************************************************/
+ /*                  Clustering methods                        */
+ /**************************************************************/
+ 
    #if ENABLE_CLUSTERING
  
***************
*** 997,1015 ****
    }
  
    void setCH(uint16_t ch_id){
!       //if(!call AddressMgrI.isGW()){
          if(chId == TOS_LOCAL_ADDRESS){
            // this node is giving up being a clusterhead
            call CHDirControl.stop();
          }
          if(ch_id == TOS_LOCAL_ADDRESS){
            // this node is a new clusterhead
            call CHDirControl.start();
          }
-       //}
        chId = ch_id;
        chSelectTime = call Time.get();
    }
  
  /*
     command uint8_t ClusteringI.getCommRange(){
--- 820,865 ----
    }
  
+ 
+   command result_t ClusteringI.isClusterMember(uint16_t id){
+       uint8_t i;
+       for (i=0; i < numNbrs; i++) {
+             if (nbrs[i].addr == id && nbrs[i].chId != -1 && nbrs[i].chId == chId)
+               return SUCCESS;
+       }
+       return FAIL;
+   }
+ 
+ 
+ 
    void setCH(uint16_t ch_id){
! 
          if(chId == TOS_LOCAL_ADDRESS){
            // this node is giving up being a clusterhead
            call CHDirControl.stop();
+           //#if DEBUG_CLUSTERING
+             call Leds.greenOff();
+           //#endif
          }
          if(ch_id == TOS_LOCAL_ADDRESS){
            // this node is a new clusterhead
            call CHDirControl.start();
+           //#if DEBUG_CLUSTERING
+             call Leds.greenOn();
+           //#endif
          }
        chId = ch_id;
        chSelectTime = call Time.get();
+ 
+       #if DEBUG_CLUSTERING
+         //call ClusteringI.sendClusterDebugMsg();
+         dbg(DBG_USR1, "NeighborListM:setCH [%i] clusterhead set to %i\n", chSelectTime.low32, chId);
+       #endif
+       #if ENABLE_EXP_LOGGING
+         call ExpLoggerI.sendSetCluster(chId);
+       #endif
+ 
    }
  
+ 
  /*
     command uint8_t ClusteringI.getCommRange(){
***************
*** 1017,1058 ****
     }
  */
-   #endif
  
  
! /*  #if DEBUG_CLUSTERING
  
!   event result_t SendClusterMsg.sendDone(TOS_MsgPtr m, result_t success)
    {
        call MessageBufferI.freeMsg(m);
        return SUCCESS;
    }
  
!   event TOS_MsgPtr RcvClusterMsg.receive(TOS_MsgPtr m) {
!       AgillaClusterDebugMsg* cmsg = (AgillaClusterDebugMsg *)m->data;
!       dbg(DBG_USR1, "NeighborListM: received cluster msg at time(%i) from addr(%i)\n", m->time, cmsg->dummy);
        return m;
    }
  
  
!   void sendClusterMsg(int16_t dest){
        TOS_MsgPtr msg;
!       if(dest == -1) return;
        msg = call MessageBufferI.getMsg();
        if (msg != NULL)
        {
          AgillaClusterDebugMsg* cmsg = (AgillaClusterDebugMsg *)msg->data;
!         cmsg->dummy = TOS_LOCAL_ADDRESS;
!         dbg(DBG_USR1, "NeighborListM: sending cluster msg to %i\n", dest);
  
!         if (!call SendClusterMsg.send(dest, sizeof(AgillaClusterDebugMsg), msg))
          {
!           dbg(DBG_USR1, "NeighborListM: ERROR: Unable to send cluster msg.\n");
            call MessageBufferI.freeMsg(msg);
          }
        }
    }
  
  
!   #endif    */
  
  }
--- 867,1058 ----
     }
  */
  
+   inline void determineCluster(TOS_MsgPtr m)
+   {
  
!       int8_t i = 0, pos = -1;
!       uint16_t hopsToGW = NO_GW;
!       uint16_t addr, nbrId;
!       tos_time_t now = call Time.get();
  
!       AgillaBeaconMsg* bmsg = (AgillaBeaconMsg *)m->data;
!       // get hops to GW
!       hopsToGW = call NeighborListI.getGW(&addr);
!       if(hopsToGW != NO_GW){
!           hopsToGW++; // add one hop to get to the neighbor
! 
!           #if DEBUG_CLUSTERING
!           //dbg(DBG_USR1, "NeighborListM:determineCluster: hopsToGW=%i\n", hopsToGW);
!           #endif
!           if(hopsToGW == 1 && chId != addr){
!                   setCH(addr);
!           } else if(chId == -1){
!               // cluster head not yet set
! 
!               if (bmsg->id == bmsg->chId){
!                   // msg is from a clusterhead
!                   setCH(bmsg->id);
!               } else if(hopsToGW % 2 == 0){
!                   setCH(TOS_LOCAL_ADDRESS);
!               } else if((now.low32 - initTime.low32) > 5*(BEACON_PERIOD+BEACON_RAND)){
!                   // if the node has not heard from a clusterhead in a long time
!                   // it should become a clusterhead
!                   setCH(TOS_LOCAL_ADDRESS);
!               }
! 
!           } else if(chId != TOS_LOCAL_ADDRESS){
!                   // This node is not a cluster head
! 
!                   // Check if it should join some other cluster
!                   // The node should change its clusterhead if it has
!                   // not heard from its current cluster head in time T
!                   // OR if the difference in the link quality of the
!                   // node sending the beacon is more than a threshold
!                   // OR if its clusterhead is no more a clusterhead
! 
!                   i = 0;
!                   pos = -1;
!                   while (i < numNbrs && pos == -1) {
!                         if (nbrs[i].addr == chId && nbrs[i].addr == nbrs[i].chId)
!                           pos = i;
!                         i++;
!                   }
! 
!                   /*if(bmsg->id == bmsg->chId && pos != -1 && ((m->lqi - nbrs[pos].linkQuality) > 20)){
!                         setCH(bmsg->id);
!                   } else */
!                   if(pos == -1 || ((now.low32 - nbrs[pos].timeStamp.low32 ) > 5*(BEACON_PERIOD+BEACON_RAND))){
!                       // if clusterhead entry not found
!                       // or if not heard from clusterhead for a while
!                       // or link quality of neighbor is much better
!                       // than link quality of current cluster head
!                       // set neighbor as cluster head
!                       nbrId = TOS_LOCAL_ADDRESS;
!                       i = 0;
!                       while (i < numNbrs && nbrId == TOS_LOCAL_ADDRESS) {
!                           if (nbrs[i].addr != chId && nbrs[i].addr == nbrs[i].chId &&
!                                 ((now.low32 - nbrs[i].timeStamp.low32 ) <= 2*(BEACON_PERIOD+BEACON_RAND)))
!                                 nbrId = nbrs[i].addr;
!                           i++;
!                       }
!                       setCH(nbrId);
!                   }
!             } else {
!                   // this node is a clusterhead
!                   #if DEBUG_CLUSTERING
!                   //dbg(DBG_USR1, "[%i] NeighborListM:determineCluster: Number of clustermembers = %i\n", now.low32, call CHDir.numClusterMembers());
!                   //dbg(DBG_USR1, "[%i] NeighborListM:determineCluster: chSelectTime = %i, 3*(BEACON_PERIOD+BEACON_RAND) = %i\n",
!                   //                                 now.low32, chSelectTime.low32, 3*(BEACON_PERIOD+BEACON_RAND));
!                   #endif
!                   // if after a time period, I see that I don't have any cluster members
!                   // I should stop being a clusterhead and join the neighbor that is one
!                   if(bmsg->id == bmsg->chId && call CHDir.numClusterMembers() == 0 &&
!                           (now.low32 - chSelectTime.low32) > 3*(BEACON_PERIOD+BEACON_RAND)){
! 
!                       // check if there is a clusterhead closer to the GW than
!                       // the node sending the beacon msg
!                       // find a neighbor that is a clusterhead and from whom
!                       // this node has heard from recently, and join its cluster
! 
!                       setCH(bmsg->id);
! 
!                       /*
!                       // commenting this off, to save space
!                       pos = -1;
!                       i = 0;
!                       while (i < numNbrs && pos == -1) {
!                          if (nbrs[i].addr == nbrs[i].chId &&
!                                 ((now.low32 - nbrs[i].timeStamp.low32 ) <= 2*(BEACON_PERIOD+BEACON_RAND))){
!                                 pos = i;
!                          }
!                          i++;
!                       }
!                       if(pos != -1) setCH(nbrs[pos].addr);
!                       */
!                       #if DEBUG_CLUSTERING
!                       //dbg(DBG_USR1, "NeighborListM:determineCluster: pos = %i\n", pos);
!                       //dbg(DBG_USR1, "NeighborListM:determineCluster: 2*(BEACON_PERIOD+BEACON_RAND) = %i\n", 2*(BEACON_PERIOD+BEACON_RAND));
!                       #endif
! 
!                   }
!             }
! 
!           } else {
!             if(chId != -1) setCH(-1);
!           }
!           //for DEBUGGING/////////////////
!           //#if DEBUG_CLUSTERING
!             //dbg(DBG_USR1, "NeighborListM:determineCluster: current cluster head is %i\n", chId);
!             //printNbrList();
!             if(chId == TOS_LOCAL_ADDRESS) call Leds.greenOn(); // this is needed if reset msg sent
!          // #endif
!           ///////////////////////////
!       }
! 
! 
!         /**
!          * This method is copied from MultiHopLQI to adjust the link quality.
!          */
!         /*
!         uint16_t adjustLQI(uint8_t val) {
!             uint16_t result = (80 - (val - 40));
!             result = (((result * result) >> 3) * result) >> 3;
!             return result;
!         }*/
! 
! 
! 
! 
! 
! 
! 
! 
! 
!  #if DEBUG_CLUSTERING
! 
! 
!   event result_t SendClusterDebugMsg.sendDone(TOS_MsgPtr m, result_t success)
    {
+ 
        call MessageBufferI.freeMsg(m);
        return SUCCESS;
    }
  
! 
!   event TOS_MsgPtr RcvClusterDebugMsg.receive(TOS_MsgPtr m) {
!       //AgillaClusterDebugMsg* cmsg = (AgillaClusterDebugMsg *)m->data;
!       //dbg(DBG_USR1, "NeighborListM: received cluster msg at time(%i) from addr(%i)\n", m->time, cmsg->dummy);
        return m;
    }
  
  
!   command void ClusteringI.sendClusterDebugMsg(){
        TOS_MsgPtr msg;
! 
        msg = call MessageBufferI.getMsg();
        if (msg != NULL)
        {
          AgillaClusterDebugMsg* cmsg = (AgillaClusterDebugMsg *)msg->data;
!         cmsg->src = TOS_LOCAL_ADDRESS;
!         cmsg->id = chId;
!         if(chId == TOS_LOCAL_ADDRESS)
!             call CHDir.getBoundingBox(&(cmsg->bounding_box));
!         dbg(DBG_USR1, "NeighborListM: sending cluster debug msg\n");
  
!         if (!call SendClusterDebugMsg.send(TOS_UART_ADDR, sizeof(AgillaClusterDebugMsg), msg))
          {
!           dbg(DBG_USR1, "NeighborListM: ERROR: Unable to send cluster debug msg.\n");
            call MessageBufferI.freeMsg(msg);
          }
        }
+ 
    }
  
  
! 
!   #endif /*DEBUG_CLUSTERING*/
! 
!   #endif /*ENABLE_CLUSTERING*/
! 
  
  }

Index: NeighborListProxy.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/ContextDiscovery/NeighborListProxy.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NeighborListProxy.nc	6 Feb 2006 09:40:39 -0000	1.2
--- NeighborListProxy.nc	7 Apr 2006 01:14:50 -0000	1.3
***************
*** 2,37 ****
  
  /* Agilla - A middleware for wireless sensor networks.
!  * Copyright (C) 2004, Washington University in Saint Louis 
   * By Chien-Liang Fok.
!  * 
!  * Washington University states that Agilla is free software; 
!  * you can redistribute it and/or modify it under the terms of 
!  * the current version of the GNU Lesser General Public License 
   * as published by the Free Software Foundation.
!  * 
!  * Agilla is distributed in the hope that it will be useful, but 
!  * THERE ARE NO WARRANTIES, WHETHER ORAL OR WRITTEN, EXPRESS OR 
!  * IMPLIED, INCLUDING BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 
   * MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.
   *
!  * YOU UNDERSTAND THAT AGILLA IS PROVIDED "AS IS" FOR WHICH NO 
!  * WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. THERE ARE NO 
!  * WARRANTIES AND NO REPRESENTATION THAT AGILLA IS FREE OF 
!  * INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER 
!  * PROPRIETARY RIGHTS.  THERE ARE NO WARRANTIES THAT SOFTWARE IS 
!  * FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS", 
!  * OR OTHER HARMFUL CODE.  
   *
!  * YOU ASSUME THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR 
!  * ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF 
!  * INFORMATION GENERATED USING SOFTWARE. By using Agilla you agree to 
!  * indemnify, defend, and hold harmless WU, its employees, officers and 
!  * agents from any and all claims, costs, or liabilities, including 
!  * attorneys fees and court costs at both the trial and appellate levels 
!  * for any loss, damage, or injury caused by your actions or actions of 
!  * your officers, servants, agents or third parties acting on behalf or 
!  * under authorization from you, as a result of using Agilla. 
   *
!  * See the GNU Lesser General Public License for more details, which can 
   * be found here: http://www.gnu.org/copyleft/lesser.html
   */
--- 2,37 ----
  
  /* Agilla - A middleware for wireless sensor networks.
!  * Copyright (C) 2004, Washington University in Saint Louis
   * By Chien-Liang Fok.
!  *
!  * Washington University states that Agilla is free software;
!  * you can redistribute it and/or modify it under the terms of
!  * the current version of the GNU Lesser General Public License
   * as published by the Free Software Foundation.
!  *
!  * Agilla is distributed in the hope that it will be useful, but
!  * THERE ARE NO WARRANTIES, WHETHER ORAL OR WRITTEN, EXPRESS OR
!  * IMPLIED, INCLUDING BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
   * MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.
   *
!  * YOU UNDERSTAND THAT AGILLA IS PROVIDED "AS IS" FOR WHICH NO
!  * WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. THERE ARE NO
!  * WARRANTIES AND NO REPRESENTATION THAT AGILLA IS FREE OF
!  * INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER
!  * PROPRIETARY RIGHTS.  THERE ARE NO WARRANTIES THAT SOFTWARE IS
!  * FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS",
!  * OR OTHER HARMFUL CODE.
   *
!  * YOU ASSUME THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR
!  * ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF
!  * INFORMATION GENERATED USING SOFTWARE. By using Agilla you agree to
!  * indemnify, defend, and hold harmless WU, its employees, officers and
!  * agents from any and all claims, costs, or liabilities, including
!  * attorneys fees and court costs at both the trial and appellate levels
!  * for any loss, damage, or injury caused by your actions or actions of
!  * your officers, servants, agents or third parties acting on behalf or
!  * under authorization from you, as a result of using Agilla.
   *
!  * See the GNU Lesser General Public License for more details, which can
   * be found here: http://www.gnu.org/copyleft/lesser.html
   */
***************
*** 48,52 ****
  }
  implementation {
!       
    #if OMIT_CONTEXT_DISCOVERY
      components NeighborListDummy as NeighborList;
--- 48,52 ----
  }
  implementation {
! 
    #if OMIT_CONTEXT_DISCOVERY
      components NeighborListDummy as NeighborList;
***************
*** 54,58 ****
      components NeighborListC as NeighborList;
    #endif
!   
    NeighborListI = NeighborList;
  }
--- 54,58 ----
      components NeighborListC as NeighborList;
    #endif
! 
    NeighborListI = NeighborList;
  }



More information about the Tinyos-contrib-commits mailing list