[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/wustl/apps/Agilla/components ClusterheadDirectoryM.nc, NONE, 1.1 ExpLoggerC.nc, NONE, 1.1 ExpLoggerM.nc, NONE, 1.1 AgentMgrC.nc, 1.9, 1.10 AgentMgrM.nc, 1.22, 1.23 TimeSyncM.nc, 1.3, 1.4

Chien-Liang Fok chien-liang at users.sourceforge.net
Wed Apr 5 19:10:10 PDT 2006


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

Modified Files:
	AgentMgrC.nc AgentMgrM.nc TimeSyncM.nc 
Added Files:
	ClusterheadDirectoryM.nc ExpLoggerC.nc ExpLoggerM.nc 
Log Message:


--- NEW FILE: ClusterheadDirectoryM.nc ---
// $Id: ClusterheadDirectoryM.nc,v 1.1 2006/04/06 02:10:05 chien-liang Exp $

/* 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
 */
includes Agilla;

/**
 * The Clusterhead Directory maintains clusterhead information like
 * bounding box and agents detected by cluster members and itself. This
 * module handles queries from agents and either replies to the query
 * if it has the required information or passes the query upto the GW
 * and then passes the query reply to cluster member on receiving it
 * from the GW.
 *
 * @author Sangeeta Bhattacharya
 */

module ClusterheadDirectoryM {
  provides {
    interface StdControl;
    interface ClusterheadDirectoryI;
  }
  uses {

    //interface Time;
    interface AddressMgrI;
    interface Timer as ClusterTimer;

    // send cluster id and bounding box to GW node
    interface SendMsg as SendClusterMsg;
    interface ReceiveMsg as RcvClusterMsg;

    // Grid topology
    interface LocationMgrI;
    interface LocationUtilI;
    interface NeighborListI;
    interface ClusteringI;
    interface MessageBufferI;

    interface Leds; // debug
  }
}
implementation {

  typedef struct ClusterMember {
    uint16_t addr;          // 2 bytes: The address of the neighbor
    //uint16_t range;         // 2 bytes: Approximate communication range of the neighbor
  } ClusterMember;          // 4 bytes

  typedef struct AgentInfo{
    AgillaAgentID id;       //  2 bytes: id of agent
    uint16_t type;          //  2 bytes: type of agent
    AgillaLocation loc;     //  4 bytes: location of host that detected the agent
    tos_time_t timestamp;   //  2 bytes: time at which agent was detected
  } AgentInfo;              //  10 bytes


  /**************************************************************/
  /*                    Variable declarations                   */
  /**************************************************************/


  /**
   * An array of cluster member information
   * cl_members[0] through cl_members[numMembers] have valid data.
   */
  ClusterMember cl_members[AGILLA_MAX_NUM_NEIGHBORS];
  uint8_t numMembers;

  /*
   * An array of agent information
   * agents[0] through agents[numAgents] have valid data
   */
  AgentInfo agents[AGILLA_MAX_NUM_AGENTS];
  uint8_t numAgents;

  bool running;
  AgillaRectangle bounding_box;

  /**************************************************************/
  /*                    Method declarations                     */
  /**************************************************************/

  inline result_t sendClusterMsg(TOS_MsgPtr msg);
  void updateBoundingBox(uint16_t nbr/*, uint16_t range*/);
  void recomputeBoundingBox();
  void getBoundingBox(uint16_t id, /*uint16_t range,*/ AgillaRectangle* tempbb);
  //void modifyBoundingBox(AgillaRectangle* tempbb);

  #if DEBUG_CLUSTERING
    void printClusterMemberList()
    {
      uint8_t i;
      dbg(DBG_USR1, "--- Cluster Member list ---\n");
      for (i = 0; i < numMembers; i++) {
        //dbg(DBG_USR1, "\t%i:\tID = %i\trange = %i\n", i, cl_members[i].addr, cl_members[i].range);
        dbg(DBG_USR1, "\t%i:\tID = %i\n", i, cl_members[i].addr);
      }
    }

    void printAgentList()
    {
      uint8_t i;
      dbg(DBG_USR1, "--- Agent list ---\n");
      for (i = 0; i < numAgents; i++) {
        dbg(DBG_USR1, "\t%i:\tID = %i\ttype = %i\tloc = [%i,%i]\ttimestamp=%i\n",
            i, agents[i].id.id, agents[i].type, agents[i].loc.x, agents[i].loc.y, agents[i].timestamp.low32);
      }
    }
  #endif

  /**************************************************************/
  /*                     StdControl                             */
  /**************************************************************/

  command result_t StdControl.init() {
    running = FALSE;
    numMembers = 0;
    bounding_box.llc.x = 0;
    bounding_box.llc.y = 0;
    bounding_box.urc.x = 0;
    bounding_box.urc.y = 0;
    //atomic {
    //  call Random.init();
    //};
    call Leds.init();
    return SUCCESS;
  }

  command result_t StdControl.start() {
      running = TRUE;
      numMembers = 0;
      // update bounding box with own bounding box
      getBoundingBox(TOS_LOCAL_ADDRESS, /*call ClusteringI.getCommRange(),*/ &bounding_box);

      #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "Clusterhead Directory started; bounding box = [(%i,%i),(%i,%i)]\n",
                    bounding_box.llc.x, bounding_box.llc.y, bounding_box.urc.x, bounding_box.urc.y);
      #endif
      call ClusterTimer.start(TIMER_ONE_SHOT, CLUSTER_UPDATE_INTERVAL);
      return SUCCESS;
  }

  command result_t StdControl.stop(){
      running = FALSE;
      call ClusterTimer.stop();
      #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "Clusterhead Directory stopped\n");
      #endif
      return SUCCESS;
  }



  /**************************************************************/
  /*                       TIMERS                               */
  /**************************************************************/

  /**
   * Send a cluster message.
   */
  event result_t ClusterTimer.fired()
  {
    TOS_MsgPtr msgptr = call MessageBufferI.getMsg();
    if (msgptr != NULL && running)
    {
      AgillaClusterMsg* cmsg = (AgillaClusterMsg *)msgptr->data;
      cmsg->id = TOS_LOCAL_ADDRESS;
      cmsg->bounding_box = bounding_box;


      #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "ClusterheadDirectoryM: Sending cluster msg id=%i, bounding_box[(%i,%i),(%i,%i)]\n",
                                cmsg->id, cmsg->bounding_box.llc.x, cmsg->bounding_box.llc.y,
                                cmsg->bounding_box.urc.x, cmsg->bounding_box.urc.y);
      #endif

      if (!sendClusterMsg(msgptr))
      {
        dbg(DBG_USR1, "ClusterheadDirectoryM: ERROR: Unable to send cluster msg.\n");
        call MessageBufferI.freeMsg(msgptr);
      }
    }
    return SUCCESS;
  }


  /**************************************************************/
  /*                Message Handlers                            */
  /**************************************************************/

    /**
     * Figures out what the next hop should be towards the base station and
     * sends the message to that node.  If this node is the gateway, the message
     * is forwarded to the UART.
     */
    inline result_t sendClusterMsg(TOS_MsgPtr msg)
    {
      if (call AddressMgrI.isGW())
      {
        #if DEBUG_CLUSTERING
          dbg(DBG_USR1, "ClusterheadDirectoryM: sendMsg(): Sent cluster msg to BS\n");
        #endif
        return call SendClusterMsg.send(TOS_UART_ADDR, sizeof(AgillaClusterMsg), msg);
      } else {
        uint16_t onehop_dest;

        // Get the one-hop neighbor that is closest to the gateway.
        // If there is no known gateway, abort.
        if (call NeighborListI.getGW(&onehop_dest) == NO_GW)
        {
          dbg(DBG_USR1, "ClusterheadDirectoryM: sendMsg(): ERROR: No neighbor closer to a gateway.\n");
          return FAIL;
        }

        return call SendClusterMsg.send(onehop_dest, sizeof(AgillaClusterMsg), msg);
      }
    } // sendClusterMsg()


    event result_t SendClusterMsg.sendDone(TOS_MsgPtr m, result_t success)
    {
        call MessageBufferI.freeMsg(m);
        return SUCCESS;
    }

    /**
     * Bounces the cluster message off this mote.
     */
    event TOS_MsgPtr RcvClusterMsg.receive(TOS_MsgPtr m)
    {
        // Should I put in a neighbor filter here?
        TOS_MsgPtr msg = call MessageBufferI.getMsg();
        if (msg != NULL)
        {
            *msg = *m;
            if (!sendClusterMsg(msg)) call MessageBufferI.freeMsg(msg);
        }
        return m;
    }

  /**************************************************************/
  /*            ClusterheadDirectory Interface methods          */
  /**************************************************************/


  command result_t ClusterheadDirectoryI.addClusterMember(uint16_t nbr/*, uint16_t range*/){
    int8_t i = 0, indx = -1;

    // Find the index of the cluster member if it is already in the list

    while (i < numMembers && indx == -1) {
        if (cl_members[i].addr == nbr)
          indx = i;
        i++;
    }
    if (indx == -1) {
        indx = numMembers++;
        cl_members[indx].addr = nbr;
        //cl_members[indx].range = range;
        updateBoundingBox(nbr/*, range*/);

        #if DEBUG_CLUSTERING
            dbg(DBG_USR1, "ClusterheadDirectoryI: added new cluster member!\n");
            printClusterMemberList();
        #endif
    }
    /*else {
        cl_members[indx].range = range;
    }*/
    #if DEBUG_CLUSTERING
        if(!running) dbg(DBG_USR1, "ERROR! Trying to add cluster member when not running!\n");
    #endif
    return SUCCESS;
  }

  command result_t ClusterheadDirectoryI.removeClusterMember(uint16_t nbr){
    int8_t i = 0, indx = -1;

    // Find the index of the cluster member
    while (i < numMembers && indx == -1) {
        if (cl_members[i].addr == nbr)
            indx = i;
        i++;
    }
    if (indx != -1) {
        // remove the cluster member by shifting all following members forward
        for (i = indx; i < numMembers-1; i++) {
            cl_members[i] = cl_members[i+1];
        }
        numMembers--;
        #if DEBUG_CLUSTERING
            if(!running) dbg(DBG_USR1, "ERROR! Trying to remove cluster member when not running!\n");
            dbg(DBG_USR1, "ClusterheadDirectoryM: removed cluster member %i\n", nbr);
        #endif
        recomputeBoundingBox();
        return SUCCESS;
    } else {
        dbg(DBG_USR1, "ClusterheadDirectoryM: Could not delete cluster member %i\n", nbr);
        return FAIL;
    }
  }

  command result_t ClusterheadDirectoryI.addAgent(AgillaAgentID* aid, uint16_t atype,
                        AgillaLocation* aloc, tos_time_t* timestamp, int8_t* known){
      int8_t i = 0, indx = -1;
      while (i < numAgents && indx == -1) {
              if (agents[i].id.id == aid->id)
                indx = i;
              i++;
      }
      *known = indx + 1;
      if (indx == -1) {
          indx = numAgents++;
          agents[indx].id = *aid;
      } else {
          if(agents[indx].type != atype)
                *known = 0;
      }
      agents[indx].type = atype;
      agents[indx].loc = *aloc;
      agents[indx].timestamp = *timestamp;
      #if DEBUG_CLUSTERING
        if(!running) dbg(DBG_USR1, "ERROR! Trying to add agent when not running!\n");
        dbg(DBG_USR1, "ClusterheadDirectoryM: added agent %i\n", aid->id);
        printAgentList();
      #endif
      return SUCCESS;
  }

  command result_t ClusterheadDirectoryI.removeAgent(AgillaAgentID* aid){
      int8_t i = 0, indx = -1;

      // Find the index of the agent
      while (i < numAgents && indx == -1) {
          if (agents[i].id.id == aid->id)
              indx = i;
          i++;
      }
      if (indx != -1) {
          // remove the agent by shifting all following agents forward
          for (i = indx; i < numAgents-1; i++) {
              agents[i] = agents[i+1];
          }
          numAgents--;
          #if DEBUG_CLUSTERING
              if(!running) dbg(DBG_USR1, "ERROR! Trying to remove agent when not running!\n");
              dbg(DBG_USR1, "ClusterheadDirectoryM: removed agent %i\n", aid->id);
              printAgentList();
          #endif
          return SUCCESS;
      } else {
          dbg(DBG_USR1, "ClusterheadDirectoryM: Could not delete agent %i\n", aid->id);
          return FAIL;
      }
  }

  command result_t ClusterheadDirectoryI.getAgent(AgillaAgentID* aid, AgillaLocation* aLoc){
    int8_t i = 0;

    // Find the agent
    for(i=0; i < numAgents; i++) {
        if (agents[i].id.id == aid->id){
            *aLoc = agents[i].loc;
            return SUCCESS;
         }
    }
    return FAIL;
  }

  command result_t ClusterheadDirectoryI.getNearestAgent(AgillaAgentID* aid, AgillaLocation* aLoc, uint16_t* aType,
            AgillaAgentID* nearestAgentId, AgillaLocation* nearestAgentLoc)
  {
    int8_t i = 0, indx = -1;
    uint16_t dist = 0xffff, min_dist=0xffff;

    #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "ClusterheadDirectoryI.getNearestAgent: finding nearest agent to loc [%i,%i]\n", aLoc->x, aLoc->y);
    #endif
    // Find the agent
    for(i=0; i < numAgents; i++) {
        if (agents[i].id.id != aid->id && agents[i].type == *aType){
            dist = call LocationUtilI.dist(aLoc, &(agents[i].loc));
            #if DEBUG_CLUSTERING
                dbg(DBG_USR1, "%i[%i,%i] dist = %i\n", agents[i].id.id, agents[i].loc.x, agents[i].loc.y, dist);
            #endif
            if(dist < min_dist){
                min_dist = dist;
                indx = i;
            }
         }
    }
    if(indx == -1) {
        #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "ClusterheadDirectoryI.getNearestAgent: did not find any agent!\n");
        #endif
        return FAIL;
    } else {

        *nearestAgentId = agents[indx].id;
        *nearestAgentLoc = agents[indx].loc;

        #if DEBUG_CLUSTERING
            dbg(DBG_USR1, "ClusterheadDirectoryI.getNearestAgent: Found closest agent %i[%i,%i] dist = %i\n",
                nearestAgentId->id, nearestAgentLoc->x, nearestAgentLoc->y, min_dist);
        #endif

        return SUCCESS;
    }
  }

  command result_t ClusterheadDirectoryI.getAllAgents(AgillaLocMAgentInfo* agentList, uint8_t* num_agents, uint16_t* aType){
      int8_t i = 0, indx = -1;
      if(agentList == NULL) return FAIL;
      // need to check for array overflow!!
      for(i=0; i < numAgents; i++) {
          if(*aType == UNSPECIFIED || agents[i].type == *aType){
            agentList[indx].agent_id.id = agents[i].id.id;
            agentList[indx].loc.x = agents[i].loc.x;
            agentList[indx++].loc.y = agents[i].loc.y;
          }
      }
      if(indx == -1) {
          #if DEBUG_CLUSTERING
            dbg(DBG_USR1, "ClusterheadDirectoryI.getAllAgents: did not find any agent!\n");
          #endif
          return FAIL;
      } else {
          *num_agents = indx;
          #if DEBUG_CLUSTERING
            dbg(DBG_USR1, "ClusterheadDirectoryI.getAllAgents: found %i agents!\n", *num_agents);
            for(i = 0; i < indx; i++){
                dbg(DBG_USR1, "\tAgent %i[%i,%i]\n",
                    agentList[indx].agent_id.id, agentList[indx].loc.x, agentList[indx].loc.y);
            }
          #endif
          return SUCCESS;
      }
  }


  /**************************************************************/
  /*                      Helper methods                        */
  /**************************************************************/

  /*
   * Update bounding box based on bounding box of new cluster member
   */

    void updateBoundingBox(uint16_t nbr/*, uint16_t range*/){
        //AgillaRectangle tempbb;
        AgillaLocation loc;

        call LocationMgrI.getLocation(nbr, &loc);
        //getBoundingBox(nbr, range, &tempbb);
        //modifyBoundingBox(&tempbb);
        if(loc.x < bounding_box.llc.x) bounding_box.llc.x = loc.x;
        if(loc.y < bounding_box.llc.y) bounding_box.llc.y = loc.y;
        if(loc.x > bounding_box.urc.x) bounding_box.urc.x = loc.x;
        if(loc.y > bounding_box.urc.y) bounding_box.urc.y = loc.y;
        #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "ClusterheadDirectoryM: new bounding box: [(%i,%i),(%i,%i)]\n",
                       bounding_box.llc.x, bounding_box.llc.y, bounding_box.urc.x, bounding_box.urc.y);
        #endif
    }

    /*
     * Recompute bounding box
     */

    void recomputeBoundingBox(){
        int16_t i = 0;
        //AgillaRectangle tempbb;

        getBoundingBox(TOS_LOCAL_ADDRESS, /*call ClusteringI.getCommRange(),*/ &bounding_box);
        for (i = 0; i < numMembers; i++) {
            updateBoundingBox(cl_members[i].addr);
        }
        #if DEBUG_CLUSTERING
             dbg(DBG_USR1, "ClusterheadDirectoryM: recomputed bounding box: [(%i,%i),(%i,%i)]\n",
                   bounding_box.llc.x, bounding_box.llc.y, bounding_box.urc.x, bounding_box.urc.y);
        #endif
    }


    inline void getBoundingBox(uint16_t id, /*uint16_t range,*/ AgillaRectangle* tempbb){
        AgillaLocation loc;

        call LocationMgrI.getLocation(id, &loc);
        #if DEBUG_CLUSTERING
           //dbg(DBG_USR1, "ClusterheadDirectoryM.getBoundingBox(): id=%i, loc=[%i,%i], range=%i\n",
           //                         id, loc.x, loc.y, range);
            dbg(DBG_USR1, "ClusterheadDirectoryM.getBoundingBox(): id=%i, loc=[%i,%i]\n",
                                    id, loc.x, loc.y);
        #endif
        /*
        if(loc.x <= range) tempbb->llc.x = 0; else tempbb->llc.x = loc.x - range;
        if(loc.y <= range) tempbb->llc.y = 0; else tempbb->llc.y = loc.y - range;
        tempbb->urc.x = loc.x + range;
        tempbb->urc.y = loc.y + range;
        */
        tempbb->llc.x = loc.x;
        tempbb->llc.y = loc.y;
        tempbb->urc.x = loc.x;
        tempbb->urc.y = loc.y;
        #if DEBUG_CLUSTERING
            dbg(DBG_USR1, "ClusterheadDirectoryM.getBoundingBox(): tempbb[(%i,%i)(%i,%i)]\n",
                            tempbb->llc.x, tempbb->llc.y, tempbb->urc.x, tempbb->urc.y);
        #endif
    }

