@@ -183,36 +183,38 @@ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWh
|
183 | 183 | * @brief Set the advertisement data that is to be published in a regular advertisement.
|
184 | 184 | * @param [in] advertisementData The data to be advertised.
|
185 | 185 | */
|
186 |
| -void BLEAdvertising::setAdvertisementData(BLEAdvertisementData &advertisementData) { |
| 186 | +bool BLEAdvertising::setAdvertisementData(BLEAdvertisementData &advertisementData) { |
187 | 187 | log_v(">> setAdvertisementData");
|
188 | 188 | esp_err_t errRc = ::esp_ble_gap_config_adv_data_raw((uint8_t *)advertisementData.getPayload().c_str(), advertisementData.getPayload().length());
|
189 | 189 | if (errRc != ESP_OK) {
|
190 | 190 | log_e("esp_ble_gap_config_adv_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc));
|
191 | 191 | }
|
192 | 192 | m_customAdvData = true; // Set the flag that indicates we are using custom advertising data.
|
193 | 193 | log_v("<< setAdvertisementData");
|
| 194 | +return ESP_OK == errRc; |
194 | 195 | } // setAdvertisementData
|
195 | 196 |
|
196 | 197 | /**
|
197 | 198 | * @brief Set the advertisement data that is to be published in a scan response.
|
198 | 199 | * @param [in] advertisementData The data to be advertised.
|
199 | 200 | */
|
200 |
| -void BLEAdvertising::setScanResponseData(BLEAdvertisementData &advertisementData) { |
| 201 | +bool BLEAdvertising::setScanResponseData(BLEAdvertisementData &advertisementData) { |
201 | 202 | log_v(">> setScanResponseData");
|
202 | 203 | esp_err_t errRc = ::esp_ble_gap_config_scan_rsp_data_raw((uint8_t *)advertisementData.getPayload().c_str(), advertisementData.getPayload().length());
|
203 | 204 | if (errRc != ESP_OK) {
|
204 | 205 | log_e("esp_ble_gap_config_scan_rsp_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc));
|
205 | 206 | }
|
206 | 207 | m_customScanResponseData = true; // Set the flag that indicates we are using custom scan response data.
|
207 | 208 | log_v("<< setScanResponseData");
|
| 209 | +return ESP_OK == errRc; |
208 | 210 | } // setScanResponseData
|
209 | 211 |
|
210 | 212 | /**
|
211 | 213 | * @brief Start advertising.
|
212 | 214 | * Start advertising.
|
213 | 215 | * @return N/A.
|
214 | 216 | */
|
215 |
| -void BLEAdvertising::start() { |
| 217 | +bool BLEAdvertising::start() { |
216 | 218 | log_v(">> start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData);
|
217 | 219 |
|
218 | 220 | // We have a vector of service UUIDs that we wish to advertise. In order to use the
|
@@ -225,7 +227,7 @@ void BLEAdvertising::start() {
|
225 | 227 | m_advData.p_service_uuid = (uint8_t *)malloc(m_advData.service_uuid_len);
|
226 | 228 | if (!m_advData.p_service_uuid) {
|
227 | 229 | log_e(">> start failed: out of memory");
|
228 |
| -return; |
| 230 | +return false; |
229 | 231 | }
|
230 | 232 |
|
231 | 233 | uint8_t *p = m_advData.p_service_uuid;
|
@@ -250,7 +252,7 @@ void BLEAdvertising::start() {
|
250 | 252 | errRc = ::esp_ble_gap_config_adv_data(&m_advData);
|
251 | 253 | if (errRc != ESP_OK) {
|
252 | 254 | log_e("<< esp_ble_gap_config_adv_data: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
253 |
| -return; |
| 255 | +return false; |
254 | 256 | }
|
255 | 257 | }
|
256 | 258 |
|
@@ -266,7 +268,7 @@ void BLEAdvertising::start() {
|
266 | 268 | errRc = ::esp_ble_gap_config_adv_data(&m_scanRespData);
|
267 | 269 | if (errRc != ESP_OK) {
|
268 | 270 | log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
269 |
| -return; |
| 271 | +return false; |
270 | 272 | }
|
271 | 273 | }
|
272 | 274 |
|
@@ -279,24 +281,26 @@ void BLEAdvertising::start() {
|
279 | 281 | errRc = ::esp_ble_gap_start_advertising(&m_advParams);
|
280 | 282 | if (errRc != ESP_OK) {
|
281 | 283 | log_e("<< esp_ble_gap_start_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
282 |
| -return; |
| 284 | +} else { |
| 285 | +log_v("<< start"); |
283 | 286 | }
|
284 |
| -log_v("<< start"); |
| 287 | +return ESP_OK == errRc; |
285 | 288 | } // start
|
286 | 289 |
|
287 | 290 | /**
|
288 | 291 | * @brief Stop advertising.
|
289 | 292 | * Stop advertising.
|
290 | 293 | * @return N/A.
|
291 | 294 | */
|
292 |
| -void BLEAdvertising::stop() { |
| 295 | +bool BLEAdvertising::stop() { |
293 | 296 | log_v(">> stop");
|
294 | 297 | esp_err_t errRc = ::esp_ble_gap_stop_advertising();
|
295 | 298 | if (errRc != ESP_OK) {
|
296 | 299 | log_e("esp_ble_gap_stop_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
297 |
| -return; |
| 300 | +} else { |
| 301 | +log_v("<< stop"); |
298 | 302 | }
|
299 |
| -log_v("<< stop"); |
| 303 | +return ESP_OK == errRc; |
300 | 304 | } // stop
|
301 | 305 |
|
302 | 306 | /**
|
@@ -305,17 +309,17 @@ void BLEAdvertising::stop() {
|
305 | 309 | * @param [in] Bluetooth address type.
|
306 | 310 | * Set BLE address.
|
307 | 311 | */
|
308 |
| - |
309 |
| -void BLEAdvertising::setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type) { |
| 312 | +bool BLEAdvertising::setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type) { |
310 | 313 | log_v(">> setPrivateAddress");
|
311 | 314 |
|
312 | 315 | m_advParams.own_addr_type = type;
|
313 | 316 | esp_err_t errRc = esp_ble_gap_set_rand_addr((uint8_t *)addr);
|
314 | 317 | if (errRc != ESP_OK) {
|
315 | 318 | log_e("esp_ble_gap_set_rand_addr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
316 |
| -return; |
| 319 | +} else { |
| 320 | +log_v("<< setPrivateAddress"); |
317 | 321 | }
|
318 |
| -log_v("<< setPrivateAddress"); |
| 322 | +return ESP_OK == errRc; |
319 | 323 | } // setPrivateAddress
|
320 | 324 |
|
321 | 325 | /**
|
|
0 commit comments