8000 Add read raw data from remote characteristic · Netoperz/esp32-snippets@1012efc · GitHub
[go: up one dir, main page]

Skip to content

Commit 1012efc

Browse files
committed
Add read raw data from remote characteristic
1 parent 49d6aba commit 1012efc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

cpp_utils/BLERemoteCharacteristic.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ void BLERemoteCharacteristic::gattClientEventHandler(
204204
// and unlock the semaphore to ensure that the requestor of the data can continue.
205205
if (evtParam->read.status == ESP_GATT_OK) {
206206
m_value = std::string((char*)evtParam->read.value, evtParam->read.value_len);
207+
if(m_rawData != nullptr)
208+
free(m_rawData);
209+
210+
m_rawData = calloc(evtParam->read.value_len, sizeof(uint8_t));
211+
memcpy(m_rawData, evtParam->read.value, evtParam->read.value_len);
207212
} else {
208213
m_value = "";
209214
}
@@ -613,4 +618,12 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
613618
writeValue(std::string((char *)data, length), response);
614619
} // writeValue
615620

621+
/**
622+
* @brief Read raw data from remote characteristic as hex bytes
623+
* @return return pointer data read
624+
*/
625+
uint8_t* BLERemoteCharacteristic::readRawData() {
626+
return m_rawData;
627+
}
628+
616629
#endif /* CONFIG_BT_ENABLED */

cpp_utils/BLERemoteCharacteristic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class BLERemoteCharacteristic {
4949
void writeValue(std::string newValue, bool response = false);
5050
void writeValue(uint8_t newValue, bool response = false);
5151
std::string toString(void);
52+
uint8_t* readRawData();
5253

5354
private:
5455
BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
@@ -76,6 +77,7 @@ class BLERemoteCharacteristic {
7677
FreeRTOS::Semaphore m_semaphoreRegForNotifyEvt = FreeRTOS::Semaphore("RegForNotifyEvt");
7778
FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt");
7879
std::string m_value;
80+
uint8_t *m_rawData;
7981
void (*m_notifyCallback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, 421B uint8_t* pData, size_t length, bool isNotify);
8082

8183
// We maintain a map of descriptors owned by this characteristic keyed by a string representation of the UUID.

0 commit comments

Comments
 (0)
0