mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
Bugfixes + add new NimBLEUUID constructor.
This commit is contained in:
parent
725807b619
commit
1779a3f723
8 changed files with 42 additions and 35 deletions
|
@ -59,9 +59,9 @@ NimBLEAddress::NimBLEAddress(std::string stringAddress) {
|
|||
|
||||
/**
|
||||
* @brief Constructor for compatibility with bluedrioid esp library.
|
||||
* @param [in] esp_bd_addr_t struct containing the address.
|
||||
* @param [in] uint8_t[6] or esp_bd_addr_t struct containing the address.
|
||||
*/
|
||||
NimBLEAddress::NimBLEAddress(esp_bd_addr_t address) {
|
||||
NimBLEAddress::NimBLEAddress(uint8_t address[6]) {
|
||||
NimBLEUtils::memrcpy(m_address, address, 6);
|
||||
} // NimBLEAddress
|
||||
|
||||
|
|
|
@ -25,22 +25,6 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
typedef enum {
|
||||
BLE_ADDR_TYPE_PUBLIC = 0x00,
|
||||
BLE_ADDR_TYPE_RANDOM = 0x01,
|
||||
BLE_ADDR_TYPE_RPA_PUBLIC = 0x02,
|
||||
BLE_ADDR_TYPE_RPA_RANDOM = 0x03,
|
||||
} esp_nimble_addr_type_t;
|
||||
|
||||
typedef uint8_t esp_ble_addr_type_t ;
|
||||
|
||||
/// Bluetooth address length
|
||||
#define ESP_BD_ADDR_LEN 6
|
||||
|
||||
/// Bluetooth device address
|
||||
typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN];
|
||||
|
||||
|
||||
/**
|
||||
* @brief A %BLE device address.
|
||||
*
|
||||
|
@ -49,7 +33,7 @@ typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN];
|
|||
class NimBLEAddress {
|
||||
public:
|
||||
NimBLEAddress(ble_addr_t address);
|
||||
NimBLEAddress(esp_bd_addr_t address);
|
||||
NimBLEAddress(uint8_t address[6]);
|
||||
NimBLEAddress(std::string stringAddress);
|
||||
bool equals(NimBLEAddress otherAddress);
|
||||
uint8_t* getNative();
|
||||
|
|
|
@ -74,7 +74,7 @@ NimBLEClient::~NimBLEClient() {
|
|||
// Before we are finished with the client, we must release resources.
|
||||
clearServices();
|
||||
|
||||
if(m_deleteCallbacks) {
|
||||
if(m_deleteCallbacks && m_pClientCallbacks != &defaultCallbacks) {
|
||||
delete m_pClientCallbacks;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class NimBLEAdvertisedDevice;
|
|||
class NimBLEClient {
|
||||
public:
|
||||
bool connect(NimBLEAdvertisedDevice* device, bool refreshServices = true);
|
||||
bool connect(NimBLEAddress address, uint8_t type = BLE_ADDR_TYPE_PUBLIC, bool refreshServices = true); // Connect to the remote BLE Server
|
||||
bool connect(NimBLEAddress address, uint8_t type = BLE_ADDR_PUBLIC, bool refreshServices = true); // Connect to the remote BLE Server
|
||||
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM); // Disconnect from the remote BLE Server
|
||||
NimBLEAddress getPeerAddress(); // Get the address of the remote BLE Server
|
||||
int getRssi(); // Get the RSSI of the remote BLE Server
|
||||
|
|
|
@ -379,14 +379,16 @@ void NimBLEDevice::stopAdvertising() {
|
|||
|
||||
m_synced = true;
|
||||
|
||||
if(m_pScan != nullptr) {
|
||||
// Restart scanning with the last values sent, allow to clear results.
|
||||
m_pScan->start(m_pScan->m_duration, m_pScan->m_scanCompleteCB);
|
||||
}
|
||||
|
||||
if(m_bleAdvertising != nullptr) {
|
||||
// Restart advertisng, parameters should already be set.
|
||||
m_bleAdvertising->start();
|
||||
if(initialized) {
|
||||
if(m_pScan != nullptr) {
|
||||
// Restart scanning with the last values sent, allow to clear results.
|
||||
m_pScan->start(m_pScan->m_duration, m_pScan->m_scanCompleteCB);
|
||||
}
|
||||
|
||||
if(m_bleAdvertising != nullptr) {
|
||||
// Restart advertisng, parameters should already be set.
|
||||
m_bleAdvertising->start();
|
||||
}
|
||||
}
|
||||
} // onSync
|
||||
|
||||
|
@ -410,8 +412,6 @@ void NimBLEDevice::stopAdvertising() {
|
|||
*/
|
||||
/* STATIC */ void NimBLEDevice::init(std::string deviceName) {
|
||||
if(!initialized){
|
||||
initialized = true; // Set the initialization flag to ensure we are only initialized once.
|
||||
|
||||
int rc=0;
|
||||
esp_err_t errRc = ESP_OK;
|
||||
|
||||
|
@ -421,7 +421,7 @@ void NimBLEDevice::stopAdvertising() {
|
|||
#endif
|
||||
|
||||
errRc = nvs_flash_init();
|
||||
|
||||
|
||||
if (errRc == ESP_ERR_NVS_NO_FREE_PAGES || errRc == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
errRc = nvs_flash_init();
|
||||
|
@ -452,14 +452,15 @@ void NimBLEDevice::stopAdvertising() {
|
|||
assert(rc == 0);
|
||||
|
||||
ble_store_config_init();
|
||||
|
||||
|
||||
nimble_port_freertos_init(NimBLEDevice::host_task);
|
||||
}
|
||||
// Wait for host and controller to sync before returning and accepting new tasks
|
||||
while(!m_synced){
|
||||
vTaskDelay(1 / portTICK_PERIOD_MS);
|
||||
}
|
||||
//vTaskDelay(200 / portTICK_PERIOD_MS); // Delay for 200 msecs as a workaround to an apparent Arduino environment issue.
|
||||
|
||||
initialized = true; // Set the initialization flag to ensure we are only initialized once.
|
||||
} // init
|
||||
|
||||
|
||||
|
@ -477,6 +478,7 @@ void NimBLEDevice::stopAdvertising() {
|
|||
}
|
||||
|
||||
initialized = false;
|
||||
m_synced = false;
|
||||
}
|
||||
} // deinit
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ NimBLEScan::NimBLEScan() {
|
|||
|
||||
if (pScan->m_pAdvertisedDeviceCallbacks) {
|
||||
// If not active scanning report the result to the listener.
|
||||
if(pScan->m_scan_params.passive) {
|
||||
if(pScan->m_scan_params.passive || event->disc.event_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND) {
|
||||
pScan->m_pAdvertisedDeviceCallbacks->onResult(advertisedDevice);
|
||||
// Otherwise wait for the scan response so we can report all of the data at once.
|
||||
} else if (event->disc.event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) {
|
||||
|
|
|
@ -156,6 +156,26 @@ NimBLEUUID::NimBLEUUID(ble_uuid128_t* uuid) {
|
|||
} // NimBLEUUID
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a UUID from the 128bit value using hex parts instead of string,
|
||||
* instead of BLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"), it becomes
|
||||
* BLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)
|
||||
*
|
||||
* @param [in] first The first 32bit of the UUID.
|
||||
* @param [in] second The next 16bit of the UUID.
|
||||
* @param [in] third The next 16bit of the UUID.
|
||||
* @param [in] fourth The last 64bit of the UUID, combining the last 2 parts of the string equivalent
|
||||
*/
|
||||
NimBLEUUID::NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth) {
|
||||
m_uuid.u.type = BLE_UUID_TYPE_128;
|
||||
memcpy(m_uuid.u128.value + 12, &first, 4);
|
||||
memcpy(m_uuid.u128.value + 10, &second, 2);
|
||||
memcpy(m_uuid.u128.value + 8, &third, 2);
|
||||
memcpy(m_uuid.u128.value, &fourth, 8);
|
||||
m_valueSet = true;
|
||||
}
|
||||
|
||||
|
||||
NimBLEUUID::NimBLEUUID() {
|
||||
m_valueSet = false;
|
||||
} // NimBLEUUID
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
NimBLEUUID(uint32_t uuid);
|
||||
NimBLEUUID(ble_uuid128_t* uuid);
|
||||
NimBLEUUID(uint8_t* pData, size_t size, bool msbFirst);
|
||||
NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth);
|
||||
NimBLEUUID();
|
||||
uint8_t bitSize(); // Get the number of bits in this uuid.
|
||||
bool equals(NimBLEUUID uuid);
|
||||
|
|
Loading…
Reference in a new issue