Roy Want / Mbed OS beaconCompileReadyFork
Embed: (wiki syntax)

« Back to documentation index

EddystoneService Class Reference

This class implements the Eddystone-URL Config Service and the Eddystone Protocol Specification as defined in the publicly available specification at https://github.com/google/eddystone/blob/master/protocol-specification.md. More...

#include <EddystoneService.h>

Data Structures

struct  EddystoneParams_t
 Structure that encapsulates the Eddystone configuration parameters. More...

Public Types

enum  OperationModes { EDDYSTONE_MODE_NONE, EDDYSTONE_MODE_CONFIG, EDDYSTONE_MODE_BEACON }
 

Enumeration that defines the various operation modes of the EddystoneService.

More...
enum  EddystoneError_t { EDDYSTONE_ERROR_NONE, EDDYSTONE_ERROR_INVALID_ADVERTISING_INTERVAL, EDDYSTONE_ERROR_INVALID_STATE }
 

Enumeration that defines the various error codes for EddystoneService.

More...
enum  FrameType {
  EDDYSTONE_FRAME_UID, EDDYSTONE_FRAME_URL, EDDYSTONE_FRAME_TLM, EDDYSTONE_FRAME_EID,
  NUM_EDDYSTONE_FRAMES
}
 

Enumeration that defines the available frame types within Eddystone advertising packets.

More...

Public Member Functions

 EddystoneService (BLE &bleIn, EddystoneParams_t &paramsIn, const PowerLevels_t &radioPowerLevelsIn, event_queue_t &eventQueue, uint32_t advConfigIntervalIn=DEFAULT_CONFIG_PERIOD_MSEC)
 Constructor that Initializes the EddystoneService using parameters from the supplied EddystoneParams_t.
 EddystoneService (BLE &bleIn, const PowerLevels_t &advPowerLevelsIn, const PowerLevels_t &radioPowerLevelsIn, event_queue_t &eventQueue, uint32_t advConfigIntervalIn=DEFAULT_CONFIG_PERIOD_MSEC)
 Constructor to initialize the EddystoneService to default values.
void genEIDBeaconKeys (void)
 Generate the EID Beacon Random ECHD Keys (private and Public)
void doFactoryReset (void)
 Factory Reset all parameters in the beacon.
void onTLMBatteryVoltageUpdate (TlmUpdateCallback_t tlmBatteryVoltageCallbackIn)
 Setup callback to update BatteryVoltage in Eddystone-TLM frames.
void onTLMBeaconTemperatureUpdate (TlmUpdateCallback_t tlmBeaconTemperatureCallbackIn)
 Setup callback to update BeaconTemperature in Eddystone-TLM frames.
EddystoneError_t startConfigService (void)
 Change the EddystoneService OperationMode to EDDYSTONE_MODE_CONFIG.
EddystoneError_t startEddystoneBeaconAdvertisements (void)
 Change the EddystoneService to start transmitting Eddystone beacons operationMode = EDDYSTONE_MODE_BEACON.
ble_error_t setCompleteDeviceName (const char *deviceNameIn)
 Set the Comple Local Name for the BLE device.
void getEddystoneParams (EddystoneParams_t &params)
 Get the Eddystone Configuration parameters.
EddystoneService::EddystoneError_t startEddystoneConfigAdvertisements (void)
 Start advertising packets indicating the Eddystone Configuration state operationMode = EDDYSTONE_MODE_CONFIG.
void stopEddystoneBeaconAdvertisements (void)
 Free the resources acquired by a call to setupBeaconService() and cancel all pending callbacks that operate the radio and frame queue.
void startEddystoneConfigService ()
 Initialize and start the BLE Eddystone Configuration Service This will create the 12-characteristics of the service and make them available when a client connects.
void stopEddystoneConfigService ()
 Stops the Eddystone Configuration Service and frees its resources and cancels all pending callbacks that operate the radio and frame queue.

Static Public Member Functions

