Skip to content

Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parame… #3531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions libraries/BLE/src/BLERemoteCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ BLEUUID BLERemoteCharacteristic::getUUID() {
* @brief Read an unsigned 16 bit value
* @return The unsigned 16 bit value.
*/
uint16_t BLERemoteCharacteristic::readUInt16() {
std::string value = readValue();
uint16_t BLERemoteCharacteristic::readUInt16(esp_gatt_auth_req_t auth) {
std::string value = readValue(auth);
if (value.length() >= 2) {
return *(uint16_t*)(value.data());
}
Expand All @@ -368,8 +368,8 @@ uint16_t BLERemoteCharacteristic::readUInt16() {
* @brief Read an unsigned 32 bit value.
* @return the unsigned 32 bit value.
*/
uint32_t BLERemoteCharacteristic::readUInt32() {
std::string value = readValue();
uint32_t BLERemoteCharacteristic::readUInt32(esp_gatt_auth_req_t auth) {
std::string value = readValue(auth);
if (value.length() >= 4) {
return *(uint32_t*)(value.data());
}
Expand All @@ -381,8 +381,8 @@ uint32_t BLERemoteCharacteristic::readUInt32() {
* @brief Read a byte value
* @return The value as a byte
*/
uint8_t BLERemoteCharacteristic::readUInt8() {
std::string value = readValue();
uint8_t BLERemoteCharacteristic::readUInt8(esp_gatt_auth_req_t auth) {
std::string value = readValue(auth);
if (value.length() >= 1) {
return (uint8_t)value[0];
}
Expand All @@ -393,8 +393,8 @@ uint8_t BLERemoteCharacteristic::readUInt8() {
* @brief Read a float value.
* @return the float value.
*/
float BLERemoteCharacteristic::readFloat() {
std::string value = readValue();
float BLERemoteCharacteristic::readFloat(esp_gatt_auth_req_t auth) {
std::string value = readValue(auth);
if (value.length() >= 4) {
return *(float*)(value.data());
}
Expand All @@ -405,7 +405,7 @@ float BLERemoteCharacteristic::readFloat() {
* @brief Read the value of the remote characteristic.
* @return The value of the remote characteristic.
*/
std::string BLERemoteCharacteristic::readValue() {
std::string BLERemoteCharacteristic::readValue(esp_gatt_auth_req_t auth) {
log_v(">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle());

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

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


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


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

Expand All @@ -574,7 +574,7 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
length,
data,
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
ESP_GATT_AUTH_REQ_NONE
auth
);

if (errRc != ESP_OK) {
Expand Down
16 changes: 8 additions & 8 deletions libraries/BLE/src/BLERemoteCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class BLERemoteCharacteristic {
std::map<std::string, BLERemoteDescriptor*>* getDescriptors();
uint16_t getHandle();
BLEUUID getUUID();
std::string readValue();
uint8_t readUInt8();
uint16_t readUInt16();
uint32_t readUInt32();
float readFloat();
std::string readValue(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
uint8_t readUInt8(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
uint16_t readUInt16(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
uint32_t readUInt32(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
float readFloat(esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
void registerForNotify(notify_callback _callback, bool notifications = true);
void writeValue(uint8_t* data, size_t length, bool response = false);
void writeValue(std::string newValue, bool response = false);
void writeValue(uint8_t newValue, bool response = false);
void writeValue(uint8_t* data, size_t length, bool response = false, esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
void writeValue(std::string newValue, bool response = false, esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
void writeValue(uint8_t newValue, bool response = false, esp_gatt_auth_req_t auth = ESP_GATT_AUTH_REQ_NONE);
std::string toString();
uint8_t* readRawData();

Expand Down