diff --git a/include/openthread/types.h b/include/openthread/types.h index acd14c7b1..cf2abf669 100644 --- a/include/openthread/types.h +++ b/include/openthread/types.h @@ -953,6 +953,7 @@ typedef struct otMacCounters uint32_t mTxRetry; ///< The number of retransmission times. uint32_t mTxErrCca; ///< The number of CCA failure times. uint32_t mTxErrAbort; ///< The number of frame transmission failures due to abort error. + uint32_t mTxErrBusyChannel; ///< The number of frames that were dropped due to a busy channel. uint32_t mRxTotal; ///< The total number of received packets. uint32_t mRxUnicast; ///< The total number of unicast packets received. uint32_t mRxBroadcast; ///< The total number of broadcast packets received. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index bb2e10af8..a801517cb 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -667,6 +667,7 @@ void Interpreter::ProcessCounters(int argc, char *argv[]) mServer->OutputFormat(" TxOther: %d\r\n", counters->mTxOther); mServer->OutputFormat(" TxRetry: %d\r\n", counters->mTxRetry); mServer->OutputFormat(" TxErrCca: %d\r\n", counters->mTxErrCca); + mServer->OutputFormat(" TxErrBusyChannel: %d\r\n", counters->mTxErrBusyChannel); mServer->OutputFormat("RxTotal: %d\r\n", counters->mRxTotal); mServer->OutputFormat(" RxUnicast: %d\r\n", counters->mRxUnicast); mServer->OutputFormat(" RxBroadcast: %d\r\n", counters->mRxBroadcast); diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 37775cf07..f0e6078f8 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -991,8 +991,6 @@ void Mac::TransmitDoneTask(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otErro mMacTimer.Stop(); - mCounters.mTxTotal++; - txFrame->GetDstAddr(addr); if (aError == OT_ERROR_NONE && txFrame->GetAckRequest() && aAckFrame != NULL) @@ -1009,17 +1007,6 @@ void Mac::TransmitDoneTask(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otErro } } - if (addr.mShortAddress == kShortAddrBroadcast) - { - // Broadcast frame - mCounters.mTxBroadcast++; - } - else - { - // Unicast frame - mCounters.mTxUnicast++; - } - if (aError == OT_ERROR_ABORT) { mCounters.mTxErrAbort++; @@ -1171,8 +1158,6 @@ void Mac::HandleMacTimer(Timer &aTimer) void Mac::HandleMacTimer(void) { - Address addr; - switch (mOperation) { case kOperationActiveScan: @@ -1200,21 +1185,6 @@ void Mac::HandleMacTimer(void) case kOperationTransmitData: otLogDebgMac(GetInstance(), "Ack timer fired"); - mCounters.mTxTotal++; - - mTxFrame->GetDstAddr(addr); - - if (addr.mShortAddress == kShortAddrBroadcast) - { - // Broadcast frame - mCounters.mTxBroadcast++; - } - else - { - // Unicast Frame - mCounters.mTxUnicast++; - } - SentFrame(OT_ERROR_NO_ACK); break; @@ -1263,6 +1233,7 @@ void Mac::SentFrame(otError aError) { Frame &sendFrame(*mTxFrame); Sender *sender; + Address addr; mTransmitAttempts++; @@ -1302,6 +1273,26 @@ void Mac::SentFrame(otError aError) mTransmitAttempts = 0; mCsmaAttempts = 0; + mCounters.mTxTotal++; + + if (aError == OT_ERROR_CHANNEL_ACCESS_FAILURE) + { + mCounters.mTxErrBusyChannel++; + } + + mTxFrame->GetDstAddr(addr); + + if (addr.mShortAddress == kShortAddrBroadcast) + { + // Broadcast frame + mCounters.mTxBroadcast++; + } + else + { + // Unicast Frame + mCounters.mTxUnicast++; + } + if (sendFrame.GetAckRequest()) { mCounters.mTxAckRequested++;