static void logPrintHex (uint8_t *a, int len)
 Print an array as a set of hex values.
static void swapEndianArray (uint8_t *ptrIn, uint8_t *ptrOut, int size)
 Swaps the endianess of an array ptrIn[size] to ptrOut[size].
static void generateRandom (uint8_t *ain, int size)
 Generate a random array of bytes of length size.

Static Public Attributes

static const uint16_t TOTAL_CHARACTERISTICS = 12
 Total number of GATT Characteristics in the Eddystonei-URL Configuration Service.
static const uint8_t MAX_DATA_WRITE = 34
 Max data that can be written to the data characteristic.
static const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = EDDYSTONE_DEFAULT_CONFIG_ADV_INTERVAL
 Default interval for advertising packets for the Eddystone-URL Configuration Service.
static Timer timeSinceBootTimer
 Timer that keeps track of the time since boot.

Detailed Description

This class implements the Eddystone-URL Config Service and the Eddystone Protocol Specification as defined in the publicly available specification at https://github.com/google/eddystone/blob/master/protocol-specification.md.

Definition at line 50 of file EddystoneService.h.


Member Enumeration Documentation

Enumeration that defines the various error codes for EddystoneService.

Enumerator:
EDDYSTONE_ERROR_NONE 

No error occurred.

EDDYSTONE_ERROR_INVALID_ADVERTISING_INTERVAL 

The supplied advertising interval is invalid.

The interval may be too short/long for the type of advertising packets being broadcast.

Note:
For the acceptable range of advertising interval refer to the following functions in mbed BLE API:
  • Gap::getMinNonConnectableAdvertisingInterval()
  • Gap::getMinAdvertisingInterval()
  • Gap::getMaxAdvertisingInterval()
EDDYSTONE_ERROR_INVALID_STATE 

The result of executing a call when the the EddystoneService is in the incorrect operation mode.

Definition at line 218 of file EddystoneService.h.

enum FrameType

Enumeration that defines the available frame types within Eddystone advertising packets.

Enumerator:
EDDYSTONE_FRAME_UID 

The Eddystone-UID frame.

Refer to https://github.com/google/eddystone/tree/master/eddystone-uid.

EDDYSTONE_FRAME_URL 

The Eddystone-URL frame.

Refer to https://github.com/google/eddystone/tree/master/eddystone-url.

EDDYSTONE_FRAME_TLM 

The Eddystone-TLM frame.

Refer to https://github.com/google/eddystone/tree/master/eddystone-tlm.

EDDYSTONE_FRAME_EID 

The Eddystone-EID frame.

Refer to https://github.com/google/eddystone/tree/master/eddystone-eid.

NUM_EDDYSTONE_FRAMES 

The total number Eddystone frame types.

Definition at line 245 of file EddystoneService.h.

Enumeration that defines the various operation modes of the EddystoneService.

Note:
The main app can change the mode of EddystoneService at any point of time by calling startConfigService() or startBeaconService(). Resources from the previous mode will be freed.
It is currently NOT possible to force EddystoneService back into EDDYSTONE_MODE_NONE.
Enumerator:
EDDYSTONE_MODE_NONE 

NONE: EddystoneService has been initialized but no memory has been dynamically allocated.

Additionally, no services are running nothing is being advertised.

EDDYSTONE_MODE_CONFIG 

CONFIG: EddystoneService has been initialized, the configuration service started and memory has been allocated for BLE characteristics.

Memory consumption peaks during CONFIG mode.

EDDYSTONE_MODE_BEACON 

BEACON: Eddystone service is running as a beacon advertising URL, UID and/or TLM frames depending on how it is configured.

Definition at line 81 of file EddystoneService.h.


Constructor & Destructor Documentation

EddystoneService ( BLE &  bleIn,
EddystoneParams_t paramsIn,
const PowerLevels_t &  radioPowerLevelsIn,
event_queue_t &  eventQueue,
uint32_t  advConfigIntervalIn = DEFAULT_CONFIG_PERIOD_MSEC 
)

