One of the most difficult part of creating connected medical applications is, actually, keep it connected. Different protocols are available to transmit information from a medical device to a database or user interface. Sometimes integrating our application to the current communication protocols can be as difficult as developing the device itself.
Freescale has launched its Bluetooth® Low Energy (BLE) chips, and with them, a complete software stack that integrates most of the available profiles for BLE oriented applications. Using this set, it becomes easy to integrate your current medical application to use BLE as communications method.
The connectivity software includes examples to demonstrate BLE communications with a smartphone device. Using these examples as a base facilitates the integration with an existing application and reduces the required time it takes to have a fully connected application. This post uses as an example the Heart Rate Monitor demo to show how these applications can be customized.
The BLE services information reported by the device is stored in a file named “gatt_db.h”. This services information is what is shown on a smartphone when the device has connected. The Generic Access Profile service includes the device name reported when advertising. To change it just replace the device name between “” and update the character count.
Detailed device information is accessed via the Device Information Service including the manufacturer name, model and serial number etcetera. This information can also be adjusted to the custom device requirements by modifying the string between “” and updating the character number.
The connectivity software includes some predefined services that can be used to customize the server to report our application data. These predefined services already include structures with the information that needs to be reported to the client.
On the application example file app.c some of these services are configured. For the heart rate service, a variable of type hrsConfig_t is created containing configuration information of the heart rate sensor such as the supported characteristics and sensor location. All of these characteristics are described in the heart rate service file heart_rate_interface.h
/* Service Data*/
static basConfig_t basServiceConfig = {service_battery, 0};
static disConfig_t disServiceConfig = {service_device_info};
static hrsUserData_t hrsUserData;
static hrsConfig_t hrsServiceConfig = {service_heart_rate, TRUE, TRUE, TRUE, gHrs_BodySensorLocChest_c, &hrsUserData};
static uint16_t cpHandles[1] = { value_hr_ctrl_point };
/*! Heart Rate Service - Configuration */
typedef struct hrsConfig_tag
{
uint16_t serviceHandle;
bool_t sensorContactSupported;
bool_t sensorContactDetected;
bool_t energyExpandedEnabled;
hrsBodySensorLoc_t bodySensorLocation;
hrsUserData_t *pUserData;
} hrsConfig_t;
This information is used to configure the server when the function BleApp_Config is called.
/* Start services */
hrsServiceConfig.sensorContactDetected = mContactStatus;
#if gHrs_EnableRRIntervalMeasurements_d
hrsServiceConfig.pUserData->pStoredRrIntervals = MEM_BufferAlloc(sizeof(uint16_t) * gHrs_NumOfRRIntervalsRecorded_c);
#endif
Hrs_Start(&hrsServiceConfig);
basServiceConfig.batteryLevel = BOARD_GetBatteryLevel();
Bas_Start(&basServiceConfig);
/* Allocate application timers */
mAdvTimerId = TMR_AllocateTimer();
Once the server is configured, the application is stated by entering the device in advertising state in order to make it visible for clients. This is done by calling the function BleApp_Advertise that configures the server to start advertising.
void BleApp_Start(void)
{
/* Device is not connected and not advertising*/
if (!mAdvState.advOn)
{
#if gBondingSupported_d
if (mcBondedDevices > 0)
{
mAdvState.advType = fastWhiteListAdvState_c;
}
else
{
#endif
mAdvState.advType = fastAdvState_c;
#if gBondingSupported_d
}
#endif
BleApp_Advertise();
}
#if (cPWR_UsePowerDownMode)
PWR_ChangeDeepSleepMode(1); /* MCU=LLS3, LL=DSM, wakeup on GPIO/LL */
PWR_AllowDeviceToSleep();
#endif
}
Once the server has been found and a connection has been stablished with the client, the configured services must be started. This is done by calling the “subscribe” function for each service. For heart rate sensor, the function Hrs_Suscribe must be called. This function is available from the heart_rate_interface files.
/* Subscribe client*/
Bas_Subscribe(peerDeviceId);
Hrs_Subscribe(peerDeviceId);
#if (!cPWR_UsePowerDownMode)
/* UI */
During connection, the application measurements can be reported to the client by using the “record measurement” functions included in the service interfaces. For the heart rate sensor this is the Hrs_RecordHeartRateMeasurement function.
static void TimerMeasurementCallback(void * pParam)
{
uint16_t hr = BOARD_GetPotentiometerLevel();
hr = (hr * mHeartRateRange_c) >> 12;
#if gHrs_EnableRRIntervalMeasurements_d
Hrs_RecordRRInterval(&hrsUserData, (hr & 0x0F));
Hrs_RecordRRInterval(&hrsUserData,(hr & 0xF0));
#endif
if (mToggle16BitHeartRate)
{
Hrs_RecordHeartRateMeasurement(service_heart_rate, 0x0100 + (hr & 0xFF), &hrsUserData);
}
else
{
Hrs_RecordHeartRateMeasurement(service_heart_rate, mHeartRateLowerLimit_c + hr, &hrsUserData);
}
Hrs_AddExpendedEnergy(&hrsUserData, 100);
#if (cPWR_UsePowerDownMode)
PWR_SetDeepSleepTimeInMs(900);
PWR_ChangeDeepSleepMode(6);
PWR_AllowDeviceToSleep();
#endif
}
This updates the current measurement and sends a notification to the client indicating that a new measurement report is ready.
Many profiles are implemented in the connectivity software to enable already developed medical applications with BLE connectivity. APIs are easy to use and can significantly reduce the development times.