17 #ifndef __BLE_HEALTH_THERMOMETER_SERVICE_H__ 18 #define __BLE_HEALTH_THERMOMETER_SERVICE_H__ 22 #if BLE_FEATURE_GATT_SERVER 57 valueBytes(initialTemp),
64 ble.gattServer().addService(hrmService);
75 valueBytes.updateTemperature(temperature);
76 ble.gattServer().write(tempMeasurement.
getValueHandle(), valueBytes.getPointer(),
sizeof(TemperatureValueBytes));
85 ble.gattServer().write(tempLocation.
getValueHandle(),
reinterpret_cast<uint8_t *
>(&loc),
sizeof(uint8_t));
90 struct TemperatureValueBytes {
91 static const unsigned OFFSET_OF_FLAGS = 0;
92 static const unsigned OFFSET_OF_VALUE = OFFSET_OF_FLAGS +
sizeof(uint8_t);
93 static const unsigned SIZEOF_VALUE_BYTES =
sizeof(uint8_t) +
sizeof(
float);
95 static const unsigned TEMPERATURE_UNITS_FLAG_POS = 0;
96 static const unsigned TIMESTAMP_FLAG_POS = 1;
97 static const unsigned TEMPERATURE_TYPE_FLAG_POS = 2;
99 static const uint8_t TEMPERATURE_UNITS_CELSIUS = 0;
100 static const uint8_t TEMPERATURE_UNITS_FAHRENHEIT = 1;
102 TemperatureValueBytes(
float initialTemperature) : bytes() {
104 bytes[OFFSET_OF_FLAGS] = (TEMPERATURE_UNITS_CELSIUS << TEMPERATURE_UNITS_FLAG_POS) |
105 (
false << TIMESTAMP_FLAG_POS) |
106 (
false << TEMPERATURE_TYPE_FLAG_POS);
111 uint32_t temp_ieee11073 = quick_ieee11073_from_float(temp);
112 memcpy(&bytes[OFFSET_OF_VALUE], &temp_ieee11073,
sizeof(
float));
115 uint8_t *getPointer(
void) {
119 const uint8_t *getPointer(
void)
const {
129 uint32_t quick_ieee11073_from_float(
float temperature) {
130 uint8_t exponent = 0xFE;
131 uint32_t mantissa = (uint32_t)(temperature * 100);
133 return (((uint32_t)exponent) << 24) | mantissa;
139 uint8_t bytes[SIZEOF_VALUE_BYTES];
144 TemperatureValueBytes valueBytes;
149 #endif // BLE_FEATURE_GATT_SERVER void updateTemperature(float temperature)
Update the temperature being broadcast.
Abstract away BLE-capable radio transceivers or SOCs.
SensorLocation_t
Location of sensor on the body.
BLE Health Thermometer Service.
UUID of the health thermometer.
Representation of a GattServer characteristic.
GattAttribute::Handle_t getValueHandle(void) const
Get the characteristic's value attribute handle in the ATT table.
void updateLocation(SensorLocation_t loc)
Update the location.
Representation of a GattServer service.
Entry namespace for all BLE API definitions.
HealthThermometerService(BLE &_ble, float initialTemp, uint8_t _location)
Add the Health Thermometer Service to an existing BLE object, initialize with temperature and locatio...