|
|
@ -6,22 +6,27 @@ |
|
|
|
CONDITIONS OF ANY KIND, either express or implied. |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "ble_spp_server_demo.h" |
|
|
|
|
|
|
|
#include "driver/uart.h" |
|
|
|
#include "esp_bt.h" |
|
|
|
#include "esp_bt_defs.h" |
|
|
|
#include "esp_bt_main.h" |
|
|
|
#include "esp_gap_ble_api.h" |
|
|
|
#include "esp_gatts_api.h" |
|
|
|
#include "esp_log.h" |
|
|
|
#include "esp_system.h" |
|
|
|
#include "freertos/FreeRTOS.h" |
|
|
|
#include "freertos/task.h" |
|
|
|
#include "freertos/event_groups.h" |
|
|
|
#include "esp_system.h" |
|
|
|
#include "esp_log.h" |
|
|
|
#include "freertos/task.h" |
|
|
|
#include "nvs_flash.h" |
|
|
|
#include "esp_bt.h" |
|
|
|
#include "driver/uart.h" |
|
|
|
#include "string.h" |
|
|
|
|
|
|
|
#include "esp_gap_ble_api.h" |
|
|
|
#include "esp_gatts_api.h" |
|
|
|
#include "esp_bt_defs.h" |
|
|
|
#include "esp_bt_main.h" |
|
|
|
#include "ble_spp_server_demo.h" |
|
|
|
static bleuart_t *s_ble_uart_init_struct; |
|
|
|
static blerxcb_t s_cb; |
|
|
|
static uint16_t table_conn_id_m; |
|
|
|
static esp_gatt_if_t table_gatts_if_m; |
|
|
|
static uint16_t table_handle_m; |
|
|
|
|
|
|
|
#define GATTS_TABLE_TAG "GATTS_SPP_DEMO" |
|
|
|
|
|
|
@ -49,8 +54,7 @@ static const uint8_t spp_adv_data[23] = { |
|
|
|
/* Complete List of 16-bit Service Class UUIDs */ |
|
|
|
0x03, 0x03, 0xF0, 0xAB, |
|
|
|
/* Complete Local Name in advertising */ |
|
|
|
0x0F,0x09, 'E', 'S', 'P', '_', 'S', 'P', 'P', '_', 'S', 'E', 'R','V', 'E', 'R' |
|
|
|
}; |
|
|
|
0x0F, 0x09, 'E', 'S', 'P', '_', 'S', 'P', 'P', '_', 'S', 'E', 'R', 'V', 'E', 'R'}; |
|
|
|
|
|
|
|
static uint16_t spp_mtu_size = 23; |
|
|
|
static uint16_t spp_conn_id = 0xffff; |
|
|
@ -67,7 +71,9 @@ static uint8_t heartbeat_count_num = 0; |
|
|
|
|
|
|
|
static bool enable_data_ntf = false; |
|
|
|
static bool is_connected = false; |
|
|
|
static esp_bd_addr_t spp_remote_bda = {0x0,}; |
|
|
|
static esp_bd_addr_t spp_remote_bda = { |
|
|
|
0x0, |
|
|
|
}; |
|
|
|
|
|
|
|
static uint16_t spp_handle_table[SPP_IDX_NB]; |
|
|
|
|
|
|
@ -110,19 +116,15 @@ typedef struct spp_receive_data_buff{ |
|
|
|
spp_receive_data_node_t *first_node; |
|
|
|
} spp_receive_data_buff_t; |
|
|
|
|
|
|
|
static spp_receive_data_buff_t SppRecvDataBuff = { |
|
|
|
.node_num = 0, |
|
|
|
.buff_size = 0, |
|
|
|
.first_node = NULL |
|
|
|
}; |
|
|
|
static spp_receive_data_buff_t SppRecvDataBuff = {.node_num = 0, .buff_size = 0, .first_node = NULL}; |
|
|
|
|
|
|
|
static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param); |
|
|
|
|
|
|
|
/* One gatt-based profile one app_id and one gatts_if, this array will store the gatts_if returned by ESP_GATTS_REG_EVT */ |
|
|
|
static struct gatts_profile_inst spp_profile_tab[SPP_PROFILE_NUM] = { |
|
|
|
[SPP_PROFILE_APP_IDX] = { |
|
|
|
.gatts_cb = gatts_profile_event_handler, |
|
|
|
.gatts_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */ |
|
|
|
[SPP_PROFILE_APP_IDX] = |
|
|
|
{ |
|
|
|
.gatts_cb = gatts_profile_event_handler, .gatts_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */ |
|
|
|
}, |
|
|
|
}; |
|
|
|
|
|
|
@ -169,83 +171,71 @@ static const uint8_t spp_heart_beat_ccc[2] = {0x00, 0x00}; |
|
|
|
#endif |
|
|
|
|
|
|
|
/// Full HRS Database Description - Used to add attributes into the database |
|
|
|
static const esp_gatts_attr_db_t spp_gatt_db[SPP_IDX_NB] = |
|
|
|
{ |
|
|
|
static const esp_gatts_attr_db_t spp_gatt_db[SPP_IDX_NB] = { |
|
|
|
// SPP - Service Declaration |
|
|
|
[SPP_IDX_SVC] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ, |
|
|
|
sizeof(spp_service_uuid), sizeof(spp_service_uuid), (uint8_t *)&spp_service_uuid}}, |
|
|
|
[SPP_IDX_SVC] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ, sizeof(spp_service_uuid), sizeof(spp_service_uuid), (uint8_t *)&spp_service_uuid}}, |
|
|
|
|
|
|
|
// SPP - data receive characteristic Declaration |
|
|
|
[SPP_IDX_SPP_DATA_RECV_CHAR] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, |
|
|
|
CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write}}, |
|
|
|
[SPP_IDX_SPP_DATA_RECV_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write}}, |
|
|
|
|
|
|
|
// SPP - data receive characteristic Value |
|
|
|
[SPP_IDX_SPP_DATA_RECV_VAL] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&spp_data_receive_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE, |
|
|
|
SPP_DATA_MAX_LEN,sizeof(spp_data_receive_val), (uint8_t *)spp_data_receive_val}}, |
|
|
|
[SPP_IDX_SPP_DATA_RECV_VAL] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&spp_data_receive_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, SPP_DATA_MAX_LEN, sizeof(spp_data_receive_val), |
|
|
|
(uint8_t *)spp_data_receive_val}}, |
|
|
|
|
|
|
|
// SPP - data notify characteristic Declaration |
|
|
|
[SPP_IDX_SPP_DATA_NOTIFY_CHAR] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, |
|
|
|
CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_notify}}, |
|
|
|
[SPP_IDX_SPP_DATA_NOTIFY_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_notify}}, |
|
|
|
|
|
|
|
// SPP - data notify characteristic Value |
|
|
|
[SPP_IDX_SPP_DATA_NTY_VAL] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&spp_data_notify_uuid, ESP_GATT_PERM_READ, |
|
|
|
SPP_DATA_MAX_LEN, sizeof(spp_data_notify_val), (uint8_t *)spp_data_notify_val}}, |
|
|
|
[SPP_IDX_SPP_DATA_NTY_VAL] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&spp_data_notify_uuid, ESP_GATT_PERM_READ, SPP_DATA_MAX_LEN, sizeof(spp_data_notify_val), (uint8_t *)spp_data_notify_val}}, |
|
|
|
|
|
|
|
// SPP - data notify characteristic - Client Characteristic Configuration Descriptor |
|
|
|
[SPP_IDX_SPP_DATA_NTF_CFG] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE, |
|
|
|
sizeof(uint16_t),sizeof(spp_data_notify_ccc), (uint8_t *)spp_data_notify_ccc}}, |
|
|
|
[SPP_IDX_SPP_DATA_NTF_CFG] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, sizeof(uint16_t), sizeof(spp_data_notify_ccc), |
|
|
|
(uint8_t *)spp_data_notify_ccc}}, |
|
|
|
|
|
|
|
// SPP - command characteristic Declaration |
|
|
|
[SPP_IDX_SPP_COMMAND_CHAR] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, |
|
|
|
CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write}}, |
|
|
|
[SPP_IDX_SPP_COMMAND_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write}}, |
|
|
|
|
|
|
|
// SPP - command characteristic Value |
|
|
|
[SPP_IDX_SPP_COMMAND_VAL] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&spp_command_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE, |
|
|
|
SPP_CMD_MAX_LEN,sizeof(spp_command_val), (uint8_t *)spp_command_val}}, |
|
|
|
[SPP_IDX_SPP_COMMAND_VAL] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&spp_command_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, SPP_CMD_MAX_LEN, sizeof(spp_command_val), (uint8_t *)spp_command_val}}, |
|
|
|
|
|
|
|
// SPP - status characteristic Declaration |
|
|
|
[SPP_IDX_SPP_STATUS_CHAR] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, |
|
|
|
CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_notify}}, |
|
|
|
[SPP_IDX_SPP_STATUS_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_notify}}, |
|
|
|
|
|
|
|
// SPP - status characteristic Value |
|
|
|
[SPP_IDX_SPP_STATUS_VAL] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&spp_status_uuid, ESP_GATT_PERM_READ, |
|
|
|
SPP_STATUS_MAX_LEN,sizeof(spp_status_val), (uint8_t *)spp_status_val}}, |
|
|
|
[SPP_IDX_SPP_STATUS_VAL] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&spp_status_uuid, ESP_GATT_PERM_READ, SPP_STATUS_MAX_LEN, sizeof(spp_status_val), (uint8_t *)spp_status_val}}, |
|
|
|
|
|
|
|
// SPP - status characteristic - Client Characteristic Configuration Descriptor |
|
|
|
[SPP_IDX_SPP_STATUS_CFG] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE, |
|
|
|
sizeof(uint16_t),sizeof(spp_status_ccc), (uint8_t *)spp_status_ccc}}, |
|
|
|
[SPP_IDX_SPP_STATUS_CFG] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, sizeof(uint16_t), sizeof(spp_status_ccc), |
|
|
|
(uint8_t *)spp_status_ccc}}, |
|
|
|
|
|
|
|
#ifdef SUPPORT_HEARTBEAT |
|
|
|
// SPP - Heart beat characteristic Declaration |
|
|
|
[SPP_IDX_SPP_HEARTBEAT_CHAR] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, |
|
|
|
CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write_notify}}, |
|
|
|
[SPP_IDX_SPP_HEARTBEAT_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, |
|
|
|
(uint8_t *)&char_prop_read_write_notify}}, |
|
|
|
|
|
|
|
// SPP - Heart beat characteristic Value |
|
|
|
[SPP_IDX_SPP_HEARTBEAT_VAL] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&spp_heart_beat_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE, |
|
|
|
sizeof(spp_heart_beat_val), sizeof(spp_heart_beat_val), (uint8_t *)spp_heart_beat_val}}, |
|
|
|
[SPP_IDX_SPP_HEARTBEAT_VAL] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&spp_heart_beat_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, sizeof(spp_heart_beat_val), sizeof(spp_heart_beat_val), |
|
|
|
(uint8_t *)spp_heart_beat_val}}, |
|
|
|
|
|
|
|
// SPP - Heart beat characteristic - Client Characteristic Configuration Descriptor |
|
|
|
[SPP_IDX_SPP_HEARTBEAT_CFG] = |
|
|
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE, |
|
|
|
sizeof(uint16_t),sizeof(spp_data_notify_ccc), (uint8_t *)spp_heart_beat_ccc}}, |
|
|
|
[SPP_IDX_SPP_HEARTBEAT_CFG] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, sizeof(uint16_t), sizeof(spp_data_notify_ccc), |
|
|
|
(uint8_t *)spp_heart_beat_ccc}}, |
|
|
|
#endif |
|
|
|
}; |
|
|
|
|
|
|
|
static uint8_t find_char_and_desr_index(uint16_t handle) |
|
|
|
{ |
|
|
|
static uint8_t find_char_and_desr_index(uint16_t handle) { |
|
|
|
uint8_t error = 0xff; |
|
|
|
|
|
|
|
for (int i = 0; i < SPP_IDX_NB; i++) { |
|
|
@ -257,8 +247,7 @@ static uint8_t find_char_and_desr_index(uint16_t handle) |
|
|
|
return error; |
|
|
|
} |
|
|
|
|
|
|
|
static bool store_wr_buffer(esp_ble_gatts_cb_param_t *p_data) |
|
|
|
{ |
|
|
|
static bool store_wr_buffer(esp_ble_gatts_cb_param_t *p_data) { |
|
|
|
temp_spp_recv_data_node_p1 = (spp_receive_data_node_t *)malloc(sizeof(spp_receive_data_node_t)); |
|
|
|
|
|
|
|
if (temp_spp_recv_data_node_p1 == NULL) { |
|
|
@ -284,8 +273,7 @@ static bool store_wr_buffer(esp_ble_gatts_cb_param_t *p_data) |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
static void free_write_buffer(void) |
|
|
|
{ |
|
|
|
static void free_write_buffer(void) { |
|
|
|
temp_spp_recv_data_node_p1 = SppRecvDataBuff.first_node; |
|
|
|
|
|
|
|
while (temp_spp_recv_data_node_p1 != NULL) { |
|
|
@ -300,8 +288,7 @@ static void free_write_buffer(void) |
|
|
|
SppRecvDataBuff.first_node = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
static void print_write_buffer(void) |
|
|
|
{ |
|
|
|
static void print_write_buffer(void) { |
|
|
|
temp_spp_recv_data_node_p1 = SppRecvDataBuff.first_node; |
|
|
|
|
|
|
|
while (temp_spp_recv_data_node_p1 != NULL) { |
|
|
@ -310,8 +297,7 @@ static void print_write_buffer(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void uart_task(void *pvParameters) |
|
|
|
{ |
|
|
|
void uart_task(void *pvParameters) { |
|
|
|
uart_event_t event; |
|
|
|
uint8_t total_num = 0; |
|
|
|
uint8_t current_num = 0; |
|
|
@ -389,8 +375,7 @@ void uart_task(void *pvParameters) |
|
|
|
vTaskDelete(NULL); |
|
|
|
} |
|
|
|
|
|
|
|
static void spp_uart_init(void) |
|
|
|
{ |
|
|
|
static void spp_uart_init(void) { |
|
|
|
uart_config_t uart_config = { |
|
|
|
.baud_rate = 115200, |
|
|
|
.data_bits = UART_DATA_8_BITS, |
|
|
@ -411,8 +396,7 @@ static void spp_uart_init(void) |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef SUPPORT_HEARTBEAT |
|
|
|
void spp_heartbeat_task(void * arg) |
|
|
|
{ |
|
|
|
void spp_heartbeat_task(void *arg) { |
|
|
|
uint16_t cmd_id; |
|
|
|
|
|
|
|
for (;;) { |
|
|
@ -436,8 +420,7 @@ void spp_heartbeat_task(void * arg) |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
void spp_cmd_task(void * arg) |
|
|
|
{ |
|
|
|
void spp_cmd_task(void *arg) { |
|
|
|
uint8_t *cmd_id; |
|
|
|
|
|
|
|
for (;;) { |
|
|
@ -450,8 +433,7 @@ void spp_cmd_task(void * arg) |
|
|
|
vTaskDelete(NULL); |
|
|
|
} |
|
|
|
|
|
|
|
static void spp_task_init(void) |
|
|
|
{ |
|
|
|
static void spp_task_init(void) { |
|
|
|
spp_uart_init(); |
|
|
|
|
|
|
|
#ifdef SUPPORT_HEARTBEAT |
|
|
@ -463,8 +445,7 @@ static void spp_task_init(void) |
|
|
|
xTaskCreate(spp_cmd_task, "spp_cmd_task", 2048, NULL, 10, NULL); |
|
|
|
} |
|
|
|
|
|
|
|
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) |
|
|
|
{ |
|
|
|
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { |
|
|
|
esp_err_t err; |
|
|
|
ESP_LOGE(GATTS_TABLE_TAG, "GAP_EVT, event %d\n", event); |
|
|
|
|
|
|
@ -483,8 +464,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) |
|
|
|
{ |
|
|
|
static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) { |
|
|
|
esp_ble_gatts_cb_param_t *p_data = (esp_ble_gatts_cb_param_t *)param; |
|
|
|
uint8_t res = 0xff; |
|
|
|
|
|
|
@ -544,7 +524,11 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ |
|
|
|
#ifdef SPP_DEBUG_MODE |
|
|
|
esp_log_buffer_char(GATTS_TABLE_TAG, (char *)(p_data->write.value), p_data->write.len); |
|
|
|
#else |
|
|
|
uart_write_bytes(UART_NUM_0, (char *)(p_data->write.value), p_data->write.len); |
|
|
|
// uart_write_bytes(UART_NUM_0, (char *)(p_data->write.value), p_data->write.len); |
|
|
|
if (s_ble_uart_init_struct->receive_data_processing_flag == false) { |
|
|
|
s_cb(p_data->write.value, p_data->write.len); |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
} else { |
|
|
|
// TODO: |
|
|
@ -577,6 +561,9 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ |
|
|
|
case ESP_GATTS_STOP_EVT: |
|
|
|
break; |
|
|
|
case ESP_GATTS_CONNECT_EVT: |
|
|
|
table_conn_id_m = param->connect.conn_id; |
|
|
|
table_gatts_if_m = gatts_if; |
|
|
|
table_handle_m = spp_handle_table[SPP_IDX_SPP_DATA_NTY_VAL]; |
|
|
|
spp_conn_id = p_data->connect.conn_id; |
|
|
|
spp_gatts_if = gatts_if; |
|
|
|
is_connected = true; |
|
|
@ -587,6 +574,9 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ |
|
|
|
#endif |
|
|
|
break; |
|
|
|
case ESP_GATTS_DISCONNECT_EVT: |
|
|
|
table_conn_id_m = 0; |
|
|
|
table_gatts_if_m = 0; |
|
|
|
table_handle_m = 0; |
|
|
|
is_connected = false; |
|
|
|
enable_data_ntf = false; |
|
|
|
#ifdef SUPPORT_HEARTBEAT |
|
|
@ -609,11 +599,9 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ |
|
|
|
ESP_LOGI(GATTS_TABLE_TAG, "The number handle =%x\n", param->add_attr_tab.num_handle); |
|
|
|
if (param->add_attr_tab.status != ESP_GATT_OK) { |
|
|
|
ESP_LOGE(GATTS_TABLE_TAG, "Create attribute table failed, error code=0x%x", param->add_attr_tab.status); |
|
|
|
} |
|
|
|
else if (param->add_attr_tab.num_handle != SPP_IDX_NB){ |
|
|
|
} else if (param->add_attr_tab.num_handle != SPP_IDX_NB) { |
|
|
|
ESP_LOGE(GATTS_TABLE_TAG, "Create attribute table abnormally, num_handle (%d) doesn't equal to HRS_IDX_NB(%d)", param->add_attr_tab.num_handle, SPP_IDX_NB); |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
memcpy(spp_handle_table, param->add_attr_tab.handles, sizeof(spp_handle_table)); |
|
|
|
esp_ble_gatts_start_service(spp_handle_table[SPP_IDX_SVC]); |
|
|
|
} |
|
|
@ -624,9 +612,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) |
|
|
|
{ |
|
|
|
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) { |
|
|
|
ESP_LOGI(GATTS_TABLE_TAG, "EVT %d, gatts if %d\n", event, gatts_if); |
|
|
|
|
|
|
|
/* If event is register event, store the gatts_if for each profile */ |
|
|
@ -652,11 +638,14 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ |
|
|
|
} while (0); |
|
|
|
} |
|
|
|
|
|
|
|
void ble_spp_server_demo_app_main(void) |
|
|
|
{ |
|
|
|
void bleuart_reg_cb(blerxcb_t cb) { s_cb = cb; } |
|
|
|
|
|
|
|
void ble_spp_server_demo_app_main(bleuart_t *bleuart) { |
|
|
|
esp_err_t ret; |
|
|
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); |
|
|
|
|
|
|
|
s_ble_uart_init_struct = bleuart; |
|
|
|
|
|
|
|
// Initialize NVS |
|
|
|
ret = nvs_flash_init(); |
|
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { |
|
|
|