Transcript EnviroTrack

Sown Code Report:
Aggregation
Tracking
Group Management
Pascal A. Vicaire
University of Virginia
[email protected]
Tracking
TrackingM
Sens Bottom
Control Sensing
Sens
GM
GM
Control
Local
Std
Control
Sensing
Leds
Tracking
Timer
Local
Report
Comm
LocalM
SensingC
Group
Management
Std
Control
Group
ManagementC
Leds
LedsC
RC
RC
Base Attribute
Control Station Sensing
Aggr
Std
Control
TimerC
Trip
Wire
TripWire
Report
CommC
Tracking
Timer
Aggr Static
Control Leader
Static
Leader
BackboneC
Base
Station
ReceiveC
Trip
WireM
Aggregation
Std
Control
AggregationC
Bottom
Sensing
Attribute
Sensing
BottomSensingC
Configuration
Provided
Interface
Used
Interface
Module
TrackingC
Tracking
TrackingM
Sens Bottom
Control Sensing
Sens
GM
GM
Control
Local
Std
Control
Sensing
Leds
Tracking
Timer
Local
Report
Comm
LocalM
SensingC
Group
Management
Std
Control
Group
ManagementC
Leds
LedsC
RC
RC
Base Attribute
Control Station Sensing
Aggr
Std
Control
TimerC
Trip
Wire
TripWire
Report
CommC
Tracking
Timer
Aggr Static
Control Leader
Static
Leader
BackboneC
Base
Station
ReceiveC
Trip
WireM
Aggregation
Std
Control
AggregationC
Bottom
Sensing
Attribute
Sensing
BottomSensingC
TrackingC
Configuration
Provided
Interface
Used
Interface
Module
Studied
Modules &
Configurations
setParameters
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
setParameters

…
GM
GM
Control
setParameters
Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
Trip
Wire
init
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
init
Local
Leds
Tracking
Timer
init
ET_POSITION_Sense

Initialize:






Sensing module.
Group management module.
ReportComm module.
Aggregation module.
Leader identifier.
TripWire information.
RC
RC
Base Attribute
Control Station Sensing
init
Aggr
Aggr Static
Control Leader
Trip
Wire
init
whoIsMyLeader
isTripWireBase
start
Tracking
TrackingM
Sens Bottom
Control Sensing
Sens
start

GM
GM
Control
start
Local
getX
Leds
getY
Tracking
Timer
start
Start:






Sensing module.
Group management module.
Tracking timer.
Report module.
Aggregation module.
Localization module.
RC
RC
Base Attribute
Control Station Sensing
start
Aggr
Aggr Static
Control Leader
start
Trip
Wire
stop
Tracking
TrackingM
Sens Bottom
Control Sensing
Sens
stop

GM
GM
Control
stop
Local
Leds
Tracking
Timer
stop
Stop:





Sensing module.
Group management module.
Tracking module.
Report module.
Aggregation module.
RC
RC
Base Attribute
Control Station Sensing
stop
Aggr
Aggr Static
Control Leader
stop
Trip
Wire
Tracking
TrackingM
Sens Bottom
Control Sensing
Sens
GM
GM
Control
Local
GMTask
sendTask
senseTask
aggrTask
post GMTask();
Leds
Tracking
Timer
Aggr
Aggr Static
Control Leader
Periodically
Post group
management task for this
Tracking phase
if (_newSensing) {
ET_sendCount ++;
if (ET_sendCount >=
(REFRESH_INTERVAL/ENVIRO_WORKING_CLOCK)) {
}
RC
Base Attribute
Control Station Sensing
fired
if (!_isBaseLeader) {
_senseCounter++;
if (_senseCounter >=
SENSE_CNT_THRESHOLD/ENVIRO_WORKING_CLOCK) {
_senseCounter = 0;
post SenseTask();
Post sense task
}
If not a base
}
ET_sendCount = 0;
post sendTask();
}
RC
Send Sensing Report
(Only non base motes)
if (_isLeader) {
ET_aggrCount ++;
if (ET_aggrCount >=
(REFRESH_INTERVAL/ENVIRO_WORKING_CLOCK)) {
ET_aggrCount = 0;
post aggrTask();
}
}
Aggregate received
Data if leader
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
Sensing
Done

Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
Aggr
SenseDoneTask
Post sensing done task.
Aggr Static
Control Leader
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
Leader
GM
Control
Local
greenOff
Leds
Tracking
Timer
RC
redOn
redOff




The mote is a group leader if on_off is true.
If it is a leader: green LED off, red LED on.
If it is not a leader: green LED off, red LED off.
Update variables.
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
Member
Local
Leds
greenOff
Tracking
Timer
RC
redOff
greenOn




