phyphox BLE
Plot your Arduino's data in the phyphox app and control the board from the phone
Loading...
Searching...
No Matches
Esp32CoreBleTransport.h
Go to the documentation of this file.
1// Transport for the BLE library of arduino-esp32 3.x (BLEDevice / BLEServer /
2// BLECharacteristic; 4.x replaced it, see Esp32Ble4Transport.h), which sits on Bluedroid on
3// the classic ESP32 and on NimBLE on the S3/C3/C6/H2/P4 variants. One transport, two
4// `#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)` branches at the callback layer, because the
5// two stacks deliver subscriptions differently (Bluedroid: a write to the CCCD descriptor;
6// NimBLE: BLECharacteristicCallbacks::onSubscribe) — the 1.x fix in commit 42bad88. Never
7// pins a task to a core (1.x commit ca630b9, single-core C3).
8//
9// notify() returns void in this library on both stacks; a send refused up front arrives as
10// BLECharacteristicCallbacks::onStatus(ERROR_GATT, rc) from inside notify(), which this
11// transport turns into a synchronous false. On Bluedroid a packet can still be dropped later,
12// in the stack's own task, so for the experiment characteristic the transport also waits for
13// the stack's confirmation event (see the .cpp). Those are the signals the transfer's retry
14// hangs off (plan §3.4). Build with -DPHYPHOX_BLE_ESP32_TRACE to see refused confirmations on
15// Serial. poll() is a no-op: the stack runs in its own tasks.
16#ifndef PHYPHOX_BLE_TRANSPORT_ESP32COREBLE_H
17#define PHYPHOX_BLE_TRANSPORT_ESP32COREBLE_H
18
19#include "Transport.h"
20
21namespace phyphox {
22
24public:
25 bool begin(const GattLayout& layout, TransportListener& listener) override;
26 bool notify(CharId id, const uint8_t* data, uint16_t len) override;
27 void setValue(CharId id, const uint8_t* data, uint16_t len) override;
28 bool connected() const override;
29 uint16_t mtuPayload() const override;
30 void requestMtu(uint16_t payload) override;
31 void requestConnectionParameters(uint16_t, uint16_t, uint16_t, uint16_t) override;
32 void poll() override {}
33 bool drivesTransfer() const override { return true; }
34 void restartAdvertising() override;
35 const char* name() const override { return "ESP32"; }
37private:
39 // Services are created with an explicit handle count (2 per characteristic + 1 per CCCD),
40 // never the library's default of 15 — plan §3.3.
41};
42
43} // namespace phyphox
44
45#endif
Definition Esp32CoreBleTransport.h:23
void requestConnectionParameters(uint16_t, uint16_t, uint16_t, uint16_t) override
Ask the central for connection parameters (units of 1.25 ms / 10 ms).
bool begin(const GattLayout &layout, TransportListener &listener) override
Create services and characteristics, start advertising the experiment service.
const char * name() const override
"ArduinoBLE", "ESP32", "NINA-B31" — for printXML/debug
Definition Esp32CoreBleTransport.h:35
bool drivesTransfer() const override
True if the transport calls listener.pump() from a task of its own, so the core must not also pump fr...
Definition Esp32CoreBleTransport.h:33
void setValue(CharId id, const uint8_t *data, uint16_t len) override
Set a characteristic's value without notifying (initial values, the legacy config).
bool notify(CharId id, const uint8_t *data, uint16_t len) override
Send a notification.
void restartAdvertising() override
uint16_t mtuPayload() const override
The negotiated MTU payload (ATT_MTU − 3), or PHYPHOX_BLE_DEFAULT_MTU.
bool connected() const override
void requestMtu(uint16_t payload) override
Ask the stack for an MTU before connecting (ESP32 only today; others ignore).
void poll() override
Give the stack CPU time.
Definition Esp32CoreBleTransport.h:32
static Esp32CoreBleTransport & instance()
Callbacks from the transport into the core (implemented by Server).
Definition Transport.h:40
Definition Transport.h:59
Definition ChannelStore.h:11
Definition Transport.h:23
What the core asks the transport to create at begin().
Definition Transport.h:29