20#warning "These services are deprecated and will be removed. Please see services.md for details about replacement services."
22#ifndef MBED_BLE_HEART_RATE_SERVICE_H__
23#define MBED_BLE_HEART_RATE_SERVICE_H__
27#include "ble/GattServer.h"
29#if BLE_FEATURE_GATT_SERVER
125 valueBytes(hrmCounter),
128 valueBytes.getPointer(),
129 valueBytes.getNumValueBytes(),
135 reinterpret_cast<uint8_t*>(&location)
155 valueBytes.updateHeartRate(hrmCounter);
156 ble.gattServer().write(
158 valueBytes.getPointer(),
159 valueBytes.getNumValueBytes()
175 sizeof(charTable) /
sizeof(charTable[0])
178 ble.gattServer().addService(hrmService);
187 static const unsigned MAX_VALUE_BYTES = 3;
188 static const unsigned FLAGS_BYTE_INDEX = 0;
190 static const unsigned VALUE_FORMAT_BITNUM = 0;
191 static const uint8_t VALUE_FORMAT_FLAG = (1 << VALUE_FORMAT_BITNUM);
195 updateHeartRate(hrmCounter);
198 void updateHeartRate(uint16_t hrmCounter)
200 if (hrmCounter <= 255) {
201 valueBytes[FLAGS_BYTE_INDEX] &= ~VALUE_FORMAT_FLAG;
202 valueBytes[FLAGS_BYTE_INDEX + 1] = hrmCounter;
204 valueBytes[FLAGS_BYTE_INDEX] |= VALUE_FORMAT_FLAG;
205 valueBytes[FLAGS_BYTE_INDEX + 1] = (uint8_t)(hrmCounter & 0xFF);
206 valueBytes[FLAGS_BYTE_INDEX + 2] = (uint8_t)(hrmCounter >> 8);
210 uint8_t *getPointer()
215 const uint8_t *getPointer()
const
220 unsigned getNumValueBytes()
const
222 if (valueBytes[FLAGS_BYTE_INDEX] & VALUE_FORMAT_FLAG) {
223 return 1 +
sizeof(uint16_t);
225 return 1 +
sizeof(uint8_t);
230 uint8_t valueBytes[MAX_VALUE_BYTES];
Representation of a GattServer characteristic.
GattAttribute::Handle_t getValueHandle() const
Get the characteristic's value attribute handle in the ATT table.
Representation of a GattServer service.
@ UUID_HEART_RATE_SERVICE
UUID of the Heart Rate service.
HeartRateService(BLE &_ble, uint16_t hrmCounter, BodySensorLocation location)
Construct and initialize a heart rate service.
BodySensorLocation
Intended location of the heart rate sensor.
@ LOCATION_EAR_LOBE
Earlobe.
@ LOCATION_OTHER
Other location.
void updateHeartRate(uint16_t hrmCounter)
Update the heart rate that the service exposes.
void setupService()
Construct and add to the GattServer the heart rate service.
Helper class that represents a read only GattCharacteristic.
Abstract away BLE-capable radio transceivers or SOCs.
Entry namespace for all BLE API definitions.