Eddystone test using modified DAL

Dependencies:   BLE_API mbed-dev-bin nRF51822

Dependents:   microbit-eddystone

Fork of microbit-dal by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

MicroBitBLEManager Class Reference

Class definition for the MicroBitBLEManager. More...

#include <MicroBitBLEManager.h>

Inherits MicroBitComponent.

Public Member Functions

 MicroBitBLEManager (MicroBitStorage &_storage)
 Constructor.
 MicroBitBLEManager ()
 Constructor.
void init (ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding)
 Post constructor initialisation method as the BLE stack cannot be brought up in a static context.
int setTransmitPower (int power)
 Change the output power level of the transmitter to the given value.
void pairingMode (MicroBitDisplay &display, MicroBitButton &authorisationButton)
 Enter pairing mode.
void advertise ()
 When called, the micro:bit will begin advertising for a predefined period, MICROBIT_BLE_ADVERTISING_TIMEOUT seconds to bonded devices.
int getBondCount ()
 Determines the number of devices currently bonded with this micro:bit.
void pairingRequested (ManagedString passKey)
 A request to pair has been received from a BLE device.
void pairingComplete (bool success)
 A pairing request has been sucessfully completed.
void idleTick ()
 Periodic callback in thread context.
void stopAdvertising ()
 Stops any currently running BLE advertisements.
int advertiseEddystoneUrl (const char *url, int8_t calibratedPower=MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER, bool connectable=true, uint16_t interval=MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL)
 Set the content of Eddystone URL frames.
int advertiseEddystoneUrl (ManagedString url, int8_t calibratedPower=MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER, bool connectable=true, uint16_t interval=MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL)
 Set the content of Eddystone URL frames, but accepts a ManagedString as a url.
int advertiseEddystoneUid (const char *uid_namespace, const char *uid_instance, int8_t calibratedPower=MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER, bool connectable=true, uint16_t interval=MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL)
 Set the content of Eddystone UID frames.

Static Public Member Functions

static MicroBitBLEManagergetInstance ()
 getInstance

Private Member Functions

virtual void systemTick ()
 The system timer will call this member function once the component has been added to the array of system components using system_timer_add_component.

Detailed Description

Class definition for the MicroBitBLEManager.

Definition at line 93 of file MicroBitBLEManager.h.


Constructor & Destructor Documentation

Constructor.

Configure and manage the micro:bit's Bluetooth Low Energy (BLE) stack.

Parameters:
_storagean instance of MicroBitStorage used to persist sys attribute information. (This is required for compatability with iOS).
Note:
The BLE stack *cannot* be brought up in a static context (the software simply hangs or corrupts itself). Hence, the init() member function should be used to initialise the BLE stack.

Definition at line 226 of file MicroBitBLEManager.cpp.

Constructor.

Configure and manage the micro:bit's Bluetooth Low Energy (BLE) stack.

Note:
The BLE stack *cannot* be brought up in a static context (the software simply hangs or corrupts itself). Hence, the init() member function should be used to initialise the BLE stack.

Definition at line 241 of file MicroBitBLEManager.cpp.


Member Function Documentation

void advertise (  )

When called, the micro:bit will begin advertising for a predefined period, MICROBIT_BLE_ADVERTISING_TIMEOUT seconds to bonded devices.

Definition at line 265 of file MicroBitBLEManager.cpp.

int advertiseEddystoneUid ( const char *  uid_namespace,
const char *  uid_instance,
int8_t  calibratedPower = MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER,
bool  connectable = true,
uint16_t  interval = MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL 
)

Set the content of Eddystone UID frames.

Parameters:
uid_namespace,:the uid namespace. Must 10 bytes long.
uid_instance,:the uid instance value. Must 6 bytes long.
calibratedPowerthe transmission range of the beacon (Defaults to: 0xF0 ~10m).
connectabletrue to keep bluetooth connectable for other services, false otherwise. (Defaults to true)
intervalthe rate at which the micro:bit will advertise url frames. (Defaults to MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL)
Note:
The calibratedPower value ranges from -100 to +20 to a resolution of 1. The calibrated power should be binary encoded. More information can be found at https://github.com/google/eddystone/tree/master/eddystone-uid#tx-power

Definition at line 585 of file MicroBitBLEManager.cpp.

int advertiseEddystoneUrl ( const char *  url,
int8_t  calibratedPower = MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER,
bool  connectable = true,
uint16_t  interval = MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL 
)

