My Project
 All Classes Functions Variables Pages
BLEScan.h
1 /*
2  * BLEScan.h
3  *
4  * Created on: Jul 1, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_BLESCAN_H_
9 #define COMPONENTS_CPP_UTILS_BLESCAN_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 #include <esp_gap_ble_api.h>
13 
14 // #include <vector>
15 #include <string>
16 #include "BLEAdvertisedDevice.h"
17 #include "BLEClient.h"
18 #include "FreeRTOS.h"
19 
20 class BLEAdvertisedDevice;
21 class BLEAdvertisedDeviceCallbacks;
22 class BLEClient;
23 class BLEScan;
24 
25 
33 class BLEScanResults {
34 public:
35  void dump();
36  int getCount();
37  BLEAdvertisedDevice getDevice(uint32_t i);
38 
39 private:
40  friend BLEScan;
41  std::map<std::string, BLEAdvertisedDevice*> m_vectorAdvertisedDevices;
42 };
43 
49 class BLEScan {
50 public:
51  void setActiveScan(bool active);
52  void setAdvertisedDeviceCallbacks(
53  BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks,
54  bool wantDuplicates = false);
55  void setInterval(uint16_t intervalMSecs);
56  void setWindow(uint16_t windowMSecs);
57  bool start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue = false);
58  BLEScanResults start(uint32_t duration, bool is_continue = false);
59  void stop();
60  void erase(BLEAddress address);
61  BLEScanResults getResults();
62  void clearResults();
63 
64 private:
65  BLEScan(); // One doesn't create a new instance instead one asks the BLEDevice for the singleton.
66  friend class BLEDevice;
67  void handleGAPEvent(
68  esp_gap_ble_cb_event_t event,
69  esp_ble_gap_cb_param_t* param);
70  void parseAdvertisement(BLEClient* pRemoteDevice, uint8_t *payload);
71 
72 
73  esp_ble_scan_params_t m_scan_params;
74  BLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr;
75  bool m_stopped = true;
76  FreeRTOS::Semaphore m_semaphoreScanEnd = FreeRTOS::Semaphore("ScanEnd");
77  BLEScanResults m_scanResults;
78  bool m_wantDuplicates;
79  void (*m_scanCompleteCB)(BLEScanResults scanResults);
80 }; // BLEScan
81 
82 #endif /* CONFIG_BT_ENABLED */
83 #endif /* COMPONENTS_CPP_UTILS_BLESCAN_H_ */
Definition: FreeRTOS.h:31