You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

133 lines
3.9 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.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 "driver/timer.h"
#include "cJSON.h"
#include "cJSON_Utils.h"
#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "esp_gatt_common_api.h"
#include "sdkconfig.h"
#define GATTS_TAG "GATTS_DEMO"
#define GATTS_SERVICE_UUID_TEST_A 0x00FF
#define GATTS_CHAR_UUID_TEST_A 0xFF01
#define GATTS_DESCR_UUID_TEST_A 0x3333
#define GATTS_NUM_HANDLE_TEST_A 4
#define GATTS_SERVICE_UUID_TEST_B 0x00EE
#define GATTS_CHAR_UUID_TEST_B 0xEE01
#define GATTS_DESCR_UUID_TEST_B 0x2222
#define GATTS_NUM_HANDLE_TEST_B 4
#define TEST_DEVICE_NAME "ESP_GATTS_DEMO"
#define TEST_MANUFACTURER_DATA_LEN 17
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 0x40
#define PREPARE_BUF_MAX_SIZE 1024
#define adv_config_flag (1 << 0)
#define scan_rsp_config_flag (1 << 1)
#define PROFILE_NUM 2
#define PROFILE_A_APP_ID 0
#define PROFILE_B_APP_ID 1
/***********************************************************************************************************************
* ****************************************************user_define**************************************************** *
***********************************************************************************************************************/
#define profile_b_buffer_size 128
#define timer_group0_interval_num 10000
// #define timer_group1_interval_num 5
#define timer_interval_s (uint32_t)1000000
#define timer_interval_ms (uint32_t)1000
#define timer_interval_us (uint32_t)1
#define kbluetooth_baundrate_one_packet_delay_ms 200
#define cmd_length_set_position 5
#define cmd_length_get_status 2
// #define cmd_length_device_status_report 6
#define set_position "setPosition"
#define get_status "getStatus"
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
{
uint8_t *prepare_buf;
int prepare_len;
} prepare_type_env_t;
typedef struct ble_gatts_str
{
uint8_t send_gatts_if;
uint16_t send_conn_id;
uint16_t attr_handle;
} ble_gatts_str_t;
typedef struct bluetooth_processer
{
char *bluetooth_processer_rx_buf;
uint8_t bluetooth_processer_rx_buf_size; //
int bluetooth_baundrate_one_packet_delay_ms;
void (*port_delay_ms)(uint64_t us);
bool bluetooth_rx_buffer_start_receving;
bool bluetooth_rx_buffer_processing;
char *order; //指令名称
int index; //
int speed_level; //
double position; //角度
int direction; //旋转方向
int code; //错误码
char *info; //错误码信息
char *deviceState; //设备状态
int deviceException; //设备异常编号
char *deviceExceptionInfo; //设备异常信息
bool cmd_flag;
bool actively_report_flag;
} bluetooth_processer_t;
void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param);
void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param);
void esp_ble_gatts_init(ble_gatts_str_t *ble_gatts_a_str, bluetooth_processer_t *bluetooth_processer);
void gatts_profile_a_constructor(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
void start_receive_data_to_buffer(uint16_t length, uint8_t *value);
void buffer_all_init();
void gatts_profile_a_constructor_s();