mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Improve GapScanningParams.h documentation.
parent
282740a1c5
commit
4209e88b9e
|
@ -14,89 +14,154 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __GAP_SCANNING_PARAMS_H__
|
#ifndef MBED_GAP_SCANNING_PARAMS_H__
|
||||||
#define __GAP_SCANNING_PARAMS_H__
|
#define MBED_GAP_SCANNING_PARAMS_H__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup ble
|
||||||
|
* @{
|
||||||
|
* @addtogroup gap
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters defining the scan process.
|
||||||
|
*
|
||||||
|
* The scan procedure is defined by four distinct parameters:
|
||||||
|
* - Scan window: Period during which the scanner listen to advertising
|
||||||
|
* channels. That value shall be in the 2.5ms to 10.24s. this value can be
|
||||||
|
* set at construction time, updated by calling setWindow() and retrieved
|
||||||
|
* by invoking getWindow().
|
||||||
|
*
|
||||||
|
* - Scan interval: interval between the start of two consecutive scan window.
|
||||||
|
* That value shall be greater or equal to the scan window value. The
|
||||||
|
* maximum allowed value is 10.24ms. The scan interval value can be set at
|
||||||
|
* construction time, updated with a call to setInterval() and queried by a
|
||||||
|
* call to getInterval().
|
||||||
|
*
|
||||||
|
* - Timeout: The duration of the scan procedure if any. It can be set at
|
||||||
|
* construction time, updated with setTimeout() and obtained from
|
||||||
|
* getTimeout().
|
||||||
|
*
|
||||||
|
* - Active scanning: If set then the scanner sends scan requests to scanable
|
||||||
|
* or connectable advertiser. Advertisers may respond to the scan request
|
||||||
|
* by a scan response containing the scan response payload. If not set then
|
||||||
|
* the scanner does not send any request. This flag is set at construction
|
||||||
|
* time, may be updated with the help of setActiveScanning() and get by
|
||||||
|
* getActiveScanning().
|
||||||
|
*
|
||||||
|
* @note If the scan windows duration is equal to the scan interval then the
|
||||||
|
* device should listen continuously during the scan procedure.
|
||||||
|
*/
|
||||||
class GapScanningParams {
|
class GapScanningParams {
|
||||||
public:
|
public:
|
||||||
static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625us units - 2.5ms. */
|
/**
|
||||||
static const unsigned SCAN_INTERVAL_MAX = 0x4000; /**< Maximum Scan interval in 625us units - 10.24s. */
|
* Minimum Scan interval in 625us units - 2.5ms.
|
||||||
static const unsigned SCAN_WINDOW_MIN = 0x0004; /**< Minimum Scan window in 625us units - 2.5ms. */
|
*/
|
||||||
static const unsigned SCAN_WINDOW_MAX = 0x4000; /**< Maximum Scan window in 625us units - 10.24s. */
|
static const unsigned SCAN_INTERVAL_MIN = 0x0004;
|
||||||
static const unsigned SCAN_TIMEOUT_MIN = 0x0001; /**< Minimum Scan timeout in seconds. */
|
|
||||||
static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF; /**< Maximum Scan timeout in seconds. */
|
/**
|
||||||
|
* Maximum Scan interval in 625us units - 10.24s.
|
||||||
|
*/
|
||||||
|
static const unsigned SCAN_INTERVAL_MAX = 0x4000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum Scan window in 625us units - 2.5ms.
|
||||||
|
*/
|
||||||
|
static const unsigned SCAN_WINDOW_MIN = 0x0004;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum Scan window in 625us units - 10.24s.
|
||||||
|
*/
|
||||||
|
static const unsigned SCAN_WINDOW_MAX = 0x4000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum Scan duration in seconds.
|
||||||
|
*/
|
||||||
|
static const unsigned SCAN_TIMEOUT_MIN = 0x0001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum Scan duration in seconds.
|
||||||
|
*/
|
||||||
|
static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Construct an instance of GapScanningParams.
|
* Construct an instance of GapScanningParams.
|
||||||
*
|
*
|
||||||
* @param[in] interval
|
* @param[in] interval Milliseconds interval between the start of two
|
||||||
* The scan interval in milliseconds. Default is
|
* consecutive scan window. The value passed shall be between the scan
|
||||||
* GapScanningParams::SCAN_INTERVAL_MIN.
|
* window value and 10.24 seconds.
|
||||||
* @param[in] window
|
*
|
||||||
* The scan window in milliseconds. Default is
|
* @param[in] window Milliseconds period during which the device should
|
||||||
* GapScanningParams::SCAN_WINDOW_MAX.
|
* listen to advertising channels. The value of the scan window shall be in
|
||||||
* @param[in] timeout
|
* the range 2.5ms to 10.24s.
|
||||||
* The scan timeout in seconds. Default is 0.
|
*
|
||||||
* @param[in] activeScanning
|
* @param[in] timeout Duration in seconds of the scan procedure. The special
|
||||||
* Set to True if active-scanning is required. This is used to
|
* value 0 may be used when the scan procedure is not time bounded.
|
||||||
* fetch the scan response from a peer if possible. Default is
|
*
|
||||||
* false.
|
* @param[in] activeScanning If true then the scanner sends scan requests to
|
||||||
|
* to scanable or connectable advertiser. Advertisers may respond to the
|
||||||
|
* scan request by a scan response containing the scan response payload. If
|
||||||
|
* false, the scanner does not send any request.
|
||||||
|
*
|
||||||
|
* @note If interval is equal to window
|
||||||
*/
|
*/
|
||||||
GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
|
GapScanningParams(
|
||||||
|
uint16_t interval = SCAN_INTERVAL_MAX,
|
||||||
uint16_t window = SCAN_WINDOW_MAX,
|
uint16_t window = SCAN_WINDOW_MAX,
|
||||||
uint16_t timeout = 0,
|
uint16_t timeout = 0,
|
||||||
bool activeScanning = false);
|
bool activeScanning = false
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of microseconds in 0.625 milliseconds.
|
||||||
|
*/
|
||||||
|
static const uint16_t UNIT_0_625_MS = 625;
|
||||||
|
|
||||||
static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */
|
|
||||||
/**
|
/**
|
||||||
* Convert milliseconds to units of 0.625ms.
|
* Convert milliseconds to units of 0.625ms.
|
||||||
*
|
*
|
||||||
* @param[in] durationInMillis
|
* @param[in] durationInMillis Milliseconds to convert.
|
||||||
* The number of milliseconds to convert.
|
|
||||||
*
|
*
|
||||||
* @return The value of @p durationInMillis in units of 0.625ms.
|
* @return The value of @p durationInMillis in units of 0.625ms.
|
||||||
*/
|
*/
|
||||||
static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis) {
|
static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis)
|
||||||
|
{
|
||||||
return (durationInMillis * 1000) / UNIT_0_625_MS;
|
return (durationInMillis * 1000) / UNIT_0_625_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the scan interval.
|
* Update the scan interval.
|
||||||
*
|
*
|
||||||
* @param[in] newIntervalInMS
|
* @param[in] newIntervalInMS New scan interval in milliseconds.
|
||||||
* New scan interval in milliseconds.
|
|
||||||
*
|
*
|
||||||
* @return BLE_ERROR_NONE if the new scan interval was set successfully.
|
* @return BLE_ERROR_NONE if the new scan interval was set successfully.
|
||||||
*/
|
*/
|
||||||
ble_error_t setInterval(uint16_t newIntervalInMS);
|
ble_error_t setInterval(uint16_t newIntervalInMS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the scan window.
|
* Update the scan window.
|
||||||
*
|
*
|
||||||
* @param[in] newWindowInMS
|
* @param[in] newWindowInMS New scan window in milliseconds.
|
||||||
* New scan window in milliseconds.
|
|
||||||
*
|
*
|
||||||
* @return BLE_ERROR_NONE if the new scan window was set successfully.
|
* @return BLE_ERROR_NONE if the new scan window was set successfully.
|
||||||
*/
|
*/
|
||||||
ble_error_t setWindow(uint16_t newWindowInMS);
|
ble_error_t setWindow(uint16_t newWindowInMS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the scan timeout.
|
* Update the scan timeout.
|
||||||
*
|
*
|
||||||
* @param[in] newTimeout
|
* @param[in] newTimeout New scan timeout in seconds.
|
||||||
* New scan timeout in seconds.
|
|
||||||
*
|
*
|
||||||
* @return BLE_ERROR_NONE if the new scan window was set successfully.
|
* @return BLE_ERROR_NONE if the new scan window was set successfully.
|
||||||
*/
|
*/
|
||||||
ble_error_t setTimeout(uint16_t newTimeout);
|
ble_error_t setTimeout(uint16_t newTimeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set active scanning. This is used to fetch the scan response from a peer
|
* Update the active scanning flag.
|
||||||
* if possible.
|
|
||||||
*
|
*
|
||||||
* @param[in] activeScanning
|
* @param[in] activeScanning Mew boolean value of active scanning.
|
||||||
* The new boolean value of active scanning.
|
|
||||||
*/
|
*/
|
||||||
void setActiveScanning(bool activeScanning);
|
void setActiveScanning(bool activeScanning);
|
||||||
|
|
||||||
|
@ -106,7 +171,8 @@ public:
|
||||||
*
|
*
|
||||||
* @return the scan interval in units of 0.625ms.
|
* @return the scan interval in units of 0.625ms.
|
||||||
*/
|
*/
|
||||||
uint16_t getInterval(void) const {
|
uint16_t getInterval(void) const
|
||||||
|
{
|
||||||
return _interval;
|
return _interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +181,8 @@ public:
|
||||||
*
|
*
|
||||||
* @return the scan window in units of 0.625ms.
|
* @return the scan window in units of 0.625ms.
|
||||||
*/
|
*/
|
||||||
uint16_t getWindow(void) const {
|
uint16_t getWindow(void) const
|
||||||
|
{
|
||||||
return _window;
|
return _window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +191,8 @@ public:
|
||||||
*
|
*
|
||||||
* @return The scan timeout in seconds.
|
* @return The scan timeout in seconds.
|
||||||
*/
|
*/
|
||||||
uint16_t getTimeout(void) const {
|
uint16_t getTimeout(void) const
|
||||||
|
{
|
||||||
return _timeout;
|
return _timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,15 +201,31 @@ public:
|
||||||
*
|
*
|
||||||
* @return True if active scanning is set, false otherwise.
|
* @return True if active scanning is set, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool getActiveScanning(void) const {
|
bool getActiveScanning(void) const
|
||||||
|
{
|
||||||
return _activeScanning;
|
return _activeScanning;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t _interval; /**< Scan interval in units of 625us (between 2.5ms and 10.24s). */
|
/**
|
||||||
uint16_t _window; /**< Scan window in units of 625us (between 2.5ms and 10.24s). */
|
* Scan interval in units of 625us (between 2.5ms and 10.24s).
|
||||||
uint16_t _timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout. */
|
*/
|
||||||
bool _activeScanning; /**< Obtain the peer device's advertising data and (if possible) scanResponse. */
|
uint16_t _interval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scan window in units of 625us (between 2.5ms and 10.24s).
|
||||||
|
*/
|
||||||
|
uint16_t _window;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout.
|
||||||
|
*/
|
||||||
|
uint16_t _timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain the peer device's advertising data and (if possible) scanResponse.
|
||||||
|
*/
|
||||||
|
bool _activeScanning;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Disallow copy constructor. */
|
/* Disallow copy constructor. */
|
||||||
|
@ -149,4 +233,9 @@ private:
|
||||||
GapScanningParams& operator =(const GapScanningParams &in);
|
GapScanningParams& operator =(const GapScanningParams &in);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ifndef __GAP_SCANNING_PARAMS_H__ */
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* ifndef MBED_GAP_SCANNING_PARAMS_H__ */
|
||||||
|
|
Loading…
Reference in New Issue