Tutorial Blood Pressure

Prerequisite

 

In this document, we use “com.vitalsigns.democardio” to demonstrate how to use the VitalSigns SDK to develop an android app that can measure blood pressure with VitalSigns Blood Pressure Wristband device step by step.

Typically, this app has following features.

  • BLE connection with VitalSigns Blood Pressure Wristband device
  • Calculate bio-signal, such as systolic blood pressure, diastolic blood pressure, and heart rate

The source code of the app can be downloaded from GitHub.

There are two things has to be noticed when you create a project.

  1. The “allowBackup” in the AndroidManifest.xml has to be set to “false”.
  2. The “Min Sdk Version” has to be larger than or equal to “API 18” due to the limitation of VitalSigns SDK library.

Add SDK Library

 

You have to register a free account on VitalSigns SDK Console before using the VitalSigns SDK.

Following shows the web after you login the VitalSigns SDK Console. The package list is empty because we have not register any app to use the VitalSigns SDK. Now, we are going to register a package by clicking the “+” button.

picture_vitalsigns_sdk_console_home

Following shows the web to add a package. In this tutorial, we register “com.vitalsigns.democardio”. Be aware that this package name has to be the same as the package name in the AndroidManifest.xml.

picture_register_package

The package name we entered in the previous step is shown in the registered package list as following showing. In the same row, there is an “Identity” code, which is needed when we uses the VitalSigns SDK to calculate blood pressure. In this tutorial, the identity code is “5d2b160c3d83f1134f9909be64f41a58”.

picture_package_registered

Next, we are going to download the VitalSigns SDK library and import it into our project. The VitalSigns SDK library is an aar file, which can be downloaded from the VitalSigns Developer. Extract the downloaded tarball, and you will get an aar file. In this tutorial, we are going to use the “VitalSigns_Sdk_V1.03.aar.tar.gz”.

picture_download_aar

Open your project in Android Studio and select “File > Project Structure …”, and you will see following dialog.

picture_add_the_sdk_library

Click the “+” button at the top-left corner, and you will see following dialog. Select the “Import JAR/AAR package” and click “Next”.

picture_import_aar_library

Select the unzipped file that we downloaded in previous step. In this tutorial, we set the name as “sdk” and click “Finish” in following dialog.

picture_select_aar_package

Click “OK” > “OK” in the next two dialogs, and you will back to your project. Wait for a while, and the “sdk” appears in the “Project” list.

picture_confirmation

Now we have added the VitalSigns SDK into our project, but we still can not use it because of dependency. We have to add dependency in “File > Project Structure … > app > Dependencies” as following dialog.

picture_add_the_dependencies

Click the “+” button at the bottom-left corner and select the “Module dependency”, and there will be a dialog as following. Select the “sdk” and click “OK”, and “OK” in next dialog.

picture_add_dependency_of_sdk

After that, the VitalSigns SDK has been added into the project successfully, and we can start to use it.


BLE Function

 

Now, we are going to implement the BLE connection of VitalSigns Blood Pressure Wristband device with the VitalSigns SDK.

In this tutorial, the app will list all scanned BLE devices at initial. When user select the device in the list, it will try to establish the BLE connection with the selected device. If the connection is established successfully, it will enter the main activity.

In order to use the BLE APIs provided in the SDK, we have to declare an object of “com.vitalsigns.sdk.ble.BleControl”, BleControl, in the GlobalData class. All the BLE APIs can be found in this object.

In the app, the BleControl is created in the initBle() function as following.

picture_initble

There are three arguments required when construct the BleControl, Context, BleEvent object, and target BLE device type.

The BleEvent is an interface provided by the SDK to handle the specified BLE states, and in this tutorial, we implement the BleEvent interface in MainActivity as following.

picture_bleevent

We implement four functions of BleEvent interface, onDisconnect, onConnect, onDataReceived, and onBleFirmwareUpdate.

onDisconnect is called when the BLE device is disconnected. In this tutorial, we scan and list the devices for user to select again.

onConnect is called when the BLE device connection is established. In the onConnect event, the device is still not available due to there is an initialization procedure has to be done in the SDK, and that is why we need a runnable to check the connection is established successfully or not by a runnable when user select the device.

onDataReceived is called when the host receives the data from VitalSigns Blood Pressure Wristband.

onBleFirmwareUpdate is called when the BLE OTP process is executed.

After the BleControl is constructed, we call Initialize() to initialize the BleControl object.

There three APIs of BLE in SDK has to be called at onResume, onPause, and onDestroy according to the app’s lifecycle.

picture_app_lifecycle

We create a DialogFragment, BleDeviceListDialog, to scan the BLE devices and list them in a list for user to select.

In this class, we define an interface, OnBleDeviceSelectedListener, which is implemented in MainActivity to get the mac address of selected BLE device.

