BLE demo for the Health-Thermometer service.
Dependencies: BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1
This example demonstrates how to use the Health Thermometer Service. The Health Thermometer service reports two pieces of information, Temperature and Sensor Location.
API
Import library
Public Types |
|
enum |
SensorLocation_t
{
LOCATION_ARMPIT = 1, LOCATION_BODY , LOCATION_EAR , LOCATION_FINGER , LOCATION_GI_TRACT , LOCATION_MOUTH , LOCATION_RECTUM , LOCATION_TOE , LOCATION_EAR_DRUM } |
Public Member Functions |
|
HealthThermometerService ( BLE &_ble, float initialTemp, uint8_t _location) | |
Add the Health Thermometer Service to an existing
BLE
object, initialize with temperature and location.
|
|
void | updateTemperature (float temperature) |
Update the temperature being broadcast.
|
|
void | updateLocation ( SensorLocation_t loc) |
Update the location.
|
Technical Details
Further Technical Details can be found at the following links
- Temperature Service : Gatt profile details from bluetooth.org
- Temperature Measurement : Gatt Characteristic details
- Temperature Type : Gatt Characteristic details
Revision 3:8733f3e50c84, committed 2014-09-04
- Comitter:
- rgrover1
- Date:
- Thu Sep 04 07:14:25 2014 +0000
- Parent:
- 2:a34d554282b0
- Child:
- 4:83c07b0e93d6
- Commit message:
- use ieee11073_from_float to encode temperature correctly.
Changed in this revision
HealthThermometerService.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/HealthThermometerService.h Wed Sep 03 16:25:50 2014 +0000 +++ b/HealthThermometerService.h Thu Sep 04 07:14:25 2014 +0000 @@ -89,7 +89,8 @@ } void updateTemperature(float temp) { - memcpy(&bytes[OFFSET_OF_VALUE], &temp, sizeof(float)); + uint32_t temp_ieee11073 = quick_ieee11073_from_float(temp); + memcpy(&bytes[OFFSET_OF_VALUE], &temp_ieee11073, sizeof(float)); } uint8_t *getPointer(void) { @@ -101,6 +102,19 @@ } private: + /** + * @brief A very quick conversion between a float temperature and 11073-20601 FLOAT-Type. + * @param temperature The temperature as a float. + * @return The temperature in 11073-20601 FLOAT-Type format. + */ + uint32_t quick_ieee11073_from_float(float temperature) { + uint8_t exponent = 0xFE; //exponent is -2 + uint32_t mantissa = (uint32_t)(temperature * 100); + + return (((uint32_t)exponent) << 24) | mantissa; + } + + private: /* First byte = 8-bit flags, Second field is a float holding the temperature value. */ /* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml */ uint8_t bytes[SIZEOF_VALUE_BYTES];