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<packet_link_metadata_t>;
+ interface RadioPacket as SubPacket;
}
}
/** 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;
/***************** 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
* the message
*/
command void PacketLink.setRetries(message_t *msg, uint16_t maxRetries) {
- (call PacketData.getData(msg))->maxRetries = maxRetries;
+ getMeta(msg)->maxRetries = maxRetries;
}
/**
* @param retryDelay the delay betweeen retry attempts, in milliseconds
*/
command void PacketLink.setRetryDelay(message_t *msg, uint16_t retryDelay) {
- (call PacketData.getData(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 PacketData.getData(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 PacketData.getData(msg))->retryDelay;
+ return getMeta(msg)->retryDelay;
}
/**
return call PacketAcknowledgements.wasAcked(msg);
}
- async event void PacketData.clear(packet_link_metadata_t* data) {
- data->maxRetries = 0;
- }
-
/***************** Send Commands ***************/
/**
* Each call to this send command gives the message a single
* 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) {
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;
}
}
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++;
call PacketAcknowledgements.requestAck(currentSendMsg);
}
- if(call SubSend.send(currentSendMsg, currentSendLen) != SUCCESS) {
+ if(call SubSend.send(currentSendMsg) != SUCCESS) {
post send();
}
}
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);
+ }
}