Skip to content

Commit 4209e88

Browse files
committed
BLE: Improve GapScanningParams.h documentation.
1 parent 282740a commit 4209e88

File tree

1 file changed

+141
-52
lines changed

1 file changed

+141
-52
lines changed

features/FEATURE_BLE/ble/GapScanningParams.h

Lines changed: 141 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,89 +14,154 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef __GAP_SCANNING_PARAMS_H__
18-
#define __GAP_SCANNING_PARAMS_H__
17+
#ifndef MBED_GAP_SCANNING_PARAMS_H__
18+
#define MBED_GAP_SCANNING_PARAMS_H__
1919

20+
/**
21+
* @addtogroup ble
22+
* @{
23+
* @addtogroup gap
24+
* @{
25+
*/
26+
27+
/**
28+
* Parameters defining the scan process.
29+
*
30+
* The scan procedure is defined by four distinct parameters:
31+
* - Scan window: Period during which the scanner listen to advertising
32+
* channels. That value shall be in the 2.5ms to 10.24s. this value can be
33+
* set at construction time, updated by calling setWindow() and retrieved
34+
* by invoking getWindow().
35+
*
36+
* - Scan interval: interval between the start of two consecutive scan window.
37+
* That value shall be greater or equal to the scan window value. The
38+
* maximum allowed value is 10.24ms. The scan interval value can be set at
39+
* construction time, updated with a call to setInterval() and queried by a
40+
* call to getInterval().
41+
*
42+
* - Timeout: The duration of the scan procedure if any. It can be set at
43+
* construction time, updated with setTimeout() and obtained from
44+
* getTimeout().
45+
*
46+
* - Active scanning: If set then the scanner sends scan requests to scanable
47+
* or connectable advertiser. Advertisers may respond to the scan request
48+
* by a scan response containing the scan response payload. If not set then
49+
* the scanner does not send any request. This flag is set at construction
50+
* time, may be updated with the help of setActiveScanning() and get by
51+
* getActiveScanning().
52+
*
53+
* @note If the scan windows duration is equal to the scan interval then the
54+
* device should listen continuously during the scan procedure.
55+
*/
2056
class GapScanningParams {
2157
public:
22-
static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625us units - 2.5ms. */
23-
static const unsigned SCAN_INTERVAL_MAX = 0x4000; /**< Maximum Scan interval in 625us units - 10.24s. */
24-
static const unsigned SCAN_WINDOW_MIN = 0x0004; /**< Minimum Scan window in 625us units - 2.5ms. */
25-
static const unsigned SCAN_WINDOW_MAX = 0x4000; /**< Maximum Scan window in 625us units - 10.24s. */
26-
static const unsigned SCAN_TIMEOUT_MIN = 0x0001; /**< Minimum Scan timeout in seconds. */
27-
static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF; /**< Maximum Scan timeout in seconds. */
58+
/**
59+
* Minimum Scan interval in 625us units - 2.5ms.
60+
*/
61+
static const unsigned SCAN_INTERVAL_MIN = 0x0004;
62+
63+
/**
64+
* Maximum Scan interval in 625us units - 10.24s.
65+
*/
66+
static const unsigned SCAN_INTERVAL_MAX = 0x4000;
67+
68+
/**
69+
* Minimum Scan window in 625us units - 2.5ms.
70+
*/
71+
static const unsigned SCAN_WINDOW_MIN = 0x0004;
72+
73+
/**
74+
* Maximum Scan window in 625us units - 10.24s.
75+
*/
76+
static const unsigned SCAN_WINDOW_MAX = 0x4000;
77+
78+
/**
79+
* Minimum Scan duration in seconds.
80+
*/
81+
static const unsigned SCAN_TIMEOUT_MIN = 0x0001;
82+
83+
/**
84+
* Maximum Scan duration in seconds.
85+
*/
86+
static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF;
2887

2988
public:
3089
/**
3190
* Construct an instance of GapScanningParams.
3291
*
33-
* @param[in] interval
34-
* The scan interval in milliseconds. Default is
35-
* GapScanningParams::SCAN_INTERVAL_MIN.
36-
* @param[in] window
37-
* The scan window in milliseconds. Default is
38-
* GapScanningParams::SCAN_WINDOW_MAX.
39-
* @param[in] timeout
40-
* The scan timeout in seconds. Default is 0.
41-
* @param[in] activeScanning
42-
* Set to True if active-scanning is required. This is used to
43-
* fetch the scan response from a peer if possible. Default is
44-
* false.
45-
*/
46-
GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
47-
uint16_t window = SCAN_WINDOW_MAX,
48-
uint16_t timeout = 0,
49-
bool activeScanning = false);
50-
51-
static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */
92+
* @param[in] interval Milliseconds interval between the start of two
93+
* consecutive scan window. The value passed shall be between the scan
94+
* window value and 10.24 seconds.
95+
*
96+
* @param[in] window Milliseconds period during which the device should
97+
* listen to advertising channels. The value of the scan window shall be in
98+
* the range 2.5ms to 10.24s.
99+
*
100+
* @param[in] timeout Duration in seconds of the scan procedure. The special
101+
* value 0 may be used when the scan procedure is not time bounded.
102+
*
103+
* @param[in] activeScanning If true then the scanner sends scan requests to
104+
* to scanable or connectable advertiser. Advertisers may respond to the
105+
* scan request by a scan response containing the scan response payload. If
106+
* false, the scanner does not send any request.
107+
*
108+
* @note If interval is equal to window
109+
*/
110+
GapScanningParams(
111+
uint16_t interval = SCAN_INTERVAL_MAX,
112+
uint16_t window = SCAN_WINDOW_MAX,
113+
uint16_t timeout = 0,
114+
bool activeScanning = false
115+
);
116+
117+
/**
118+
* Number of microseconds in 0.625 milliseconds.
119+
*/
120+
static const uint16_t UNIT_0_625_MS = 625;
121+
52122
/**
53123
* Convert milliseconds to units of 0.625ms.
54124
*
55-
* @param[in] durationInMillis
56-
* The number of milliseconds to convert.
125+
* @param[in] durationInMillis Milliseconds to convert.
57126
*
58127
* @return The value of @p durationInMillis in units of 0.625ms.
59128
*/
60-
static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis) {
129+
static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis)
130+
{
61131
return (durationInMillis * 1000) / UNIT_0_625_MS;
62132
}
63133