/*
    void modifyBoundingBox(AgillaRectangle* tempbb){
        #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "ClusterheadDirectoryM.modifyBoundingBox(): tempbb[(%i,%i)(%i,%i)]\n",
                       tempbb->llc.x, tempbb->llc.y, tempbb->urc.x, tempbb->urc.y);
        dbg(DBG_USR1, "ClusterheadDirectoryM.modifyBoundingBox(): before modification bounding_box[(%i,%i)(%i,%i)]\n",
                       bounding_box.llc.x, bounding_box.llc.y, bounding_box.urc.x, bounding_box.urc.y);
        #endif
        if(tempbb->llc.x < bounding_box.llc.x) bounding_box.llc.x = tempbb->llc.x;
        if(tempbb->llc.y < bounding_box.llc.y) bounding_box.llc.y = tempbb->llc.y;
        if(tempbb->urc.x > bounding_box.urc.x) bounding_box.urc.x = tempbb->urc.x;
        if(tempbb->urc.y > bounding_box.urc.y) bounding_box.urc.y = tempbb->urc.y;
        #if DEBUG_CLUSTERING
        dbg(DBG_USR1, "ClusterheadDirectoryM.modifyBoundingBox(): after modification bounding_box[(%i,%i)(%i,%i)]\n",
                       bounding_box.llc.x, bounding_box.llc.y, bounding_box.urc.x, bounding_box.urc.y);
        #endif
    }
*/
}

