From 6cf94291b9fff5d84c5c6f29dccb634621b529dc Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 22 Aug 2016 21:20:14 -0700 Subject: [PATCH] Adding openthread API for Energy Scan operation (#448) --- include/openthread-types.h | 10 ++++++++++ include/openthread.h | 33 +++++++++++++++++++++++++++++++++ src/core/openthread.cpp | 22 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/include/openthread-types.h b/include/openthread-types.h index 80f138f8a..a23e1871e 100644 --- a/include/openthread-types.h +++ b/include/openthread-types.h @@ -259,6 +259,16 @@ typedef struct otActiveScanResult bool mIsJoinable : 1; ///< Joining Permitted flag } otActiveScanResult; +/** + * This struct represents an energy scan result. + * + */ +typedef struct otEnergyScanResult +{ + uint8_t mChannel; ///< IEEE 802.15.4 Channel + int8_t mMaxRssi; ///< The max RSSI (dBm) +} otEnergyScanResult; + /** * @} * diff --git a/include/openthread.h b/include/openthread.h index a5e2c0935..061e46099 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -268,6 +268,39 @@ ThreadError otActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, otHandl */ bool otIsActiveScanInProgress(void); +/** + * This function pointer is called during an IEEE 802.15.4 Energy Scan when the result for a channel is ready or the + * scan completes. + * + * @param[in] aResult A valid pointer to the energy scan result information or NULL when the energy scan completes. + * @param[in] aContext A pointer to application-specific context. + * + */ +typedef void (*otHandleEnergyScanResult)(otEnergyScanResult *aResult, void *aContext); + +/** + * This function starts an IEEE 802.15.4 Energy Scan + * + * @param[in] aScanChannels A bit vector indicating on which channels to perform energy scan. + * @param[in] aScanDuration The time in milliseconds to spend scanning each channel. + * @param[in] aCallback A pointer to a function called to pass on scan result on indicate scan completion. + * @param[in] aCallbackContext A pointer to application-specific context. + * + * @retval kThreadError_None Accepted the Energy Scan request. + * @retval kThreadError_Busy Already performing an Active Scan. + * + */ +ThreadError otEnergyScan(uint32_t aScanChannels, uint16_t aScanDuration, otHandleEnergyScanResult aCallback, + void *aCallbackContext); + +/** + * This function indicates whether or not an IEEE 802.15.4 Energy Scan is currently in progress. + * + * @returns true if an IEEE 802.15.4 Energy Scan is in progress, false otherwise. + * + */ +bool otIsEnergyScanInProgress(void); + /** * This function starts a Thread Discovery scan. * diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 230fae38c..8598fb891 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -68,6 +68,9 @@ static void HandleMleDiscover(otActiveScanResult *aResult, void *aContext); static otHandleActiveScanResult sActiveScanCallback = NULL; static void *sActiveScanCallbackContext = NULL; +static otHandleEnergyScanResult sEnergyScanCallback = NULL; +static void *sEnergyScanCallbackContext = NULL; + static otHandleActiveScanResult sDiscoverCallback = NULL; static void *sDiscoverCallbackContext = NULL; @@ -991,6 +994,25 @@ exit: return; } +ThreadError otEnergyScan(uint32_t aScanChannels, uint16_t aScanDuration, otHandleEnergyScanResult aCallback, + void *aCallbackContext) +{ + sEnergyScanCallback = aCallback; + sEnergyScanCallbackContext = aCallbackContext; + + (void)aScanChannels; + (void)aScanDuration; + + // TODO: Implement the energy scan at mac layer. + + return kThreadError_NotImplemented; +} + +bool otIsEnegyScanInProgress(void) +{ + return false; +} + ThreadError otDiscover(uint32_t aScanChannels, uint16_t aScanDuration, uint16_t aPanId, otHandleActiveScanResult aCallback, void *aCallbackContext) {