My Project
 All Classes Functions Variables Pages
BLEAdvertising.h
1 /*
2  * BLEAdvertising.h
3  *
4  * Created on: Jun 21, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_BLEADVERTISING_H_
9 #define COMPONENTS_CPP_UTILS_BLEADVERTISING_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 #include <esp_gap_ble_api.h>
13 #include "BLEUUID.h"
14 #include <vector>
15 #include "FreeRTOS.h"
16 
20 class BLEAdvertisementData {
21  // Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will
22  // be exposed on demand/request or as time permits.
23  //
24 public:
25  void setAppearance(uint16_t appearance);
26  void setCompleteServices(BLEUUID uuid);
27  void setFlags(uint8_t);
28  void setManufacturerData(std::string data);
29  void setName(std::string name);
30  void setPartialServices(BLEUUID uuid);
31  void setServiceData(BLEUUID uuid, std::string data);
32  void setShortName(std::string name);
33  void addData(std::string data); // Add data to the payload.
34  std::string getPayload(); // Retrieve the current advert payload.
35 
36 private:
37  friend class BLEAdvertising;
38  std::string m_payload; // The payload of the advertisement.
39 }; // BLEAdvertisementData
40 
41 
47 class BLEAdvertising {
48 public:
49  BLEAdvertising();
50  void addServiceUUID(BLEUUID serviceUUID);
51  void addServiceUUID(const char* serviceUUID);
52  void start();
53  void stop();
54  void setAppearance(uint16_t appearance);
55  void setMaxInterval(uint16_t maxinterval);
56  void setMinInterval(uint16_t mininterval);
57  void setAdvertisementData(BLEAdvertisementData& advertisementData);
58  void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly);
59  void setScanResponseData(BLEAdvertisementData& advertisementData);
60  void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM);
61 
62  void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param);
63  void setMinPreferred(uint16_t);
64  void setMaxPreferred(uint16_t);
65  void setScanResponse(bool);
66 
67 private:
68  esp_ble_adv_data_t m_advData;
69  esp_ble_adv_params_t m_advParams;
70  std::vector<BLEUUID> m_serviceUUIDs;
71  bool m_customAdvData = false; // Are we using custom advertising data?
72  bool m_customScanResponseData = false; // Are we using custom scan response data?
73  FreeRTOS::Semaphore m_semaphoreSetAdv = FreeRTOS::Semaphore("startAdvert");
74  bool m_scanResp = true;
75 
76 };
77 #endif /* CONFIG_BT_ENABLED */
78 #endif /* COMPONENTS_CPP_UTILS_BLEADVERTISING_H_ */
Definition: FreeRTOS.h:31