Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9877d96

Browse files
Jeroen88h2zero
Jeroen88
andauthored
Remove getRawData() and getDataLength() (#41)
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. Co-authored-by: h2zero <[email protected]>
1 parent c2ae3cd commit 9877d96

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

src/NimBLERemoteCharacteristic.cpp

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
5353
m_uuid = nullptr;
5454
break;
5555
}
56+
5657
m_handle = chr->val_handle;
5758
m_defHandle = chr->def_handle;
5859
m_charProp = chr->properties;
5960
m_pRemoteService = pRemoteService;
6061
m_notifyCallback = nullptr;
61-
m_rawData = nullptr;
62-
m_dataLen = 0;
6362
m_timestamp = 0;
6463
} // NimBLERemoteCharacteristic
6564

@@ -69,9 +68,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
6968
*/
7069
NimBLERemoteCharacteristic::~NimBLERemoteCharacteristic() {
7170
removeDescriptors(); // Release resources for any descriptor information we may have allocated.
72-
if(m_rawData != nullptr) {
73-
free(m_rawData);
74-
}
7571
} // ~NimBLERemoteCharacteristic
7672

7773
/*
@@ -396,7 +392,7 @@ std::string NimBLERemoteCharacteristic::readValue(time_t *timestamp) {
396392
// Check to see that we are connected.
397393
if (!pClient->isConnected()) {
398394
NIMBLE_LOGE(LOG_TAG, "Disconnected");
399-
return "";
395+
return ""
400396
}
401397

402398
do {
@@ -702,36 +698,6 @@ int NimBLERemoteCharacteristic::onWriteCB(uint16_t conn_handle,
702698
}
703699

704700

705-
/**
706-
* @brief Read raw data from remote characteristic as hex bytes
707-
* @return uint8_t pointer to the data read.
708-
*/
709-
uint8_t* NimBLERemoteCharacteristic::readRawData() {
710-
if(m_rawData != nullptr) {
711-
free(m_rawData);
712-
m_rawData = nullptr;
713-
}
714-
715-
m_dataLen = m_value.length();
716-
// If we have data copy it to rawData
717-
if(m_dataLen) {
718-
m_rawData = (uint8_t*) calloc(m_dataLen, sizeof(uint8_t));
719-
memcpy(m_rawData, m_value.data(), m_dataLen);
720-
}
721-
722-
return m_rawData;
723-
}
724-
725-
726-
/**
727-
* @brief Get the length of the data read from the remote characteristic.
728-
* @return size_t length of the data in bytes.
729-
*/
730-
size_t NimBLERemoteCharacteristic::getDataLength() {
731-
return m_value.length();
732-
}
733-
734-
735701
void NimBLERemoteCharacteristic::releaseSemaphores() {
736702
for (auto &it: m_descriptorVector) {
737703
it->releaseSemaphores();

src/NimBLERemoteCharacteristic.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class NimBLERemoteCharacteristic {
8787
bool writeValue(uint8_t newValue,
8888
bool response = false);
8989
std::string toString();
90-
uint8_t* readRawData();
91-
size_t getDataLength();
9290
NimBLERemoteService* getRemoteService();
9391

9492
private:
@@ -121,8 +119,6 @@ class NimBLERemoteCharacteristic {
121119
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
122120
FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt");
123121
std::string m_value;
124-
uint8_t* m_rawData;
125-
size_t m_dataLen;
126122
notify_callback m_notifyCallback;
127123
time_t m_timestamp;
128124

0 commit comments

Comments
 (0)