From cbfff2298f777dba6fe7651567e466d79ead172c Mon Sep 17 00:00:00 2001 From: mmaroti Date: Tue, 6 Oct 2009 01:32:10 +0000 Subject: [PATCH] automaticaly call Packet.clear if user forgot to do so --- tos/chips/rf2xx/layers/ActiveMessageConfig.nc | 8 ++++++++ tos/chips/rf2xx/layers/ActiveMessageLayerP.nc | 3 +++ tos/chips/rf2xx/rf212/RF212RadioP.nc | 8 ++++++++ tos/chips/rf2xx/rf230/RF230RadioP.nc | 8 ++++++++ 4 files changed, 27 insertions(+) diff --git a/tos/chips/rf2xx/layers/ActiveMessageConfig.nc b/tos/chips/rf2xx/layers/ActiveMessageConfig.nc index 1de4576b..d5ba7b8e 100755 --- a/tos/chips/rf2xx/layers/ActiveMessageConfig.nc +++ b/tos/chips/rf2xx/layers/ActiveMessageConfig.nc @@ -42,4 +42,12 @@ interface ActiveMessageConfig /** Same as AMPacket.setGroup */ command void setGroup(message_t* msg, am_group_t grp); + + /** + * Check if the packet is properly formatted, and if the user + * forgot to call Packet.clear then format it properly. + * Return SUCCESS if the frame is now properly set up, + * or FAIL of the send operation should be aborted. + */ + command error_t checkFrame(message_t* msg); } diff --git a/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc b/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc index a652486e..1f75d36b 100644 --- a/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc +++ b/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc @@ -65,6 +65,9 @@ implementation if( len > call Packet.maxPayloadLength() ) return EINVAL; + if( call Config.checkFrame(msg) != SUCCESS ) + return FAIL; + call Packet.setPayloadLength(msg, len); call AMPacket.setSource(msg, call AMPacket.address()); call AMPacket.setGroup(msg, call AMPacket.localGroup()); diff --git a/tos/chips/rf2xx/rf212/RF212RadioP.nc b/tos/chips/rf2xx/rf212/RF212RadioP.nc index 699aeb56..14f32949 100644 --- a/tos/chips/rf2xx/rf212/RF212RadioP.nc +++ b/tos/chips/rf2xx/rf212/RF212RadioP.nc @@ -189,6 +189,14 @@ implementation call Ieee154PacketLayer.setDestPan(msg, grp); } + command error_t ActiveMessageConfig.checkFrame(message_t* msg) + { + if( ! call Ieee154PacketLayer.isDataFrame(msg) ) + call Ieee154PacketLayer.createDataFrame(msg); + + return SUCCESS; + } + /*----------------- CsmaConfig -----------------*/ async command bool CsmaConfig.requiresSoftwareCCA(message_t* msg) diff --git a/tos/chips/rf2xx/rf230/RF230RadioP.nc b/tos/chips/rf2xx/rf230/RF230RadioP.nc index 57ad57a9..db37bee3 100644 --- a/tos/chips/rf2xx/rf230/RF230RadioP.nc +++ b/tos/chips/rf2xx/rf230/RF230RadioP.nc @@ -189,6 +189,14 @@ implementation call Ieee154PacketLayer.setDestPan(msg, grp); } + command error_t ActiveMessageConfig.checkFrame(message_t* msg) + { + if( ! call Ieee154PacketLayer.isDataFrame(msg) ) + call Ieee154PacketLayer.createDataFrame(msg); + + return SUCCESS; + } + /*----------------- CsmaConfig -----------------*/ async command bool CsmaConfig.requiresSoftwareCCA(message_t* msg) -- 2.39.2