]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/PollP.nc
- fixed an issue with the beacon sequence number being set incorrectly
[tinyos-2.x.git] / tos / lib / mac / tkn154 / PollP.nc
index d00e986f6e44448d102acdb03e1ffdf3695d65ab..3b5c83aa0f3b3037e99d83b4ea53607f2d6cc23f 100644 (file)
@@ -64,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()
@@ -105,7 +105,7 @@ implementation
       txFrame->handle = HANDLE_MLME_POLL_REQUEST;
       if (call MLME_GET.macShortAddress() >= 0xFFFE)
         srcAddrMode = 3;
-      buildDataRequestFrame(coordAddrMode, coordPANID, coordAddressLE, srcAddrMode, txFrame);
+      assembleDataRequestFrame(coordAddrMode, coordPANID, coordAddressLE, srcAddrMode, txFrame);
       if ((status = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS) {
         call TxFramePool.put(txFrame);
         call TxControlPool.put(txControl);
@@ -125,34 +125,35 @@ implementation
     ieee154_txcontrol_t *txControl;
     ieee154_status_t status = IEEE154_TRANSACTION_OVERFLOW;
 
-    dbg_serial("PollP", "InternalPoll\n");
+    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) {
           call TxControlPool.put(txControl);
           call TxFramePool.put(txFrame);
-          dbg_serial("PollP", "Overflow\n");
+          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 !