interface TimeSyncAMSend<precision_tag,uint32_t> as Send;
interface Receive;
interface Timer<TMilli>;
+ interface Random;
interface Leds;
interface TimeSyncPacket<precision_tag,uint32_t>;
interface LocalTime<precision_tag> as LocalTime;
+
+
+#ifdef LOW_POWER_LISTENING
+ interface LowPowerListening;
+#endif
+
}
}
implementation
IGNORE_ROOT_MSG = 4, // after becoming the root ignore other roots messages (in send period)
ENTRY_VALID_LIMIT = 4, // number of entries to become synchronized
ENTRY_SEND_LIMIT = 3, // number of entries to send sync messages
- ENTRY_THROWOUT_LIMIT = 100, // if time sync error is bigger than this clear the table
+ ENTRY_THROWOUT_LIMIT = 500, // if time sync error is bigger than this clear the table
};
typedef struct TableItem
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;
}
if( diff < -16 || diff > 16 )
return msg;
#endif
+
if( (state & STATE_PROCESSING) == 0
&& call TimeSyncPacket.isValid(msg)) {
message_t* old = processedMsg;
}
outgoingMsg->globalTime = globalTime;
-
+#ifdef LOW_POWER_LISTENING
+ 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 ){
++heartBeats;
}
command error_t TimeSyncMode.setMode(uint8_t mode_){
- if (mode == mode_)
- return SUCCESS;
-
- if (mode_ == TS_USER_MODE){
- call Timer.startPeriodic((uint32_t)1000 * BEACON_RATE);
+ if (mode_ == TS_TIMER_MODE){
+ call Timer.startPeriodic((uint32_t)(896U+(call Random.rand16()&0xFF)) * BEACON_RATE);
}
else
call Timer.stop();
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;
}