For Blood Pressure Demo

BLE_BloodPressure_demo implements Blood Pressure Service which enables a collector device to connect and interact with it. the service spec can be found here. User can download the APP 'nRF Connect' or 'nRF Toolbox' available in both App Store and Google Play to scan the adverting and connect to the module.

Committer:
tsungta
Date:
Thu Apr 20 10:25:42 2017 +0000
Revision:
2:64cead334a4c
Parent:
1:fc03791a9842
Update to support NQ620 and NNN50 platform

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Marcomissyou 0:546d7178e278 1 #include "mbed.h"
wgd8700 1:fc03791a9842 2 #include "BLE.h"
Marcomissyou 0:546d7178e278 3 #include "DeviceInformationService.h"
Marcomissyou 0:546d7178e278 4 #include "BloodPressureService.h"
Marcomissyou 0:546d7178e278 5
Marcomissyou 0:546d7178e278 6 BLEDevice ble;
Marcomissyou 0:546d7178e278 7 DigitalOut led01(LED1);
Marcomissyou 0:546d7178e278 8
Marcomissyou 0:546d7178e278 9 const static char DEVICE_NAME[] = "Blood Pressure";
Marcomissyou 0:546d7178e278 10 static const uint16_t uuid16_list[] = {GattService::UUID_BLOOD_PRESSURE_SERVICE,
Marcomissyou 0:546d7178e278 11 GattService::UUID_DEVICE_INFORMATION_SERVICE};
Marcomissyou 0:546d7178e278 12 static volatile bool triggerSensorPolling = false;
Marcomissyou 0:546d7178e278 13
tsungta 2:64cead334a4c 14 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
Marcomissyou 0:546d7178e278 15 {
Marcomissyou 0:546d7178e278 16 ble.startAdvertising(); // restart advertising
Marcomissyou 0:546d7178e278 17 }
Marcomissyou 0:546d7178e278 18
Marcomissyou 0:546d7178e278 19 void periodicCallback(void)
Marcomissyou 0:546d7178e278 20 {
Marcomissyou 0:546d7178e278 21 led01 = !led01; /* Do blinky on LED1 while we're waiting for BLE events */
Marcomissyou 0:546d7178e278 22
Marcomissyou 0:546d7178e278 23 /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
Marcomissyou 0:546d7178e278 24 * heavy-weight sensor polling from the main thread. */
Marcomissyou 0:546d7178e278 25 triggerSensorPolling = true;
Marcomissyou 0:546d7178e278 26 }
Marcomissyou 0:546d7178e278 27
Marcomissyou 0:546d7178e278 28 int main(void)
Marcomissyou 0:546d7178e278 29 {
Marcomissyou 0:546d7178e278 30 led01 = 1;
Marcomissyou 0:546d7178e278 31 Ticker ticker;
Marcomissyou 0:546d7178e278 32 ticker.attach(periodicCallback, 1); // blink LED every second
Marcomissyou 0:546d7178e278 33
Marcomissyou 0:546d7178e278 34 ble.init();
tsungta 2:64cead334a4c 35 ble.gap().onDisconnection(disconnectionCallback);
Marcomissyou 0:546d7178e278 36
Marcomissyou 0:546d7178e278 37 /* Setup primary service. */
Marcomissyou 0:546d7178e278 38 float SystolicValue = 100.0f; // mmHg
Marcomissyou 0:546d7178e278 39 float DiastolicValue = 70.0f; //
Marcomissyou 0:546d7178e278 40 float MeanArterialValue = 55.0f; //
Marcomissyou 0:546d7178e278 41
Marcomissyou 0:546d7178e278 42 BloodPressureService BloPressureService(ble, SystolicValue, DiastolicValue, MeanArterialValue, 0);
Marcomissyou 0:546d7178e278 43
Marcomissyou 0:546d7178e278 44 /* Setup auxiliary service. */
Marcomissyou 0:546d7178e278 45 DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
Marcomissyou 0:546d7178e278 46
Marcomissyou 0:546d7178e278 47 /* Setup advertising. */
Marcomissyou 0:546d7178e278 48 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
Marcomissyou 0:546d7178e278 49 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
Marcomissyou 0:546d7178e278 50 ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_BLOOD_PRESSURE);
Marcomissyou 0:546d7178e278 51 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
Marcomissyou 0:546d7178e278 52 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Marcomissyou 0:546d7178e278 53 ble.setAdvertisingInterval(1000);
Marcomissyou 0:546d7178e278 54 ble.startAdvertising();
Marcomissyou 0:546d7178e278 55
Marcomissyou 0:546d7178e278 56 while (1) {
Marcomissyou 0:546d7178e278 57 // check for trigger from periodicCallback()
Marcomissyou 0:546d7178e278 58 if (triggerSensorPolling && ble.getGapState().connected) {
Marcomissyou 0:546d7178e278 59 triggerSensorPolling = false;
Marcomissyou 0:546d7178e278 60
Marcomissyou 0:546d7178e278 61 // Do blocking calls or whatever is necessary for sensor polling.
Marcomissyou 0:546d7178e278 62 // In our case, we simply update the HRM measurement.
Marcomissyou 0:546d7178e278 63 SystolicValue++;
Marcomissyou 0:546d7178e278 64 DiastolicValue++;
Marcomissyou 0:546d7178e278 65 MeanArterialValue++;
Marcomissyou 0:546d7178e278 66
Marcomissyou 0:546d7178e278 67 if (SystolicValue == 140.0f) {
Marcomissyou 0:546d7178e278 68 SystolicValue = 90.0f;
Marcomissyou 0:546d7178e278 69 }
Marcomissyou 0:546d7178e278 70 if (DiastolicValue == 90.0f) {
Marcomissyou 0:546d7178e278 71 DiastolicValue = 50.0f;
Marcomissyou 0:546d7178e278 72 }
Marcomissyou 0:546d7178e278 73 if (MeanArterialValue == 105.0f) {
Marcomissyou 0:546d7178e278 74 MeanArterialValue = 70.0f;
Marcomissyou 0:546d7178e278 75 }
Marcomissyou 0:546d7178e278 76 // update Blood Pressure
Marcomissyou 0:546d7178e278 77 BloPressureService.updateBloodPressureMeasurement(SystolicValue, DiastolicValue, MeanArterialValue);
Marcomissyou 0:546d7178e278 78 } else {
Marcomissyou 0:546d7178e278 79 ble.waitForEvent(); // low power wait for event
Marcomissyou 0:546d7178e278 80 }
Marcomissyou 0:546d7178e278 81 }
Marcomissyou 0:546d7178e278 82 }