Set the content of Eddystone URL frames.

Parameters:
urlThe url to broadcast
calibratedPowerthe transmission range of the beacon (Defaults to: 0xF0 ~10m).
connectabletrue to keep bluetooth connectable for other services, false otherwise. (Defaults to true)
intervalthe rate at which the micro:bit will advertise url frames. (Defaults to MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL)
Note:
The calibratedPower value ranges from -100 to +20 to a resolution of 1. The calibrated power should be binary encoded. More information can be found at https://github.com/google/eddystone/tree/master/eddystone-uid#tx-power

Definition at line 528 of file MicroBitBLEManager.cpp.

int advertiseEddystoneUrl ( ManagedString  url,
int8_t  calibratedPower = MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER,
bool  connectable = true,
uint16_t  interval = MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL 
)

Set the content of Eddystone URL frames, but accepts a ManagedString as a url.

Parameters:
urlThe url to broadcast
calibratedPowerthe transmission range of the beacon (Defaults to: 0xF0 ~10m).
connectabletrue to keep bluetooth connectable for other services, false otherwise. (Defaults to true)
intervalthe rate at which the micro:bit will advertise url frames. (Defaults to MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL)
Note:
The calibratedPower value ranges from -100 to +20 to a resolution of 1. The calibrated power should be binary encoded. More information can be found at https://github.com/google/eddystone/tree/master/eddystone-uid#tx-power

Definition at line 562 of file MicroBitBLEManager.cpp.

int getBondCount (  )

Determines the number of devices currently bonded with this micro:bit.

Returns:
The number of active bonds.

Definition at line 446 of file MicroBitBLEManager.cpp.

MicroBitBLEManager * getInstance (  ) [static]

getInstance

When called, the micro:bit will begin advertising for a predefined period, MICROBIT_BLE_ADVERTISING_TIMEOUT seconds to bonded devices.

Allows other objects to easily obtain a pointer to the single instance of this object. By rights the constructor should be made private to properly implement the singleton pattern.

Definition at line 252 of file MicroBitBLEManager.cpp.

void idleTick (  ) [virtual]

Periodic callback in thread context.

We use this here purely to safely issue a disconnect operation after a pairing operation is complete.

Reimplemented from MicroBitComponent.

Definition at line 494 of file MicroBitBLEManager.cpp.

void init ( ManagedString  deviceName,
ManagedString  serialNumber,
EventModel messageBus,
bool  enableBonding 
)

Post constructor initialisation method as the BLE stack cannot be brought up in a static context.

Parameters:
deviceNameThe name used when advertising
serialNumberThe serial number exposed by the device information service
messageBusAn instance of an EventModel, used during pairing.
enableBondingIf true, the security manager enabled bonding.
 bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true);

Definition at line 284 of file MicroBitBLEManager.cpp.

void pairingComplete ( bool  success )

A pairing request has been sucessfully completed.

If we're in pairing mode, display a success or failure message.

Note:
for internal use only.

Definition at line 477 of file MicroBitBLEManager.cpp.

void pairingMode ( MicroBitDisplay display,
MicroBitButton authorisationButton 
)

Enter pairing mode.

This is mode is called to initiate pairing, and to enable FOTA programming of the micro:bit in cases where BLE is disabled during normal operation.

Parameters:
displayAn instance of MicroBitDisplay used when displaying pairing information.
authorizationButtonThe button to use to authorise a pairing request.
 // initiate pairing mode
 bleManager.pairingMode(uBit.display, uBit.buttonA);

Definition at line 618 of file MicroBitBLEManager.cpp.

void pairingRequested ( ManagedString  passKey )

A request to pair has been received from a BLE device.

If we're in pairing mode, display the passkey to the user. Also, purge the bonding table if it has reached capacity.

Note:
for internal use only.

Definition at line 464 of file MicroBitBLEManager.cpp.

int setTransmitPower ( int  power )

Change the output power level of the transmitter to the given value.

Parameters:
powera value in the range 0..7, where 0 is the lowest power and 7 is the highest.
Returns:
MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range.
 // maximum transmission power.
 bleManager.setTransmitPower(7);

Definition at line 431 of file MicroBitBLEManager.cpp.

void stopAdvertising (  )

Stops any currently running BLE advertisements.

Definition at line 508 of file MicroBitBLEManager.cpp.