From 52354e73c7386548bbe7cedc3b5b503982ff3553 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 4 Jul 2018 13:40:40 -0700 Subject: [PATCH] [ncp] add new fields (age, rssi, etc) to PARENT spinel property (#2854) This commit appends new fields to format of `PROP_THREAD_PARENT` spinel property. The new fields provide age, avrerage RSSI and last RSSI, etc. This commit also updates the spinel documentation. --- doc/spinel-protocol-src/spinel-tech-thread.md | 13 ++++++++--- src/ncp/ncp_base_mtd.cpp | 22 +++++++++++++++++-- src/ncp/spinel.h | 15 ++++++++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/doc/spinel-protocol-src/spinel-tech-thread.md b/doc/spinel-protocol-src/spinel-tech-thread.md index ba74d6fb1..e8b06be9f 100644 --- a/doc/spinel-protocol-src/spinel-tech-thread.md +++ b/doc/spinel-protocol-src/spinel-tech-thread.md @@ -32,10 +32,17 @@ The IPv6 address of the leader. (Note: May change to long and short address of l ### PROP 81: PROP_THREAD_PARENT * Type: Read-Only -* Packed-Encoding: `ES` -* LADDR, SADDR +* Packed-Encoding: `ESLccCC` -The long address and short address of the parent of this node. +Information about parent of this node. + +* `E`: Extended address +* `S`: RLOC16 +* `L`: Age (seconds since last heard from) +* `c`: Average RSS (in dBm) +* `c`: Last RSSI (in dBm) +* `C`: Link Quality In +* `C`: Link Quality Out ### PROP 82: PROP_THREAD_CHILD_TABLE * Type: Read-Only diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index e3fff2c6a..c740128d4 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -568,8 +568,26 @@ template <> otError NcpBase::HandlePropertyGet(void) if (error == OT_ERROR_NONE) { - SuccessOrExit(error = mEncoder.WriteEui64(parentInfo.mExtAddress)); // Parent's extended address - SuccessOrExit(error = mEncoder.WriteUint16(parentInfo.mRloc16)); + if (parentInfo.mLinkEstablished) + { + int8_t averageRssi; + int8_t lastRssi; + + otThreadGetParentAverageRssi(mInstance, &averageRssi); + otThreadGetParentLastRssi(mInstance, &lastRssi); + + SuccessOrExit(error = mEncoder.WriteEui64(parentInfo.mExtAddress)); + SuccessOrExit(error = mEncoder.WriteUint16(parentInfo.mRloc16)); + SuccessOrExit(error = mEncoder.WriteUint32(parentInfo.mAge)); + SuccessOrExit(error = mEncoder.WriteInt8(averageRssi)); + SuccessOrExit(error = mEncoder.WriteInt8(lastRssi)); + SuccessOrExit(error = mEncoder.WriteUint8(parentInfo.mLinkQualityIn)); + SuccessOrExit(error = mEncoder.WriteUint8(parentInfo.mLinkQualityOut)); + } + else + { + SuccessOrExit(error = mEncoder.OverwriteWithLastStatusError(SPINEL_STATUS_ITEM_NOT_FOUND)); + } } else { diff --git a/src/ncp/spinel.h b/src/ncp/spinel.h index 8aa7bc16a..f4b5abe7a 100644 --- a/src/ncp/spinel.h +++ b/src/ncp/spinel.h @@ -923,7 +923,20 @@ typedef enum { SPINEL_PROP_THREAD__BEGIN = 0x50, SPINEL_PROP_THREAD_LEADER_ADDR = SPINEL_PROP_THREAD__BEGIN + 0, ///< [6] - SPINEL_PROP_THREAD_PARENT = SPINEL_PROP_THREAD__BEGIN + 1, ///< LADDR, SADDR [ES] + + /// Thread Parent Info + /** Format: `ESLccCC` - Read only + * + * `E`: Extended address + * `S`: RLOC16 + * `L`: Age (seconds since last heard from) + * `c`: Average RSS (in dBm) + * `c`: Last RSSI (in dBm) + * `C`: Link Quality In + * `C`: Link Quality Out + * + */ + SPINEL_PROP_THREAD_PARENT = SPINEL_PROP_THREAD__BEGIN + 1, /// Thread Child Table /** Format: [A(t(ESLLCCcCc)] - Read only