forked from espressif/esp-idf
component/bt: refactor spp client demo
- fix the bug that before free the db pointer, the db was set to NULL
This commit is contained in:
@@ -42,8 +42,6 @@
|
|||||||
#define BT_BD_ADDR_HEX(addr) addr[0],addr[1],addr[2],addr[3],addr[4],addr[5]
|
#define BT_BD_ADDR_HEX(addr) addr[0],addr[1],addr[2],addr[3],addr[4],addr[5]
|
||||||
#define ESP_GATT_SPP_SERVICE_UUID 0xABF0
|
#define ESP_GATT_SPP_SERVICE_UUID 0xABF0
|
||||||
#define SCAN_ALL_THE_TIME 0
|
#define SCAN_ALL_THE_TIME 0
|
||||||
//#define SUPPORT_HEARTBEAT
|
|
||||||
//#define DEBUG_MODE
|
|
||||||
|
|
||||||
struct gattc_profile_inst {
|
struct gattc_profile_inst {
|
||||||
esp_gattc_cb_t gattc_cb;
|
esp_gattc_cb_t gattc_cb;
|
||||||
@@ -135,7 +133,7 @@ static void notify_event_handler(esp_ble_gattc_cb_param_t * p_data)
|
|||||||
ESP_LOGI(GATTC_TAG,"+INDICATE:handle = %d,length = %d ", p_data->notify.handle, p_data->notify.value_len);
|
ESP_LOGI(GATTC_TAG,"+INDICATE:handle = %d,length = %d ", p_data->notify.handle, p_data->notify.value_len);
|
||||||
}
|
}
|
||||||
handle = p_data->notify.handle;
|
handle = p_data->notify.handle;
|
||||||
if(handle == ((db+SPP_IDX_SPP_DATA_NTY_VAL)->attribute_handle)){
|
if(handle == db[SPP_IDX_SPP_DATA_NTY_VAL].attribute_handle){
|
||||||
#ifdef SPP_DEBUG_MODE
|
#ifdef SPP_DEBUG_MODE
|
||||||
esp_log_buffer_char(GATTC_TAG, (char *)p_data->notify.value, p_data->notify.value_len);
|
esp_log_buffer_char(GATTC_TAG, (char *)p_data->notify.value, p_data->notify.value_len);
|
||||||
#else
|
#else
|
||||||
@@ -192,7 +190,6 @@ static void notify_event_handler(esp_ble_gattc_cb_param_t * p_data)
|
|||||||
|
|
||||||
static void free_gattc_srv_db(void)
|
static void free_gattc_srv_db(void)
|
||||||
{
|
{
|
||||||
db = NULL;
|
|
||||||
is_connect = false;
|
is_connect = false;
|
||||||
spp_gattc_if = 0xff;
|
spp_gattc_if = 0xff;
|
||||||
spp_conn_id = 0;
|
spp_conn_id = 0;
|
||||||
@@ -205,6 +202,7 @@ static void free_gattc_srv_db(void)
|
|||||||
notify_value_count = 0;
|
notify_value_count = 0;
|
||||||
if(db){
|
if(db){
|
||||||
free(db);
|
free(db);
|
||||||
|
db = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,11 +316,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
|||||||
esp_ble_gap_set_scan_params(&ble_scan_params);
|
esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_CONNECT_EVT:
|
case ESP_GATTC_CONNECT_EVT:
|
||||||
if(p_data->connect.status != ESP_GATT_OK){
|
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT: conn_id=%d, gatt_if = %d", spp_conn_id, gattc_if);
|
||||||
ESP_LOGE(GATTC_TAG, "connect fail, status = %d", p_data->connect.status);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT: conn_id=%d, gatt_if = %d, status =%d", spp_conn_id, gattc_if, p_data->connect.status);
|
|
||||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
|
||||||
esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
|
||||||
spp_gattc_if = gattc_if;
|
spp_gattc_if = gattc_if;
|
||||||
@@ -348,7 +342,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
|||||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||||
ESP_LOGI(GATTC_TAG,"Index = %d,status = %d,handle = %d\n",cmd, p_data->reg_for_notify.status, p_data->reg_for_notify.handle);
|
ESP_LOGI(GATTC_TAG,"Index = %d,status = %d,handle = %d\n",cmd, p_data->reg_for_notify.status, p_data->reg_for_notify.handle);
|
||||||
if(p_data->reg_for_notify.status != ESP_GATT_OK){
|
if(p_data->reg_for_notify.status != ESP_GATT_OK){
|
||||||
ESP_LOGE(GATTC_TAG, "ESP_GATTC_REG_FOR_NOTIFY_EVT, status = %d", p_data->connect.status);
|
ESP_LOGE(GATTC_TAG, "ESP_GATTC_REG_FOR_NOTIFY_EVT, status = %d", p_data->reg_for_notify.status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint16_t notify_en = 1;
|
uint16_t notify_en = 1;
|
||||||
@@ -609,6 +603,9 @@ static void spp_uart_init(void)
|
|||||||
void app_main()
|
void app_main()
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||||
|
|
||||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||||
|
|
||||||
nvs_flash_init();
|
nvs_flash_init();
|
||||||
|
Reference in New Issue
Block a user