Skip to content

Instantly share code, notes, and snippets.

@trieb
Created April 25, 2019 12:01
Show Gist options
  • Save trieb/a08439f2858a1a38d6c54822f07c37d4 to your computer and use it in GitHub Desktop.
Save trieb/a08439f2858a1a38d6c54822f07c37d4 to your computer and use it in GitHub Desktop.
GATT table description example
#include "gatts_table_profile.h"
#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 "uart_comms.h"
#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_bt_main.h"
#include "esp_gatt_common_api.h"
#include "sdkconfig.h"
#define GATTS_TABLE_TAG "GATTS_TABLE"
#define PROFILE_NUM 1
#define PROFILE_APP_IDX 0
//allows for different app IDs for different connected devices (ie smartphones get one app id, computer gets another app id, gateway device gets another)
#define ESP_APP_ID 0x55
//default device name
#define SAMPLE_DEVICE_NAME "AMETEK_ESP"
#define SVC_INST_ID 0
//MAX value size, could end up being a smaller value after negotiation, but this is the max that WE will allow (need to set MTU size somewhere)
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 100
//prepare write buffer size
#define PREPARE_BUF_MAX_SIZE 1024
//char is the 1 byte
#define CHAR_DECLARATION_SIZE (sizeof(uint8_t))
//advertising and scan response configuration flags
#define ADV_CONFIG_FLAG (1 << 0)
#define SCAN_RSP_CONFIG_FLAG (1 << 1)
//advertising configuration done value
static uint8_t adv_config_done = 0;
//profile handle table "HRS_IDX_NB" references one of the enums in the header file
uint16_t device_handle_table[ESP_IDX_DEVICE_NB];
uint16_t measurements_handle_table[ESP_IDX_MEASUREMENTS_NB];
uint16_t events_handle_table[ESP_IDX_EVENTS_NB];
uint16_t settings_handle_table[ESP_IDX_SETTINGS_NB];
uint16_t datasets_handle_table[ESP_IDX_DATASETS_NB];
uint16_t battery_handle_table[ESP_IDX_BATTERY_NB];
uint16_t streaming_handle_table[ESP_IDX_STREAMING_NB];
//prepare buffer and length structure before sending data
typedef struct {
uint8_t *prepare_buf;
int prepare_len;
} prepare_type_env_t;
static prepare_type_env_t prepare_write_env;
//advertisement data as raw bytes (rather than structure), improves runtime performance
#ifndef CONFIG_SET_RAW_ADV_DATA
#define CONFIG_SET_RAW_ADV_DATA
#endif
#ifdef CONFIG_SET_RAW_ADV_DATA
//advertisement packet starts with a few flags, and then the primary UUID
static uint8_t raw_adv_data[] = {
0x02, 0x01, 0x06,
0x11, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x80, 0x68, 0x69, 0x00, 0x67, 0xA6, 0xAC
};
//scan response packet starts with the local name, and then the primary UUID (name is default at NextGenPCS in this array, could be different than parameter above)
static uint8_t raw_scan_rsp_data[] = {
0x0B, 0x09, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x4b, 0x5f, 0x45, 0x53, 0x50, //AMETEK_ESP
// 0x0B, 0x09, 0x4E, 0x65, 0x78, 0x74, 0x47, 0x65, 0x6E, 0x50, 0x43, 0x53, //NextGenPCS
0x11, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x80, 0x68, 0x69, 0x00, 0x67, 0xA6, 0xAC //Server_UART BLE UUID backwards
};
//used to create the advertisement and scan response packets if not using raw data (preprocessor)
#else
static uint8_t service_uuid[16] = {
/* LSB <--------------------------------------------------------------------------------> MSB */
//first uuid, 16bit, [12],[13] is the value
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x80, 0x68, 0x69, 0x00, 0x67, 0xA6, 0xAC,
};
/* 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 = false,
.min_interval = 0x20,
.max_interval = 0x40,
.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 = false,
.min_interval = 0x20,
.max_interval = 0x40,
.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 = 16,
.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 */
//advertisement parameters
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 uint8_t GATTS_SERVICE_UUID_DEVICE[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t GATTS_CHAR_UUID_DEVICE_A[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x01};
static const uint8_t GATTS_CHAR_UUID_DEVICE_B[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x02};
static const uint8_t GATTS_CHAR_UUID_DEVICE_C[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x03};
static const uint8_t GATTS_CHAR_UUID_DEVICE_D[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x04};
static const uint8_t GATTS_CHAR_UUID_DEVICE_E[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x05};
static const uint8_t GATTS_CHAR_UUID_DEVICE_F[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x06};
static const uint8_t GATTS_CHAR_UUID_DEVICE_G[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x07};
static const uint8_t GATTS_CHAR_UUID_DEVICE_H[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x08};
static const uint8_t GATTS_CHAR_UUID_DEVICE_I[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x09};
static const uint8_t GATTS_CHAR_UUID_DEVICE_J[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x10};
static const uint8_t GATTS_CHAR_UUID_DEVICE_K[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x11};
static const uint8_t GATTS_SERVICE_UUID_MEASUREMENTS[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_A[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_B[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x02};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_C[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x03};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_D[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x04};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_E[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x05};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_F[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x06};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_G[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x07};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_H[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x08};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_I[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x09};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_J[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x10};
static const uint8_t GATTS_CHAR_UUID_MEASUREMENTS_K[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x11};
static const uint8_t GATTS_SERVICE_UUID_EVENTS[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t GATTS_CHAR_UUID_EVENTS_A[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01};
static const uint8_t GATTS_CHAR_UUID_EVENTS_B[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x02};
static const uint8_t GATTS_CHAR_UUID_EVENTS_C[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x03};
static const uint8_t GATTS_CHAR_UUID_EVENTS_D[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x04};
static const uint8_t GATTS_CHAR_UUID_EVENTS_E[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x05};
static const uint8_t GATTS_CHAR_UUID_EVENTS_F[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x06};
static const uint8_t GATTS_CHAR_UUID_EVENTS_G[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x07};
static const uint8_t GATTS_CHAR_UUID_EVENTS_H[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x08};
static const uint8_t GATTS_CHAR_UUID_EVENTS_I[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x09};
static const uint8_t GATTS_CHAR_UUID_EVENTS_J[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x10};
static const uint8_t GATTS_CHAR_UUID_EVENTS_K[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x11};
static const uint8_t GATTS_CHAR_UUID_EVENTS_L[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x12};
static const uint8_t GATTS_CHAR_UUID_EVENTS_M[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x13};
static const uint8_t GATTS_CHAR_UUID_EVENTS_N[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x14};
static const uint8_t GATTS_CHAR_UUID_EVENTS_O[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x15};
static const uint8_t GATTS_CHAR_UUID_EVENTS_P[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x16};
static const uint8_t GATTS_CHAR_UUID_EVENTS_Q[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x17};
static const uint8_t GATTS_CHAR_UUID_EVENTS_R[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x18};
static const uint8_t GATTS_CHAR_UUID_EVENTS_S[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x19};
static const uint8_t GATTS_SERVICE_UUID_SETTINGS[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_A[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x01};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_B[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x02};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_C[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x03};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_D[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x04};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_E[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x05};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_F[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x06};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_G[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x07};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_H[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x08};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_I[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x09};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_J[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x10};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_K[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x11};
static const uint8_t GATTS_CHAR_UUID_SETTINGS_L[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x12};
//static const uint8_t GATTS_CHAR_UUID_SETTINGS_M[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x13};
static const uint8_t GATTS_SERVICE_UUID_DATASETS[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t GATTS_CHAR_UUID_DATASETS_A[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x01};
static const uint8_t GATTS_CHAR_UUID_DATASETS_B[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x02};
static const uint8_t GATTS_CHAR_UUID_DATASETS_C[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x03};
static const uint8_t GATTS_CHAR_UUID_DATASETS_D[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x04};
static const uint8_t GATTS_CHAR_UUID_DATASETS_E[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x05};
static const uint8_t GATTS_SERVICE_UUID_STREAMING[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t GATTS_CHAR_UUID_STREAMING_A[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x01};
static const uint8_t GATTS_CHAR_UUID_STREAMING_B[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x02};
static const uint8_t GATTS_CHAR_UUID_STREAMING_C[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x03};
static const uint8_t GATTS_CHAR_UUID_STREAMING_D[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x04};
static const uint8_t GATTS_SERVICE_UUID_BATTERY[] = {0x0F,0x18};
static const uint8_t GATTS_CHAR_UUID_BATTERY_BATTERY_LEVEL[]= {0x19,0x2A};
static const uint8_t GATTS_SERVICE_UUID_CONFIGURATION[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t GATTS_CHAR_UUID_CONFIGURATION_A[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x01};
static const uint8_t GATTS_CHAR_UUID_CONFIGURATION_B[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x02};
static const uint8_t GATTS_CHAR_UUID_CONFIGURATION_C[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x03};
static const uint8_t GATTS_CHAR_UUID_CONFIGURATION_D[] = {0xAC,0xA6,0x67,0x00,0x69,0x68,0x80,0x01,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x04};
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_write = ESP_GATT_CHAR_PROP_BIT_WRITE;
static const uint8_t char_prop_notify = ESP_GATT_CHAR_PROP_BIT_NOTIFY;
static const uint8_t char_prop_read_indicate = ESP_GATT_CHAR_PROP_BIT_INDICATE | ESP_GATT_CHAR_PROP_BIT_READ;
static const uint8_t char_prop_read_write_indicate = ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_INDICATE;
static const uint8_t cccd[2] = {0x00, 0x00};
//static const uint8_t char_value[4] = {0x11, 0x22, 0x33, 0x44};
static const uint8_t initNull[2] = {};
static const uint8_t xg[2] = {'X','G'};
/* Full Database Description - Used to add attributes into the database */
static const esp_gatts_attr_db_t gatt_device_db[ESP_IDX_DEVICE_NB] =
{
// Service Declaration
[IDX_SVC_DEVICE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(GATTS_SERVICE_UUID_DEVICE), sizeof(GATTS_SERVICE_UUID_DEVICE), (uint8_t *)&GATTS_SERVICE_UUID_DEVICE}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_A] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_A_FIRMWARE_REVISION] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_A, ESP_GATT_PERM_READ,
sizeof(firmwareRev), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_A_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_B] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_B_CHIP_ID] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(chipID), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_B_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_C] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_C_COMMUNICATION_MODE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_C_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_D] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_D_PRODUCT_VOLTAGE_RATING] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_D, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_D_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_E] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_E_OUTLET_STATE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_E, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_E_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_F] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_F_CURRENT_TIME] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_F, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_F_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_G] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_G_DATE_PROGRAMMED] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_G, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_G_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_H] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_H_HARDWARE_REVISION] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_H, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_H_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_I] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_I_CONNECTED_NAME] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_I, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DEVICE_I_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_J] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_J_SET_CONNECTED_NAME] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_J, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_DEVICE_K] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_DEVICE_K_SET_LOCAL_NAME] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DEVICE_K, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
};
/* Full Database Description - Used to add attributes into the measurements database */
static const esp_gatts_attr_db_t gatt_measurements_db[ESP_IDX_MEASUREMENTS_NB] =
{
[IDX_SVC_MEASUREMENTS] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(GATTS_SERVICE_UUID_MEASUREMENTS), sizeof(GATTS_SERVICE_UUID_MEASUREMENTS), (uint8_t *)&GATTS_SERVICE_UUID_MEASUREMENTS}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_A] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_A_RMS_LINEVOLTAGE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_A, ESP_GATT_PERM_READ,
sizeof(firmwareRev), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_A_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_B] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_B_RMS_NGVOLTAGE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(chipID), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_B_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_C] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_C_RMS_CURRENT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_C_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_D] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_D_AVERAGE_POWER] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_D, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_D_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_E] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_E_POWER_FACTOR] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_E, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_E_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_F] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_F_LINE_FREQUENCY] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_F, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_F_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_G] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_G_CREST_FACTOR] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_G, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_G_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_H] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_H_INTERNAL_TEMPERATURE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_H, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_H_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_I] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_I_BATTERY_VOLTAGE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_I, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_I_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_J] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_J_ENERGY_USAGE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_J, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_J_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_MEASUREMENTS_K] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_MEASUREMENTS_K_ENERGY_USAGE_DATE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_MEASUREMENTS_K, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_MEASUREMENTS_K_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(cccd), (uint8_t *)cccd}},
};
/* Full Database Description - Used to add attributes into the measurements database */
static const esp_gatts_attr_db_t gatt_events_db[ESP_IDX_EVENTS_NB] =
{
[IDX_SVC_EVENTS] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(GATTS_SERVICE_UUID_EVENTS), sizeof(GATTS_SERVICE_UUID_EVENTS), (uint8_t *)&GATTS_SERVICE_UUID_EVENTS}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_A] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_A_UNDERVOLTAGE_RECORD_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_A, ESP_GATT_PERM_READ,
sizeof(firmwareRev), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_A_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_B] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_B_UNDERVOLTAGE_TURNOFF_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(chipID), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_B_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_C] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_C_OVERVOLTAGE_RECORD_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_C_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_D] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_D_OVERVOLTAGE_TURNOFF_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_D, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_D_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_E] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_E_POWEROUTAGE_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_E, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_E_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_F] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_F_SURGE_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_F, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_F_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_G] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_G_OVERLOAD_RECORD_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_G, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_G_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_H] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_H_OVERTEMPERATURE_RECORD_COUNT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_H, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_H_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_I] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_I_TIME_SINCE_LAST_EVENT_XG] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_I, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_I_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_J] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_J_LAST_EVENT_EV] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_J, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_J_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_K] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_K_UNDERVOLTAGE_CUTOFF_THRESHOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_K, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_K_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_L] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_L_UNDERVOLTAGE_RECORD_THRESHOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_L, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_L_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_M] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_M_UNDERVOLTAGE_RESTORE_THRESHOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_M, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_M_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_N] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_N_OVERVOLTAGE_CUTOFF_THRESHOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_N, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_N_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_O] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_O_OVERVOLTAGE_RECORD_THRESHOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_O, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_O_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_P] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_P_OVERVOLTAGE_RESTORE_THRESHOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_P, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_P_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_Q] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_Q_OVERLOAD_RECORD_THRESHOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_Q, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_EVENTS_Q_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_R] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_R_UPDATE_THRESHOLD_EV] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_R, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_EVENTS_S] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_EVENTS_S_UPDATE_THRESHOLD_XG] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_EVENTS_S, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
};
/* Full Database Description - Used to add attributes into the measurements database */
static const esp_gatts_attr_db_t gatt_settings_db[ESP_IDX_SETTINGS_NB] =
{
[IDX_SVC_SETTINGS] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(GATTS_SERVICE_UUID_SETTINGS), sizeof(GATTS_SERVICE_UUID_SETTINGS), (uint8_t *)&GATTS_SERVICE_UUID_SETTINGS}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_A] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_A_AUTOTRANSMIT] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_A, ESP_GATT_PERM_READ,
sizeof(firmwareRev), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_SETTINGS_A_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_B] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_B_LINE_VOLTAGE_CONFIGURATION] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(chipID), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_SETTINGS_B_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_C] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_C_CLEAR_MEMORY_ALL] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_D] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_D_CLEAR_EVENT_COUNTS] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_D, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_E] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_E_CLEAR_TIMESTAMPS] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_E, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_F] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_F_CLEAR_HISTORICAL_DATA] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_F, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_G] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_G_RESET_ENERGY_USAGE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_G, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_H] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_H_SET_DEVICE_TIME] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_H, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_I] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_I_INTERNAL_CHART_MODE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_I, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_SETTINGS_I_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_J] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_J_GROUND_DETECTION] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_J, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_SETTINGS_J_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_K] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_K_OVERLOAD_SHUTDOWN] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_K, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_SETTINGS_K_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_SETTINGS_L] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_SETTINGS_L_POWER_FAIL_HOLD] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_SETTINGS_L, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_SETTINGS_L_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(cccd), (uint8_t *)cccd}},
};
/* Full Database Description - Used to add attributes into the measurements database */
static const esp_gatts_attr_db_t gatt_datasets_db[ESP_IDX_DATASETS_NB] =
{
[IDX_SVC_DATASETS] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(GATTS_SERVICE_UUID_DATASETS), sizeof(GATTS_SERVICE_UUID_DATASETS), (uint8_t *)&GATTS_SERVICE_UUID_DATASETS}},
/* Characteristic Declaration */
[IDX_CHAR_DATASETS_A] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DATASETS_A_EEPROM_XG] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DATASETS_A, ESP_GATT_PERM_READ,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DATASETS_A_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DATASETS_B] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DATASETS_B_HISTORICAL_DATA] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DATASETS_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DATASETS_B_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DATASETS_C] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DATASETS_C_TIMESTAMPED_DATA] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DATASETS_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DATASETS_C_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DATASETS_D] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DATASETS_D_INTERNAL_CHART_DATA] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DATASETS_D, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DATASETS_D_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_DATASETS_E] =
{{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_indicate}},
/* Characteristic Value */
[IDX_CHAR_DATASETS_E_TIMESTAMPED_WAVEFORMS] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_DATASETS_E, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_DATASETS_E_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(cccd), (uint8_t *)cccd}},
};
/* Full Database Description - Used to add attributes into the measurements database */
static const esp_gatts_attr_db_t gatt_streaming_db[ESP_IDX_STREAMING_NB] =
{
[IDX_SVC_STREAMING] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(GATTS_SERVICE_UUID_STREAMING), sizeof(GATTS_SERVICE_UUID_STREAMING), (uint8_t *)&GATTS_SERVICE_UUID_STREAMING}},
/* Characteristic Declaration */
[IDX_CHAR_STREAMING_A] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_STREAMING_A_STREAM_SCOPE_DATA] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_STREAMING_A, ESP_GATT_PERM_READ,
sizeof(firmwareRev), sizeof(initNull), (uint8_t *)initNull}},
/* Characteristic Declaration */
[IDX_CHAR_STREAMING_B] =
{{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_notify}},
/* Characteristic Value */
[IDX_CHAR_STREAMING_B_VOLTAGE_SCOPE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_STREAMING_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(chipID), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_STREAMING_B_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_STREAMING_C] =
{{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_notify}},
/* Characteristic Value */
[IDX_CHAR_STREAMING_C_CURRENT_SCOPE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_STREAMING_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_STREAMING_C_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_STREAMING_D] =
{{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_notify}},
/* Characteristic Value */
[IDX_CHAR_STREAMING_D_VOLTAGE_CURRENT_SCOPE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_STREAMING_D, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_STREAMING_D_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(cccd), (uint8_t *)cccd}},
};
/* Full Database Description - Used to add attributes into the measurements database */
static const esp_gatts_attr_db_t gatt_battery_db[ESP_IDX_BATTERY_NB] =
{
[IDX_SVC_BATTERY] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_BATTERY), (uint8_t *)&GATTS_SERVICE_UUID_BATTERY}},
/* Characteristic Declaration */
[IDX_CHAR_BATTERY_A] =
{{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}},
/* Characteristic Value */
[IDX_CHAR_BATTERY_A_BATTERY_LEVEL] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_BATTERY_BATTERY_LEVEL, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(chipID), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_BATTERY_A_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(cccd), (uint8_t *)cccd}},
};
/* Full Database Description - Used to add attributes into the measurements database */
static const esp_gatts_attr_db_t gatt_configuration_db[ESP_IDX_CONFIGURATION_NB] =
{
[IDX_SVC_CONFIGURATION] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(GATTS_SERVICE_UUID_CONFIGURATION), sizeof(GATTS_SERVICE_UUID_CONFIGURATION), (uint8_t *)&GATTS_SERVICE_UUID_CONFIGURATION}},
/* Characteristic Declaration */
[IDX_CHAR_CONFIGURATION_A] =
{{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_write}},
/* Characteristic Value */
[IDX_CHAR_CONFIGURATION_A_STREAM_SCOPE_DATA] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_CONFIGURATION_A, ESP_GATT_PERM_READ,
sizeof(firmwareRev), sizeof(initNull), (uint8_t *)initNull}},
/* Characteristic Declaration */
[IDX_CHAR_CONFIGURATION_B] =
{{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_notify}},
/* Characteristic Value */
[IDX_CHAR_CONFIGURATION_B_VOLTAGE_SCOPE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_CONFIGURATION_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(chipID), sizeof(initNull), (uint8_t *)initNull}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_CONFIGURATION_B_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_CONFIGURATION_C] =
{{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_notify}},
/* Characteristic Value */
[IDX_CHAR_CONFIGURATION_C_CURRENT_SCOPE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_CONFIGURATION_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_CONFIGURATION_C_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(cccd), (uint8_t *)cccd}},
/* Characteristic Declaration */
[IDX_CHAR_CONFIGURATION_D] =
{{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_notify}},
/* Characteristic Value */
[IDX_CHAR_CONFIGURATION_D_VOLTAGE_CURRENT_SCOPE] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_CONFIGURATION_D, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(communicationMode), sizeof(xg), (uint8_t *)xg}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_CONFIGURATION_D_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(cccd), (uint8_t *)cccd}},
};
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\n");
}else{
ESP_LOGI(GATTS_TABLE_TAG, "advertising start successfully\n");
}
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\n");
}
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 connetion 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 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\n", __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\n");
}
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);
}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_LOGI(GATTS_TABLE_TAG, "before create attr error");
esp_err_t create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_device_db, gatts_if, ESP_IDX_DEVICE_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_measurements_db, gatts_if, ESP_IDX_MEASUREMENTS_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_events_db, gatts_if, ESP_IDX_EVENTS_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_settings_db, gatts_if, ESP_IDX_SETTINGS_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_datasets_db, gatts_if, ESP_IDX_DATASETS_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_streaming_db, gatts_if, ESP_IDX_STREAMING_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_battery_db, gatts_if, ESP_IDX_BATTERY_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_configuration_db, gatts_if, ESP_IDX_CONFIGURATION_NB, SVC_INST_ID);
if (create_attr_ret){
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
}
//ESP_LOGI(GATTS_TABLE_TAG, "after create attr error");
}
break;
case ESP_GATTS_READ_EVT:
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_READ_EVT");
break;
case ESP_GATTS_WRITE_EVT:
if (!param->write.is_prep){
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 a CCCD, update the notify/indicate value
if ((device_handle_table[IDX_CHAR_DEVICE_A_CFG] == param->write.handle || device_handle_table[IDX_CHAR_DEVICE_B_CFG] == param->write.handle || device_handle_table[IDX_CHAR_DEVICE_C_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");
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, device_handle_table[IDX_CHAR_DEVICE_A_FIRMWARE_REVISION],
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, device_handle_table[IDX_CHAR_DEVICE_A_FIRMWARE_REVISION],
sizeof(indicate_data), indicate_data, true);
}
else if (descr_value == 0x0000){
ESP_LOGI(GATTS_TABLE_TAG, "notify/indicate disable ");
}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:
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);
//MTU changed call back, set up when MTU size is negotiated??
break;
case ESP_GATTS_CONF_EVT:
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONF_EVT, status = %d", param->conf.status);
//send notification or indication failed
break;
case ESP_GATTS_START_EVT:
ESP_LOGI(GATTS_TABLE_TAG, "SERVICE_START_EVT, status %d, service_handle %d\n", param->start.status, param->start.service_handle);
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 reference the 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);
break;
case ESP_GATTS_DISCONNECT_EVT:
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_DISCONNECT_EVT, reason = %d", param->disconnect.reason);
esp_ble_gap_start_advertising(&adv_params);
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.svc_uuid.len == ESP_UUID_LEN_16){
if(param->add_attr_tab.svc_uuid.uuid.uuid16 == 0x180F){ //battery service
if (param->add_attr_tab.num_handle != ESP_IDX_BATTERY_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_BATTERY_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_BATTERY_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(battery_handle_table, param->add_attr_tab.handles, sizeof(battery_handle_table));
esp_ble_gatts_start_service(battery_handle_table[IDX_SVC_BATTERY]);
}
}
else{
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, the number handle = %d\n",param->add_attr_tab.num_handle);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid length = %d\n",param->add_attr_tab.svc_uuid.len);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid16 = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid16);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid32 = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid32);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[1] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[1]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[2] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[2]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[3] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[3]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[4] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[4]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[5] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[5]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[6] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[6]);
}
}
else{
switch(param->add_attr_tab.svc_uuid.uuid.uuid128[9]){
case 0x02:{ //DEVICE Service
if (param->add_attr_tab.num_handle != ESP_IDX_DEVICE_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_DEVICE_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_DEVICE_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(device_handle_table, param->add_attr_tab.handles, sizeof(device_handle_table));
esp_ble_gatts_start_service(device_handle_table[IDX_SVC_DEVICE]);
}
break;
}
case 0x03:{ //MEASUREMENTS Service
if (param->add_attr_tab.num_handle != ESP_IDX_MEASUREMENTS_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_MEASUREMENTS_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_MEASUREMENTS_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(measurements_handle_table, param->add_attr_tab.handles, sizeof(measurements_handle_table));
esp_ble_gatts_start_service(measurements_handle_table[IDX_SVC_MEASUREMENTS]);
}
break;
}
case 0x04:{ //EVENTS Services
if (param->add_attr_tab.num_handle != ESP_IDX_EVENTS_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_EVENTS_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_EVENTS_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(events_handle_table, param->add_attr_tab.handles, sizeof(events_handle_table));
esp_ble_gatts_start_service(events_handle_table[IDX_SVC_EVENTS]);
}
break;
}
case 0x05:{ //SETTINGS Services
if (param->add_attr_tab.num_handle != ESP_IDX_SETTINGS_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_SETTINGS_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_SETTINGS_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(settings_handle_table, param->add_attr_tab.handles, sizeof(settings_handle_table));
esp_ble_gatts_start_service(settings_handle_table[IDX_SVC_SETTINGS]);
}
break;
}
case 0x06:{ //DATASETS Services
if (param->add_attr_tab.num_handle != ESP_IDX_DATASETS_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_DATASETS_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_DATASETS_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(datasets_handle_table, param->add_attr_tab.handles, sizeof(datasets_handle_table));
esp_ble_gatts_start_service(datasets_handle_table[IDX_SVC_DATASETS]);
}
break;
}
case 0x07:{ //STREAMING Services
if (param->add_attr_tab.num_handle != ESP_IDX_STREAMING_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_STREAMING_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_STREAMING_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(streaming_handle_table, param->add_attr_tab.handles, sizeof(streaming_handle_table));
esp_ble_gatts_start_service(streaming_handle_table[IDX_SVC_STREAMING]);
}
break;
}
case 0x08:{ //CONFIGURATION Services
if (param->add_attr_tab.num_handle != ESP_IDX_CONFIGURATION_NB){
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_CONFIGURATION_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_CONFIGURATION_NB);
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(streaming_handle_table, param->add_attr_tab.handles, sizeof(streaming_handle_table));
esp_ble_gatts_start_service(streaming_handle_table[IDX_SVC_CONFIGURATION]);
}
break;
}
default :{
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, the number handle = %d\n",param->add_attr_tab.num_handle);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid length = %d\n",param->add_attr_tab.svc_uuid.len);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid16 = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid16);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid32 = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid32);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[1] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[1]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[2] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[2]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[3] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[3]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[4] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[4]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[5] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[5]);
ESP_LOGE(GATTS_TABLE_TAG, "attribute table does not match any known cases, uuid128[6] = %d\n",param->add_attr_tab.svc_uuid.uuid.uuid128[6]);
break;
}
}
}
/*
if (param->add_attr_tab.num_handle != ESP_IDX_DEVICE_NB){
if(param->add_attr_tab.num_handle == ESP_IDX_MEASUREMENTS_NB){
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(measurements_handle_table, param->add_attr_tab.handles, sizeof(measurements_handle_table));
esp_ble_gatts_start_service(measurements_handle_table[IDX_SVC_MEASUREMENTS]);
}
else{
ESP_LOGE(GATTS_TABLE_TAG, "create attribute table abnormally, num_handle (%d) \
doesn't equal to ESP_IDX_DEVICE_NB(%d)", param->add_attr_tab.num_handle, ESP_IDX_DEVICE_NB);
}
}
else {
ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
memcpy(device_handle_table, param->add_attr_tab.handles, sizeof(device_handle_table));
esp_ble_gatts_start_service(device_handle_table[IDX_SVC_DEVICE]);
}
*
*/
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_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 < 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);
}
void app_main()
{
esp_err_t ret;
/* Initialize NVS. */
ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
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\n", __func__);
return;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret) {
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
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\n", __func__);
return;
}
ret = esp_bluedroid_enable();
if (ret) {
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed\n", __func__);
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);
}
initUART();
startUartTasks();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment