38 lines
1.4 KiB
C
38 lines
1.4 KiB
C
#ifndef BLE_MGMT_H
|
|
#define BLE_MGMT_H
|
|
|
|
#include <zephyr/types.h>
|
|
|
|
typedef void (*ble_mgmt_rx_cb_t)(const uint8_t *data, uint16_t len);
|
|
|
|
/**
|
|
* Initializes the BLE management module, sets up the GATT service and starts advertising.
|
|
* @param rx_cb Callback function to handle received data from the central device.
|
|
* @param device_name Optional custom device name for advertising. If NULL, a default name is used.
|
|
* @return 0 on success, or a negative error code on failure.
|
|
*/
|
|
int ble_mgmt_init(ble_mgmt_rx_cb_t rx_cb, const char *device_name);
|
|
|
|
/**
|
|
* Sends data to the connected central device via a GATT characteristic.
|
|
* @param data Pointer to the data buffer to send.
|
|
* @param len Length of the data in bytes.
|
|
* @return 0 on success, -EACCES if notifications are not enabled, or a negative error code on failure.
|
|
*/
|
|
int ble_mgmt_send(const uint8_t *data, uint16_t len);
|
|
|
|
/**
|
|
* Updates the advertised device name and restarts advertising with the new name.
|
|
* @param new_name The new device name to advertise.
|
|
* @return 0 on success, or a negative error code on failure.
|
|
*/
|
|
int ble_mgmt_update_adv_name(const char *new_name);
|
|
|
|
/**
|
|
* Retrieves the maximum payload size that can be sent in a single notification.
|
|
* This is determined by the current ATT MTU size minus the GATT header overhead.
|
|
* @return The maximum payload size in bytes.
|
|
*/
|
|
uint16_t ble_mgmt_get_max_payload(void);
|
|
|
|
#endif // BLE_MGMT_H
|