|
|
@ -208,14 +208,14 @@ typedef struct bluetooth_processer |
|
|
|
void (*port_delay_ms)(uint64_t us); |
|
|
|
|
|
|
|
char *order; //指令名称 |
|
|
|
uint8_t index; // |
|
|
|
uint8_t speed_level; // |
|
|
|
int index; // |
|
|
|
int speed_level; // |
|
|
|
double position; //角度 |
|
|
|
int direction; //旋转方向 |
|
|
|
uint8_t code; //错误码 |
|
|
|
int code; //错误码 |
|
|
|
char *info; //错误码信息 |
|
|
|
char *deviceState; //设备状态 |
|
|
|
uint8_t deviceException; //设备异常编号 |
|
|
|
int deviceException; //设备异常编号 |
|
|
|
char *deviceExceptionInfo; //设备异常信息 |
|
|
|
|
|
|
|
bool cmd_flag; |
|
|
@ -223,7 +223,7 @@ typedef struct bluetooth_processer |
|
|
|
|
|
|
|
} bluetooth_processer_t; |
|
|
|
|
|
|
|
#define profile_b_buffer_size 100 |
|
|
|
#define profile_b_buffer_size 128 |
|
|
|
char bluetooth_rx_buffer[profile_b_buffer_size] = {0}; |
|
|
|
uint8_t bluetooth_rx_buffer_len = 0; |
|
|
|
bool bluetooth_rx_buffer_start_receving = false; |
|
|
@ -246,6 +246,7 @@ void timer_set_pause_and_counter_zero(int group, int timer); |
|
|
|
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); |
|
|
|
bool parse_json_to_struct(cJSON *ch); |
|
|
|
|
|
|
|
bluetooth_processer_t s_bluetooth_processer = { |
|
|
|
.bluetooth_processer_rx_buf = bluetooth_rx_buffer, |
|
|
@ -920,7 +921,7 @@ bool validation_param(cJSON *object, char *param) |
|
|
|
void bluetooth_gatts_try_process_data() |
|
|
|
{ |
|
|
|
cJSON *json_tmp; |
|
|
|
cJSON *ch; |
|
|
|
// cJSON *ch; |
|
|
|
//开始接收 |
|
|
|
if (bluetooth_rx_buffer_start_receving) |
|
|
|
{ |
|
|
@ -933,46 +934,21 @@ void bluetooth_gatts_try_process_data() |
|
|
|
// ESP_LOGI(GATTS_TAG, "%s", s_bluetooth_processer.bluetooth_processer_rx_buf); |
|
|
|
|
|
|
|
//验证解析数据是否正确 |
|
|
|
if (!parse_rxbuffer_and_validation_data(&json_tmp)) |
|
|
|
if (parse_rxbuffer_and_validation_data(&json_tmp)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
ch = json_tmp->child; |
|
|
|
|
|
|
|
while (ch != NULL) |
|
|
|
{ |
|
|
|
ESP_LOGI(GATTS_TAG, "%s", ch->string); |
|
|
|
if (strcmp(ch->string, "order") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.order = ch->valuestring; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "index") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.index = ch->valueint; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "speedLevel") == 0) |
|
|
|
// JSON解析到结构体,如果order更改表示有指令传输进来,并且更改指令标志位(cmd_flag)为true |
|
|
|
if (parse_json_to_struct(json_tmp->child)) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.speed_level = ch->valueint; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "position") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.position = ch->valuedouble; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "direction") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.direction = ch->valueint; |
|
|
|
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); |
|
|
|
} |
|
|
|
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 |
|
|
|
buffer_all_init(); |
|
|
|
//未在处理数据 |
|
|
|
s_bluetooth_processer.cmd_flag = false; |
|
|
|
bluetooth_rx_buffer_start_receving = false; |
|
|
|
bluetooth_rx_buffer_processing = false; |
|
|
|
} |
|
|
@ -1018,11 +994,39 @@ bool parse_rxbuffer_and_validation_data(cJSON **json_tmp) |
|
|
|
if (*json_tmp == NULL) |
|
|
|
{ |
|
|
|
ESP_LOGE("ERROR", "json_tmp null"); |
|
|
|
cJSON_Delete(*json_tmp); |
|
|
|
buffer_all_init(); |
|
|
|
bluetooth_rx_buffer_start_receving = false; |
|
|
|
bluetooth_rx_buffer_processing = false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
bool parse_json_to_struct(cJSON *ch) |
|
|
|
{ |
|
|
|
while (ch != NULL) |
|
|
|
{ |
|
|
|
// ESP_LOGI(GATTS_TAG, "%s", ch->string); |
|
|
|
if (strcmp(ch->string, "order") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.order = ch->valuestring; |
|
|
|
s_bluetooth_processer.cmd_flag = true; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "index") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.index = ch->valueint; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "speedLevel") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.speed_level = ch->valueint; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "position") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.position = ch->valuedouble; |
|
|
|
} |
|
|
|
if (strcmp(ch->string, "direction") == 0) |
|
|
|
{ |
|
|
|
s_bluetooth_processer.direction = ch->valueint; |
|
|
|
} |
|
|
|
ch = ch->next; |
|
|
|
} |
|
|
|
|
|
|
|
return s_bluetooth_processer.cmd_flag; |
|
|
|
} |