forked from h2zero/esp-nimble-cpp
Conditionally compile code for specific roles.
This allows NimBLE options in menuconfig to reduce code size based on the roles selected (scan/advertising/central/peripheral). Significant code space can be saved by removing unnecessary roles for the application.
This commit is contained in:
1 parent
3d6f8b691e
commit
03cb7b21d9
53 files changed
+2335
-2012
No files matched your search
+79
-30
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
*
|
||||
*
|
||||
* Originally:
|
||||
*
|
||||
* BLEDevice.h
|
||||
@@ -17,11 +17,27 @@
|
||||
#include "sdkconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
#include "NimBLEScan.h"
|
||||
#include "NimBLEUtils.h"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
#include "NimBLEAdvertising.h"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
#include "NimBLEClient.h"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
#include "NimBLEServer.h"
|
||||
#endif
|
||||
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLESecurity.h"
|
||||
#include "NimBLEAddress.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
|
||||
@@ -50,43 +66,46 @@
|
||||
#define BLEAdvertising NimBLEAdvertising
|
||||
#define BLEServerCallbacks NimBLEServerCallbacks
|
||||
#define BLECharacteristicCallbacks NimBLECharacteristicCallbacks
|
||||
#define BLEAdvertisementData NimBLEAdvertisementData
|
||||
#define BLEDescriptor NimBLEDescriptor
|
||||
#define BLE2902 NimBLE2902
|
||||
#define BLE2904 NimBLE2904
|
||||
#define BLEDescriptorCallbacks NimBLEDescriptorCallbacks
|
||||
#define BLEAdvertisementData NimBLEAdvertisementData
|
||||
#define BLEDescriptor NimBLEDescriptor
|
||||
#define BLE2902 NimBLE2902
|
||||
#define BLE2904 NimBLE2904
|
||||
#define BLEDescriptorCallbacks NimBLEDescriptorCallbacks
|
||||
#define BLEBeacon NimBLEBeacon
|
||||
#define BLEEddystoneTLM NimBLEEddystoneTLM
|
||||
#define BLEEddystoneURL NimBLEEddystoneURL
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_MAX_CONNECTIONS
|
||||
#define NIMBLE_MAX_CONNECTIONS CONFIG_BT_NIMBLE_MAX_CONNECTIONS
|
||||
#else
|
||||
#else
|
||||
#define NIMBLE_MAX_CONNECTIONS CONFIG_NIMBLE_MAX_CONNECTIONS
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief BLE functions.
|
||||
*/
|
||||
typedef int (*gap_event_handler)(ble_gap_event *event, void *arg);
|
||||
//typedef void (*gattc_event_handler)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param);
|
||||
//typedef void (*gatts_event_handler)(esp_gatts_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gatts_cb_param_t* param);
|
||||
|
||||
extern "C" void ble_store_config_init(void);
|
||||
|
||||
class NimBLEDevice {
|
||||
public:
|
||||
static void init(const std::string &deviceName); // Initialize the local BLE environment.
|
||||
static void init(const std::string &deviceName);
|
||||
static void deinit();
|
||||
static bool getInitialized();
|
||||
static NimBLEAddress getAddress();
|
||||
static std::string toString();
|
||||
static NimBLEScan* getScan(); // Get the scan object
|
||||
static NimBLEClient* createClient();
|
||||
static NimBLEServer* createServer();
|
||||
static bool deleteClient(NimBLEClient* pClient);
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
static NimBLEScan* getScan();
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
static NimBLEServer* createServer();
|
||||
#endif
|
||||
|
||||
static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
|
||||
static int getPower(esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
|
||||
static int getPower(esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT);
|
||||
static void setCustomGapHandler(gap_event_handler handler);
|
||||
static void setSecurityAuth(bool bonding, bool mitm, bool sc);
|
||||
static void setSecurityAuth(uint8_t auth_req);
|
||||
@@ -101,36 +120,66 @@ public:
|
||||
static bool isIgnored(const NimBLEAddress &address);
|
||||
static void addIgnored(const NimBLEAddress &address);
|
||||
static void removeIgnored(const NimBLEAddress &address);
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
static NimBLEAdvertising* getAdvertising();
|
||||
static void startAdvertising();
|
||||
static void stopAdvertising();
|
||||
static void startAdvertising();
|
||||
static void stopAdvertising();
|
||||
#endif
|
||||
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
static NimBLEClient* createClient();
|
||||
static bool deleteClient(NimBLEClient* pClient);
|
||||
static NimBLEClient* getClientByID(uint16_t conn_id);
|
||||
static NimBLEClient* getClientByPeerAddress(const NimBLEAddress &peer_addr);
|
||||
static NimBLEClient* getDisconnectedClient();
|
||||
static size_t getClientListSize();
|
||||
static std::list<NimBLEClient*>* getClientList();
|
||||
|
||||
static size_t getClientListSize();
|
||||
static std::list<NimBLEClient*>* getClientList();
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend class NimBLEServer;
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
friend class NimBLEClient;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
friend class NimBLEScan;
|
||||
friend class NimBLEAdvertising;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
friend class NimBLEServer;
|
||||
friend class NimBLECharacteristic;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
friend class NimBLEAdvertising;
|
||||
#endif
|
||||
|
||||
static void onReset(int reason);
|
||||
static void onSync(void);
|
||||
static void host_task(void *param);
|
||||
static int startSecurity( uint16_t conn_id);
|
||||
|
||||
static bool m_synced;
|
||||
static int startSecurity(uint16_t conn_id);
|
||||
static bool m_synced;
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
|
||||
static NimBLEScan* m_pScan;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
static NimBLEServer* m_pServer;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
|
||||
static NimBLEAdvertising* m_bleAdvertising;
|
||||
static ble_gap_event_listener m_listener;
|
||||
static uint32_t m_passkey;
|
||||
#endif
|
||||
|
||||
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
static std::list <NimBLEClient*> m_cList;
|
||||
#endif
|
||||
static std::list <NimBLEAddress> m_ignoreList;
|
||||
static NimBLESecurityCallbacks* m_securityCallbacks;
|
||||
static uint32_t m_passkey;
|
||||
static ble_gap_event_listener m_listener;
|
||||
|
||||
public:
|
||||
static gap_event_handler m_customGapHandler;
|
||||
|
||||
Reference in new issue
Block a user