From ab1bfa99fad90ced8eeeb1debb70a064772fe330 Mon Sep 17 00:00:00 2001 From: Adam Eliot Date: Thu, 23 Feb 2017 11:23:27 -0800 Subject: [PATCH] Parent Info (#1370) * Expanded otGetParentInfo to populate the entire aParentInfo structure * Added otGetParentAverageRssi function * Use GetRouterId from rloc function instead of doing it manualy, and corrected documentation --- include/openthread.h | 11 ++++++++++- src/core/openthread.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/openthread.h b/include/openthread.h index 1dc1bfaf4..aa8521863 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -1933,7 +1933,7 @@ OTAPI uint8_t OTCALL otGetRouterIdSequence(otInstance *aInstance); OTAPI ThreadError OTCALL otGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo); /** - * The function retains diagnostic information for a Thread Router as parent. + * The function retrieves diagnostic information for a Thread Router as parent. * * @param[in] aInstance A pointer to an OpenThread instance. * @param[out] aParentInfo A pointer to where the parent router information is placed. @@ -1941,6 +1941,15 @@ OTAPI ThreadError OTCALL otGetRouterInfo(otInstance *aInstance, uint16_t aRouter */ OTAPI ThreadError OTCALL otGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo); +/** + * The function retrieves the average RSSI for the Thread Parent. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aParentInfo A pointer to where the parent rssi should be placed. + * + */ +OTAPI ThreadError OTCALL otGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi); + /** * Get the Stable Network Data Version. * diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index d9570592a..559af5a57 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -906,7 +906,32 @@ ThreadError otGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) parent = aInstance->mThreadNetif.GetMle().GetParent(); memcpy(aParentInfo->mExtAddress.m8, parent->mMacAddr.m8, OT_EXT_ADDRESS_SIZE); - aParentInfo->mRloc16 = parent->mValid.mRloc16; + + aParentInfo->mRloc16 = parent->mValid.mRloc16; + aParentInfo->mRouterId = Mle::Mle::GetRouterId(parent->mValid.mRloc16); + aParentInfo->mNextHop = parent->mNextHop; + aParentInfo->mPathCost = parent->mCost; + aParentInfo->mLinkQualityIn = parent->mLinkInfo.GetLinkQuality(aInstance->mThreadNetif.GetMac().GetNoiseFloor()); + aParentInfo->mLinkQualityOut = parent->mLinkQualityOut; + aParentInfo->mAge = static_cast(Timer::MsecToSec(Timer::GetNow() - parent->mLastHeard)); + aParentInfo->mAllocated = parent->mAllocated; + aParentInfo->mLinkEstablished = parent->mState == Neighbor::kStateValid; + +exit: + return error; +} + +ThreadError otGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) +{ + ThreadError error = kThreadError_None; + Router *parent; + + VerifyOrExit(aParentRssi != NULL, error = kThreadError_InvalidArgs); + + parent = aInstance->mThreadNetif.GetMle().GetParent(); + *aParentRssi = parent->mLinkInfo.GetAverageRss(); + + VerifyOrExit(*aParentRssi != LinkQualityInfo::kUnknownRss, error = kThreadError_Failed); exit: return error;