esp-nimble-cpp / NimBLE-Arduino  1.3.1
NimBLEScan.h
1 /*
2  * NimBLEScan.h
3  *
4  * Created: on Jan 24 2020
5  * Author H2zero
6  *
7  * Originally:
8  *
9  * BLEScan.h
10  *
11  * Created on: Jul 1, 2017
12  * Author: kolban
13  */
14 #ifndef COMPONENTS_NIMBLE_SCAN_H_
15 #define COMPONENTS_NIMBLE_SCAN_H_
16 #include "sdkconfig.h"
17 #if defined(CONFIG_BT_ENABLED)
18 
19 #include "nimconfig.h"
20 #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
21 
22 #include "NimBLEAdvertisedDevice.h"
23 #include "NimBLEUtils.h"
24 
25 #include "host/ble_gap.h"
26 
27 #include <vector>
28 
29 class NimBLEDevice;
30 class NimBLEScan;
33 class NimBLEAddress;
34 
43 public:
44  void dump();
45  int getCount();
47  std::vector<NimBLEAdvertisedDevice*>::iterator begin();
48  std::vector<NimBLEAdvertisedDevice*>::iterator end();
50 
51 private:
52  friend NimBLEScan;
53  std::vector<NimBLEAdvertisedDevice*> m_advertisedDevicesVector;
54 };
55 
61 class NimBLEScan {
62 public:
63  bool start(uint32_t duration, void (*scanCompleteCB)(NimBLEScanResults), bool is_continue = false);
64  NimBLEScanResults start(uint32_t duration, bool is_continue = false);
65  bool isScanning();
66  void setAdvertisedDeviceCallbacks(NimBLEAdvertisedDeviceCallbacks* pAdvertisedDeviceCallbacks, bool wantDuplicates = false);
67  void setActiveScan(bool active);
68  void setInterval(uint16_t intervalMSecs);
69  void setWindow(uint16_t windowMSecs);
70  void setDuplicateFilter(bool enabled);
71  void setLimitedOnly(bool enabled);
72  void setFilterPolicy(uint8_t filter);
73  void clearDuplicateCache();
74  bool stop();
75  void clearResults();
77  void setMaxResults(uint8_t maxResults);
78  void erase(const NimBLEAddress &address);
79 
80 
81 private:
82  friend class NimBLEDevice;
83 
84  NimBLEScan();
85  ~NimBLEScan();
86  static int handleGapEvent(ble_gap_event* event, void* arg);
87  void onHostReset();
88  void onHostSync();
89 
90  NimBLEAdvertisedDeviceCallbacks* m_pAdvertisedDeviceCallbacks = nullptr;
91  void (*m_scanCompleteCB)(NimBLEScanResults scanResults);
92  ble_gap_disc_params m_scan_params;
93  bool m_ignoreResults;
94  NimBLEScanResults m_scanResults;
95  uint32_t m_duration;
96  ble_task_data_t *m_pTaskData;
97  uint8_t m_maxResults;
98 };
99 
100 #endif // #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
101 #endif /* CONFIG_BT_ENABLED */
102 #endif /* COMPONENTS_NIMBLE_SCAN_H_ */
A BLE device address.
Definition: NimBLEAddress.h:34
A callback handler for callbacks associated device scanning.
Definition: NimBLEAdvertisedDevice.h:162
A representation of a BLE advertised device found by a scan.
Definition: NimBLEAdvertisedDevice.h:40
A model of a BLE Device from which all the BLE roles are created.
Definition: NimBLEDevice.h:91
Perform and manage BLE scans.
Definition: NimBLEScan.h:61
bool start(uint32_t duration, void(*scanCompleteCB)(NimBLEScanResults), bool is_continue=false)
Start scanning.
Definition: NimBLEScan.cpp:286
NimBLEScanResults getResults()
Get the results of the scan.
Definition: NimBLEScan.cpp:455
void setInterval(uint16_t intervalMSecs)
Set the interval to scan.
Definition: NimBLEScan.cpp:256
void setFilterPolicy(uint8_t filter)
Sets the scan filter policy.
Definition: NimBLEScan.cpp:225
void erase(const NimBLEAddress &address)
Delete peer device from the scan results vector.
Definition: NimBLEScan.cpp:418
bool stop()
Stop an in progress scan.
Definition: NimBLEScan.cpp:377
void clearDuplicateCache()
Clears the duplicate scan filter cache.
Definition: NimBLEScan.cpp:406
void setLimitedOnly(bool enabled)
Set whether or not the BLE controller only report scan results from devices advertising in limited di...
Definition: NimBLEScan.cpp:202
void setActiveScan(bool active)
Should we perform an active or passive scan? The default is a passive scan. An active scan means that...
Definition: NimBLEScan.cpp:180
void setMaxResults(uint8_t maxResults)
Sets the max number of results to store.
Definition: NimBLEScan.cpp:235
void setAdvertisedDeviceCallbacks(NimBLEAdvertisedDeviceCallbacks *pAdvertisedDeviceCallbacks, bool wantDuplicates=false)
Set the call backs to be invoked.
Definition: NimBLEScan.cpp:245
bool isScanning()
Get the status of the scanner.
Definition: NimBLEScan.cpp:274
void setWindow(uint16_t windowMSecs)
Set the window to actively scan.
Definition: NimBLEScan.cpp:265
void setDuplicateFilter(bool enabled)
Set whether or not the BLE controller should only report results from devices it has not already seen...
Definition: NimBLEScan.cpp:192
void clearResults()
Clear the results of the scan.
Definition: NimBLEScan.cpp:463
A class that contains and operates on the results of a BLE scan.
Definition: NimBLEScan.h:42
void dump()
Dump the scan results to the log.
Definition: NimBLEScan.cpp:475
std::vector< NimBLEAdvertisedDevice * >::iterator end()
Get iterator to the end of the vector of advertised device pointers.
Definition: NimBLEScan.cpp:516
NimBLEAdvertisedDevice getDevice(uint32_t i)
Return the specified device at the given index. The index should be between 0 and getCount()-1.
Definition: NimBLEScan.cpp:498
std::vector< NimBLEAdvertisedDevice * >::iterator begin()
Get iterator to the beginning of the vector of advertised device pointers.
Definition: NimBLEScan.cpp:507
int getCount()
Get the count of devices found in the last scan.
Definition: NimBLEScan.cpp:487