8000 Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parame… · cipherz/arduino-esp32@ec5afd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec5afd0

Browse files
committed
Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parameter for readValue and writeValue.
1 parent cec3fca commit ec5afd0

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

libraries/BLE/src/BLERemoteCharacteristic.cpp

8000
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ BLEUUID BLERemoteCharacteristic::getUUID() {
355355
* @brief Read an unsigned 16 bit value
356356
* @return The unsigned 16 bit value.
357357
*/
358-
uint16_t BLERemoteCharacteristic::readUInt16() {
359-
std::string value = readValue();
358+
uint16_t BLERemoteCharacteristic::readUInt16(esp_gatt_auth_req_t auth) {
359+
std::string value = readValue(auth);
360360
if (value.length() >= 2) {
361361
return *(uint16_t*)(value.data());
362362
}
@@ -368,8 +368,8 @@ uint16_t BLERemoteCharacteristic::readUInt16() {
368368
* @brief Read an unsigned 32 bit value.
369369
* @return the unsigned 32 bit value.
370370
*/
371-
uint32_t BLERemoteCharacteristic::readUInt32() {
372-
std::string value = readValue();
371+
uint32_t BLERemoteCharacteristic::readUInt32(esp_gatt_auth_req_t auth) {
372+
std::string value = readValue(auth);
373373
if (value.length() >= 4) {
374374
return *(uint32_t*)(value.data());
375375
}
@@ -381,8 +381,8 @@ uint32_t BLERemoteCharacteristic::readUInt32() {
381381
* @brief Read a byte value
382382
* @return The value as a byte
383383
*/
384-
uint8_t BLERemoteCharacteristic::readUInt8() {
385-
std::string value = readValue();
384+
uint8_t BLERemoteCharacteristic::readUInt8(esp_gatt_auth_req_t auth) {
385+
std::string value = readValue(auth);
386386
if (value.length() >= 1) {
387387
return (uint8_t)value[0];
388388
}
@@ -393,8 +393,8 @@ uint8_t BLERemoteCharacteristic::readUInt8() {
393393
* @brief Read a float value.
394394
* @return the float value.
395395
*/
396-
float BLERemoteCharacteristic::readFloat() {
397-
std::string value = readValue();
396+
float BLERemoteCharacteristic::readFloat(esp_gatt_auth_req_t auth) {
397+
std::string value = readValue(auth);
398398
if (value.length() >= 4) {
399399
return *(float*)(value.data());
400400
}
@@ -405,7 +405,7 @@ float BLERemoteCharacteristic::readFloat() {
405405
* @brief Read the value of the remote characteristic.
406406
* @return The value of the remote characteristic.
407407
*/
408-
std::string BLERemoteCharacteristic::readValue() {
408+
std::string BLERemoteCharacteristic::readValue(esp_gatt_auth_req_t auth) {
409409
log_v(">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle());
410410

411411
// Check to see that we are connected.
@@ -423,7 +423,7 @@ std::string BLERemoteCharacteristic::readValue() {
423423
m_pRemoteService->getClient()->getGattcIf(),
424424
m_pRemoteService->getClient()->getConnId(), // The connection ID to the BLE server
425425
getHandle(), // The handle of this characteristic
426-
ESP_GATT_AUTH_REQ_NONE); // Security
426+
auth); // Security
427427

428428
if (errRc != ESP_OK) {
429429
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
@@ -531,8 +531,8 @@ std::string BLERemoteCharacteristic::toString() {
531531
* @param [in] response Do we expect a response?
532532
* @return N/A.
533533
*/
534-
void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
535-
writeValue((uint8_t*)newValue.c_str(), strlen(newValue.c_str()), response);
534+
void BLERemoteCharacteristic::writeValue(std::string newValue, bool response, esp_gatt_auth_req_t auth) {
535+
writeValue((uint8_t*)newValue.c_str(), strlen(newValue.c_str()), response, auth);
536536
} // writeValue
537537

538538

@@ -544,8 +544,8 @@ void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
544544
* @param [in] response Whether we require a response from the write.
545545
* @return N/A.
546546
*/
547-
void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) {
548-
writeValue(&newValue, 1, response);
547+
void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response, esp_gatt_auth_req_t auth) {
548+
writeValue(&newValue, 1, response, auth);
549549
} // writeValue
550550

551551

@@ -555,7 +555,7 @@ void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) {
555555
* @param [in] length The length of the data in the data buffer.
556556
* @param [in] response Whether we require a response from the write.
557557
*/
558-
void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response) {
558+
void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response, esp_gatt_auth_req_t auth) {
559559
// writeValue(std::string((char*)data, length), response);
560560
log_v(">> writeValue(), length: %d", length);
561561

@@ -574,7 +574,7 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
574574
length,
575575
data,
576576
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
577-
ESP_GATT_AUTH_REQ_NONE
577+
auth
578578
);
579579

580580
if (errRc != ESP_OK) {

libraries/BLE/src/BLERemoteCharacteristic.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ class BLERemoteCharacteristic {
4141
std::map<std::string, BLERemoteDescriptor*>* getDescriptors();
4242
uint16_t getHandle();
4343
BLEUUID getUUID();
44-
std::string readValue();
45-
uint8_t readUInt8();
46-
uint16_t readUInt16();
47-
uint32_t readUInt32();
48-
float readFloat();
44+
std::string readValue(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
45+
uint8_t readUInt8(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
46+
uint16_t readUInt16(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
47+
uint32_t readUInt32(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
48+
float readFloat(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
4949
void registerForNotify(notify_callback _callback, bool notifications = true);
50-
void writeValue(uint8_t* data, size_t length, bool response = false);
51-
void writeValue(std::string newValue, bool response = false);
52-
void writeValue(uint8_t newValue, bool response = false);
50+
void writeValue(uint8_t* data, size_t length, bool response = false, esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
51+
void writeValue(std::string newValue, bool response = false, esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
52+
void writeValue(uint8_t newValue, bool response = false, esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
5353
std::string toString();
5454
uint8_t* readRawData();
5555

0 commit comments

Comments
 (0)
0