X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=blobdiff_plain;f=tos%2Flib%2Fftsp%2FTimeSyncP.nc;h=6a17381db172e17fc18e04081fc29f3bca3ad3e8;hp=3c3affe83d12528d0d7ef1ece43dfbe316742875;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hpb=adf1de6c009d13b7b52e68535c63b28f59c97400 diff --git a/tos/lib/ftsp/TimeSyncP.nc b/tos/lib/ftsp/TimeSyncP.nc index 3c3affe8..6a17381d 100644 --- a/tos/lib/ftsp/TimeSyncP.nc +++ b/tos/lib/ftsp/TimeSyncP.nc @@ -43,6 +43,7 @@ generic module TimeSyncP(typedef precision_tag) interface TimeSyncAMSend as Send; interface Receive; interface Timer; + interface Random; interface Leds; interface TimeSyncPacket; interface LocalTime as LocalTime; @@ -283,7 +284,7 @@ implementation if( msg->rootID < outgoingMsg->rootID && // jw: after becoming the root ignore other roots messages (in send period) - ~(heartBeats < IGNORE_ROOT_MSG && outgoingMsg->rootID == TOS_NODE_ID) ){ + !(heartBeats < IGNORE_ROOT_MSG && outgoingMsg->rootID == TOS_NODE_ID) ){ outgoingMsg->rootID = msg->rootID; outgoingMsg->seqNum = msg->seqNum; } @@ -316,6 +317,7 @@ implementation if( diff < -16 || diff > 16 ) return msg; #endif + if( (state & STATE_PROCESSING) == 0 && call TimeSyncPacket.isValid(msg)) { message_t* old = processedMsg; @@ -358,9 +360,8 @@ implementation } outgoingMsg->globalTime = globalTime; - #ifdef LOW_POWER_LISTENING - call LowPowerListening.setRxSleepInterval(&outgoingMsgBuffer, LPL_INTERVAL); + call LowPowerListening.setRemoteWakeupInterval(&outgoingMsgBuffer, LPL_INTERVAL); #endif // we don't send time sync msg, if we don't have enough data if( numEntries < ENTRY_SEND_LIMIT && outgoingMsg->rootID != TOS_NODE_ID ){ @@ -414,11 +415,8 @@ implementation } command error_t TimeSyncMode.setMode(uint8_t mode_){ - if (mode == mode_) - return SUCCESS; - if (mode_ == TS_TIMER_MODE){ - call Timer.startPeriodic((uint32_t)1000 * BEACON_RATE); + call Timer.startPeriodic((uint32_t)(896U+(call Random.rand16()&0xFF)) * BEACON_RATE); } else call Timer.stop(); @@ -466,10 +464,9 @@ implementation command error_t StdControl.start() { - mode = TS_TIMER_MODE; heartBeats = 0; outgoingMsg->nodeID = TOS_NODE_ID; - call Timer.startPeriodic((uint32_t)1000 * BEACON_RATE); + call TimeSyncMode.setMode(TS_TIMER_MODE); return SUCCESS; }