summaryrefslogtreecommitdiff
path: root/sensor/patchedBLE/src/BLEScan.h
blob: 2f71a72738e81269e42308c4562d0a2595f44d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * BLEScan.h
 *
 *  Created on: Jul 1, 2017
 *      Author: kolban
 */
 
#ifndef COMPONENTS_CPP_UTILS_BLESCAN_H_
#define COMPONENTS_CPP_UTILS_BLESCAN_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <esp_gap_ble_api.h>
 
// #include <vector> 
#include <string>
#include "BLEAdvertisedDevice.h"
#include "BLEClient.h"
#include "FreeRTOS.h"
 
class BLEAdvertisedDevice;
class BLEAdvertisedDeviceCallbacks;
class BLEClient;
class BLEScan;
 
 
/**
 * @brief The result of having performed a scan.
 * When a scan completes, we have a set of found devices.  Each device is described
 * by a BLEAdvertisedDevice object.  The number of items in the set is given by
 * getCount().  We can retrieve a device by calling getDevice() passing in the
 * index (starting at 0) of the desired device.
 */
class BLEScanResults {
public:
void                dump();
int                 getCount();
BLEAdvertisedDevice getDevice(uint32_t i);
 
private:
friend BLEScan;
std::map<std::string, BLEAdvertisedDevice*> m_vectorAdvertisedDevices;
};
 
/**
 * @brief Perform and manage %BLE scans.
 *
 * Scanning is associated with a %BLE client that is attempting to locate BLE servers.
 */
class BLEScan {
public:
void           setActiveScan(bool active);
void           setAdvertisedDeviceCallbacks(
              BLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks,
bool wantDuplicates = false);
void           setInterval(uint16_t intervalMSecs);
void           setWindow(uint16_t windowMSecs);
bool           start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue = false);
BLEScanResults start(uint32_t duration, bool is_continue = false);
void           stop();
void     erase(BLEAddress address);
BLEScanResults getResults();
void clearResults();
 
private:
BLEScan();   // One doesn't create a new instance instead one asks the BLEDevice for the singleton. 
friend class BLEDevice;
void         handleGAPEvent(
esp_gap_ble_cb_event_t  event,
esp_ble_gap_cb_param_t* param);
void parseAdvertisement(BLEClient* pRemoteDevice, uint8_t *payload);
 
 
esp_ble_scan_params_t         m_scan_params;
BLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr;
bool                          m_stopped = true;
FreeRTOS::Semaphore           m_semaphoreScanEnd = FreeRTOS::Semaphore("ScanEnd");
BLEScanResults                m_scanResults;
bool                          m_wantDuplicates;
void                        (*m_scanCompleteCB)(BLEScanResults scanResults);
}; // BLEScan 
 
#endif /* CONFIG_BT_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLESCAN_H_ */