From 2129b567b461f403258927012b591d919e43ec8c Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Wed, 22 Jul 2020 14:09:18 +0800 Subject: [PATCH] [otns] emit device mode (#5268) This commit allows OTNS to correctly visualize node mode when it changes. --- src/core/thread/mle.cpp | 4 ++++ src/core/utils/otns.cpp | 6 ++++++ src/core/utils/otns.hpp | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 001c07516..bf331d651 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -778,6 +778,10 @@ otError Mle::SetDeviceMode(DeviceMode aDeviceMode) VerifyOrExit(mDeviceMode != aDeviceMode, OT_NOOP); mDeviceMode = aDeviceMode; +#if OPENTHREAD_CONFIG_OTNS_ENABLE + Get().EmitDeviceMode(mDeviceMode); +#endif + otLogNoteMle("Mode 0x%02x -> 0x%02x [%s]", oldMode.Get(), mDeviceMode.Get(), mDeviceMode.ToString().AsCString()); IgnoreError(Store()); diff --git a/src/core/utils/otns.cpp b/src/core/utils/otns.cpp index 1d7a595e3..f61faac44 100644 --- a/src/core/utils/otns.cpp +++ b/src/core/utils/otns.cpp @@ -153,6 +153,12 @@ void Otns::EmitTransmit(const Mac::TxFrame &aFrame) } } +void Otns::EmitDeviceMode(Mle::DeviceMode aMode) +{ + EmitStatus("mode=%s%s%s%s", aMode.IsRxOnWhenIdle() ? "r" : "", aMode.IsSecureDataRequest() ? "s" : "", + aMode.IsFullThreadDevice() ? "d" : "", aMode.IsFullNetworkData() ? "n" : ""); +} + } // namespace Utils } // namespace ot diff --git a/src/core/utils/otns.hpp b/src/core/utils/otns.hpp index bb747946b..dcb8fb8f9 100644 --- a/src/core/utils/otns.hpp +++ b/src/core/utils/otns.hpp @@ -132,6 +132,14 @@ public: */ static void EmitTransmit(const Mac::TxFrame &aFrame); + /** + * This function emits the device mode to OTNS. + * + * @param[in] aMode The device mode. + * + */ + static void EmitDeviceMode(Mle::DeviceMode aMode); + private: static void EmitStatus(const char *aFmt, ...);