The mote is a group member if on_off is true.
If it is a member: green LED on, red LED off.
It it is not a member: green LED off, red LED off.
Update variables.
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
receiveMessage
Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
receiveReport
Aggr
Aggr Static
Control Leader
reportPosition
event result_t RC.receiveReport(RCReport *rcReport) {
Base mote reports
dbg(DBG_TRACKING, "TrackingM.RC.receiveReport\n");
to base station
if (_isBaseLeader) {
baseStation_reportPosition_struct *temp;
temp = (baseStation_reportPosition_struct*)(rcReport->data);
call baseStation.reportPosition(temp);
}
} else {
baseStation_reportPosition_struct *temp;
temp = (baseStation_reportPosition_struct*)(rcReport->data);
call GM.receiveMessage(1, temp->GMInformation);
}
return SUCCESS;
Other motes (only leaders can
Receive reports) call the group
Management module
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
aggrSendDone

This function does nothing.
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
ET_Position_senseDone

ET_ATTRIBUTES.ET_POSITION=value.
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
Local
Leds
fireHeartBeart
GMTask

Start group management heart beat.
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
conditionSense
SenseTask

Initiate sensor reading
Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
join
GM
Control
Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
leave
SenseDoneTask
if (_newSensing) {
if (_sensing == FALSE) {
_sensing = TRUE;
call GM.join();
}
}
else {
if (_sensing == TRUE) {
_sensing = FALSE;
if (!_isLeader || _sent) {
call GM.leave();
}
}
}
If there is a new sensing report,
and the mote was not currently sensing,
Seek to join group.
If there is no new sensing report,
And the mote was currently sensing,
Seek to leave group.
Aggr
Aggr Static
Control Leader
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
GM
GM
Control
Local
Leds
Tracking
Timer
RC
RC
Base Attribute
Control Station Sensing
Aggr
Aggr Static
Control Leader
sendData
SendTask


Only non base motes.
Call aggregation module.
Trip
Wire
Tracking
TrackingM
Sens
Sens Bottom
Control Sensing
Leave
aggrTask
GM
GM
Control
Local
Leds
Tracking
Timer
getState
RC
RC
Base Attribute
Control Station Sensing
sendReport
Aggr
Aggr Static
Control Leader
Trip
Wire
aggregate
setState
Only Leader
baseStation_reportPosition_struct temp;
tos_time_t timeStamp;
Aggregate sensing
dbg(DBG_TRACKING, "TrackingM.aggrTask\n");
Data
ET_AGGRATTRIBUTES = call Aggr.aggregate();
_GMInfo = call GM.getState();
if ((ET_AGGRATTRIBUTES.degreeA + _GMInfo.groupAge) <
DEGREE_OF_AGGREGATION) {
if (!_sensing) {
call GM.leave();
}
return;
}
If leader did not receive enough sensing
Data and is not currently sensing,
Leave group without sending report.
_GMInfo.groupAge += ET_AGGRATTRIBUTES.degreeA;
call GM.setState(_GMInfo);
temp.GMInformation = _GMInfo;
temp.position.x = (uint16_t)(ET_AGGRATTRIBUTES.A.x);
temp.position.y = (uint16_t)(ET_AGGRATTRIBUTES.A.y);
call GlobalAbsoluteTimer.getGlobalTime(&timeStamp);
temp.timeStamp = timeStamp.low32/100;
temp.leaderID = TOS_LOCAL_ADDRESS;
temp.degreeOfAggregation = ET_AGGRATTRIBUTES.degreeA;
temp.degreeOfMag = ET_AGGRATTRIBUTES.degreeA;
temp.degreeOfPIR = 0;
temp.degreeOfAccoustic = 0;
if (_isLeader) {
call RC.sendReport((char *)&temp, BROADCAST_TYPE);
_sent = TRUE;
Otherwise, send
if (!_sensing) {
call GM.leave();
Tracking report and leave
}
If not sensing.
}
group
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone
RoutingSendByAddress
[RC_ROUTING_PORT]
RoutingSendByBroadcast
[RC_ROUTING_PORT]
RoutingC
TripWire
RoutingReceive
[RC_ROUTING_PORT]
TLeds
BackboneM
TripWireM
ReportCommC
init
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone

Init some parameters
TripWire
TLeds
start
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone

Does nothing.
TripWire
TLeds
stop
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone

Does nothing.
TripWire
TLeds
sendReport
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone
send

…
send
receive
currentParent
TripWire
TLeds
getCurrentTripWireID
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone
sendDone

No message waiting to be sent.
TripWire
TLeds
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone
sendDone

No message waiting to be sent.
TripWire
TLeds
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone
TripWire
TLeds
receive
ProcessReceiveMessage

Post process receive message if no other message is already waiting to be
processed.
receiveReport
sendReport
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone
ProcessReceiveMessage

If group leader, send report.
TripWire
TLeds
ReportComm
StdControl
ReportCommM
SendMsgByID SendMsgByBct ReceiveRoutingMsg Backbone
TripWire
GenericReceive

Does nothing.
TLeds
baseStation
ReceiveM
SendToUART
TLeds
RoutingSendByAddress
[255]
RoutingC
ReceiveC

Role: debugging messages?
processReport
baseStation
ReceiveM
SendToUART

Return leaderID
TLeds
reportPosition
baseStation
ReceiveM
SendToUART