--- NEW FILE: ExpLoggerC.nc ---
includes ExpLogger;

configuration ExpLoggerC
{
  provides {
    interface ExpLoggerI;
  }  
}
implementation 
{
  components Main, ExpLoggerM, NetworkInterfaceProxy, MessageBufferM, SimpleTime;
  
  ExpLoggerI = ExpLoggerM;
  
  Main.StdControl -> ExpLoggerM;
  Main.StdControl -> MessageBufferM;
  Main.StdControl -> SimpleTime;
  
  ExpLoggerM.SendResults -> NetworkInterfaceProxy.SendMsg[AM_AGILLAEXPRESULTSMSG];
  ExpLoggerM.SendLatency -> NetworkInterfaceProxy.SendMsg[AM_AGILLAEXPLATENCYMSG];
  ExpLoggerM.SendTrace -> NetworkInterfaceProxy.SendMsg[AM_AGILLATRACEMSG];
  ExpLoggerM.ReceiveQuery -> NetworkInterfaceProxy.ReceiveMsg[AM_AGILLAEXPQUERYRESULTSMSG]; 
  ExpLoggerM.MessageBufferI -> MessageBufferM;
  ExpLoggerM.Time -> SimpleTime;;
}

--- NEW FILE: ExpLoggerM.nc ---
module ExpLoggerM
{
  provides {
    interface StdControl;
    interface ExpLoggerI;
  }
  uses {
    interface SendMsg as SendResults;
    interface SendMsg as SendLatency;
    interface SendMsg as SendTrace;
    interface ReceiveMsg as ReceiveQuery;
    interface MessageBufferI;
    interface Time;
  }
}
implementation {
  
  uint16_t _numQueries, _numUpdates;
  
  command result_t StdControl.init() {
    call ExpLoggerI.reset();
    return SUCCESS;
  }

  command result_t StdControl.start() {
    return SUCCESS;
  }
  
  command result_t StdControl.stop() {
    return SUCCESS;
  }  
  
  command result_t ExpLoggerI.reset() {
    _numQueries = 0;
    _numUpdates = 0;
    return SUCCESS;
  }
  
  command result_t ExpLoggerI.incQueryMsg() {
    _numQueries++;
    return SUCCESS;
  }
  
  command result_t ExpLoggerI.incNumUpdates() {
    _numUpdates++;
    return SUCCESS;
  }
  
  command result_t ExpLoggerI.sendQueryLatency(uint32_t latency) {
    TOS_MsgPtr msg = call MessageBufferI.getMsg();
    if (msg != NULL) 
    {
      struct AgillaExpLatencyMsg *lMsg = (struct AgillaExpLatencyMsg *)msg->data;
      lMsg->latency = latency;      
      if (!call SendLatency.send(TOS_UART_ADDR, sizeof(AgillaExpLatencyMsg), msg)) 
        call MessageBufferI.freeMsg(msg);            
    }    
    return SUCCESS;
  }
  
  command result_t ExpLoggerI.sendTrace(uint16_t agentID, uint16_t nodeID, 
    uint16_t action, uint16_t success, AgillaLocation loc)
  {
    TOS_MsgPtr msg = call MessageBufferI.getMsg();
    if (msg != NULL) 
    {
      struct AgillaTraceMsg *traceMsg = (struct AgillaTraceMsg *)msg->data;
      traceMsg->timestamp = call Time.get();
      traceMsg->agentID = agentID;
      traceMsg->nodeID = nodeID;
      traceMsg->action = action;
      traceMsg->success = success;
      traceMsg->loc = loc;
      if (!call SendTrace.send(TOS_UART_ADDR, sizeof(AgillaTraceMsg), msg)) 
        call MessageBufferI.freeMsg(msg);            
    }     
    return SUCCESS;
  }
  
  /**
   * This task is executed when a query is received.
   */
  task void sendResults() {
    TOS_MsgPtr msg = call MessageBufferI.getMsg();
    if (msg != NULL) 
    {
      struct AgillaExpResultsMsg *rMsg = (struct AgillaExpResultsMsg *)msg->data;
      rMsg->numQueries = _numQueries;      
      rMsg->numUpdates = _numUpdates;
      if (!call SendResults.send(TOS_UART_ADDR, sizeof(AgillaExpResultsMsg), msg)) 
        call MessageBufferI.freeMsg(msg);            
    }      
  }
  
  event TOS_MsgPtr ReceiveQuery.receive(TOS_MsgPtr m) 
  {    
    #if DEBUG_EXP_LOGGER
      dbg(DBG_USR1, "ExpLoggerM: Sending Results.\n");    
    #endif  
    post sendResults();
    return m;
  }
  
  event result_t SendLatency.sendDone(TOS_MsgPtr m, result_t success)
  {
    call MessageBufferI.freeMsg(m);
    return SUCCESS;
  }  
  
  event result_t SendResults.sendDone(TOS_MsgPtr m, result_t success)
  {
    call MessageBufferI.freeMsg(m);
    return SUCCESS;
  }    
  
  event result_t SendTrace.sendDone(TOS_MsgPtr m, result_t success)
  {
    call MessageBufferI.freeMsg(m);
    return SUCCESS;
  }    
}

