[Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/commstack DBGSendMsg.nc, NONE, 1.1 FilterLocalCommM.nc, NONE, 1.1 GenericCommReallyPromiscuous.nc, NONE, 1.1 GenericCommReallyPromiscuousM.nc, NONE, 1.1 LinkEstimatorComm.nc, NONE, 1.1 LinkEstimatorCommM.nc, NONE, 1.1 LinkEstimatorTaggerCommM.nc, NONE, 1.1 QueueCommand.nc, NONE, 1.1 QueueControl.nc, NONE, 1.1 S4ActiveMessageC.nc, NONE, 1.1 S4CommStack.nc, NONE, 1.1 S4QueuedSendComm.nc, NONE, 1.1 S4QueuedSendM.nc, NONE, 1.1 UARTInterceptComm.nc, NONE, 1.1 UARTInterceptCommM.nc, NONE, 1.1
Tahir Azim
genie1 at users.sourceforge.net
Thu Oct 23 15:22:43 PDT 2008
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/bvr BVR.h, NONE, 1.1 CoordinateTable.h, NONE, 1.1 CoordinateTable.nc, NONE, 1.1 CoordinateTableC.nc, NONE, 1.1 CoordinateTableM.nc, NONE, 1.1 RouteToInterface.nc, NONE, 1.1 S4.h, NONE, 1.1 S4Locator.nc, NONE, 1.1 S4Neighborhood.nc, NONE, 1.1 S4RouterC.nc, NONE, 1.1 S4RouterM.nc, NONE, 1.1 S4StateC.nc, NONE, 1.1 S4StateCommand.nc, NONE, 1.1 S4StateM.nc, NONE, 1.1 S4Topology.nc, NONE, 1.1 S4TopologyC.nc, NONE, 1.1 S4TopologyM.nc, NONE, 1.1 coordinate_table_entry.h, NONE, 1.1 coordinates.h, NONE, 1.1 nexthopinfo.h, NONE, 1.1 topology-old.h, NONE, 1.1 topology.h, NONE, 1.1 topology.sample.testbed.h, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/interfaces BVRSend.h, NONE, 1.1 FreezeThaw.nc, NONE, 1.1 Reset.nc, NONE, 1.1 RoutingTable.nc, NONE, 1.1 S4Receive.nc, NONE, 1.1 S4Send.nc, NONE, 1.1 SelectiveDisseminationInterface.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/commstack
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv29813/commstack
Added Files:
DBGSendMsg.nc FilterLocalCommM.nc
GenericCommReallyPromiscuous.nc
GenericCommReallyPromiscuousM.nc LinkEstimatorComm.nc
LinkEstimatorCommM.nc LinkEstimatorTaggerCommM.nc
QueueCommand.nc QueueControl.nc S4ActiveMessageC.nc
S4CommStack.nc S4QueuedSendComm.nc S4QueuedSendM.nc
UARTInterceptComm.nc UARTInterceptCommM.nc
Log Message:
tos/lib Library files for S4 tinyos 2.x port.
--- NEW FILE: DBGSendMsg.nc ---
module DBGSendMsg {
provides interface BareSendMsg as Send;
provides interface StdControl as Control;
}
implementation {
char* _DBG_MODE = "BVR-mode"; /////////////////////// diff DBG_USR3
bool busy = FALSE;
message_t* msg_ptr;
command error_t Control.init() {
return SUCCESS;
}
command error_t Control.start() {
return SUCCESS;
}
command error_t Control.stop() {
return SUCCESS;
}
command error_t Send.send(message_t* msg) {
uint8_t i;
uint8_t h = offsetof(message_t,data) + msg->length;
dbg("BVR-debug","DBGSendMsg$send: %p\n",msg);
//dbg_clear(_DBG_MODE,"UL: %d %d ",TOS_LOCAL_ADDRESS,tos_state.tos_time / 4000);
dbg_clear(_DBG_MODE,"%d %d ",TOS_LOCAL_ADDRESS,tos_state.tos_time / 4000);
for(i = 0; i < h; i++)
dbg_clear(_DBG_MODE, "%02hhX ", ((uint8_t *)msg)[i]);
dbg_clear(_DBG_MODE, "\n");
return FAIL;
}
}
--- NEW FILE: FilterLocalCommM.nc ---
/* ex: set tabstop=2 shiftwidth=2 expandtab syn=c:*/
/* $Id: FilterLocalCommM.nc,v 1.1 2008/10/23 22:22:40 genie1 Exp $ */
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
includes AM;
module FilterLocalCommM {
provides {
interface StdControl;
interface Init;
/*interface SendMsg[ uint8_t am];
interface ReceiveMsg[uint8_t am];*/
interface AMSend[ uint8_t am];
interface Receive[uint8_t am];
}
uses {
interface StdControl as BottomStdControl;
interface Init as BottomStdControlInit;
interface AMSend as BottomSendMsg[ uint8_t am ];
interface Receive as BottomReceiveMsg[ uint8_t am ];
interface AMPacket;
interface Packet;
}
}
implementation {
bool initialized = FALSE;
command error_t Init.init() {
error_t err = call BottomStdControlInit.init();
initialized = TRUE;
return err;
}
command error_t StdControl.start() {
if (!initialized) {
call Init.init();
}
return call BottomStdControl.start();
}
command error_t StdControl.stop() {
return call BottomStdControl.stop();
}
command error_t AMSend.send[ uint8_t am ]( uint16_t addr, message_t* msg, uint8_t length ) {
dbg("BVR-debug","FilterLocalCommM$AMSend$send am=%d\n", am);
return call BottomSendMsg.send[ am ]( addr, msg, length );
}
command error_t AMSend.cancel[ uint8_t am ]( message_t* msg ) {
return call BottomSendMsg.cancel[ am ]( msg );
}
command void* AMSend.getPayload[ uint8_t am ]( message_t* msg ) {
return call BottomSendMsg.getPayload[ am ]( msg );
}
command uint8_t AMSend.maxPayloadLength[ uint8_t am ]( ) {
return call BottomSendMsg.maxPayloadLength[ am ]( );
}
event void BottomSendMsg.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
dbg("BVR-temp","FilterLocalCommM$sendDone: result:%d\n",success);
signal AMSend.sendDone[ am ]( msg, success );
}
//This is the only thing this module does: it filters messages which are not
//for this node, in case the GenericComm being used is
//GenericCommPromiscuous
event message_t* BottomReceiveMsg.receive[ uint8_t am ](message_t* msg, void* payload, uint8_t len ) {
if (call AMPacket.destination(msg) == call AMPacket.address() || call AMPacket.destination(msg) == TOS_BCAST_ADDR) {
dbg("BVR-debug","FilterLocalCommM: addr:%d. Receive.\n",call AMPacket.destination(msg));
return signal Receive.receive[ am ]( msg, payload, len );
}
dbg("BVR-debug","FilterLocalCommM: addr:%d. Drop.\n", call AMPacket.destination(msg));
return msg;
}
default event void AMSend.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
return;
}
default event message_t* Receive.receive[ uint8_t am ]( message_t* msg, void* payload, uint8_t len) {
return msg;
}
command void* Receive.getPayload[ uint8_t am ]( message_t* msg, uint8_t* len) {
return call Packet.getPayload(msg, len);
}
command uint8_t Receive.payloadLength[ uint8_t am ]( message_t* msg) {
return call Packet.payloadLength(msg);
}
} //end of implementation
--- NEW FILE: GenericCommReallyPromiscuous.nc ---
configuration GenericCommReallyPromiscuous
{
provides interface Init;
provides interface StdControl;
provides interface AMSend[ uint8_t am ];
provides interface Receive[ uint8_t am ];
}
implementation
{
components GenericCommReallyPromiscuousM as Comm
, ActiveMessageC
, new AMSenderC(AM_S4_APP_MSG)
, new AMReceiverC(AM_S4_APP_MSG)
, new AMSenderC(AM_S4_BEACON_MSG) as AMBeaconSenderC
, new AMReceiverC(AM_S4_BEACON_MSG) as AMBeaconReceiverC
, new AMSenderC(AM_LE_REVERSE_LINK_ESTIMATION_MSG) as AMLESenderC
, new AMReceiverC(AM_LE_REVERSE_LINK_ESTIMATION_MSG) as AMLEReceiverC
, new AMSenderC(AM_DV_MSG) as AMDVSenderC
, new AMReceiverC(AM_DV_MSG) as AMDVReceiverC
#if defined(PLATFORM_MICA2) || defined (PLATFORM_MICA2DOT)
, CC1000RadioC as RadioC
#endif
;
Init = Comm;
StdControl = Comm;
AMSend = Comm;
Receive = Comm;
//Comm.BottomStdControl -> BottomComm;
Comm.BottomSendMsg[AM_S4_APP_MSG] -> AMSenderC;
Comm.BottomReceiveMsg[AM_S4_APP_MSG] -> AMReceiverC;
Comm.BottomSendMsg[AM_S4_BEACON_MSG] -> AMBeaconSenderC;
Comm.BottomReceiveMsg[AM_S4_BEACON_MSG] -> AMBeaconReceiverC;
Comm.BottomSendMsg[AM_LE_REVERSE_LINK_ESTIMATION_MSG] -> AMLESenderC;
Comm.BottomReceiveMsg[AM_LE_REVERSE_LINK_ESTIMATION_MSG] -> AMLEReceiverC;
Comm.BottomSendMsg[AM_DV_MSG] -> AMDVSenderC;
Comm.BottomReceiveMsg[AM_DV_MSG] -> AMDVReceiverC;
Comm.Packet -> AMSenderC.Packet;
Comm.Acks-> ActiveMessageC;
#if defined(PLATFORM_MICA2) || defined(PLATFORM_MICA2DOT)
Comm.MacControl -> RadioC;
#endif
}
--- NEW FILE: GenericCommReallyPromiscuousM.nc ---
module GenericCommReallyPromiscuousM {
provides {
interface Init;
interface StdControl;
interface AMSend[ uint8_t am];
interface Receive[uint8_t am];
}
uses {
interface Packet;
interface StdControl as BottomStdControl;
interface AMSend as BottomSendMsg[ uint8_t am ];
interface Receive as BottomReceiveMsg[ uint8_t am ];
interface PacketAcknowledgements as Acks;
#if defined(PLATFORM_MICA2) || defined (PLATFORM_MICA2DOT)
interface MacControl;
#endif
}
}
implementation {
bool initialized = FALSE;
command error_t Init.init() {
initialized = TRUE;
return SUCCESS;
}
command error_t StdControl.start() {
error_t ok;
if (!initialized) {
call Init.init();
}
//ok = call BottomStdControl.start();
#if defined(PLATFORM_MICA2) || defined (PLATFORM_MICA2DOT)
call MacControl.enableAck();
#endif
return ok;
}
command error_t StdControl.stop() {
//return call BottomStdControl.stop();
return SUCCESS;
}
command error_t AMSend.send[ uint8_t am ]( uint16_t addr, message_t* msg, uint8_t length ) {
error_t err;
err = call BottomSendMsg.send[ am ]( addr, msg, length );
dbg("S4-debug", "Called GenericCommReallyPromiscuousM.AMSend.send with args(am=%d): %d, msg=%x, %d, ret val=%d, time=%s \n",
am, addr, msg, length, err, sim_time_string());
return err;
}
default command error_t BottomSendMsg.send[ uint8_t am ]( uint16_t addr, message_t* msg, uint8_t length ) {
return SUCCESS;
}
event void BottomSendMsg.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
dbg("S4-debug", "Called GenericCommReallyPromiscuousM.AMSend.sendDone with args(am=%d): msg, %d\n",
am, success);
signal AMSend.sendDone[ am ]( msg, success );
}
event message_t* BottomReceiveMsg.receive[ uint8_t am ]( message_t* msg, void* payload, uint8_t len ) {
if (am == AM_S4_APP_MSG)
dbg("BVR", "Called GenericCommReallyPromiscuousM.Receive.receive with args(am=%d): time=%s\n",
am, sim_time_string());
return signal Receive.receive[ am ]( msg, payload, len );
}
default event void AMSend.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
return ;
}
default event message_t* Receive.receive[ uint8_t am ]( message_t* msg, void* payload, uint8_t len) {
return msg;
}
command error_t AMSend.cancel[uint8_t id]( message_t* msg){
return call BottomSendMsg.cancel[id](msg);
}
command void* AMSend.getPayload[uint8_t id]( message_t* msg){
return call BottomSendMsg.getPayload[id](msg);
}
command uint8_t AMSend.maxPayloadLength[uint8_t id]( ){
return call BottomSendMsg.maxPayloadLength[id]();
}
command void* Receive.getPayload[ uint8_t am ]( message_t* msg, uint8_t* len) {
return call Packet.getPayload(msg, len);
}
command uint8_t Receive.payloadLength[ uint8_t am ]( message_t* msg) {
return call Packet.payloadLength(msg);
}
} //end of implementation
--- NEW FILE: LinkEstimatorComm.nc ---
configuration LinkEstimatorComm
{
provides {
interface Init;
interface StdControl;
interface AMSend[ uint8_t am ];
interface Receive[ uint8_t am ];
interface FreezeThaw;
}
uses {
interface Init as BottomStdControlInit;
interface StdControl as BottomStdControl;
interface AMSend as BottomSendMsg[uint8_t id];
interface Receive as BottomReceiveMsg[uint8_t id];
}
}
implementation
{
components LinkEstimatorCommM as Comm
, new TimerMilliC() as MinRateTimer
, LinkEstimatorC as LinkEstimator
, RandomLfsrC as Random
#ifdef TOSSIM
#else
, CC2420PacketC ///extra
#endif
#ifdef SERIAL_LOGGING
, new SerialAMSenderC(BVR_UART_ADDR) //extra
#endif
, S4ActiveMessageC //extra
, ActiveMessageC //extra
;
Init = Comm;
StdControl = Comm;
AMSend = Comm;
Receive = Comm;
Comm.BottomStdControlInit = BottomStdControlInit;
Comm.BottomStdControl = BottomStdControl;
Comm.BottomSendMsg = BottomSendMsg;
Comm.BottomReceiveMsg = BottomReceiveMsg;
FreezeThaw = Comm;
Comm.LinkEstimator -> LinkEstimator;
Comm.LinkEstimatorControl -> LinkEstimator;
Comm.LinkEstimatorControlInit -> LinkEstimator; ///extra
#ifdef TOSSIM
#else
Comm.CC2420Packet -> CC2420PacketC;///extra
#endif
Comm.Packet -> ActiveMessageC;///extra
Comm.AMPacket -> ActiveMessageC;///extra
#ifdef SERIAL_LOGGING
Comm.SerialActiveMessagePacket -> SerialAMSenderC.AMPacket;///extra
Comm.SerialAMSend -> SerialAMSenderC.AMSend;///extra
#endif
Comm.MinRateTimer -> MinRateTimer; ///change
Comm.Random -> Random;
}
--- NEW FILE: LinkEstimatorCommM.nc ---
/* ex: set tabstop=2 shiftwidth=2 expandtab syn=c:*/
/* $Id: LinkEstimatorCommM.nc,v 1.1 2008/10/23 22:22:40 genie1 Exp $ */
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
includes AM;
includes LinkEstimator;
includes ReverseLinkInfo;
module LinkEstimatorCommM {
provides {
interface Init;
interface StdControl;
interface FreezeThaw;
interface AMSend[ uint8_t am];
interface Receive[uint8_t am];
}
uses {
interface StdControl as BottomStdControl;
interface Init as BottomStdControlInit;
interface AMSend as BottomSendMsg[ uint8_t am ];
interface Receive as BottomReceiveMsg[ uint8_t am ];
interface Timer<TMilli> as MinRateTimer;
interface Random;
interface LinkEstimator;
interface StdControl as LinkEstimatorControl;
interface Init as LinkEstimatorControlInit;
#ifdef TOSSIM
#else
interface CC2420Packet;
#endif
interface Packet;
interface AMPacket;
#ifdef SERIAL_LOGGING
interface AMPacket as SerialActiveMessagePacket;
interface AMSend as SerialAMSend;
#endif
}
}
implementation {
bool filter_by_strength;
uint32_t reverse_period;
uint32_t reverse_jitter;
uint8_t reverse_info_index; //This tells the linke estimator at which index to
//start when filling the ReverseLinkInfo.
bool state_is_active;
message_t send_buffer;
ReverseLinkMsg * link_msg_ptr;
ReverseLinkInfo link_info_buf;
bool send_buffer_busy;
uint8_t reverse_msg_length;
bool initialized = FALSE;
//inline functions
inline uint8_t getRssi(message_t* m) {
#ifdef TOSSIM
return *((uint8_t*)(m->metadata)+1);
#else
return call CC2420Packet.getRssi(m);
#endif
}
command error_t Init.init() {
error_t err;
state_is_active = TRUE;
filter_by_strength = LINK_ESTIMATOR_FILTER_BY_STRENGTH;
reverse_info_index = 0;
reverse_period = I_REVERSE_LINK_PERIOD;
reverse_jitter = I_REVERSE_LINK_JITTER;
reverseLinkInfoInit(&link_info_buf);
send_buffer_busy = FALSE;
link_msg_ptr = (ReverseLinkMsg *)&send_buffer.data[0];
reverse_msg_length = sizeof(ReverseLinkMsg);
call LinkEstimatorControlInit.init();
err = call BottomStdControlInit.init();
initialized = TRUE;
return err;
}
command error_t StdControl.start() {
if (!initialized) {
call Init.init();
}
state_is_active = TRUE;
call MinRateTimer.startOneShot(reverse_period);
call LinkEstimatorControl.start();
return call BottomStdControl.start();
}
command error_t StdControl.stop() {
call MinRateTimer.stop();
call LinkEstimatorControl.stop();
return call BottomStdControl.stop();
}
command error_t FreezeThaw.thaw() {
dbg("BVR-debug","LinkEstimatorCommM$thaw\n");
state_is_active = TRUE;
call MinRateTimer.startOneShot(reverse_period);
return SUCCESS;
}
command error_t FreezeThaw.freeze() {
dbg("BVR-debug","LinkEstimatorCommM$freeze\n");
call MinRateTimer.stop();
state_is_active = FALSE;
return SUCCESS;
}
command error_t AMSend.send[ uint8_t am ]( uint16_t addr, message_t* msg, uint8_t length ) {
dbg("BVR-debug","LinkEstimatorCommM$AMSend am=%d\n", am);
return call BottomSendMsg.send[ am ]( addr, msg, length );
}
command void* AMSend.getPayload[ uint8_t am ]( message_t* msg ) {
return call BottomSendMsg.getPayload[ am ]( msg );
}
command uint8_t AMSend.maxPayloadLength[ uint8_t am ]( ) {
return call BottomSendMsg.maxPayloadLength[ am ]( );
}
command error_t AMSend.cancel[ uint8_t am ]( message_t* msg ) {
return call BottomSendMsg.cancel[ am ]( msg );
}
event void BottomSendMsg.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
dbg("BVR-debug","LinkEstimatorCommM$sendDone: result:%d\n",success);
if (msg == &send_buffer) {
dbg("BVR-debug", "LinkEstimatorCommM:sendDone, packet (%p) is from us. result=%s\n",msg,(success==SUCCESS)?"ok":"failure");
send_buffer_busy = FALSE;
return ;
}
return signal AMSend.sendDone[ am ]( msg, success );
}
event message_t* BottomReceiveMsg.receive[ uint8_t am ]( message_t* msg, void* payload, uint8_t len ) {
bool found = FALSE;
bool stored = FALSE;
LEHeader* link_header_ptr = (LEHeader*)&msg->data[0];
uint8_t reverse_quality;
uint8_t reverse_expiration;
uint8_t idx;
if (link_header_ptr->last_hop == call AMPacket.address()) {
dbg("BVR-debug", "LinkEstimatorCommM: received packet from ourselves!!! (%p)\n",msg);
return msg;
}
//this will only use as estimates the packets that have a signal strength
//better than SIGNAL_STRENGTH_FILTER_THRESHOLD
if ( state_is_active &&
(!filter_by_strength ||
(filter_by_strength && getRssi(msg) < SIGNAL_STRENGTH_FILTER_THRESHOLD)) /* &&
link_header_ptr->last_hop != call SerialActiveMessagePacket.address() */) {
dbg("BVR-debug", "LinkEstimatorCommM: packet will be used for link estimation (strength:%d)\n",
getRssi(msg));
link_msg_ptr = (ReverseLinkMsg*)&msg->data[0];
found = (call LinkEstimator.find(link_header_ptr->last_hop, &idx) == SUCCESS);
dbg("BVR-debug", "LinkEstimatorCommM.receive: Found or not %d\n", found);
if (!found) {
stored = (call LinkEstimator.store(link_header_ptr->last_hop,
link_header_ptr->seqno, getRssi(msg), &idx) == SUCCESS);
} else {
call LinkEstimator.updateSeqno(idx, link_header_ptr->seqno);
call LinkEstimator.updateStrength(idx, getRssi(msg));
}
if (found || stored) {
if (am == AM_LE_REVERSE_LINK_ESTIMATION_MSG) {
reverseLinkInfoFromMsg(&link_info_buf, link_msg_ptr);
dbg("S4-debug", "before reverseLinkInfoGetQuality: %x %d rliPtr->num_elements=%d\n", &link_info_buf, call AMPacket.address(), link_info_buf.num_elements);
if (reverseLinkInfoGetQuality(&link_info_buf, call AMPacket.address(),&reverse_quality) == SUCCESS) {
reverse_expiration = (link_info_buf.total_links / link_info_buf.num_elements + 1) * 3;
dbg("BVR-debug","LinkEstimatorCommM: links: %d received: %d expiration:%d\n",
link_info_buf.total_links, link_info_buf.num_elements, reverse_expiration);
call LinkEstimator.updateReverse(idx, reverse_quality, reverse_expiration);
} else {
call LinkEstimator.ageReverse(idx);
}
}
} else {
//msg does not fit in cache. will send up the stack anyway
dbg("BVR-debug","LinkEstimatorCommM: neighbor (%d) cannot be stored now\n",link_header_ptr->last_hop);
}
} else {
dbg("BVR-debug", "LinkEstimatorCommM: packet not used for link estimation (strength:%d)\n",
getRssi(msg));
}
dbg("BVR-debug","LinkEstimatorCommM: received message from:%d seqno:%d AM:%d strength:%d found:%d stored:%d\n",
link_header_ptr->last_hop, link_header_ptr->seqno, am, getRssi(msg),found, stored);
return signal Receive.receive[ am ]( msg, payload, len );
}
event void MinRateTimer.fired() {
int32_t jitter;
uint32_t interval;
dbg("BVR-debug", "LinkEstimatorCommM.MinRateTimer.fired\n");
if (!state_is_active) {
return ;
}
jitter = ((call Random.rand32()) % reverse_jitter) - (reverse_jitter >> 1);
interval = reverse_period + jitter;
//schedule the next timer
call MinRateTimer.startOneShot( interval);
//see if we need to send the reverse beacon, or if we
// must send the reverse link information anyway
dbg("BVR-debug","LinkEstimatorCommM:MinRateTimer$fired: will send packet\n");
//ok, we send a packet if no one will! :)
if (!send_buffer_busy) {
//prepare packet
link_msg_ptr = (ReverseLinkMsg*)&send_buffer.data[0];
reverseLinkInfoReset(&link_info_buf);
call LinkEstimator.setReverseLinkInfo(&link_info_buf,&reverse_info_index);
reverseLinkInfoToMsg(&link_info_buf,link_msg_ptr);
if (call BottomSendMsg.send[AM_LE_REVERSE_LINK_ESTIMATION_MSG](TOS_BCAST_ADDR,
&send_buffer, reverse_msg_length) == SUCCESS) {
send_buffer_busy = TRUE;
dbg("BVR-debug", "LinkEstimatorCommM:MinRateTimer$fired: successfully enqueued send\n");
} else {
dbg("BVR-debug", "LinkEstimatorCommM:MinRateTimer$fired: cannot send, send returned fail\n");
}
} else {
dbg("BVR-debug", "LinkEstimatorCommM:MinRateTimer$fired: cannot send, buffer is busy\n");
}
return ;
}
event error_t LinkEstimator.canEvict(uint16_t addr) {
return SUCCESS;
}
default event void AMSend.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
return ;
}
default event message_t* Receive.receive[ uint8_t am ]( message_t* msg,void* payload, uint8_t len) {
return msg;
}
command void* Receive.getPayload[ uint8_t am ]( message_t* msg, uint8_t* len) {
return call Packet.getPayload(msg, len);
}
command uint8_t Receive.payloadLength[ uint8_t am ]( message_t* msg) {
return call Packet.payloadLength(msg);
}
#ifdef SERIAL_LOGGING
event void SerialAMSend.sendDone( message_t* msg, error_t success ) {
return ;
}
#endif
} //end of implementation
--- NEW FILE: LinkEstimatorTaggerCommM.nc ---
includes AM;
includes LinkEstimator;
module LinkEstimatorTaggerCommM {
provides {
interface Init;
interface StdControl;
interface AMSend[ uint8_t am];
interface Receive[uint8_t am];
}
uses {
interface Packet; /////////// diff
interface AMPacket; //////// diff
interface Init as BottomStdControlInit;
interface StdControl as BottomStdControl;
interface AMSend as BottomSendMsg[ uint8_t am ];
interface Receive as BottomReceiveMsg[ uint8_t am ];
#ifdef SERIAL_LOGGING
interface AMPacket as SerialActiveMessagePkt; /// diff
interface AMSend as SerialAMSend; // diff
#endif
//interface Logger;
}
}
implementation {
uint16_t my_seqno;
bool initialized = FALSE;
command error_t Init.init() {
error_t err;
my_seqno = 1;
err = call BottomStdControlInit.init();
initialized = TRUE;
return err;
}
command error_t StdControl.start() {
if (!initialized) {
call Init.init();
}
return call BottomStdControl.start();
}
command error_t StdControl.stop() {
return call BottomStdControl.stop();
}
//This is the only thing this module does, tag the outgoing packets with an ever increasing
//sequence number and with the local address.
//This is not subject to freezing, because we assume that it is the recipient who
//should freeze the link quality of this node.
command error_t AMSend.send[ uint8_t am ]( uint16_t addr, message_t* msg, uint8_t length) {
LEHeader* link_header_ptr = (LEHeader*)&msg->data[0];
//if (addr != call SerialActiveMessagePkt.address()) {
dbg("BVR-debug","LinkEstimatorCommM$send. Will tag packet with sequence number (%d)\n",my_seqno);
link_header_ptr->last_hop = call AMPacket.address();
link_header_ptr->seqno = my_seqno++;
//}
return call BottomSendMsg.send[ am ]( addr, msg, length );
}
command error_t AMSend.cancel[uint8_t id]( message_t* msg){
return call BottomSendMsg.cancel[id](msg);
}
command void* AMSend.getPayload[uint8_t id]( message_t* msg){
return call BottomSendMsg.getPayload[id](msg);
}
command uint8_t AMSend.maxPayloadLength[uint8_t id]( ){
return call BottomSendMsg.maxPayloadLength[id]();
}
event void BottomSendMsg.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
dbg("BVR-debug","LinkEstimatorCommM$sendDone: result:%d\n",success);
signal AMSend.sendDone[ am ]( msg, success );
}
event message_t* BottomReceiveMsg.receive[ uint8_t am ]( message_t* msg, void* payload, uint8_t len ) {
return signal Receive.receive[ am ]( msg, payload, len );
}
default event void AMSend.sendDone[ uint8_t am ]( message_t* msg, error_t success ) {
return;
}
default event message_t* Receive.receive[ uint8_t am ]( message_t* msg, void* payload, uint8_t len ) {
return msg;
}
command void* Receive.getPayload[ uint8_t am ]( message_t* msg, uint8_t* len) {
return call Packet.getPayload(msg, len);
}
command uint8_t Receive.payloadLength[ uint8_t am ]( message_t* msg) {
return call Packet.payloadLength(msg);
}
#ifdef SERIAL_LOGGING
event void SerialAMSend.sendDone( message_t* msg, error_t success ) {
return;
}
#endif
} //end of implementation
--- NEW FILE: QueueCommand.nc ---
interface QueueCommand {
command error_t setRetransmitCount(uint8_t r);
command uint8_t getRetransmitCount();
}
--- NEW FILE: QueueControl.nc ---
// $Id: QueueControl.nc,v 1.1 2008/10/23 22:22:40 genie1 Exp $
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Author: Phil Buonadonna
* $Revision: 1.1 $
*/
/**
* @author Phil Buonadonna
*/
interface QueueControl {
command uint16_t getOccupancy();
command uint8_t getXmitCount();
}
--- NEW FILE: S4ActiveMessageC.nc ---
module S4ActiveMessageC {
provides {
interface AMPacket;
interface Packet;
interface PacketAcknowledgements;
}
uses {
interface AMPacket as S4AMPacket;
interface Packet as S4Packet;
interface SplitControl;
interface PacketAcknowledgements as S4Acks;
}
}
implementation {
event void SplitControl.startDone(error_t err){
}
event void SplitControl.stopDone(error_t err){
}
command am_addr_t AMPacket.address(){
return call S4AMPacket.address();
}
command am_group_t AMPacket.group(message_t* amsg) {
return call S4AMPacket.group(amsg);
}
command void AMPacket.setGroup(message_t* msg, am_group_t group) {
return call S4AMPacket.setGroup(msg, group);
}
command am_group_t AMPacket.localGroup() {
return call S4AMPacket.localGroup();
}
command am_addr_t AMPacket.destination(message_t *amsg){
return call S4AMPacket.destination(amsg);
}
command bool AMPacket.isForMe(message_t *amsg) {
return call S4AMPacket.isForMe(amsg);
}
command void AMPacket.setDestination(message_t *amsg, am_addr_t addr){
return call S4AMPacket.setDestination(amsg, addr);
}
command void AMPacket.setType(message_t *amsg, am_id_t t){
return call S4AMPacket.setType(amsg, t);
}
command am_id_t AMPacket.type(message_t *amsg){
return call S4AMPacket.type(amsg);
}
command am_addr_t AMPacket.source(message_t *amsg){
return call S4AMPacket.source(amsg);
}
command void AMPacket.setSource(message_t *amsg, am_addr_t addr){
return call S4AMPacket.setSource(amsg, addr);
}
command void Packet.setPayloadLength(message_t *msg, uint8_t len) {
return call S4Packet.setPayloadLength(msg, len);
}
command uint8_t Packet.payloadLength(message_t *msg) {
return call S4Packet.payloadLength(msg);
}
command uint8_t Packet.maxPayloadLength() {
return call S4Packet.maxPayloadLength();
}
command void* Packet.getPayload(message_t *msg, uint8_t *len){
return call S4Packet.getPayload(msg, len);
}
command void Packet.clear(message_t *msg) {
return call S4Packet.clear(msg);
}
async command error_t PacketAcknowledgements.noAck(message_t *msg){
return call S4Acks.noAck(msg);
}
async command error_t PacketAcknowledgements.requestAck(message_t *msg){
return call S4Acks.requestAck(msg);
}
async command bool PacketAcknowledgements.wasAcked(message_t *msg) {
return call S4Acks.wasAcked(msg);
}
}
--- NEW FILE: S4CommStack.nc ---
configuration S4CommStack {
provides {
interface StdControl;
interface AMSend[ uint8_t am];
interface Receive[ uint8_t am];
}
}
implementation {
components
FilterLocalCommM
, LinkEstimatorComm
, S4QueuedSendComm
, LinkEstimatorTaggerCommM
, GenericCommReallyPromiscuous
, S4ActiveMessageC ////////////////////////Extra
, ActiveMessageC ////////////////////////Extra
#ifdef SERIAL_LOGGING
, new SerialAMSenderC(BVR_UART_ADDR) ///////////Extra
#endif
;
/*********** ************/
StdControl = FilterLocalCommM;
AMSend = FilterLocalCommM;
Receive = FilterLocalCommM;
S4ActiveMessageC.S4AMPacket -> ActiveMessageC; ///All BVRActivemessege are extra ????
S4ActiveMessageC.S4Packet -> ActiveMessageC;
S4ActiveMessageC.SplitControl -> ActiveMessageC;
S4ActiveMessageC.S4Acks -> ActiveMessageC;
FilterLocalCommM.BottomStdControlInit -> LinkEstimatorComm.Init;
FilterLocalCommM.BottomStdControl -> LinkEstimatorComm.StdControl;
FilterLocalCommM.BottomSendMsg -> LinkEstimatorComm.AMSend;
FilterLocalCommM.BottomReceiveMsg -> LinkEstimatorComm.Receive;
FilterLocalCommM.AMPacket -> S4ActiveMessageC;////////////////////////??????
LinkEstimatorComm.BottomStdControlInit -> S4QueuedSendComm.Init;
LinkEstimatorComm.BottomStdControl -> S4QueuedSendComm.StdControl;
LinkEstimatorComm.BottomSendMsg -> S4QueuedSendComm.AMSend;
LinkEstimatorComm.BottomReceiveMsg -> S4QueuedSendComm.Receive;
S4QueuedSendComm.BottomStdControl -> LinkEstimatorTaggerCommM.StdControl; ///StdControl int is not used Why????
S4QueuedSendComm.BottomSendMsg -> LinkEstimatorTaggerCommM.AMSend;
S4QueuedSendComm.BottomReceiveMsg -> LinkEstimatorTaggerCommM.Receive;
LinkEstimatorTaggerCommM.BottomStdControlInit -> GenericCommReallyPromiscuous;
LinkEstimatorTaggerCommM.BottomStdControl -> GenericCommReallyPromiscuous;
LinkEstimatorTaggerCommM.BottomSendMsg -> GenericCommReallyPromiscuous;
LinkEstimatorTaggerCommM.BottomReceiveMsg -> GenericCommReallyPromiscuous;
LinkEstimatorTaggerCommM.Packet -> S4ActiveMessageC; /////////Extra added ///place in endif?
LinkEstimatorTaggerCommM.AMPacket -> S4ActiveMessageC; ///Extra added
#ifdef SERIAL_LOGGING
LinkEstimatorTaggerCommM.SerialActiveMessagePkt -> SerialAMSenderC; ///extra added
LinkEstimatorTaggerCommM.SerialAMSend -> SerialAMSenderC.AMSend; ////extra added
#endif
}
--- NEW FILE: S4QueuedSendComm.nc ---
/* ex: set tabstop=2 shiftwidth=2 expandtab syn=c:*/
/* $Id: S4QueuedSendComm.nc,v 1.1 2008/10/23 22:22:40 genie1 Exp $ */
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
configuration S4QueuedSendComm {
provides {
interface Init;
interface StdControl;
interface AMSend[uint8_t id];
interface Receive[uint8_t id];
}
uses {
interface StdControl as BottomStdControl;
interface AMSend as BottomSendMsg[uint8_t id];
interface Receive as BottomReceiveMsg[uint8_t id];
}
}
implementation {
components
S4QueuedSendM as QueuedSendM
, LedsC as Leds /////Diff
, ActiveMessageC ///??????????????????
, S4ActiveMessageC ///??????????????????????
#ifdef SERIAL_LOGGING
, new SerialAMSenderC(AM_RTLOGGINGPACKET) ////??????????????
, SerialActiveMessageC ////?????????????????????????
#endif
, new TimerMilliC() as QueueRetransmitTimer
, RandomLfsrC
////////////////////////////////////////////////Qasim
#ifdef EXP_BACKOFF
,RandomLfsrC as Random
#endif
//////////////////////////////////////////////////////
;
StdControl = BottomStdControl;
StdControl = QueuedSendM;
Init = QueuedSendM;
AMSend = QueuedSendM.QueueSendMsg;
Receive = BottomReceiveMsg;
QueuedSendM.AirSendMsg = BottomSendMsg; /////QueuedSendM.SerialSendMsg= ?????????
QueuedSendM.Leds -> Leds;
QueuedSendM.Acks -> S4ActiveMessageC;/////Additional Added????
#ifndef NO_S4_INTROSPECT
//QueuedSendM.Logger -> Logger;
#endif
/////////////////////////////////////////// Qasim 1/15/2007
#ifdef EXP_BACKOFF
QueuedSendM.QueueRetransmitTimer->QueueRetransmitTimer;
QueuedSendM.Random->RandomLfsrC;
#endif
#ifdef SERIAL_LOGGING
QueuedSendM.SerialActiveMessagePkt -> SerialAMSenderC;
QueuedSendM.SerialAMSend -> SerialAMSenderC;
QueuedSendM.SerialAMControl -> SerialActiveMessageC;
QueuedSendM.SerialPacketInterface -> SerialAMSenderC;
#endif
}
--- NEW FILE: S4QueuedSendM.nc ---
// ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: S4QueuedSendM.nc,v 1.1 2008/10/23 22:22:40 genie1 Exp $
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Phil Buonadonna, David Culler, Matt Welsh
* Authors: Rodrigo Fonseca (some changes for BVR)
*
* $Revision: 1.1 $
*
* This MODULE implements queued send with optional retransmit.
* NOTE: This module only queues POINTERS to the application messages.
* IT DOES NOT COPY THE MESSAGE DATA ITSELF! Applications must maintain
* their own data queues if more than one outstanding message is required.
*
*/
/* This is an altered version of QueuedSendM.nc, not to be used normally.
* It assumes that all unicast packets sent are from CBRouter, and
* logs them as such. This is a cross-layer interaction for the sole purpose
* of performing a test of the link-level retransmission.
* It is QueuedSend that knows about retransmissions, and what we are doing here
* is just a way of associating the packets with a particular multihop message,
* so that we can make the analysis easier.
* Rodrigo, 05/08/04
*/
/**
* @author Phil Buonadonna
* @author David Culler
* @author Matt Welsh
*/
/* To use this without dependencies and interactions with BVR application
* code, define NO_BVR_INTROSPECT */
includes AM;
#ifndef NO_BVR_INTROSPECT
includes BVR;
includes Logging;
#endif
#ifndef SEND_QUEUE_SIZE
#define SEND_QUEUE_SIZE 32
#endif
#ifndef MAX_QUEUE_RETRANSMITS
#define MAX_QUEUE_RETRANSMITS 5
#endif
module S4QueuedSendM {
provides {
interface Init;
interface StdControl;
interface AMSend as QueueSendMsg[uint8_t id];
interface QueueControl;
interface QueueCommand;
}
uses {
interface AMSend as AirSendMsg[uint8_t id];
interface Leds;
interface PacketAcknowledgements as Acks;
#ifdef SERIAL_LOGGING
interface AMPacket as SerialActiveMessagePkt;
interface AMSend as SerialAMSend;
interface SplitControl as SerialAMControl;
interface Packet as SerialPacketInterface;
#endif
#ifndef NO_BVR_INTROSPECT
//interface Logger;
#endif
;
#ifdef EXP_BACKOFF
interface Timer<TMilli> as QueueRetransmitTimer;
interface Random;
#endif
}
}
implementation {
enum {
MESSAGE_QUEUE_SIZE = SEND_QUEUE_SIZE,
MAX_RETRANSMIT_COUNT = MAX_QUEUE_RETRANSMITS,
};
uint8_t max_retransmit_count;
bool initialized = FALSE;
struct _msgq_entry {
uint16_t address;
uint8_t length;
uint8_t id;
uint8_t xmit_count;
message_t* pMsg;
} msgqueue[MESSAGE_QUEUE_SIZE];
uint16_t enqueue_next, dequeue_next;
bool retransmit;
bool fQueueIdle = TRUE;
bool serialPortLocked = FALSE;
message_t loggingPacket;
void sendTestSerialPacket(uint16_t origin, uint16_t dest, uint8_t type) {
#ifndef TOSSIM
#ifdef SERIAL_LOGGING
RTLoggingPacket* sp = (RTLoggingPacket*) call SerialPacketInterface.getPayload(&loggingPacket, NULL);
sp->origin = origin;
sp->dest = dest;
sp->type = type;
if (call SerialAMSend.send(AM_BROADCAST_ADDR, &loggingPacket, sizeof(RTLoggingPacket)) == SUCCESS){
serialPortLocked = TRUE;
}
#endif
#endif
}
command error_t Init.init() {
int i;
max_retransmit_count = MAX_RETRANSMIT_COUNT;
for (i = 0; i < MESSAGE_QUEUE_SIZE; i++) {
msgqueue[i].length = 0;
}
#if PLATFORM_MICA2|| PLATFORM_MICA2DOT || TOSSIM
retransmit = TRUE; // Set to TRUE to enable retransmission
#else
retransmit = TRUE; // Set to FALSE to disable retransmission
#endif
enqueue_next = 0;
dequeue_next = 0;
dbg("BVR-debug", "BVRQueuedSendM.Init.init called\n");
fQueueIdle = TRUE;
initialized = TRUE;
#ifdef SERIAL_LOGGING
call SerialAMControl.start();
#endif
return SUCCESS;
}
command error_t StdControl.start() {
if (!initialized) {
call Init.init();
}
return SUCCESS;
}
command error_t StdControl.stop() {
return SUCCESS;
}
command error_t QueueCommand.setRetransmitCount(uint8_t r) {
max_retransmit_count = r;
return SUCCESS;
}
command uint8_t QueueCommand.getRetransmitCount() {
return max_retransmit_count;
}
/* added by FENG WANG
* implement a simple backoff timeout before each retransmission
* the timeout value depends on the xmit_count
*/
#ifndef EXP_BACKOFF
task void QueueServiceTask() {
uint8_t id;
// Try to send next message (ignore xmit_count)
if (msgqueue[dequeue_next].length != 0) {
id = msgqueue[dequeue_next].id;
//XXX: help to the mac layer: setting the ack bit to 0, just in case
//msgqueue[dequeue_next].pMsg->ack = 0;
if (id != AM_S4_LOG_MSG && msgqueue[dequeue_next].address != TOS_BCAST_ADDR) {
call Acks.requestAck(msgqueue[dequeue_next].pMsg);
}
if ((call AirSendMsg.send[id](msgqueue[dequeue_next].address,
msgqueue[dequeue_next].pMsg,
msgqueue[dequeue_next].length
)) != SUCCESS) {
dbg(DBG_USR2, "QueuedSend: send request failed. stuck in queue\n");
}
else {
}
}
else {
fQueueIdle = TRUE;
}
}
#else
/* Queue data structure
Circular Buffer
enqueue_next indexes first empty entry
buffer full if incrementing enqueue_next would wrap to dequeue
empty if dequeue_next == enqueue_next
or msgqueue[dequeue_next].length == 0
*/
task void QueueServiceTask() {
uint8_t id;
// Try to send next message (ignore xmit_count)
if (msgqueue[dequeue_next].length != 0) {
if (msgqueue[dequeue_next].xmit_count > 0) {
uint16_t delay = call Random.rand32() % (20*msgqueue[dequeue_next].xmit_count) + 1;
call QueueRetransmitTimer.startOneShot(delay);
dbg("TestBVR", "Will retransmit after delay=%d\n", delay);
return;
}
dbg("BVR-debug", "QueuedSend: sending msg (0x%x)\n", dequeue_next);
id = msgqueue[dequeue_next].id;
//XXX: help to the mac layer: setting the ack bit to 0, just in case
//msgqueue[dequeue_next].pMsg->ack = 0;
if (id != AM_S4_LOG_MSG && id != AM_BVR_LOG_MSG && msgqueue[dequeue_next].address != TOS_BCAST_ADDR) {
call Acks.requestAck(msgqueue[dequeue_next].pMsg);
}
if (id == AM_S4_LOG_MSG || id == AM_BVR_LOG_MSG) {
}
else if ((call AirSendMsg.send[id](msgqueue[dequeue_next].address,
msgqueue[dequeue_next].pMsg,
msgqueue[dequeue_next].length)) != SUCCESS) {
dbg("S4-debug", "QueuedSend: send request failed. stuck in queue\n");
}
else {
}
}
else {
fQueueIdle = TRUE;
}
}
event void QueueRetransmitTimer.fired() {
uint8_t id;
S4AppMsg* pS4Msg;
//retransmission timer expires
id = msgqueue[dequeue_next].id;
//XXX: help to the mac layer: setting the ack bit to 0, just in case
//msgqueue[dequeue_next].pMsg->ack = 0;
if (id != AM_S4_LOG_MSG && id != AM_BVR_LOG_MSG && msgqueue[dequeue_next].address != TOS_BCAST_ADDR) {
call Acks.requestAck(msgqueue[dequeue_next].pMsg);
}
if (call AirSendMsg.send[id](msgqueue[dequeue_next].address,msgqueue[dequeue_next].pMsg,
msgqueue[dequeue_next].length
) != SUCCESS) {
dbg("S4-debug", "QueuedSend: send request failed. stuck in queue\n");
}
pS4Msg = (S4AppMsg*) msgqueue[dequeue_next].pMsg->data;
return;
}
#endif
command error_t QueueSendMsg.send[uint8_t id](uint16_t address, message_t* msg, uint8_t length) {
dbg("BVR-debug", "QueuedSend: queue msg enq %d deq %d\n", enqueue_next, dequeue_next);
//don't enqueue UART messages in TOSSIM
if (id == AM_S4_LOG_MSG) {
call Leds.led1Toggle();
#ifdef TOSSIM
return FAIL;
#endif
}
if (((enqueue_next + 1) % MESSAGE_QUEUE_SIZE) == dequeue_next) {
// Fail if queue is full
return FAIL;
}
msgqueue[enqueue_next].address = address;
msgqueue[enqueue_next].length = length;
msgqueue[enqueue_next].id = id;
msgqueue[enqueue_next].pMsg = msg;
msgqueue[enqueue_next].xmit_count = 0;
//msgqueue[enqueue_next].pMsg->ack = 0;
enqueue_next++; enqueue_next %= MESSAGE_QUEUE_SIZE;
dbg("BVR-debug", "QueuedSend: Successfully queued msg to 0x%x, id %d enq %d, deq %d\n", address, id, enqueue_next, dequeue_next);
dbg("BVR-debug", "QueuedSend: X fQueueIdle: %d\n",fQueueIdle);
if (fQueueIdle) {
fQueueIdle = FALSE;
if (post QueueServiceTask() == FAIL)
dbg("BVR-error","QueueSendM: post QueueServiceTask returned error!!\n");
}
return SUCCESS;
}
/* Warning: this is the place that interacts with BVR code, but is not
* essential for the functionality of the module. The purpose of this is
* to log retransmissions in a way that is easy to correlate with the
* application messages. A layering violation for the progress (or
* debugging) of science... */
event void AirSendMsg.sendDone[uint8_t id](message_t* msg, error_t success) {
#ifndef NO_BVR_INTROSPECT
S4AppMsg* pS4Msg;
uint16_t app_msg_id;
pS4Msg = (S4AppMsg*)msg->data;
app_msg_id = *(uint16_t*)(&pS4Msg->type_data.data);
#endif
if (id==AM_S4_APP_MSG)
call Leds.led0Toggle();
dbg("BVR-debug","QueueSendM$AirSendMsg$sendDone: result:%d ack:%d is_BCAST:%d\n",success,call Acks.wasAcked(msg),
(msgqueue[dequeue_next].address == TOS_BCAST_ADDR));
if (msg != msgqueue[dequeue_next].pMsg) {
dbg("BVR-debug","QueuedSendM$AirSendMsg$sendDone: Internal Error: buffer mismatch!\n");
return ; // This would be internal error
}
#ifndef NO_BVR_INTROSPECT
//Logging of retransmissions
if (id == AM_S4_APP_MSG &&
(retransmit) &&
(call Acks.wasAcked(msg) != 0) &&
(msgqueue[dequeue_next].address != TOS_BCAST_ADDR)) {
/* Rodrigo: logging for retransmission test */
}
#endif
// filter out non-queuesend msgs
if ((!retransmit) || (call Acks.wasAcked(msg) != FALSE) || msgqueue[dequeue_next].address == TOS_BCAST_ADDR) {
signal QueueSendMsg.sendDone[id](msg,success);
msgqueue[dequeue_next].length = 0;
dbg("BVR-debug", "qent %d dequeued.\n", dequeue_next);
dequeue_next++; dequeue_next %= MESSAGE_QUEUE_SIZE;
}
else {
//added by Feng Wang on Sept. 22, to log # of retransmissions
if (id == AM_S4_APP_MSG) {
pS4Msg->type_data.rexmit_count++;
}
if ((++(msgqueue[dequeue_next].xmit_count) > max_retransmit_count)) {
// Tried to send too many times, just drop
signal QueueSendMsg.sendDone[id](msg,FAIL);
msgqueue[dequeue_next].length = 0;
dequeue_next++; dequeue_next %= MESSAGE_QUEUE_SIZE;
}
}
// Send next
if (post QueueServiceTask() == FAIL)
dbg("BVR-error","QueueSendM: post QueueServiceTask returned error!!\n");
return ;
}
command uint16_t QueueControl.getOccupancy() {
uint16_t uiOutstanding = enqueue_next - dequeue_next;
uiOutstanding %= MESSAGE_QUEUE_SIZE;
return uiOutstanding;
}
command uint8_t QueueControl.getXmitCount() {
if (msgqueue[dequeue_next].length != 0)
return msgqueue[dequeue_next].xmit_count;
return 0;
}
default event void QueueSendMsg.sendDone[uint8_t id](message_t* msg, error_t success) {
return ;
}
command error_t QueueSendMsg.cancel[uint8_t id]( message_t* msg){
return call AirSendMsg.cancel[id](msg);
}
command void* QueueSendMsg.getPayload[uint8_t id]( message_t* msg){
return call AirSendMsg.getPayload[id](msg);
}
command uint8_t QueueSendMsg.maxPayloadLength[uint8_t id]( ){
return call AirSendMsg.maxPayloadLength[id]();
}
default command error_t AirSendMsg.send[uint8_t id](uint16_t address, message_t* msg, uint8_t length)
{
return SUCCESS;
}
#ifdef SERIAL_LOGGING
event void SerialAMSend.sendDone(message_t* msg, error_t success) {
if (msg == &loggingPacket)
serialPortLocked = FALSE;
}
event void SerialAMControl.startDone(error_t err){
if (err != SUCCESS) {
call SerialAMControl.start();
}
}
event void SerialAMControl.stopDone(error_t err){
if (err != SUCCESS) {
call SerialAMControl.stop();
}
}
#endif
}
--- NEW FILE: UARTInterceptComm.nc ---
configuration UARTInterceptComm
{
provides {
interface StdControl;
interface SendMsg[ uint8_t am ];
interface ReceiveMsg[ uint8_t am ];
}
uses {
interface StdControl as BottomStdControl;
interface SendMsg as BottomSendMsg[ uint8_t am ];
interface ReceiveMsg as BottomReceiveMsg[ uint8_t am ];
}
}
implementation {
components UARTInterceptCommM as Comm
, DBGSendMsg as UARTPacket
;
StdControl = Comm;
SendMsg = Comm;
ReceiveMsg = Comm;
Comm.BottomStdControl = BottomStdControl;
Comm.BottomSendMsg = BottomSendMsg;
Comm.BottomReceiveMsg = BottomReceiveMsg;
Comm.UARTControl -> UARTPacket.Control;
Comm.UARTSend -> UARTPacket.Send;
}
--- NEW FILE: UARTInterceptCommM.nc ---
includes AM;
module UARTInterceptCommM {
provides {
interface StdControl;
interface SendMsg[ uint8_t am];
interface ReceiveMsg[uint8_t am];
}
uses {
interface StdControl as UARTControl;
interface BareSendMsg as UARTSend;
interface StdControl as BottomStdControl;
interface SendMsg as BottomSendMsg[ uint8_t am ];
interface ReceiveMsg as BottomReceiveMsg[ uint8_t am ];
}
}
implementation {
bool initialized = FALSE; ///////////////// diff
command result_t StdControl.init() {
call UARTControl.init();
call BottomStdControl.init();
initialized = TRUE;
return SUCCESS;
}
command result_t StdControl.start() {
if (!initialized ) {
call Init.init();
}
call UARTControl.start();
return call BottomStdControl.start();
}
command result_t StdControl.stop() {
call UARTControl.stop();
return call BottomStdControl.stop();
}
command result_t SendMsg.send[ uint8_t am ]( uint16_t addr, uint8_t length, message_t* msg ) {
result_t ok;
dbg("S4-debug","UARTInterceptCommM$Send: (%p) am:%d addr:%d msg.addr:%d length:%d\n",
msg, am, addr, msg->addr, length);
if (addr == TOS_UART_ADDR) {
msg->type = am;
msg->length = length;
msg->group = TOS_AM_GROUP;
//Address is not set here. UARTLoggerComm should set in case of a UART packet.
//Otherwise, we want to preserve the original destination in the UART packet,
//instead of having it be TOS_UART_ADDRESS. This is the main point of all of this.
ok = call UARTSend.send(msg);
dbg("S4-debug","UARTInterceptCommM$Send to UART: result:%d\n",ok);
} else {
ok = call BottomSendMsg.send[ am ]( addr, length, msg );
dbg("BVR-debug","UARTInterceptCommM$Send to BottomSend: result:%d\n",ok);
}
return ok;
}
event result_t BottomSendMsg.sendDone[ uint8_t am ]( message_t* msg, result_t success ) {
dbg("S4-debug","UARTInterceptCommM$sendDone: (%p) am:%d result:%d\n",msg,am,success);
return signal SendMsg.sendDone[ am ]( msg, success );
}
//This does not do anything.
event result_t UARTSend.sendDone(message_t* msg, result_t success) {
return SUCCESS;
}
//Doesn't do anything special
event message_t* BottomReceiveMsg.receive[ uint8_t am ]( message_t* msg ) {
return signal ReceiveMsg.receive[ am ]( msg );
}
default event result_t SendMsg.sendDone[ uint8_t am ]( message_t* msg, result_t success ) {
return SUCCESS;
}
default event message_t* ReceiveMsg.receive[ uint8_t am ]( message_t* msg ) {
return msg;
}
} //end of implementation
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/bvr BVR.h, NONE, 1.1 CoordinateTable.h, NONE, 1.1 CoordinateTable.nc, NONE, 1.1 CoordinateTableC.nc, NONE, 1.1 CoordinateTableM.nc, NONE, 1.1 RouteToInterface.nc, NONE, 1.1 S4.h, NONE, 1.1 S4Locator.nc, NONE, 1.1 S4Neighborhood.nc, NONE, 1.1 S4RouterC.nc, NONE, 1.1 S4RouterM.nc, NONE, 1.1 S4StateC.nc, NONE, 1.1 S4StateCommand.nc, NONE, 1.1 S4StateM.nc, NONE, 1.1 S4Topology.nc, NONE, 1.1 S4TopologyC.nc, NONE, 1.1 S4TopologyM.nc, NONE, 1.1 coordinate_table_entry.h, NONE, 1.1 coordinates.h, NONE, 1.1 nexthopinfo.h, NONE, 1.1 topology-old.h, NONE, 1.1 topology.h, NONE, 1.1 topology.sample.testbed.h, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/interfaces BVRSend.h, NONE, 1.1 FreezeThaw.nc, NONE, 1.1 Reset.nc, NONE, 1.1 RoutingTable.nc, NONE, 1.1 S4Receive.nc, NONE, 1.1 S4Send.nc, NONE, 1.1 SelectiveDisseminationInterface.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list