[mac] refactor frame rx/tx logging logic into methods (#2613)

This commit helps reduce stack usage by refactoring logging related
code for frame rx/tx failure and beacon rx/tx into separate methods.
This commit is contained in:
Abtin Keshavarzian
2018-03-15 16:46:02 +00:00
committed by Jonathan Hui
parent f602dcd5e7
commit 9d661319b9
4 changed files with 58 additions and 29 deletions
+52 -27
View File
@@ -272,7 +272,6 @@ otError Mac::ConvertBeaconToActiveScanResult(Frame *aBeaconFrame, otActiveScanRe
Beacon * beacon = NULL;
BeaconPayload *beaconPayload = NULL;
uint8_t payloadLength;
char stringBuffer[BeaconPayload::kInfoStringSize];
memset(&aResult, 0, sizeof(otActiveScanResult));
@@ -302,9 +301,7 @@ otError Mac::ConvertBeaconToActiveScanResult(Frame *aBeaconFrame, otActiveScanRe
memcpy(&aResult.mExtendedPanId, beaconPayload->GetExtendedPanId(), sizeof(aResult.mExtendedPanId));
}
otLogInfoMac(GetInstance(), "Received Beacon, %s", beaconPayload->ToInfoString(stringBuffer, sizeof(stringBuffer)));
OT_UNUSED_VARIABLE(stringBuffer);
LogBeacon("Received", *beaconPayload);
exit:
return error;
@@ -761,7 +758,6 @@ void Mac::SendBeacon(Frame &aFrame)
uint16_t fcf;
Beacon * beacon = NULL;
BeaconPayload *beaconPayload = NULL;
char stringBuffer[BeaconPayload::kInfoStringSize];
// initialize MAC header
fcf = Frame::kFcfFrameBeacon | Frame::kFcfDstAddrNone | Frame::kFcfSrcAddrExt;
@@ -800,9 +796,7 @@ void Mac::SendBeacon(Frame &aFrame)
aFrame.SetPayloadLength(beaconLength);
otLogInfoMac(GetInstance(), "Sending Beacon, %s", beaconPayload->ToInfoString(stringBuffer, sizeof(stringBuffer)));
OT_UNUSED_VARIABLE(stringBuffer);
LogBeacon("Sending", *beaconPayload);
}
void Mac::ProcessTransmitSecurity(Frame &aFrame)
@@ -1227,11 +1221,8 @@ void Mac::HandleTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otEr
if (aError != OT_ERROR_NONE)
{
char stringBuffer[Frame::kInfoStringSize];
LogFrameTxFailure(sendFrame, aError);
otLogInfoMac(GetInstance(), "Frame tx failed, error:%s, attempt:%d/%d, %s", otThreadErrorToString(aError),
mTransmitAttempts, sendFrame.GetMaxTxAttempts(),
sendFrame.ToInfoString(stringBuffer, sizeof(stringBuffer)));
otDumpDebgMac(GetInstance(), "TX ERR", sendFrame.GetHeader(), 16);
if (!RadioSupportsRetries() && mTransmitAttempts < sendFrame.GetMaxTxAttempts())
@@ -1240,8 +1231,6 @@ void Mac::HandleTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otEr
StartCsmaBackoff();
ExitNow();
}
OT_UNUSED_VARIABLE(stringBuffer);
}
mTransmitAttempts = 0;
@@ -1938,19 +1927,7 @@ exit:
if (error != OT_ERROR_NONE)
{
if (aFrame == NULL)
{
otLogInfoMac(GetInstance(), "Frame rx failed, error:%s", otThreadErrorToString(error));
}
else
{
char stringBuffer[Frame::kInfoStringSize];
otLogInfoMac(GetInstance(), "Frame rx failed, error:%s, %s", otThreadErrorToString(error),
aFrame->ToInfoString(stringBuffer, sizeof(stringBuffer)));
OT_UNUSED_VARIABLE(stringBuffer);
}
LogFrameRxFailure(aFrame, error);
switch (error)
{
@@ -2149,5 +2126,53 @@ const char *Mac::OperationToString(Operation aOperation)
return retval;
}
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
void Mac::LogFrameRxFailure(const Frame *aFrame, otError aError) const
{
char string[Frame::kInfoStringSize];
if (aFrame == NULL)
{
otLogInfoMac(GetInstance(), "Frame rx failed, error:%s", otThreadErrorToString(aError));
}
else
{
otLogInfoMac(GetInstance(), "Frame rx failed, error:%s, %s", otThreadErrorToString(aError),
aFrame->ToInfoString(string, sizeof(string)));
}
}
void Mac::LogFrameTxFailure(const Frame &aFrame, otError aError) const
{
char string[Frame::kInfoStringSize];
otLogInfoMac(GetInstance(), "Frame tx failed, error:%s, attempt:%d/%d, %s", otThreadErrorToString(aError),
mTransmitAttempts, aFrame.GetMaxTxAttempts(), aFrame.ToInfoString(string, sizeof(string)));
}
void Mac::LogBeacon(const char *aActionText, const BeaconPayload &aBeaconPayload) const
{
char string[BeaconPayload::kInfoStringSize];
otLogInfoMac(GetInstance(), "%s Beacon, %s", aActionText, aBeaconPayload.ToInfoString(string, sizeof(string)));
}
#else // #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
void Mac::LogFrameRxFailure(const Frame *, otError) const
{
}
void Mac::LogBeacon(const char *, const BeaconPayload &) const
{
}
void Mac::LogFrameTxFailure(const Frame &, otError) const
{
}
#endif // #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
} // namespace Mac
} // namespace ot
+4
View File
@@ -852,6 +852,10 @@ private:
otError RadioReceive(uint8_t aChannel);
otError RadioSleep(void);
void LogFrameRxFailure(const Frame *aFrame, otError aError) const;
void LogFrameTxFailure(const Frame &aFrame, otError aError) const;
void LogBeacon(const char *aActionText, const BeaconPayload &aBeaconPayload) const;
static const char *OperationToString(Operation aOperation);
Operation mOperation;
+1 -1
View File
@@ -998,7 +998,7 @@ const char *Frame::ToInfoString(char *aBuf, uint16_t aSize) const
return aBuf;
}
const char *BeaconPayload::ToInfoString(char *aBuf, uint16_t aSize)
const char *BeaconPayload::ToInfoString(char *aBuf, uint16_t aSize) const
{
const uint8_t *xpanid = GetExtendedPanId();
+1 -1
View File
@@ -1234,7 +1234,7 @@ public:
* @returns A pointer to the char string buffer.
*
*/
const char *ToInfoString(char *aBuf, uint16_t aSize);
const char *ToInfoString(char *aBuf, uint16_t aSize) const;
private:
uint8_t mProtocolId;