From ffcb325aea6bfaf0b70c69e28e06a7d8686e669f Mon Sep 17 00:00:00 2001 From: h2zero Date: Fri, 29 May 2020 20:49:46 -0600 Subject: [PATCH] Remove getRawData() and getDataLength() Previously getRawData() made an unnecessary copy of the remote characteristic value data in order to return a uint8_t*. The resources used for this was unjustified by the value it provided as templates to retrieve such data have been added. Also the application writer could cast the std::string result of readValue() and/or getValue() however they choose using the data() method on the container if desired. getDataLength() is also an unnecessary function as the length can be retrieved by the returned std::string from readValue() and/or getValue() with the length() method. --- src/NimBLERemoteCharacteristic.cpp | 36 +----------------------------- src/NimBLERemoteCharacteristic.h | 4 ---- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/src/NimBLERemoteCharacteristic.cpp b/src/NimBLERemoteCharacteristic.cpp index c879d71..5e4a7cb 100644 --- a/src/NimBLERemoteCharacteristic.cpp +++ b/src/NimBLERemoteCharacteristic.cpp @@ -53,13 +53,12 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic"; m_uuid = nullptr; break; } + m_handle = chr->val_handle; m_defHandle = chr->def_handle; m_charProp = chr->properties; m_pRemoteService = pRemoteService; m_notifyCallback = nullptr; - m_rawData = nullptr; - m_dataLen = 0; m_timestamp = 0; } // NimBLERemoteCharacteristic @@ -69,9 +68,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic"; */ NimBLERemoteCharacteristic::~NimBLERemoteCharacteristic() { removeDescriptors(); // Release resources for any descriptor information we may have allocated. - if(m_rawData != nullptr) { - free(m_rawData); - } } // ~NimBLERemoteCharacteristic /* @@ -702,36 +698,6 @@ int NimBLERemoteCharacteristic::onWriteCB(uint16_t conn_handle, } -/** - * @brief Read raw data from remote characteristic as hex bytes - * @return uint8_t pointer to the data read. - */ -uint8_t* NimBLERemoteCharacteristic::readRawData() { - if(m_rawData != nullptr) { - free(m_rawData); - m_rawData = nullptr; - } - - m_dataLen = m_value.length(); - // If we have data copy it to rawData - if(m_dataLen) { - m_rawData = (uint8_t*) calloc(m_dataLen, sizeof(uint8_t)); - memcpy(m_rawData, m_value.data(), m_dataLen); - } - - return m_rawData; -} - - -/** - * @brief Get the length of the data read from the remote characteristic. - * @return size_t length of the data in bytes. - */ -size_t NimBLERemoteCharacteristic::getDataLength() { - return m_value.length(); -} - - void NimBLERemoteCharacteristic::releaseSemaphores() { for (auto &it: m_descriptorVector) { it->releaseSemaphores(); diff --git a/src/NimBLERemoteCharacteristic.h b/src/NimBLERemoteCharacteristic.h index f6afa21..4b66458 100644 --- a/src/NimBLERemoteCharacteristic.h +++ b/src/NimBLERemoteCharacteristic.h @@ -87,8 +87,6 @@ public: bool writeValue(uint8_t newValue, bool response = false); std::string toString(); - uint8_t* readRawData(); - size_t getDataLength(); NimBLERemoteService* getRemoteService(); private: @@ -121,8 +119,6 @@ private: FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt"); FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt"); std::string m_value; - uint8_t* m_rawData; - size_t m_dataLen; notify_callback m_notifyCallback; time_t m_timestamp;