Profile configuration
The implemented profiles and services are located in middleware/wireless/bluetooth/profiles folder. The application links every service source file and interface it needs to implement the profile. For example, for the Temperature Sensor the tree looks as shown Figure 1:
The Temperature Profile implements the custom Temperature service, the Battery, and Device Information services.
Application code
The application folder contains the following modules:
app.c and app.h. This module stores the application-specific functionality (APIs for specific triggers, handling of peripherals, callbacks from the stack, handling of low power, and so on).
Before initializing the Bluetooth LE Host Stack, the start task calls BluetoothLEHost_AppInit. This function initializes application specific functionality before initializing the Bluetooth LE Host Stack by calling BluetoothLEHost_Init.
After the stack is initialized, the BluetoothLEHost_Initialized callback is called. The function contains configurations made to the Bluetooth LE Host Stack after the initialization. This includes registering callbacks, setting security for services, starting services, allocating timers, adding devices to the Filter Accept List, and so on. For example, the Temperature Sensor configures the following:
static void **BluetoothLEHost\_Initialized**(void)
{
/* Common GAP configuration */
BleConnManager_GapCommonConfig();
/* Register for callbacks*/
(void)App_RegisterGattServerCallback(BleApp_GattServerCallback);
mAdvState.advOn = FALSE;
/* Start services */
SENSORS_TriggerTemperatureMeasurement();
(void)SENSORS_RefreshTemperatureValue();
/* Multiply temperature value by 10. SENSORS_GetTemperature() reports temperature
value in tenths of degrees Celsius. Temperature characteristic value is degrees
Celsius with a resolution of 0.01 degrees Celsius (GATT Specification
Supplement v6). */
tmsServiceConfig.initialTemperature = (int16_t)(10 * SENSORS_GetTemperature());
(void)Tms_Start(&tmsServiceConfig);
basServiceConfig.batteryLevel = SENSORS_GetBatteryLevel();
(void)Bas_Start(&basServiceConfig);
(void)Dis_Start(&disServiceConfig);
/* Allocate application timer */
(void)TM_Open(appTimerId);
AppPrintString("\r\nTemperature sensor -> Press switch to start advertising.\r\n");
}
To start the application functionality, BleApp_Start()
function is called. This function usually contains code to start advertising for sensor nodes or scanning for central devices. In the example of the Temperature Sensor, the function is the following:
static void **BleApp\_Start**(void)
{
Led1On();
if (mPeerDeviceId == gInvalidDeviceId_c)
{
/* Device is not connected and not advertising */
if (!mAdvState.advOn)
{
/* Set advertising parameters, advertising to start on gAdvertisingParametersSetupComplete_c */
BleApp_Advertise();
}
}
else
{
/* Device is connected, send temperature value */
BleApp_SendTemperature();
}
}
app_config.c. This file contains data structures that are used to configure the stack.
This includes advertising data, scanning data, connection parameters, advertising parameters, SMP keys, security requirements, and so on.
app_preinclude.h.
This header file contains macros to override the default configuration of any module in the application. It is added as a preinclude file in the preprocessor command line in IAR, as shown in Figure 1:
gatt_db.h and gatt_uuid128.h. The two header files contain the definition of the GATT database and the custom UUIDs used by the application. See Creating GATT database for more information.
Parent topic:Profile configuration
Parent topic:Application Structure