Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 9 additions & 4 deletions src/NimBLEAttValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
#include "syscfg/syscfg.h"
#if CONFIG_BT_NIMBLE_ENABLED

# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
# include <Arduino.h>
/* Enables the use of Arduino String class for attribute values */
# ifndef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (__has_include(<Arduino.h>))
# endif

# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
# include <WString.h>
# endif

# include <string>
Expand Down Expand Up @@ -145,7 +150,7 @@ class NimBLEAttValue {
NimBLEAttValue(const std::vector<uint8_t> vec, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
: NimBLEAttValue(&vec[0], vec.size(), max_len) {}

# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
/**
* @brief Construct with an initial value from an Arduino String.
* @param str An Arduino String containing to the initial value to set.
Expand Down Expand Up @@ -398,7 +403,7 @@ class NimBLEAttValue {
/** @brief Inequality operator */
bool operator!=(const NimBLEAttValue& source) const { return !(*this == source); }

# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
/** @brief Operator; Get the value as an Arduino String value. */
operator String() const { return String(reinterpret_cast<char*>(m_attr_value)); }
# endif
Expand Down
40 changes: 22 additions & 18 deletions src/NimBLEStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
# include <type_traits>
# include <cstdarg>

# ifndef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
# define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (__has_include(<Arduino.h>))
# endif

# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
# include <Stream.h>
# else
Expand Down Expand Up @@ -100,7 +104,7 @@ class NimBLEStream : public Stream {
*/
void setRxOverflowCallback(RxOverflowCallback cb, void* userArg = nullptr) {
m_rxOverflowCallback = cb;
m_rxOverflowUserArg = userArg;
m_rxOverflowUserArg = userArg;
}

operator bool() const { return ready(); }
Expand All @@ -118,17 +122,17 @@ class NimBLEStream : public Stream {
static void txDrainEventCb(struct ble_npl_event* ev);
static void txDrainCalloutCb(struct ble_npl_event* ev);

ByteRingBuffer* m_txBuf{nullptr};
ByteRingBuffer* m_rxBuf{nullptr};
uint8_t m_txChunkBuf[MYNEWT_VAL(BLE_ATT_PREFERRED_MTU)];
uint32_t m_txBufSize{1024};
uint32_t m_rxBufSize{1024};
ble_npl_event m_txDrainEvent{};
ble_npl_callout m_txDrainCallout{};
ByteRingBuffer* m_txBuf{nullptr};
ByteRingBuffer* m_rxBuf{nullptr};
uint8_t m_txChunkBuf[MYNEWT_VAL(BLE_ATT_PREFERRED_MTU)];
uint32_t m_txBufSize{1024};
uint32_t m_rxBufSize{1024};
ble_npl_event m_txDrainEvent{};
ble_npl_callout m_txDrainCallout{};
RxOverflowCallback m_rxOverflowCallback{nullptr};
void* m_rxOverflowUserArg{nullptr};
bool m_coInitialized{false};
bool m_eventInitialized{false};
void* m_rxOverflowUserArg{nullptr};
bool m_coInitialized{false};
bool m_eventInitialized{false};
};

# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
Expand Down Expand Up @@ -203,13 +207,13 @@ class NimBLEStreamClient : public NimBLEStream {

// Attach a discovered remote characteristic; app owns discovery/connection.
// Set subscribeNotify=true to receive notifications into RX buffer.
bool begin(NimBLERemoteCharacteristic* pChr,
bool subscribeNotify = false,
uint32_t txBufSize = 1024,
uint32_t rxBufSize = 1024);
void end() override;
void setNotifyCallback(NimBLERemoteCharacteristic::notify_callback cb) { m_userNotifyCallback = cb; }
bool ready() const override;
bool begin(NimBLERemoteCharacteristic* pChr,
bool subscribeNotify = false,
uint32_t txBufSize = 1024,
uint32_t rxBufSize = 1024);
void end() override;
void setNotifyCallback(NimBLERemoteCharacteristic::notify_callback cb) { m_userNotifyCallback = cb; }
bool ready() const override;
virtual void flush() override;

using NimBLEStream::write; // Inherit template write overloads
Expand Down