Does nothing.
TLeds
baseStation
ReceiveM
SendToUART
sendDone

Does nothing.
TLeds
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg
RoutingSendByBroadcast
RoutingReceive
[AGGR_ROUTING_PORT] [AGGR_ROUTING_PORT]
RoutingC
GM
Group
ManagementC
AggregationC
start
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg

Does nothing.
GM
stop
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg

Does nothing.
GM
aggregate
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg


GM
Uses averaging functions to aggregate sensing data.
Return aggregation degree.
aggregationSendDone
sendData
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg
GM
send
dbg(DBG_USR2, "AggregationM.sendData(leaderID:%d)\n", leaderID);
if ((leaderID == TOS_LOCAL_ADDRESS) && !_receivePending)
{
_receivePending = TRUE;
If node is leader,
not send
RxBuffer = report;
do
add();
_receivePending = FALSE;
signal Aggregation.aggrSendDone(SUCCESS);
return SUCCESS;
}
if (!_sendPending){
_sendPending = TRUE;
if ((TxBuffer = (AttrReport*)initRoutingMsg(&_TxMsg,
sizeof(AttrReport))) == 0)
{
dbg(DBG_USR2, "\t\tinitRoutingMsg fail\n");
_sendPending = FALSE;
return FAIL;
}
Otherwise, send by
Broadcast to leader
*TxBuffer = *report;
if (call SendMsgByBct.send(1, &_TxMsg) == FAIL)
{
dbg(DBG_USR2, "\t\tSendMsgByBct.sendto:%d fail\n", leaderID);
_sendPending = FALSE;
return FAIL;
}
dbg(DBG_TEMP, "RSEVENT: %i.%08i: SENDMSG: %d\n", (uint32_t)
(tos_state.tos_time / 4000000), (uint32_t) (tos_state.tos_time %
4000000 * 25), leaderID);
return SUCCESS;
} else {
dbg(DBG_USR2, "\t\t_sendPending fail\n");
return FAIL;
}
aggregationSendDone
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg
sendDone
GM
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg
GM
receive
ProcessReceiveAggr
dbg(DBG_USR2, "AggregationM.ReceiveRoutingMsg.receive\n");
if(!_receivePending) {
TOS_MsgPtr p = _RxMsgP;
_receivePending = TRUE;
_RxMsgP = msg;
if(!post ProcessReceiveAggr())
_receivePending = FALSE;
return p;
}
else {
return msg;
}
Post processReceiveAggr task
If no such task pending.
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg
GM
receiveMessage
ProcessReceiveAggr
dbg(DBG_USR2, "AggregationM.ProcessReceiveAggr task\n");
if ((RxBuffer = (AttrReport*)popFromRoutingMsg(_RxMsgP, sizeof(AttrReport))) ==
0)
{
dbg(DBG_USR2, "\tpopFromRoutingMsg fail\n");
_receivePending = FALSE;
return;
}
Call Group Management
call GM.receiveMessage(2, RxBuffer->GMInformation);
if (RxBuffer->GMInformation.leaderID == TOS_LOCAL_ADDRESS) {
dbg(DBG_USR2, "add!\n");
add();
Message contents added to message
} else {
If node is leader.
dbg(DBG_USR2, "not add!\n");
}
_receivePending = FALSE;
table
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg
GM
leader

Does nothing.
Aggregation
StdControl
AggregationM
SendMsgByBct ReceiveRoutingMsg
GM
member

Does nothing.
Group Management
StdControl
GroupManagementM
Random
RandomLFSR
Local
LocalM
Static
Leader
BackboneM
GroupManagementC
setParameters
Group Management
StdControl
GroupManagementM
Random

…
Local
Static
Leader
init
Group Management
StdControl
GroupManagementM
Random
init
Local
Static
Leader
start
Group Management
StdControl
GroupManagementM
Random
Local
getX
getY
Static
Leader
stop
Group Management
StdControl
GroupManagementM
Random
Local
Static
Leader
fireHeartBeat
Group Management
StdControl
GroupManagementM
Random

Local
Static
Leader
Initiate group management timer.
join
leader
member
Group Management
StdControl
GroupManagementM
Random
rand



Local
Static
Leader
NodeNumber
No status: node becomes member.
Follower: node becomes member.
Leader Candidate: node becomes leader.
leave
leader
member
Group Management
StdControl
GroupManagementM
Random


Local
Static
Leader
Member: node becomes follower.
Leader: node becomes leader candidate.
setState
Group Management
StdControl
GroupManagementM
Random

…
Local
Static
Leader
getState
Group Management
StdControl
GroupManagementM
Random

…
Local
Static
Leader
leader
Group Management
StdControl
GroupManagementM
Random
Local
Static
Leader
ProcessRecuritMessage





None: follower.
Follower: check for group competition.
Member: check for group competition.
Leader candidate: check for group competition.
Leader: check for group competition.
receiveMessage
Group Management
StdControl
GroupManagementM
Random
Local
Static
Leader
ProcessRecuritMessage

Check if already processing such a message.