Browse Source

参数解析到结构体中

master
zwsd 3 years ago
parent
commit
a082dcbac2
  1. 69
      main/gatts_demo.c
  2. 0
      main/motor_drive.c
  3. 0
      main/motor_drive.h

69
main/gatts_demo.c

@ -37,6 +37,8 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "motor_drive.h"
#define GATTS_TAG "GATTS_DEMO" #define GATTS_TAG "GATTS_DEMO"
/// Declare the static function /// 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**************************************************** * * ****************************************************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 #define profile_b_buffer_size 100
char bluetooth_rx_buffer[profile_b_buffer_size] = {0}; char bluetooth_rx_buffer[profile_b_buffer_size] = {0};
uint8_t bluetooth_rx_buffer_len = 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_s (uint32_t)1000000
#define timer_interval_ms (uint32_t)1000 #define timer_interval_ms (uint32_t)1000
#define timer_interval_us (uint32_t)1 #define timer_interval_us (uint32_t)1
#define kbluetooth_baundrate_one_packet_delay_ms 200
/*********************************************************************************************************************** /***********************************************************************************************************************
* **********************************************user_function_statement********************************************** * * **********************************************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); void start_receive_data_to_buffer(uint16_t length, uint8_t *value);
bool parse_rxbuffer_and_validation_data(cJSON **json_tmp); 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) static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{ {
switch (event) switch (event)
@ -874,14 +921,16 @@ void bluetooth_gatts_try_process_data()
{ {
cJSON *json_tmp; cJSON *json_tmp;
cJSON *ch; cJSON *ch;
//
//
if (bluetooth_rx_buffer_start_receving) 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; 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)) 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); ESP_LOGI(GATTS_TAG, "%s", ch->string);
if (strcmp(ch->string, "order") == 0) if (strcmp(ch->string, "order") == 0)
{ {
ESP_LOGI("receve", "order");
s_bluetooth_processer.order = ch->valuestring;
} }
if (strcmp(ch->string, "index") == 0) if (strcmp(ch->string, "index") == 0)
{ {
ESP_LOGI("receve", "index");
s_bluetooth_processer.index = ch->valueint;
} }
if (strcmp(ch->string, "speedLevel") == 0) if (strcmp(ch->string, "speedLevel") == 0)
{ {
ESP_LOGI("receve", "speedLevel");
s_bluetooth_processer.speed_level = ch->valueint;
} }
if (strcmp(ch->string, "position") == 0) if (strcmp(ch->string, "position") == 0)
{ {
ESP_LOGI("receve", "position");
s_bluetooth_processer.position = ch->valuedouble;
} }
if (strcmp(ch->string, "direction") == 0) if (strcmp(ch->string, "direction") == 0)
{ {
ESP_LOGI("receve", "direction");
s_bluetooth_processer.direction = ch->valueint;
} }
ch = ch->next; 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); cJSON_Delete(json_tmp);
// buffer置0 // buffer置0

0
main/motor_drive.c

0
main/motor_drive.h

Loading…
Cancel
Save