mirror of
https://github.com/espressif/openthread.git
synced 2026-08-06 10:47:46 +00:00
[string] add ToYesNo() to convert a boolean to "yes" or "no" (#7270)
This commit is contained in:
@@ -196,6 +196,13 @@ char ToUppercase(char aChar)
|
||||
return aChar;
|
||||
}
|
||||
|
||||
const char *ToYesNo(bool aBool)
|
||||
{
|
||||
static const char *const kYesNoStrings[] = {"no", "yes"};
|
||||
|
||||
return kYesNoStrings[aBool];
|
||||
}
|
||||
|
||||
StringWriter::StringWriter(char *aBuffer, uint16_t aSize)
|
||||
: mBuffer(aBuffer)
|
||||
, mLength(0)
|
||||
|
||||
@@ -194,6 +194,16 @@ char ToLowercase(char aChar);
|
||||
*/
|
||||
char ToUppercase(char aChar);
|
||||
|
||||
/**
|
||||
* This function coverts a boolean to "yes" or "no" string.
|
||||
*
|
||||
* @param[in] aBool A boolean value to convert.
|
||||
*
|
||||
* @returns The converted string representation of @p aBool ("yes" for TRUE and "no" for FALSE).
|
||||
*
|
||||
*/
|
||||
const char *ToYesNo(bool aBool);
|
||||
|
||||
/**
|
||||
* This class implements writing to a string buffer.
|
||||
*
|
||||
|
||||
@@ -1495,7 +1495,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, Error aError)
|
||||
StartOperation(kOperationWaitingForData);
|
||||
}
|
||||
|
||||
otLogInfoMac("Sent data poll, fp:%s", framePending ? "yes" : "no");
|
||||
otLogInfoMac("Sent data poll, fp:%s", ToYesNo(framePending));
|
||||
}
|
||||
|
||||
mCounters.mTxDataPoll++;
|
||||
|
||||
@@ -1437,7 +1437,7 @@ Frame::InfoString Frame::ToInfoString(void) const
|
||||
IgnoreError(GetDstAddr(dst));
|
||||
|
||||
string.Append(", src:%s, dst:%s, sec:%s, ackreq:%s", src.ToString().AsCString(), dst.ToString().AsCString(),
|
||||
GetSecurityEnabled() ? "yes" : "no", GetAckRequest() ? "yes" : "no");
|
||||
ToYesNo(GetSecurityEnabled()), ToYesNo(GetAckRequest()));
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
string.Append(", radio:%s", RadioTypeToString(GetRadioType()));
|
||||
@@ -1455,7 +1455,7 @@ BeaconPayload::InfoString BeaconPayload::ToInfoString(void) const
|
||||
|
||||
string.Append("name:%s, xpanid:%s, id:%d, ver:%d, joinable:%s, native:%s", name.GetAsCString(),
|
||||
mExtendedPanId.ToString().AsCString(), GetProtocolId(), GetProtocolVersion(),
|
||||
IsJoiningPermitted() ? "yes" : "no", IsNative() ? "yes" : "no");
|
||||
ToYesNo(IsJoiningPermitted()), ToYesNo(IsNative()));
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ void Joiner::SaveDiscoveredJoinerRouter(const Mle::DiscoverScanner::ScanResult &
|
||||
|
||||
otLogInfoMeshCoP("Joiner discover network: %s, pan:0x%04x, port:%d, chan:%d, rssi:%d, allow-any:%s",
|
||||
AsCoreType(&aResult.mExtAddress).ToString().AsCString(), aResult.mPanId, aResult.mJoinerUdpPort,
|
||||
aResult.mChannel, aResult.mRssi, doesAllowAny ? "yes" : "no");
|
||||
aResult.mChannel, aResult.mRssi, ToYesNo(doesAllowAny));
|
||||
|
||||
priority = CalculatePriority(aResult.mRssi, doesAllowAny);
|
||||
|
||||
|
||||
@@ -1773,7 +1773,7 @@ void MeshForwarder::LogIp6Message(MessageAction aAction,
|
||||
aMessage.GetLength(), checksum,
|
||||
(aMacAddress == nullptr) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"),
|
||||
(aMacAddress == nullptr) ? "" : aMacAddress->ToString().AsCString(),
|
||||
aMessage.IsLinkSecurityEnabled() ? "yes" : "no",
|
||||
ToYesNo(aMessage.IsLinkSecurityEnabled()),
|
||||
(aError == kErrorNone) ? "" : ", error:", (aError == kErrorNone) ? "" : ErrorToString(aError),
|
||||
MessagePriorityToString(aMessage), shouldLogRss ? ", rss:" : "",
|
||||
shouldLogRss ? aMessage.GetRssAverager().ToString().AsCString() : "", shouldLogRadio ? ", radio:" : "",
|
||||
@@ -1854,7 +1854,7 @@ void MeshForwarder::LogFragmentFrameDrop(Error aError,
|
||||
otLogNoteMac("Dropping rx frag frame, error:%s, len:%d, src:%s, dst:%s, tag:%d, offset:%d, dglen:%d, sec:%s",
|
||||
ErrorToString(aError), aFrameLength, aMacSource.ToString().AsCString(),
|
||||
aMacDest.ToString().AsCString(), aFragmentHeader.GetDatagramTag(), aFragmentHeader.GetDatagramOffset(),
|
||||
aFragmentHeader.GetDatagramSize(), aIsSecure ? "yes" : "no");
|
||||
aFragmentHeader.GetDatagramSize(), ToYesNo(aIsSecure));
|
||||
}
|
||||
|
||||
void MeshForwarder::LogLowpanHcFrameDrop(Error aError,
|
||||
@@ -1864,8 +1864,7 @@ void MeshForwarder::LogLowpanHcFrameDrop(Error aError,
|
||||
bool aIsSecure)
|
||||
{
|
||||
otLogNoteMac("Dropping rx lowpan HC frame, error:%s, len:%d, src:%s, dst:%s, sec:%s", ErrorToString(aError),
|
||||
aFrameLength, aMacSource.ToString().AsCString(), aMacDest.ToString().AsCString(),
|
||||
aIsSecure ? "yes" : "no");
|
||||
aFrameLength, aMacSource.ToString().AsCString(), aMacDest.ToString().AsCString(), ToYesNo(aIsSecure));
|
||||
}
|
||||
|
||||
#else // #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_NOTE) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
|
||||
|
||||
@@ -838,7 +838,7 @@ exit:
|
||||
if (error != kErrorNone)
|
||||
{
|
||||
otLogInfoMac("Dropping rx mesh frame, error:%s, len:%d, src:%s, sec:%s", ErrorToString(error), aFrameLength,
|
||||
aMacSource.ToString().AsCString(), aLinkInfo.IsLinkSecurityEnabled() ? "yes" : "no");
|
||||
aMacSource.ToString().AsCString(), ToYesNo(aLinkInfo.IsLinkSecurityEnabled()));
|
||||
FreeMessage(message);
|
||||
}
|
||||
}
|
||||
@@ -1070,7 +1070,7 @@ Error MeshForwarder::LogMeshFragmentHeader(MessageAction aAction,
|
||||
(aMacAddress == nullptr) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"),
|
||||
(aMacAddress == nullptr) ? "" : aMacAddress->ToString().AsCString(), aMeshSource.ToString().AsCString(),
|
||||
aMeshDest.ToString().AsCString(), meshHeader.GetHopsLeft() + ((aAction == kMessageReceive) ? 1 : 0),
|
||||
hasFragmentHeader ? "yes" : "no", aMessage.IsLinkSecurityEnabled() ? "yes" : "no",
|
||||
ToYesNo(hasFragmentHeader), ToYesNo(aMessage.IsLinkSecurityEnabled()),
|
||||
(aError == kErrorNone) ? "" : ", error:", (aError == kErrorNone) ? "" : ErrorToString(aError),
|
||||
shouldLogRss ? ", rss:" : "", shouldLogRss ? aMessage.GetRssAverager().ToString().AsCString() : "",
|
||||
shouldLogRadio ? ", radio:" : "", radioString);
|
||||
|
||||
@@ -1559,7 +1559,7 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId)
|
||||
(router.GetNextHop() == kInvalidRouterId) ? 0xffff : Rloc16FromRouterId(router.GetNextHop()),
|
||||
router.GetCost(), mRouterTable.GetLinkCost(router), router.GetLinkInfo().GetLinkQuality(),
|
||||
router.GetLinkQualityOut(),
|
||||
router.GetRloc16() == GetRloc16() ? "device" : (router.IsStateValid() ? "yes" : "no"));
|
||||
router.GetRloc16() == GetRloc16() ? "device" : ToYesNo(router.IsStateValid()));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -57,8 +57,8 @@ DeviceMode::InfoString DeviceMode::ToString(void) const
|
||||
{
|
||||
InfoString string;
|
||||
|
||||
string.Append("rx-on:%s ftd:%s full-net:%s", IsRxOnWhenIdle() ? "yes" : "no", IsFullThreadDevice() ? "yes" : "no",
|
||||
IsFullNetworkData() ? "yes" : "no");
|
||||
string.Append("rx-on:%s ftd:%s full-net:%s", ToYesNo(IsRxOnWhenIdle()), ToYesNo(IsFullThreadDevice()),
|
||||
ToYesNo(IsFullNetworkData()));
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "common/locator_getters.hpp"
|
||||
#include "common/logging.hpp"
|
||||
#include "common/random.hpp"
|
||||
#include "common/string.hpp"
|
||||
#include "meshcop/dataset_updater.hpp"
|
||||
#include "radio/radio.hpp"
|
||||
|
||||
@@ -235,7 +236,7 @@ bool ChannelManager::ShouldAttemptChannelChange(void)
|
||||
bool shouldAttempt = (ccaFailureRate >= mCcaFailureRateThreshold);
|
||||
|
||||
otLogInfoUtil("ChannelManager: CCA-err-rate: 0x%04x %s 0x%04x, selecting channel: %s", ccaFailureRate,
|
||||
shouldAttempt ? ">=" : "<", mCcaFailureRateThreshold, shouldAttempt ? "yes" : "no");
|
||||
shouldAttempt ? ">=" : "<", mCcaFailureRateThreshold, ToYesNo(shouldAttempt));
|
||||
|
||||
return shouldAttempt;
|
||||
}
|
||||
@@ -246,8 +247,7 @@ Error ChannelManager::RequestChannelSelect(bool aSkipQualityCheck)
|
||||
uint8_t curChannel, newChannel;
|
||||
uint16_t curOccupancy, newOccupancy;
|
||||
|
||||
otLogInfoUtil("ChannelManager: Request to select channel (skip quality check: %s)",
|
||||
aSkipQualityCheck ? "yes" : "no");
|
||||
otLogInfoUtil("ChannelManager: Request to select channel (skip quality check: %s)", ToYesNo(aSkipQualityCheck));
|
||||
|
||||
VerifyOrExit(!Get<Mle::Mle>().IsDisabled(), error = kErrorInvalidState);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user