picture_onbledeviceselectedlistener

The mac address of the callback function’s argument will be null if no device is selected, and it will re-start the BleDeviceListDialog to scan device again. If the mac address is assigned, it will be passed into Connect() of BleControl to establish the connection. After that, a runnable is posted after 7 seconds to check the connection is established successfully or not.


Blood Pressure

We create a class, VitalSignsDsp, to handle the DSP operation to calculate systolic blood pressure, diastolic blood pressure, and heart rate.

In this class, it controls the start/stop procedure of DSP, issues start/stop command to the BLE device, calls Execute() to process data from the BLE device and GetSbp(), GetDbp(), GetHeartRate() to read the bio-signals from the SDK, and stop the measurement automatically if the blood pressure measurement is stable.

picture_vitalsignsdsp

Now, we are going to explain some important parts of the VitalSignsDsp class.

In the constructor of the VitalSignsDsp class, it creates an object for bio-signal calculation, DSP and a callback function for updating result on the screen, OnUpdateResultCallback. It requires two information to create DSP, one is a storage space for NET file generated in the SDK, and the other one is identity code of the package, which is copied from the registered package list on VitalSigns SDK Console website.

picture_vitalsignsdsp_constructor

Start() starts the DSP for bio-signal calculation, and issues start command to the BLE device. It is very wise to check the DSP is available or not at the beginning of it, or the app will be crashed. Generally speaking, the DSP is unavailable if the authentication is failed.

picture_start

Start() creates three thread, DspThreadHandler, UpdateResultHandler, and BleTimeoutHandler.

  • DspThreadHandler is the main process to calculate the bio-signal. The data is poll from the queueBleData with the order of “ECG_0, PPG_0, ECG_1, PPG_1, … ECG_n, PPG_n”.

picture_dspthreadrunnable

  • UpdateResultHandler is used to update the systolic blood pressure, diastolic blood pressure, and heart rate to the screen every second. The first step is call DSP.UpdateView() to update the bio-signal result of the time region defined by fStartTime and fEndTime. The time region can be assigned arbitrarily within the last time tag, which can be get by calling DSP.GetEndTime(). DSP.BPStable() is used to get the blood pressure measurement is stable or not. The systolic blood pressure, diastolic blood pressure, and heart rate can be get by calling DSP.GetSbp(), DSP.GetDbp(), and DSP.GetHeartRate() respectively.

picture_updateresultrunnable

  • BleTimeoutHandler is used to check the BLE transmission is existed or not. If the BLE transmission is stopped unexpectedly, the whole measurement process has to be stopped.

startDsp() called in Start() is used to start the DSP for the measurement. There are three steps have to be done before starting the DSP.

  • SetUserInfo() sets the basic user information for the blood pressure calculation. It is important for the blood pressure calculation.
  • SetMeasInfo() sets the basic information of the measurement, such as time, ambient temperature, left or right hand, sit, stand, or lay-down position. It is also important for the blood pressure calculation.
  • SetInitValue() sets the initizal state of the DSP. Set these values properly shorten the time for blood pressure measurement stable. If you do not care about the time, -1 is a good choice.

There are two arguments have to be passed to the DSP.Start(), sample rate of the BLE device, and the device type. The sample rate can be get in the BleControl, and the device type is set to DEV_TYPE_BLE_WATCH for VitalSigns Blood Pressure Wristband.

picture_startdsp

Stop() stops all the thread created in Start(). Be notice that the stop command can not be issued before making sure that the DspThreadHandler stopped.

picture_stop

SetBleData() is called in onDataReceived() in MainActivity when data is received from the BLE device.

It is important that the operation of SetBleData() has to be as less as possible to get the best BLE transmission performance. The measured data is stored in the SRAM of VitalSigns Blood Pressure Wristband, which the SRAM size is around 17k bytes, before received by the phone/pad. If the BLE transmission rate is less than the data sample rate of the device, it will make the device run out of memory, and the device stops the measurement by itself. Typically, the sample rate of the VitalSigns Blood Pressure Wristband device is 250kHz for both ECG and PPG, and the data size of ECG and PPG are 4 bytes. In other words, the BLE transmission rate has to be more than or equal to 2k bytes per second.

For example, if the BLE transmission rate is limited by the host at 1k bytes per second, the VitalSigns Blood Pressure Wristband will stop the measurement by itself after 17 seconds due to it runs out of memory.


Build and Run

 

Build the project and run it. You can enjoy to use the VitalSigns Blood Pressure Wristband to measure your blood pressure.

Select the BLE Device

screenshot_2016-10-26-18-26-04

Enter MainActivity

screenshot_2016-10-26-18-26-19

Measure the Blood Pressure

screenshot_2016-10-26-18-27-29