|
|
@ -37,6 +37,8 @@ |
|
|
|
|
|
|
|
#include "sdkconfig.h" |
|
|
|
|
|
|
|
#include "motor_drive.h" |
|
|
|
|
|
|
|
#define GATTS_TAG "GATTS_DEMO" |
|
|
|
|
|
|
|
/// Declare the static function |
|
|
@ -197,7 +199,30 @@ void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble |
|
|
|
/*********************************************************************************************************************** |
|
|
|
* ****************************************************user_define**************************************************** * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
//实际只让接收profile_b_buffer_size-1个 |
|
|
|
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); |
|
|
|
|
|
|
|
char *order; //指令名称 |
|
|
|
uint8_t index; // |
|
|
|
uint8_t speed_level; // |
|
|
|
double position; //角度 |
|
|
|
int direction; //旋转方向 |
|
|
|
uint8_t code; //错误码 |
|
|
|
char *info; //错误码信息 |
|
|
|
char *deviceState; //设备状态 |
|
|
|
uint8_t deviceException; //设备异常编号 |
|
|
|
char *deviceExceptionInfo; //设备异常信息 |
|
|
|
|
|
|
|
bool cmd_flag; |
|
|
|
bool actively_report_flag; |
|
|
|
|
|
|
|
} bluetooth_processer_t; |
|
|
|
|
|
|
|
#define profile_b_buffer_size 100 |
|
|
|
char bluetooth_rx_buffer[profile_b_buffer_size] = {0}; |
|
|
|
uint8_t bluetooth_rx_buffer_len = 0; |
|
|
@ -210,6 +235,7 @@ uint32_t total = 0; |
|
|
|
#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 |
|
|
|
|
|
|
|
/*********************************************************************************************************************** |
|
|
|
* **********************************************user_function_statement********************************************** * |
|
|
@ -221,6 +247,27 @@ void port_timer_delay_ms(uint64_t delay); |
|
|
|
void start_receive_data_to_buffer(uint16_t length, uint8_t *value); |
|
|
|
bool parse_rxbuffer_and_validation_data(cJSON **json_tmp); |
|
|
|
|
|
|
|
bluetooth_processer_t s_bluetooth_processer = { |
|
|
|
.bluetooth_processer_rx_buf = bluetooth_rx_buffer, |
|
|
|
.bluetooth_processer_rx_buf_size = sizeof(bluetooth_rx_buffer), |
|
|
|
.bluetooth_baundrate_one_packet_delay_ms = kbluetooth_baundrate_one_packet_delay_ms, |
|
|
|
.port_delay_ms = port_timer_delay_ms, |
|
|
|
|
|
|
|
.order = "order", |
|
|
|
.index = 0, |
|
|
|
.speed_level = 0, |
|
|
|
.position = 0.0, |
|
|
|
.direction = 0, |
|
|
|
.code = 0, |
|
|
|
.info = "noerror", |
|
|
|
.deviceState = "init", |
|
|
|
.deviceException = 0, |
|
|
|
.deviceExceptionInfo = "noexception", |
|
|
|
|
|
|
|
.cmd_flag = false, |
|
|
|
.actively_report_flag = false, |
|
|
|
}; |
|
|
|
|
|
|
|
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) |
|
|
|
{ |
|
|
|
switch (event) |
|
|
@ -874,14 +921,16 @@ void bluetooth_gatts_try_process_data() |
|
|
|
{ |
|
|
|
cJSON *json_tmp; |
|
|
|
cJSON *ch; |
|
|
|
//接收完毕 |
|
|
|
//开始接收 |
|
|
|
if (bluetooth_rx_buffer_start_receving) |
|
|
|
{ |
|
|
|
//开启定时器 |
|
|
|
port_timer_delay_ms(200); |
|
|
|
s_bluetooth_processer.port_delay_ms(s_bluetooth_processer.bluetooth_baundrate_one_packet_delay_ms); |
|
|
|
// port_timer_delay_ms(kbluetooth_baundrate_one_packet_delay_ms); |
|
|
|
bluetooth_rx_buffer_processing = true; |
|
|
|
|
|
|
|
//打印输出 |
|
|
|
ESP_LOGI(GATTS_TAG, "%s", &bluetooth_rx_buffer[0]); |
|
|
|
// ESP_LOGI(GATTS_TAG, "%s", s_bluetooth_processer.bluetooth_processer_rx_buf); |
|
|
|
|
|
|
|
//验证解析数据是否正确 |
|
|
|
if (!parse_rxbuffer_and_validation_data(&json_tmp)) |
|
|
@ -896,27 +945,29 @@ void bluetooth_gatts_try_process_data() |
|
|
|
ESP_LOGI(GATTS_TAG, "%s", ch->string); |
|
|
|
if (strcmp(ch->string, "order") == 0) |
|
|
|
{ |
|
|
|
ESP_LOGI("receve", "order"); |
|
|
|
s_bluetooth_processer.order = ch->valuestring; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "index") == 0) |
|
|
|
{ |
|
|
|
ESP_LOGI("receve", "index"); |
|
|
|
s_bluetooth_processer.index = ch->valueint; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "speedLevel") == 0) |
|
|
|
{ |
|
|
|
ESP_LOGI("receve", "speedLevel"); |
|
|
|
s_bluetooth_processer.speed_level = ch->valueint; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "position") == 0) |
|
|
|
{ |
|
|
|
ESP_LOGI("receve", "position"); |
|
|
|
s_bluetooth_processer.position = ch->valuedouble; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "direction") == 0) |
|
|
|
{ |
|
|
|
ESP_LOGI("receve", "direction"); |
|
|
|
s_bluetooth_processer.direction = ch->valueint; |
|
|
|
} |
|
|
|
ch = ch->next; |
|
|
|
} |
|
|
|
|
|
|
|
ESP_LOGI(GATTS_TAG, "order:%s ,index:%d speedLevel:%d position:%f direction:%d", s_bluetooth_processer.order, s_bluetooth_processer.index, s_bluetooth_processer.speed_level, s_bluetooth_processer.position, s_bluetooth_processer.direction); |
|
|
|
|
|
|
|
//释放空间 |
|
|
|
cJSON_Delete(json_tmp); |
|
|
|
// buffer置0 |
|
|
|