mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2026-01-28 01:52:27 +01:00
Add NimBLEAttValue class. (#67)
This is a specialized container class to hold BLE attribute values. - Removes the use of std::string previously used to store the values. - Allows for setting/getting/notifying values from std::string, std::vector<uint8_t>, Arduino String, const char*, and uint8_t buffers. - Has operators retrieve the value as std::string, Arduino String, std::vector<uint8_t>, uint8_t* or char pointers. - Includes iterators and subscript/random access operator. - Introduces a max length parameter to the creation of server characteristics/descriptors to limit the size of the memory footprint. - Nearly Seamless integration with existing code. - Adds a config option to enable/disable timestamp storage when the value is updated. - Adds a config option to specify the initial size of the value container if not specified in the constructor.
This commit is contained in:
@@ -768,11 +768,11 @@ int NimBLEClient::serviceDiscoveredCB(
|
||||
* @param [in] characteristicUUID The characteristic whose value we wish to read.
|
||||
* @returns characteristic value or an empty string if not found
|
||||
*/
|
||||
std::string NimBLEClient::getValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID) {
|
||||
NimBLEAttValue NimBLEClient::getValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> getValue: serviceUUID: %s, characteristicUUID: %s",
|
||||
serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
|
||||
|
||||
std::string ret = "";
|
||||
NimBLEAttValue ret;
|
||||
NimBLERemoteService* pService = getService(serviceUUID);
|
||||
|
||||
if(pService != nullptr) {
|
||||
@@ -796,7 +796,7 @@ std::string NimBLEClient::getValue(const NimBLEUUID &serviceUUID, const NimBLEUU
|
||||
* @returns true if successful otherwise false
|
||||
*/
|
||||
bool NimBLEClient::setValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID,
|
||||
const std::string &value, bool response)
|
||||
const NimBLEAttValue &value, bool response)
|
||||
{
|
||||
NIMBLE_LOGD(LOG_TAG, ">> setValue: serviceUUID: %s, characteristicUUID: %s",
|
||||
serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
|
||||
@@ -857,7 +857,7 @@ uint16_t NimBLEClient::getMTU() {
|
||||
* @param [in] arg A pointer to the client instance that registered for this callback.
|
||||
*/
|
||||
/*STATIC*/
|
||||
int NimBLEClient::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
||||
int NimBLEClient::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
||||
NimBLEClient* client = (NimBLEClient*)arg;
|
||||
int rc;
|
||||
|
||||
@@ -976,11 +976,7 @@ uint16_t NimBLEClient::getMTU() {
|
||||
(*characteristic)->toString().c_str());
|
||||
|
||||
uint32_t data_len = OS_MBUF_PKTLEN(event->notify_rx.om);
|
||||
time_t t = time(nullptr);
|
||||
ble_npl_hw_enter_critical();
|
||||
(*characteristic)->m_value = std::string((char *)event->notify_rx.om->om_data, data_len);
|
||||
(*characteristic)->m_timestamp = t;
|
||||
ble_npl_hw_exit_critical(0);
|
||||
(*characteristic)->m_value.setValue(event->notify_rx.om->om_data, data_len);
|
||||
|
||||
if ((*characteristic)->m_notifyCallback != nullptr) {
|
||||
NIMBLE_LOGD(LOG_TAG, "Invoking callback for notification on characteristic %s",
|
||||
|
||||
Reference in New Issue
Block a user