Ncp: Add support for requesting "EnergyScan" and passing the result to host (#498)

This commit is contained in:
Abtin Keshavarzian
2016-08-31 10:14:38 -07:00
committed by Jonathan Hui
parent 233bc92883
commit f77b1b525c
3 changed files with 68 additions and 2 deletions
+60 -2
View File
@@ -565,6 +565,48 @@ void NcpBase::HandleActiveScanResult(otActiveScanResult *result)
}
}
void NcpBase::HandleEnergyScanResult_Jump(otEnergyScanResult *aResult, void *aContext)
{
static_cast<NcpBase *>(aContext)->HandleEnergyScanResult(aResult);
}
void NcpBase::HandleEnergyScanResult(otEnergyScanResult *aResult)
{
ThreadError errorCode;
if (aResult)
{
NcpBase::SendPropertyUpdate(
SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0,
SPINEL_CMD_PROP_VALUE_INSERTED,
SPINEL_PROP_MAC_ENERGY_SCAN_RESULT,
"Cc",
aResult->mChannel,
aResult->mMaxRssi
);
}
else
{
// We are finished with the scan, so send out
// a property update indicating such.
errorCode = SendPropertyUpdate(
SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0,
SPINEL_CMD_PROP_VALUE_IS,
SPINEL_PROP_MAC_SCAN_STATE,
SPINEL_DATATYPE_UINT8_S,
SPINEL_SCAN_STATE_IDLE
);
// If we could not send the end of scan inidciator message now (no
// buffer space), we set `mShouldSignalEndOfScan` to true to send
// it out when buffer space becomes available.
if (errorCode != kThreadError_None)
{
mShouldSignalEndOfScan = true;
}
}
}
// ----------------------------------------------------------------------------
// MARK: Address Table Changed Glue
// ----------------------------------------------------------------------------
@@ -2538,17 +2580,33 @@ ThreadError NcpBase::SetPropertyHandler_MAC_SCAN_STATE(uint8_t header, spinel_pr
break;
case SPINEL_SCAN_STATE_BEACON:
mShouldSignalEndOfScan = false;
errorCode = otActiveScan(
mChannelMask,
mScanPeriod,
&HandleActiveScanResult_Jump,
this
);
if (errorCode == kThreadError_None)
{
mShouldSignalEndOfScan = false;
}
break;
case SPINEL_SCAN_STATE_ENERGY:
errorCode = kThreadError_NotImplemented;
errorCode = otEnergyScan(
mChannelMask,
mScanPeriod,
&HandleEnergyScanResult_Jump,
this
);
if (errorCode == kThreadError_None)
{
mShouldSignalEndOfScan = false;
}
break;
default:
+7
View File
@@ -139,6 +139,13 @@ private:
void HandleActiveScanResult(otActiveScanResult *result);
/**
* Trampoline for HandleEnergyScanResult().
*/
static void HandleEnergyScanResult_Jump(otEnergyScanResult *aResult, void *aContext);
void HandleEnergyScanResult(otEnergyScanResult *result);
/**
* Trampoline for UpdateChangedProps().
*/
+1
View File
@@ -326,6 +326,7 @@ typedef enum
SPINEL_PROP_MAC_15_4_PANID = SPINEL_PROP_MAC__BEGIN + 6, ///< [S]
SPINEL_PROP_MAC_RAW_STREAM_ENABLED = SPINEL_PROP_MAC__BEGIN + 7, ///< [C]
SPINEL_PROP_MAC_FILTER_MODE = SPINEL_PROP_MAC__BEGIN + 8, ///< [C]
SPINEL_PROP_MAC_ENERGY_SCAN_RESULT = SPINEL_PROP_MAC__BEGIN + 9, ///< chan,maxRssi [Cc]
SPINEL_PROP_MAC__END = 0x40,
SPINEL_PROP_MAC_EXT__BEGIN = 0x1300,