Constructor that Initializes the EddystoneService using parameters from the supplied EddystoneParams_t.

This constructor is particularly useful for configuring the EddystoneService with parameters fetched from persistent storage.

Parameters:
[in]bleInThe BLE instance.
[in]paramInThe input Eddystone configuration parameters.
[in]radioPowerLevelsInThe value set internally into the radion tx power.
[in]eventQueueThe event queue used by the service to schedule tasks.
[in]advConfigIntervalInThe advertising interval for advertising packets of the Eddystone-URL Configuration Service.

Definition at line 80 of file EddystoneService.cpp.

EddystoneService ( BLE &  bleIn,
const PowerLevels_t &  advPowerLevelsIn,
const PowerLevels_t &  radioPowerLevelsIn,
event_queue_t &  eventQueue,
uint32_t  advConfigIntervalIn = DEFAULT_CONFIG_PERIOD_MSEC 
)

Constructor to initialize the EddystoneService to default values.

Parameters:
[in]bleInThe BLE instance.
[in]advPowerLevelsInThe value of the Eddystone-URL Configuration Service TX Power Mode characteristic.
[in]radioPowerLevelsInThe value set internally into the radion tx power.
[in]eventQueueThe event queue used by the service to schedule tasks.
[in]advConfigIntervalInThe advertising interval for advertising packets of the Eddystone-URL Configuration Service.
Note:
When using this constructor the setURLData(), setTMLData() and setUIDData() and setEIDData() functions must be called to initialize EddystoneService manually.

Definition at line 31 of file EddystoneService.cpp.


Member Function Documentation

void doFactoryReset ( void   )

Factory Reset all parameters in the beacon.

Factory reset all parmeters: used at initial boot, and activated from Char 11.

Definition at line 167 of file EddystoneService.cpp.

void genEIDBeaconKeys ( void   )

Generate the EID Beacon Random ECHD Keys (private and Public)

Definition at line 154 of file EddystoneService.cpp.

static void generateRandom ( uint8_t *  ain,
int  size 
) [static]

Generate a random array of bytes of length size.

Parameters:
[in]*ainThe input/output array
[in]sizeThe size of the array in bytes
void getEddystoneParams ( EddystoneParams_t params )

Get the Eddystone Configuration parameters.

This is particularly useful for storing the configuration parameters in persistent storage. It is not the responsibility of the Eddystone implementation to store the configured parameters in persistent storage since this is platform-specific.

Parameters:
[out]paramsA reference to an EddystoneParams_t structure with the configured parameters of the EddystoneService.

Definition at line 324 of file EddystoneService.cpp.

void logPrintHex ( uint8_t *  a,
int  len 
) [static]

Print an array as a set of hex values.

Parameters:
[in]aThe array to be printed.
[in]lenThe length of the array.
Returns:
void

Definition at line 1206 of file EddystoneService.cpp.

void onTLMBatteryVoltageUpdate ( TlmUpdateCallback_t  tlmBatteryVoltageCallbackIn )

Setup callback to update BatteryVoltage in Eddystone-TLM frames.

Parameters:
[in]tlmBatteryVoltageCallbackInThe callback being registered.

Definition at line 241 of file EddystoneService.cpp.

void onTLMBeaconTemperatureUpdate ( TlmUpdateCallback_t  tlmBeaconTemperatureCallbackIn )

Setup callback to update BeaconTemperature in Eddystone-TLM frames.

Parameters:
[in]tlmBeaconTemperatureCallbackInThe callback being registered.

Definition at line 247 of file EddystoneService.cpp.

ble_error_t setCompleteDeviceName ( const char *  deviceNameIn )

Set the Comple Local Name for the BLE device.

This not only updates the value of the Device Name Characteristic, it also updates the scan response payload if the EddystoneService is currently in EDDYSTONE_MODE_CONFIG.

Parameters:
[in]deviceNameInA pointer to a null terminated string containing the new device name.
Returns:
BLE_ERROR_NONE if the name was successfully set. Otherwise an appropriate error.
Note:
EddystoneService does not make an internal copy of the string pointed to by deviceNameIn. Therefore, the user is responsible for ensuring that the string persists in memory as long as it is in use by the EddystoneService.
The device name is not considered an Eddystone configuration parameter; therefore, it is not contained within the EddystoneParams_t structure and must be stored to persistent storage separately.

Definition at line 303 of file EddystoneService.cpp.

EddystoneError_t startConfigService ( void   )

Change the EddystoneService OperationMode to EDDYSTONE_MODE_CONFIG.

Return values:
EDDYSTONE_ERROR_NONEif the operation succeeded.
EDDYSONE_ERROR_INVALID_ADVERTISING_INTERVALif the configured advertising interval is zero.
Note:
If EddystoneService was previously in EDDYSTONE_MODE_BEACON, then the resources allocated to that mode of operation such as memory are freed and the BLE instance shutdown before the new operation mode is configured.
EddystoneService::EddystoneError_t startEddystoneBeaconAdvertisements ( void   )

Change the EddystoneService to start transmitting Eddystone beacons operationMode = EDDYSTONE_MODE_BEACON.

Return values:
EDDYSTONE_ERROR_NONEif the operation succeeded.
EDDYSONE_ERROR_INVALID_ADVERTISING_INTERVALif the configured advertising interval is zero.
Note:
If EddystoneService was previously in EDDYSTONE_MODE_CONFIG, then the resources allocated to that mode of operation such as memory are freed and the BLE instance shutdown before the new operation mode is configured.

Definition at line 252 of file EddystoneService.cpp.

EddystoneService::EddystoneError_t startEddystoneConfigAdvertisements ( void   )

Start advertising packets indicating the Eddystone Configuration state operationMode = EDDYSTONE_MODE_CONFIG.

Definition at line 628 of file EddystoneService.cpp.

void startEddystoneConfigService ( void   )

Initialize and start the BLE Eddystone Configuration Service This will create the 12-characteristics of the service and make them available when a client connects.

Definition at line 466 of file EddystoneService.cpp.

void stopEddystoneBeaconAdvertisements ( void   )

Free the resources acquired by a call to setupBeaconService() and cancel all pending callbacks that operate the radio and frame queue.

Note:
This call will not modify the current state of the BLE device. EddystoneService::stopBeaconService should only be called after a call to BLE::shutdown().

Definition at line 558 of file EddystoneService.cpp.

void stopEddystoneConfigService (  )

Stops the Eddystone Configuration Service and frees its resources and cancels all pending callbacks that operate the radio and frame queue.

Note:
This call will not modify the current state of the BLE device. EddystoneService::stopBeaconService should only be called after a call to BLE::shutdown().
static void swapEndianArray ( uint8_t *  ptrIn,
uint8_t *  ptrOut,
int  size 
) [static]

Swaps the endianess of an array ptrIn[size] to ptrOut[size].

Parameters:
[in]*ptrInThe input array
[in]*ptrOutThe output array
[in]sizeThe sizes of the arrays (num bytes to be reversed)

Field Documentation

const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = EDDYSTONE_DEFAULT_CONFIG_ADV_INTERVAL [static]

Default interval for advertising packets for the Eddystone-URL Configuration Service.

Definition at line 68 of file EddystoneService.h.

const uint8_t MAX_DATA_WRITE = 34 [static]

Max data that can be written to the data characteristic.

Definition at line 62 of file EddystoneService.h.

Timer timeSinceBootTimer [static]

Timer that keeps track of the time since boot.

Definition at line 491 of file EddystoneService.h.

const uint16_t TOTAL_CHARACTERISTICS = 12 [static]

Total number of GATT Characteristics in the Eddystonei-URL Configuration Service.

Definition at line 57 of file EddystoneService.h.