]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf2xx/layers/ActiveMessageLayerP.nc
Use BareSend/BareReceive instead of Send/Receive to avoid duplication of payload...
[tinyos-2.x.git] / tos / chips / rf2xx / layers / ActiveMessageLayerP.nc
index 90406a94d2862f954fa653b1b7abcad452115405..1f9cb5ec06bdfe63990f2d8e63c684f30763236d 100644 (file)
  * Author: Miklos Maroti
  */
 
+#include <ActiveMessageLayer.h>
+
 module ActiveMessageLayerP
 {
        provides
        {
+               interface RadioPacket;
                interface AMPacket;
+               interface Packet;
                interface AMSend[am_id_t id];
                interface Receive[am_id_t id];
                interface Receive as Snoop[am_id_t id]; 
+               interface SendNotifier[am_id_t id];
        }
 
        uses
        {
-               interface Send as SubSend;
-               interface Receive as SubReceive;
+               interface RadioPacket as SubPacket;
+               interface BareSend as SubSend;
+               interface BareReceive as SubReceive;
                interface ActiveMessageConfig as Config;
                interface ActiveMessageAddress;
        }
@@ -42,22 +48,32 @@ module ActiveMessageLayerP
 
 implementation
 {
+       activemessage_header_t* getHeader(message_t* msg)
+       {
+               return ((void*)msg) + call SubPacket.headerLength(msg);
+       }
+
+       void* getPayload(message_t* msg)
+       {
+               return ((void*)msg) + call RadioPacket.headerLength(msg);
+       }
+
 /*----------------- Send -----------------*/
 
        command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len)
        {
-               error_t error;
-
-               error = call Config.checkPacket(msg);
-               if( error != SUCCESS )
-                       return error;
+               if( len > call Packet.maxPayloadLength() )
+                       return EINVAL;
 
+               call Packet.setPayloadLength(msg, len);
                call AMPacket.setSource(msg, call AMPacket.address());
                call AMPacket.setGroup(msg, call AMPacket.localGroup());
                call AMPacket.setType(msg, id);
                call AMPacket.setDestination(msg, addr);
 
-               return call SubSend.send(msg, len);
+               signal SendNotifier.aboutToSend[id](addr, msg);
+
+               return call SubSend.send(msg);
        }
 
        inline event void SubSend.sendDone(message_t* msg, error_t error)
@@ -76,23 +92,29 @@ implementation
 
        inline command uint8_t AMSend.maxPayloadLength[am_id_t id]()
        {
-               return call SubSend.maxPayloadLength();
+               return call Packet.maxPayloadLength();
        }
 
        inline command void* AMSend.getPayload[am_id_t id](message_t* msg, uint8_t len)
        {
-               return call SubSend.getPayload(msg, len);
+               return call Packet.getPayload(msg, len);
+       }
+
+       default event void SendNotifier.aboutToSend[am_id_t id](am_addr_t addr, message_t* msg)
+       {
        }
 
 /*----------------- Receive -----------------*/
 
-       event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len)
+       event message_t* SubReceive.receive(message_t* msg)
        {
-               am_id_t type = call AMPacket.type(msg);
+               am_id_t id = call AMPacket.type(msg);
+               void* payload = getPayload(msg);
+               uint8_t len = call Packet.payloadLength(msg);
 
                msg = call AMPacket.isForMe(msg) 
-                       ? signal Receive.receive[type](msg, payload, len)
-                       : signal Snoop.receive[type](msg, payload, len);
+                       ? signal Receive.receive[id](msg, payload, len)
+                       : signal Snoop.receive[id](msg, payload, len);
 
                return msg;
        }
@@ -147,12 +169,12 @@ implementation
 
        inline command am_id_t AMPacket.type(message_t* msg)
        {
-               return (call Config.getHeader(msg))->type;
+               return getHeader(msg)->type;
        }
 
        inline command void AMPacket.setType(message_t* msg, am_id_t type)
        {
-               (call Config.getHeader(msg))->type = type;
+               getHeader(msg)->type = type;
        }
   
        inline command am_group_t AMPacket.group(message_t* msg) 
@@ -168,4 +190,66 @@ implementation
        inline async event void ActiveMessageAddress.changed()
        {
        }
+
+/*----------------- RadioPacket -----------------*/
+
+       async command uint8_t RadioPacket.headerLength(message_t* msg)
+       {
+               return call SubPacket.headerLength(msg) + sizeof(activemessage_header_t);
+       }
+
+       async command uint8_t RadioPacket.payloadLength(message_t* msg)
+       {
+               return call SubPacket.payloadLength(msg) - sizeof(activemessage_header_t);
+       }
+
+       async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length)
+       {
+               call SubPacket.setPayloadLength(msg, length + sizeof(activemessage_header_t));
+       }
+
+       async command uint8_t RadioPacket.maxPayloadLength()
+       {
+               return call SubPacket.maxPayloadLength() - sizeof(activemessage_header_t);
+       }
+
+       async command uint8_t RadioPacket.metadataLength(message_t* msg)
+       {
+               return call SubPacket.metadataLength(msg);
+       }
+
+       async command void RadioPacket.clear(message_t* msg)
+       {
+               call SubPacket.clear(msg);
+       }
+
+/*----------------- Packet -----------------*/
+
+       command void Packet.clear(message_t* msg)
+       {
+               call SubPacket.clear(msg);
+       }
+
+       command uint8_t Packet.payloadLength(message_t* msg)
+       {
+               return call SubPacket.payloadLength(msg);
+       }
+
+       command void Packet.setPayloadLength(message_t* msg, uint8_t len)
+       {
+               call SubPacket.setPayloadLength(msg, len);
+       }
+
+       command uint8_t Packet.maxPayloadLength()
+       {
+               return call SubPacket.maxPayloadLength();
+       }
+
+       command void* Packet.getPayload(message_t* msg, uint8_t len)
+       {
+               if( len > call SubPacket.maxPayloadLength() )
+                       return NULL;
+
+               return ((void*)msg) + call SubPacket.headerLength(msg);
+       }
 }