Creating a GATT database on the BLE Server through FSCI commands

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating a GATT database on the BLE Server through FSCI commands

Creating a GATT database on the BLE Server through FSCI commands

Introduction

 

This post explains how to create a BLE GATT database using FSCI commands sent to the BLE Server device. Additionally, this document explains how to set up the fields of each FSCI command used to create the BLE GATT database for the BLE Server.

 

Main FSCI commands to create the BLE GATT DB in the BLE Server device

 

The following, are the main commands to create, write and read the GATT DB from the BLE Server perspective. The purpose of this post is to serve as a reference and summary of the most important commands. The full list of commands FSCI commands can be found in the Framework Serial Connectivity Interface (FSCI) for Bluetooth Low Energy Host Stack documentation within your SDK package.

GATT-InitRequest

This command is used to initialize the GATT database at runtime, and it must be sent before any other command to declare a database in your BLE Server device.

GATTServer-RegisterCallback.Request

This command installs an application callback for the GATT Server module, enabling the device to respond to the FSCI request from the CPU application through an FSCI indication.

GATTDBDynamic-AddPrimaryServiceDeclaration.Request

It adds a primary service to the database. It has 3 parameters that should be configured, the desired handle, the UUID type (16 bits, 32 bits, 128 bits), and the UUID value. Usually, the desired handle should be set to zero and the stack will assign the handle of the primary service automatically.

EdgarLomeli_0-1613662148797.png

 

If the GATT application callback was installed through the GATTServer-RegisterCallback.Request command, the GATT Server responds to the GATTDBDynamic-AddPrimaryServiceDeclaration.Request command with a GATTDBDynamic-AddPrimaryServiceDeclaration.Indication that contains the handle assigned to the primary service. The following example shows how to prepare this command to define the battery service in the database.

EdgarLomeli_1-1613662240971.png

GATTDBDynamic-AddCharacteristicDeclarationAndValue.Request

It adds a characteristic and its value to the database. It has 7 parameters that should be configured, the UUID type (16 bits, 32 bits, 128 bits), the UUID value, characteristic properties, the maximum length of the value (only for variable-length values), the initial length of the value, the initial value of the characteristic and value access permissions. The characteristic declared using this command, belongs to the last primary service declared in the database. For values with a fixed length, the maximum length parameter should be set to 0, and the length is obtained from the initial length of the value parameter.

EdgarLomeli_2-1613662313466.png

 

If the GATT application callback was installed, the response of this command is indicated by the GATTDBDynamic-AddCharacteristicDeclarationAndValue.Indication command. The following example shows how to prepare this command to define the battery level characteristic in the database with a fixed length of 1 byte and an initial value of 90%.

EdgarLomeli_3-1613662360497.png


GATTDBDynamic-AddCharacteristicDescriptor.Request

It adds a characteristic descriptor to the database. It has 5 parameters that should be configured, the UUID type (16 bits, 32 bits, 128 bits), UUID value, length of the descriptor value, descriptor’s value, and descriptor access permissions. The descriptor declared using this command, belongs to the last characteristic declared in the database.

EdgarLomeli_4-1613662465943.png

 

If the GATT application callback was installed, the response of this command is indicated by the GATTDBDynamic-AddCharacteristicDescriptor.Indication command. The following example shows how to prepare this command to add the characteristic presentation format descriptor of the battery level characteristic in the database.

EdgarLomeli_5-1613662501509.png

 

GATTDBDynamic-AddCccd.Request

It adds a CCDD into the database. This command does not have parameters. The CCCD declared using this command, belongs to the last characteristic declared in the database. The response of this command is indicated by GATTDBDynamic-AddCccd.Indication.

EdgarLomeli_6-1613662554825.png

 

GATTDB-FindServiceHandle.Request

This command is used to find the handle of a service previously declared in the database. It has 3 parameters that should be configured, the handle to start the search (should be 1 on the first call), the UUID type of the service to find (16 bits, 32 bits, 128 bits), and the UUID value of the service that you are searching.

