ble gatts add
This commit is contained in:
parent
49877801f4
commit
03a6fc4c92
@ -1,4 +1,4 @@
|
|||||||
# idf_component_register(SRCS "uart_example.c" "main.c"
|
# idf_component_register(SRCS "ble_gatts_server.c" "uart_example.c" "main.c"
|
||||||
# "modbus-tcp.c"
|
# "modbus-tcp.c"
|
||||||
# "can_network.c"
|
# "can_network.c"
|
||||||
# "./stm32/ads1220.c"
|
# "./stm32/ads1220.c"
|
||||||
@ -35,7 +35,8 @@ set(SRCS
|
|||||||
"./stm32/ModbusM.c"
|
"./stm32/ModbusM.c"
|
||||||
"./stm32/uart0_modbus_slave.c"
|
"./stm32/uart0_modbus_slave.c"
|
||||||
"wifi_softap.c"
|
"wifi_softap.c"
|
||||||
"bt_server.c"
|
|
||||||
|
"ble_gatts_server.c"
|
||||||
#"C:\Espressif\frameworks\esp-idf-v4.4.5\components\bt\include"
|
#"C:\Espressif\frameworks\esp-idf-v4.4.5\components\bt\include"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
724
main/ble_gatts_server.c
Normal file
724
main/ble_gatts_server.c
Normal file
@ -0,0 +1,724 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* This demo showcases creating a GATT database using a predefined attribute table.
|
||||||
|
* It acts as a GATT server and can send adv data, be connected by client.
|
||||||
|
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server_service_table demo.
|
||||||
|
* Client demo will enable GATT server's notify after connection. The two devices will then exchange
|
||||||
|
* data.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/event_groups.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "esp_bt.h"
|
||||||
|
|
||||||
|
#include "esp_gap_ble_api.h"
|
||||||
|
#include "esp_gatts_api.h"
|
||||||
|
#include "esp_bt_main.h"
|
||||||
|
#include "ble_gatts_server.h"
|
||||||
|
#include "esp_gatt_common_api.h"
|
||||||
|
|
||||||
|
#include "stm32/config.h"
|
||||||
|
#include "stm32/ModbusS.h"
|
||||||
|
|
||||||
|
#define GATTS_TABLE_TAG "BLE_GATTS_SERVER"
|
||||||
|
|
||||||
|
#define PROFILE_NUM 1
|
||||||
|
#define PROFILE_APP_IDX 0
|
||||||
|
#define ESP_APP_ID 0x55
|
||||||
|
#define SAMPLE_DEVICE_NAME "ESP_GATTS_DEMO"
|
||||||
|
#define SVC_INST_ID 0
|
||||||
|
|
||||||
|
/* The max length of characteristic value. When the GATT client performs a write or prepare write operation,
|
||||||
|
* the data length must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX.
|
||||||
|
*/
|
||||||
|
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 500
|
||||||
|
#define PREPARE_BUF_MAX_SIZE 1024
|
||||||
|
#define CHAR_DECLARATION_SIZE (sizeof(uint8_t))
|
||||||
|
|
||||||
|
#define ADV_CONFIG_FLAG (1 << 0)
|
||||||
|
#define SCAN_RSP_CONFIG_FLAG (1 << 1)
|
||||||
|
|
||||||
|
static uint8_t adv_config_done = 0;
|
||||||
|
|
||||||
|
uint16_t ble_gatts_handle_table[IDX_NB];
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t *prepare_buf;
|
||||||
|
int prepare_len;
|
||||||
|
} prepare_type_env_t;
|
||||||
|
|
||||||
|
static prepare_type_env_t prepare_write_env;
|
||||||
|
|
||||||
|
#define CONFIG_SET_RAW_ADV_DATA
|
||||||
|
#ifdef CONFIG_SET_RAW_ADV_DATA
|
||||||
|
static uint8_t raw_adv_data[] = {
|
||||||
|
/* flags */
|
||||||
|
0x02, 0x01, 0x06,
|
||||||
|
/* tx power*/
|
||||||
|
0x02, 0x0a, 0xeb,
|
||||||
|
/* service uuid */
|
||||||
|
0x03, 0x03, 0xFF, 0x00,
|
||||||
|
/* device name */
|
||||||
|
0x0f, 0x09, 'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D','E', 'M', 'O'
|
||||||
|
};
|
||||||
|
static uint8_t raw_scan_rsp_data[] = {
|
||||||
|
/* flags */
|
||||||
|
0x02, 0x01, 0x06,
|
||||||
|
/* tx power */
|
||||||
|
0x02, 0x0a, 0xeb,
|
||||||
|
/* service uuid */
|
||||||
|
0x03, 0x03, 0xFF,0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
static uint8_t service_uuid[16] = {
|
||||||
|
/* LSB <--------------------------------------------------------------------------------> MSB */
|
||||||
|
//first uuid, 16bit, [12],[13] is the value
|
||||||
|
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The length of adv data must be less than 31 bytes */
|
||||||
|
static esp_ble_adv_data_t adv_data = {
|
||||||
|
.set_scan_rsp = false,
|
||||||
|
.include_name = true,
|
||||||
|
.include_txpower = true,
|
||||||
|
.min_interval = 0x0006, //slave connection min interval, Time = min_interval * 1.25 msec
|
||||||
|
.max_interval = 0x0010, //slave connection max interval, Time = max_interval * 1.25 msec
|
||||||
|
.appearance = 0x00,
|
||||||
|
.manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
|
||||||
|
.p_manufacturer_data = NULL, //test_manufacturer,
|
||||||
|
.service_data_len = 0,
|
||||||
|
.p_service_data = NULL,
|
||||||
|
.service_uuid_len = sizeof(service_uuid),
|
||||||
|
.p_service_uuid = service_uuid,
|
||||||
|
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
|
||||||
|
};
|
||||||
|
|
||||||
|
// scan response data
|
||||||
|
static esp_ble_adv_data_t scan_rsp_data = {
|
||||||
|
.set_scan_rsp = true,
|
||||||
|
.include_name = true,
|
||||||
|
.include_txpower = true,
|
||||||
|
.min_interval = 0x0006,
|
||||||
|
.max_interval = 0x0010,
|
||||||
|
.appearance = 0x00,
|
||||||
|
.manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
|
||||||
|
.p_manufacturer_data = NULL, //&test_manufacturer[0],
|
||||||
|
.service_data_len = 0,
|
||||||
|
.p_service_data = NULL,
|
||||||
|
.service_uuid_len = sizeof(service_uuid),
|
||||||
|
.p_service_uuid = service_uuid,
|
||||||
|
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
|
||||||
|
};
|
||||||
|
#endif /* CONFIG_SET_RAW_ADV_DATA */
|
||||||
|
|
||||||
|
static esp_ble_adv_params_t adv_params = {
|
||||||
|
.adv_int_min = 0x20,
|
||||||
|
.adv_int_max = 0x40,
|
||||||
|
.adv_type = ADV_TYPE_IND,
|
||||||
|
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
|
||||||
|
.channel_map = ADV_CHNL_ALL,
|
||||||
|
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gatts_profile_inst {
|
||||||
|
esp_gatts_cb_t gatts_cb;
|
||||||
|
uint16_t gatts_if;
|
||||||
|
uint16_t app_id;
|
||||||
|
uint16_t conn_id;
|
||||||
|
uint16_t service_handle;
|
||||||
|
esp_gatt_srvc_id_t service_id;
|
||||||
|
uint16_t char_handle;
|
||||||
|
esp_bt_uuid_t char_uuid;
|
||||||
|
esp_gatt_perm_t perm;
|
||||||
|
esp_gatt_char_prop_t property;
|
||||||
|
uint16_t descr_handle;
|
||||||
|
esp_bt_uuid_t descr_uuid;
|
||||||
|
};
|
||||||
|
|
||||||
|
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 ble_gatts_profile_tab[PROFILE_NUM] = {
|
||||||
|
[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 */
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Service */
|
||||||
|
static const uint16_t GATTS_SERVICE_UUID = 0x00FF;
|
||||||
|
static const uint16_t GATTS_DATA_READ_WRITE_UUID = 0xFF01;
|
||||||
|
static const uint16_t GATTS_DATA_NOTIFY_UUID = 0xFF02;
|
||||||
|
|
||||||
|
|
||||||
|
static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE;
|
||||||
|
static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE;
|
||||||
|
static const uint16_t character_client_config_uuid = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
|
||||||
|
static const uint8_t char_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
static const uint8_t char_prop_read_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
static const uint8_t data_read_write_value[4] = {0x00};
|
||||||
|
static const uint8_t data_read_write_ccc[2] = {0x00, 0x00};
|
||||||
|
static const uint8_t data_notify_val[4] = {0x00};
|
||||||
|
static const uint8_t data_notify_ccc[2] = {0x00, 0x00};
|
||||||
|
|
||||||
|
bool data_notify_enable = false; /* 是否允许数据上报 */
|
||||||
|
bool is_connected = false; /* 蓝牙是否连接 */
|
||||||
|
static uint16_t ble_gatts_conn_id = 0xffff;
|
||||||
|
static esp_gatt_if_t ble_gatts_if = 0xff;
|
||||||
|
|
||||||
|
/* Full Database Description - Used to add attributes into the database */
|
||||||
|
static const esp_gatts_attr_db_t gatt_db[IDX_NB] =
|
||||||
|
{
|
||||||
|
// Service Declaration
|
||||||
|
[IDX_SVC] =
|
||||||
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
|
||||||
|
sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID), (uint8_t *)&GATTS_SERVICE_UUID}},
|
||||||
|
|
||||||
|
/* Characteristic Declaration */
|
||||||
|
[IDX_DATA_READ_WRITE_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}},
|
||||||
|
|
||||||
|
/* Characteristic Value */
|
||||||
|
[IDX_DATA_READ_WRITE_VAL] =
|
||||||
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_DATA_READ_WRITE_UUID, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
|
||||||
|
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(data_read_write_value), (uint8_t *)data_read_write_value}},
|
||||||
|
|
||||||
|
/* Client Characteristic Configuration Descriptor */
|
||||||
|
[IDX_DATA_READ_WRITE_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(data_read_write_ccc), (uint8_t *)data_read_write_ccc}},
|
||||||
|
|
||||||
|
|
||||||
|
//SPP - data notify characteristic Declaration
|
||||||
|
[IDX_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
|
||||||
|
[IDX_DATA_NOTIFY_VAL] =
|
||||||
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_DATA_NOTIFY_UUID, ESP_GATT_PERM_READ,
|
||||||
|
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(data_notify_val), (uint8_t *)data_notify_val}},
|
||||||
|
|
||||||
|
//SPP - data notify characteristic - Client Characteristic Configuration Descriptor
|
||||||
|
[IDX_DATA_NOTIFY_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(data_notify_ccc), (uint8_t *)data_notify_ccc}},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
|
||||||
|
{
|
||||||
|
switch (event) {
|
||||||
|
#ifdef CONFIG_SET_RAW_ADV_DATA
|
||||||
|
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~ADV_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~SCAN_RSP_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~ADV_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~SCAN_RSP_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||||
|
/* advertising start complete event to indicate advertising start successfully or failed */
|
||||||
|
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "advertising start failed");
|
||||||
|
}else{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "advertising start successfully");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||||
|
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "Advertising stop failed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "Stop adv successfully\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
|
||||||
|
param->update_conn_params.status,
|
||||||
|
param->update_conn_params.min_int,
|
||||||
|
param->update_conn_params.max_int,
|
||||||
|
param->update_conn_params.conn_int,
|
||||||
|
param->update_conn_params.latency,
|
||||||
|
param->update_conn_params.timeout);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* [0]: 标识 F0--写多个modbus内存地址
|
||||||
|
* [2:1]: 起始地址
|
||||||
|
* [3]: 写的字节数 0-255
|
||||||
|
* ...: 数据内容
|
||||||
|
*/
|
||||||
|
void gatts_write_data_cb(uint8_t *data, uint32_t len, esp_ble_gatts_cb_param_t *param)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "gatts_write_data_cb");
|
||||||
|
|
||||||
|
if (len >= 4 && data[0] == 0xF0) /* 写gWordVar寄存器 */
|
||||||
|
{
|
||||||
|
uint16_t addr = data[1] + (data[2] << 8);
|
||||||
|
uint16_t addr_ = addr;
|
||||||
|
uint8_t cnt = data[3];
|
||||||
|
if (cnt > len - 4)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "write format is fault, cnt > len - 4");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "write addr:%d cnt:%d", addr, cnt);
|
||||||
|
uint8_t i;
|
||||||
|
for (i = 0 + 4; i < cnt + 4; i+=2) /* 发送的数据要求两字节对齐 */
|
||||||
|
{
|
||||||
|
gWordVar[addr++] = data[i] + (data[i + 1] << 8);
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "gwordvar[%d]:0x%x", addr-1, gWordVar[addr-1]);
|
||||||
|
}
|
||||||
|
/* 还应该调用 ModBusWordWriteHook 来处理这些写动作带来的影响 */
|
||||||
|
ModBusWordWriteHook(addr_, cnt);
|
||||||
|
}
|
||||||
|
else if (len >= 4 && data[0] == 0xF1) /* 读gWordVar,通过notify上报回去 */
|
||||||
|
{
|
||||||
|
uint16_t addr = data[1] + (data[2] << 8);
|
||||||
|
uint8_t cnt = data[3];
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "read addr:%d cnt:%d", addr, cnt);
|
||||||
|
uint8_t buf[500];
|
||||||
|
buf[0] = data[0];
|
||||||
|
buf[1] = data[1];
|
||||||
|
buf[2] = data[2];
|
||||||
|
buf[3] = data[3];
|
||||||
|
memcpy(buf + 4, (uint8_t *)(gWordVar + addr), cnt);
|
||||||
|
notify_data_fun(IDX_DATA_READ_WRITE_VAL, buf, cnt + 4);
|
||||||
|
}
|
||||||
|
else if (len == 1 && data[0] == 0xF2) /* 开启notify */
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "enable notify");
|
||||||
|
data_notify_enable = true;
|
||||||
|
}
|
||||||
|
else ESP_LOGI(GATTS_TABLE_TAG, "format err!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void example_prepare_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "prepare write, handle = %d, value len = %d", param->write.handle, param->write.len);
|
||||||
|
esp_gatt_status_t status = ESP_GATT_OK;
|
||||||
|
if (prepare_write_env->prepare_buf == NULL) {
|
||||||
|
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
|
||||||
|
prepare_write_env->prepare_len = 0;
|
||||||
|
if (prepare_write_env->prepare_buf == NULL) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s, Gatt_server prep no mem", __func__);
|
||||||
|
status = ESP_GATT_NO_RESOURCES;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
|
||||||
|
status = ESP_GATT_INVALID_OFFSET;
|
||||||
|
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
|
||||||
|
status = ESP_GATT_INVALID_ATTR_LEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*send response when param->write.need_rsp is true */
|
||||||
|
if (param->write.need_rsp){
|
||||||
|
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));
|
||||||
|
if (gatt_rsp != NULL){
|
||||||
|
gatt_rsp->attr_value.len = param->write.len;
|
||||||
|
gatt_rsp->attr_value.handle = param->write.handle;
|
||||||
|
gatt_rsp->attr_value.offset = param->write.offset;
|
||||||
|
gatt_rsp->attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE;
|
||||||
|
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);
|
||||||
|
if (response_err != ESP_OK){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "Send response error");
|
||||||
|
}
|
||||||
|
free(gatt_rsp);
|
||||||
|
}else{
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s, malloc failed", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (status != ESP_GATT_OK){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(prepare_write_env->prepare_buf + param->write.offset,
|
||||||
|
param->write.value,
|
||||||
|
param->write.len);
|
||||||
|
prepare_write_env->prepare_len += param->write.len;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param){
|
||||||
|
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC && prepare_write_env->prepare_buf){
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, prepare_write_env->prepare_buf, prepare_write_env->prepare_len);
|
||||||
|
gatts_write_data_cb(prepare_write_env->prepare_buf, prepare_write_env->prepare_len, param); /* 此处有隐患,有可能不是data_write特征的数据 */
|
||||||
|
}else{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG,"ESP_GATT_PREP_WRITE_CANCEL");
|
||||||
|
}
|
||||||
|
if (prepare_write_env->prepare_buf) {
|
||||||
|
free(prepare_write_env->prepare_buf);
|
||||||
|
prepare_write_env->prepare_buf = NULL;
|
||||||
|
}
|
||||||
|
prepare_write_env->prepare_len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
switch (event) {
|
||||||
|
case ESP_GATTS_REG_EVT:{
|
||||||
|
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||||
|
if (set_dev_name_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||||
|
}
|
||||||
|
#ifdef CONFIG_SET_RAW_ADV_DATA
|
||||||
|
esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
|
||||||
|
if (raw_adv_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config raw adv data failed, error code = %x ", raw_adv_ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= ADV_CONFIG_FLAG;
|
||||||
|
esp_err_t raw_scan_ret = esp_ble_gap_config_scan_rsp_data_raw(raw_scan_rsp_data, sizeof(raw_scan_rsp_data));
|
||||||
|
if (raw_scan_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config raw scan rsp data failed, error code = %x", raw_scan_ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= SCAN_RSP_CONFIG_FLAG;
|
||||||
|
#else
|
||||||
|
//config adv data
|
||||||
|
esp_err_t ret = esp_ble_gap_config_adv_data(&adv_data);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config adv data failed, error code = %x", ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= ADV_CONFIG_FLAG;
|
||||||
|
//config scan response data
|
||||||
|
ret = esp_ble_gap_config_adv_data(&scan_rsp_data);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config scan response data failed, error code = %x", ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= SCAN_RSP_CONFIG_FLAG;
|
||||||
|
#endif
|
||||||
|
esp_err_t create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_db, gatts_if, IDX_NB, SVC_INST_ID);
|
||||||
|
if (create_attr_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_READ_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_READ_EVT");
|
||||||
|
// esp_gatt_rsp_t rsp;
|
||||||
|
// memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
|
||||||
|
// rsp.attr_value.handle = param->read.handle;
|
||||||
|
// rsp.attr_value.len = 4;
|
||||||
|
// rsp.attr_value.value[0] = 0xde;
|
||||||
|
// rsp.attr_value.value[1] = 0xed;
|
||||||
|
// rsp.attr_value.value[2] = 0xbe;
|
||||||
|
// rsp.attr_value.value[3] = 0xef;
|
||||||
|
// esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
|
||||||
|
// ESP_GATT_OK, NULL);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_WRITE_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_WRITE_EVT, need_rsp=%d", param->write.need_rsp);
|
||||||
|
|
||||||
|
if (!param->write.is_prep){
|
||||||
|
// the data length of gattc write must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX.
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "GATT_WRITE_EVT, handle = %d, value len = %d, value :", param->write.handle, param->write.len);
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, param->write.value, param->write.len);
|
||||||
|
if (ble_gatts_handle_table[IDX_DATA_READ_WRITE_VAL] == param->write.handle)
|
||||||
|
gatts_write_data_cb(param->write.value, param->write.len, param);
|
||||||
|
if (ble_gatts_handle_table[IDX_DATA_NOTIFY_CFG] == param->write.handle && param->write.len == 2){
|
||||||
|
uint16_t descr_value = param->write.value[1]<<8 | param->write.value[0];
|
||||||
|
if (descr_value == 0x0001){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify enable");
|
||||||
|
data_notify_enable = true;
|
||||||
|
}//else if (descr_value == 0x0002){
|
||||||
|
// ESP_LOGI(GATTS_TABLE_TAG, "indicate enable");
|
||||||
|
// }
|
||||||
|
else if (descr_value == 0x0000){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify/indicate disable ");
|
||||||
|
data_notify_enable = false;
|
||||||
|
}else{
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "unknown descr value");
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, param->write.value, param->write.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/* send response when param->write.need_rsp is true*/
|
||||||
|
if (param->write.need_rsp){
|
||||||
|
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
/* handle prepare write */
|
||||||
|
example_prepare_write_event_env(gatts_if, &prepare_write_env, param);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_EXEC_WRITE_EVT:
|
||||||
|
// the length of gattc prepare write data must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX.
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_EXEC_WRITE_EVT");
|
||||||
|
example_exec_write_event_env(&prepare_write_env, param);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_MTU_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_MTU_EVT, MTU %d", param->mtu.mtu);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONF_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONF_EVT, status = %d, attr_handle %d", param->conf.status, param->conf.handle);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_START_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "SERVICE_START_EVT, status %d, service_handle %d", param->start.status, param->start.service_handle);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONNECT_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT, conn_id = %d", param->connect.conn_id);
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, param->connect.remote_bda, 6);
|
||||||
|
esp_ble_conn_update_params_t conn_params = {0};
|
||||||
|
memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
|
||||||
|
/* For the iOS system, please refer to Apple official documents about the BLE connection parameters restrictions. */
|
||||||
|
conn_params.latency = 0;
|
||||||
|
conn_params.max_int = 0x20; // max_int = 0x20*1.25ms = 40ms
|
||||||
|
conn_params.min_int = 0x10; // min_int = 0x10*1.25ms = 20ms
|
||||||
|
conn_params.timeout = 400; // timeout = 400*10ms = 4000ms
|
||||||
|
//start sent the update connection parameters to the peer device.
|
||||||
|
esp_ble_gap_update_conn_params(&conn_params);
|
||||||
|
is_connected = true;
|
||||||
|
ble_gatts_conn_id = param->connect.conn_id;
|
||||||
|
ble_gatts_if = gatts_if;
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_DISCONNECT_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_DISCONNECT_EVT, reason = 0x%x", param->disconnect.reason);
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
is_connected = false;
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CREAT_ATTR_TAB_EVT:{
|
||||||
|
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 != IDX_NB){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
|
||||||
|
doesn't equal to IDX_NB(%d)", param->add_attr_tab.num_handle, IDX_NB);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
|
||||||
|
memcpy(ble_gatts_handle_table, param->add_attr_tab.handles, sizeof(ble_gatts_handle_table));
|
||||||
|
esp_ble_gatts_start_service(ble_gatts_handle_table[IDX_SVC]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ESP_GATTS_STOP_EVT:
|
||||||
|
case ESP_GATTS_OPEN_EVT:
|
||||||
|
case ESP_GATTS_CANCEL_OPEN_EVT:
|
||||||
|
case ESP_GATTS_CLOSE_EVT:
|
||||||
|
case ESP_GATTS_LISTEN_EVT:
|
||||||
|
case ESP_GATTS_CONGEST_EVT:
|
||||||
|
case ESP_GATTS_UNREG_EVT:
|
||||||
|
case ESP_GATTS_DELETE_EVT:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
|
||||||
|
{
|
||||||
|
/* If event is register event, store the gatts_if for each profile */
|
||||||
|
if (event == ESP_GATTS_REG_EVT) {
|
||||||
|
if (param->reg.status == ESP_GATT_OK) {
|
||||||
|
ble_gatts_profile_tab[PROFILE_APP_IDX].gatts_if = gatts_if;
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "reg app failed, app_id %04x, status %d",
|
||||||
|
param->reg.app_id,
|
||||||
|
param->reg.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
int idx;
|
||||||
|
for (idx = 0; idx < PROFILE_NUM; idx++) {
|
||||||
|
/* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */
|
||||||
|
if (gatts_if == ESP_GATT_IF_NONE || gatts_if == ble_gatts_profile_tab[idx].gatts_if) {
|
||||||
|
if (ble_gatts_profile_tab[idx].gatts_cb) {
|
||||||
|
ble_gatts_profile_tab[idx].gatts_cb(event, gatts_if, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 上报长度过长,则分包,这里限制长度最大20,分包协议:
|
||||||
|
* [1:0] ‘#’, ‘#’,分包标识
|
||||||
|
* [2] 总包个数
|
||||||
|
* [3] 当前包号,从0开始
|
||||||
|
* ... 包数据
|
||||||
|
*/
|
||||||
|
static uint16_t gatts_mtu_size = 23;
|
||||||
|
void notify_data_fun(int id, uint8_t *data, uint32_t len)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify_data_fun:");
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, data, len);
|
||||||
|
if (len <= gatts_mtu_size - 3) /* 包数据可以一次完整发送 */
|
||||||
|
{
|
||||||
|
esp_ble_gatts_send_indicate(ble_gatts_if, ble_gatts_conn_id, ble_gatts_handle_table[id], len, data, false);
|
||||||
|
}
|
||||||
|
else /* 需要分包发送 */
|
||||||
|
{
|
||||||
|
int total_num = 0;
|
||||||
|
uint8_t buf[gatts_mtu_size - 3];
|
||||||
|
if ((len % (gatts_mtu_size - 7)) == 0)
|
||||||
|
total_num = len / (gatts_mtu_size - 7);
|
||||||
|
else
|
||||||
|
total_num = len / (gatts_mtu_size - 7) + 1;
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify packet has %d", total_num);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
buf[0] = '#';
|
||||||
|
buf[1] = '#';
|
||||||
|
buf[2] = total_num;
|
||||||
|
for (i = 0; i < total_num - 1; i++)
|
||||||
|
{
|
||||||
|
buf[3] = i;
|
||||||
|
memcpy(buf + 4, data + i * (gatts_mtu_size - 7), gatts_mtu_size - 7);
|
||||||
|
esp_ble_gatts_send_indicate(ble_gatts_if, ble_gatts_conn_id, ble_gatts_handle_table[IDX_DATA_NOTIFY_VAL],gatts_mtu_size - 3, buf, false);
|
||||||
|
}
|
||||||
|
/* 最后一个包 */
|
||||||
|
buf[3] = i;
|
||||||
|
memcpy(buf + 4, data + i * (gatts_mtu_size - 7), len % (gatts_mtu_size - 7));
|
||||||
|
esp_ble_gatts_send_indicate(ble_gatts_if, ble_gatts_conn_id, ble_gatts_handle_table[IDX_DATA_NOTIFY_VAL], (len % (gatts_mtu_size - 7)) + 4, buf, false);
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify packet send end!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern flow_t *pflow;
|
||||||
|
extern depth_t *depth_data;
|
||||||
|
void notify_all_data(void)
|
||||||
|
{
|
||||||
|
uint8_t buf[30];
|
||||||
|
|
||||||
|
buf[0] = 1; /* tag:1号通道流量:瞬时,每10cm,总 */
|
||||||
|
buf[1] = pflow[0].flow & 0xff;
|
||||||
|
buf[2] = (pflow[0].flow >> 8) & 0xff;
|
||||||
|
buf[3] = depth_data->depth_flow[0] & 0xff;
|
||||||
|
buf[4] = (depth_data->depth_flow[0] >> 8) & 0xff;
|
||||||
|
buf[5] = pflow[0].total_flow & 0xff;
|
||||||
|
buf[6] = (pflow[0].total_flow >> 8) & 0xff;
|
||||||
|
notify_data_fun(IDX_DATA_NOTIFY_VAL, buf, 7);
|
||||||
|
|
||||||
|
buf[0] = 2; /* tag:2号通道流量:瞬时,每10cm,总 */
|
||||||
|
buf[1] = pflow[1].flow & 0xff;
|
||||||
|
buf[2] = (pflow[1].flow >> 8) & 0xff;
|
||||||
|
buf[3] = depth_data->depth_flow[1] & 0xff;
|
||||||
|
buf[4] = (depth_data->depth_flow[1] >> 8) & 0xff;
|
||||||
|
buf[5] = pflow[1].total_flow & 0xff;
|
||||||
|
buf[6] = (pflow[1].total_flow >> 8) & 0xff;
|
||||||
|
notify_data_fun(IDX_DATA_NOTIFY_VAL, buf, 7);
|
||||||
|
|
||||||
|
buf[0] = 3; /* tag:深度:速度 深度 */
|
||||||
|
buf[1] = depth_data->speed & 0xff;
|
||||||
|
buf[2] = (depth_data->speed >> 8) & 0xff;
|
||||||
|
buf[3] = depth_data->depth & 0xff;
|
||||||
|
buf[4] = (depth_data->depth >> 8) & 0xff;
|
||||||
|
notify_data_fun(IDX_DATA_NOTIFY_VAL, buf, 5);
|
||||||
|
|
||||||
|
/* 需要上报什么数据在此处添加 */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void notify_task(void *pvParameters)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (data_notify_enable && is_connected)
|
||||||
|
{
|
||||||
|
notify_all_data();
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
}
|
||||||
|
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_gatts_server_init(void)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
ret = esp_bt_controller_init(&bt_cfg);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_bluedroid_init();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_bluedroid_enable();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_ble_gatts_register_callback(gatts_event_handler);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "gatts register error, error code = %x", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_ble_gap_register_callback(gap_event_handler);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "gap register error, error code = %x", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_ble_gatts_app_register(ESP_APP_ID);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "gatts app register error, error code = %x", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
|
||||||
|
if (local_mtu_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 创建任务用于定期的数据上报notify */
|
||||||
|
xTaskCreate(notify_task, "notify_Task", 4096, NULL, 8, NULL);
|
||||||
|
}
|
29
main/ble_gatts_server.h
Normal file
29
main/ble_gatts_server.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef __BLE_GATTS_SERVER_H
|
||||||
|
#define __BLE_GATTS_SERVER_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Attributes State Machine */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
IDX_SVC,
|
||||||
|
|
||||||
|
/* gWordVar data write */
|
||||||
|
IDX_DATA_READ_WRITE_CHAR,
|
||||||
|
IDX_DATA_READ_WRITE_VAL,
|
||||||
|
IDX_DATA_READ_WRITE_CFG,
|
||||||
|
|
||||||
|
/* gWordVar data notify */
|
||||||
|
IDX_DATA_NOTIFY_CHAR,
|
||||||
|
IDX_DATA_NOTIFY_VAL,
|
||||||
|
IDX_DATA_NOTIFY_CFG,
|
||||||
|
|
||||||
|
IDX_NB,
|
||||||
|
};
|
||||||
|
|
||||||
|
void ble_gatts_server_init(void);
|
||||||
|
void notify_data_fun(int id, uint8_t *data, uint32_t len);
|
||||||
|
|
||||||
|
#endif
|
38
main/main.c
38
main/main.c
@ -27,11 +27,14 @@
|
|||||||
#include "driver/mcpwm.h"
|
#include "driver/mcpwm.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
/*蓝牙相关的头文件*/
|
/*蓝牙相关的头文件*/
|
||||||
#include "esp_bt.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"
|
||||||
#include "esp_bt_defs.h"
|
// #include "esp_bt_defs.h"
|
||||||
#include "esp_bt_main.h"
|
// #include "esp_bt_main.h"
|
||||||
|
//#include "ble_server.h"
|
||||||
|
#include "stm32/config.h"
|
||||||
|
#include "ble_gatts_server.h"
|
||||||
|
|
||||||
|
|
||||||
/* The examples use WiFi configuration that you can set via project configuration menu
|
/* The examples use WiFi configuration that you can set via project configuration menu
|
||||||
@ -93,6 +96,11 @@ extern void bt_client_init(void);
|
|||||||
//extern void ESP32_Uart_Receive_Data(void);
|
//extern void ESP32_Uart_Receive_Data(void);
|
||||||
uint32_t rtc_clk_apb_freq;
|
uint32_t rtc_clk_apb_freq;
|
||||||
|
|
||||||
|
|
||||||
|
extern cal_4_20ma_t *cal_4_20ma;//电流数据结构体
|
||||||
|
extern flow_config_t *flow_config;//流量数据结构体
|
||||||
|
extern depth_config_t *depth_config;//深度数据结构体
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
// Initialize NVS
|
// Initialize NVS
|
||||||
@ -104,6 +112,7 @@ void app_main(void)
|
|||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
ESP_ERROR_CHECK(i2c_master_init());
|
ESP_ERROR_CHECK(i2c_master_init());
|
||||||
|
//restore_default();
|
||||||
config_load();//读取保存在FRAM里的数据
|
config_load();//读取保存在FRAM里的数据
|
||||||
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||||
// rtc_clk_apb_freq = rtc_clk_apb_freq_get();
|
// rtc_clk_apb_freq = rtc_clk_apb_freq_get();
|
||||||
@ -112,24 +121,29 @@ void app_main(void)
|
|||||||
wifi_init_softap();//ok
|
wifi_init_softap();//ok
|
||||||
// wifi_init_sta();
|
// wifi_init_sta();
|
||||||
// can_init();
|
// can_init();
|
||||||
|
// PWR_4G_Init();
|
||||||
PWR_4G_Init();
|
|
||||||
ModBusTCPSlave_init();
|
ModBusTCPSlave_init();
|
||||||
|
|
||||||
ads1220_task_start();
|
ads1220_task_start(); /* 两路电流AD采样获取瞬时流量,计算累计流量 */
|
||||||
BL0939_init();
|
BL0939_init(); /* 实时采集通道电流,根据depth_config_t中配置的启动与结束电流,以及持续时间进行move_t机器开关状态的判断 */
|
||||||
DEPTH_init();
|
DEPTH_init(); /* 编码器计算深度,同时进行流量的按深度计数,以及record的记录 */
|
||||||
FLOW_init();
|
FLOW_init(); /* 两一种计算流量的方法,计算累计流量 */
|
||||||
|
|
||||||
uart0_modbus_slave_init();
|
uart0_modbus_slave_init();
|
||||||
|
|
||||||
bt_client_init();//ok
|
// ble_server_init();
|
||||||
|
ble_gatts_server_init();
|
||||||
|
|
||||||
|
// bt_client_init();//ok
|
||||||
//ESP32_Uart_Receive_Data();
|
//ESP32_Uart_Receive_Data();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWR_4G_Init(void)
|
void PWR_4G_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "HELLO~");
|
||||||
|
save_cal_4_20ma();
|
||||||
// zero-initialize the config structure.
|
// zero-initialize the config structure.
|
||||||
gpio_config_t io_conf = {
|
gpio_config_t io_conf = {
|
||||||
// disable interrupt
|
// disable interrupt
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
static const char *TAG = "main";
|
||||||
|
|
||||||
|
|
||||||
static const uint8_t auchCRCHi[] =
|
static const uint8_t auchCRCHi[] =
|
||||||
@ -110,7 +113,7 @@ extern uint16_t last_pile_id;
|
|||||||
extern int zb_ModBusWordWriteHook(uint16_t addr, uint16_t length);
|
extern int zb_ModBusWordWriteHook(uint16_t addr, uint16_t length);
|
||||||
void ModBusWordWriteHook(uint16_t addr, uint16_t length)
|
void ModBusWordWriteHook(uint16_t addr, uint16_t length)
|
||||||
{
|
{
|
||||||
|
// ESP_LOGI(TAG, "ModBusWordWriteHook");
|
||||||
if(addr == RECORD_REG_ADDR && gWordVar[RECORD_REG_ADDR] == 0xffff){
|
if(addr == RECORD_REG_ADDR && gWordVar[RECORD_REG_ADDR] == 0xffff){
|
||||||
reset_depth();
|
reset_depth();
|
||||||
gWordVar[RECORD_REG_ADDR] = 0;
|
gWordVar[RECORD_REG_ADDR] = 0;
|
||||||
@ -127,13 +130,13 @@ void ModBusWordWriteHook(uint16_t addr, uint16_t length)
|
|||||||
if(addr == LAST_PILE_ID_ADDR){
|
if(addr == LAST_PILE_ID_ADDR){
|
||||||
last_pile_id = gWordVar[LAST_PILE_ID_ADDR];
|
last_pile_id = gWordVar[LAST_PILE_ID_ADDR];
|
||||||
}
|
}
|
||||||
else if(addr == FLOW_CONFIG_ADDR && gWordVar[FLOW_CONFIG_ADDR] == 0x55aa){
|
else if(addr >= FLOW_CONFIG_ADDR && addr < (FLOW_CONFIG_ADDR + sizeof(flow_config_t))/* && gWordVar[FLOW_CONFIG_ADDR] == 0x55aa */){
|
||||||
save_flow_cfg();
|
save_flow_cfg();
|
||||||
}
|
}
|
||||||
else if(addr == DEPTH_CONFIG_ADDR && gWordVar[DEPTH_CONFIG_ADDR] == 0x55aa){
|
else if(addr >= DEPTH_CONFIG_ADDR && addr < (DEPTH_CONFIG_ADDR + sizeof(depth_config_t))){
|
||||||
save_depth_cfg();
|
save_depth_cfg();
|
||||||
}
|
}
|
||||||
else if(addr == CAL_4_20MA_ADDR && gWordVar[CAL_4_20MA_ADDR] == 0x55aa){
|
else if(addr >= CAL_4_20MA_ADDR && addr < (CAL_4_20MA_ADDR + sizeof(cal_4_20ma_t))){
|
||||||
save_cal_4_20ma();
|
save_cal_4_20ma();
|
||||||
}
|
}
|
||||||
else if(addr == REBOOT_REW_ADDR ){
|
else if(addr == REBOOT_REW_ADDR ){
|
||||||
|
@ -40,6 +40,8 @@ extern void modbus_send(uint8_t *buf, uint8_t len);
|
|||||||
// extern void save_flow_cfg(void);
|
// extern void save_flow_cfg(void);
|
||||||
extern int check_mastrt_recv(void);
|
extern int check_mastrt_recv(void);
|
||||||
|
|
||||||
|
void ModBusWordWriteHook(uint16_t addr, uint16_t length);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,10 +398,10 @@ void ads1220_task(void)
|
|||||||
if (xQueueReceive(gpio_evt_queue, &io_num, 200))
|
if (xQueueReceive(gpio_evt_queue, &io_num, 200))
|
||||||
{
|
{
|
||||||
int ad_ch;
|
int ad_ch;
|
||||||
// ESP_LOGI(TAG, "xQueueReceive during\n ");
|
|
||||||
ads1220_watchdog = 0;
|
ads1220_watchdog = 0;
|
||||||
int ad_raw = ADS1220_ReadData();
|
int ad_raw = ADS1220_ReadData();
|
||||||
// ESP_LOGI(TAG, "ad_raw : %d\n ", ad_raw);
|
// if (ch == 3)
|
||||||
|
// ESP_LOGI(TAG, "ads1220 ch3 ad_rad:%d", (int)ad_raw);
|
||||||
ad_value[ch] = ad_raw / 128;
|
ad_value[ch] = ad_raw / 128;
|
||||||
ad_ch = ch;
|
ad_ch = ch;
|
||||||
gWordVar[AD_RAW_REG_ADDR + ch] = ad_value[ch] / 2;
|
gWordVar[AD_RAW_REG_ADDR + ch] = ad_value[ch] / 2;
|
||||||
@ -437,6 +437,7 @@ void ads1220_task(void)
|
|||||||
// 取出0.01L的整数部分累加,余数部分和下次值累加
|
// 取出0.01L的整数部分累加,余数部分和下次值累加
|
||||||
// t_flow = pflow[i].flow * 1000 * time_diff / 1000000 / 60;
|
// t_flow = pflow[i].flow * 1000 * time_diff / 1000000 / 60;
|
||||||
int time_diff_us = time_diff / (APB_CLK_FREQ / 1000000);
|
int time_diff_us = time_diff / (APB_CLK_FREQ / 1000000);
|
||||||
|
// if (ad_ch == 3) ESP_LOGI(TAG, "time_diff_us:%d", time_diff_us);
|
||||||
t_flow = pflow[flow_ch].flow * (long long)time_diff_us / 60 / 100; //(5 * 60);
|
t_flow = pflow[flow_ch].flow * (long long)time_diff_us / 60 / 100; //(5 * 60);
|
||||||
flow_rem[flow_ch] += t_flow;
|
flow_rem[flow_ch] += t_flow;
|
||||||
int sub_flow = flow_rem[flow_ch] / 10000;
|
int sub_flow = flow_rem[flow_ch] / 10000;
|
||||||
@ -444,7 +445,9 @@ void ads1220_task(void)
|
|||||||
flow_rem[flow_ch] = flow_rem[flow_ch] - sub_flow * 10000;
|
flow_rem[flow_ch] = flow_rem[flow_ch] - sub_flow * 10000;
|
||||||
pflow[flow_ch].update_time = ad_update_time[ad_ch];
|
pflow[flow_ch].update_time = ad_update_time[ad_ch];
|
||||||
timeout[flow_ch] = 0;
|
timeout[flow_ch] = 0;
|
||||||
|
//if (ad_ch == 3) ESP_LOGI(TAG, "flow:%d total_flow:%d", (int)pflow[flow_ch].flow, (int)pflow[flow_ch].total_flow);
|
||||||
// ESP_LOGI(TAG, "(type1) flow_rem[%d].flow: %u time_diff=%d", flow_ch ,pflow[flow_ch].flow,time_diff);
|
// ESP_LOGI(TAG, "(type1) flow_rem[%d].flow: %u time_diff=%d", flow_ch ,pflow[flow_ch].flow,time_diff);
|
||||||
|
// ESP_LOGI(TAG, "ads1220 ch:%d time_diff:%d flow:%d total_flow:%d", flow_ch, time_diff, pflow[flow_ch].flow, pflow[flow_ch].total_flow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -218,10 +218,11 @@ void BL0939_task()
|
|||||||
bl0939_Transfer_done = 1;
|
bl0939_Transfer_done = 1;
|
||||||
|
|
||||||
BL0939_SPI_TransmitReceive(bl0939_cmd, bl0939_rxbuf[index & 1], 36);
|
BL0939_SPI_TransmitReceive(bl0939_cmd, bl0939_rxbuf[index & 1], 36);
|
||||||
if (!memcmp(bl0939_rxbuf[0], bl0939_rxbuf[1], sizeof(bl0939_rxbuf[0])))
|
if (!memcmp(bl0939_rxbuf[0], bl0939_rxbuf[1], sizeof(bl0939_rxbuf[0]))) /* 数据没有变化不处理 */
|
||||||
{
|
{
|
||||||
index++;
|
index++;
|
||||||
bl0939_Transfer_done = 0;
|
bl0939_Transfer_done = 0;
|
||||||
|
// ESP_LOGI(TAG, "bl0939 data not change");
|
||||||
// continue;
|
// continue;
|
||||||
}
|
}
|
||||||
// ESP_LOGI(TAG, "BL0939_SPI_TransmitReceive after\n ");
|
// ESP_LOGI(TAG, "BL0939_SPI_TransmitReceive after\n ");
|
||||||
@ -235,14 +236,16 @@ void BL0939_task()
|
|||||||
if (check_sum_ch(bl0939_rxbuf[index & 1], 8 + ch * 12))
|
if (check_sum_ch(bl0939_rxbuf[index & 1], 8 + ch * 12))
|
||||||
{
|
{
|
||||||
ac_ad_values[ch] = readUint24BE(bl0939_rxbuf[index & 1], 8 + ch * 12);
|
ac_ad_values[ch] = readUint24BE(bl0939_rxbuf[index & 1], 8 + ch * 12);
|
||||||
// ESP_LOGI(TAG, "channel : %d ac_ad_values: %d\n ", ch, ac_ad_values[ch]);
|
// ESP_LOGI(TAG, "bl0939 channel:%d ac_ad_values:%d", ch, ac_ad_values[ch]);
|
||||||
gWordVar[AC_CURRENT_REG_ADDR + ch] = ac_ad_values[ch] * ac_current_coef[ch];
|
gWordVar[AC_CURRENT_REG_ADDR + ch] = ac_ad_values[ch] * ac_current_coef[ch];
|
||||||
|
// ESP_LOGI(TAG, "bl0939 channel:%d value:%d", ch, gWordVar[AC_CURRENT_REG_ADDR + ch]);
|
||||||
}
|
}
|
||||||
// ac_ad_values[ch] = readUint24BE(bl0939_rxbuf,8+ch*12);
|
// ac_ad_values[ch] = readUint24BE(bl0939_rxbuf,8+ch*12);
|
||||||
// ESP_LOGI(TAG, "channel : %d ac_ad_values: %d\n ", ch, ac_ad_values[ch]);
|
// ESP_LOGI(TAG, "channel : %d ac_ad_values: %d\n ", ch, ac_ad_values[ch]);
|
||||||
}
|
}
|
||||||
if (pMoveCtx->status == 0)
|
if (pMoveCtx->status == 0)
|
||||||
{ // 停止状态,等待启动
|
{ // 停止状态,等待启动
|
||||||
|
// ESP_LOGI(TAG, "mov status is off");
|
||||||
int move_current_channel = depth_config->move_current_channel;
|
int move_current_channel = depth_config->move_current_channel;
|
||||||
if (move_current_channel > 2 || move_current_channel < 0)
|
if (move_current_channel > 2 || move_current_channel < 0)
|
||||||
{
|
{
|
||||||
@ -255,11 +258,14 @@ void BL0939_task()
|
|||||||
pMoveCtx->status = 1;
|
pMoveCtx->status = 1;
|
||||||
pMoveCtx->time_count = 0;
|
pMoveCtx->time_count = 0;
|
||||||
pMoveCtx->pile_inc_req = 1;
|
pMoveCtx->pile_inc_req = 1;
|
||||||
|
|
||||||
|
// ESP_LOGI(TAG, "cur > th, status trun to on");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (pMoveCtx->status == 1)
|
else if (pMoveCtx->status == 1)
|
||||||
{
|
{
|
||||||
|
// ESP_LOGI(TAG, "mov status is on");
|
||||||
int move_current_channel = depth_config->move_current_channel;
|
int move_current_channel = depth_config->move_current_channel;
|
||||||
if (move_current_channel > 2 || move_current_channel < 0)
|
if (move_current_channel > 2 || move_current_channel < 0)
|
||||||
{
|
{
|
||||||
@ -271,6 +277,8 @@ void BL0939_task()
|
|||||||
{
|
{
|
||||||
pMoveCtx->status = 0;
|
pMoveCtx->status = 0;
|
||||||
pMoveCtx->time_count = 0;
|
pMoveCtx->time_count = 0;
|
||||||
|
|
||||||
|
// ESP_LOGI(TAG, "cur > th, status trun to off");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,12 +115,16 @@ void config_load(void)
|
|||||||
ESP_LOGI(TAG, "fram_read cal_4_20ma failed, use default value");
|
ESP_LOGI(TAG, "fram_read cal_4_20ma failed, use default value");
|
||||||
memcpy(cal_4_20ma, &default_cal_4_20ma, sizeof(default_cal_4_20ma));
|
memcpy(cal_4_20ma, &default_cal_4_20ma, sizeof(default_cal_4_20ma));
|
||||||
}
|
}
|
||||||
|
ESP_LOGW(TAG, "load cal_4_20ma:0x%x 0x%x 0x%x 0x%x 0x%x", (unsigned int)cal_4_20ma->magic, (unsigned int)cal_4_20ma->ch[0].ad_4ma, (unsigned int)cal_4_20ma->ch[0].ad_20ma, (unsigned int)cal_4_20ma->ch[1].ad_4ma, (unsigned int)cal_4_20ma->ch[1].ad_20ma);
|
||||||
|
|
||||||
|
|
||||||
fram_read(EE_FLOW_CFG_ADDR, flow_config, sizeof(default_flow_cfg));
|
fram_read(EE_FLOW_CFG_ADDR, flow_config, sizeof(default_flow_cfg));
|
||||||
if (flow_config->magic != MAGIC)
|
if (flow_config->magic != MAGIC)
|
||||||
{
|
{
|
||||||
ESP_LOGW(TAG, "fram_read flow_config failed, use default value");
|
ESP_LOGW(TAG, "fram_read flow_config failed, use default value");
|
||||||
memcpy(flow_config, &default_flow_cfg, sizeof(default_flow_cfg));
|
memcpy(flow_config, &default_flow_cfg, sizeof(default_flow_cfg));
|
||||||
}
|
}
|
||||||
|
ESP_LOGW(TAG, "load flow_cfg:0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", (unsigned int)flow_config->magic, (unsigned int)flow_config->input_type, (unsigned int)flow_config->min_flow[0], (unsigned int)flow_config->min_flow[1], (unsigned int)flow_config->ad_cal[0].flow_min, (unsigned int)flow_config->ad_cal[0].flow_max, (unsigned int)flow_config->ad_cal[1].flow_min, (unsigned int)flow_config->ad_cal[1].flow_max, (unsigned int)flow_config->pulse_coef[0], (unsigned int)flow_config->pulse_coef[1]);
|
||||||
|
|
||||||
fram_read(EE_DEPTH_CFG_ADDR, depth_config, sizeof(default_depth_cfg));
|
fram_read(EE_DEPTH_CFG_ADDR, depth_config, sizeof(default_depth_cfg));
|
||||||
if (depth_config->magic != MAGIC)
|
if (depth_config->magic != MAGIC)
|
||||||
@ -128,12 +132,20 @@ void config_load(void)
|
|||||||
ESP_LOGW(TAG, "fram_read depth_config failed, use default value");
|
ESP_LOGW(TAG, "fram_read depth_config failed, use default value");
|
||||||
memcpy(depth_config, &default_depth_cfg, sizeof(default_depth_cfg));
|
memcpy(depth_config, &default_depth_cfg, sizeof(default_depth_cfg));
|
||||||
}
|
}
|
||||||
fram_read(EE_DEPTH_CFG_ADDR, depth_config, sizeof(default_depth_cfg));
|
ESP_LOGW(TAG, "load depth_cfg: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", \
|
||||||
if (depth_config->magic != MAGIC)
|
(unsigned int)depth_config->magic, (unsigned int)depth_config->input_type, (unsigned int)depth_config->port, \
|
||||||
{
|
(unsigned int)depth_config->N, (unsigned int)depth_config->M, (unsigned int)depth_config->min_depth, (unsigned int)depth_config->max_depth, \
|
||||||
ESP_LOGW(TAG, "fram_read depth_config failed, use default value");
|
(unsigned int)depth_config->sample_depth, (unsigned int)depth_config->depth_offset, (unsigned int)depth_config->min_valid_depth, \
|
||||||
memcpy(depth_config, &default_depth_cfg, sizeof(default_depth_cfg));
|
(unsigned int)depth_config->inc_pile_depth, (unsigned int)depth_config->current_on_threshold, (unsigned int)depth_config->current_off_threshold, \
|
||||||
}
|
(unsigned int)depth_config->move_on_duratino, (unsigned int)depth_config->move_off_duration, (unsigned int)depth_config->move_current_channel);
|
||||||
|
|
||||||
|
|
||||||
|
// fram_read(EE_DEPTH_CFG_ADDR, depth_config, sizeof(default_depth_cfg));
|
||||||
|
// if (depth_config->magic != MAGIC)
|
||||||
|
// {
|
||||||
|
// ESP_LOGW(TAG, "fram_read depth_config failed, use default value");
|
||||||
|
// memcpy(depth_config, &default_depth_cfg, sizeof(default_depth_cfg));
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//恢复默认配置
|
//恢复默认配置
|
||||||
@ -149,18 +161,27 @@ void restore_default(void)
|
|||||||
|
|
||||||
void save_cal_4_20ma(void)
|
void save_cal_4_20ma(void)
|
||||||
{
|
{
|
||||||
|
uint16_t a = 1;
|
||||||
|
ESP_LOGW(TAG, "save_cal_4_20ma:0x%x 0x%x 0x%x 0x%x 0x%x", (unsigned int)cal_4_20ma->magic, (unsigned int)cal_4_20ma->ch[0].ad_4ma, (unsigned int)cal_4_20ma->ch[0].ad_20ma, (unsigned int)cal_4_20ma->ch[1].ad_4ma, (unsigned int)cal_4_20ma->ch[1].ad_20ma);
|
||||||
cal_4_20ma->magic = MAGIC;
|
cal_4_20ma->magic = MAGIC;
|
||||||
cal_4_20ma->magic = fram_write(EE_CAL_4_20MA_ADDR, cal_4_20ma, sizeof(default_cal_4_20ma));
|
cal_4_20ma->magic = fram_write(EE_CAL_4_20MA_ADDR, cal_4_20ma, sizeof(default_cal_4_20ma));
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_flow_cfg(void)
|
void save_flow_cfg(void)
|
||||||
{
|
{
|
||||||
|
ESP_LOGW(TAG, "save_flow_cfg:0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", (unsigned int)flow_config->magic, (unsigned int)flow_config->input_type, (unsigned int)flow_config->min_flow[0], (unsigned int)flow_config->min_flow[1], (unsigned int)flow_config->ad_cal[0].flow_min, (unsigned int)flow_config->ad_cal[0].flow_max, (unsigned int)flow_config->ad_cal[1].flow_min, (unsigned int)flow_config->ad_cal[1].flow_max, (unsigned int)flow_config->pulse_coef[0], (unsigned int)flow_config->pulse_coef[1]);
|
||||||
flow_config->magic = MAGIC;
|
flow_config->magic = MAGIC;
|
||||||
flow_config->magic = fram_write(EE_FLOW_CFG_ADDR, flow_config, sizeof(default_flow_cfg));
|
flow_config->magic = fram_write(EE_FLOW_CFG_ADDR, flow_config, sizeof(default_flow_cfg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_depth_cfg(void)
|
void save_depth_cfg(void)
|
||||||
{
|
{
|
||||||
|
ESP_LOGW(TAG, "save_depth_cfg: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", \
|
||||||
|
(unsigned int)depth_config->magic, (unsigned int)depth_config->input_type, (unsigned int)depth_config->port, \
|
||||||
|
(unsigned int)depth_config->N, (unsigned int)depth_config->M, (unsigned int)depth_config->min_depth, (unsigned int)depth_config->max_depth, \
|
||||||
|
(unsigned int)depth_config->sample_depth, (unsigned int)depth_config->depth_offset, (unsigned int)depth_config->min_valid_depth, \
|
||||||
|
(unsigned int)depth_config->inc_pile_depth, (unsigned int)depth_config->current_on_threshold, (unsigned int)depth_config->current_off_threshold, \
|
||||||
|
(unsigned int)depth_config->move_on_duratino, (unsigned int)depth_config->move_off_duration, (unsigned int)depth_config->move_current_channel);
|
||||||
depth_config->magic = MAGIC;
|
depth_config->magic = MAGIC;
|
||||||
depth_config->magic = fram_write(EE_DEPTH_CFG_ADDR, depth_config, sizeof(default_depth_cfg));
|
depth_config->magic = fram_write(EE_DEPTH_CFG_ADDR, depth_config, sizeof(default_depth_cfg));
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,24 @@ typedef struct
|
|||||||
uint16_t pile_inc_req;
|
uint16_t pile_inc_req;
|
||||||
} move_t;
|
} move_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t pile_work_state_and_direction; // 12
|
||||||
|
int16_t speed; // 13
|
||||||
|
int16_t depth; // 14
|
||||||
|
uint16_t sample_count; // 15
|
||||||
|
uint16_t depth_flow[2]; // 16~17
|
||||||
|
uint32_t last_total_flow[2]; //
|
||||||
|
int16_t depth_offset; // 22
|
||||||
|
uint16_t one_pile_work_time;//23 系统工作时间
|
||||||
|
// uint32_t update_time;
|
||||||
|
// int16_t tilt_x;
|
||||||
|
// int16_t tilt_y;
|
||||||
|
// uint16_t current1;
|
||||||
|
// uint16_t current2;
|
||||||
|
// uint16_t current3;
|
||||||
|
} depth_t;
|
||||||
|
|
||||||
|
|
||||||
extern depth_config_t *depth_config;
|
extern depth_config_t *depth_config;
|
||||||
|
|
||||||
|
@ -164,23 +164,23 @@ typedef struct
|
|||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
typedef struct
|
// typedef struct
|
||||||
{
|
// {
|
||||||
uint16_t pile_work_state_and_direction; // 12
|
// uint16_t pile_work_state_and_direction; // 12
|
||||||
int16_t speed; // 13
|
// int16_t speed; // 13
|
||||||
int16_t depth; // 14
|
// int16_t depth; // 14
|
||||||
uint16_t sample_count; // 15
|
// uint16_t sample_count; // 15
|
||||||
uint16_t depth_flow[2]; // 16~17
|
// uint16_t depth_flow[2]; // 16~17
|
||||||
uint32_t last_total_flow[2]; //
|
// uint32_t last_total_flow[2]; //
|
||||||
int16_t depth_offset; // 22
|
// int16_t depth_offset; // 22
|
||||||
uint16_t one_pile_work_time;//23 系统工作时间
|
// uint16_t one_pile_work_time;//23 系统工作时间
|
||||||
// uint32_t update_time;
|
// // uint32_t update_time;
|
||||||
// int16_t tilt_x;
|
// // int16_t tilt_x;
|
||||||
// int16_t tilt_y;
|
// // int16_t tilt_y;
|
||||||
// uint16_t current1;
|
// // uint16_t current1;
|
||||||
// uint16_t current2;
|
// // uint16_t current2;
|
||||||
// uint16_t current3;
|
// // uint16_t current3;
|
||||||
} depth_t;
|
// } depth_t;
|
||||||
|
|
||||||
record_t *record = (record_t *)&gWordVar[RECORD_REG_ADDR];
|
record_t *record = (record_t *)&gWordVar[RECORD_REG_ADDR];
|
||||||
depth_t *depth_data = (depth_t *)&gWordVar[DEPTH_REG_ADDR];
|
depth_t *depth_data = (depth_t *)&gWordVar[DEPTH_REG_ADDR];
|
||||||
@ -447,9 +447,9 @@ void depth_task(void *arg)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_enc1_update_time != enc1_update_time)
|
if (_enc1_update_time != enc1_update_time) /* 深度数据更新 */
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "_enc1_update_time != enc1_update_time\n");
|
// ESP_LOGI(TAG, "_enc1_update_time != enc1_update_time\n");
|
||||||
enc_update_time = enc1_update_time;
|
enc_update_time = enc1_update_time;
|
||||||
enc_value = enc1_value;
|
enc_value = enc1_value;
|
||||||
time_diff = abs_sub(enc_update_time, _enc1_update_time);
|
time_diff = abs_sub(enc_update_time, _enc1_update_time);
|
||||||
@ -458,20 +458,20 @@ void depth_task(void *arg)
|
|||||||
|
|
||||||
if (time_diff != 0)
|
if (time_diff != 0)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "time_diff = %d\n",time_diff);
|
// ESP_LOGI(TAG, "time_diff = %d\n",time_diff);
|
||||||
int16_t depth = enc_value * depth_config->N / depth_config->M; // 1mm
|
int16_t depth = enc_value * depth_config->N / depth_config->M; // 1mm
|
||||||
depth_data->depth = depth - depth_data->depth_offset;
|
depth_data->depth = depth - depth_data->depth_offset;
|
||||||
|
|
||||||
/*深度补偿修正*/
|
/*深度补偿修正*/
|
||||||
if (depth_data->depth > depth_config->max_depth)
|
if (depth_data->depth > depth_config->max_depth)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "depth_data->depth > depth_config->max_depth\n");
|
// ESP_LOGI(TAG, "depth_data->depth > depth_config->max_depth\n");
|
||||||
depth_data->depth_offset = depth - depth_config->max_depth;
|
depth_data->depth_offset = depth - depth_config->max_depth;
|
||||||
depth_data->depth = depth_config->max_depth;
|
depth_data->depth = depth_config->max_depth;
|
||||||
}
|
}
|
||||||
else if (depth_data->depth < depth_config->min_depth)
|
else if (depth_data->depth < depth_config->min_depth)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "depth_data->depth < depth_config->min_depth\n");
|
// ESP_LOGI(TAG, "depth_data->depth < depth_config->min_depth\n");
|
||||||
depth_data->depth_offset = depth - depth_config->min_depth;
|
depth_data->depth_offset = depth - depth_config->min_depth;
|
||||||
depth_data->depth = depth_config->min_depth;
|
depth_data->depth = depth_config->min_depth;
|
||||||
}
|
}
|
||||||
@ -479,21 +479,23 @@ void depth_task(void *arg)
|
|||||||
/*更新记录值*/
|
/*更新记录值*/
|
||||||
if (depth_data->depth > record->max_depth)
|
if (depth_data->depth > record->max_depth)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "depth_data->depth > record->max_depth\n");
|
// ESP_LOGI(TAG, "depth_data->depth > record->max_depth\n");
|
||||||
record->max_depth = depth_data->depth;
|
record->max_depth = depth_data->depth;
|
||||||
// send_to_bt1.max_depth = depth_data->depth;
|
// send_to_bt1.max_depth = depth_data->depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "depth_data->depth:0x%x", (unsigned int)depth_data->depth);
|
||||||
|
|
||||||
// 500ms计算一次速度
|
// 500ms计算一次速度
|
||||||
if (speed_calc_count++ > 50)
|
if (speed_calc_count++ > 50)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "speed_calc_count++ > 50\n");
|
// ESP_LOGI(TAG, "speed_calc_count++ > 50\n");
|
||||||
speed_calc_count = 0;
|
speed_calc_count = 0;
|
||||||
int speed_time_diff = abs_sub(enc_update_time, speed_enc_update_time);
|
int speed_time_diff = abs_sub(enc_update_time, speed_enc_update_time);
|
||||||
int time_diff_us = speed_time_diff / (APB_CLK_FREQ / 1000000);
|
int time_diff_us = speed_time_diff / (APB_CLK_FREQ / 1000000);
|
||||||
if (time_diff_us > 0 && time_diff_us < 5000000)
|
if (time_diff_us > 0 && time_diff_us < 5000000)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "time_diff_us:%d,dist_diff=%d", time_diff_us, enc_value - last_speed_enc_value);
|
// ESP_LOGI(TAG, "time_diff_us:%d,dist_diff=%d", time_diff_us, enc_value - last_speed_enc_value);
|
||||||
// speed = dist_diff / speed_time_diff speed 单位mm/min dist_diff 单位mm speed_time_diff 单位us
|
// speed = dist_diff / speed_time_diff speed 单位mm/min dist_diff 单位mm speed_time_diff 单位us
|
||||||
depth_data->speed = (enc_value - last_speed_enc_value) * depth_config->N / depth_config->M * 600000ll / time_diff_us;
|
depth_data->speed = (enc_value - last_speed_enc_value) * depth_config->N / depth_config->M * 600000ll / time_diff_us;
|
||||||
speed_timeout = 0;
|
speed_timeout = 0;
|
||||||
@ -515,7 +517,7 @@ void depth_task(void *arg)
|
|||||||
uint16_t pile_work_state = (depth_data->pile_work_state_and_direction & 0xff00);
|
uint16_t pile_work_state = (depth_data->pile_work_state_and_direction & 0xff00);
|
||||||
if (pile_work_state == PILE_STATE_WORK)
|
if (pile_work_state == PILE_STATE_WORK)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "pile_work_state == PILE_STATE_WORK\n");
|
// ESP_LOGI(TAG, "pile_work_state == PILE_STATE_WORK\n");
|
||||||
/*如果机器从停止状态->工作状态,则重新记录工作开始时间*/
|
/*如果机器从停止状态->工作状态,则重新记录工作开始时间*/
|
||||||
if(last_work_state == PILE_STATE_STOP){
|
if(last_work_state == PILE_STATE_STOP){
|
||||||
// work_start_time = esp_timer_get_time();
|
// work_start_time = esp_timer_get_time();
|
||||||
@ -526,10 +528,10 @@ void depth_task(void *arg)
|
|||||||
// depth_data->one_pile_work_time = (uint16_t)((current_work_time - work_start_time)/1000000);
|
// depth_data->one_pile_work_time = (uint16_t)((current_work_time - work_start_time)/1000000);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/*下钻,深度增加*/
|
/*下钻,深度增加 计算采样深度流量*/
|
||||||
if (enc_value > last_enc_value)
|
if (enc_value > last_enc_value)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "enc_value > last_enc_value\n");
|
// ESP_LOGI(TAG, "enc_value > last_enc_value\n");
|
||||||
uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff);
|
uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff);
|
||||||
if(pile_work_dir != PILE_DIR_DOWN)
|
if(pile_work_dir != PILE_DIR_DOWN)
|
||||||
{
|
{
|
||||||
@ -562,7 +564,7 @@ void depth_task(void *arg)
|
|||||||
{
|
{
|
||||||
flow = 0;
|
flow = 0;
|
||||||
}
|
}
|
||||||
depth_data->depth_flow[i] = flow;
|
depth_data->depth_flow[i] = flow; /* 采样深度对应的流量 */
|
||||||
depth_data->last_total_flow[i] = total_flow;
|
depth_data->last_total_flow[i] = total_flow;
|
||||||
}
|
}
|
||||||
depth_data->sample_count++;
|
depth_data->sample_count++;
|
||||||
@ -574,7 +576,7 @@ void depth_task(void *arg)
|
|||||||
/*上钻,深度减少*/
|
/*上钻,深度减少*/
|
||||||
else if (enc_value < last_enc_value)
|
else if (enc_value < last_enc_value)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "enc_value < last_enc_value\n");
|
// ESP_LOGI(TAG, "enc_value < last_enc_value\n");
|
||||||
uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff);
|
uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff);
|
||||||
if (pile_work_dir != PILE_DIR_UP)
|
if (pile_work_dir != PILE_DIR_UP)
|
||||||
{
|
{
|
||||||
@ -650,7 +652,7 @@ void depth_task(void *arg)
|
|||||||
last_enc_value = enc_value;
|
last_enc_value = enc_value;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ESP_LOGI(TAG, "time diff = 0\n");
|
// ESP_LOGI(TAG, "time diff = 0\n");
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ int fram_write(uint16_t addr, void * buf,uint32_t len)
|
|||||||
printf("esp_err : %s \n", esp_err_to_name(ret));
|
printf("esp_err : %s \n", esp_err_to_name(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
ESP_LOGI(TAG,"fram_write succeed\n");
|
||||||
i2c_cmd_link_delete(cmd);
|
i2c_cmd_link_delete(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
714
main/tmp/ble_gatts_server.c
Normal file
714
main/tmp/ble_gatts_server.c
Normal file
@ -0,0 +1,714 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* This demo showcases creating a GATT database using a predefined attribute table.
|
||||||
|
* It acts as a GATT server and can send adv data, be connected by client.
|
||||||
|
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server_service_table demo.
|
||||||
|
* Client demo will enable GATT server's notify after connection. The two devices will then exchange
|
||||||
|
* data.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/event_groups.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "esp_bt.h"
|
||||||
|
|
||||||
|
#include "esp_gap_ble_api.h"
|
||||||
|
#include "esp_gatts_api.h"
|
||||||
|
#include "esp_bt_main.h"
|
||||||
|
#include "ble_gatts_server.h"
|
||||||
|
#include "esp_gatt_common_api.h"
|
||||||
|
|
||||||
|
#include "stm32/config.h"
|
||||||
|
#include "stm32/ModbusS.h"
|
||||||
|
|
||||||
|
#define GATTS_TABLE_TAG "GATTS_TABLE_DEMO"
|
||||||
|
|
||||||
|
#define PROFILE_NUM 1
|
||||||
|
#define PROFILE_APP_IDX 0
|
||||||
|
#define ESP_APP_ID 0x55
|
||||||
|
#define SAMPLE_DEVICE_NAME "ESP_GATTS_DEMO"
|
||||||
|
#define SVC_INST_ID 0
|
||||||
|
|
||||||
|
/* The max length of characteristic value. When the GATT client performs a write or prepare write operation,
|
||||||
|
* the data length must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX.
|
||||||
|
*/
|
||||||
|
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 500
|
||||||
|
#define PREPARE_BUF_MAX_SIZE 1024
|
||||||
|
#define CHAR_DECLARATION_SIZE (sizeof(uint8_t))
|
||||||
|
|
||||||
|
#define ADV_CONFIG_FLAG (1 << 0)
|
||||||
|
#define SCAN_RSP_CONFIG_FLAG (1 << 1)
|
||||||
|
|
||||||
|
static uint8_t adv_config_done = 0;
|
||||||
|
|
||||||
|
uint16_t heart_rate_handle_table[HRS_IDX_NB];
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t *prepare_buf;
|
||||||
|
int prepare_len;
|
||||||
|
} prepare_type_env_t;
|
||||||
|
|
||||||
|
static prepare_type_env_t prepare_write_env;
|
||||||
|
|
||||||
|
#define CONFIG_SET_RAW_ADV_DATA
|
||||||
|
#ifdef CONFIG_SET_RAW_ADV_DATA
|
||||||
|
static uint8_t raw_adv_data[] = {
|
||||||
|
/* flags */
|
||||||
|
0x02, 0x01, 0x06,
|
||||||
|
/* tx power*/
|
||||||
|
0x02, 0x0a, 0xeb,
|
||||||
|
/* service uuid */
|
||||||
|
0x03, 0x03, 0xFF, 0x00,
|
||||||
|
/* device name */
|
||||||
|
0x0f, 0x09, 'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D','E', 'M', 'O'
|
||||||
|
};
|
||||||
|
static uint8_t raw_scan_rsp_data[] = {
|
||||||
|
/* flags */
|
||||||
|
0x02, 0x01, 0x06,
|
||||||
|
/* tx power */
|
||||||
|
0x02, 0x0a, 0xeb,
|
||||||
|
/* service uuid */
|
||||||
|
0x03, 0x03, 0xFF,0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
static uint8_t service_uuid[16] = {
|
||||||
|
/* LSB <--------------------------------------------------------------------------------> MSB */
|
||||||
|
//first uuid, 16bit, [12],[13] is the value
|
||||||
|
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The length of adv data must be less than 31 bytes */
|
||||||
|
static esp_ble_adv_data_t adv_data = {
|
||||||
|
.set_scan_rsp = false,
|
||||||
|
.include_name = true,
|
||||||
|
.include_txpower = true,
|
||||||
|
.min_interval = 0x0006, //slave connection min interval, Time = min_interval * 1.25 msec
|
||||||
|
.max_interval = 0x0010, //slave connection max interval, Time = max_interval * 1.25 msec
|
||||||
|
.appearance = 0x00,
|
||||||
|
.manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
|
||||||
|
.p_manufacturer_data = NULL, //test_manufacturer,
|
||||||
|
.service_data_len = 0,
|
||||||
|
.p_service_data = NULL,
|
||||||
|
.service_uuid_len = sizeof(service_uuid),
|
||||||
|
.p_service_uuid = service_uuid,
|
||||||
|
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
|
||||||
|
};
|
||||||
|
|
||||||
|
// scan response data
|
||||||
|
static esp_ble_adv_data_t scan_rsp_data = {
|
||||||
|
.set_scan_rsp = true,
|
||||||
|
.include_name = true,
|
||||||
|
.include_txpower = true,
|
||||||
|
.min_interval = 0x0006,
|
||||||
|
.max_interval = 0x0010,
|
||||||
|
.appearance = 0x00,
|
||||||
|
.manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
|
||||||
|
.p_manufacturer_data = NULL, //&test_manufacturer[0],
|
||||||
|
.service_data_len = 0,
|
||||||
|
.p_service_data = NULL,
|
||||||
|
.service_uuid_len = sizeof(service_uuid),
|
||||||
|
.p_service_uuid = service_uuid,
|
||||||
|
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
|
||||||
|
};
|
||||||
|
#endif /* CONFIG_SET_RAW_ADV_DATA */
|
||||||
|
|
||||||
|
static esp_ble_adv_params_t adv_params = {
|
||||||
|
.adv_int_min = 0x20,
|
||||||
|
.adv_int_max = 0x40,
|
||||||
|
.adv_type = ADV_TYPE_IND,
|
||||||
|
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
|
||||||
|
.channel_map = ADV_CHNL_ALL,
|
||||||
|
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gatts_profile_inst {
|
||||||
|
esp_gatts_cb_t gatts_cb;
|
||||||
|
uint16_t gatts_if;
|
||||||
|
uint16_t app_id;
|
||||||
|
uint16_t conn_id;
|
||||||
|
uint16_t service_handle;
|
||||||
|
esp_gatt_srvc_id_t service_id;
|
||||||
|
uint16_t char_handle;
|
||||||
|
esp_bt_uuid_t char_uuid;
|
||||||
|
esp_gatt_perm_t perm;
|
||||||
|
esp_gatt_char_prop_t property;
|
||||||
|
uint16_t descr_handle;
|
||||||
|
esp_bt_uuid_t descr_uuid;
|
||||||
|
};
|
||||||
|
|
||||||
|
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 heart_rate_profile_tab[PROFILE_NUM] = {
|
||||||
|
[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 */
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Service */
|
||||||
|
static const uint16_t GATTS_SERVICE_UUID_TEST = 0x00FF;
|
||||||
|
static const uint16_t GATTS_CHAR_UUID_TEST_A = 0xFF01;
|
||||||
|
static const uint16_t ESP_GATT_UUID_SPP_DATA_NOTIFY = 0xFF02;
|
||||||
|
|
||||||
|
|
||||||
|
static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE;
|
||||||
|
static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE;
|
||||||
|
static const uint16_t character_client_config_uuid = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
|
||||||
|
static const uint8_t char_prop_read_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
static const uint8_t char_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
static const uint8_t heart_measurement_ccc[2] = {0x00, 0x00};
|
||||||
|
static const uint8_t char_value[4] = {0x11, 0x22, 0x33, 0x44};
|
||||||
|
|
||||||
|
///SPP Service - data notify characteristic, notify&read
|
||||||
|
static const uint16_t spp_data_notify_uuid = ESP_GATT_UUID_SPP_DATA_NOTIFY;
|
||||||
|
static const uint8_t spp_data_notify_val[20] = {0x00};
|
||||||
|
static const uint8_t spp_data_notify_ccc[2] = {0x00, 0x00};
|
||||||
|
|
||||||
|
bool data_notify_enable = false; /* 是否允许数据上报 */
|
||||||
|
bool is_connected = false; /* 蓝牙是否连接 */
|
||||||
|
static uint16_t spp_conn_id = 0xffff;
|
||||||
|
static esp_gatt_if_t spp_gatts_if = 0xff;
|
||||||
|
|
||||||
|
/* Full Database Description - Used to add attributes into the database */
|
||||||
|
static const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
|
||||||
|
{
|
||||||
|
// Service Declaration
|
||||||
|
[IDX_SVC] =
|
||||||
|
{{ESP_GATT_RSP_BY_APP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
|
||||||
|
sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_TEST), (uint8_t *)&GATTS_SERVICE_UUID_TEST}},
|
||||||
|
|
||||||
|
/* Characteristic Declaration */
|
||||||
|
[IDX_CHAR_A] =
|
||||||
|
{{ESP_GATT_RSP_BY_APP}, {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}},
|
||||||
|
|
||||||
|
/* Characteristic Value */
|
||||||
|
[IDX_CHAR_VAL_A] =
|
||||||
|
{{ESP_GATT_RSP_BY_APP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_A, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
|
||||||
|
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
|
||||||
|
|
||||||
|
/* Client Characteristic Configuration Descriptor */
|
||||||
|
[IDX_CHAR_CFG_A] =
|
||||||
|
{{ESP_GATT_RSP_BY_APP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
|
||||||
|
sizeof(uint16_t), sizeof(heart_measurement_ccc), (uint8_t *)heart_measurement_ccc}},
|
||||||
|
|
||||||
|
|
||||||
|
//SPP - data notify characteristic Declaration
|
||||||
|
[SPP_IDX_SPP_DATA_NOTIFY_CHAR] =
|
||||||
|
{{ESP_GATT_RSP_BY_APP}, {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_RSP_BY_APP}, {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_RSP_BY_APP}, {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}},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
|
||||||
|
{
|
||||||
|
switch (event) {
|
||||||
|
#ifdef CONFIG_SET_RAW_ADV_DATA
|
||||||
|
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~ADV_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~SCAN_RSP_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~ADV_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT:
|
||||||
|
adv_config_done &= (~SCAN_RSP_CONFIG_FLAG);
|
||||||
|
if (adv_config_done == 0){
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||||
|
/* advertising start complete event to indicate advertising start successfully or failed */
|
||||||
|
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "advertising start failed");
|
||||||
|
}else{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "advertising start successfully");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||||
|
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "Advertising stop failed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "Stop adv successfully\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
|
||||||
|
param->update_conn_params.status,
|
||||||
|
param->update_conn_params.min_int,
|
||||||
|
param->update_conn_params.max_int,
|
||||||
|
param->update_conn_params.conn_int,
|
||||||
|
param->update_conn_params.latency,
|
||||||
|
param->update_conn_params.timeout);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void notify_data_fun(int id, uint8_t *data, uint32_t len);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* [0]: 标识 F0--写多个modbus内存地址
|
||||||
|
* [2:1]: 起始地址
|
||||||
|
* [3]: 写的字节数 0-255
|
||||||
|
* ...: 数据内容
|
||||||
|
*/
|
||||||
|
void gatts_write_data_cb(uint8_t *data, uint32_t len, esp_ble_gatts_cb_param_t *param)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "gatts_write_data_cb");
|
||||||
|
if (len < 4) {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "write format is fault, len less 4");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (data[0] == 0xF0) /* 写gWordVar寄存器 */
|
||||||
|
{
|
||||||
|
uint16_t addr = data[1] + (data[2] << 8);
|
||||||
|
uint16_t addr_ = addr;
|
||||||
|
uint8_t cnt = data[3];
|
||||||
|
if (cnt > len - 4)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "write format is fault, cnt > len - 4");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "write addr:%d cnt:%d", addr, cnt);
|
||||||
|
uint8_t i;
|
||||||
|
for (i = 0 + 4; i < cnt + 4; i+=2) /* 发送的数据要求两字节对齐 */
|
||||||
|
{
|
||||||
|
gWordVar[addr++] = data[i] + (data[i + 1] << 8);
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "gwordvar[%d]:0x%x", addr-1, gWordVar[addr-1]);
|
||||||
|
}
|
||||||
|
/* 还应该调用 ModBusWordWriteHook 来处理这些写动作带来的影响 */
|
||||||
|
ModBusWordWriteHook(addr, cnt);
|
||||||
|
}
|
||||||
|
else if (data[0] == 0xF1) /* 读gWordVar,通过notify上报回去 */
|
||||||
|
{
|
||||||
|
uint16_t addr = data[1] + (data[2] << 8);
|
||||||
|
uint8_t cnt = data[3];
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "!read addr:%d cnt:%d", addr, cnt);
|
||||||
|
uint8_t buf[500];
|
||||||
|
buf[0] = data[0];
|
||||||
|
buf[1] = data[1];
|
||||||
|
buf[2] = data[2];
|
||||||
|
buf[3] = data[3];
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "gWordVar[0]:0x%x gWordVar[1]:0x%x", gWordVar[0], gWordVar[1]);
|
||||||
|
memcpy(buf + 4, (uint8_t *)(gWordVar + addr), cnt);
|
||||||
|
notify_data_fun(IDX_CHAR_VAL_A, buf, cnt + 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void example_prepare_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "prepare write, handle = %d, value len = %d", param->write.handle, param->write.len);
|
||||||
|
esp_gatt_status_t status = ESP_GATT_OK;
|
||||||
|
if (prepare_write_env->prepare_buf == NULL) {
|
||||||
|
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
|
||||||
|
prepare_write_env->prepare_len = 0;
|
||||||
|
if (prepare_write_env->prepare_buf == NULL) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s, Gatt_server prep no mem", __func__);
|
||||||
|
status = ESP_GATT_NO_RESOURCES;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
|
||||||
|
status = ESP_GATT_INVALID_OFFSET;
|
||||||
|
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
|
||||||
|
status = ESP_GATT_INVALID_ATTR_LEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*send response when param->write.need_rsp is true */
|
||||||
|
// if (param->write.need_rsp){
|
||||||
|
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));
|
||||||
|
if (gatt_rsp != NULL){
|
||||||
|
gatt_rsp->attr_value.len = param->write.len;
|
||||||
|
gatt_rsp->attr_value.handle = param->write.handle;
|
||||||
|
gatt_rsp->attr_value.offset = param->write.offset;
|
||||||
|
gatt_rsp->attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE;
|
||||||
|
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);
|
||||||
|
if (response_err != ESP_OK){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "Send response error");
|
||||||
|
}
|
||||||
|
free(gatt_rsp);
|
||||||
|
}else{
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s, malloc failed", __func__);
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
if (status != ESP_GATT_OK){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(prepare_write_env->prepare_buf + param->write.offset,
|
||||||
|
param->write.value,
|
||||||
|
param->write.len);
|
||||||
|
prepare_write_env->prepare_len += param->write.len;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param){
|
||||||
|
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC && prepare_write_env->prepare_buf){
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, prepare_write_env->prepare_buf, prepare_write_env->prepare_len);
|
||||||
|
gatts_write_data_cb(prepare_write_env->prepare_buf, prepare_write_env->prepare_len, param); /* 此处有隐患,有可能不是data_write特征的数据 */
|
||||||
|
}else{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG,"ESP_GATT_PREP_WRITE_CANCEL");
|
||||||
|
}
|
||||||
|
if (prepare_write_env->prepare_buf) {
|
||||||
|
free(prepare_write_env->prepare_buf);
|
||||||
|
prepare_write_env->prepare_buf = NULL;
|
||||||
|
}
|
||||||
|
prepare_write_env->prepare_len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
switch (event) {
|
||||||
|
case ESP_GATTS_REG_EVT:{
|
||||||
|
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||||
|
if (set_dev_name_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||||
|
}
|
||||||
|
#ifdef CONFIG_SET_RAW_ADV_DATA
|
||||||
|
esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
|
||||||
|
if (raw_adv_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config raw adv data failed, error code = %x ", raw_adv_ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= ADV_CONFIG_FLAG;
|
||||||
|
esp_err_t raw_scan_ret = esp_ble_gap_config_scan_rsp_data_raw(raw_scan_rsp_data, sizeof(raw_scan_rsp_data));
|
||||||
|
if (raw_scan_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config raw scan rsp data failed, error code = %x", raw_scan_ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= SCAN_RSP_CONFIG_FLAG;
|
||||||
|
#else
|
||||||
|
//config adv data
|
||||||
|
esp_err_t ret = esp_ble_gap_config_adv_data(&adv_data);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config adv data failed, error code = %x", ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= ADV_CONFIG_FLAG;
|
||||||
|
//config scan response data
|
||||||
|
ret = esp_ble_gap_config_adv_data(&scan_rsp_data);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "config scan response data failed, error code = %x", ret);
|
||||||
|
}
|
||||||
|
adv_config_done |= SCAN_RSP_CONFIG_FLAG;
|
||||||
|
#endif
|
||||||
|
esp_err_t create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_db, gatts_if, HRS_IDX_NB, SVC_INST_ID);
|
||||||
|
if (create_attr_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_READ_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_READ_EVT");
|
||||||
|
// esp_gatt_rsp_t rsp;
|
||||||
|
// memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
|
||||||
|
// rsp.attr_value.handle = param->read.handle;
|
||||||
|
// rsp.attr_value.len = 4;
|
||||||
|
// rsp.attr_value.value[0] = 0xde;
|
||||||
|
// rsp.attr_value.value[1] = 0xed;
|
||||||
|
// rsp.attr_value.value[2] = 0xbe;
|
||||||
|
// rsp.attr_value.value[3] = 0xef;
|
||||||
|
// esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
|
||||||
|
// ESP_GATT_OK, &rsp);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_WRITE_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_WRITE_EVT, need_rsp=%d", param->write.need_rsp);
|
||||||
|
|
||||||
|
if (!param->write.is_prep){
|
||||||
|
// the data length of gattc write must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX.
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "GATT_WRITE_EVT, handle = %d, value len = %d, value :", param->write.handle, param->write.len);
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, param->write.value, param->write.len);
|
||||||
|
if (heart_rate_handle_table[IDX_CHAR_VAL_A] == param->write.handle)
|
||||||
|
gatts_write_data_cb(param->write.value, param->write.len, param);
|
||||||
|
if (heart_rate_handle_table[SPP_IDX_SPP_DATA_NTF_CFG] == param->write.handle && param->write.len == 2){
|
||||||
|
uint16_t descr_value = param->write.value[1]<<8 | param->write.value[0];
|
||||||
|
if (descr_value == 0x0001){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify enable");
|
||||||
|
data_notify_enable = true;
|
||||||
|
// uint8_t notify_data[15];
|
||||||
|
// for (int i = 0; i < sizeof(notify_data); ++i)
|
||||||
|
// {
|
||||||
|
// notify_data[i] = i % 0xff;
|
||||||
|
// }
|
||||||
|
// //the size of notify_data[] need less than MTU size
|
||||||
|
// esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, heart_rate_handle_table[IDX_CHAR_VAL_A],
|
||||||
|
// sizeof(notify_data), notify_data, false);
|
||||||
|
}//else if (descr_value == 0x0002){
|
||||||
|
// ESP_LOGI(GATTS_TABLE_TAG, "indicate enable");
|
||||||
|
// uint8_t indicate_data[15];
|
||||||
|
// for (int i = 0; i < sizeof(indicate_data); ++i)
|
||||||
|
// {
|
||||||
|
// indicate_data[i] = i % 0xff;
|
||||||
|
// }
|
||||||
|
// //the size of indicate_data[] need less than MTU size
|
||||||
|
// esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, heart_rate_handle_table[IDX_CHAR_VAL_A],
|
||||||
|
// sizeof(indicate_data), indicate_data, true);
|
||||||
|
// }
|
||||||
|
else if (descr_value == 0x0000){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify/indicate disable ");
|
||||||
|
data_notify_enable = false;
|
||||||
|
}else{
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "unknown descr value");
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, param->write.value, param->write.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/* send response when param->write.need_rsp is true*/
|
||||||
|
if (param->write.need_rsp){
|
||||||
|
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
/* handle prepare write */
|
||||||
|
example_prepare_write_event_env(gatts_if, &prepare_write_env, param);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_EXEC_WRITE_EVT:
|
||||||
|
// the length of gattc prepare write data must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX.
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_EXEC_WRITE_EVT");
|
||||||
|
example_exec_write_event_env(&prepare_write_env, param);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_MTU_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_MTU_EVT, MTU %d", param->mtu.mtu);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONF_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONF_EVT, status = %d, attr_handle %d", param->conf.status, param->conf.handle);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_START_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "SERVICE_START_EVT, status %d, service_handle %d", param->start.status, param->start.service_handle);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONNECT_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT, conn_id = %d", param->connect.conn_id);
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, param->connect.remote_bda, 6);
|
||||||
|
esp_ble_conn_update_params_t conn_params = {0};
|
||||||
|
memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
|
||||||
|
/* For the iOS system, please refer to Apple official documents about the BLE connection parameters restrictions. */
|
||||||
|
conn_params.latency = 0;
|
||||||
|
conn_params.max_int = 0x20; // max_int = 0x20*1.25ms = 40ms
|
||||||
|
conn_params.min_int = 0x10; // min_int = 0x10*1.25ms = 20ms
|
||||||
|
conn_params.timeout = 400; // timeout = 400*10ms = 4000ms
|
||||||
|
//start sent the update connection parameters to the peer device.
|
||||||
|
esp_ble_gap_update_conn_params(&conn_params);
|
||||||
|
is_connected = true;
|
||||||
|
spp_conn_id = param->connect.conn_id;
|
||||||
|
spp_gatts_if = gatts_if;
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_DISCONNECT_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_DISCONNECT_EVT, reason = 0x%x", param->disconnect.reason);
|
||||||
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
|
is_connected = false;
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CREAT_ATTR_TAB_EVT:{
|
||||||
|
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 != HRS_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, HRS_IDX_NB);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
|
||||||
|
memcpy(heart_rate_handle_table, param->add_attr_tab.handles, sizeof(heart_rate_handle_table));
|
||||||
|
esp_ble_gatts_start_service(heart_rate_handle_table[IDX_SVC]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ESP_GATTS_STOP_EVT:
|
||||||
|
case ESP_GATTS_OPEN_EVT:
|
||||||
|
case ESP_GATTS_CANCEL_OPEN_EVT:
|
||||||
|
case ESP_GATTS_CLOSE_EVT:
|
||||||
|
case ESP_GATTS_LISTEN_EVT:
|
||||||
|
case ESP_GATTS_CONGEST_EVT:
|
||||||
|
case ESP_GATTS_UNREG_EVT:
|
||||||
|
case ESP_GATTS_DELETE_EVT:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* If event is register event, store the gatts_if for each profile */
|
||||||
|
if (event == ESP_GATTS_REG_EVT) {
|
||||||
|
if (param->reg.status == ESP_GATT_OK) {
|
||||||
|
heart_rate_profile_tab[PROFILE_APP_IDX].gatts_if = gatts_if;
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "reg app failed, app_id %04x, status %d",
|
||||||
|
param->reg.app_id,
|
||||||
|
param->reg.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
int idx;
|
||||||
|
for (idx = 0; idx < PROFILE_NUM; idx++) {
|
||||||
|
/* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */
|
||||||
|
if (gatts_if == ESP_GATT_IF_NONE || gatts_if == heart_rate_profile_tab[idx].gatts_if) {
|
||||||
|
if (heart_rate_profile_tab[idx].gatts_cb) {
|
||||||
|
heart_rate_profile_tab[idx].gatts_cb(event, gatts_if, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 上报长度过长,则分包,这里限制长度最大20,分包协议:
|
||||||
|
* [1:0] ‘#’, ‘#’,分包标识
|
||||||
|
* [2] 总包个数
|
||||||
|
* [3] 当前包号,从0开始
|
||||||
|
* ... 包数据
|
||||||
|
*/
|
||||||
|
static uint16_t spp_mtu_size = 23;
|
||||||
|
void notify_data_fun(int id, uint8_t *data, uint32_t len)
|
||||||
|
{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify_data_fun:");
|
||||||
|
esp_log_buffer_hex(GATTS_TABLE_TAG, data, len);
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "hihi");
|
||||||
|
if (len <= spp_mtu_size - 3) /* 包数据可以一次完整发送 */
|
||||||
|
{
|
||||||
|
esp_ble_gatts_send_indicate(spp_gatts_if, spp_conn_id, heart_rate_handle_table[id], len, data, false);
|
||||||
|
}
|
||||||
|
else /* 需要分包发送 */
|
||||||
|
{
|
||||||
|
int total_num = 0;
|
||||||
|
uint8_t buf[spp_mtu_size - 3];
|
||||||
|
if ((len % (spp_mtu_size - 7)) == 0)
|
||||||
|
total_num = len / (spp_mtu_size - 7);
|
||||||
|
else
|
||||||
|
total_num = len / (spp_mtu_size - 7) + 1;
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify packet has %d", total_num);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
buf[0] = '#';
|
||||||
|
buf[1] = '#';
|
||||||
|
buf[2] = total_num;
|
||||||
|
for (i = 0; i < total_num - 1; i++)
|
||||||
|
{
|
||||||
|
buf[3] = i;
|
||||||
|
memcpy(buf + 4, data + i * (spp_mtu_size - 7), spp_mtu_size - 7);
|
||||||
|
esp_ble_gatts_send_indicate(spp_gatts_if, spp_conn_id, heart_rate_handle_table[SPP_IDX_SPP_DATA_NTY_VAL],spp_mtu_size - 3, buf, false);
|
||||||
|
}
|
||||||
|
/* 最后一个包 */
|
||||||
|
buf[3] = i;
|
||||||
|
memcpy(buf + 4, data + i * (spp_mtu_size - 7), len % (spp_mtu_size - 7));
|
||||||
|
esp_ble_gatts_send_indicate(spp_gatts_if, spp_conn_id, heart_rate_handle_table[SPP_IDX_SPP_DATA_NTY_VAL], (len % (spp_mtu_size - 7)) + 4, buf, false);
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "notify packet send end!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t notify_data[500] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; /* 外部程序可以将需要上报的数据拷贝进来 */
|
||||||
|
uint32_t notify_len = 63;
|
||||||
|
void notify_task(void *pvParameters)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (data_notify_enable && is_connected)
|
||||||
|
{
|
||||||
|
notify_data_fun(SPP_IDX_SPP_DATA_NTY_VAL, notify_data, notify_len);
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < notify_len; i++) notify_data[i]++;
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_gatts_server_init(void)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
ret = esp_bt_controller_init(&bt_cfg);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_bluedroid_init();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_bluedroid_enable();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed: %s", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_ble_gatts_register_callback(gatts_event_handler);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "gatts register error, error code = %x", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_ble_gap_register_callback(gap_event_handler);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "gap register error, error code = %x", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_ble_gatts_app_register(ESP_APP_ID);
|
||||||
|
if (ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "gatts app register error, error code = %x", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
|
||||||
|
if (local_mtu_ret){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 创建任务用于定期的数据上报notify */
|
||||||
|
xTaskCreate(notify_task, "notify_Task", 4096, NULL, 8, NULL);
|
||||||
|
}
|
37
main/tmp/ble_gatts_server.h
Normal file
37
main/tmp/ble_gatts_server.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef __BLE_GATTS_SERVER_H
|
||||||
|
#define __BLE_GATTS_SERVER_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define SPP_DATA_MAX_LEN (512)
|
||||||
|
|
||||||
|
|
||||||
|
/* Attributes State Machine */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
IDX_SVC,
|
||||||
|
|
||||||
|
/* gWordVar data write */
|
||||||
|
IDX_CHAR_A,
|
||||||
|
IDX_CHAR_VAL_A,
|
||||||
|
IDX_CHAR_CFG_A,
|
||||||
|
|
||||||
|
/* gWordVar data notify */
|
||||||
|
SPP_IDX_SPP_DATA_NOTIFY_CHAR,
|
||||||
|
SPP_IDX_SPP_DATA_NTY_VAL,
|
||||||
|
SPP_IDX_SPP_DATA_NTF_CFG,
|
||||||
|
|
||||||
|
|
||||||
|
HRS_IDX_NB,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 定时上报的数据内容 */
|
||||||
|
extern uint8_t notify_data[500];
|
||||||
|
extern uint32_t notify_len;
|
||||||
|
|
||||||
|
void ble_gatts_server_init(void);
|
||||||
|
|
||||||
|
#endif
|
502
main/tmp/ble_server.c
Normal file
502
main/tmp/ble_server.c
Normal file
@ -0,0 +1,502 @@
|
|||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/event_groups.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_log.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_server.h"
|
||||||
|
|
||||||
|
#include "stm32/config.h"
|
||||||
|
#include "stm32/ModbusS.h"
|
||||||
|
|
||||||
|
#define GATTS_TABLE_TAG "GATTS_SPP_DEMO"
|
||||||
|
|
||||||
|
#define SPP_PROFILE_NUM 1
|
||||||
|
#define SPP_PROFILE_APP_IDX 0
|
||||||
|
#define ESP_SPP_APP_ID 0x56
|
||||||
|
#define SAMPLE_DEVICE_NAME "ESP_SPP_SERVER" //The Device Name Characteristics in GAP
|
||||||
|
#define SPP_SVC_INST_ID 0
|
||||||
|
|
||||||
|
/// SPP Service
|
||||||
|
static const uint16_t spp_service_uuid = 0xABF0;
|
||||||
|
/// Characteristic UUID
|
||||||
|
#define ESP_GATT_UUID_SPP_DATA_RECEIVE 0xABF1
|
||||||
|
#define ESP_GATT_UUID_SPP_DATA_NOTIFY 0xABF2
|
||||||
|
#define ESP_GATT_UUID_SPP_COMMAND_RECEIVE 0xABF3
|
||||||
|
#define ESP_GATT_UUID_SPP_COMMAND_NOTIFY 0xABF4
|
||||||
|
|
||||||
|
#define ESP_GATT_UUID_PILE_DATA_RECEIVE1 0XABF5
|
||||||
|
#define ESP_GATT_UUID_PILE_DATA_RECEIVE2 0XABF6
|
||||||
|
#define ESP_GATT_UUID_PILE_DATA_RECEIVE3 0XABF7
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
#define ESP_GATT_UUID_SPP_HEARTBEAT 0xABF5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const uint8_t spp_adv_data[23] = {
|
||||||
|
/* Flags */
|
||||||
|
0x02,0x01,0x06,
|
||||||
|
/* 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'
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint16_t spp_mtu_size = 23;
|
||||||
|
static uint16_t spp_conn_id = 0xffff;
|
||||||
|
static esp_gatt_if_t spp_gatts_if = 0xff;
|
||||||
|
QueueHandle_t spp_uart_queue = NULL;
|
||||||
|
static QueueHandle_t cmd_cmd_queue = NULL;
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
static QueueHandle_t cmd_heartbeat_queue = NULL;
|
||||||
|
static uint8_t heartbeat_s[9] = {'E','s','p','r','e','s','s','i','f'};
|
||||||
|
static bool enable_heart_ntf = false;
|
||||||
|
static uint8_t heartbeat_count_num = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static bool enable_data_ntf = false;
|
||||||
|
static bool is_connected = false;
|
||||||
|
static esp_bd_addr_t spp_remote_bda = {0x0,};
|
||||||
|
|
||||||
|
static uint16_t spp_handle_table[SPP_IDX_NB];
|
||||||
|
|
||||||
|
static esp_ble_adv_params_t spp_adv_params = {
|
||||||
|
.adv_int_min = 0x20,
|
||||||
|
.adv_int_max = 0x40,
|
||||||
|
.adv_type = ADV_TYPE_IND,
|
||||||
|
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
|
||||||
|
.channel_map = ADV_CHNL_ALL,
|
||||||
|
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gatts_profile_inst {
|
||||||
|
esp_gatts_cb_t gatts_cb;
|
||||||
|
uint16_t gatts_if;
|
||||||
|
uint16_t app_id;
|
||||||
|
uint16_t conn_id;
|
||||||
|
uint16_t service_handle;
|
||||||
|
esp_gatt_srvc_id_t service_id;
|
||||||
|
uint16_t char_handle;
|
||||||
|
esp_bt_uuid_t char_uuid;
|
||||||
|
esp_gatt_perm_t perm;
|
||||||
|
esp_gatt_char_prop_t property;
|
||||||
|
uint16_t descr_handle;
|
||||||
|
esp_bt_uuid_t descr_uuid;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct spp_receive_data_node{
|
||||||
|
int32_t len;
|
||||||
|
uint8_t * node_buff;
|
||||||
|
struct spp_receive_data_node * next_node;
|
||||||
|
}spp_receive_data_node_t;
|
||||||
|
|
||||||
|
static spp_receive_data_node_t * temp_spp_recv_data_node_p1 = NULL;
|
||||||
|
static spp_receive_data_node_t * temp_spp_recv_data_node_p2 = NULL;
|
||||||
|
|
||||||
|
typedef struct spp_receive_data_buff{
|
||||||
|
int32_t node_num;
|
||||||
|
int32_t buff_size;
|
||||||
|
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 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 ATTRIBUTES
|
||||||
|
****************************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CHAR_DECLARATION_SIZE (sizeof(uint8_t))
|
||||||
|
static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE;
|
||||||
|
static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE;
|
||||||
|
static const uint16_t character_client_config_uuid = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
|
||||||
|
|
||||||
|
static const uint8_t char_prop_read_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
static const uint8_t char_prop_read_write = ESP_GATT_CHAR_PROP_BIT_WRITE_NR|ESP_GATT_CHAR_PROP_BIT_READ;
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
static const uint8_t char_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_WRITE_NR|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
///SPP Service - data receive characteristic, read&write without response
|
||||||
|
static const uint16_t spp_data_receive_uuid = ESP_GATT_UUID_SPP_DATA_RECEIVE;
|
||||||
|
static const uint8_t spp_data_receive_val[20] = {0x02, 0x03};
|
||||||
|
|
||||||
|
///SPP Service - data notify characteristic, notify&read
|
||||||
|
static const uint16_t spp_data_notify_uuid = ESP_GATT_UUID_SPP_DATA_NOTIFY;
|
||||||
|
static const uint8_t spp_data_notify_val[20] = {0x00};
|
||||||
|
static const uint8_t spp_data_notify_ccc[2] = {0x00, 0x00};
|
||||||
|
|
||||||
|
///SPP Service - command characteristic, read&write without response
|
||||||
|
static const uint16_t spp_command_uuid = ESP_GATT_UUID_SPP_COMMAND_RECEIVE;
|
||||||
|
static const uint8_t spp_command_val[10] = {0x00};
|
||||||
|
|
||||||
|
///SPP Service - status characteristic, notify&read
|
||||||
|
static const uint16_t spp_status_uuid = ESP_GATT_UUID_SPP_COMMAND_NOTIFY;
|
||||||
|
static const uint8_t spp_status_val[10] = {0x00};
|
||||||
|
static const uint8_t spp_status_ccc[2] = {0x00, 0x00};
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
///SPP Server - Heart beat characteristic, notify&write&read
|
||||||
|
static const uint16_t spp_heart_beat_uuid = ESP_GATT_UUID_SPP_HEARTBEAT;
|
||||||
|
static const uint8_t spp_heart_beat_val[2] = {0x00, 0x00};
|
||||||
|
static const uint8_t spp_heart_beat_ccc[2] = {0x00, 0x00};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern cal_4_20ma_t *cal_4_20ma;//电流数据结构体
|
||||||
|
extern flow_config_t *flow_config;//流量数据结构体
|
||||||
|
extern depth_config_t *depth_config;//深度数据结构体
|
||||||
|
|
||||||
|
static const uint16_t pile_data_receive1_uuid = ESP_GATT_UUID_PILE_DATA_RECEIVE1;
|
||||||
|
static const uint16_t pile_data_receive2_uuid = ESP_GATT_UUID_PILE_DATA_RECEIVE2;
|
||||||
|
static const uint16_t pile_data_receive3_uuid = ESP_GATT_UUID_PILE_DATA_RECEIVE3;
|
||||||
|
|
||||||
|
///Full HRS Database Description - Used to add attributes into the database
|
||||||
|
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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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}},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[PILE_IDX_DATA_RECV1_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}},
|
||||||
|
[PILE_IDX_DATA_RECV1_VAL] =
|
||||||
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&pile_data_receive1_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
|
||||||
|
SPP_DATA_MAX_LEN,sizeof(cal_4_20ma_t), (uint8_t *)&gWordVar[CAL_4_20MA_ADDR]}},
|
||||||
|
|
||||||
|
[PILE_IDX_DATA_RECV2_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}},
|
||||||
|
[PILE_IDX_DATA_RECV2_VAL] =
|
||||||
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&pile_data_receive2_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
|
||||||
|
SPP_DATA_MAX_LEN,sizeof(flow_config_t), (uint8_t *)&gWordVar[FLOW_CONFIG_ADDR]}},
|
||||||
|
|
||||||
|
[PILE_IDX_DATA_RECV3_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}},
|
||||||
|
[PILE_IDX_DATA_RECV3_VAL] =
|
||||||
|
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&pile_data_receive3_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
|
||||||
|
SPP_DATA_MAX_LEN,sizeof(depth_config_t), (uint8_t *)&gWordVar[DEPTH_CONFIG_ADDR]}},
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint8_t find_char_and_desr_index(uint16_t handle)
|
||||||
|
{
|
||||||
|
uint8_t error = 0xff;
|
||||||
|
|
||||||
|
for(int i = 0; i < SPP_IDX_NB ; i++){
|
||||||
|
if(handle == spp_handle_table[i]){
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
switch (event) {
|
||||||
|
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
|
||||||
|
esp_ble_gap_start_advertising(&spp_adv_params);
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||||
|
//advertising start complete event to indicate advertising start successfully or failed
|
||||||
|
if((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "Advertising start failed: %s\n", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "event = %d\n",event);
|
||||||
|
switch (event) {
|
||||||
|
case ESP_GATTS_REG_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_REG_EVT");
|
||||||
|
|
||||||
|
esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||||
|
|
||||||
|
esp_ble_gap_config_adv_data_raw((uint8_t *)spp_adv_data, sizeof(spp_adv_data));
|
||||||
|
|
||||||
|
esp_ble_gatts_create_attr_tab(spp_gatt_db, gatts_if, SPP_IDX_NB, SPP_SVC_INST_ID);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_READ_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_READ_EVT");
|
||||||
|
gWordVar[CAL_4_20MA_ADDR] = 1;
|
||||||
|
// res = find_char_and_desr_index(p_data->read.handle);
|
||||||
|
// if(res == SPP_IDX_SPP_STATUS_VAL){
|
||||||
|
// //TODO:client read the status characteristic
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_WRITE_EVT: {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_WRITE_EVT");
|
||||||
|
res = find_char_and_desr_index(p_data->write.handle);
|
||||||
|
if(p_data->write.is_prep == false){
|
||||||
|
// ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_WRITE_EVT : handle = %d\n", res);
|
||||||
|
if(res == SPP_IDX_SPP_COMMAND_VAL){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "SPP_IDX_SPP_COMMAND_VAL");
|
||||||
|
// uint8_t * spp_cmd_buff = NULL;
|
||||||
|
// spp_cmd_buff = (uint8_t *)malloc((spp_mtu_size - 3) * sizeof(uint8_t));
|
||||||
|
// if(spp_cmd_buff == NULL){
|
||||||
|
// ESP_LOGE(GATTS_TABLE_TAG, "%s malloc failed\n", __func__);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// memset(spp_cmd_buff,0x0,(spp_mtu_size - 3));
|
||||||
|
// memcpy(spp_cmd_buff,p_data->write.value,p_data->write.len);
|
||||||
|
// xQueueSend(cmd_cmd_queue,&spp_cmd_buff,10/portTICK_PERIOD_MS);
|
||||||
|
}else if(res == SPP_IDX_SPP_DATA_NTF_CFG){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "SPP_IDX_SPP_DATA_NTF_CFG");
|
||||||
|
if((p_data->write.len == 2)&&(p_data->write.value[0] == 0x01)&&(p_data->write.value[1] == 0x00)){
|
||||||
|
enable_data_ntf = true;
|
||||||
|
}else if((p_data->write.len == 2)&&(p_data->write.value[0] == 0x00)&&(p_data->write.value[1] == 0x00)){
|
||||||
|
enable_data_ntf = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(res == SPP_IDX_SPP_DATA_RECV_VAL){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "SPP_IDX_SPP_DATA_RECV_VAL");
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "0x%x 0x%x", spp_data_receive_val[0], spp_data_receive_val[1]);
|
||||||
|
// uart_write_bytes(UART_NUM_2, (char *)(p_data->write.value), p_data->write.len);
|
||||||
|
}
|
||||||
|
else if (res == PILE_IDX_DATA_RECV1_VAL){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "PILE_IDX_DATA_RECV1_VAL %d:0x%x 0x%x 0x%x 0x%x", p_data->write.len, p_data->write.value[0], p_data->write.value[1], p_data->write.value[2], p_data->write.value[3]);
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "0x%x 0x%x", gWordVar[CAL_4_20MA_ADDR], gWordVar[CAL_4_20MA_ADDR + 1]);
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "cal_4_20ma->magic=%d", cal_4_20ma->magic);
|
||||||
|
}
|
||||||
|
else if (res == PILE_IDX_DATA_RECV2_VAL){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "PILE_IDX_DATA_RECV2_VAL");
|
||||||
|
}
|
||||||
|
else if (res == PILE_IDX_DATA_RECV3_VAL){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "PILE_IDX_DATA_RECV3_VAL");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
}else if((p_data->write.is_prep == true)&&(res == SPP_IDX_SPP_DATA_RECV_VAL)){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_PREP_WRITE_EVT : handle = %d\n", res);
|
||||||
|
// store_wr_buffer(p_data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ESP_GATTS_EXEC_WRITE_EVT:{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_EXEC_WRITE_EVT\n");
|
||||||
|
if(p_data->exec_write.exec_write_flag){
|
||||||
|
// print_write_buffer();
|
||||||
|
// free_write_buffer();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ESP_GATTS_MTU_EVT:
|
||||||
|
spp_mtu_size = p_data->mtu.mtu;
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONF_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_UNREG_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_DELETE_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_START_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_STOP_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONNECT_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT");
|
||||||
|
spp_conn_id = p_data->connect.conn_id;
|
||||||
|
spp_gatts_if = gatts_if;
|
||||||
|
is_connected = true;
|
||||||
|
memcpy(&spp_remote_bda,&p_data->connect.remote_bda,sizeof(esp_bd_addr_t));
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
uint16_t cmd = 0;
|
||||||
|
xQueueSend(cmd_heartbeat_queue,&cmd,10/portTICK_PERIOD_MS);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_DISCONNECT_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_DISCONNECT_EVT");
|
||||||
|
is_connected = false;
|
||||||
|
enable_data_ntf = false;
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
enable_heart_ntf = false;
|
||||||
|
heartbeat_count_num = 0;
|
||||||
|
#endif
|
||||||
|
esp_ble_gap_start_advertising(&spp_adv_params);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_OPEN_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CANCEL_OPEN_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CLOSE_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_LISTEN_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONGEST_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CREAT_ATTR_TAB_EVT:{
|
||||||
|
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){
|
||||||
|
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 {
|
||||||
|
memcpy(spp_handle_table, param->add_attr_tab.handles, sizeof(spp_handle_table));
|
||||||
|
esp_ble_gatts_start_service(spp_handle_table[SPP_IDX_SVC]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
||||||
|
if (event == ESP_GATTS_REG_EVT) {
|
||||||
|
if (param->reg.status == ESP_GATT_OK) {
|
||||||
|
spp_profile_tab[SPP_PROFILE_APP_IDX].gatts_if = gatts_if;
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "Reg app failed, app_id %04x, status %d\n",param->reg.app_id, param->reg.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
int idx;
|
||||||
|
for (idx = 0; idx < SPP_PROFILE_NUM; idx++) {
|
||||||
|
if (gatts_if == ESP_GATT_IF_NONE || /* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */
|
||||||
|
gatts_if == spp_profile_tab[idx].gatts_if) {
|
||||||
|
if (spp_profile_tab[idx].gatts_cb) {
|
||||||
|
spp_profile_tab[idx].gatts_cb(event, gatts_if, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_server_init(void)
|
||||||
|
{
|
||||||
|
esp_err_t ret;
|
||||||
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||||
|
|
||||||
|
ret = esp_bt_controller_init(&bt_cfg);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth\n", __func__);
|
||||||
|
ret = esp_bluedroid_init();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ret = esp_bluedroid_enable();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_ble_gatts_register_callback(gatts_event_handler);
|
||||||
|
esp_ble_gap_register_callback(gap_event_handler);
|
||||||
|
esp_ble_gatts_app_register(ESP_SPP_APP_ID);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
59
main/tmp/ble_server.h
Normal file
59
main/tmp/ble_server.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#ifndef __BLE_SERCER_H
|
||||||
|
#define __BLE_SERCER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DEFINES
|
||||||
|
****************************************************************************************
|
||||||
|
*/
|
||||||
|
//#define SUPPORT_HEARTBEAT
|
||||||
|
//#define SPP_DEBUG_MODE
|
||||||
|
|
||||||
|
#define spp_sprintf(s,...) sprintf((char*)(s), ##__VA_ARGS__)
|
||||||
|
#define SPP_DATA_MAX_LEN (512)
|
||||||
|
#define SPP_CMD_MAX_LEN (20)
|
||||||
|
#define SPP_STATUS_MAX_LEN (20)
|
||||||
|
#define SPP_DATA_BUFF_MAX_LEN (2*1024)
|
||||||
|
///Attributes State Machine
|
||||||
|
enum{
|
||||||
|
SPP_IDX_SVC,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_DATA_RECV_CHAR,
|
||||||
|
SPP_IDX_SPP_DATA_RECV_VAL,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_DATA_NOTIFY_CHAR,
|
||||||
|
SPP_IDX_SPP_DATA_NTY_VAL,
|
||||||
|
SPP_IDX_SPP_DATA_NTF_CFG,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_COMMAND_CHAR,
|
||||||
|
SPP_IDX_SPP_COMMAND_VAL,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_STATUS_CHAR,
|
||||||
|
SPP_IDX_SPP_STATUS_VAL,
|
||||||
|
SPP_IDX_SPP_STATUS_CFG,
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
SPP_IDX_SPP_HEARTBEAT_CHAR,
|
||||||
|
SPP_IDX_SPP_HEARTBEAT_VAL,
|
||||||
|
SPP_IDX_SPP_HEARTBEAT_CFG,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PILE_IDX_DATA_RECV1_CHAR,
|
||||||
|
PILE_IDX_DATA_RECV1_VAL,
|
||||||
|
|
||||||
|
PILE_IDX_DATA_RECV2_CHAR,
|
||||||
|
PILE_IDX_DATA_RECV2_VAL,
|
||||||
|
|
||||||
|
PILE_IDX_DATA_RECV3_CHAR,
|
||||||
|
PILE_IDX_DATA_RECV3_VAL,
|
||||||
|
|
||||||
|
SPP_IDX_NB,
|
||||||
|
};
|
||||||
|
|
||||||
|
void ble_server_init(void);
|
||||||
|
|
||||||
|
#endif
|
859
main/tmp/bt_server.c
Normal file
859
main/tmp/bt_server.c
Normal file
@ -0,0 +1,859 @@
|
|||||||
|
/*
|
||||||
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, this
|
||||||
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/event_groups.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_log.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 "bt_server.h"
|
||||||
|
|
||||||
|
#define SPP_DEBUG_MODE 1
|
||||||
|
|
||||||
|
#define GATTS_TABLE_TAG "GATTS_SPP_DEMO"
|
||||||
|
|
||||||
|
#define SPP_PROFILE_NUM 1
|
||||||
|
#define SPP_PROFILE_APP_IDX 0
|
||||||
|
#define ESP_SPP_APP_ID 0x56
|
||||||
|
#define SAMPLE_DEVICE_NAME "ESP_SPP_SERVER" //The Device Name Characteristics in GAP
|
||||||
|
#define SPP_SVC_INST_ID 0
|
||||||
|
|
||||||
|
/// SPP Service
|
||||||
|
static const uint16_t spp_service_uuid = 0xABF0;
|
||||||
|
/// Characteristic UUID
|
||||||
|
#define ESP_GATT_UUID_SPP_DATA_RECEIVE 0xABF1
|
||||||
|
#define ESP_GATT_UUID_SPP_DATA_NOTIFY 0xABF2
|
||||||
|
#define ESP_GATT_UUID_SPP_COMMAND_RECEIVE 0xABF3
|
||||||
|
#define ESP_GATT_UUID_SPP_COMMAND_NOTIFY 0xABF4
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
#define ESP_GATT_UUID_SPP_HEARTBEAT 0xABF5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*蓝牙的广播数据*/
|
||||||
|
static const uint8_t spp_adv_data[23] = {
|
||||||
|
/* Flags */
|
||||||
|
0x02,0x01,0x06, //表示设备支持LE General Discoverable Mode(可被发现模式)和BR/EDR Not Supported(不支持传统蓝牙)
|
||||||
|
/* Complete List of 16-bit Service Class UUIDs */
|
||||||
|
0x03,0x03,0xF0,0xAB,//广播数据中的16位服务UUID字段,表示设备提供了一个特定的服务,这里是自定义的16位UUID
|
||||||
|
/* Complete Local Name in advertising */
|
||||||
|
0x0F,0x09, 'E', 'S', 'P', '_', 'S', 'P', 'P', '_', 'S', 'E', 'R','V', 'E', 'R'
|
||||||
|
//广播数据中的16位服务UUID字段,表示设备提供了一个特定的服务,这里是自定义的16位UUID
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint16_t spp_mtu_size = 23;
|
||||||
|
uint16_t spp_conn_id = 0xffff;
|
||||||
|
esp_gatt_if_t spp_gatts_if = 0xff;
|
||||||
|
QueueHandle_t spp_uart_queue = NULL;
|
||||||
|
static QueueHandle_t cmd_cmd_queue = NULL;
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
static QueueHandle_t cmd_heartbeat_queue = NULL;
|
||||||
|
static uint8_t heartbeat_s[9] = {'E','s','p','r','e','s','s','i','f'};
|
||||||
|
static bool enable_heart_ntf = false;
|
||||||
|
static uint8_t heartbeat_count_num = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static bool enable_data_ntf = false;
|
||||||
|
bool is_connected = false;
|
||||||
|
static esp_bd_addr_t spp_remote_bda = {0x0,};
|
||||||
|
|
||||||
|
uint16_t spp_handle_table[SPP_IDX_NB];
|
||||||
|
|
||||||
|
static esp_ble_adv_params_t spp_adv_params = {
|
||||||
|
.adv_int_min = 0x20,
|
||||||
|
.adv_int_max = 0x40,
|
||||||
|
.adv_type = ADV_TYPE_IND,
|
||||||
|
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
|
||||||
|
.channel_map = ADV_CHNL_ALL,
|
||||||
|
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gatts_profile_inst {
|
||||||
|
esp_gatts_cb_t gatts_cb;
|
||||||
|
uint16_t gatts_if;
|
||||||
|
uint16_t app_id;
|
||||||
|
uint16_t conn_id;
|
||||||
|
uint16_t service_handle;
|
||||||
|
esp_gatt_srvc_id_t service_id;
|
||||||
|
uint16_t char_handle;
|
||||||
|
esp_bt_uuid_t char_uuid;
|
||||||
|
esp_gatt_perm_t perm;
|
||||||
|
esp_gatt_char_prop_t property;
|
||||||
|
uint16_t descr_handle;
|
||||||
|
esp_bt_uuid_t descr_uuid;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct spp_receive_data_node{
|
||||||
|
int32_t len;
|
||||||
|
uint8_t * node_buff;
|
||||||
|
struct spp_receive_data_node * next_node;
|
||||||
|
}spp_receive_data_node_t;
|
||||||
|
|
||||||
|
static spp_receive_data_node_t * temp_spp_recv_data_node_p1 = NULL;
|
||||||
|
static spp_receive_data_node_t * temp_spp_recv_data_node_p2 = NULL;
|
||||||
|
|
||||||
|
typedef struct spp_receive_data_buff{
|
||||||
|
int32_t node_num;
|
||||||
|
int32_t buff_size;
|
||||||
|
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 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 ATTRIBUTES
|
||||||
|
****************************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CHAR_DECLARATION_SIZE (sizeof(uint8_t))
|
||||||
|
static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE; //0x2800
|
||||||
|
static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE; //0x2803
|
||||||
|
static const uint16_t character_client_config_uuid = ESP_GATT_UUID_CHAR_CLIENT_CONFIG; //0x2902
|
||||||
|
|
||||||
|
static const uint8_t char_prop_read_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
static const uint8_t char_prop_read_write = ESP_GATT_CHAR_PROP_BIT_WRITE_NR|ESP_GATT_CHAR_PROP_BIT_READ;
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
static const uint8_t char_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_WRITE_NR|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
///SPP Service - data receive characteristic, read&write without response
|
||||||
|
static const uint16_t spp_data_receive_uuid = ESP_GATT_UUID_SPP_DATA_RECEIVE; //0xABF1
|
||||||
|
static const uint8_t spp_data_receive_val[20] = {0x00};
|
||||||
|
|
||||||
|
///SPP Service - data notify characteristic, notify&read
|
||||||
|
static const uint16_t spp_data_notify_uuid = ESP_GATT_UUID_SPP_DATA_NOTIFY; //0xABF2
|
||||||
|
static const uint8_t spp_data_notify_val[20] = {0x00};
|
||||||
|
static const uint8_t spp_data_notify_ccc[2] = {0x00, 0x00};
|
||||||
|
|
||||||
|
///SPP Service - command characteristic, read&write without response
|
||||||
|
static const uint16_t spp_command_uuid = ESP_GATT_UUID_SPP_COMMAND_RECEIVE; //0xABF3
|
||||||
|
static const uint8_t spp_command_val[10] = {0x00};
|
||||||
|
|
||||||
|
///SPP Service - status characteristic, notify&read
|
||||||
|
static const uint16_t spp_status_uuid = ESP_GATT_UUID_SPP_COMMAND_NOTIFY; //0xABF4
|
||||||
|
static const uint8_t spp_status_val[10] = {0x00};
|
||||||
|
static const uint8_t spp_status_ccc[2] = {0x00, 0x00};//状态特征值。这个值允许其他设备配置是否接收状态特征通知,这里是禁用
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
///SPP Server - Heart beat characteristic, notify&write&read
|
||||||
|
static const uint16_t spp_heart_beat_uuid = ESP_GATT_UUID_SPP_HEARTBEAT;
|
||||||
|
static const uint8_t spp_heart_beat_val[2] = {0x00, 0x00};
|
||||||
|
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] =
|
||||||
|
{
|
||||||
|
//SPP - Service Declaration 服务声明
|
||||||
|
[SPP_IDX_SVC] = {
|
||||||
|
{ESP_GATT_AUTO_RSP},
|
||||||
|
{
|
||||||
|
ESP_UUID_LEN_16,
|
||||||
|
(uint8_t *)&primary_service_uuid, //0x2800
|
||||||
|
ESP_GATT_PERM_READ,
|
||||||
|
sizeof(spp_service_uuid), //0xABF0
|
||||||
|
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, //0x2803
|
||||||
|
ESP_GATT_PERM_READ,
|
||||||
|
CHAR_DECLARATION_SIZE,
|
||||||
|
CHAR_DECLARATION_SIZE,
|
||||||
|
(uint8_t *)&char_prop_read_write
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//SPP - data receive characteristic Value spp服务中数据接收特征值
|
||||||
|
[SPP_IDX_SPP_DATA_RECV_VAL] = {
|
||||||
|
{ESP_GATT_AUTO_RSP},
|
||||||
|
{
|
||||||
|
ESP_UUID_LEN_16,
|
||||||
|
(uint8_t *)&spp_data_receive_uuid, //0xABF1
|
||||||
|
ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
|
||||||
|
SPP_DATA_MAX_LEN,
|
||||||
|
sizeof(spp_data_receive_val),
|
||||||
|
(uint8_t *)spp_data_receive_val //0x00
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//SPP - data notify characteristic Declaration spp协议中数据通知特征
|
||||||
|
[SPP_IDX_SPP_DATA_NOTIFY_CHAR] = {
|
||||||
|
{ESP_GATT_AUTO_RSP},
|
||||||
|
{
|
||||||
|
ESP_UUID_LEN_16,
|
||||||
|
(uint8_t *)&character_declaration_uuid, //0x2803
|
||||||
|
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, //0xABF2
|
||||||
|
ESP_GATT_PERM_READ,
|
||||||
|
SPP_DATA_MAX_LEN,
|
||||||
|
sizeof(spp_data_notify_val),
|
||||||
|
(uint8_t *)spp_data_notify_val //0x00
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//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, //0x2902
|
||||||
|
ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
|
||||||
|
sizeof(uint16_t),
|
||||||
|
sizeof(spp_data_notify_ccc),
|
||||||
|
(uint8_t *)spp_data_notify_ccc //{0x00, 0x00}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//SPP - command characteristic Declaration 命令特征声明
|
||||||
|
[SPP_IDX_SPP_COMMAND_CHAR]= {
|
||||||
|
{ESP_GATT_AUTO_RSP},
|
||||||
|
{
|
||||||
|
ESP_UUID_LEN_16,
|
||||||
|
(uint8_t *)&character_declaration_uuid, //0x2803
|
||||||
|
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, //0xABF3
|
||||||
|
ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
|
||||||
|
SPP_CMD_MAX_LEN,
|
||||||
|
sizeof(spp_command_val),
|
||||||
|
(uint8_t *)spp_command_val //{0x00}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//SPP - status characteristic Declaration
|
||||||
|
[SPP_IDX_SPP_STATUS_CHAR] = {
|
||||||
|
{ESP_GATT_AUTO_RSP},
|
||||||
|
{
|
||||||
|
ESP_UUID_LEN_16,
|
||||||
|
(uint8_t *)&character_declaration_uuid, //0x2803
|
||||||
|
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, //0xABF4
|
||||||
|
ESP_GATT_PERM_READ,
|
||||||
|
SPP_STATUS_MAX_LEN,
|
||||||
|
sizeof(spp_status_val),
|
||||||
|
(uint8_t *)spp_status_val //{0x00}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//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, //0x2902
|
||||||
|
ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
|
||||||
|
sizeof(uint16_t),
|
||||||
|
sizeof(spp_status_ccc),
|
||||||
|
(uint8_t *)spp_status_ccc //{0x00, 0x00}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
#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 - 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 - 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}},
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/*在 spp_handle_table 数组中查找与给定句柄匹配的特性或描述符,返回其索引值。如果没有找到匹配的值,则返回 0xff*/
|
||||||
|
static uint8_t find_char_and_desr_index(uint16_t handle)
|
||||||
|
{
|
||||||
|
uint8_t error = 0xff;
|
||||||
|
|
||||||
|
for(int i = 0; i < SPP_IDX_NB ; i++){
|
||||||
|
if(handle == spp_handle_table[i]){
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*存储写入缓冲区的数据*/
|
||||||
|
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){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "malloc error %s %d\n", __func__, __LINE__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(temp_spp_recv_data_node_p2 != NULL){
|
||||||
|
temp_spp_recv_data_node_p2->next_node = temp_spp_recv_data_node_p1;
|
||||||
|
}
|
||||||
|
temp_spp_recv_data_node_p1->len = p_data->write.len;
|
||||||
|
SppRecvDataBuff.buff_size += p_data->write.len;
|
||||||
|
temp_spp_recv_data_node_p1->next_node = NULL;
|
||||||
|
temp_spp_recv_data_node_p1->node_buff = (uint8_t *)malloc(p_data->write.len);
|
||||||
|
temp_spp_recv_data_node_p2 = temp_spp_recv_data_node_p1;
|
||||||
|
memcpy(temp_spp_recv_data_node_p1->node_buff,p_data->write.value,p_data->write.len);
|
||||||
|
if(SppRecvDataBuff.node_num == 0){
|
||||||
|
SppRecvDataBuff.first_node = temp_spp_recv_data_node_p1;
|
||||||
|
SppRecvDataBuff.node_num++;
|
||||||
|
}else{
|
||||||
|
SppRecvDataBuff.node_num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//释放缓冲区内存
|
||||||
|
static void free_write_buffer(void)
|
||||||
|
{
|
||||||
|
temp_spp_recv_data_node_p1 = SppRecvDataBuff.first_node;
|
||||||
|
|
||||||
|
while(temp_spp_recv_data_node_p1 != NULL){
|
||||||
|
temp_spp_recv_data_node_p2 = temp_spp_recv_data_node_p1->next_node;
|
||||||
|
free(temp_spp_recv_data_node_p1->node_buff);
|
||||||
|
free(temp_spp_recv_data_node_p1);
|
||||||
|
temp_spp_recv_data_node_p1 = temp_spp_recv_data_node_p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
SppRecvDataBuff.node_num = 0;
|
||||||
|
SppRecvDataBuff.buff_size = 0;
|
||||||
|
SppRecvDataBuff.first_node = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*将缓冲区数据写入uart*/
|
||||||
|
static void print_write_buffer(void)
|
||||||
|
{
|
||||||
|
temp_spp_recv_data_node_p1 = SppRecvDataBuff.first_node;
|
||||||
|
|
||||||
|
while(temp_spp_recv_data_node_p1 != NULL){
|
||||||
|
uart_write_bytes(UART_NUM_2, (char *)(temp_spp_recv_data_node_p1->node_buff), temp_spp_recv_data_node_p1->len);
|
||||||
|
temp_spp_recv_data_node_p1 = temp_spp_recv_data_node_p1->next_node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//蓝牙设备接收到消息后将分组数据通过蓝牙的 GATT Indicate 方式发送给蓝牙连接的设备(也就是蓝牙客户端)
|
||||||
|
void uart_task(void *pvParameters)
|
||||||
|
{
|
||||||
|
uart_event_t event;
|
||||||
|
uint8_t total_num = 0;
|
||||||
|
uint8_t current_num = 0;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
//Waiting for UART event.
|
||||||
|
if (xQueueReceive(spp_uart_queue, (void * )&event, 10/portTICK_PERIOD_MS)) {
|
||||||
|
switch (event.type) {
|
||||||
|
//Event of UART receving data
|
||||||
|
case UART_DATA:
|
||||||
|
if ((event.size)&&(is_connected)) {
|
||||||
|
uint8_t * temp = NULL;
|
||||||
|
uint8_t * ntf_value_p = NULL;
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
if(!enable_heart_ntf){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s do not enable heartbeat Notify\n", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if(!enable_data_ntf){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s do not enable data Notify\n", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
temp = (uint8_t *)malloc(sizeof(uint8_t)*event.size);
|
||||||
|
if(temp == NULL){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s malloc.1 failed\n", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//将数据通过uart串口读入缓冲区
|
||||||
|
memset(temp,0x0,event.size);
|
||||||
|
uart_read_bytes(UART_NUM_2,temp,event.size,10/portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
if(event.size <= (spp_mtu_size - 3)){ //spp_mtu_size - 3是一个分组的最大容量
|
||||||
|
//向gatt发送indicate消息
|
||||||
|
//1.接口号2.连接id 3.特征句柄 4.数据长度 5.数据指针
|
||||||
|
esp_ble_gatts_send_indicate(spp_gatts_if,
|
||||||
|
spp_conn_id,
|
||||||
|
spp_handle_table[4],
|
||||||
|
event.size,
|
||||||
|
temp,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}else if(event.size > (spp_mtu_size - 3)){
|
||||||
|
if((event.size%(spp_mtu_size - 7)) == 0){
|
||||||
|
total_num = event.size/(spp_mtu_size - 7);//spp_mtu_size - 7是有效负载大小
|
||||||
|
}else{
|
||||||
|
total_num = event.size/(spp_mtu_size - 7) + 1;
|
||||||
|
}
|
||||||
|
current_num = 1;
|
||||||
|
ntf_value_p = (uint8_t *)malloc((spp_mtu_size-3)*sizeof(uint8_t));
|
||||||
|
if(ntf_value_p == NULL){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s malloc.2 failed\n", __func__);
|
||||||
|
free(temp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while(current_num <= total_num){
|
||||||
|
if(current_num < total_num){
|
||||||
|
ntf_value_p[0] = '#';
|
||||||
|
ntf_value_p[1] = '#';
|
||||||
|
ntf_value_p[2] = total_num;
|
||||||
|
ntf_value_p[3] = current_num;
|
||||||
|
memcpy(ntf_value_p + 4,temp + (current_num - 1)*(spp_mtu_size-7),(spp_mtu_size-7));
|
||||||
|
esp_ble_gatts_send_indicate(spp_gatts_if,
|
||||||
|
spp_conn_id,
|
||||||
|
spp_handle_table[SPP_IDX_SPP_DATA_NTY_VAL],
|
||||||
|
(spp_mtu_size-3),
|
||||||
|
ntf_value_p,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}else if(current_num == total_num){
|
||||||
|
ntf_value_p[0] = '#';
|
||||||
|
ntf_value_p[1] = '#';
|
||||||
|
ntf_value_p[2] = total_num;
|
||||||
|
ntf_value_p[3] = current_num;
|
||||||
|
memcpy(ntf_value_p + 4,temp + (current_num - 1)*(spp_mtu_size-7),(event.size - (current_num - 1)*(spp_mtu_size - 7)));
|
||||||
|
esp_ble_gatts_send_indicate(spp_gatts_if,
|
||||||
|
spp_conn_id,
|
||||||
|
spp_handle_table[SPP_IDX_SPP_DATA_NTY_VAL],
|
||||||
|
(event.size - (current_num - 1)*(spp_mtu_size - 7) + 4),
|
||||||
|
ntf_value_p,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||||
|
current_num++;
|
||||||
|
}
|
||||||
|
free(ntf_value_p);
|
||||||
|
}
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spp_uart_init(void)
|
||||||
|
{
|
||||||
|
uart_config_t uart_config = {
|
||||||
|
.baud_rate = 115200,
|
||||||
|
.data_bits = UART_DATA_8_BITS,
|
||||||
|
.parity = UART_PARITY_DISABLE,
|
||||||
|
.stop_bits = UART_STOP_BITS_1,
|
||||||
|
.flow_ctrl = UART_HW_FLOWCTRL_RTS,
|
||||||
|
.rx_flow_ctrl_thresh = 122,
|
||||||
|
.source_clk = UART_SCLK_APB,
|
||||||
|
};
|
||||||
|
|
||||||
|
//Install UART driver, and get the queue.
|
||||||
|
uart_driver_install(UART_NUM_2, 4096, 8192, 10, &spp_uart_queue,0);
|
||||||
|
//Set UART parameters
|
||||||
|
uart_param_config(UART_NUM_2, &uart_config);
|
||||||
|
//Set UART pins
|
||||||
|
uart_set_pin(UART_NUM_2, 14, 21, 47, UART_PIN_NO_CHANGE);
|
||||||
|
xTaskCreate(uart_task, "uTask", 2048, (void*)UART_NUM_2, 8, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
void spp_heartbeat_task(void * arg)
|
||||||
|
{
|
||||||
|
uint16_t cmd_id;
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||||
|
if(xQueueReceive(cmd_heartbeat_queue, &cmd_id, portMAX_DELAY)) {
|
||||||
|
while(1){
|
||||||
|
heartbeat_count_num++;
|
||||||
|
vTaskDelay(5000/ portTICK_PERIOD_MS);
|
||||||
|
if((heartbeat_count_num >3)&&(is_connected)){
|
||||||
|
esp_ble_gap_disconnect(spp_remote_bda);
|
||||||
|
}
|
||||||
|
if(is_connected && enable_heart_ntf){
|
||||||
|
esp_ble_gatts_send_indicate(spp_gatts_if, spp_conn_id, spp_handle_table[SPP_IDX_SPP_HEARTBEAT_VAL],sizeof(heartbeat_s), heartbeat_s, false);
|
||||||
|
}else if(!is_connected){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//通过接收队列获取蓝牙命令数据,进行相应的处理,然后打印到系统日志并释放相关内存
|
||||||
|
void spp_cmd_task(void * arg)
|
||||||
|
{
|
||||||
|
uint8_t * cmd_id;
|
||||||
|
|
||||||
|
for(;;){
|
||||||
|
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||||
|
if(xQueueReceive(cmd_cmd_queue, &cmd_id, 10 / portTICK_PERIOD_MS)) {
|
||||||
|
esp_log_buffer_char(GATTS_TABLE_TAG,(char *)(cmd_id),strlen((char *)cmd_id));
|
||||||
|
free(cmd_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spp_task_init(void)
|
||||||
|
{
|
||||||
|
spp_uart_init();
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
cmd_heartbeat_queue = xQueueCreate(10, sizeof(uint32_t));
|
||||||
|
xTaskCreate(spp_heartbeat_task, "spp_heartbeat_task", 2048, NULL, 10, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cmd_cmd_queue = xQueueCreate(10, sizeof(uint32_t));
|
||||||
|
xTaskCreate(spp_cmd_task, "spp_cmd_task", 2048, NULL, 10, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*gap事件回调函数*/
|
||||||
|
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
|
||||||
|
{
|
||||||
|
esp_err_t err;
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "GAP_EVT, event %d\n", event);
|
||||||
|
|
||||||
|
switch (event) {
|
||||||
|
/*表示原始广播数据设置完成*/
|
||||||
|
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
|
||||||
|
/*启动广播,并传递蓝牙广播参数 spp_adv_params*/
|
||||||
|
esp_ble_gap_start_advertising(&spp_adv_params);
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
|
||||||
|
//advertising start complete event to indicate advertising start successfully or failed
|
||||||
|
if((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "Advertising start failed: %s\n", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*处理gatt事件的回调函数,根据不同的请求执行不同的操作*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "event = %x\n",event);
|
||||||
|
switch (event) {
|
||||||
|
|
||||||
|
//gatt服务器注册事件
|
||||||
|
case ESP_GATTS_REG_EVT:
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "%s %d\n", __func__, __LINE__);
|
||||||
|
|
||||||
|
//设置蓝牙设备名称
|
||||||
|
esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||||
|
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "%s %d\n", __func__, __LINE__);
|
||||||
|
|
||||||
|
//配置蓝牙广播数据的原始数据
|
||||||
|
esp_ble_gap_config_adv_data_raw((uint8_t *)spp_adv_data, sizeof(spp_adv_data));
|
||||||
|
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "%s %d\n", __func__, __LINE__);
|
||||||
|
|
||||||
|
//创建gatt服务的属性表
|
||||||
|
esp_ble_gatts_create_attr_tab(spp_gatt_db, gatts_if, SPP_IDX_NB, SPP_SVC_INST_ID);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//收到读取数据的请求
|
||||||
|
case ESP_GATTS_READ_EVT:
|
||||||
|
//找到对应句柄,返回对应索引
|
||||||
|
res = find_char_and_desr_index(p_data->read.handle);
|
||||||
|
if(res == SPP_IDX_SPP_STATUS_VAL){
|
||||||
|
//TODO:client read the status characteristic
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//收到写数据的请求
|
||||||
|
case ESP_GATTS_WRITE_EVT: {
|
||||||
|
res = find_char_and_desr_index(p_data->write.handle);
|
||||||
|
if(p_data->write.is_prep == false){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_WRITE_EVT : handle = %d\n", res);
|
||||||
|
if(res == SPP_IDX_SPP_COMMAND_VAL){
|
||||||
|
uint8_t * spp_cmd_buff = NULL;
|
||||||
|
spp_cmd_buff = (uint8_t *)malloc((spp_mtu_size - 3) * sizeof(uint8_t));
|
||||||
|
if(spp_cmd_buff == NULL){
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s malloc failed\n", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memset(spp_cmd_buff,0x0,(spp_mtu_size - 3));
|
||||||
|
memcpy(spp_cmd_buff,p_data->write.value,p_data->write.len);
|
||||||
|
xQueueSend(cmd_cmd_queue,&spp_cmd_buff,10/portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
//SPP 数据通知配置
|
||||||
|
}else if(res == SPP_IDX_SPP_DATA_NTF_CFG){
|
||||||
|
//第一个字节为 0x01,第二个字节为 0x00。如果条件满足,则将 enable_data_ntf 设置为 true,表示启用数据通知
|
||||||
|
if((p_data->write.len == 2)&&(p_data->write.value[0] == 0x01)&&(p_data->write.value[1] == 0x00)){
|
||||||
|
enable_data_ntf = true;
|
||||||
|
}else if((p_data->write.len == 2)&&(p_data->write.value[0] == 0x00)&&(p_data->write.value[1] == 0x00)){
|
||||||
|
enable_data_ntf = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
else if(res == SPP_IDX_SPP_HEARTBEAT_CFG){
|
||||||
|
if((p_data->write.len == 2)&&(p_data->write.value[0] == 0x01)&&(p_data->write.value[1] == 0x00)){
|
||||||
|
enable_heart_ntf = true;
|
||||||
|
}else if((p_data->write.len == 2)&&(p_data->write.value[0] == 0x00)&&(p_data->write.value[1] == 0x00)){
|
||||||
|
enable_heart_ntf = false;
|
||||||
|
}
|
||||||
|
}else if(res == SPP_IDX_SPP_HEARTBEAT_VAL){
|
||||||
|
if((p_data->write.len == sizeof(heartbeat_s))&&(memcmp(heartbeat_s,p_data->write.value,sizeof(heartbeat_s)) == 0)){
|
||||||
|
heartbeat_count_num = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else if(res == SPP_IDX_SPP_DATA_RECV_VAL){
|
||||||
|
#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_2, (char *)(p_data->write.value), p_data->write.len);
|
||||||
|
#endif
|
||||||
|
}else{
|
||||||
|
//TODO:
|
||||||
|
}
|
||||||
|
}else if((p_data->write.is_prep == true)&&(res == SPP_IDX_SPP_DATA_RECV_VAL)){
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_PREP_WRITE_EVT : handle = %d\n", res);
|
||||||
|
store_wr_buffer(p_data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//执行写入操作
|
||||||
|
case ESP_GATTS_EXEC_WRITE_EVT:{
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_EXEC_WRITE_EVT\n");
|
||||||
|
if(p_data->exec_write.exec_write_flag){
|
||||||
|
print_write_buffer();
|
||||||
|
free_write_buffer();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ESP_GATTS_MTU_EVT:
|
||||||
|
spp_mtu_size = p_data->mtu.mtu;
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONF_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_UNREG_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_DELETE_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_START_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_STOP_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONNECT_EVT:
|
||||||
|
spp_conn_id = p_data->connect.conn_id;
|
||||||
|
spp_gatts_if = gatts_if;
|
||||||
|
is_connected = true;
|
||||||
|
memcpy(&spp_remote_bda,&p_data->connect.remote_bda,sizeof(esp_bd_addr_t));
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
uint16_t cmd = 0;
|
||||||
|
xQueueSend(cmd_heartbeat_queue,&cmd,10/portTICK_PERIOD_MS);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_DISCONNECT_EVT:
|
||||||
|
is_connected = false;
|
||||||
|
enable_data_ntf = false;
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
enable_heart_ntf = false;
|
||||||
|
heartbeat_count_num = 0;
|
||||||
|
#endif
|
||||||
|
esp_ble_gap_start_advertising(&spp_adv_params);
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_OPEN_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CANCEL_OPEN_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CLOSE_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_LISTEN_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_GATTS_CONGEST_EVT:
|
||||||
|
break;
|
||||||
|
//gatt创建属性表
|
||||||
|
case ESP_GATTS_CREAT_ATTR_TAB_EVT:{
|
||||||
|
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){
|
||||||
|
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 {
|
||||||
|
memcpy(spp_handle_table, param->add_attr_tab.handles, sizeof(spp_handle_table));
|
||||||
|
//启动gatt服务
|
||||||
|
esp_ble_gatts_start_service(spp_handle_table[SPP_IDX_SVC]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*gatt事件回调函数*/ //gatt属于ble的一个协议层
|
||||||
|
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);//打印接口标识符gatts_if
|
||||||
|
|
||||||
|
/* If event is register event, store the gatts_if for each profile */
|
||||||
|
//GATT 注册事件
|
||||||
|
if (event == ESP_GATTS_REG_EVT) {
|
||||||
|
if (param->reg.status == ESP_GATT_OK) {
|
||||||
|
spp_profile_tab[SPP_PROFILE_APP_IDX].gatts_if = gatts_if;
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "Reg app failed, app_id %04x, status %d\n",param->reg.app_id, param->reg.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//循环遍历 spp_profile_tab 结构体中的配置文件,根据条件判断是否需要调用回调函数处理事件
|
||||||
|
do {
|
||||||
|
int idx;
|
||||||
|
for (idx = 0; idx < SPP_PROFILE_NUM; idx++) {
|
||||||
|
|
||||||
|
/* 表示没有指定特定的 gatts_if ,需要调用每个配置文件的回调函数*/
|
||||||
|
if (gatts_if == ESP_GATT_IF_NONE || gatts_if == spp_profile_tab[idx].gatts_if) {
|
||||||
|
if (spp_profile_tab[idx].gatts_cb) {
|
||||||
|
spp_profile_tab[idx].gatts_cb(event, gatts_if, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bt_client_init(void)
|
||||||
|
{
|
||||||
|
esp_err_t ret;
|
||||||
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||||
|
|
||||||
|
/*初始化nvs*/
|
||||||
|
// ret = nvs_flash_init();
|
||||||
|
// if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
// ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
// ret = nvs_flash_init();
|
||||||
|
// }
|
||||||
|
// ESP_ERROR_CHECK( ret );
|
||||||
|
|
||||||
|
/*对 BTDM 控制器的 ROM(只读存储器)数据进行初始化操作*/
|
||||||
|
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||||
|
|
||||||
|
/*蓝牙控制器初始化*/
|
||||||
|
ret = esp_bt_controller_init(&bt_cfg);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*蓝牙控制器使能*/
|
||||||
|
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth\n", __func__);
|
||||||
|
|
||||||
|
/*初始化蓝牙协议栈r*/
|
||||||
|
ret = esp_bluedroid_init();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*使能蓝牙协议栈*/
|
||||||
|
ret = esp_bluedroid_enable();
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*注册ble的gap和gatt回调函数*/
|
||||||
|
esp_ble_gatts_register_callback(gatts_event_handler);
|
||||||
|
esp_ble_gap_register_callback(gap_event_handler);
|
||||||
|
|
||||||
|
/*注册gatt服务应用*/
|
||||||
|
esp_ble_gatts_app_register(ESP_SPP_APP_ID);
|
||||||
|
|
||||||
|
/*spp任务初始化*/
|
||||||
|
spp_task_init(); //初始化uart,创建消息队列以及任务
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
42
main/tmp/bt_server.h
Normal file
42
main/tmp/bt_server.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DEFINES
|
||||||
|
****************************************************************************************
|
||||||
|
*/
|
||||||
|
//#define SUPPORT_HEARTBEAT
|
||||||
|
//#define SPP_DEBUG_MODE
|
||||||
|
|
||||||
|
#define spp_sprintf(s,...) sprintf((char*)(s), ##__VA_ARGS__)
|
||||||
|
#define SPP_DATA_MAX_LEN (512)
|
||||||
|
#define SPP_CMD_MAX_LEN (20)
|
||||||
|
#define SPP_STATUS_MAX_LEN (20)
|
||||||
|
#define SPP_DATA_BUFF_MAX_LEN (2*1024)
|
||||||
|
///Attributes State Machine
|
||||||
|
enum{
|
||||||
|
SPP_IDX_SVC,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_DATA_RECV_CHAR,
|
||||||
|
SPP_IDX_SPP_DATA_RECV_VAL,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_DATA_NOTIFY_CHAR,
|
||||||
|
SPP_IDX_SPP_DATA_NTY_VAL,
|
||||||
|
SPP_IDX_SPP_DATA_NTF_CFG,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_COMMAND_CHAR,
|
||||||
|
SPP_IDX_SPP_COMMAND_VAL,
|
||||||
|
|
||||||
|
SPP_IDX_SPP_STATUS_CHAR,
|
||||||
|
SPP_IDX_SPP_STATUS_VAL,
|
||||||
|
SPP_IDX_SPP_STATUS_CFG,
|
||||||
|
|
||||||
|
#ifdef SUPPORT_HEARTBEAT
|
||||||
|
SPP_IDX_SPP_HEARTBEAT_CHAR,
|
||||||
|
SPP_IDX_SPP_HEARTBEAT_VAL,
|
||||||
|
SPP_IDX_SPP_HEARTBEAT_CFG,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SPP_IDX_NB,
|
||||||
|
};
|
97
pile_com蓝牙传输数据说明.txt
Normal file
97
pile_com蓝牙传输数据说明.txt
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
上位机说明
|
||||||
|
由于MTU限制,建议采用分小包发送的方式进行数据读写,即上位机需要控制写入和读取的长度,不能过长,一般不超过20个字节
|
||||||
|
SERVER UUID:0X00FF
|
||||||
|
|
||||||
|
1. 写参数设置:
|
||||||
|
发送命令到UUID:0XFF01
|
||||||
|
格式:0xf0 byte1 byte2 byte3 ...数据(小端)
|
||||||
|
功能码 写地址 数据长度 数据
|
||||||
|
|
||||||
|
(1)电流:
|
||||||
|
起始地址:0x0180
|
||||||
|
总长度:0x0a
|
||||||
|
数据结构:
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t magic;
|
||||||
|
struct _ch
|
||||||
|
{
|
||||||
|
uint16_t ad_4ma;
|
||||||
|
uint16_t ad_20ma;
|
||||||
|
} ch[2];
|
||||||
|
} cal_4_20ma_t;
|
||||||
|
|
||||||
|
|
||||||
|
(2)流量
|
||||||
|
起始地址:0x0188
|
||||||
|
总长度:0x14
|
||||||
|
数据结构:
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int16_t flow_min;
|
||||||
|
int16_t flow_max;
|
||||||
|
} ad_flow_cal_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t magic;
|
||||||
|
uint16_t input_type;
|
||||||
|
int16_t min_flow[2];
|
||||||
|
ad_flow_cal_t ad_cal[2];
|
||||||
|
uint16_t pulse_coef[2];
|
||||||
|
uint16_t rsv[6];
|
||||||
|
} flow_config_t;
|
||||||
|
|
||||||
|
(3)深度
|
||||||
|
起始地址:0x0198
|
||||||
|
总长度:0x1e
|
||||||
|
数据结构:
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t magic;
|
||||||
|
uint8_t input_type; // 0:正交 1:正交反向 2:方向脉冲 3:方向脉冲反向
|
||||||
|
uint8_t port; // 编码器端口
|
||||||
|
uint16_t N; //编码器系数分子
|
||||||
|
uint16_t M; //编码器系数分母
|
||||||
|
// int pluse_coef; // 脉冲系数0.001mm
|
||||||
|
int16_t min_depth; // 最小深度 mm
|
||||||
|
int16_t max_depth; // 最大深度 mm
|
||||||
|
int16_t sample_depth; // 采样深度 mm
|
||||||
|
int16_t depth_offset; // 默认深度偏移
|
||||||
|
int16_t min_valid_depth; // 最小有效深度
|
||||||
|
int16_t inc_pile_depth; // 允许换桩深度
|
||||||
|
uint16_t current_on_threshold; // 行走电机开启电流
|
||||||
|
uint16_t current_off_threshold; // 行走电机关闭电流
|
||||||
|
uint16_t move_on_duratino; // 持续时间
|
||||||
|
uint16_t move_off_duration; // 持续时间
|
||||||
|
uint16_t move_current_channel; //行走电流通道
|
||||||
|
} depth_config_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
2. 读:
|
||||||
|
发送命令到UUID:0XFF01
|
||||||
|
格式:0xf1 byte1 byte2 byte3
|
||||||
|
功能码 地址 长度
|
||||||
|
监听UUID:0xff01即可得到数据
|
||||||
|
读取得到的数据前面包含发送的信息(发送的命令 + 数据),读取者需要自行处理前面多的数据
|
||||||
|
|
||||||
|
|
||||||
|
3. 上报实时数据:
|
||||||
|
接受端需要开启上报,发送0xF2命令到UUID:0XFF01
|
||||||
|
之后监听UUID:0XFF02即可得到实时数据
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
下位机说明
|
||||||
|
1. 如需添加上报数据,在 ble_gatts_server.c文件的notify_all_data 函数中添加即可
|
||||||
|
2. 如需响应上位机的控制,例如开始和暂停按键,则需要在 stm32/ModbusS.c 中的 ModBusWordWriteHook 函数中添加写入特定值的响应操作
|
||||||
|
目前只实现的配置参数保存的响应,其他的没有实现
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
322
sdkconfig
322
sdkconfig
@ -1,22 +1,24 @@
|
|||||||
#
|
#
|
||||||
# Automatically generated file. DO NOT EDIT.
|
# Automatically generated file. DO NOT EDIT.
|
||||||
# Espressif IoT Development Framework (ESP-IDF) 5.1.2 Project Configuration
|
# Espressif IoT Development Framework (ESP-IDF) Project Configuration
|
||||||
#
|
#
|
||||||
|
CONFIG_SOC_LEDC_SUPPORT_APB_CLOCK=y
|
||||||
|
CONFIG_SOC_LEDC_SUPPORT_XTAL_CLOCK=y
|
||||||
|
CONFIG_SOC_LEDC_CHANNEL_NUM=8
|
||||||
|
CONFIG_SOC_LEDC_TIMER_BIT_WIDE_NUM=14
|
||||||
|
CONFIG_SOC_LEDC_SUPPORT_FADE_STOP=y
|
||||||
CONFIG_SOC_MPU_MIN_REGION_SIZE=0x20000000
|
CONFIG_SOC_MPU_MIN_REGION_SIZE=0x20000000
|
||||||
CONFIG_SOC_MPU_REGIONS_MAX_NUM=8
|
CONFIG_SOC_MPU_REGIONS_MAX_NUM=8
|
||||||
CONFIG_SOC_ADC_SUPPORTED=y
|
CONFIG_SOC_ADC_SUPPORTED=y
|
||||||
CONFIG_SOC_UART_SUPPORTED=y
|
|
||||||
CONFIG_SOC_PCNT_SUPPORTED=y
|
CONFIG_SOC_PCNT_SUPPORTED=y
|
||||||
CONFIG_SOC_WIFI_SUPPORTED=y
|
CONFIG_SOC_WIFI_SUPPORTED=y
|
||||||
CONFIG_SOC_TWAI_SUPPORTED=y
|
CONFIG_SOC_TWAI_SUPPORTED=y
|
||||||
CONFIG_SOC_GDMA_SUPPORTED=y
|
CONFIG_SOC_GDMA_SUPPORTED=y
|
||||||
CONFIG_SOC_GPTIMER_SUPPORTED=y
|
|
||||||
CONFIG_SOC_LCDCAM_SUPPORTED=y
|
CONFIG_SOC_LCDCAM_SUPPORTED=y
|
||||||
CONFIG_SOC_MCPWM_SUPPORTED=y
|
CONFIG_SOC_MCPWM_SUPPORTED=y
|
||||||
CONFIG_SOC_DEDICATED_GPIO_SUPPORTED=y
|
CONFIG_SOC_DEDICATED_GPIO_SUPPORTED=y
|
||||||
CONFIG_SOC_CACHE_SUPPORT_WRAP=y
|
CONFIG_SOC_CACHE_SUPPORT_WRAP=y
|
||||||
CONFIG_SOC_ULP_SUPPORTED=y
|
CONFIG_SOC_ULP_SUPPORTED=y
|
||||||
CONFIG_SOC_ULP_FSM_SUPPORTED=y
|
|
||||||
CONFIG_SOC_RISCV_COPROC_SUPPORTED=y
|
CONFIG_SOC_RISCV_COPROC_SUPPORTED=y
|
||||||
CONFIG_SOC_BT_SUPPORTED=y
|
CONFIG_SOC_BT_SUPPORTED=y
|
||||||
CONFIG_SOC_USB_OTG_SUPPORTED=y
|
CONFIG_SOC_USB_OTG_SUPPORTED=y
|
||||||
@ -34,9 +36,6 @@ CONFIG_SOC_XT_WDT_SUPPORTED=y
|
|||||||
CONFIG_SOC_I2S_SUPPORTED=y
|
CONFIG_SOC_I2S_SUPPORTED=y
|
||||||
CONFIG_SOC_RMT_SUPPORTED=y
|
CONFIG_SOC_RMT_SUPPORTED=y
|
||||||
CONFIG_SOC_SDM_SUPPORTED=y
|
CONFIG_SOC_SDM_SUPPORTED=y
|
||||||
CONFIG_SOC_GPSPI_SUPPORTED=y
|
|
||||||
CONFIG_SOC_LEDC_SUPPORTED=y
|
|
||||||
CONFIG_SOC_I2C_SUPPORTED=y
|
|
||||||
CONFIG_SOC_SYSTIMER_SUPPORTED=y
|
CONFIG_SOC_SYSTIMER_SUPPORTED=y
|
||||||
CONFIG_SOC_SUPPORT_COEXISTENCE=y
|
CONFIG_SOC_SUPPORT_COEXISTENCE=y
|
||||||
CONFIG_SOC_TEMP_SENSOR_SUPPORTED=y
|
CONFIG_SOC_TEMP_SENSOR_SUPPORTED=y
|
||||||
@ -49,13 +48,12 @@ CONFIG_SOC_FLASH_ENC_SUPPORTED=y
|
|||||||
CONFIG_SOC_SECURE_BOOT_SUPPORTED=y
|
CONFIG_SOC_SECURE_BOOT_SUPPORTED=y
|
||||||
CONFIG_SOC_MEMPROT_SUPPORTED=y
|
CONFIG_SOC_MEMPROT_SUPPORTED=y
|
||||||
CONFIG_SOC_TOUCH_SENSOR_SUPPORTED=y
|
CONFIG_SOC_TOUCH_SENSOR_SUPPORTED=y
|
||||||
CONFIG_SOC_BOD_SUPPORTED=y
|
|
||||||
CONFIG_SOC_XTAL_SUPPORT_40M=y
|
CONFIG_SOC_XTAL_SUPPORT_40M=y
|
||||||
CONFIG_SOC_APPCPU_HAS_CLOCK_GATING_BUG=y
|
CONFIG_SOC_APPCPU_HAS_CLOCK_GATING_BUG=y
|
||||||
CONFIG_SOC_ADC_RTC_CTRL_SUPPORTED=y
|
CONFIG_SOC_ADC_RTC_CTRL_SUPPORTED=y
|
||||||
CONFIG_SOC_ADC_DIG_CTRL_SUPPORTED=y
|
CONFIG_SOC_ADC_DIG_CTRL_SUPPORTED=y
|
||||||
CONFIG_SOC_ADC_ARBITER_SUPPORTED=y
|
CONFIG_SOC_ADC_ARBITER_SUPPORTED=y
|
||||||
CONFIG_SOC_ADC_DIG_IIR_FILTER_SUPPORTED=y
|
CONFIG_SOC_ADC_FILTER_SUPPORTED=y
|
||||||
CONFIG_SOC_ADC_MONITOR_SUPPORTED=y
|
CONFIG_SOC_ADC_MONITOR_SUPPORTED=y
|
||||||
CONFIG_SOC_ADC_DMA_SUPPORTED=y
|
CONFIG_SOC_ADC_DMA_SUPPORTED=y
|
||||||
CONFIG_SOC_ADC_PERIPH_NUM=2
|
CONFIG_SOC_ADC_PERIPH_NUM=2
|
||||||
@ -67,17 +65,15 @@ CONFIG_SOC_ADC_DIGI_MIN_BITWIDTH=12
|
|||||||
CONFIG_SOC_ADC_DIGI_MAX_BITWIDTH=12
|
CONFIG_SOC_ADC_DIGI_MAX_BITWIDTH=12
|
||||||
CONFIG_SOC_ADC_DIGI_RESULT_BYTES=4
|
CONFIG_SOC_ADC_DIGI_RESULT_BYTES=4
|
||||||
CONFIG_SOC_ADC_DIGI_DATA_BYTES_PER_CONV=4
|
CONFIG_SOC_ADC_DIGI_DATA_BYTES_PER_CONV=4
|
||||||
CONFIG_SOC_ADC_DIGI_IIR_FILTER_NUM=2
|
|
||||||
CONFIG_SOC_ADC_SAMPLE_FREQ_THRES_HIGH=83333
|
CONFIG_SOC_ADC_SAMPLE_FREQ_THRES_HIGH=83333
|
||||||
CONFIG_SOC_ADC_SAMPLE_FREQ_THRES_LOW=611
|
CONFIG_SOC_ADC_SAMPLE_FREQ_THRES_LOW=611
|
||||||
CONFIG_SOC_ADC_RTC_MIN_BITWIDTH=12
|
CONFIG_SOC_ADC_RTC_MIN_BITWIDTH=12
|
||||||
CONFIG_SOC_ADC_RTC_MAX_BITWIDTH=12
|
CONFIG_SOC_ADC_RTC_MAX_BITWIDTH=12
|
||||||
|
CONFIG_SOC_RTC_SLOW_CLOCK_SUPPORT_8MD256=y
|
||||||
CONFIG_SOC_ADC_CALIBRATION_V1_SUPPORTED=y
|
CONFIG_SOC_ADC_CALIBRATION_V1_SUPPORTED=y
|
||||||
CONFIG_SOC_ADC_SELF_HW_CALI_SUPPORTED=y
|
|
||||||
CONFIG_SOC_APB_BACKUP_DMA=y
|
CONFIG_SOC_APB_BACKUP_DMA=y
|
||||||
CONFIG_SOC_BROWNOUT_RESET_SUPPORTED=y
|
CONFIG_SOC_BROWNOUT_RESET_SUPPORTED=y
|
||||||
CONFIG_SOC_CACHE_WRITEBACK_SUPPORTED=y
|
CONFIG_SOC_MMU_LINEAR_ADDRESS_REGION_NUM=1
|
||||||
CONFIG_SOC_CACHE_FREEZE_SUPPORTED=y
|
|
||||||
CONFIG_SOC_CPU_CORES_NUM=2
|
CONFIG_SOC_CPU_CORES_NUM=2
|
||||||
CONFIG_SOC_CPU_INTR_NUM=32
|
CONFIG_SOC_CPU_INTR_NUM=32
|
||||||
CONFIG_SOC_CPU_HAS_FPU=y
|
CONFIG_SOC_CPU_HAS_FPU=y
|
||||||
@ -90,10 +86,9 @@ CONFIG_SOC_DS_KEY_CHECK_MAX_WAIT_US=1100
|
|||||||
CONFIG_SOC_GDMA_GROUPS=y
|
CONFIG_SOC_GDMA_GROUPS=y
|
||||||
CONFIG_SOC_GDMA_PAIRS_PER_GROUP=5
|
CONFIG_SOC_GDMA_PAIRS_PER_GROUP=5
|
||||||
CONFIG_SOC_GDMA_SUPPORT_PSRAM=y
|
CONFIG_SOC_GDMA_SUPPORT_PSRAM=y
|
||||||
|
CONFIG_SOC_GDMA_PSRAM_MIN_ALIGN=16
|
||||||
CONFIG_SOC_GPIO_PORT=1
|
CONFIG_SOC_GPIO_PORT=1
|
||||||
CONFIG_SOC_GPIO_PIN_COUNT=49
|
CONFIG_SOC_GPIO_PIN_COUNT=49
|
||||||
CONFIG_SOC_GPIO_SUPPORT_PIN_GLITCH_FILTER=y
|
|
||||||
CONFIG_SOC_GPIO_FILTER_CLK_SUPPORT_APB=y
|
|
||||||
CONFIG_SOC_GPIO_SUPPORT_RTC_INDEPENDENT=y
|
CONFIG_SOC_GPIO_SUPPORT_RTC_INDEPENDENT=y
|
||||||
CONFIG_SOC_GPIO_SUPPORT_FORCE_HOLD=y
|
CONFIG_SOC_GPIO_SUPPORT_FORCE_HOLD=y
|
||||||
CONFIG_SOC_GPIO_VALID_GPIO_MASK=0x1FFFFFFFFFFFF
|
CONFIG_SOC_GPIO_VALID_GPIO_MASK=0x1FFFFFFFFFFFF
|
||||||
@ -103,27 +98,18 @@ CONFIG_SOC_DEDIC_GPIO_IN_CHANNELS_NUM=8
|
|||||||
CONFIG_SOC_DEDIC_GPIO_OUT_AUTO_ENABLE=y
|
CONFIG_SOC_DEDIC_GPIO_OUT_AUTO_ENABLE=y
|
||||||
CONFIG_SOC_I2C_NUM=2
|
CONFIG_SOC_I2C_NUM=2
|
||||||
CONFIG_SOC_I2C_FIFO_LEN=32
|
CONFIG_SOC_I2C_FIFO_LEN=32
|
||||||
CONFIG_SOC_I2C_CMD_REG_NUM=8
|
|
||||||
CONFIG_SOC_I2C_SUPPORT_SLAVE=y
|
CONFIG_SOC_I2C_SUPPORT_SLAVE=y
|
||||||
CONFIG_SOC_I2C_SUPPORT_HW_CLR_BUS=y
|
CONFIG_SOC_I2C_SUPPORT_HW_CLR_BUS=y
|
||||||
CONFIG_SOC_I2C_SUPPORT_XTAL=y
|
CONFIG_SOC_I2C_SUPPORT_XTAL=y
|
||||||
CONFIG_SOC_I2C_SUPPORT_RTC=y
|
CONFIG_SOC_I2C_SUPPORT_RTC=y
|
||||||
CONFIG_SOC_I2S_NUM=2
|
CONFIG_SOC_I2S_NUM=2
|
||||||
CONFIG_SOC_I2S_HW_VERSION_2=y
|
CONFIG_SOC_I2S_HW_VERSION_2=y
|
||||||
CONFIG_SOC_I2S_SUPPORTS_XTAL=y
|
|
||||||
CONFIG_SOC_I2S_SUPPORTS_PLL_F160M=y
|
|
||||||
CONFIG_SOC_I2S_SUPPORTS_PCM=y
|
CONFIG_SOC_I2S_SUPPORTS_PCM=y
|
||||||
CONFIG_SOC_I2S_SUPPORTS_PDM=y
|
CONFIG_SOC_I2S_SUPPORTS_PDM=y
|
||||||
CONFIG_SOC_I2S_SUPPORTS_PDM_TX=y
|
CONFIG_SOC_I2S_SUPPORTS_PDM_TX=y
|
||||||
CONFIG_SOC_I2S_PDM_MAX_TX_LINES=2
|
|
||||||
CONFIG_SOC_I2S_SUPPORTS_PDM_RX=y
|
CONFIG_SOC_I2S_SUPPORTS_PDM_RX=y
|
||||||
CONFIG_SOC_I2S_PDM_MAX_RX_LINES=4
|
CONFIG_SOC_I2S_SUPPORTS_PDM_CODEC=y
|
||||||
CONFIG_SOC_I2S_SUPPORTS_TDM=y
|
CONFIG_SOC_I2S_SUPPORTS_TDM=y
|
||||||
CONFIG_SOC_LEDC_SUPPORT_APB_CLOCK=y
|
|
||||||
CONFIG_SOC_LEDC_SUPPORT_XTAL_CLOCK=y
|
|
||||||
CONFIG_SOC_LEDC_CHANNEL_NUM=8
|
|
||||||
CONFIG_SOC_LEDC_TIMER_BIT_WIDTH=14
|
|
||||||
CONFIG_SOC_LEDC_SUPPORT_FADE_STOP=y
|
|
||||||
CONFIG_SOC_MCPWM_GROUPS=2
|
CONFIG_SOC_MCPWM_GROUPS=2
|
||||||
CONFIG_SOC_MCPWM_TIMERS_PER_GROUP=3
|
CONFIG_SOC_MCPWM_TIMERS_PER_GROUP=3
|
||||||
CONFIG_SOC_MCPWM_OPERATORS_PER_GROUP=3
|
CONFIG_SOC_MCPWM_OPERATORS_PER_GROUP=3
|
||||||
@ -135,9 +121,7 @@ CONFIG_SOC_MCPWM_CAPTURE_TIMERS_PER_GROUP=y
|
|||||||
CONFIG_SOC_MCPWM_CAPTURE_CHANNELS_PER_TIMER=3
|
CONFIG_SOC_MCPWM_CAPTURE_CHANNELS_PER_TIMER=3
|
||||||
CONFIG_SOC_MCPWM_GPIO_SYNCHROS_PER_GROUP=3
|
CONFIG_SOC_MCPWM_GPIO_SYNCHROS_PER_GROUP=3
|
||||||
CONFIG_SOC_MCPWM_SWSYNC_CAN_PROPAGATE=y
|
CONFIG_SOC_MCPWM_SWSYNC_CAN_PROPAGATE=y
|
||||||
CONFIG_SOC_MMU_LINEAR_ADDRESS_REGION_NUM=1
|
CONFIG_SOC_PCNT_GROUPS=y
|
||||||
CONFIG_SOC_MMU_PERIPH_NUM=1
|
|
||||||
CONFIG_SOC_PCNT_GROUPS=1
|
|
||||||
CONFIG_SOC_PCNT_UNITS_PER_GROUP=4
|
CONFIG_SOC_PCNT_UNITS_PER_GROUP=4
|
||||||
CONFIG_SOC_PCNT_CHANNELS_PER_UNIT=2
|
CONFIG_SOC_PCNT_CHANNELS_PER_UNIT=2
|
||||||
CONFIG_SOC_PCNT_THRES_POINT_PER_UNIT=2
|
CONFIG_SOC_PCNT_THRES_POINT_PER_UNIT=2
|
||||||
@ -173,7 +157,6 @@ CONFIG_SOC_RTCIO_HOLD_SUPPORTED=y
|
|||||||
CONFIG_SOC_RTCIO_WAKE_SUPPORTED=y
|
CONFIG_SOC_RTCIO_WAKE_SUPPORTED=y
|
||||||
CONFIG_SOC_SDM_GROUPS=y
|
CONFIG_SOC_SDM_GROUPS=y
|
||||||
CONFIG_SOC_SDM_CHANNELS_PER_GROUP=8
|
CONFIG_SOC_SDM_CHANNELS_PER_GROUP=8
|
||||||
CONFIG_SOC_SDM_CLK_SUPPORT_APB=y
|
|
||||||
CONFIG_SOC_SPI_PERIPH_NUM=3
|
CONFIG_SOC_SPI_PERIPH_NUM=3
|
||||||
CONFIG_SOC_SPI_MAX_CS_NUM=6
|
CONFIG_SOC_SPI_MAX_CS_NUM=6
|
||||||
CONFIG_SOC_SPI_MAXIMUM_BUFFER_SIZE=64
|
CONFIG_SOC_SPI_MAXIMUM_BUFFER_SIZE=64
|
||||||
@ -182,8 +165,6 @@ CONFIG_SOC_SPI_SLAVE_SUPPORT_SEG_TRANS=y
|
|||||||
CONFIG_SOC_SPI_SUPPORT_CD_SIG=y
|
CONFIG_SOC_SPI_SUPPORT_CD_SIG=y
|
||||||
CONFIG_SOC_SPI_SUPPORT_CONTINUOUS_TRANS=y
|
CONFIG_SOC_SPI_SUPPORT_CONTINUOUS_TRANS=y
|
||||||
CONFIG_SOC_SPI_SUPPORT_SLAVE_HD_VER2=y
|
CONFIG_SOC_SPI_SUPPORT_SLAVE_HD_VER2=y
|
||||||
CONFIG_SOC_SPI_SUPPORT_CLK_APB=y
|
|
||||||
CONFIG_SOC_SPI_SUPPORT_CLK_XTAL=y
|
|
||||||
CONFIG_SOC_SPI_PERIPH_SUPPORT_CONTROL_DUMMY_OUT=y
|
CONFIG_SOC_SPI_PERIPH_SUPPORT_CONTROL_DUMMY_OUT=y
|
||||||
CONFIG_SOC_MEMSPI_IS_INDEPENDENT=y
|
CONFIG_SOC_MEMSPI_IS_INDEPENDENT=y
|
||||||
CONFIG_SOC_SPI_MAX_PRE_DIVIDER=16
|
CONFIG_SOC_SPI_MAX_PRE_DIVIDER=16
|
||||||
@ -193,7 +174,6 @@ CONFIG_SOC_MEMSPI_SRC_FREQ_80M_SUPPORTED=y
|
|||||||
CONFIG_SOC_MEMSPI_SRC_FREQ_40M_SUPPORTED=y
|
CONFIG_SOC_MEMSPI_SRC_FREQ_40M_SUPPORTED=y
|
||||||
CONFIG_SOC_MEMSPI_SRC_FREQ_20M_SUPPORTED=y
|
CONFIG_SOC_MEMSPI_SRC_FREQ_20M_SUPPORTED=y
|
||||||
CONFIG_SOC_SPIRAM_SUPPORTED=y
|
CONFIG_SOC_SPIRAM_SUPPORTED=y
|
||||||
CONFIG_SOC_SPIRAM_XIP_SUPPORTED=y
|
|
||||||
CONFIG_SOC_SYSTIMER_COUNTER_NUM=2
|
CONFIG_SOC_SYSTIMER_COUNTER_NUM=2
|
||||||
CONFIG_SOC_SYSTIMER_ALARM_NUM=3
|
CONFIG_SOC_SYSTIMER_ALARM_NUM=3
|
||||||
CONFIG_SOC_SYSTIMER_BIT_WIDTH_LO=32
|
CONFIG_SOC_SYSTIMER_BIT_WIDTH_LO=32
|
||||||
@ -213,11 +193,6 @@ CONFIG_SOC_TOUCH_PROXIMITY_CHANNEL_NUM=3
|
|||||||
CONFIG_SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED=y
|
CONFIG_SOC_TOUCH_PROXIMITY_MEAS_DONE_SUPPORTED=y
|
||||||
CONFIG_SOC_TOUCH_PAD_THRESHOLD_MAX=0x1FFFFF
|
CONFIG_SOC_TOUCH_PAD_THRESHOLD_MAX=0x1FFFFF
|
||||||
CONFIG_SOC_TOUCH_PAD_MEASURE_WAIT_MAX=0xFF
|
CONFIG_SOC_TOUCH_PAD_MEASURE_WAIT_MAX=0xFF
|
||||||
CONFIG_SOC_TWAI_CONTROLLER_NUM=1
|
|
||||||
CONFIG_SOC_TWAI_CLK_SUPPORT_APB=y
|
|
||||||
CONFIG_SOC_TWAI_BRP_MIN=2
|
|
||||||
CONFIG_SOC_TWAI_BRP_MAX=16384
|
|
||||||
CONFIG_SOC_TWAI_SUPPORTS_RX_STATUS=y
|
|
||||||
CONFIG_SOC_UART_NUM=3
|
CONFIG_SOC_UART_NUM=3
|
||||||
CONFIG_SOC_UART_FIFO_LEN=128
|
CONFIG_SOC_UART_FIFO_LEN=128
|
||||||
CONFIG_SOC_UART_BITRATE_MAX=5000000
|
CONFIG_SOC_UART_BITRATE_MAX=5000000
|
||||||
@ -245,8 +220,6 @@ CONFIG_SOC_AES_SUPPORT_DMA=y
|
|||||||
CONFIG_SOC_AES_GDMA=y
|
CONFIG_SOC_AES_GDMA=y
|
||||||
CONFIG_SOC_AES_SUPPORT_AES_128=y
|
CONFIG_SOC_AES_SUPPORT_AES_128=y
|
||||||
CONFIG_SOC_AES_SUPPORT_AES_256=y
|
CONFIG_SOC_AES_SUPPORT_AES_256=y
|
||||||
CONFIG_SOC_PM_SUPPORT_EXT0_WAKEUP=y
|
|
||||||
CONFIG_SOC_PM_SUPPORT_EXT1_WAKEUP=y
|
|
||||||
CONFIG_SOC_PM_SUPPORT_EXT_WAKEUP=y
|
CONFIG_SOC_PM_SUPPORT_EXT_WAKEUP=y
|
||||||
CONFIG_SOC_PM_SUPPORT_WIFI_WAKEUP=y
|
CONFIG_SOC_PM_SUPPORT_WIFI_WAKEUP=y
|
||||||
CONFIG_SOC_PM_SUPPORT_BT_WAKEUP=y
|
CONFIG_SOC_PM_SUPPORT_BT_WAKEUP=y
|
||||||
@ -254,25 +227,13 @@ CONFIG_SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP=y
|
|||||||
CONFIG_SOC_PM_SUPPORT_CPU_PD=y
|
CONFIG_SOC_PM_SUPPORT_CPU_PD=y
|
||||||
CONFIG_SOC_PM_SUPPORT_TAGMEM_PD=y
|
CONFIG_SOC_PM_SUPPORT_TAGMEM_PD=y
|
||||||
CONFIG_SOC_PM_SUPPORT_RTC_PERIPH_PD=y
|
CONFIG_SOC_PM_SUPPORT_RTC_PERIPH_PD=y
|
||||||
CONFIG_SOC_PM_SUPPORT_RC_FAST_PD=y
|
|
||||||
CONFIG_SOC_PM_SUPPORT_VDDSDIO_PD=y
|
|
||||||
CONFIG_SOC_PM_SUPPORT_MAC_BB_PD=y
|
|
||||||
CONFIG_SOC_PM_SUPPORT_MODEM_PD=y
|
CONFIG_SOC_PM_SUPPORT_MODEM_PD=y
|
||||||
CONFIG_SOC_CONFIGURABLE_VDDSDIO_SUPPORTED=y
|
|
||||||
CONFIG_SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY=y
|
CONFIG_SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY=y
|
||||||
CONFIG_SOC_PM_CPU_RETENTION_BY_RTCCNTL=y
|
|
||||||
CONFIG_SOC_PM_MODEM_RETENTION_BY_BACKUPDMA=y
|
|
||||||
CONFIG_SOC_CLK_RC_FAST_D256_SUPPORTED=y
|
|
||||||
CONFIG_SOC_RTC_SLOW_CLK_SUPPORT_RC_FAST_D256=y
|
|
||||||
CONFIG_SOC_CLK_RC_FAST_SUPPORT_CALIBRATION=y
|
|
||||||
CONFIG_SOC_CLK_XTAL32K_SUPPORTED=y
|
|
||||||
CONFIG_SOC_EFUSE_DIS_DOWNLOAD_ICACHE=y
|
|
||||||
CONFIG_SOC_EFUSE_DIS_DOWNLOAD_DCACHE=y
|
CONFIG_SOC_EFUSE_DIS_DOWNLOAD_DCACHE=y
|
||||||
CONFIG_SOC_EFUSE_HARD_DIS_JTAG=y
|
CONFIG_SOC_EFUSE_HARD_DIS_JTAG=y
|
||||||
CONFIG_SOC_EFUSE_DIS_USB_JTAG=y
|
CONFIG_SOC_EFUSE_DIS_USB_JTAG=y
|
||||||
CONFIG_SOC_EFUSE_SOFT_DIS_JTAG=y
|
CONFIG_SOC_EFUSE_SOFT_DIS_JTAG=y
|
||||||
CONFIG_SOC_EFUSE_DIS_DIRECT_BOOT=y
|
CONFIG_SOC_EFUSE_DIS_DIRECT_BOOT=y
|
||||||
CONFIG_SOC_EFUSE_DIS_ICACHE=y
|
|
||||||
CONFIG_SOC_EFUSE_BLOCK9_KEY_PURPOSE_QUIRK=y
|
CONFIG_SOC_EFUSE_BLOCK9_KEY_PURPOSE_QUIRK=y
|
||||||
CONFIG_SOC_SECURE_BOOT_V2_RSA=y
|
CONFIG_SOC_SECURE_BOOT_V2_RSA=y
|
||||||
CONFIG_SOC_EFUSE_SECURE_BOOT_KEY_DIGESTS=3
|
CONFIG_SOC_EFUSE_SECURE_BOOT_KEY_DIGESTS=3
|
||||||
@ -295,9 +256,7 @@ CONFIG_SOC_SPI_MEM_SUPPORT_SW_SUSPEND=y
|
|||||||
CONFIG_SOC_SPI_MEM_SUPPORT_OPI_MODE=y
|
CONFIG_SOC_SPI_MEM_SUPPORT_OPI_MODE=y
|
||||||
CONFIG_SOC_SPI_MEM_SUPPORT_TIME_TUNING=y
|
CONFIG_SOC_SPI_MEM_SUPPORT_TIME_TUNING=y
|
||||||
CONFIG_SOC_SPI_MEM_SUPPORT_CONFIG_GPIO_BY_EFUSE=y
|
CONFIG_SOC_SPI_MEM_SUPPORT_CONFIG_GPIO_BY_EFUSE=y
|
||||||
CONFIG_SOC_SPI_MEM_SUPPORT_WRAP=y
|
|
||||||
CONFIG_SOC_COEX_HW_PTI=y
|
CONFIG_SOC_COEX_HW_PTI=y
|
||||||
CONFIG_SOC_EXTERNAL_COEX_LEADER_TX_LINE=y
|
|
||||||
CONFIG_SOC_SDMMC_USE_GPIO_MATRIX=y
|
CONFIG_SOC_SDMMC_USE_GPIO_MATRIX=y
|
||||||
CONFIG_SOC_SDMMC_NUM_SLOTS=2
|
CONFIG_SOC_SDMMC_NUM_SLOTS=2
|
||||||
CONFIG_SOC_SDMMC_SUPPORT_XTAL_CLOCK=y
|
CONFIG_SOC_SDMMC_SUPPORT_XTAL_CLOCK=y
|
||||||
@ -308,14 +267,13 @@ CONFIG_SOC_WIFI_GCMP_SUPPORT=y
|
|||||||
CONFIG_SOC_WIFI_WAPI_SUPPORT=y
|
CONFIG_SOC_WIFI_WAPI_SUPPORT=y
|
||||||
CONFIG_SOC_WIFI_CSI_SUPPORT=y
|
CONFIG_SOC_WIFI_CSI_SUPPORT=y
|
||||||
CONFIG_SOC_WIFI_MESH_SUPPORT=y
|
CONFIG_SOC_WIFI_MESH_SUPPORT=y
|
||||||
CONFIG_SOC_WIFI_SUPPORT_VARIABLE_BEACON_WINDOW=y
|
|
||||||
CONFIG_SOC_BLE_SUPPORTED=y
|
CONFIG_SOC_BLE_SUPPORTED=y
|
||||||
CONFIG_SOC_BLE_MESH_SUPPORTED=y
|
CONFIG_SOC_BLE_MESH_SUPPORTED=y
|
||||||
CONFIG_SOC_BLE_50_SUPPORTED=y
|
CONFIG_SOC_BLE_50_SUPPORTED=y
|
||||||
CONFIG_SOC_BLE_DEVICE_PRIVACY_SUPPORTED=y
|
CONFIG_SOC_BLE_DEVICE_PRIVACY_SUPPORTED=y
|
||||||
CONFIG_SOC_BLUFI_SUPPORTED=y
|
CONFIG_SOC_TWAI_BRP_MIN=2
|
||||||
CONFIG_SOC_ULP_HAS_ADC=y
|
CONFIG_SOC_TWAI_BRP_MAX=16384
|
||||||
CONFIG_SOC_PHY_COMBO_MODULE=y
|
CONFIG_SOC_TWAI_SUPPORTS_RX_STATUS=y
|
||||||
CONFIG_IDF_CMAKE=y
|
CONFIG_IDF_CMAKE=y
|
||||||
CONFIG_IDF_TARGET_ARCH_XTENSA=y
|
CONFIG_IDF_TARGET_ARCH_XTENSA=y
|
||||||
CONFIG_IDF_TARGET_ARCH="xtensa"
|
CONFIG_IDF_TARGET_ARCH="xtensa"
|
||||||
@ -327,7 +285,7 @@ CONFIG_IDF_FIRMWARE_CHIP_ID=0x0009
|
|||||||
# Build type
|
# Build type
|
||||||
#
|
#
|
||||||
CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y
|
CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y
|
||||||
# CONFIG_APP_BUILD_TYPE_RAM is not set
|
# CONFIG_APP_BUILD_TYPE_ELF_RAM is not set
|
||||||
CONFIG_APP_BUILD_GENERATE_BINARIES=y
|
CONFIG_APP_BUILD_GENERATE_BINARIES=y
|
||||||
CONFIG_APP_BUILD_BOOTLOADER=y
|
CONFIG_APP_BUILD_BOOTLOADER=y
|
||||||
CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y
|
CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y
|
||||||
@ -393,20 +351,17 @@ CONFIG_ESP_ROM_HAS_MZ_CRC32=y
|
|||||||
CONFIG_ESP_ROM_HAS_JPEG_DECODE=y
|
CONFIG_ESP_ROM_HAS_JPEG_DECODE=y
|
||||||
CONFIG_ESP_ROM_UART_CLK_IS_XTAL=y
|
CONFIG_ESP_ROM_UART_CLK_IS_XTAL=y
|
||||||
CONFIG_ESP_ROM_HAS_RETARGETABLE_LOCKING=y
|
CONFIG_ESP_ROM_HAS_RETARGETABLE_LOCKING=y
|
||||||
|
CONFIG_ESP_ROM_USB_OTG_NUM=3
|
||||||
CONFIG_ESP_ROM_USB_SERIAL_DEVICE_NUM=4
|
CONFIG_ESP_ROM_USB_SERIAL_DEVICE_NUM=4
|
||||||
CONFIG_ESP_ROM_HAS_ERASE_0_REGION_BUG=y
|
CONFIG_ESP_ROM_HAS_ERASE_0_REGION_BUG=y
|
||||||
CONFIG_ESP_ROM_GET_CLK_FREQ=y
|
CONFIG_ESP_ROM_GET_CLK_FREQ=y
|
||||||
CONFIG_ESP_ROM_HAS_HAL_WDT=y
|
CONFIG_ESP_ROM_HAS_HAL_WDT=y
|
||||||
CONFIG_ESP_ROM_NEEDS_SWSETUP_WORKAROUND=y
|
CONFIG_ESP_ROM_NEEDS_SWSETUP_WORKAROUND=y
|
||||||
CONFIG_ESP_ROM_HAS_LAYOUT_TABLE=y
|
|
||||||
CONFIG_ESP_ROM_HAS_SPI_FLASH=y
|
|
||||||
CONFIG_ESP_ROM_HAS_ETS_PRINTF_BUG=y
|
CONFIG_ESP_ROM_HAS_ETS_PRINTF_BUG=y
|
||||||
CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y
|
|
||||||
CONFIG_ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE=y
|
|
||||||
CONFIG_ESP_ROM_RAM_APP_NEEDS_MMU_INIT=y
|
|
||||||
CONFIG_ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG=y
|
CONFIG_ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG=y
|
||||||
CONFIG_ESP_ROM_HAS_CACHE_SUSPEND_WAITI_BUG=y
|
CONFIG_ESP_ROM_HAS_CACHE_SUSPEND_WAITI_BUG=y
|
||||||
CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG=y
|
CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG=y
|
||||||
|
CONFIG_ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE=y
|
||||||
|
|
||||||
#
|
#
|
||||||
# Boot ROM Behavior
|
# Boot ROM Behavior
|
||||||
@ -422,7 +377,6 @@ CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y
|
|||||||
#
|
#
|
||||||
# CONFIG_ESPTOOLPY_NO_STUB is not set
|
# CONFIG_ESPTOOLPY_NO_STUB is not set
|
||||||
# CONFIG_ESPTOOLPY_OCT_FLASH is not set
|
# CONFIG_ESPTOOLPY_OCT_FLASH is not set
|
||||||
CONFIG_ESPTOOLPY_FLASH_MODE_AUTO_DETECT=y
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set
|
# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set
|
||||||
# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set
|
# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set
|
||||||
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
|
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
|
||||||
@ -433,7 +387,6 @@ CONFIG_ESPTOOLPY_FLASHMODE="dio"
|
|||||||
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
||||||
# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set
|
# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set
|
||||||
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
|
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
|
||||||
CONFIG_ESPTOOLPY_FLASHFREQ_80M_DEFAULT=y
|
|
||||||
CONFIG_ESPTOOLPY_FLASHFREQ="80m"
|
CONFIG_ESPTOOLPY_FLASHFREQ="80m"
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
||||||
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
|
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
|
||||||
@ -504,7 +457,6 @@ CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y
|
|||||||
# CONFIG_COMPILER_STACK_CHECK_MODE_STRONG is not set
|
# CONFIG_COMPILER_STACK_CHECK_MODE_STRONG is not set
|
||||||
# CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set
|
# CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set
|
||||||
# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set
|
# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set
|
||||||
# CONFIG_COMPILER_DISABLE_GCC12_WARNINGS is not set
|
|
||||||
# CONFIG_COMPILER_DUMP_RTL_FILES is not set
|
# CONFIG_COMPILER_DUMP_RTL_FILES is not set
|
||||||
# end of Compiler options
|
# end of Compiler options
|
||||||
|
|
||||||
@ -553,9 +505,6 @@ CONFIG_BT_GATT_MAX_SR_ATTRIBUTES=100
|
|||||||
# CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set
|
# CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set
|
||||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO=y
|
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO=y
|
||||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
|
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
|
||||||
# CONFIG_BT_GATTS_ROBUST_CACHING_ENABLED is not set
|
|
||||||
# CONFIG_BT_GATTS_DEVICE_NAME_WRITABLE is not set
|
|
||||||
# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set
|
|
||||||
CONFIG_BT_GATTC_ENABLE=y
|
CONFIG_BT_GATTC_ENABLE=y
|
||||||
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
|
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
|
||||||
# CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set
|
# CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set
|
||||||
@ -746,10 +695,8 @@ CONFIG_BT_SMP_ENABLE=y
|
|||||||
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
|
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
|
||||||
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
|
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
|
||||||
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
|
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
|
||||||
CONFIG_BT_BLE_RPA_TIMEOUT=900
|
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
|
||||||
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y
|
|
||||||
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||||
# CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL is not set
|
|
||||||
# end of Bluedroid Options
|
# end of Bluedroid Options
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -766,10 +713,7 @@ CONFIG_BT_CTRL_HCI_MODE_VHCI=y
|
|||||||
# CONFIG_BT_CTRL_HCI_MODE_UART_H4 is not set
|
# CONFIG_BT_CTRL_HCI_MODE_UART_H4 is not set
|
||||||
CONFIG_BT_CTRL_HCI_TL=1
|
CONFIG_BT_CTRL_HCI_TL=1
|
||||||
CONFIG_BT_CTRL_ADV_DUP_FILT_MAX=30
|
CONFIG_BT_CTRL_ADV_DUP_FILT_MAX=30
|
||||||
CONFIG_BT_BLE_CCA_MODE_NONE=y
|
# CONFIG_BT_CTRL_HW_CCA is not set
|
||||||
# CONFIG_BT_BLE_CCA_MODE_HW is not set
|
|
||||||
# CONFIG_BT_BLE_CCA_MODE_SW is not set
|
|
||||||
CONFIG_BT_BLE_CCA_MODE=0
|
|
||||||
CONFIG_BT_CTRL_HW_CCA_VAL=20
|
CONFIG_BT_CTRL_HW_CCA_VAL=20
|
||||||
CONFIG_BT_CTRL_HW_CCA_EFF=0
|
CONFIG_BT_CTRL_HW_CCA_EFF=0
|
||||||
CONFIG_BT_CTRL_CE_LENGTH_TYPE_ORIG=y
|
CONFIG_BT_CTRL_CE_LENGTH_TYPE_ORIG=y
|
||||||
@ -810,6 +754,8 @@ CONFIG_BT_CTRL_SCAN_DUPL_TYPE=0
|
|||||||
CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE=100
|
CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE=100
|
||||||
CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD=0
|
CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD=0
|
||||||
# CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN is not set
|
# CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN is not set
|
||||||
|
# CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EN is not set
|
||||||
|
CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_DIS=y
|
||||||
CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF=0
|
CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF=0
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -890,7 +836,6 @@ CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM=y
|
|||||||
#
|
#
|
||||||
# GPTimer Configuration
|
# GPTimer Configuration
|
||||||
#
|
#
|
||||||
CONFIG_GPTIMER_ISR_HANDLER_IN_IRAM=y
|
|
||||||
# CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is not set
|
# CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is not set
|
||||||
# CONFIG_GPTIMER_ISR_IRAM_SAFE is not set
|
# CONFIG_GPTIMER_ISR_IRAM_SAFE is not set
|
||||||
# CONFIG_GPTIMER_SUPPRESS_DEPRECATE_WARN is not set
|
# CONFIG_GPTIMER_SUPPRESS_DEPRECATE_WARN is not set
|
||||||
@ -930,11 +875,6 @@ CONFIG_GPTIMER_ISR_HANDLER_IN_IRAM=y
|
|||||||
# CONFIG_I2S_SUPPRESS_DEPRECATE_WARN is not set
|
# CONFIG_I2S_SUPPRESS_DEPRECATE_WARN is not set
|
||||||
# CONFIG_I2S_ENABLE_DEBUG_LOG is not set
|
# CONFIG_I2S_ENABLE_DEBUG_LOG is not set
|
||||||
# end of I2S Configuration
|
# end of I2S Configuration
|
||||||
|
|
||||||
#
|
|
||||||
# USB Serial/JTAG Configuration
|
|
||||||
#
|
|
||||||
# end of USB Serial/JTAG Configuration
|
|
||||||
# end of Driver Configurations
|
# end of Driver Configurations
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -964,12 +904,6 @@ CONFIG_ESP_TLS_USE_DS_PERIPHERAL=y
|
|||||||
# CONFIG_ADC_CONTINUOUS_FORCE_USE_ADC2_ON_C3_S3 is not set
|
# CONFIG_ADC_CONTINUOUS_FORCE_USE_ADC2_ON_C3_S3 is not set
|
||||||
# end of ADC and ADC Calibration
|
# end of ADC and ADC Calibration
|
||||||
|
|
||||||
#
|
|
||||||
# Wireless Coexistence
|
|
||||||
#
|
|
||||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y
|
|
||||||
# end of Wireless Coexistence
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Common ESP-related
|
# Common ESP-related
|
||||||
#
|
#
|
||||||
@ -1061,7 +995,6 @@ CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y
|
|||||||
CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
|
CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y
|
||||||
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y
|
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y
|
||||||
CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y
|
CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y
|
||||||
CONFIG_ESP_MAC_UNIVERSAL_MAC_ADDRESSES_FOUR=y
|
|
||||||
# CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO is not set
|
# CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_TWO is not set
|
||||||
CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_FOUR=y
|
CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES_FOUR=y
|
||||||
CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES=4
|
CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES=4
|
||||||
@ -1076,7 +1009,6 @@ CONFIG_ESP_SLEEP_MSPI_NEED_ALL_IO_PU=y
|
|||||||
CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y
|
CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y
|
||||||
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
|
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
|
||||||
CONFIG_ESP_SLEEP_DEEP_SLEEP_WAKEUP_DELAY=2000
|
CONFIG_ESP_SLEEP_DEEP_SLEEP_WAKEUP_DELAY=2000
|
||||||
CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y
|
|
||||||
# end of Sleep Config
|
# end of Sleep Config
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1087,12 +1019,13 @@ CONFIG_RTC_CLK_SRC_INT_RC=y
|
|||||||
# CONFIG_RTC_CLK_SRC_EXT_OSC is not set
|
# CONFIG_RTC_CLK_SRC_EXT_OSC is not set
|
||||||
# CONFIG_RTC_CLK_SRC_INT_8MD256 is not set
|
# CONFIG_RTC_CLK_SRC_INT_8MD256 is not set
|
||||||
CONFIG_RTC_CLK_CAL_CYCLES=1024
|
CONFIG_RTC_CLK_CAL_CYCLES=1024
|
||||||
|
CONFIG_RTC_CLOCK_BBPLL_POWER_ON_WITH_USB=y
|
||||||
# end of RTC Clock Config
|
# end of RTC Clock Config
|
||||||
|
|
||||||
#
|
#
|
||||||
# Peripheral Control
|
# Peripheral Control
|
||||||
#
|
#
|
||||||
CONFIG_PERIPH_CTRL_FUNC_IN_IRAM=y
|
# CONFIG_PERIPH_CTRL_FUNC_IN_IRAM is not set
|
||||||
# end of Peripheral Control
|
# end of Peripheral Control
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1134,17 +1067,11 @@ CONFIG_LCD_PANEL_IO_FORMAT_BUF_SIZE=32
|
|||||||
CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120
|
CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120
|
||||||
CONFIG_ESP_NETIF_TCPIP_LWIP=y
|
CONFIG_ESP_NETIF_TCPIP_LWIP=y
|
||||||
# CONFIG_ESP_NETIF_LOOPBACK is not set
|
# CONFIG_ESP_NETIF_LOOPBACK is not set
|
||||||
CONFIG_ESP_NETIF_USES_TCPIP_WITH_BSD_API=y
|
|
||||||
# CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS is not set
|
# CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS is not set
|
||||||
# CONFIG_ESP_NETIF_L2_TAP is not set
|
# CONFIG_ESP_NETIF_L2_TAP is not set
|
||||||
# CONFIG_ESP_NETIF_BRIDGE_EN is not set
|
# CONFIG_ESP_NETIF_BRIDGE_EN is not set
|
||||||
# end of ESP NETIF Adapter
|
# end of ESP NETIF Adapter
|
||||||
|
|
||||||
#
|
|
||||||
# Partition API Configuration
|
|
||||||
#
|
|
||||||
# end of Partition API Configuration
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# PHY
|
# PHY
|
||||||
#
|
#
|
||||||
@ -1154,7 +1081,6 @@ CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20
|
|||||||
CONFIG_ESP_PHY_MAX_TX_POWER=20
|
CONFIG_ESP_PHY_MAX_TX_POWER=20
|
||||||
# CONFIG_ESP_PHY_REDUCE_TX_POWER is not set
|
# CONFIG_ESP_PHY_REDUCE_TX_POWER is not set
|
||||||
CONFIG_ESP_PHY_ENABLE_USB=y
|
CONFIG_ESP_PHY_ENABLE_USB=y
|
||||||
# CONFIG_ESP_PHY_ENABLE_CERT_TEST is not set
|
|
||||||
CONFIG_ESP_PHY_RF_CAL_PARTIAL=y
|
CONFIG_ESP_PHY_RF_CAL_PARTIAL=y
|
||||||
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
|
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
|
||||||
# CONFIG_ESP_PHY_RF_CAL_FULL is not set
|
# CONFIG_ESP_PHY_RF_CAL_FULL is not set
|
||||||
@ -1233,7 +1159,6 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y
|
|||||||
# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set
|
# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set
|
||||||
# CONFIG_ESP_SYSTEM_PANIC_GDBSTUB is not set
|
# CONFIG_ESP_SYSTEM_PANIC_GDBSTUB is not set
|
||||||
# CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set
|
# CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set
|
||||||
CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS=0
|
|
||||||
CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK=y
|
CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK=y
|
||||||
CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y
|
CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y
|
||||||
|
|
||||||
@ -1259,7 +1184,6 @@ CONFIG_ESP_CONSOLE_UART_DEFAULT=y
|
|||||||
# CONFIG_ESP_CONSOLE_NONE is not set
|
# CONFIG_ESP_CONSOLE_NONE is not set
|
||||||
# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set
|
# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set
|
||||||
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
|
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
|
||||||
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED=y
|
|
||||||
CONFIG_ESP_CONSOLE_UART=y
|
CONFIG_ESP_CONSOLE_UART=y
|
||||||
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y
|
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y
|
||||||
CONFIG_ESP_CONSOLE_UART_NUM=0
|
CONFIG_ESP_CONSOLE_UART_NUM=0
|
||||||
@ -1311,11 +1235,6 @@ CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER=y
|
|||||||
CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER=y
|
CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER=y
|
||||||
CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584
|
CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584
|
||||||
CONFIG_ESP_TIMER_INTERRUPT_LEVEL=1
|
CONFIG_ESP_TIMER_INTERRUPT_LEVEL=1
|
||||||
# CONFIG_ESP_TIMER_SHOW_EXPERIMENTAL is not set
|
|
||||||
CONFIG_ESP_TIMER_TASK_AFFINITY=0x0
|
|
||||||
CONFIG_ESP_TIMER_TASK_AFFINITY_CPU0=y
|
|
||||||
CONFIG_ESP_TIMER_ISR_AFFINITY=0x1
|
|
||||||
CONFIG_ESP_TIMER_ISR_AFFINITY_CPU0=y
|
|
||||||
# CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD is not set
|
# CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD is not set
|
||||||
CONFIG_ESP_TIMER_IMPL_SYSTIMER=y
|
CONFIG_ESP_TIMER_IMPL_SYSTIMER=y
|
||||||
# end of High resolution timer (esp_timer)
|
# end of High resolution timer (esp_timer)
|
||||||
@ -1323,34 +1242,28 @@ CONFIG_ESP_TIMER_IMPL_SYSTIMER=y
|
|||||||
#
|
#
|
||||||
# Wi-Fi
|
# Wi-Fi
|
||||||
#
|
#
|
||||||
CONFIG_ESP_WIFI_ENABLED=y
|
CONFIG_ESP32_WIFI_ENABLED=y
|
||||||
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=10
|
CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y
|
||||||
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10
|
||||||
# CONFIG_ESP_WIFI_STATIC_TX_BUFFER is not set
|
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
||||||
CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER=y
|
# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set
|
||||||
CONFIG_ESP_WIFI_TX_BUFFER_TYPE=1
|
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
|
||||||
CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=32
|
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
|
||||||
CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y
|
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32
|
||||||
# CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set
|
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
|
||||||
CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0
|
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
|
||||||
CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF=5
|
CONFIG_ESP32_WIFI_TX_BA_WIN=6
|
||||||
# CONFIG_ESP_WIFI_CSI_ENABLED is not set
|
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
|
||||||
CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y
|
CONFIG_ESP32_WIFI_RX_BA_WIN=6
|
||||||
CONFIG_ESP_WIFI_TX_BA_WIN=6
|
CONFIG_ESP32_WIFI_NVS_ENABLED=y
|
||||||
CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y
|
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
|
||||||
CONFIG_ESP_WIFI_RX_BA_WIN=6
|
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
|
||||||
CONFIG_ESP_WIFI_NVS_ENABLED=y
|
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
|
||||||
CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0=y
|
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
|
||||||
# CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_1 is not set
|
CONFIG_ESP32_WIFI_IRAM_OPT=y
|
||||||
CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752
|
CONFIG_ESP32_WIFI_RX_IRAM_OPT=y
|
||||||
CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32
|
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
|
||||||
CONFIG_ESP_WIFI_IRAM_OPT=y
|
CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=y
|
||||||
# CONFIG_ESP_WIFI_EXTRA_IRAM_OPT is not set
|
|
||||||
CONFIG_ESP_WIFI_RX_IRAM_OPT=y
|
|
||||||
CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y
|
|
||||||
CONFIG_ESP_WIFI_ENABLE_SAE_PK=y
|
|
||||||
CONFIG_ESP_WIFI_SOFTAP_SAE_SUPPORT=y
|
|
||||||
CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_STA=y
|
|
||||||
# CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set
|
# CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set
|
||||||
# CONFIG_ESP_WIFI_FTM_ENABLE is not set
|
# CONFIG_ESP_WIFI_FTM_ENABLE is not set
|
||||||
CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=y
|
CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=y
|
||||||
@ -1359,26 +1272,7 @@ CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=y
|
|||||||
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y
|
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y
|
||||||
# CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT is not set
|
# CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT is not set
|
||||||
CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM=7
|
CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM=7
|
||||||
CONFIG_ESP_WIFI_MBEDTLS_CRYPTO=y
|
|
||||||
CONFIG_ESP_WIFI_MBEDTLS_TLS_CLIENT=y
|
|
||||||
# CONFIG_ESP_WIFI_WAPI_PSK is not set
|
|
||||||
# CONFIG_ESP_WIFI_SUITE_B_192 is not set
|
|
||||||
# CONFIG_ESP_WIFI_11KV_SUPPORT is not set
|
|
||||||
# CONFIG_ESP_WIFI_MBO_SUPPORT is not set
|
|
||||||
# CONFIG_ESP_WIFI_DPP_SUPPORT is not set
|
|
||||||
# CONFIG_ESP_WIFI_11R_SUPPORT is not set
|
|
||||||
# CONFIG_ESP_WIFI_WPS_SOFTAP_REGISTRAR is not set
|
|
||||||
|
|
||||||
#
|
|
||||||
# WPS Configuration Options
|
|
||||||
#
|
|
||||||
# CONFIG_ESP_WIFI_WPS_STRICT is not set
|
|
||||||
# CONFIG_ESP_WIFI_WPS_PASSPHRASE is not set
|
# CONFIG_ESP_WIFI_WPS_PASSPHRASE is not set
|
||||||
# end of WPS Configuration Options
|
|
||||||
|
|
||||||
# CONFIG_ESP_WIFI_DEBUG_PRINT is not set
|
|
||||||
# CONFIG_ESP_WIFI_TESTING_OPTIONS is not set
|
|
||||||
CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=y
|
|
||||||
# end of Wi-Fi
|
# end of Wi-Fi
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1393,11 +1287,18 @@ CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y
|
|||||||
# FAT Filesystem support
|
# FAT Filesystem support
|
||||||
#
|
#
|
||||||
CONFIG_FATFS_VOLUME_COUNT=2
|
CONFIG_FATFS_VOLUME_COUNT=2
|
||||||
CONFIG_FATFS_LFN_NONE=y
|
|
||||||
# CONFIG_FATFS_LFN_HEAP is not set
|
|
||||||
# CONFIG_FATFS_LFN_STACK is not set
|
|
||||||
# CONFIG_FATFS_SECTOR_512 is not set
|
# CONFIG_FATFS_SECTOR_512 is not set
|
||||||
|
# CONFIG_FATFS_SECTOR_1024 is not set
|
||||||
|
# CONFIG_FATFS_SECTOR_2048 is not set
|
||||||
CONFIG_FATFS_SECTOR_4096=y
|
CONFIG_FATFS_SECTOR_4096=y
|
||||||
|
CONFIG_FATFS_SECTORS_PER_CLUSTER_1=y
|
||||||
|
# CONFIG_FATFS_SECTORS_PER_CLUSTER_2 is not set
|
||||||
|
# CONFIG_FATFS_SECTORS_PER_CLUSTER_4 is not set
|
||||||
|
# CONFIG_FATFS_SECTORS_PER_CLUSTER_8 is not set
|
||||||
|
# CONFIG_FATFS_SECTORS_PER_CLUSTER_16 is not set
|
||||||
|
# CONFIG_FATFS_SECTORS_PER_CLUSTER_32 is not set
|
||||||
|
# CONFIG_FATFS_SECTORS_PER_CLUSTER_64 is not set
|
||||||
|
# CONFIG_FATFS_SECTORS_PER_CLUSTER_128 is not set
|
||||||
# CONFIG_FATFS_CODEPAGE_DYNAMIC is not set
|
# CONFIG_FATFS_CODEPAGE_DYNAMIC is not set
|
||||||
CONFIG_FATFS_CODEPAGE_437=y
|
CONFIG_FATFS_CODEPAGE_437=y
|
||||||
# CONFIG_FATFS_CODEPAGE_720 is not set
|
# CONFIG_FATFS_CODEPAGE_720 is not set
|
||||||
@ -1420,12 +1321,17 @@ CONFIG_FATFS_CODEPAGE_437=y
|
|||||||
# CONFIG_FATFS_CODEPAGE_936 is not set
|
# CONFIG_FATFS_CODEPAGE_936 is not set
|
||||||
# CONFIG_FATFS_CODEPAGE_949 is not set
|
# CONFIG_FATFS_CODEPAGE_949 is not set
|
||||||
# CONFIG_FATFS_CODEPAGE_950 is not set
|
# CONFIG_FATFS_CODEPAGE_950 is not set
|
||||||
|
CONFIG_FATFS_AUTO_TYPE=y
|
||||||
|
# CONFIG_FATFS_FAT12 is not set
|
||||||
|
# CONFIG_FATFS_FAT16 is not set
|
||||||
CONFIG_FATFS_CODEPAGE=437
|
CONFIG_FATFS_CODEPAGE=437
|
||||||
|
CONFIG_FATFS_LFN_NONE=y
|
||||||
|
# CONFIG_FATFS_LFN_HEAP is not set
|
||||||
|
# CONFIG_FATFS_LFN_STACK is not set
|
||||||
CONFIG_FATFS_FS_LOCK=0
|
CONFIG_FATFS_FS_LOCK=0
|
||||||
CONFIG_FATFS_TIMEOUT_MS=10000
|
CONFIG_FATFS_TIMEOUT_MS=10000
|
||||||
CONFIG_FATFS_PER_FILE_CACHE=y
|
CONFIG_FATFS_PER_FILE_CACHE=y
|
||||||
# CONFIG_FATFS_USE_FASTSEEK is not set
|
# CONFIG_FATFS_USE_FASTSEEK is not set
|
||||||
CONFIG_FATFS_VFS_FSTAT_BLKSIZE=0
|
|
||||||
# end of FAT Filesystem support
|
# end of FAT Filesystem support
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1451,7 +1357,6 @@ CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1
|
|||||||
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048
|
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048
|
||||||
CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10
|
CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10
|
||||||
CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
|
CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
|
||||||
CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1
|
|
||||||
# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
|
# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
|
||||||
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
|
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
|
||||||
# end of Kernel
|
# end of Kernel
|
||||||
@ -1461,7 +1366,6 @@ CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1
|
|||||||
#
|
#
|
||||||
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
|
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
|
||||||
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
|
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
|
||||||
CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS=y
|
|
||||||
# CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set
|
# CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set
|
||||||
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
|
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
|
||||||
CONFIG_FREERTOS_ISR_STACKSIZE=1536
|
CONFIG_FREERTOS_ISR_STACKSIZE=1536
|
||||||
@ -1473,6 +1377,7 @@ CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER=y
|
|||||||
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
|
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
|
||||||
# CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH is not set
|
# CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH is not set
|
||||||
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
|
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
|
||||||
|
CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
|
||||||
CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT=y
|
CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT=y
|
||||||
# end of Port
|
# end of Port
|
||||||
|
|
||||||
@ -1490,8 +1395,6 @@ CONFIG_HAL_ASSERTION_EQUALS_SYSTEM=y
|
|||||||
# CONFIG_HAL_ASSERTION_ENABLE is not set
|
# CONFIG_HAL_ASSERTION_ENABLE is not set
|
||||||
CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=2
|
CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=2
|
||||||
CONFIG_HAL_WDT_USE_ROM_IMPL=y
|
CONFIG_HAL_WDT_USE_ROM_IMPL=y
|
||||||
CONFIG_HAL_SPI_MASTER_FUNC_IN_IRAM=y
|
|
||||||
CONFIG_HAL_SPI_SLAVE_FUNC_IN_IRAM=y
|
|
||||||
# end of Hardware Abstraction Layer (HAL) and Low Level (LL)
|
# end of Hardware Abstraction Layer (HAL) and Low Level (LL)
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1503,14 +1406,9 @@ CONFIG_HEAP_POISONING_DISABLED=y
|
|||||||
CONFIG_HEAP_TRACING_OFF=y
|
CONFIG_HEAP_TRACING_OFF=y
|
||||||
# CONFIG_HEAP_TRACING_STANDALONE is not set
|
# CONFIG_HEAP_TRACING_STANDALONE is not set
|
||||||
# CONFIG_HEAP_TRACING_TOHOST is not set
|
# CONFIG_HEAP_TRACING_TOHOST is not set
|
||||||
# CONFIG_HEAP_USE_HOOKS is not set
|
|
||||||
# CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS is not set
|
# CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS is not set
|
||||||
# CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH is not set
|
|
||||||
# end of Heap memory debugging
|
# end of Heap memory debugging
|
||||||
|
|
||||||
CONFIG_IEEE802154_CCA_THRESHOLD=-60
|
|
||||||
CONFIG_IEEE802154_PENDING_TABLE_SIZE=20
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Log output
|
# Log output
|
||||||
#
|
#
|
||||||
@ -1535,15 +1433,12 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
|
|||||||
#
|
#
|
||||||
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
|
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
|
||||||
# CONFIG_LWIP_NETIF_API is not set
|
# CONFIG_LWIP_NETIF_API is not set
|
||||||
CONFIG_LWIP_TCPIP_TASK_PRIO=18
|
|
||||||
# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set
|
# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set
|
||||||
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
|
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
|
||||||
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
|
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
|
||||||
# CONFIG_LWIP_L2_TO_L3_COPY is not set
|
# CONFIG_LWIP_L2_TO_L3_COPY is not set
|
||||||
# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
|
# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
|
||||||
# CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION is not set
|
|
||||||
CONFIG_LWIP_TIMERS_ONDEMAND=y
|
CONFIG_LWIP_TIMERS_ONDEMAND=y
|
||||||
CONFIG_LWIP_ND6=y
|
|
||||||
CONFIG_LWIP_MAX_SOCKETS=10
|
CONFIG_LWIP_MAX_SOCKETS=10
|
||||||
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
|
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
|
||||||
# CONFIG_LWIP_SO_LINGER is not set
|
# CONFIG_LWIP_SO_LINGER is not set
|
||||||
@ -1555,7 +1450,6 @@ CONFIG_LWIP_IP4_FRAG=y
|
|||||||
CONFIG_LWIP_IP6_FRAG=y
|
CONFIG_LWIP_IP6_FRAG=y
|
||||||
# CONFIG_LWIP_IP4_REASSEMBLY is not set
|
# CONFIG_LWIP_IP4_REASSEMBLY is not set
|
||||||
# CONFIG_LWIP_IP6_REASSEMBLY is not set
|
# CONFIG_LWIP_IP6_REASSEMBLY is not set
|
||||||
CONFIG_LWIP_IP_REASS_MAX_PBUFS=10
|
|
||||||
# CONFIG_LWIP_IP_FORWARD is not set
|
# CONFIG_LWIP_IP_FORWARD is not set
|
||||||
# CONFIG_LWIP_STATS is not set
|
# CONFIG_LWIP_STATS is not set
|
||||||
CONFIG_LWIP_ESP_GRATUITOUS_ARP=y
|
CONFIG_LWIP_ESP_GRATUITOUS_ARP=y
|
||||||
@ -1580,7 +1474,6 @@ CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8
|
|||||||
# end of DHCP server
|
# end of DHCP server
|
||||||
|
|
||||||
# CONFIG_LWIP_AUTOIP is not set
|
# CONFIG_LWIP_AUTOIP is not set
|
||||||
CONFIG_LWIP_IPV4=y
|
|
||||||
CONFIG_LWIP_IPV6=y
|
CONFIG_LWIP_IPV6=y
|
||||||
# CONFIG_LWIP_IPV6_AUTOCONFIG is not set
|
# CONFIG_LWIP_IPV6_AUTOCONFIG is not set
|
||||||
CONFIG_LWIP_IPV6_NUM_ADDRESSES=3
|
CONFIG_LWIP_IPV6_NUM_ADDRESSES=3
|
||||||
@ -1674,9 +1567,6 @@ CONFIG_LWIP_HOOK_IP6_ROUTE_NONE=y
|
|||||||
CONFIG_LWIP_HOOK_ND6_GET_GW_NONE=y
|
CONFIG_LWIP_HOOK_ND6_GET_GW_NONE=y
|
||||||
# CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT is not set
|
# CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT is not set
|
||||||
# CONFIG_LWIP_HOOK_ND6_GET_GW_CUSTOM is not set
|
# CONFIG_LWIP_HOOK_ND6_GET_GW_CUSTOM is not set
|
||||||
CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_NONE=y
|
|
||||||
# CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT is not set
|
|
||||||
# CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_CUSTOM is not set
|
|
||||||
CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE=y
|
CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE=y
|
||||||
# CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT is not set
|
# CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT is not set
|
||||||
# CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_CUSTOM is not set
|
# CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_CUSTOM is not set
|
||||||
@ -1723,7 +1613,7 @@ CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=200
|
|||||||
# end of Certificate Bundle
|
# end of Certificate Bundle
|
||||||
|
|
||||||
# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
|
# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
|
||||||
CONFIG_MBEDTLS_CMAC_C=y
|
# CONFIG_MBEDTLS_CMAC_C is not set
|
||||||
CONFIG_MBEDTLS_HARDWARE_AES=y
|
CONFIG_MBEDTLS_HARDWARE_AES=y
|
||||||
CONFIG_MBEDTLS_AES_USE_INTERRUPT=y
|
CONFIG_MBEDTLS_AES_USE_INTERRUPT=y
|
||||||
CONFIG_MBEDTLS_HARDWARE_MPI=y
|
CONFIG_MBEDTLS_HARDWARE_MPI=y
|
||||||
@ -1813,6 +1703,7 @@ CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
|
|||||||
# CONFIG_MBEDTLS_HKDF_C is not set
|
# CONFIG_MBEDTLS_HKDF_C is not set
|
||||||
# CONFIG_MBEDTLS_THREADING_C is not set
|
# CONFIG_MBEDTLS_THREADING_C is not set
|
||||||
# CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI is not set
|
# CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI is not set
|
||||||
|
# CONFIG_MBEDTLS_SECURITY_RISKS is not set
|
||||||
# end of mbedTLS
|
# end of mbedTLS
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1857,20 +1748,6 @@ CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC_HRT=y
|
|||||||
# OpenThread
|
# OpenThread
|
||||||
#
|
#
|
||||||
# CONFIG_OPENTHREAD_ENABLED is not set
|
# CONFIG_OPENTHREAD_ENABLED is not set
|
||||||
|
|
||||||
#
|
|
||||||
# Thread Operational Dataset
|
|
||||||
#
|
|
||||||
CONFIG_OPENTHREAD_NETWORK_NAME="OpenThread-ESP"
|
|
||||||
CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX="fd00:db8:a0:0::/64"
|
|
||||||
CONFIG_OPENTHREAD_NETWORK_CHANNEL=15
|
|
||||||
CONFIG_OPENTHREAD_NETWORK_PANID=0x1234
|
|
||||||
CONFIG_OPENTHREAD_NETWORK_EXTPANID="dead00beef00cafe"
|
|
||||||
CONFIG_OPENTHREAD_NETWORK_MASTERKEY="00112233445566778899aabbccddeeff"
|
|
||||||
CONFIG_OPENTHREAD_NETWORK_PSKC="104810e2315100afd6bc9215a6bfac53"
|
|
||||||
# end of Thread Operational Dataset
|
|
||||||
|
|
||||||
CONFIG_OPENTHREAD_XTAL_ACCURACY=130
|
|
||||||
# end of OpenThread
|
# end of OpenThread
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1908,10 +1785,12 @@ CONFIG_MMU_PAGE_SIZE=0x10000
|
|||||||
# CONFIG_SPI_FLASH_VERIFY_WRITE is not set
|
# CONFIG_SPI_FLASH_VERIFY_WRITE is not set
|
||||||
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
|
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
|
||||||
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
|
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
|
||||||
|
CONFIG_SPI_FLASH_HAS_ROM_IMPL=y
|
||||||
# CONFIG_SPI_FLASH_ROM_IMPL is not set
|
# CONFIG_SPI_FLASH_ROM_IMPL is not set
|
||||||
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
|
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
|
||||||
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
|
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
|
||||||
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set
|
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set
|
||||||
|
# CONFIG_SPI_FLASH_SHARE_SPI1_BUS is not set
|
||||||
# CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE is not set
|
# CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE is not set
|
||||||
CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y
|
CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y
|
||||||
CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20
|
CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20
|
||||||
@ -1931,13 +1810,6 @@ CONFIG_SPI_FLASH_BROWNOUT_RESET=y
|
|||||||
#
|
#
|
||||||
# Auto-detect flash chips
|
# Auto-detect flash chips
|
||||||
#
|
#
|
||||||
CONFIG_SPI_FLASH_VENDOR_XMC_SUPPORTED=y
|
|
||||||
CONFIG_SPI_FLASH_VENDOR_GD_SUPPORTED=y
|
|
||||||
CONFIG_SPI_FLASH_VENDOR_ISSI_SUPPORTED=y
|
|
||||||
CONFIG_SPI_FLASH_VENDOR_MXIC_SUPPORTED=y
|
|
||||||
CONFIG_SPI_FLASH_VENDOR_WINBOND_SUPPORTED=y
|
|
||||||
CONFIG_SPI_FLASH_VENDOR_BOYA_SUPPORTED=y
|
|
||||||
CONFIG_SPI_FLASH_VENDOR_TH_SUPPORTED=y
|
|
||||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y
|
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y
|
||||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=y
|
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=y
|
||||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y
|
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y
|
||||||
@ -2044,7 +1916,6 @@ CONFIG_VFS_SUPPORT_DIR=y
|
|||||||
CONFIG_VFS_SUPPORT_SELECT=y
|
CONFIG_VFS_SUPPORT_SELECT=y
|
||||||
CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y
|
CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y
|
||||||
CONFIG_VFS_SUPPORT_TERMIOS=y
|
CONFIG_VFS_SUPPORT_TERMIOS=y
|
||||||
CONFIG_VFS_MAX_COUNT=8
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Host File System I/O (Semihosting)
|
# Host File System I/O (Semihosting)
|
||||||
@ -2072,12 +1943,26 @@ CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30
|
|||||||
CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y
|
CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y
|
||||||
# CONFIG_WIFI_PROV_STA_FAST_SCAN is not set
|
# CONFIG_WIFI_PROV_STA_FAST_SCAN is not set
|
||||||
# end of Wi-Fi Provisioning Manager
|
# end of Wi-Fi Provisioning Manager
|
||||||
|
|
||||||
|
#
|
||||||
|
# Supplicant
|
||||||
|
#
|
||||||
|
CONFIG_WPA_MBEDTLS_CRYPTO=y
|
||||||
|
CONFIG_WPA_MBEDTLS_TLS_CLIENT=y
|
||||||
|
# CONFIG_WPA_WAPI_PSK is not set
|
||||||
|
# CONFIG_WPA_SUITE_B_192 is not set
|
||||||
|
# CONFIG_WPA_DEBUG_PRINT is not set
|
||||||
|
# CONFIG_WPA_TESTING_OPTIONS is not set
|
||||||
|
# CONFIG_WPA_WPS_STRICT is not set
|
||||||
|
# CONFIG_WPA_11KV_SUPPORT is not set
|
||||||
|
# CONFIG_WPA_MBO_SUPPORT is not set
|
||||||
|
# CONFIG_WPA_DPP_SUPPORT is not set
|
||||||
|
# CONFIG_WPA_11R_SUPPORT is not set
|
||||||
|
# CONFIG_WPA_WPS_SOFTAP_REGISTRAR is not set
|
||||||
|
# end of Supplicant
|
||||||
# end of Component config
|
# end of Component config
|
||||||
|
|
||||||
# CONFIG_IDF_EXPERIMENTAL_FEATURES is not set
|
|
||||||
|
|
||||||
# Deprecated options for backward compatibility
|
# Deprecated options for backward compatibility
|
||||||
# CONFIG_APP_BUILD_TYPE_ELF_RAM is not set
|
|
||||||
# CONFIG_NO_BLOBS is not set
|
# CONFIG_NO_BLOBS is not set
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
|
||||||
@ -2292,9 +2177,6 @@ CONFIG_SMP_ENABLE=y
|
|||||||
# CONFIG_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY is not set
|
# CONFIG_BLE_ACTIVE_SCAN_REPORT_ADV_SCAN_RSP_INDIVIDUALLY is not set
|
||||||
CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30
|
CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30
|
||||||
# CONFIG_MCPWM_ISR_IN_IRAM is not set
|
# CONFIG_MCPWM_ISR_IN_IRAM is not set
|
||||||
CONFIG_SW_COEXIST_ENABLE=y
|
|
||||||
CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y
|
|
||||||
CONFIG_ESP_WIFI_SW_COEXIST_ENABLE=y
|
|
||||||
# CONFIG_EVENT_LOOP_PROFILING is not set
|
# CONFIG_EVENT_LOOP_PROFILING is not set
|
||||||
CONFIG_POST_EVENTS_FROM_ISR=y
|
CONFIG_POST_EVENTS_FROM_ISR=y
|
||||||
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
|
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
|
||||||
@ -2360,41 +2242,7 @@ CONFIG_BROWNOUT_DET_LVL=7
|
|||||||
CONFIG_ESP32S3_BROWNOUT_DET_LVL=7
|
CONFIG_ESP32S3_BROWNOUT_DET_LVL=7
|
||||||
CONFIG_IPC_TASK_STACK_SIZE=1280
|
CONFIG_IPC_TASK_STACK_SIZE=1280
|
||||||
CONFIG_TIMER_TASK_STACK_SIZE=3584
|
CONFIG_TIMER_TASK_STACK_SIZE=3584
|
||||||
CONFIG_ESP32_WIFI_ENABLED=y
|
CONFIG_SW_COEXIST_ENABLE=y
|
||||||
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10
|
|
||||||
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
|
||||||
# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set
|
|
||||||
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
|
|
||||||
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
|
|
||||||
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32
|
|
||||||
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
|
|
||||||
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
|
|
||||||
CONFIG_ESP32_WIFI_TX_BA_WIN=6
|
|
||||||
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
|
|
||||||
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
|
|
||||||
CONFIG_ESP32_WIFI_RX_BA_WIN=6
|
|
||||||
CONFIG_ESP32_WIFI_RX_BA_WIN=6
|
|
||||||
CONFIG_ESP32_WIFI_NVS_ENABLED=y
|
|
||||||
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
|
|
||||||
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
|
|
||||||
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
|
|
||||||
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
|
|
||||||
CONFIG_ESP32_WIFI_IRAM_OPT=y
|
|
||||||
CONFIG_ESP32_WIFI_RX_IRAM_OPT=y
|
|
||||||
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
|
|
||||||
CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=y
|
|
||||||
CONFIG_WPA_MBEDTLS_CRYPTO=y
|
|
||||||
CONFIG_WPA_MBEDTLS_TLS_CLIENT=y
|
|
||||||
# CONFIG_WPA_WAPI_PSK is not set
|
|
||||||
# CONFIG_WPA_SUITE_B_192 is not set
|
|
||||||
# CONFIG_WPA_11KV_SUPPORT is not set
|
|
||||||
# CONFIG_WPA_MBO_SUPPORT is not set
|
|
||||||
# CONFIG_WPA_DPP_SUPPORT is not set
|
|
||||||
# CONFIG_WPA_11R_SUPPORT is not set
|
|
||||||
# CONFIG_WPA_WPS_SOFTAP_REGISTRAR is not set
|
|
||||||
# CONFIG_WPA_WPS_STRICT is not set
|
|
||||||
# CONFIG_WPA_DEBUG_PRINT is not set
|
|
||||||
# CONFIG_WPA_TESTING_OPTIONS is not set
|
|
||||||
# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
|
# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
|
||||||
# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
|
# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
|
||||||
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
|
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
|
||||||
|
1213
sdkconfig.old
1213
sdkconfig.old
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user