Application common modules#
While the CS APIs are available to applications and can be used directly, common application modules are also provided. These modules, detailed below, offer a simplified API for performing distance measurements and allow for quick integration into existing applications.
app_localization common module#
Introduction#
The app_localization common module allows for quick integration of Channel Sounding functionality in a Bluetooth LE application.
Integration#
All the APIs referenced in this section are available in the app_localization application common module.
Perform the following steps for integration into the application. Unless specified, each step applies to both the CS Initiator and the CS Reflector:
Add the following components to the application project via Kconfig:
CONFIG_MCUX_COMPONENT_middleware.wireless.lcl=yCONFIG_MCUX_COMPONENT_middleware.wireless.ble_host_CS=yCONFIG_MCUX_COMPONENT_middleware.wireless.ble_host_CS_component_lib=y
Begin the initialization of the common module by calling
AppLocalization_Init(). One of the parameters of this API is the application callback where events will be received from the app_localization module.Complete the initialization of the common module by calling
AppLocalization_HostInitHandler()after the Host stack has been initialized.The CS Config depends on the Bluetooth LE connection interval. Upon connection with the peer, the CS Config is retrieved by calling
AppLocalization_ReadConfig()and updated by callingAppLocalization_WriteConfig().If the application is the Ranging Requester, that is, it will run the distance measurement algorithm, the connection interval must also be saved by calling the function
AppLocalization_SetConnectionInterval(). This is required by the algorithm.Once the Ranging Requester has discovered and subscribed to the Ranging Service on the Ranging Responder (as detailed in the section below), the CS procedure can begin. The first step is to call
AppLocalization_Config().Upon receiving the
gConfigComplete_cor thegLocalConfigWritten_cevents, only the device who has the GAP Central role must callAppLocalization_SecurityEnable().Upon receiving the
gCsSecurityEnabled_cevent, only one device must callAppLocalization_SetProcedureParameters().Upon receiving the
gSetProcParamsComplete_cevent, the device from step 8 must callAppLocalization_StartMeasurement().From this point onwards, the application will receive events informing it of the status of the distance measurement procedure, such as:
gDistanceMeastStarted_c- the CS Procedure has startedgLocalMeasurementComplete_c- the CS Procedure is complete and local data is availablevarious error events
Upon peer disconnection, cleanup should be performed by calling
AppLocalization_ResetPeer().
app_localization_algo common module#
Introduction#
The app_localization_algo module is responsible for unpacking the data resulted from the CS Procedure and the RAS transfer. The module then passes it to the distance measurement algorithm to obtain the distance in meters, which is then communicated to the application.`
Integration#
The app_localization_algo is only required on the application that has the role of Ranging Requester and computes the actual distance. Perform the following steps to integrate app_localization_algo common module:
Add the following component to the application project via Kconfig:
CONFIG_MCUX_COMPONENT_middleware.wireless.lcl_algo=y
Pass a callback of type
pfAppDisplayResult_tas the third parameter ofAppLocalization_Init. This callback receives the distance measurement result, which the application displays.Call the function
AppLocalizationAlgo_ResetPeerupon peer disconnection to clean up algorithm-related data structures.There is no other direct interaction between the application and this module. Its APIs are mostly used by the app_localization module.
Ranging Service common module#
Introduction#
The Ranging Service is a GATT service used to transfer the data resulted from the CS Procedure from one device (the Ranging Responder) to the other (the Ranging Requester).
Integration#
Perform the following steps to integrate the Ranging Service on the application that has the role of Ranging Requester (GATT client):
Add the following component to the application project via Kconfig:
CONFIG_MCUX_COMPONENT_middleware.wireless.ble_profiles_ranging_client=y
Ensure the
gRasRREQ_ddefine is present and set to1in the application’sapp_preinclude.hfile.After the connection with the peer is encrypted, proceed to discover the RAS and its characteristics through the common Service Discovery module. Register a service discovery callback using
BleServDisc_RegisterCallbackand callBleServDisc_FindService()with thegBleSig_RangingService_dUUID as parameter. On thegServiceDiscovered_cevent in the registered callback, store the handles of the RAS and its characteristics and characteristic descriptors for later use. Some handles also need to be registered with the localization component via the following APIs:RasClient_SetRasControlPointHandleRasClient_SetRasRealTimeHandleRasClient_SetRasSupportedFeatures
Proceed to use the regular GATT client APIs such as
GattClient_ReadCharacteristicValue()andGattClient_WriteCharacteristicDescriptor()in order to read the peer’s supported RAS features and enable notifications/indications on the RAS Control Point CCCD and on either the On-Demand or Real-Time CCCDs. If you choose On-Demand as a data transfer method, you must also enable notifications/indications on the RAS Data Ready and Data Overwritten CCCDs. The client is now considered subscribed to the RAS and the CS Procedure can start by following the steps described in the sections above.Depending on the RAS settings chosen by the client application, communication from the server arrives as either GATT notifications or indications. In the GATT notification or indication callback, the following APIs should be used:
RasClient_StorePeerMeasurementData, when the On-Demand or Real-Time handle is notified/indicated.RasClient_ProcessRasCPRsp, when the Control Point handle is notified/indicated.RasClient_ProcessRasDataReadyIndications, when the Data Ready handle is notified/indicated.RasClient_ProcessRasDataOverwrittenIndications, when the Data Overwritten handle is notified/indicated.
Perform the following steps to integrate the Ranging Service on the application that has the role of Ranging Responder (GATT server):
Add the following component to the application project via Kconfig:
CONFIG_MCUX_COMPONENT_middleware.wireless.ble_profiles_ranging=y
Ensure the
gRasRRSP_dandgAppRasDataTransfer_ddefines are present and set to1in the application’sapp_preinclude.hfile.Add the Ranging Service and its characteristics to the GATT database in the application project’s
gatt_db.hfile as in the excerpt below:PRIMARY_SERVICE(service_ranging, gBleSig_RangingService_d) CHARACTERISTIC(char_ras_ctrl_point, gBleSig_RasControlPoint_d, (gGattCharPropWriteWithoutRsp_c | gGattCharPropIndicate_c) ) VALUE_VARLEN(value_ras_ctrl_point, gBleSig_RasControlPoint_d, (gPermissionFlagWritable_c | gPermissionFlagWriteWithEncryption_c ), 0x05, 0x01, 0x00) CCCD(cccd_ras_ctrl_point) CHARACTERISTIC(char_ras_stored_data, gBleSig_RasOnDemandProcData_d, (gGattCharPropNotify_c | gGattCharPropIndicate_c) ) VALUE_VARLEN(value_ras_stored_data, gBleSig_RasOnDemandProcData_d, (gPermissionNone_c), gAttMaxNotifIndDataSize_d(gAttMaxMtu_c), 0x01, 0x00) CCCD(cccd_ras_stored_data) CHARACTERISTIC(char_ras_real_time_data, gBleSig_RasRealTimeProcData_d, (gGattCharPropNotify_c | gGattCharPropIndicate_c) ) VALUE_VARLEN(value_ras_real_time_data, gBleSig_RasRealTimeProcData_d, (gPermissionNone_c), gAttMaxNotifIndDataSize_d(gAttMaxMtu_c), 0x01, 0x00) CCCD(cccd_ras_real_time_data) CHARACTERISTIC(char_ras_ranging_data_ready, gBleSig_RasProcDataReady_d, (gGattCharPropNotify_c | gGattCharPropIndicate_c) ) VALUE(value_ras_ranging_data_ready, gBleSig_RasProcDataReady_d, (gPermissionNone_c), 0x02, 0x00, 0x00) CCCD(cccd_ras_data_ready) CHARACTERISTIC(char_ras_ranging_data_overwritten, gBleSig_RasprocDataOverwritten_d, (gGattCharPropNotify_c | gGattCharPropIndicate_c) ) VALUE(value_ras_ranging_data_overwritten, gBleSig_RasprocDataOverwritten_d, (gPermissionNone_c), 0x02, 0x00, 0x00) CCCD(cccd_ras_data_overwritten) CHARACTERISTIC(char_ras_feature, gBleSig_RasFeature_d, (gGattCharPropRead_c) ) VALUE(value_ras_feature, gBleSig_RasFeature_d, (gPermissionFlagReadable_c | gPermissionFlagReadWithEncryption_c), 4, 0x0F, 0x00, 0x00, 0x00)
Initialize RAS by calling
Ras_Start()with the handles defined in the GATT database.Upon the MTU Exchange procedure’s completion, call
Ras_SetMtuValue()to inform the module.The client’s interactions with the server are processed in the GATT server callback. Here the following APIs are used:
Ras_Subscribewhen the client subscribes to either On-Demand or Real-Time CCCDs.Ras_SetDataSendPreferenceto save the client’s preference for the data transfer (either notifications or indications).Ras_ControlPointHandlerwhen the client writes a command to the RAS Control Point.Ras_Unsubscribewhen the client unsubscribes or disconnects.
Distance Measurement Algorithm#
Introduction#
The SDK provides the RADE (Rapid Accurate Distance Estimator) algorithm for precise distance measurement between devices. This algorithm leverages the LCE (Localization Compute Engine) accelerator to calculate distances with high accuracy and low latency.
Integration#
Perform the following steps to integrate the RADE algorithm on the distance-measuring application:
Add the following components to the application project via Kconfig:
CONFIG_MCUX_COMPONENT_middleware.wireless.genfsk_wr_lcl_algo_cm33_lce_lib=yCONFIG_MCUX_PRJSEG_module.board.wireless.app_lce=yCONFIG_MCUX_PRJSEG_module.board.wireless.linker_script_ble=nCONFIG_MCUX_PRJSEG_module.board.wireless.linker_script_ble_loc=y
APP_InitLce()will be automatically called byAppLocalization_Init()during application initialization.Heap areas required by the algorithm are defined and registered in
app_lce_init.c.