Error 230
Dependencies: BLE_API mbed nRF51822
Fork of BLE_HeartRate by
Diff: main.cpp
- Revision:
- 39:d0a7eb186652
- Parent:
- 37:d310a72115c7
- Child:
- 40:626757c0bb3b
--- a/main.cpp Fri Jul 25 17:23:34 2014 +0100 +++ b/main.cpp Fri Aug 08 13:44:31 2014 +0000 @@ -17,6 +17,7 @@ #include "mbed.h" #include "BLEDevice.h" #include "ble_hrs.h" +#include "ble_hts.h" BLEDevice ble; DigitalOut led1(LED1); @@ -31,24 +32,40 @@ #define DEBUG(...) /* nothing */ #endif /* #if NEED_CONSOLE_OUTPUT */ -const static char DEVICE_NAME[] = "Nordic_HRM"; +const static char DEVICE_NAME[] = "Rob's Tool"; /* Heart Rate Service */ /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.heart_rate.xml */ /* HRM Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml */ /* Location: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.body_sensor_location.xml */ -static uint8_t hrmCounter = 100; -static uint8_t bpm[2] = {0x00, hrmCounter}; -GattCharacteristic hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, bpm, sizeof(bpm), sizeof(bpm), - GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); + +/* Temperature Service */ +/* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.health_thermometer.xml */ +/* Temp Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml */ +/* Location: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_type.xml */ + +/* Heart Rate */ +static uint8_t bpm[2] = {0x00, 80}; +GattCharacteristic hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, bpm, sizeof(bpm), sizeof(bpm), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); + static uint8_t location = BLE_HRS_BODY_SENSOR_LOCATION_FINGER; -GattCharacteristic hrmLocation(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, - (uint8_t *)&location, sizeof(location), sizeof(location), - GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); +GattCharacteristic hrmLocation(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, (uint8_t *)&location, sizeof(location), sizeof(location), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); + GattCharacteristic *hrmChars[] = {&hrmRate, &hrmLocation, }; -GattService hrmService(GattService::UUID_HEART_RATE_SERVICE, hrmChars, sizeof(hrmChars) / sizeof(GattCharacteristic *)); +GattService hrmService(GattService::UUID_HEART_RATE_SERVICE, hrmChars, sizeof(hrmChars) / sizeof(GattCharacteristic *)); + +/* Temperature */ +static uint8_t temp[5] = {0, 0, 0, 0, 0}; +GattCharacteristic recTemp(GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, temp, sizeof(temp), sizeof(temp), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); -static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; +static uint8_t type = BLE_HTS_TEMP_TYPE_RECTUM; +GattCharacteristic recType(GattCharacteristic::UUID_TEMPERATURE_TYPE_CHAR, (uint8_t *)&type, sizeof(type), sizeof(type), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); + +GattCharacteristic *recChars[] = {&recTemp, &recType, }; +GattService recService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, recChars, sizeof(recChars) / sizeof(GattCharacteristic *)); + +/* List */ +static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, GattService::UUID_HEALTH_THERMOMETER_SERVICE}; static volatile bool triggerSensorPolling = false; /* set to high periodically to indicate to the main thread that * polling is necessary. */ @@ -83,6 +100,14 @@ * thread.*/ } +uint32_t quick_ieee11073_from_float(float temperature) +{ + uint8_t exponent = 0xFF; //exponent is -1 + uint32_t mantissa = (uint32_t)(temperature*10); + + return ( ((uint32_t)exponent) << 24) | mantissa; +} + int main(void) { led1 = 1; @@ -102,28 +127,30 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::HEART_RATE_SENSOR_HEART_RATE_BELT); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ + ble.setAdvertisingInterval(80); /* 100ms; in multiples of 0.625ms. */ ble.startAdvertising(); ble.addService(hrmService); + ble.addService(recService); while (true) { if (triggerSensorPolling) { triggerSensorPolling = false; /* Do blocking calls or whatever is necessary for sensor polling. */ - /* In our case, we simply update the dummy HRM measurement. */ - hrmCounter++; - if (hrmCounter == 175) { - hrmCounter = 100; - } - + /* In our case, we simply update the dummy HRM measurement. */ if (ble.getGapState().connected) { /* First byte = 8-bit values, no extra info, Second byte = uint8_t HRM value */ /* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml */ - bpm[1] = hrmCounter; + bpm[1] = rand() % 40 + 60; ble.updateCharacteristicValue(hrmRate.getHandle(), bpm, sizeof(bpm)); - } + + float f = 12.5f;//(float)(((float)bpm[1]) / 10.0f);//(rand() % 20 + 360) / 10.0f; + uint8_t tem = quick_ieee11073_from_float(f); + memcpy(temp+1, &tem, 4); + // temp[1] = f; + ble.updateCharacteristicValue(recTemp.getHandle(), temp, sizeof(temp)); + } } else { ble.waitForEvent(); }