From 74ba03e3a88ba118a0fed53df8fb6e44cee9b7fe Mon Sep 17 00:00:00 2001 From: h2zero Date: Tue, 31 Mar 2020 20:16:27 -0600 Subject: [PATCH] Add CMakeLists.txt. Fix compilation in strict enviroments. Fix compliation in IDF v4.0. --- API_DIFFERENCES.md | 10 ++++----- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++ README.md | 3 +-- src/FreeRTOS.cpp | 4 ++++ src/FreeRTOS.h | 4 ++++ src/NimBLEAdvertisedDevice.cpp | 2 +- src/NimBLEAdvertising.h | 4 ++++ src/NimBLECharacteristic.h | 4 ++++ src/NimBLERemoteCharacteristic.cpp | 8 +++---- src/NimBLERemoteDescriptor.cpp | 8 +++---- src/NimBLEUUID.h | 4 ++++ src/NimBLEUtils.cpp | 4 ++-- 12 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 CMakeLists.txt diff --git a/API_DIFFERENCES.md b/API_DIFFERENCES.md index f47f8d0..d503569 100644 --- a/API_DIFFERENCES.md +++ b/API_DIFFERENCES.md @@ -120,13 +120,13 @@ The default configuration will use "just-works" pairing with no bonding, if you Security callback functions are now incorporated in the client/server Callbacks class. However backward compatibility with the `BLESecurity` class is retained to minimize app code changes. -The relevent server callbacks are defined as: +The relevant server callbacks are defined as: ``` bool onConfirmPIN(uint32_t pin); // accept or reject the passkey void onAuthenticationComplete(ble_gap_conn_desc* desc); // auth complete - details in desc bool onPassKeyNotify(uint32_t pass_key); // receive the passkey sent by the client, accept or reject ``` -The relevent client callbacks are defined as: +The relevant client callbacks are defined as: ``` bool onConfirmPIN(uint32_t pin); // accept or reject the passkey void onAuthenticationComplete(ble_gap_conn_desc* desc); // auth complete - details in desc @@ -148,7 +148,7 @@ static void setSecurityRespKey(uint8_t init_key); * @param mitm, if true we are capable of man in the middle protection, false if not. * @param sc, if true we will perform secure connection pairing, false we will use legacy pairing. */ -void NimBLEDevice::setSecuityAuth(bool bonding, bool mitm, bool sc) +void NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc) @@ -162,7 +162,7 @@ void NimBLEDevice::setSecuityAuth(bool bonding, bool mitm, bool sc) ** 0x10 BLE_SM_PAIR_AUTHREQ_KEYPRESS - not yet supported. ** 0xe2 BLE_SM_PAIR_AUTHREQ_RESERVED - for reference only. */ -void NimBLEDevice::setSecuityAuth(uint8_t auth_req) +void NimBLEDevice::setSecurityAuth(uint8_t auth_req) @@ -204,4 +204,4 @@ void NimBLEDevice::setSecurityRespKey(uint8_t init_key) ``` I'm sure there are more things I have forgotten but this is all the majors. - I will update this document as necessary. \ No newline at end of file + I will update this document as necessary. diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1eb9d2e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(SUPPORTED_TARGETS esp32) + +idf_component_register(SRCS "src/FreeRTOS.cpp" + "src/NimBLE2902.cpp" + "src/NimBLE2904.cpp" + "src/NimBLEAddress.cpp" + "src/NimBLEAdvertisedDevice.cpp" + "src/NimBLEAdvertising.cpp" + "src/NimBLEBeacon.cpp" + "src/NimBLECharacteristic.cpp" + "src/NimBLECharacteristicMap.cpp" + "src/NimBLEClient.cpp" + "src/NimBLEDescriptor.cpp" + "src/NimBLEDescriptorMap.cpp" + "src/NimBLEDevice.cpp" + "src/NimBLEEddystoneTLM.cpp" + "src/NimBLEEddystoneURL.cpp" + "src/NimBLERemoteCharacteristic.cpp" + "src/NimBLERemoteDescriptor.cpp" + "src/NimBLERemoteService.cpp" + "src/NimBLEScan.cpp" + "src/NimBLESecurity.cpp" + "src/NimBLEServer.cpp" + "src/NimBLEService.cpp" + "src/NimBLEServiceMap.cpp" + "src/NimBLEUtils.cpp" + "src/NimBLEUUID.cpp" + "src/NimBLEValue.cpp" + INCLUDE_DIRS "src" + REQUIRES bt) diff --git a/README.md b/README.md index 6252fdc..5ffa3c5 100644 --- a/README.md +++ b/README.md @@ -37,5 +37,4 @@ This library is intended to be compatible with the original ESP32 BLE functions 1. Code cleanup. 2. Create documentation. 3. Expose more NimBLE features. -4. Add BLE Mesh code. - +4. Add BLE Mesh code. \ No newline at end of file diff --git a/src/FreeRTOS.cpp b/src/FreeRTOS.cpp index 6435590..ced1616 100644 --- a/src/FreeRTOS.cpp +++ b/src/FreeRTOS.cpp @@ -261,7 +261,11 @@ void FreeRTOS::Semaphore::setName(std::string name) { * @param [in] length The amount of storage to allocate for the ring buffer. * @param [in] type The type of buffer. One of RINGBUF_TYPE_NOSPLIT, RINGBUF_TYPE_ALLOWSPLIT, RINGBUF_TYPE_BYTEBUF. */ +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) +Ringbuffer::Ringbuffer(size_t length, RingbufferType_t type) { +#else Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type) { +#endif m_handle = ::xRingbufferCreate(length, type); } // Ringbuffer diff --git a/src/FreeRTOS.h b/src/FreeRTOS.h index efec5be..40462f4 100644 --- a/src/FreeRTOS.h +++ b/src/FreeRTOS.h @@ -61,7 +61,11 @@ public: */ class Ringbuffer { public: +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) + Ringbuffer(size_t length, RingbufferType_t type = RINGBUF_TYPE_NOSPLIT); +#else Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT); +#endif ~Ringbuffer(); void* receive(size_t* size, TickType_t wait = portMAX_DELAY); diff --git a/src/NimBLEAdvertisedDevice.cpp b/src/NimBLEAdvertisedDevice.cpp index a0c2e30..ff0097a 100644 --- a/src/NimBLEAdvertisedDevice.cpp +++ b/src/NimBLEAdvertisedDevice.cpp @@ -504,7 +504,7 @@ std::string NimBLEAdvertisedDevice::toString() { } if (haveTXPower()) { - char val[4]; + char val[5]; snprintf(val, sizeof(val), "%d", getTXPower()); res += ", txPower: "; res += val; diff --git a/src/NimBLEAdvertising.h b/src/NimBLEAdvertising.h index cfb8adc..9e8f131 100644 --- a/src/NimBLEAdvertising.h +++ b/src/NimBLEAdvertising.h @@ -18,6 +18,10 @@ #if defined(CONFIG_BT_ENABLED) #include "host/ble_gap.h" +/**** FIX COMPILATION ****/ +#undef min +#undef max +/**************************/ #include "NimBLEUUID.h" #include "FreeRTOS.h" diff --git a/src/NimBLECharacteristic.h b/src/NimBLECharacteristic.h index 743178a..1787937 100644 --- a/src/NimBLECharacteristic.h +++ b/src/NimBLECharacteristic.h @@ -17,6 +17,10 @@ #if defined(CONFIG_BT_ENABLED) #include "host/ble_hs.h" +/**** FIX COMPILATION ****/ +#undef min +#undef max +/**************************/ typedef enum { READ = BLE_GATT_CHR_F_READ, diff --git a/src/NimBLERemoteCharacteristic.cpp b/src/NimBLERemoteCharacteristic.cpp index f054c00..bf60d81 100644 --- a/src/NimBLERemoteCharacteristic.cpp +++ b/src/NimBLERemoteCharacteristic.cpp @@ -346,13 +346,13 @@ std::string NimBLERemoteCharacteristic::readValue() { switch(rc){ case 0: break; - + case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHEN): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHOR): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_ENC): if (retryCount && pClient->secureConnection()) break; - + /* Else falls through. */ default: return ""; } @@ -545,13 +545,13 @@ bool NimBLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool r switch(rc){ case 0: break; - + case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHEN): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHOR): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_ENC): if (retryCount && pClient->secureConnection()) break; - + /* Else falls through. */ default: return false; } diff --git a/src/NimBLERemoteDescriptor.cpp b/src/NimBLERemoteDescriptor.cpp index 7b61cc6..d862a8c 100644 --- a/src/NimBLERemoteDescriptor.cpp +++ b/src/NimBLERemoteDescriptor.cpp @@ -134,13 +134,13 @@ std::string NimBLERemoteDescriptor::readValue() { switch(rc){ case 0: break; - + case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHEN): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHOR): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_ENC): if (retryCount && pClient->secureConnection()) break; - + /* Else falls through. */ default: return ""; } @@ -265,13 +265,13 @@ bool NimBLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool respo switch(rc){ case 0: break; - + case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHEN): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_AUTHOR): case BLE_HS_ATT_ERR(BLE_ATT_ERR_INSUFFICIENT_ENC): if (retryCount && pClient->secureConnection()) break; - + /* Else falls through. */ default: return false; } diff --git a/src/NimBLEUUID.h b/src/NimBLEUUID.h index df36a52..63230fb 100644 --- a/src/NimBLEUUID.h +++ b/src/NimBLEUUID.h @@ -18,6 +18,10 @@ #if defined(CONFIG_BT_ENABLED) #include "host/ble_uuid.h" +/**** FIX COMPILATION ****/ +#undef min +#undef max +/**************************/ #include diff --git a/src/NimBLEUtils.cpp b/src/NimBLEUtils.cpp index 1ac609d..3911fd7 100644 --- a/src/NimBLEUtils.cpp +++ b/src/NimBLEUtils.cpp @@ -490,7 +490,7 @@ const char* NimBLEUtils::gapEventToString(uint8_t eventType) { case BLE_GAP_EVENT_EXT_DISC: //19 return "BLE_GAP_EVENT_EXT_DISC"; - +#ifdef BLE_GAP_EVENT_PERIODIC_SYNC // IDF 4.0 does not support these case BLE_GAP_EVENT_PERIODIC_SYNC: //20 return "BLE_GAP_EVENT_PERIODIC_SYNC"; @@ -502,7 +502,7 @@ const char* NimBLEUtils::gapEventToString(uint8_t eventType) { case BLE_GAP_EVENT_SCAN_REQ_RCVD: //23 return "BLE_GAP_EVENT_SCAN_REQ_RCVD"; - +#endif default: NIMBLE_LOGD(LOG_TAG, "gapEventToString: Unknown event type %d 0x%.2x", eventType, eventType); return "Unknown event type";