64134
/**
65-
* Set the scan interval.
135+
* Update the scan interval.
66136
*
67-
* @param[in] newIntervalInMS
68-
* New scan interval in milliseconds.
137+
* @param[in] newIntervalInMS New scan interval in milliseconds.
69138
*
70139
* @return BLE_ERROR_NONE if the new scan interval was set successfully.
71140
*/
72141
ble_error_t setInterval(uint16_t newIntervalInMS);
73142

74143
/**
75-
* Set the scan window.
144+
* Update the scan window.
76145
*
77-
* @param[in] newWindowInMS
78-
* New scan window in milliseconds.
146+
* @param[in] newWindowInMS New scan window in milliseconds.
79147
*
80148
* @return BLE_ERROR_NONE if the new scan window was set successfully.
81149
*/
82150
ble_error_t setWindow(uint16_t newWindowInMS);
83151

84152
/**
85-
* Set the scan timeout.
153+
* Update the scan timeout.
86154
*
87-
* @param[in] newTimeout
88-
* New scan timeout in seconds.
155+
* @param[in] newTimeout New scan timeout in seconds.
89156
*
90157
* @return BLE_ERROR_NONE if the new scan window was set successfully.
91158
*/
92159
ble_error_t setTimeout(uint16_t newTimeout);
93160

94161
/**
95-
* Set active scanning. This is used to fetch the scan response from a peer
96-
* if possible.
162+
* Update the active scanning flag.
97163
*
98-
* @param[in] activeScanning
99-
* The new boolean value of active scanning.
164+
* @param[in] activeScanning Mew boolean value of active scanning.
100165
*/
101166
void setActiveScanning(bool activeScanning);
102167

@@ -106,7 +171,8 @@ class GapScanningParams {
106171
*
107172
* @return the scan interval in units of 0.625ms.
108173
*/
109-
uint16_t getInterval(void) const {
174+
uint16_t getInterval(void) const
175+
{
110176
return _interval;
111177
}
112178

@@ -115,7 +181,8 @@ class GapScanningParams {
115181
*
116182
* @return the scan window in units of 0.625ms.
117183
*/
118-
uint16_t getWindow(void) const {
184+
uint16_t getWindow(void) const
185+
{
119186
return _window;
120187
}
121188

@@ -124,7 +191,8 @@ class GapScanningParams {
124191
*
125192
* @return The scan timeout in seconds.
126193
*/
127-
uint16_t getTimeout(void) const {
194+
uint16_t getTimeout(void) const
195+
{
128196
return _timeout;
129197
}
130198

@@ -133,20 +201,41 @@ class GapScanningParams {
133201
*
134202
* @return True if active scanning is set, false otherwise.
135203
*/
136-
bool getActiveScanning(void) const {
204+
bool getActiveScanning(void) const
205+
{
137206
return _activeScanning;
138207
}
139208

140209
private:
141-
uint16_t _interval; /**< Scan interval in units of 625us (between 2.5ms and 10.24s). */
142-
uint16_t _window; /**< Scan window in units of 625us (between 2.5ms and 10.24s). */
143-
uint16_t _timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout. */
144-
bool _activeScanning; /**< Obtain the peer device's advertising data and (if possible) scanResponse. */
210+
/**
211+
* Scan interval in units of 625us (between 2.5ms and 10.24s).
212+
*/
213+
uint16_t _interval;
214+
215+
/**
216+
* Scan window in units of 625us (between 2.5ms and 10.24s).
217+
*/
218+
uint16_t _window;
219+
220+
/**
221+
* Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout.
222+
*/
223+
uint16_t _timeout;
224+
225+
/**
226+
* Obtain the peer device's advertising data and (if possible) scanResponse.
227+
*/
228+
bool _activeScanning;
145229

146230
private:
147231
/* Disallow copy constructor. */
148232
GapScanningParams(const GapScanningParams &);
149233
GapScanningParams& operator =(const GapScanningParams &in);
150234
};
151235

152-
#endif /* ifndef __GAP_SCANNING_PARAMS_H__ */
236+
/**
237+
* @}
238+
* @}
239+
*/
240+
241+
#endif /* ifndef MBED_GAP_SCANNING_PARAMS_H__ */

0 commit comments

Comments
 (0)