Error 230

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

Revision:
40:626757c0bb3b
Parent:
39:d0a7eb186652
--- a/main.cpp	Fri Aug 08 13:44:31 2014 +0000
+++ b/main.cpp	Fri Aug 08 16:10:15 2014 +0000
@@ -44,19 +44,30 @@
 /* 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);
+/* Heart Rate 1 */
+static uint8_t bpm1[2] = {0x00, 80};
+GattCharacteristic hrmRate1(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, bpm1, sizeof(bpm1), sizeof(bpm1), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
+
+static uint8_t location1 = BLE_HRS_BODY_SENSOR_LOCATION_EAR_LOBE;
+GattCharacteristic hrmLocation1(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, (uint8_t *)&location1, sizeof(location1), sizeof(location1), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
+                               
+GattCharacteristic *hrmChars1[] = {&hrmRate1, &hrmLocation1, };
+GattService hrmService1(GattService::UUID_HEART_RATE_SERVICE, hrmChars1, sizeof(hrmChars1) / sizeof(GattCharacteristic *));
 
-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);
+/* Heart Rate 2 */
+static uint8_t bpm2[2] = {0x00, 80};
+GattCharacteristic hrmRate2(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, bpm2, sizeof(bpm2), sizeof(bpm2), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
+
+static uint8_t location2 = BLE_HRS_BODY_SENSOR_LOCATION_HAND;
+GattCharacteristic hrmLocation2(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, (uint8_t *)&location2, sizeof(location2), sizeof(location2), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
                                
-GattCharacteristic *hrmChars[] = {&hrmRate, &hrmLocation, };
-GattService hrmService(GattService::UUID_HEART_RATE_SERVICE, hrmChars, sizeof(hrmChars) / sizeof(GattCharacteristic *));
+GattCharacteristic *hrmChars2[] = {&hrmRate2, &hrmLocation2, };
+GattService hrmService2(GattService::UUID_HEART_RATE_SERVICE, hrmChars2, sizeof(hrmChars2) / 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);
+GattCharacteristic recTemp(GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, temp, sizeof(temp), sizeof(temp), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE);
 
 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);
@@ -65,7 +76,7 @@
 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 const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, 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. */
@@ -130,7 +141,8 @@
     ble.setAdvertisingInterval(80); /* 100ms; in multiples of 0.625ms. */
     ble.startAdvertising();
 
-    ble.addService(hrmService);
+    ble.addService(hrmService1);
+    ble.addService(hrmService2);
     ble.addService(recService);
 
     while (true) {
@@ -142,13 +154,15 @@
             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] = 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);
+                bpm1[1] = rand() % 40 + 60;
+                ble.updateCharacteristicValue(hrmRate1.getHandle(), bpm1, sizeof(bpm1));
+
+                bpm2[1] = rand() % 40 + 60;
+                ble.updateCharacteristicValue(hrmRate2.getHandle(), bpm2, sizeof(bpm2));
+                                
+                float f = (rand() % 20 + 360) / 10.0f;
+                uint32_t tem = quick_ieee11073_from_float(f);
                 memcpy(temp+1, &tem, 4);
-               // temp[1] = f;
                 ble.updateCharacteristicValue(recTemp.getHandle(), temp, sizeof(temp));
             }           
         } else {