mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
Merge branch 'bugfix/btdm_modify_code_format_and_comments_v3.0' into 'release/v3.0'
Component/bt: modify code format and comments_v3.0 See merge request !1693
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* This file is for gatt server. It can send adv data, be connected by clent.
|
* This file is for gatt server. It can send adv data, be connected by client.
|
||||||
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server demo.
|
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server demo.
|
||||||
* Client demo will enable gatt_server's notify after connection. Then two devices will exchange
|
* Client demo will enable gatt_server's notify after connection. Then two devices will exchange
|
||||||
* data.
|
* data.
|
||||||
|
@@ -15,18 +15,21 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* This file is for gatt server. It can send adv data, be connected by client.
|
* This file is for gatt server. It can send adv data, be connected by client.
|
||||||
* It is a Heart Rate PROFILE demo defined by Bluetooth SIG.
|
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server_service_table demo.
|
||||||
|
* Client demo will enable gatt_server_service_table's notify after connection. Then two devices will exchange
|
||||||
|
* data.
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/task.h"
|
||||||
#include "esp_system.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "esp_log.h"
|
#include "esp_system.h"
|
||||||
#include "nvs_flash.h"
|
#include "esp_log.h"
|
||||||
#include "esp_bt.h"
|
#include "nvs_flash.h"
|
||||||
|
#include "esp_bt.h"
|
||||||
|
|
||||||
#include "esp_gap_ble_api.h"
|
#include "esp_gap_ble_api.h"
|
||||||
#include "esp_gatts_api.h"
|
#include "esp_gatts_api.h"
|
||||||
@@ -252,17 +255,17 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
|||||||
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||||
/* advertising start complete event to indicate advertising start successfully or failed */
|
/* advertising start complete event to indicate advertising start successfully or failed */
|
||||||
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "advertising start failed\n");
|
ESP_LOGE(GATTS_TABLE_TAG, "advertising start failed");
|
||||||
}else{
|
}else{
|
||||||
ESP_LOGI(GATTS_TABLE_TAG, "advertising start successfully\n");
|
ESP_LOGI(GATTS_TABLE_TAG, "advertising start successfully");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||||
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "Advertising stop failed\n");
|
ESP_LOGE(GATTS_TABLE_TAG, "advertising stop failed");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_LOGI(GATTS_TABLE_TAG, "Stop adv successfully\n");
|
ESP_LOGI(GATTS_TABLE_TAG, "stop adv successfully\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||||
@@ -287,7 +290,7 @@ void example_prepare_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t
|
|||||||
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
|
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
|
||||||
prepare_write_env->prepare_len = 0;
|
prepare_write_env->prepare_len = 0;
|
||||||
if (prepare_write_env->prepare_buf == NULL) {
|
if (prepare_write_env->prepare_buf == NULL) {
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "%s, Gatt_server prep no mem\n", __func__);
|
ESP_LOGE(GATTS_TABLE_TAG, "%s, gatt_server prep no mem", __func__);
|
||||||
status = ESP_GATT_NO_RESOURCES;
|
status = ESP_GATT_NO_RESOURCES;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -308,7 +311,7 @@ void example_prepare_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t
|
|||||||
memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len);
|
memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len);
|
||||||
esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, gatt_rsp);
|
esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, gatt_rsp);
|
||||||
if (response_err != ESP_OK){
|
if (response_err != ESP_OK){
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "Send response error\n");
|
ESP_LOGE(GATTS_TABLE_TAG, "send response error");
|
||||||
}
|
}
|
||||||
free(gatt_rsp);
|
free(gatt_rsp);
|
||||||
}else{
|
}else{
|
||||||
@@ -435,7 +438,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
|
|||||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONF_EVT, status = %d", param->conf.status);
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONF_EVT, status = %d", param->conf.status);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTS_START_EVT:
|
case ESP_GATTS_START_EVT:
|
||||||
ESP_LOGI(GATTS_TABLE_TAG, "SERVICE_START_EVT, status %d, service_handle %d\n", param->start.status, param->start.service_handle);
|
ESP_LOGI(GATTS_TABLE_TAG, "SERVICE_START_EVT, status %d, service_handle %d", param->start.status, param->start.service_handle);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTS_CONNECT_EVT:
|
case ESP_GATTS_CONNECT_EVT:
|
||||||
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT, conn_id = %d", param->connect.conn_id);
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT, conn_id = %d", param->connect.conn_id);
|
||||||
@@ -491,7 +494,7 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_
|
|||||||
if (param->reg.status == ESP_GATT_OK) {
|
if (param->reg.status == ESP_GATT_OK) {
|
||||||
heart_rate_profile_tab[PROFILE_APP_IDX].gatts_if = gatts_if;
|
heart_rate_profile_tab[PROFILE_APP_IDX].gatts_if = gatts_if;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(GATTS_TABLE_TAG, "reg app failed, app_id %04x, status %d\n",
|
ESP_LOGE(GATTS_TABLE_TAG, "reg app failed, app_id %04x, status %d",
|
||||||
param->reg.app_id,
|
param->reg.app_id,
|
||||||
param->reg.status);
|
param->reg.status);
|
||||||
return;
|
return;
|
||||||
@@ -527,25 +530,25 @@ void app_main()
|
|||||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||||
ret = esp_bt_controller_init(&bt_cfg);
|
ret = esp_bt_controller_init(&bt_cfg);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth\n", __func__);
|
|
||||||
ret = esp_bluedroid_init();
|
ret = esp_bluedroid_init();
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed\n", __func__);
|
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = esp_bluedroid_enable();
|
ret = esp_bluedroid_enable();
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed\n", __func__);
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,18 +557,22 @@ void app_main()
|
|||||||
ESP_LOGE(GATTS_TABLE_TAG, "gatts register error, error code = %x", ret);
|
ESP_LOGE(GATTS_TABLE_TAG, "gatts register error, error code = %x", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = esp_ble_gap_register_callback(gap_event_handler);
|
ret = esp_ble_gap_register_callback(gap_event_handler);
|
||||||
if (ret){
|
if (ret){
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "gap register error, error code = %x", ret);
|
ESP_LOGE(GATTS_TABLE_TAG, "gap register error, error code = %x", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = esp_ble_gatts_app_register(ESP_APP_ID);
|
ret = esp_ble_gatts_app_register(ESP_APP_ID);
|
||||||
if (ret){
|
if (ret){
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "gatts app register error, error code = %x", ret);
|
ESP_LOGE(GATTS_TABLE_TAG, "gatts app register error, error code = %x", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
|
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
|
||||||
if (local_mtu_ret){
|
if (local_mtu_ret){
|
||||||
ESP_LOGE(GATTS_TABLE_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
|
ESP_LOGE(GATTS_TABLE_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
///Attributes State Machine
|
/* Attributes State Machine */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
IDX_SVC,
|
IDX_SVC,
|
||||||
|
Reference in New Issue
Block a user