]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf2xx/layers/PacketLinkLayerP.nc
Use BareSend/BareReceive instead of Send/Receive to avoid duplication of payload...
[tinyos-2.x.git] / tos / chips / rf2xx / layers / PacketLinkLayerP.nc
index 9418770d33d7799f0ed53b6f23296aadf59daf08..b8f284e6795e08bd8c68be20277848e463d338f2 100644 (file)
 
 module PacketLinkLayerP {
   provides {
-    interface Send;
+    interface BareSend as Send;
     interface PacketLink;
+    interface RadioPacket;
   }
 
   uses {
-    interface Send as SubSend;
+    interface BareSend as SubSend;
     interface PacketAcknowledgements;
     interface Timer<TMilli> as DelayTimer;
-    interface PacketData<link_metadata_t> as PacketLinkMetadata;
+    interface RadioPacket as SubPacket;
   }
 }
 
@@ -78,9 +79,6 @@ implementation {
   /** The message currently being sent */
   message_t *currentSendMsg;
 
-  /** Length of the current send message */
-  uint8_t currentSendLen;
-
   /** The length of the current send message */
   uint16_t totalRetries;
 
@@ -91,6 +89,11 @@ implementation {
 
 
   /***************** PacketLink Commands ***************/
+
+  link_metadata_t* getMeta(message_t* msg) {
+    return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg);
+  }
+
   /**
    * Set the maximum number of times attempt message delivery
    * Default is 0
@@ -99,7 +102,7 @@ implementation {
    *     the message
    */
   command void PacketLink.setRetries(message_t *msg, uint16_t maxRetries) {
-    (call PacketLinkMetadata.get(msg))->maxRetries = maxRetries;
+    getMeta(msg)->maxRetries = maxRetries;
   }
 
   /**
@@ -108,21 +111,21 @@ implementation {
    * @param retryDelay the delay betweeen retry attempts, in milliseconds
    */
   command void PacketLink.setRetryDelay(message_t *msg, uint16_t retryDelay) {
-    (call PacketLinkMetadata.get(msg))->retryDelay = retryDelay;
+    getMeta(msg)->retryDelay = retryDelay;
   }
 
   /**
    * @return the maximum number of retry attempts for this message
    */
   command uint16_t PacketLink.getRetries(message_t *msg) {
-    return (call PacketLinkMetadata.get(msg))->maxRetries;
+    return getMeta(msg)->maxRetries;
   }
 
   /**
    * @return the delay between retry attempts in ms for this message
    */
   command uint16_t PacketLink.getRetryDelay(message_t *msg) {
-    return (call PacketLinkMetadata.get(msg))->retryDelay;
+    return getMeta(msg)->retryDelay;
   }
 
   /**
@@ -132,10 +135,6 @@ implementation {
     return call PacketAcknowledgements.wasAcked(msg);
   }
 
-  async event void PacketLinkMetadata.clear(message_t* msg) {
-    (call PacketLinkMetadata.get(msg))->maxRetries = 0;
-  }
-
   /***************** Send Commands ***************/
   /**
    * Each call to this send command gives the message a single
@@ -144,7 +143,7 @@ implementation {
    * a broadcast address message, the receiving end does not
    * signal receive() more than once for that message.
    */
-  command error_t Send.send(message_t *msg, uint8_t len) {
+  command error_t Send.send(message_t *msg) {
     error_t error = EBUSY;
     if(currentSendMsg == NULL) {
 
@@ -152,9 +151,8 @@ implementation {
         call PacketAcknowledgements.requestAck(msg);
       }
 
-      if((error = call SubSend.send(msg, len)) == SUCCESS) {
+      if((error = call SubSend.send(msg)) == SUCCESS) {
         currentSendMsg = msg;
-        currentSendLen = len;
         totalRetries = 0;
       }
     }
@@ -170,15 +168,6 @@ implementation {
     return FAIL;
   }
 
-
-  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);
-  }
-
   /***************** SubSend Events ***************/
   event void SubSend.sendDone(message_t* msg, error_t error) {
     totalRetries++;
@@ -220,7 +209,7 @@ implementation {
       call PacketAcknowledgements.requestAck(currentSendMsg);
     }
 
-    if(call SubSend.send(currentSendMsg, currentSendLen) != SUCCESS) {
+    if(call SubSend.send(currentSendMsg) != SUCCESS) {
       post send();
     }
   }
@@ -237,4 +226,30 @@ implementation {
     call PacketLink.setRetries(msg, totalRetries);
     signal Send.sendDone(msg, error);
   }
+
+  /***************** Functions ***************/
+  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(link_metadata_t);
+  }
+
+  async command void RadioPacket.clear(message_t* msg) {
+    getMeta(msg)->maxRetries = 0;
+    call SubPacket.clear(msg);
+  }
 }