Index: AgentMgrC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/AgentMgrC.nc,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** AgentMgrC.nc	8 Feb 2006 12:27:37 -0000	1.9
--- AgentMgrC.nc	6 Apr 2006 02:10:05 -0000	1.10
***************
*** 104,107 ****
--- 104,112 ----
    components OpStackC, HeapMgrC;  
    components LEDBlinkerC;
+   components LocationMgrC;
+ 
+   #if ENABLE_EXP_LOGGING
+     components ExpLoggerC;
+   #endif    
    
    
***************
*** 124,129 ****
--- 129,139 ----
    AgentMgrM.RxnMgrI -> RxnMgrProxy;
    AgentMgrM.NeighborListI -> NeighborListProxy;
+   AgentMgrM.LocationMgrI -> LocationMgrC;
    
    AgentMgrM.LEDBlinkerI -> LEDBlinkerC;
    //AgentMgrM.RadioControl -> CC1000RadioC.StdControl;  
+ 
+   #if ENABLE_EXP_LOGGING
+     AgentMgrM.ExpLoggerI -> ExpLoggerC;
+   #endif   
  }

Index: AgentMgrM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/AgentMgrM.nc,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** AgentMgrM.nc	17 Mar 2006 01:15:18 -0000	1.22
--- AgentMgrM.nc	6 Apr 2006 02:10:05 -0000	1.23
***************
*** 64,70 ****
--- 64,75 ----
      interface OpStackI;    
      interface RxnMgrI;
