
hr with 30102
Dependencies: BLE_API mbed X_NUCLEO_IDB0XA1
Fork of BLE_HeartRate by
Revision 42:06ebef2e0e44, committed 2014-09-22
- Comitter:
- rgrover1
- Date:
- Mon Sep 22 10:38:25 2014 +0000
- Parent:
- 41:9cef0129da5f
- Child:
- 43:dbb025ed4a55
- Commit message:
- updating to 0.2.0 of the BLE_API
Changed in this revision
--- a/BLE_API.lib Tue Sep 02 16:17:18 2014 +0000 +++ b/BLE_API.lib Mon Sep 22 10:38:25 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#ca826083980e +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#620d28e7a1ba
--- a/HeartRateService.h Tue Sep 02 16:17:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2013 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __BLE_HEART_RATE_SERVICE_H__ -#define __BLE_HEART_RATE_SERVICE_H__ - -#include "BLEDevice.h" - -/* 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 */ -class HeartRateService { -public: - enum { - LOCATION_OTHER = 0, - LOCATION_CHEST, - LOCATION_WRIST, - LOCATION_FINGER, - LOCATION_HAND, - LOCATION_EAR_LOBE, - LOCATION_FOOT, - }; - -public: - HeartRateService(BLEDevice &_ble, uint8_t _hrmCounter, uint8_t _location) : - ble(_ble), - bpm(_hrmCounter), - hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, bpm.getPointer(), HeartRateValueBytes::SIZEOF_ARRAY, HeartRateValueBytes::SIZEOF_ARRAY, - GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), - hrmLocation(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, (uint8_t *)&_location, sizeof(_location), sizeof(_location), - GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) { - - static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */ - if (serviceAdded) { - return; - } - - GattCharacteristic *hrmChars[] = {&hrmRate, &hrmLocation, }; - GattService hrmService(GattService::UUID_HEART_RATE_SERVICE, hrmChars, sizeof(hrmChars) / sizeof(GattCharacteristic *)); - - ble.addService(hrmService); - serviceAdded = true; - } - - void updateHeartRate(uint8_t hrmCounter) { - if (ble.getGapState().connected) { - bpm.updateHeartRate(hrmCounter); - ble.updateCharacteristicValue(hrmRate.getValueAttribute().getHandle(), bpm.getPointer(), HeartRateValueBytes::SIZEOF_ARRAY); - } - } - -private: - /* Private internal representation for the bytes used to work with the vaulue of the heart-rate characteristic. */ - struct HeartRateValueBytes { - static const unsigned SIZEOF_ARRAY = 2; - - HeartRateValueBytes(uint8_t hrmCounter) : beatsPerMinute() { - updateHeartRate(hrmCounter); - } - - void updateHeartRate(uint8_t hrmCounter) { - beatsPerMinute[1] = hrmCounter; - } - - uint8_t *getPointer(void) { - return beatsPerMinute; - } - - const uint8_t *getPointer(void) const { - return beatsPerMinute; - } - - private: - /* 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 */ - uint8_t beatsPerMinute[SIZEOF_ARRAY]; - }; - -private: - BLEDevice &ble; - HeartRateValueBytes bpm; - GattCharacteristic hrmRate; - GattCharacteristic hrmLocation; -}; - -#endif /* #ifndef __BLE_HEART_RATE_SERVICE_H__*/
--- a/main.cpp Tue Sep 02 16:17:18 2014 +0000 +++ b/main.cpp Mon Sep 22 10:38:25 2014 +0000 @@ -17,6 +17,9 @@ #include "mbed.h" #include "BLEDevice.h" #include "HeartRateService.h" +#include "BatteryService.h" +#include "DeviceInformationService.h" +// #include "DFUService.h" BLEDevice ble; DigitalOut led1(LED1); @@ -32,7 +35,9 @@ #endif /* #if NEED_CONSOLE_OUTPUT */ const static char DEVICE_NAME[] = "Nordic_HRM"; -static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; +static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, + GattService::UUID_BATTERY_SERVICE, + GattService::UUID_DEVICE_INFORMATION_SERVICE}; static volatile bool triggerSensorPolling = false; void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) @@ -64,7 +69,7 @@ /* setup advertising */ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); - ble.accumulateAdvertisingPayload(GapAdvertisingData::HEART_RATE_SENSOR_HEART_RATE_BELT); + ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(1600); /* 1000ms; in multiples of 0.625ms. */ @@ -73,6 +78,10 @@ uint8_t hrmCounter = 100; HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); + BatteryService battery(ble); + DeviceInformationService deviceInfo(ble, "ARM"); + // DFUService dfu(ble); + while (true) { if (triggerSensorPolling) { triggerSensorPolling = false;
--- a/mbed-src.lib Tue Sep 02 16:17:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-src/#1f0269907d8b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 22 10:38:25 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
--- a/nRF51822.lib Tue Sep 02 16:17:18 2014 +0000 +++ b/nRF51822.lib Mon Sep 22 10:38:25 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#e861f2041469 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#b3680699d9a4