enum
{
// minimum wakeup time to catch a transmission in milliseconds
- LISTEN_WAKEUP = 6, // use xxxL if LISTEN_WAKEUP * 10000 > 65535
+ LISTEN_WAKEUP = 6U, // use xxxL if LISTEN_WAKEUP * 10000 > 65535
// extra wakeup time after receiving a message in milliseconds
- AFTER_RECEIVE = 10,
+ AFTER_RECEIVE = 10U,
// extra wakeup time after transmitting a message in milliseconds
- AFTER_TRANSMIT = 10,
+ AFTER_TRANSMIT = 10U,
MIN_SLEEP = 2, // the minimum sleep interval in milliseconds
MAX_SLEEP = 30000, // the maximum sleep interval in milliseconds
event void Timer.fired()
{
- ASSERT( state == LISTEN || state == SLEEP || state == SEND_SUBSEND|| state == SEND_SUBSEND_DONE );
+ ASSERT( state == LISTEN || state == SLEEP || state == SEND_SUBSEND || state == SEND_SUBSEND_DONE );
if( state == LISTEN )
state = SLEEP_SUBSTOP;
post transition();
}
- void sleepIntervalChanged()
- {
- if( (state == LISTEN && sleepInterval == 0) || state == SLEEP )
- {
- call Timer.stop();
- --state;
- post transition();
- }
- }
-
event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len)
{
if( state == SLEEP_SUBSTOP )
post transition();
}
- if( state == LISTEN_SUBSTART || state == SLEEP_TIMER || state == LISTEN )
+ if( state == LISTEN_SUBSTART || state == SLEEP_TIMER || state == SLEEP )
state = SEND_SUBSTART;
else if( state == LISTEN_SUBSTART_DONE )
state = SEND_SUBSTART_DONE;
- else if( state == LISTEN_TIMER || state == SLEEP_SUBSTOP|| state == LISTEN )
+ else if( state == LISTEN_TIMER || state == SLEEP_SUBSTOP || state == LISTEN )
state = SEND_TIMER;
else
return EBUSY;
txMsg = msg;
txLen = len;
txError = FAIL;
+
+ return SUCCESS;
}
command error_t Send.cancel(message_t* msg)
if( state == SEND_SUBSEND )
{
call Timer.stop();
- state = LISTEN_TIMER;
+ state = SEND_DONE;
+ txError = ECANCEL;
post transition();
- // TODO: ask if sendDone should be called after a succesfull cancel
return SUCCESS;
}
+ else if( state == SEND_SUBSEND_DONE )
+ {
+ // we stop sending the message even if SubSend.cancel was not succesfull
+ state = SEND_SUBSEND_DONE_LAST;
+
+ return call SubSend.cancel(txMsg);
+ }
else
return FAIL;
}
else if( dutyCycle <= MIN_DUTY )
return MAX_SLEEP;
- return ((10000 * LISTEN_WAKEUP) / dutyCycle) - LISTEN_WAKEUP;
+ return ((10000U * LISTEN_WAKEUP) / dutyCycle) - LISTEN_WAKEUP;
}
command uint16_t LowPowerListening.sleepIntervalToDutyCycle(uint16_t interval)
else if( interval >= MAX_SLEEP )
return MIN_DUTY;
- return (10000 * LISTEN_WAKEUP) / (LISTEN_WAKEUP + interval);
+ return (10000U * LISTEN_WAKEUP) / (LISTEN_WAKEUP + interval);
}
command void LowPowerListening.setLocalSleepInterval(uint16_t interval)
interval = MAX_SLEEP;
sleepInterval = interval;
- sleepIntervalChanged();
+
+ if( (state == LISTEN && sleepInterval == 0) || state == SLEEP )
+ {
+ call Timer.stop();
+ --state;
+ post transition();
+ }
}
command uint16_t LowPowerListening.getLocalSleepInterval()
command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg)
{
if( ! call PacketSleepInterval.isSet(msg) )
- return 0;
+ return sleepInterval;
return call PacketSleepInterval.get(msg);
}
command void LowPowerListening.setRxDutyCycle(message_t *msg, uint16_t dutyCycle)
{
- call PacketSleepInterval.set(msg,
+ call LowPowerListening.setRxSleepInterval(msg,
call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));
}
command uint16_t LowPowerListening.getRxDutyCycle(message_t *msg)
{
- if( ! call PacketSleepInterval.isSet(msg) )
- return 10000;
-
return call LowPowerListening.sleepIntervalToDutyCycle(
- call PacketSleepInterval.get(msg));
+ call LowPowerListening.getRxSleepInterval(msg));
}
}