]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/PollP.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / lib / mac / tkn154 / PollP.nc
index df20b2a8e12768c2efc2824d118eaaa9e0a6077c..3b5c83aa0f3b3037e99d83b4ea53607f2d6cc23f 100644 (file)
@@ -52,7 +52,6 @@ module PollP
     interface FrameUtility;
     interface Pool<ieee154_txframe_t> as TxFramePool;
     interface Pool<ieee154_txcontrol_t> as TxControlPool;
-    interface Ieee802154Debug as Debug;
     interface MLME_GET;
     interface Get<uint64_t> as LocalExtendedAddress;
   }
@@ -65,7 +64,7 @@ implementation
   };
   int m_numPending;
   uint8_t m_dataRequestCmdID = CMD_FRAME_DATA_REQUEST;
-  void buildDataRequestFrame( uint8_t destAddrMode, uint16_t destPANId,
+  void assembleDataRequestFrame( uint8_t destAddrMode, uint16_t destPANId,
       uint8_t* DstAddr, uint8_t srcAddrMode, ieee154_txframe_t *txFrame);
 
   command error_t Init.init()
@@ -78,25 +77,24 @@ implementation
                           uint8_t coordAddrMode,
                           uint16_t coordPANID,
                           ieee154_address_t coordAddress,
-                          ieee154_security_t *security      
-                        )
+                          ieee154_security_t *security)
   {
     ieee154_txframe_t *txFrame;
     ieee154_txcontrol_t *txControl;
     uint8_t srcAddrMode = 2;
-    ieee154_status_t txStatus = IEEE154_SUCCESS;
+    ieee154_status_t status = IEEE154_SUCCESS;
     uint8_t coordAddressLE[8]; // little endian is what we want
 
     if (security && security->SecurityLevel)
-      txStatus = IEEE154_UNSUPPORTED_SECURITY;
+      status = IEEE154_UNSUPPORTED_SECURITY;
     else if (coordAddrMode < 2 || coordAddrMode > 3 || coordPANID == 0xFFFF)
-      txStatus = IEEE154_INVALID_PARAMETER; 
+      status = IEEE154_INVALID_PARAMETER; 
     else if (!(txFrame = call TxFramePool.get()))
       // none of the predefined return value really fits
-      txStatus = IEEE154_TRANSACTION_OVERFLOW; 
-    else if (!(txControl = call TxControlPool.get())){
+      status = IEEE154_TRANSACTION_OVERFLOW; 
+    else if (!(txControl = call TxControlPool.get())) {
       call TxFramePool.put(txFrame);
-      txStatus = IEEE154_TRANSACTION_OVERFLOW;
+      status = IEEE154_TRANSACTION_OVERFLOW;
     } else {
       txFrame->header = &txControl->header;
       txFrame->metadata = &txControl->metadata;
@@ -107,15 +105,17 @@ implementation
       txFrame->handle = HANDLE_MLME_POLL_REQUEST;
       if (call MLME_GET.macShortAddress() >= 0xFFFE)
         srcAddrMode = 3;
-      buildDataRequestFrame(coordAddrMode, coordPANID, coordAddressLE, srcAddrMode, txFrame);
-      if ((txStatus = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS){
+      assembleDataRequestFrame(coordAddrMode, coordPANID, coordAddressLE, srcAddrMode, txFrame);
+      if ((status = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS) {
         call TxFramePool.put(txFrame);
         call TxControlPool.put(txControl);
-        call Debug.log(LEVEL_IMPORTANT, PollP_ALLOC_FAIL1, 0, 0, 0);
+        status = IEEE154_TRANSACTION_OVERFLOW;
       } else 
         m_numPending++;
     }
-    return txStatus;
+
+    dbg_serial("PollP", "MLME_POLL.request -> result: %lu\n", (uint32_t) status);
+    return status;
   }
 
   command ieee154_status_t DataRequest.poll[uint8_t client](uint8_t CoordAddrMode, 
@@ -124,34 +124,36 @@ implementation
     ieee154_txframe_t *txFrame;
     ieee154_txcontrol_t *txControl;
     ieee154_status_t status = IEEE154_TRANSACTION_OVERFLOW;
-    call Debug.log(LEVEL_INFO, PollP_INTERNAL_POLL, CoordAddrMode, client, m_numPending);
-    if (client == SYNC_CLIENT && m_numPending != 0){
+
+    dbg_serial("PollP", "Internal Poll\n");
+    if (client == SYNC_POLL_CLIENT && m_numPending != 0) {
       // no point in auto-requesting if user request is pending
       signal DataRequest.pollDone[client]();
       return IEEE154_SUCCESS;
-    } else if ((txFrame = call TxFramePool.get())){
-      if (!(txControl = call TxControlPool.get()))
-        call TxFramePool.put(txFrame);
-      else {
+    } else if ((txFrame = call TxFramePool.get()) != NULL) {
+      if ((txControl = call TxControlPool.get()) != NULL) {
         txFrame->header = &txControl->header;
         txFrame->metadata = &txControl->metadata;
         txFrame->handle = client;
-        buildDataRequestFrame(CoordAddrMode, CoordPANId, 
+        assembleDataRequestFrame(CoordAddrMode, CoordPANId, 
             CoordAddressLE, srcAddrMode, txFrame);
-        if ((status = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS){
+        if ((status = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS) {
           call TxControlPool.put(txControl);
           call TxFramePool.put(txFrame);
-          call Debug.log(LEVEL_IMPORTANT, PollP_ALLOC_FAIL2, 0, 0, 0);
+          dbg_serial("PollP", "Tx Overflow\n");
         } else 
           m_numPending++;
-      }
+      } else {
+        call TxFramePool.put(txFrame);
+      } 
     }
+    dbg_serial("PollP", "Status %lu, numPending: %lu\n", (uint32_t) status, (uint32_t) m_numPending);
     if (status != IEEE154_SUCCESS)
       signal DataRequest.pollDone[client]();
     return status;
   }
 
-  void buildDataRequestFrame(uint8_t destAddrMode, uint16_t destPANId,
+  void assembleDataRequestFrame(uint8_t destAddrMode, uint16_t destPANId,
       uint8_t* destAddrPtrLE, uint8_t srcAddrMode, ieee154_txframe_t *txFrame)
   {
     // destAddrPtrLE points to an address in little-endian format !
@@ -187,26 +189,25 @@ implementation
 
   event message_t* DataExtracted.received(message_t* frame, ieee154_txframe_t *txFrame)
   {
-    if (!txFrame){
-      call Debug.log(LEVEL_CRITICAL, PollP_INTERNAL_ERROR, 0, 0, 0);
+    if (!txFrame) {
+      dbg_serial("PollP", "Internal error\n");
       return frame;
     } else
-      call Debug.log(LEVEL_INFO, PollP_SUCCESS, 0, 0, 0);
+      dbg_serial("PollP", "Extracted data successfully\n");
     if (txFrame->handle == HANDLE_MLME_POLL_REQUEST)
       signal MLME_POLL.confirm(IEEE154_SUCCESS);
     else
       signal DataRequest.pollDone[txFrame->handle]();
     txFrame->handle = HANDLE_MLME_POLL_SUCCESS; // mark as processed
     // TODO: check if pending bit is set (then initiate another POLL)
-    call Debug.log(LEVEL_IMPORTANT, PollP_RX, txFrame->handle, 0, 0);
     return signal DataRx.received(frame);
   }
 
   event void PollTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
   {
-    call Debug.log(LEVEL_IMPORTANT, PollP_TXDONE, status, txFrame->handle, 0);
+    dbg_serial("PollP", "transmitDone()\n");
     m_numPending--;
-    if (txFrame->handle != HANDLE_MLME_POLL_SUCCESS){
+    if (txFrame->handle != HANDLE_MLME_POLL_SUCCESS) {
       // didn't receive a DATA frame from the coordinator
       if (status == IEEE154_SUCCESS) // TODO: can this happen if a frame other than DATA was extracted?
         status = IEEE154_NO_DATA;
@@ -218,6 +219,6 @@ implementation
     call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
     call TxFramePool.put(txFrame);
   }
-  default event void MLME_POLL.confirm(ieee154_status_t status){}
-  default event void DataRequest.pollDone[uint8_t client](){}
+  default event void MLME_POLL.confirm(ieee154_status_t status) {}
+  default event void DataRequest.pollDone[uint8_t client]() {}
 }