arduino-audio-tools
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
AudioBLEServer Class Reference

A simple BLE server that implements the serial protocol, so that it can be used to send and recevie audio. In BLE terminologiy this is a Peripheral. This implementation uses the ArduinoBLE library! This is working only correctly if the client sets the max MTU to a value >= 256. Otherwise some of the transmitted information gets silently dropped. More...

#include <AudioBLEServer.h>

Inheritance diagram for AudioBLEServer:
AudioBLEStream AudioBLEStream AudioStream AudioStream BaseStream AudioInfoSupport AudioInfoSource BaseStream AudioInfoSupport AudioInfoSource Stream Stream Print Print

Public Member Functions

 AudioBLEServer (int mtu=0)
 
 AudioBLEServer (int mtu=517)
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
 
int available () override
 
int available () override
 
int availableForWrite () override
 
int availableForWrite () override
 
virtual bool begin ()
 
bool begin (const char *name)
 
bool begin (const char *name)
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
bool connected () override
 
bool connected () override
 
void end () override
 
void end () override
 
virtual void flush () override
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
 operator bool ()
 
size_t readBytes (uint8_t *data, size_t len) override
 
size_t readBytes (uint8_t *data, size_t len) override
 
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
void setAudioInfo (AudioInfo info)
 Defines the input AudioInfo.
 
void setAudioInfoActive (bool flag)
 
void setAudioInfoUUID (const char *uuid)
 
void setFramed (bool flag)
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setRxUUID (const char *uuid)
 
void setServiceUUID (const char *uuid)
 
void setTxUUID (const char *uuid)
 
AudioInfo toInfo (const uint8_t *str)
 
StrView toStr (AudioInfo info)
 
size_t write (const uint8_t *data, size_t dataSize) override
 
size_t write (const uint8_t *data, size_t len) override
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

bool checkCentralConnected ()
 
int getMTU () override
 
int getMTU () override
 
size_t getReadSize (size_t dataSize)
 
size_t getReadSize (size_t dataSize)
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void onConnect (BLEDevice device)
 
void onConnect (BLEServer *pServer) override
 
void onDisconnect (BLEDevice device)
 
void onDisconnect (BLEServer *pServer) override
 
void onRead (BLECharacteristic *pCharacteristic) override
 provide the next batch of audio data
 
void onRead (BLECharacteristic characteristic)
 provide the next batch of audio data
 
void onWrite (BLECharacteristic *pCharacteristic) override
 store the next batch of data
 
void onWrite (BLECharacteristic characteristic)
 store the next batch of data
 
virtual void receiveAudio (const uint8_t *data, size_t size)
 
virtual void receiveAudio (const uint8_t *data, size_t size)
 
void refillReadBuffer ()
 
virtual void setAudioInfo (const uint8_t *data, size_t size)
 
void setupBLEService ()
 
void setupBLEService ()
 
void setupRXBuffer ()
 
void setupRXBuffer ()
 
void setupTXBuffer ()
 
void setupTXBuffer ()
 
void writeAudioInfoCharacteristic (AudioInfo info)
 
void writeAudioInfoCharacteristic (AudioInfo info)
 

Static Protected Member Functions

static void bleOnRead (BLEDevice device, BLECharacteristic characteristic)
 
static void bleOnWrite (BLEDevice device, BLECharacteristic characteristic)
 
static void blePeripheralConnectHandler (BLEDevice device)
 
static void blePeripheralDisconnectHandler (BLEDevice device)
 

Protected Attributes

int _timeout = 10
 
char audio_info_str [40]
 
const char * BLE_AUDIO_SERVICE_UUID = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"
 
const char * BLE_CH1_UUID = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
 
const char * BLE_CH2_UUID = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
 
const char * BLE_INFO_UUID = "6e400004-b5a3-f393-e0a9-e50e24dcca9e"
 
const char * ble_server_name = nullptr
 
BLEDevice central
 
BLECharacteristic ch01_char {BLE_CH1_UUID, BLERead, getMTU()}
 
BLECharacteristic * ch01_char
 
BLEDescriptor ch01_desc {"2901", "channel 1"}
 
BLECharacteristic ch02_char {BLE_CH2_UUID, BLEWrite, getMTU()}
 
BLECharacteristic * ch02_char
 
BLEDescriptor ch02_desc {"2901", "channel 2"}
 
AudioInfo info
 
BLECharacteristic info_char
 
BLECharacteristic * info_char
 
BLEDescriptor info_desc {"2901", "info"}
 
bool is_audio_info_active = false
 
bool is_framed = false
 
bool is_notify_active = true
 
bool is_started = false
 
uint16_t max_transfer_size = 0
 
Vector< AudioInfoSupport * > notify_vector
 
BLEAdvertising * p_advertising = nullptr
 
BLEServer * p_server = nullptr
 
BLEService * p_service = nullptr
 
RingBuffer< uint8_t > receive_buffer {0}
 
RingBuffer< uint16_t > receive_sizes {0}
 
BLEService service {BLE_AUDIO_SERVICE_UUID}
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
RingBuffer< uint8_t > transmit_buffer {0}
 
RingBuffer< uint16_t > transmit_buffer_sizes {0}
 

Detailed Description

A simple BLE server that implements the serial protocol, so that it can be used to send and recevie audio. In BLE terminologiy this is a Peripheral. This implementation uses the ArduinoBLE library! This is working only correctly if the client sets the max MTU to a value >= 256. Otherwise some of the transmitted information gets silently dropped.

A simple BLE server that implements the serial protocol, so that it can be used to send and recevie audio. In BLE terminologiy this is a Peripheral.

Author
Phil Schatzmann

Member Data Documentation

◆ info_char

BLECharacteristic info_char
protected
Initial value:
{BLE_INFO_UUID, BLERead | BLEWrite | BLENotify,
80}

The documentation for this class was generated from the following files: