BLE Heart Rate Service. More...
#include <HeartRateService.h>
Data Structures | |
struct | HeartRateValueBytes |
Public Types |
Public Member Functions | |
HeartRateService (BLE &_ble, uint16_t hrmCounter, BodySensorLocation location) | |
Construct and initialize a heart rate service. More... | |
void | updateHeartRate (uint16_t hrmCounter) |
Update the heart rate that the service exposes. More... | |
Protected Member Functions | |
void | setupService (void) |
Construct and add to the GattServer the heart rate service. More... | |
BLE Heart Rate Service.
Fitness applications use the heart rate service to expose the heart beat per minute measured by a heart rate sensor.
Clients can read the intended location of the sensor and the last heart rate value measured. Additionally, clients can subscribe to server initiated updates of the heart rate value measured by the sensor. The service delivers these updates to the subscribed client in a notification packet.
The subscription mechanism is useful to save power; it avoids unecessary data traffic between the client and the server, which may be induced by polling the value of the heart rate measurement characteristic.
When this class is instantiated, it adds a heart rate service in the GattServer. The service contains the location of the sensor and the initial value measured by the sensor.
Application code can invoke updateHeartRate() when a new heart rate measurement is acquired; this function updates the value of the heart rate measurement characteristic and notifies the new value to subscribed clients.
Definition at line 60 of file HeartRateService.h.
enum BodySensorLocation |
Intended location of the heart rate sensor.
Enumerator | |
---|---|
LOCATION_OTHER |
Other location. |
LOCATION_CHEST |
Chest. |
LOCATION_WRIST |
Wrist. |
LOCATION_FINGER |
Finger. |
LOCATION_HAND |
Hand. |
LOCATION_EAR_LOBE |
Earlobe. |
LOCATION_FOOT |
Foot. |
Definition at line 65 of file HeartRateService.h.
HeartRateService | ( | BLE & | _ble, |
uint16_t | hrmCounter, | ||
BodySensorLocation | location | ||
) |
Construct and initialize a heart rate service.
The construction process adds a GATT heart rate service in _ble
GattServer, sets the value of the heart rate measurement characteristic to hrmCounter
and the value of the body sensor location characteristic to location
.
[in] | _ble | BLE device that hosts the heart rate service. |
[in] | hrmCounter | Heart beats per minute measured by the heart rate sensor. |
[in] | location | Intended location of the heart rate sensor. |
Definition at line 116 of file HeartRateService.h.
|
protected |
Construct and add to the GattServer the heart rate service.
Definition at line 160 of file HeartRateService.h.
void updateHeartRate | ( | uint16_t | hrmCounter | ) |
Update the heart rate that the service exposes.
The server sends a notification of the new value to clients that have subscribed to updates of the heart rate measurement characteristic; clients reading the heart rate measurement characteristic after the update obtain the updated value.
[in] | hrmCounter | Heart rate measured in BPM. |
Definition at line 147 of file HeartRateService.h.