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 (void) 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=NULL) |
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 (void) const |
Indicate if the BLE instance has been initialized. More... | |
ble_error_t | shutdown (void) |
Shut down the underlying stack, and reset state of this BLE instance. More... | |
const char * | getVersion (void) |
This call allows the application to get the BLE stack version information. More... | |
Gap & | gap () |
Accessor to Gap. More... | |
const Gap & | gap () const |
A const alternative to gap(). More... | |
GattServer & | gattServer () |
Accessor to GattServer. More... | |
const GattServer & | gattServer () const |
A const alternative to gattServer(). More... | |
GattClient & | gattClient () |
Accessors to GattClient. More... | |
const GattClient & | gattClient () const |
A const alternative to gattClient(). More... | |
SecurityManager & | securityManager () |
Accessors to SecurityManager. More... | |
const SecurityManager & | securityManager () const |
A const alternative to securityManager(). More... | |
Static Public Member Functions | |
static BLE & | Instance (InstanceID_t id=DEFAULT_INSTANCE) |
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 void(* InitializationCompleteCallback_t) (InitializationCompleteCallbackContext *context) |
typedef unsigned InstanceID_t |
|
static |
Translate error code into a printable string.
[in] | error | Error code returned by BLE functions. |
Gap& gap | ( | ) |
Accessor to Gap.
All Gap-related functionality requires going through this accessor.
const Gap& gap | ( | ) | const |
GattClient& gattClient | ( | ) |
Accessors to GattClient.
All GattClient related functionality requires going through this accessor.
const GattClient& gattClient | ( | ) | const |
A const alternative to gattClient().
GattServer& gattServer | ( | ) |
Accessor to GattServer.
All GattServer related functionality requires going through this accessor.
const GattServer& gattServer | ( | ) | const |
A const alternative to gattServer().
InstanceID_t getInstanceID | ( | void | ) | const |
const char* getVersion | ( | void | ) |
bool hasInitialized | ( | void | ) | const |
ble_error_t init | ( | InitializationCompleteCallback_t | completion_cb = NULL | ) |
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. |
|
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. |
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.
SecurityManager& securityManager | ( | ) |
Accessors to SecurityManager.
All SecurityManager-related functionality requires going through this accessor.
const SecurityManager& securityManager | ( | ) | const |
A const alternative to securityManager().
ble_error_t shutdown | ( | void | ) |
Shut down the underlying stack, and reset state of this BLE instance.
|
static |
The value of the BLE::InstanceID_t for the default BLE instance.
|
static |