13#define ESP_LOGD(...) ((void)0)
14#define ESP_LOGE(...) ((void)0)
15#define ESP_LOGI(...) ((void)0)
26 [[no_unique_address]] Impl
impl;
32 ESP_LOGD(
"CS-BLEMIDI",
"conn=%d, char=%d", con.conn,
34 if (chr.characteristic == 0xFFFF)
36 impl.notify(con, chr, data);
43 ESP_LOGD(
"CS-BLEMIDI",
"conn=%d", conn_handle.
conn);
44 this->connection.store(conn_handle);
48 ESP_LOGD(
"CS-BLEMIDI",
"conn=%d", conn_handle.conn);
49 this->connection.store({});
50 this->characteristic.store({});
53 uint16_t mtu)
override {
54 ESP_LOGD(
"CS-BLEMIDI",
"conn=%d, mtu=%d", conn_handle.conn, mtu);
59 bool notify)
override {
60 ESP_LOGD(
"CS-BLEMIDI",
"conn=%d, char=%d, notify=%d", conn_handle.
conn,
63 this->connection.store(conn_handle);
64 this->characteristic.store(char_handle);
66 this->characteristic.store({});
71 ESP_LOGD(
"CS-BLEMIDI",
"conn=%d", conn_handle.conn);
76 ESP_LOGE(
"CS-BLEMIDI",
"BLE packet dropped, size=%d",
82 ESP_LOGE(
"CS-BLEMIDI",
"BLE chunk dropped, size=%d",
86 ESP_LOGI(
"CS-BLEMIDI",
"added chunk, size=%d", cont.length);
99 std::atomic_uint_fast16_t
value;
101 return value.load(std::memory_order_acquire);
104 value.fetch_add(t, std::memory_order_release);
107 value.fetch_sub(t, std::memory_order_release);
116 return parser.popMessage(incomingMessage);
121 impl.init(*
this, ble_settings);
127 FATAL_ERROR(F(
"ESP32BLEBackend::end not implemented"), 0x3278);
130 return connection.load(std::memory_order_relaxed).conn != 0xFFFF;
Type definitions and callback interfaces for communication between the low-level BLE stacks and highe...
@ Continuation
Buffer contains a chunk of a BLE packet.
BLEDataLifetime
Should a buffer of BLEData be consumed immediately inside of the callback, or can we hold on to it an...
#define BEGIN_CS_NAMESPACE
Callable that returns the next chunk of data from a BLE packet when called.
FIFO buffer that you can push BLE packets into, and pop MIDI messages out of.
ESP32 backend intended to be plugged into GenericBLEMIDI_Interface.
std::atomic< BLECharacteristicHandle > characteristic
void handleData(BLEConnectionHandle conn_handle, BLEDataGenerator &&data, BLEDataLifetime) override
Called by the BLE stack when the central writes data to the MIDI GATT characteristic.
void handleConnect(BLEConnectionHandle conn_handle) override
Called by the BLE stack when a connection is established.
void handleDisconnect(BLEConnectionHandle conn_handle) override
Called by the BLE stack when a connection is terminated.
void sendData(BLEDataView data)
BufferedBLEMIDIParser< 4096, AtomicSize > parser
Contains incoming BLE MIDI data to be parsed.
void begin(BLESettings ble_settings)
void handleMTU(BLEConnectionHandle conn_handle, uint16_t mtu) override
Called by the BLE stack when the maximum transmission unit for the connection changes.
std::atomic< BLEConnectionHandle > connection
bool popMessage(IncomingMIDIMessage &incomingMessage)
void handleSubscribe(BLEConnectionHandle conn_handle, BLECharacteristicHandle char_handle, bool notify) override
Called by the BLE stack when the central subscribes to receive notifications for the MIDI GATT charac...
Defines the interface for callback functions registered by the low-level BLE code.
Class that manages a background thread that sends BLE packets asynchronously.
BLEMIDIPacketBuilder packet
View of the data to send.
uint16_t getMinMTU() const
Get the minimum MTU of all connected clients.
void setTimeout(std::chrono::milliseconds timeout)
Set the timeout, the number of milliseconds to buffer the outgoing MIDI messages.
void forceMinMTU(uint16_t mtu)
Force the MTU to an artificially small value (used for testing).
ProtectedBuilder acquirePacket()
Acquire exclusive access to the buffer to be sent by the timer.
void begin()
Start the background thread.
void releasePacketAndNotify(ProtectedBuilder &lck)
Release exclusive access to the buffer and notify the sender thread that data is available.
void updateMTU(uint16_t mtu)
Set the maximum transmission unit of the Bluetooth link.
void sendNow(ProtectedBuilder &lck)
Sends the data immediately without waiting for the timeout.
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
MIDI message variant type (with timestamp).
Represents a handle to a local GATT characteristic.
Represents a handle to the connection to another device.
Non-owning, std::span-style read-only view of BLE data.
Configuration options for the low-level BLE code.
void add_release(uint_fast16_t t)
void sub_release(uint_fast16_t t)
std::atomic_uint_fast16_t value
uint_fast16_t load_acquire() const
static constexpr size_t alignment
AtomicSize(uint_fast16_t value)