provides
{
interface SplitControl;
- interface Send;
- interface Receive;
+ interface BareSend as Send;
+ interface BareReceive as Receive;
interface RadioPacket;
interface LowPowerListening;
uses
{
interface SplitControl as SubControl;
- interface Send as SubSend;
- interface Receive as SubReceive;
+ interface BareSend as SubSend;
+ interface BareReceive as SubReceive;
interface RadioPacket as SubPacket;
interface PacketAcknowledgements;
interface LowPowerListeningConfig as Config;
interface Timer<TMilli>;
+ interface SystemLowPowerListening;
}
}
// minimum wakeup time to catch a transmission in milliseconds
LISTEN_WAKEUP = 6U, // use xxxL if LISTEN_WAKEUP * 10000 > 65535
- // extra wakeup time after receiving a message in milliseconds
- AFTER_RECEIVE = 10U,
-
- // extra wakeup time after transmitting a message in milliseconds
- AFTER_TRANSMIT = 10U,
-
MIN_SLEEP = 2, // the minimum sleep interval in milliseconds
- MAX_SLEEP = 30000, // the maximum sleep interval in milliseconds
- MIN_DUTY = 2, // the minimum duty cycle
};
- uint16_t sleepInterval;
+ uint16_t sleepInterval = LPL_DEF_LOCAL_WAKEUP;
message_t* txMsg;
- uint8_t txLen;
error_t txError;
/*----------------- state machine -----------------*/
}
else if( state == SEND_TIMER )
{
- transmitInterval = call LowPowerListening.getRxSleepInterval(txMsg);
+ transmitInterval = call LowPowerListening.getRemoteWakeupInterval(txMsg);
if( transmitInterval > 0 )
call Timer.startOneShot(transmitInterval);
}
else if( state == SEND_SUBSEND)
{
- txError = call SubSend.send(txMsg, txLen);
+ txError = call SubSend.send(txMsg);
if( txError == SUCCESS )
state = SEND_SUBSEND_DONE;
{
state = LISTEN;
if( sleepInterval > 0 )
- call Timer.startOneShot(AFTER_TRANSMIT);
+ call Timer.startOneShot(call SystemLowPowerListening.getDelayAfterReceive());
signal Send.sendDone(txMsg, txError);
}
post transition();
}
- event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len)
+ event message_t* SubReceive.receive(message_t* msg)
{
if( state == SLEEP_SUBSTOP )
state = LISTEN;
if( state == LISTEN && sleepInterval > 0 )
- call Timer.startOneShot(AFTER_RECEIVE);
+ call Timer.startOneShot(call SystemLowPowerListening.getDelayAfterReceive());
- return signal Receive.receive(msg, payload, len);
+ return signal Receive.receive(msg);
}
- command error_t Send.send(message_t* msg, uint8_t len)
+ command error_t Send.send(message_t* msg)
{
if( state == LISTEN || state == SLEEP )
{
return EBUSY;
txMsg = msg;
- txLen = len;
txError = FAIL;
return SUCCESS;
// TODO: extend the PacketAcknowledgements interface with getAckRequired
if( error != SUCCESS
- || call LowPowerListening.getRxSleepInterval(msg) == 0
+ || call LowPowerListening.getRemoteWakeupInterval(msg) == 0
|| state == SEND_SUBSEND_DONE_LAST
|| (call Config.getAckRequired(msg) && call PacketAcknowledgements.wasAcked(msg)) )
{
post transition();
}
- command uint8_t Send.maxPayloadLength()
- {
- return call SubSend.maxPayloadLength();
- }
-
- command void* Send.getPayload(message_t* msg, uint8_t len)
- {
- return call SubSend.getPayload(msg, len);
- }
-
/*----------------- LowPowerListening -----------------*/
lpl_metadata_t* getMeta(message_t* msg)
return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg);
}
- command uint16_t LowPowerListening.dutyCycleToSleepInterval(uint16_t dutyCycle)
- {
- if( dutyCycle >= 10000 )
- return 0;
- else if( dutyCycle <= MIN_DUTY )
- return MAX_SLEEP;
-
- return ((10000U * LISTEN_WAKEUP) / dutyCycle) - LISTEN_WAKEUP;
- }
-
- command uint16_t LowPowerListening.sleepIntervalToDutyCycle(uint16_t interval)
- {
- if( interval < MIN_SLEEP )
- return 10000;
- else if( interval >= MAX_SLEEP )
- return MIN_DUTY;
-
- return (10000U * LISTEN_WAKEUP) / (LISTEN_WAKEUP + interval);
- }
-
- command void LowPowerListening.setLocalSleepInterval(uint16_t interval)
+ command void LowPowerListening.setLocalWakeupInterval(uint16_t interval)
{
if( interval < MIN_SLEEP )
interval = 0;
- else if( interval > MAX_SLEEP )
- interval = MAX_SLEEP;
sleepInterval = interval;
}
}
- command uint16_t LowPowerListening.getLocalSleepInterval()
+ command uint16_t LowPowerListening.getLocalWakeupInterval()
{
return sleepInterval;
}
- command void LowPowerListening.setLocalDutyCycle(uint16_t dutyCycle)
- {
- call LowPowerListening.setLocalSleepInterval(
- call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));
- }
-
- command uint16_t LowPowerListening.getLocalDutyCycle()
- {
- return call LowPowerListening.sleepIntervalToDutyCycle(sleepInterval);
- }
-
- command void LowPowerListening.setRxSleepInterval(message_t *msg, uint16_t interval)
+ command void LowPowerListening.setRemoteWakeupInterval(message_t *msg, uint16_t interval)
{
if( interval < MIN_SLEEP )
interval = 0;
- else if( interval > MAX_SLEEP )
- interval = MAX_SLEEP;
getMeta(msg)->sleepint = interval;
}
- command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg)
- {
- uint16_t sleepint = getMeta(msg)->sleepint;
-
- return sleepint != 0 ? sleepint : sleepInterval;
- }
-
- command void LowPowerListening.setRxDutyCycle(message_t *msg, uint16_t dutyCycle)
- {
- call LowPowerListening.setRxSleepInterval(msg,
- call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));
- }
-
- command uint16_t LowPowerListening.getRxDutyCycle(message_t *msg)
+ command uint16_t LowPowerListening.getRemoteWakeupInterval(message_t *msg)
{
- return call LowPowerListening.sleepIntervalToDutyCycle(
- call LowPowerListening.getRxSleepInterval(msg));
+ return getMeta(msg)->sleepint;
}
/*----------------- RadioPacket -----------------*/