Mbed OS Reference
|
Abstract away BLE-capable radio transceivers or SOCs. More...
#include <BLE.h>
Data Structures | |
struct | InitializationCompleteCallbackContext |
Initialization complete event. More... | |
struct | OnEventsToProcessCallbackContext |
Events to process event. More... | |
Public Types | |
typedef unsigned | InstanceID_t |
Opaque type used to store the ID of a BLE instance. More... | |
typedef FunctionPointerWithContext< OnEventsToProcessCallbackContext * > | OnEventsToProcessCallback_t |
Events to process event handler. More... | |
typedef void(* | InitializationCompleteCallback_t) (InitializationCompleteCallbackContext *context) |
Initialization complete event handler. More... | |
Public Member Functions | |
InstanceID_t | getInstanceID () const |
Fetch the ID of a BLE instance. More... | |
void | onEventsToProcess (const OnEventsToProcessCallback_t &on_event_cb) |
Register a callback called when the BLE stack has pending work. More... | |
void | processEvents () |
Process ALL pending events living in the BLE stack and return once all events have been consumed. More... | |
ble_error_t | init (InitializationCompleteCallback_t completion_cb=nullptr) |
Initialize the BLE controller/stack. More... | |
template<typename T > | |
ble_error_t | init (T *object, void(T::*completion_cb)(InitializationCompleteCallbackContext *context)) |
Initialize the BLE controller/stack. More... | |
bool | hasInitialized () const |
Indicate if the BLE instance has been initialized. More... | |
ble_error_t | shutdown () |
Shut down the underlying stack, and reset state of this BLE instance. More... | |
const char * | getVersion () |
This call allows the application to get the BLE stack version information. More... | |
ble::Gap & | gap () |
Accessor to Gap. More... | |
const ble::Gap & | gap () const |
A const alternative to gap(). More... | |
ble::GattServer & | gattServer () |
Accessor to GattServer. More... | |
const ble::GattServer & | gattServer () const |
A const alternative to gattServer(). More... | |
ble::GattClient & | gattClient () |
Accessors to GattClient. More... | |
const ble::GattClient & | gattClient () const |
A const alternative to gattClient(). More... | |
ble::SecurityManager & | securityManager () |
Accessors to SecurityManager. More... | |
const ble::SecurityManager & | securityManager () const |
A const alternative to securityManager(). More... | |
void | signalEventsToProcess () |
This function allows the BLE stack to signal that there is work to do and event processing should be done (BLE::processEvent()). More... | |
Static Public Member Functions | |
static BLE & | Instance () |
Get a reference to the BLE singleton. More... | |
static BLE & | Instance (InstanceID_t id) |
Get a reference to the BLE singleton corresponding to a given interface. More... | |
static const char * | errorToString (ble_error_t error) |
Translate error code into a printable string. More... | |
Static Public Attributes | |
static const InstanceID_t | DEFAULT_INSTANCE = 0 |
The value of the BLE::InstanceID_t for the default BLE instance. More... | |
static const InstanceID_t | NUM_INSTANCES = 1 |
The number of permitted BLE instances for the application. More... | |
Abstract away BLE-capable radio transceivers or SOCs.
Instances of this class have three responsibilities:
The user should not create BLE instances directly but rather access to the singleton(s) holding the BLE interfaces present in the system by using the static function Instance().
Next, the signal handling/process mechanism should be set up. By design, Mbed BLE does not impose to the user an event handling/processing mechanism; however, it exposes APIs, which allows an application to compose its own:
It is common to bind BLE event mechanism with Mbed EventQueue:
Once the event processing mechanism is in place, the Bluetooth subsystem can be initialized with the init() function. That function accepts in input a callback, which will be invoked once the initialization process has finished.
typedef unsigned InstanceID_t |
Opaque type used to store the ID of a BLE instance.
typedef void(* InitializationCompleteCallback_t) (InitializationCompleteCallbackContext *context) |
|
static |
Get a reference to the BLE singleton.
|
static |
Get a reference to the BLE singleton corresponding to a given interface.
There is a static array of BLE singletons.
[in] | id | BLE Instance ID to get. |
InstanceID_t getInstanceID | ( | ) | const |
void onEventsToProcess | ( | const OnEventsToProcessCallback_t & | on_event_cb | ) |
Register a callback called when the BLE stack has pending work.
By registering a callback, application code can know when event processing has to be scheduled.
on_event_cb | Callback invoked when there are new events to process. |
void processEvents | ( | ) |
Process ALL pending events living in the BLE stack and return once all events have been consumed.
ble_error_t init | ( | InitializationCompleteCallback_t | completion_cb = nullptr | ) |
Initialize the BLE controller/stack.
init() hands control to the underlying BLE module to accomplish initialization. This initialization may tacitly depend on other hardware setup (such as clocks or power-modes) that happens early on during system startup. It may not be safe to call init() from a global static context where ordering is compiler-specific and can't be guaranteed - it is safe to call BLE::init() from within main().
[in] | completion_cb | A callback for when initialization completes for a BLE instance. This is an optional parameter; if no callback is set up, the application can still determine the status of initialization using BLE::hasInitialized() (see below). |
ble_error_t init | ( | T * | object, |
void(T::*)(InitializationCompleteCallbackContext *context) | completion_cb | ||
) |
Initialize the BLE controller/stack.
This is an alternate declaration for init(). This one takes an <Object, member> pair as its callback target.
[in] | object | Object, which will be used to invoke the completion callback. |
[in] | completion_cb | Member function pointer, which will be invoked when initialization is complete. |
bool hasInitialized | ( | ) | const |
ble_error_t shutdown | ( | ) |
Shut down the underlying stack, and reset state of this BLE instance.
const char * getVersion | ( | ) |
ble::Gap & gap | ( | ) |
const ble::Gap & gap | ( | ) | const |
ble::GattServer & gattServer | ( | ) |
Accessor to GattServer.
All GattServer related functionality requires going through this accessor.
const ble::GattServer & gattServer | ( | ) | const |
A const alternative to gattServer().
ble::GattClient & gattClient | ( | ) |
Accessors to GattClient.
All GattClient related functionality requires going through this accessor.
const ble::GattClient & gattClient | ( | ) | const |
A const alternative to gattClient().
ble::SecurityManager & securityManager | ( | ) |
Accessors to SecurityManager.
All SecurityManager-related functionality requires going through this accessor.
const ble::SecurityManager & securityManager | ( | ) | const |
A const alternative to securityManager().
|
static |
Translate error code into a printable string.
[in] | error | Error code returned by BLE functions. |
void signalEventsToProcess | ( | ) |
This function allows the BLE stack to signal that there is work to do and event processing should be done (BLE::processEvent()).
|
static |
The value of the BLE::InstanceID_t for the default BLE instance.
|
static |
The number of permitted BLE instances for the application.