EdgarLomeli_7-1613662589511.png

 

If the GATT application callback was installed, the response of this command is indicated by the GATTDB-FindServiceHandle.Indication command, which contains the handle of the found service. The following example shows how to prepare this command to find the handle of the battery service declared in the previous examples. Notice that the result of the search corresponds to the handle returned by the GATTDBDynamic-AddPrimaryServiceDeclaration.Indication as expected.

EdgarLomeli_8-1613662631192.png

 

GATTDB-FindCharValueHandleInService

It finds the characteristic´s handle of a given service previously declared in the database. It has 3 parameters that should be configured, the handle of the service that contains the characteristic, the UUID type of the characteristic to find (16 bits, 32 bits, 128 bits), and the UUID value of the characteristic that you are searching for.

EdgarLomeli_9-1613662671091.png

 

If the GATT application callback was installed, the response of this command is indicated by the GATTDB-FindCharValueHandleInService.Indication command, which contains the handle of the found characteristic’s value. The following example shows how to prepare this command to find the handle of the battery level value. Notice that the result of the search corresponds to the handle returned by the GATTDBDynamic-AddCharacteristicDeclarationAndValue.Indication plus one, because the AddCharacteristicDeclarationAndValueIndication command returns the handle of the characteristic and, on the other hand, FindCharValueHandleInService returns the handle of the characteristic’s value.

EdgarLomeli_10-1613662758533.png

GATTDB-FindDescriptorHandleForcharValueHandle.Request

It finds the descriptor´s handle of a given characteristic previously declared in the database. It has 3 parameters that should be configured, the handle of the characteristic’s value that contains the descriptor, the UUID type of the descriptor to find (16 bits, 32 bits, 128 bits), and the UUID value of the descriptor that you are searching.

EdgarLomeli_11-1613662785190.png

 

If the GATT application callback was installed, the response of this command is indicated by the GATTDB-FindDescriptorHandleForCharValueHandle.Indication command, which contains the handle of the found descriptor. The following example shows how to prepare this command to find the handle of the characteristic presentation format descriptor. The result corresponds to the handle returned by the GATTDBDynamic-AddCharacteristicDescriptor.Indication

EdgarLomeli_12-1613662827552.png

 

GATTDB-FindCccdHandleForCharValueHandle.Request

It finds the CCCD’s handle of a given characteristic previously declared in the database. It has only one parameter, the handle of the characteristic’s value that contains the CCCD.

EdgarLomeli_13-1613662861529.png

 

If the GATT application callback was installed, the response of this command is indicated by the GATTDB-FindCccdHandleForCharValueHandle.Indication command, which contains the handle of the found CCCD. The following example shows how to prepare this command to find the handle of CCCD. The result corresponds to the handle returned by the GATTDBDynamic-AddCccd.Indication.

EdgarLomeli_14-1613662890410.png

 

GATTDB-WriteAttribute.Request

It writes the value of a given attribute from the application level. It has 3 parameters that should be configured, the handle of the attribute that you want to write, the length of the value in bytes, and the new value.

EdgarLomeli_15-1613662923735.png

 

In the following example, we will modify the battery level characteristic’s value from 90% to 80%.

EdgarLomeli_16-1613662948992.png

 

GATTDB-ReadAttribute.Request

 

It reads the value of a given attribute from the application level. It has 2 parameters that should be configured, the handle of the attribute that you want to read, and the maximum bytes that you want to read. The GATT application callback must be installed, since the response of this command indicated by the GATTDB-ReadAttribute.Indication command contains the value read from the database.

In the following example, we will read the battery level characteristic’s value, the result is 80%.

EdgarLomeli_17-1613662979826.png

 

 

 

Labels (3)
No ratings
Version history
Last update:
‎02-18-2021 08:43 AM
Updated by: