Appearance
struct ble_gatt
Structure returned by the BLE driver to configure and interact with the peripheral. More...
#include <ble/ble_gatt.h>
Public Attributes
Name | |
---|---|
void(*)(ble_manager_on_connect ble_mgr_on_connect_cb, ble_manager_on_disconnect ble_mgr_on_disconnect_cb, ble_manager_on_write ble_mgr_on_write_cb, ble_manager_on_read ble_mgr_on_read_cb, void *context, uint32_t capabilities) | init |
void(*)(void) | deinit Free the resources taken by the Gatt-instance. Should be called before closing the driver handle. |
bool(*)(void) | uninitialized |
int32_t(*)(ble_uuid128_t uuid) | begin_service Begins a service with the specified UUID. |
void(*)(void) | end_service the declaration of a GATT-Service Can only be called after a previous call to begin_service (ble_uuid128_t uuid) |
int32_t(*)(ble_uuid128_t uuid, uint8_t modifiers, uint16_t len) | add_characteristic Adds a characteristic to a GATT service with a given UUID, modifiers, and length. |
int32_t(*)(ble_uuid128_t uuid, uint8_t modifiers, uint8_t *bytes, uint16_t num_bytes) | add_descriptor Adds a descriptor to a characteristic in a GATT service. |
int32_t(*)(char *name) | set_local_name Function to set the local name of the device. |
int32_t(*)(uint8_t *data, uint8_t len) | set_advertise_data Function to set the advertise data for the device. |
int32_t(*)(uint16_t min, uint16_t max) | set_advertise_timing Function to set the advertise timing for the device. |
int32_t(*)(uint8_t handle, uint8_t addr_type, uint8_t *adress, uint8_t addr_len) | set_device_address Sets the device address for a given handle and address type. |
int32_t(*)(uint8_t *data, uint8_t len) | set_scan_response_data Function to set the scan response data for the device. |
int32_t(*)(void) | start_advertising Starts the advertising process. |
int32_t(*)(void) | stop_advertising Stop Advertising. |
int32_t(*)(void) | disconnect Function to disconnect from a device. |
int32_t(*)(uint16_t start_handle, uint8_t *bytes, uint16_t num_bytes) | find_attribute_handle Function to find the handle of an attribute with a given UUID within a range of handles. |
int32_t(*)(uint16_t handle, uint8_t *bytes, uint16_t max_bytes, uint16_t *num_bytes) | get_attribute_type Function to get the type of an attribute with the given handle. |
uint16_t(*)(void) | get_mtu Function to get the Maximum Transmission Unit (MTU) size. |
int32_t(*)(uint16_t handle, uint8_t *data, uint8_t len, bool indicate) | notify Pointer to a notification function. |
Detailed Description
cpp
struct ble_gatt;
Structure returned by the BLE driver to configure and interact with the peripheral.
The BLE GATT module driver enables users to interact with BLE GATT resources, defining key functionalities and interactions available to the user.
The driver provides functionalities such as initialization and de-initialization, starting and stopping advertising, adding services and characteristics to the BLE stack, setting device name and advertisement parameters, managing BLE connections, and data transfer with connected devices among others.
Public Attributes Documentation
variable init
cpp
void(* ble_gatt::init) (ble_manager_on_connect ble_mgr_on_connect_cb, ble_manager_on_disconnect ble_mgr_on_disconnect_cb, ble_manager_on_write ble_mgr_on_write_cb, ble_manager_on_read ble_mgr_on_read_cb, void *context, uint32_t capabilities)
Parameters:
- ble_mgr_on_connect_cb function to be called when a peripheral connects
- ble_mgr_on_disconnect_cb function to be called when a peripheral disconnects
- ble_mgr_on_write_cb function to be called when a peripheral writes data
- ble_mgr_on_read_cb function to be called when a peripheral wants to read data
- context user data pointer that will be passed to all callback functions. can be used to identify the instance, e.g.
- capabilities reserved, set this to zero.
Initialize the device for use. Needs to be called before any other functions are called.
variable deinit
cpp
void(* ble_gatt::deinit) (void)
Free the resources taken by the Gatt-instance. Should be called before closing the driver handle.
variable uninitialized
cpp
bool(* ble_gatt::uninitialized) (void)
Return: true if deinitialization has finished.
Some BLE drivers need some time to free up all resources. Since deinit(void) is non-blocking, the successful finalization of the deinit process can be checked by calling this function.
variable begin_service
cpp
int32_t(* ble_gatt::begin_service) (ble_uuid128_t uuid)
Begins a service with the specified UUID.
Parameters:
- uuid The UUID of the service to begin.
Return: An integer value indicating the result of the operation.
- 0: Service started successfully.
- Non-zero: An error occurred while starting the service.
This function starts a service with the provided UUID. The UUID is specified as a 128-bit value represented by the [ble_uuid128_t](/embed/v2/API/Classes/structble__uuid128__t.md)
type.
variable end_service
cpp
void(* ble_gatt::end_service) (void)
the declaration of a GATT-Service Can only be called after a previous call to begin_service (ble_uuid128_t uuid)
variable add_characteristic
cpp
int32_t(* ble_gatt::add_characteristic) (ble_uuid128_t uuid, uint8_t modifiers, uint16_t len)
Adds a characteristic to a GATT service with a given UUID, modifiers, and length.
Parameters:
- uuid The UUID of the characteristic to be added.
- modifiers The modifiers for the characteristic.
- len The length of the characteristic.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to add a characteristic to a GATT service in the BLE driver. The characteristic is identified by its UUID, which is represented using the BLE_UUID128_t structure. The modifiers parameter is used to specify any modifiers for the characteristic. The length parameter is used to specify the length of the characteristic.
variable add_descriptor
cpp
int32_t(* ble_gatt::add_descriptor) (ble_uuid128_t uuid, uint8_t modifiers, uint8_t *bytes, uint16_t num_bytes)
Adds a descriptor to a characteristic in a GATT service.
Parameters:
- uuid The UUID of the descriptor to be added.
- modifiers The modifiers for the descriptor.
- bytes The descriptor data.
- num_bytes The number of bytes in the descriptor data.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to add a descriptor to a characteristic in a GATT service in the BLE driver. The descriptor is identified by its UUID, which is represented using the [ble_uuid128_t](/embed/v2/API/Classes/structble__uuid128__t.md)
structure. The modifiers
parameter is used to specify any modifiers for the descriptor. The bytes
parameter is used to specify the descriptor data. The num_bytes
parameter is used to specify the number of bytes in the descriptor data.
variable set_local_name
cpp
int32_t(* ble_gatt::set_local_name) (char *name)
Function to set the local name of the device.
Parameters:
- name The local name to set for the device.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to set the local name of the device in the BLE driver. The local name is a human-readable name that identifies the device to other devices.
variable set_advertise_data
cpp
int32_t(* ble_gatt::set_advertise_data) (uint8_t *data, uint8_t len)
Function to set the advertise data for the device.
Parameters:
- data Pointer to the advertise data.
- len Length of the advertise data.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to set the advertise data for the device in the BLE driver. The advertise data is the data that is transmitted by the device when advertising to other devices.
variable set_advertise_timing
cpp
int32_t(* ble_gatt::set_advertise_timing) (uint16_t min, uint16_t max)
Function to set the advertise timing for the device.
Parameters:
- min The minimum advertising interval in milliseconds.
- max The maximum advertising interval in milliseconds.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to set the advertise timing for the device in the BLE driver. The advertise timing determines the duration and interval of advertising. The min parameter specifies the minimum advertising interval in milliseconds. The max parameter specifies the maximum advertising interval in milliseconds.
variable set_device_address
cpp
int32_t(* ble_gatt::set_device_address) (uint8_t handle, uint8_t addr_type, uint8_t *adress, uint8_t addr_len)
Sets the device address for a given handle and address type.
Parameters:
- handle The handle of the device.
- addr_type The address type of the device.
- address The device address.
- addr_len The length of the device address.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to set the device address for a specific handle and address type. The device address is represented as an array of bytes in adress
, and the address length is specified by addr_len
.
variable set_scan_response_data
cpp
int32_t(* ble_gatt::set_scan_response_data) (uint8_t *data, uint8_t len)
Function to set the scan response data for the device.
Parameters:
- data Pointer to the scan response data.
- len Length of the scan response data.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to set the scan response data for the device in the BLE driver. The scan response data is the data that is transmitted by the device in response to a scan request from other devices.
variable start_advertising
cpp
int32_t(* ble_gatt::start_advertising) (void)
Starts the advertising process.
Return: An integer value indicating the status of the advertising process:
- 0: Success
- Negative value: Error code
This function is used to start the advertising process. It should be implemented by the caller of this code and registered as a callback function. The advertising process is specific to the application or the underlying system.
variable stop_advertising
cpp
int32_t(* ble_gatt::stop_advertising) (void)
Stop Advertising.
Return: int32_t Returns a value indicating the status of the function call.
- Negative value indicates an error.
- Zero indicates success.
This function is used to stop advertising.
variable disconnect
cpp
int32_t(* ble_gatt::disconnect) (void)
Function to disconnect from a device.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to disconnect from a device in the BLE driver.
variable find_attribute_handle
cpp
int32_t(* ble_gatt::find_attribute_handle) (uint16_t start_handle, uint8_t *bytes, uint16_t num_bytes)
Function to find the handle of an attribute with a given UUID within a range of handles.
Parameters:
- start_handle The starting handle of the range.
- bytes The UUID of the attribute.
- num_bytes The length of the UUID in bytes.
Return: int32_t Returns the handle of the attribute if it is found within the range, or a negative value if not found.
This function is used to find the handle of an attribute with a given UUID within a range of handles in the Bluetooth Low Energy (BLE) driver. The start_handle parameter specifies the starting handle of the range. The bytes parameter is a pointer to the UUID of the attribute. The num_bytes parameter specifies the length of the UUID in bytes.
variable get_attribute_type
cpp
int32_t(* ble_gatt::get_attribute_type) (uint16_t handle, uint8_t *bytes, uint16_t max_bytes, uint16_t *num_bytes)
Function to get the type of an attribute with the given handle.
Parameters:
- handle The handle of the attribute.
- bytes Pointer to the buffer where the type of the attribute will be stored.
- max_bytes The maximum number of bytes that can be stored in the buffer.
- num_bytes Pointer to a variable where the actual number of bytes stored in the buffer will be stored.
Return: int32_t Returns a status code indicating the result of the operation. Return 0 for success, and a negative value for failure.
This function is used to get the type of an attribute with the given handle in the BLE driver. The handle parameter specifies the handle of the attribute. The bytes parameter is a pointer to the buffer where the type of the attribute will be stored. The max_bytes parameter specifies the maximum number of bytes that can be stored in the buffer. The num_bytes parameter is a pointer to a variable where the actual number of bytes stored in the buffer will be stored.
variable get_mtu
cpp
uint16_t(* ble_gatt::get_mtu) (void)
Function to get the Maximum Transmission Unit (MTU) size.
Return: uint16_t Returns the Maximum Transmission Unit (MTU) size.
This function is used to get the Maximum Transmission Unit (MTU) size in the BLE driver. The Maximum Transmission Unit (MTU) size determines the maximum size of the data that can be transmitted in a single packet over the Bluetooth Low Energy (BLE) connection.
variable notify
cpp
int32_t(* ble_gatt::notify) (uint16_t handle, uint8_t *data, uint8_t len, bool indicate)
Pointer to a notification function.
Parameters:
- handle The handle to notify.
- data Pointer to the data to be notified.
- len Length of the data to be notified.
- indicate Indicates whether to indicate the notification or not.
Return: An int32_t value indicating the success or failure of the notification.
Note: The notification function should return a negative value in case of an error, and a positive value if the notification was successful or if there was nothing to notify. Depending on the application, a value of zero may be reserved for indicating a special meaning. The actual interpretation of the return value should be done according to the specific use case.
This function pointer type is used to define a callback function that is responsible for notifying a specific handle with provided data. The function should return an int32_t value.