]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc
Use BareSend/BareReceive instead of Send/Receive to avoid duplication of payload...
[tinyos-2.x.git] / tos / chips / rf2xx / layers / LowPowerListeningLayerP.nc
index fc02621b69af7b9cf6bbfa28a2591427af0ca9f0..0b1720408ad79d49dbedfcec973b7fee28e9afdd 100644 (file)
  */
 
 #include <RadioAssert.h>
+#include <LowPowerListeningLayer.h>
 
 module LowPowerListeningLayerP
 {
        provides
        {
                interface SplitControl;
-               interface Send;
-               interface Receive;
+               interface BareSend as Send;
+               interface BareReceive as Receive;
+               interface RadioPacket;
 
                interface LowPowerListening;
        }
@@ -37,12 +39,12 @@ module LowPowerListeningLayerP
        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 PacketField<uint16_t> as PacketSleepInterval;
-               interface IEEE154Packet2;
                interface PacketAcknowledgements;
+               interface LowPowerListeningConfig as Config;
                interface Timer<TMilli>;
        }
 }
@@ -68,7 +70,6 @@ implementation
        uint16_t sleepInterval;
 
        message_t* txMsg;
-       uint8_t txLen;
        error_t txError;
 
 /*----------------- state machine -----------------*/
@@ -77,22 +78,22 @@ implementation
        {
                OFF = 0,                                        
                OFF_SUBSTOP = 1,                        // must have consecutive indices
-               OFF_SUBSTOP_DONE = 2,           // must have consecutive indices
+               OFF_SUBSTOP_DONE = 2,                   // must have consecutive indices
                OFF_STOP_END = 3,                       // must have consecutive indices
                OFF_START_END = 4,
 
-               LISTEN_SUBSTART = 5,            // must have consecutive indices
-               LISTEN_SUBSTART_DONE = 6,       // must have consecutive indices
+               LISTEN_SUBSTART = 5,                    // must have consecutive indices
+               LISTEN_SUBSTART_DONE = 6,               // must have consecutive indices
                LISTEN_TIMER = 7,                       // must have consecutive indices
-               LISTEN = 8,                                     // must have consecutive indices
+               LISTEN = 8,                             // must have consecutive indices
 
                SLEEP_SUBSTOP = 9,                      // must have consecutive indices
-               SLEEP_SUBSTOP_DONE = 10,        // must have consecutive indices
+               SLEEP_SUBSTOP_DONE = 10,                // must have consecutive indices
                SLEEP_TIMER = 11,                       // must have consecutive indices
-               SLEEP = 12,                                     // must have consecutive indices
+               SLEEP = 12,                             // must have consecutive indices
 
                SEND_SUBSTART = 13,                     // must have consecutive indices
-               SEND_SUBSTART_DONE = 14,        // must have consecutive indices
+               SEND_SUBSTART_DONE = 14,                // must have consecutive indices
                SEND_TIMER = 15,                        // must have consecutive indices
                SEND_SUBSEND= 16,
                SEND_SUBSEND_DONE = 17,
@@ -170,7 +171,7 @@ implementation
                }
                else if( state == SEND_SUBSEND)
                {
-                       txError = call SubSend.send(txMsg, txLen);
+                       txError = call SubSend.send(txMsg);
 
                        if( txError == SUCCESS )
                                state = SEND_SUBSEND_DONE;
@@ -267,7 +268,7 @@ implementation
                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;
@@ -275,10 +276,10 @@ implementation
                if( state == LISTEN && sleepInterval > 0 )
                        call Timer.startOneShot(AFTER_RECEIVE);
 
-               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 )
                {
@@ -296,7 +297,6 @@ implementation
                        return EBUSY;
 
                txMsg = msg;
-               txLen = len;
                txError = FAIL;
 
                return SUCCESS;
@@ -335,7 +335,7 @@ implementation
                if( error != SUCCESS
                        || call LowPowerListening.getRxSleepInterval(msg) == 0
                        || state == SEND_SUBSEND_DONE_LAST
-                       || (call IEEE154Packet2.getAckRequired(msg) && call PacketAcknowledgements.wasAcked(msg)) )
+                       || (call Config.getAckRequired(msg) && call PacketAcknowledgements.wasAcked(msg)) )
                {
                        call Timer.stop();
                        state = SEND_DONE;
@@ -346,18 +346,13 @@ implementation
                post transition();
        }
 
-       command uint8_t Send.maxPayloadLength()
-       {
-               return call SubSend.maxPayloadLength();
-       }
+/*----------------- LowPowerListening -----------------*/
 
-       command void* Send.getPayload(message_t* msg, uint8_t len)
+       lpl_metadata_t* getMeta(message_t* msg)
        {
-               return call SubSend.getPayload(msg, len);
+               return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg);
        }
 
-/*----------------- LowPowerListening -----------------*/
-
        command uint16_t LowPowerListening.dutyCycleToSleepInterval(uint16_t dutyCycle)
        {
                if( dutyCycle >= 10000 )
@@ -379,7 +374,7 @@ implementation
        }
 
        command void LowPowerListening.setLocalSleepInterval(uint16_t interval)
-    {
+       {
                if( interval < MIN_SLEEP )
                        interval = 0;
                else if( interval > MAX_SLEEP )
@@ -396,7 +391,7 @@ implementation
        }
 
        command uint16_t LowPowerListening.getLocalSleepInterval()
-    {  
+       {       
                return sleepInterval;
        }
 
@@ -418,26 +413,58 @@ implementation
                else if( interval > MAX_SLEEP )
                        interval = MAX_SLEEP;
 
-               call PacketSleepInterval.set(msg, interval);
+               getMeta(msg)->sleepint = interval;
        }
 
        command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg)
-    {
-               if( ! call PacketSleepInterval.isSet(msg) )
-                       return sleepInterval;
+       {
+               uint16_t sleepint = getMeta(msg)->sleepint;
 
-               return call PacketSleepInterval.get(msg);
+               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)
-    {
+       {
                return call LowPowerListening.sleepIntervalToDutyCycle(
                        call LowPowerListening.getRxSleepInterval(msg));
        }
+
+/*----------------- RadioPacket -----------------*/
+       
+       async command uint8_t RadioPacket.headerLength(message_t* msg)
+       {
+               return call SubPacket.headerLength(msg);
+       }
+
+       async command uint8_t RadioPacket.payloadLength(message_t* msg)
+       {
+               return call SubPacket.payloadLength(msg);
+       }
+
+       async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length)
+       {
+               call SubPacket.setPayloadLength(msg, length);
+       }
+
+       async command uint8_t RadioPacket.maxPayloadLength()
+       {
+               return call SubPacket.maxPayloadLength();
+       }
+
+       async command uint8_t RadioPacket.metadataLength(message_t* msg)
+       {
+               return call SubPacket.metadataLength(msg) + sizeof(lpl_metadata_t);
+       }
+
+       async command void RadioPacket.clear(message_t* msg)
+       {
+               getMeta(msg)->sleepint = 0;
+               call SubPacket.clear(msg);
+       }
 }