diff --git a/src/core/thread/topology.cpp b/src/core/thread/topology.cpp index 60b54653b..8dfebc21c 100644 --- a/src/core/thread/topology.cpp +++ b/src/core/thread/topology.cpp @@ -197,6 +197,22 @@ void Neighbor::RemoveAllForwardTrackingSeriesInfo(void) } #endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_ENABLE +const char *Neighbor::StateToString(State aState) +{ + static const char *kStateStrings[] = { + "Invalid", // kStateInvalid + "Restored", // kStateRestored + "ParentReq", // kStateParentRequest + "ParentRes", // kStateParentResponse + "ChildIdReq", // kStateChildIdRequest + "LinkReq", // kStateLinkRequest + "ChildUpdateReq", // kStateChildUpdateRequest + "Valid", // kStateValid + }; + + return static_cast(aState) < OT_ARRAY_LENGTH(kStateStrings) ? kStateStrings[aState] : "Unknown"; +} + void Child::Info::SetFrom(const Child &aChild) { Clear(); diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index bf7f28724..cecf3c9e1 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -645,6 +645,17 @@ public: void RemoveAllForwardTrackingSeriesInfo(void); #endif + + /** + * This method converts a given `State` to a human-readable string. + * + * @param[in] aState A neighbor state. + * + * @returns A string representation of given state. + * + */ + static const char *StateToString(State aState); + protected: /** * This method initializes the `Neighbor` object.