+     interface LocationMgrI;
      
      //interface Timer as SimTimer;  // used for TOSSIM   
      interface LEDBlinkerI;
+ 
+     #if ENABLE_EXP_LOGGING
+       interface ExpLoggerI;     
+     #endif     
    }
  }
***************
*** 326,329 ****
--- 331,342 ----
    {        
      if (dest == TOS_LOCAL_ADDRESS) {
+     
+       // send the agent migration trace to the base station
+       #if ENABLE_EXP_LOGGING
+         AgillaLocation loc;
+         call LocationMgrI.getLocation(TOS_LOCAL_ADDRESS, &loc);
+         call ExpLoggerI.sendTrace(context->id.id, TOS_LOCAL_ADDRESS, AGENT_MOVED, SUCCESS, loc);
+       #endif
+       
        /*#ifdef PACKET_SIM_H_INCLUDED      
          uint8_t instr;
***************
*** 341,345 ****
          }
        #endif*/
!       runNewAgent(context);
      } else {
        uint16_t oneHopDest = dest;
--- 354,358 ----
          }
        #endif*/
!       runNewAgent(context);      
      } else {
        uint16_t oneHopDest = dest;

Index: TimeSyncM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/TimeSyncM.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TimeSyncM.nc	22 Mar 2006 01:06:02 -0000	1.3
--- TimeSyncM.nc	6 Apr 2006 02:10:05 -0000	1.4
***************
*** 74,78 ****
    command result_t StdControl.start() 
    {
!     call Timer.start(TIMER_REPEAT, 1024*5);
      return SUCCESS;
    }
--- 74,78 ----
    command result_t StdControl.start() 
    {
!     call Timer.start(TIMER_REPEAT, 1024*10);
      return SUCCESS;
    }



More information about the Tinyos-contrib-commits mailing list