[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/wustl/apps/Agilla/components/LocationReporter
LocationReporterC.nc, 1.3, 1.4 LocationReporterM.nc, 1.6, 1.7
Chien-Liang Fok
chien-liang at users.sourceforge.net
Wed Apr 5 11:04:44 PDT 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/LocationReporter
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv942/components/LocationReporter
Modified Files:
LocationReporterC.nc LocationReporterM.nc
Log Message:
Index: LocationReporterC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/LocationReporter/LocationReporterC.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** LocationReporterC.nc 27 Mar 2006 00:38:21 -0000 1.3
--- LocationReporterC.nc 5 Apr 2006 18:04:38 -0000 1.4
***************
*** 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
*/
***************
*** 49,53 ****
configuration LocationReporterC {
provides {
! interface StdControl;
interface LocationReporterI;
}
--- 49,53 ----
configuration LocationReporterC {
provides {
! interface StdControl;
interface LocationReporterI;
}
***************
*** 56,67 ****
components LocationReporterM, AgentReceiverC, AddressMgrC, MessageBufferM;
components NetworkInterfaceProxy as NIC, NeighborListProxy;
! components LocationMgrC, SimpleTime, AgentMgrC;
!
StdControl = LocationReporterM;
StdControl = MessageBufferM;
StdControl = AgentReceiverC;
!
LocationReporterI = LocationReporterM;
!
LocationReporterM.Time -> SimpleTime;
LocationReporterM.AgentMgrI -> AgentMgrC;
--- 56,71 ----
components LocationReporterM, AgentReceiverC, AddressMgrC, MessageBufferM;
components NetworkInterfaceProxy as NIC, NeighborListProxy;
! components LocationMgrC, SimpleTime, AgentMgrC /*, LocationSenderM*/;
! #if ENABLE_CLUSTERING
! components NeighborListM;
! components ClusterheadDirectoryM;
! #endif
!
StdControl = LocationReporterM;
StdControl = MessageBufferM;
StdControl = AgentReceiverC;
!
LocationReporterI = LocationReporterM;
!
LocationReporterM.Time -> SimpleTime;
LocationReporterM.AgentMgrI -> AgentMgrC;
***************
*** 71,75 ****
--- 75,84 ----
LocationReporterM.MessageBufferI -> MessageBufferM;
LocationReporterM.AgentReceiverI -> AgentReceiverC;
+ //LocationReporterM.SendLocation -> LocationSenderM;
LocationReporterM.SendLocation -> NIC.SendMsg[AM_AGILLALOCMSG];
LocationReporterM.ReceiveLocation -> NIC.ReceiveMsg[AM_AGILLALOCMSG];
+ #if ENABLE_CLUSTERING
+ LocationReporterM.ClusteringI -> NeighborListM;
+ LocationReporterM.CHDir -> ClusterheadDirectoryM;
+ #endif
}
Index: LocationReporterM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/apps/Agilla/components/LocationReporter/LocationReporterM.nc,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** LocationReporterM.nc 27 Mar 2006 00:38:21 -0000 1.6
--- LocationReporterM.nc 5 Apr 2006 18:04:38 -0000 1.7
***************
*** 45,56 ****
* @author Chien-Liang Fok
*/
! module LocationReporterM
{
! provides
{
! interface StdControl;
interface LocationReporterI;
}
! uses
{
interface Time;
--- 45,56 ----
* @author Chien-Liang Fok
*/
! module LocationReporterM
{
! provides
{
! interface StdControl;
interface LocationReporterI;
}
! uses
{
interface Time;
***************
*** 61,75 ****
interface MessageBufferI;
interface AgentReceiverI;
! interface SendMsg as SendLocation;
! interface ReceiveMsg as ReceiveLocation; // for bouncing results
}
}
! implementation
{
//uint16_t _id;
//bool _died;
!
uint16_t _serial;
!
command result_t StdControl.init()
{
--- 61,95 ----
interface MessageBufferI;
interface AgentReceiverI;
! #if ENABLE_CLUSTERING
! interface ClusteringI;
! interface ClusterheadDirectoryI as CHDir;
! #endif
! //interface LocationSenderI as SendLocation;
! interface SendMsg as SendLocation;
! interface ReceiveMsg as ReceiveLocation;
}
}
! implementation
{
//uint16_t _id;
//bool _died;
!
! /**************************************************************/
! /* Variable declarations */
! /**************************************************************/
!
uint16_t _serial;
!
! /**************************************************************/
! /* Method declarations */
! /**************************************************************/
!
! #if ENABLE_CLUSTERING
! #endif
!
! /**************************************************************/
! /* StdControl */
! /**************************************************************/
!
command result_t StdControl.init()
{
***************
*** 88,117 ****
}
!
/**
* 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 sendMsg(TOS_MsgPtr msg)
! {
if (call AddressMgrI.isGW())
{
#if DEBUG_LOCATION_DIRECTORY
dbg(DBG_USR1, "LocationReporterM: sendMsg(): Sent agent location to BS\n");
! #endif
return call SendLocation.send(TOS_UART_ADDR, sizeof(AgillaLocMsg), 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, "LocationReporterM: sendMsg(): ERROR: No neighbor closer to a gateway.\n");
! return FAIL;
! }
!
return call SendLocation.send(onehop_dest, sizeof(AgillaLocMsg), msg);
}
--- 108,178 ----
}
!
! /**************************************************************/
! /* Helper methods */
! /**************************************************************/
!
!
/**
* 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.
+ *
+ * If clustering is used, then msg is sent to clusterhead, if this node is
+ * not a cluster head. If this node is a clusterhead, msg is sent to GW
+ *
+ * "bounce" determines if the msg should be just forwarded to the GW.
*/
! inline result_t sendMsg(TOS_MsgPtr msg, bool bounce)
! {
!
if (call AddressMgrI.isGW())
{
#if DEBUG_LOCATION_DIRECTORY
dbg(DBG_USR1, "LocationReporterM: sendMsg(): Sent agent location to BS\n");
! #endif
return call SendLocation.send(TOS_UART_ADDR, sizeof(AgillaLocMsg), msg);
} else
{
uint16_t onehop_dest;
!
! #if ENABLE_CLUSTERING
! struct AgillaLocMsg *sMsg = (struct AgillaLocMsg *)msg->data;
!
! // find onehop_dest as the neighbor that is the closest to the clusterhead
! if(call ClusteringI.isClusterHead() || bounce){
! // send msg to GW
! if (call NeighborListI.getGW(&onehop_dest) == NO_GW)
! {
! dbg(DBG_USR1, "LocationReporterM: sendMsg(): ERROR: No neighbor closer to gateway.\n");
! return FAIL;
! }
! #if DEBUG_CLUSTERING
! dbg(DBG_USR1, "LocationReporterM: sendMsg(): Loc msg about agent %i being sent by CH or being bounced via %i!\n", sMsg->agent_id.id, onehop_dest);
! #endif
! } else {
! // send to clusterhead, which should be a neighbor
! if (!call ClusteringI.getClusterHead(&onehop_dest))
! {
! dbg(DBG_USR1, "LocationReporterM: sendMsg(): ERROR: Cluster head could not be obtained.\n");
! return FAIL;
! }
! sMsg->dest = onehop_dest;
! #if DEBUG_CLUSTERING
! dbg(DBG_USR1, "LocationReporterM: sendMsg(): Loc msg about agent %i being sent to CH %i\n", sMsg->agent_id.id, onehop_dest);
! #endif
! }
!
! #else
!
! // 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, "LocationReporterM: sendMsg(): ERROR: No neighbor closer to a gateway.\n");
! return FAIL;
! }
! #endif
!
return call SendLocation.send(onehop_dest, sizeof(AgillaLocMsg), msg);
}
***************
*** 126,147 ****
AgillaAgentContext* context = call AgentMgrI.getContext(aID);
TOS_MsgPtr msg = call MessageBufferI.getMsg();
!
! if (msg != NULL && context != NULL)
{
struct AgillaLocMsg *sMsg = (struct AgillaLocMsg *)msg->data;
!
// fill the location update message
sMsg->agent_id = context->id;
sMsg->agent_type = context->desc.value;
sMsg->seq = _serial++;
!
if (!died)
{
sMsg->src = TOS_LOCAL_ADDRESS;
call LocationMgrI.getLocation(TOS_LOCAL_ADDRESS, &(sMsg->loc));
! sMsg->timestamp = call Time.get();
} else
{
! // An AgillaLocMsg with the src, loc, timestamp, and dest all
// set to 0 indicates that the agent has died.
sMsg->src = 0;
--- 187,208 ----
AgillaAgentContext* context = call AgentMgrI.getContext(aID);
TOS_MsgPtr msg = call MessageBufferI.getMsg();
!
! if (msg != NULL && context != NULL)
{
struct AgillaLocMsg *sMsg = (struct AgillaLocMsg *)msg->data;
!
// fill the location update message
sMsg->agent_id = context->id;
sMsg->agent_type = context->desc.value;
sMsg->seq = _serial++;
! sMsg->dest = TOS_UART_ADDR;
if (!died)
{
sMsg->src = TOS_LOCAL_ADDRESS;
call LocationMgrI.getLocation(TOS_LOCAL_ADDRESS, &(sMsg->loc));
! sMsg->timestamp = call Time.get();
} else
{
! // An AgillaLocMsg with the src, loc, and timestamp all
// set to 0 indicates that the agent has died.
sMsg->src = 0;
***************
*** 150,156 ****
sMsg->timestamp.high32 = 0;
sMsg->timestamp.low32 = 0;
! sMsg->dest = 0;
}
! if (!sendMsg(msg))
call MessageBufferI.freeMsg(msg);
}
--- 211,217 ----
sMsg->timestamp.high32 = 0;
sMsg->timestamp.low32 = 0;
! //sMsg->dest = 0;
}
! if (!sendMsg(msg, FALSE))
call MessageBufferI.freeMsg(msg);
}
***************
*** 158,161 ****
--- 219,227 ----
+
+ /**************************************************************/
+ /* Command and event handlers */
+ /**************************************************************/
+
/**
* This event is signaled whenever a new agent has arrived.
***************
*** 165,201 ****
event void AgentReceiverI.receivedAgent(AgillaAgentContext* context, uint16_t dest)
{
! if (dest == TOS_LOCAL_ADDRESS)
{
! #if DEBUG_LOCATION_DIRECTORY
! dbg(DBG_USR1, "LocationReporterM: receivedAgent(): Sending location update for agent %i...\n",
context->id.id);
! #endif
! doSend(&context->id, FALSE);
}
}
!
command result_t LocationReporterI.agentDied(AgillaAgentID* aid)
{
doSend(aid, TRUE);
return SUCCESS;
}
!
command result_t LocationReporterI.agentChangedDesc(AgillaAgentID* aid)
{
! doSend(aid, FALSE);
return SUCCESS;
}
!
/**
! * Bounces a message off this mote.
*/
! event TOS_MsgPtr ReceiveLocation.receive(TOS_MsgPtr m)
! {
TOS_MsgPtr msg = call MessageBufferI.getMsg();
! if (msg != NULL)
{
! *msg = *m;
! if (!sendMsg(msg))
! call MessageBufferI.freeMsg(msg);
}
return m;
--- 231,381 ----
event void AgentReceiverI.receivedAgent(AgillaAgentContext* context, uint16_t dest)
{
! #if ENABLE_CLUSTERING
! AgillaLocation loc;
! tos_time_t now = call Time.get();
! int8_t agentKnown = 0;
! #endif
!
! if (dest == TOS_LOCAL_ADDRESS)
{
! #if DEBUG_LOCATION_DIRECTORY || DEBUG_CLUSTERING
! dbg(DBG_USR1, "LocationReporterM: receivedAgent(): Sending location update for agent %i...\n",
context->id.id);
! #endif
! #if ENABLE_CLUSTERING
! // check if this node is a clusterhead
! // if it is a CH store the agent in the directory
! // else send a Loc msg to the clusterhead
! if(call AddressMgrI.isGW()){
! // send msg to BS (over UART)
! doSend(&context->id, FALSE);
! } else if(call ClusteringI.isClusterHead()){
! call LocationMgrI.getLocation(TOS_LOCAL_ADDRESS, &loc);
! call CHDir.addAgent(&(context->id), context->desc.value, &loc, &now, &agentKnown);
! if(agentKnown == 0){
! // send msg to GW
! doSend(&context->id, FALSE);
! }
! } else {
! // send msg to clusterhead
! doSend(&context->id, FALSE);
! }
! #else
! doSend(&context->id, FALSE);
! #endif
}
}
!
command result_t LocationReporterI.agentDied(AgillaAgentID* aid)
{
+ #if ENABLE_CLUSTERING
+ #if DEBUG_CLUSTERING
+ dbg(DBG_USR1, "LocationReporterM: (): agent %i died\n", aid->id);
+ #endif
+ if(!call AddressMgrI.isGW() && call ClusteringI.isClusterHead()){
+ #if DEBUG_CLUSTERING
+ dbg(DBG_USR1, "LocationReporterM: Node Is CH; Updating local directory\n");
+ #endif
+ call CHDir.removeAgent(aid);
+ }
+ #endif
doSend(aid, TRUE);
return SUCCESS;
}
!
command result_t LocationReporterI.agentChangedDesc(AgillaAgentID* aid)
{
! #if ENABLE_CLUSTERING
! AgillaLocation loc;
! tos_time_t now = call Time.get();
! int8_t agentKnown = 0;
! AgillaAgentContext* context = call AgentMgrI.getContext(aid);
!
! if(context != NULL){
! #if DEBUG_CLUSTERING
! dbg(DBG_USR1, "LocationReporterM: (): agent %i changed type\n", aid->id);
! #endif
! if(!call AddressMgrI.isGW() && call ClusteringI.isClusterHead()){
! call LocationMgrI.getLocation(TOS_LOCAL_ADDRESS, &loc);
! call CHDir.addAgent(&(context->id), context->desc.value, &loc, &now, &agentKnown);
! }
! // send msg to clusterhead
! doSend(aid, FALSE);
! }
! #else
! doSend(aid, FALSE);
! #endif
return SUCCESS;
}
!
/**
! * Bounces a message off this mote if clustering is not used.
! * If clustering is used, it checks if the msg is destined for this node;
! * If so, this node must be a clusterhead and hence updates its directory.
! * If this node hears about the agent for the first time, or if the agent
! * type has changed, it notifies the BS.
! * If the msg is not destined for this node, it is bounced.
*/
! event TOS_MsgPtr ReceiveLocation.receive(TOS_MsgPtr m)
! {
TOS_MsgPtr msg = call MessageBufferI.getMsg();
! if (msg != NULL)
{
! #if ENABLE_CLUSTERING
! int8_t agentKnown = 0;
! struct AgillaLocMsg *sMsg = (struct AgillaLocMsg *)m->data;
!
! if(!call AddressMgrI.isGW() && sMsg->dest == TOS_LOCAL_ADDRESS){
! #if DEBUG_CLUSTERING
! dbg(DBG_USR1, "LocationReporterM: Received Loc Msg from %i\n", sMsg->src);
! #endif
! // make sure that this node is still a clusterhead
! if(!call ClusteringI.isClusterHead()){
! dbg(DBG_USR1, "LocationReporterM: ReceiveLocation.receive(): ERROR! Not Clusterhead, but received Loc msg for agent %i from src %i\n",
! sMsg->agent_id.id, sMsg->src);
! call MessageBufferI.freeMsg(msg);
! return m;
! }
! if(sMsg->src == 0 && sMsg->loc.x == 0 && sMsg->loc.y ==0){
! // msg indicates that agent is dead; remove agent
! call CHDir.removeAgent(&(sMsg->agent_id));
! // inform GW
! // MODIFYING RECEIVED MESSAGE; CHECK IF THIS IS OK !!!!?????????????
! sMsg->seq = _serial++;
! *msg = *m;
! if (!sendMsg(msg, FALSE)){
! call MessageBufferI.freeMsg(msg);
! }
! } else {
! // add agent
! call CHDir.addAgent(&(sMsg->agent_id), sMsg->agent_type, &(sMsg->loc), &(sMsg->timestamp), &agentKnown);
! if(agentKnown == 0){
! // send msg to GW
! // MODIFYING RECEIVED MESSAGE; CHECK IF THIS IS OK !!!!?????????????
! sMsg->src = TOS_LOCAL_ADDRESS;
! sMsg->seq = _serial++;
! *msg = *m;
! if (!sendMsg(msg, FALSE)){
! call MessageBufferI.freeMsg(msg);
! }
! }
! }
! } else {
! if(call AddressMgrI.isGW() && sMsg->dest == TOS_LOCAL_ADDRESS){
! // MODIFYING RECEIVED MESSAGE; CHECK IF THIS IS OK !!!!?????????????
! sMsg->src = TOS_LOCAL_ADDRESS;
! sMsg->seq = _serial++;
! }
! // bounce the msg
! *msg = *m;
! if (!sendMsg(msg, TRUE)){
! call MessageBufferI.freeMsg(msg);
! }
! }
! #else
! *msg = *m;
! if (!sendMsg(msg, TRUE))
! call MessageBufferI.freeMsg(msg);
! #endif
}
return m;
***************
*** 207,209 ****
--- 387,391 ----
return SUCCESS;
}
+
+
}
More information about the Tinyos-contrib-commits
mailing list