diff --git a/main/ble_spp_server_demo.c b/main/ble_spp_server_demo.c index 12152cf..27b544d 100644 --- a/main/ble_spp_server_demo.c +++ b/main/ble_spp_server_demo.c @@ -638,7 +638,7 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ void bleuart_reg_cb(blerxcb_t cb) { s_cb = cb; } -void ble_spp_server_demo_app_main(bleuart_t *bleuart) { +void bleuart_init(bleuart_t *bleuart) { esp_err_t ret; esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); diff --git a/main/ble_spp_server_demo.h b/main/ble_spp_server_demo.h index 779b648..22d3f6a 100644 --- a/main/ble_spp_server_demo.h +++ b/main/ble_spp_server_demo.h @@ -80,7 +80,8 @@ typedef struct { /*接收完整JSON*/ typedef void (*blerxcb_t)(uint8_t *rx, size_t rxsize); -void ble_spp_server_demo_app_main(bleuart_t *bleuart); + +void bleuart_init(bleuart_t *bleuart); void bleuart_reg_cb(blerxcb_t cb); void bleuart_send_packet(uint8_t *tx, size_t txsize); diff --git a/main/main.c b/main/main.c index 2fc1242..1a00606 100644 --- a/main/main.c +++ b/main/main.c @@ -30,36 +30,40 @@ bleuart_t ble_uart_init_struct = { .bleName = "yimei_ble", }; motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; + +void process_setPosition(cJSON *rxjson) { + // { "order": "setPosition", "index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } + int index = 0; + int speedLevel = 0; + float position = 0; + int direction = 0; + if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "position"))) { + position = cJSON_GetObjectItem(rxjson, "position")->valuedouble; + } + if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "index"))) { + index = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "index")); + } + if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "speedLevel"))) { + speedLevel = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "speedLevel")); + } + + if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) { + direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction")); + } + motor_run_to_postion(1, position, index); +} + void processrxjson(cJSON *rxjson) { if (!cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) { return; } + const char *order = cJSON_GetStringValue(cJSON_GetObjectItem(rxjson, "order")); if (strcmp(order, "setPosition") == 0) { - // { "order": "setPosition", "index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } - int index = 0; - int speedLevel = 0; - float position = 0; - int direction = 0; - if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "position"))) { - position = cJSON_GetObjectItem(rxjson, "position")->valuedouble; - } - if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "index"))) { - index = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "index")); - } - if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "speedLevel"))) { - speedLevel = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "speedLevel")); - } - - if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) { - direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction")); - } - motor_run_to_postion(1, position, index); - //组包,上报 + process_setPosition(rxjson); } else if (strcmp(order, "getStatus") == 0) { - - } + } } void blerxcb(uint8_t *rxmessage, size_t rxsize) { @@ -82,8 +86,9 @@ void motor_on_event(motor_event_t event) { } void app_main(void) { - ble_spp_server_demo_app_main(&ble_uart_init_struct); + bleuart_init(&ble_uart_init_struct); bleuart_reg_cb(blerxcb); + motor_init(&ble_uart_motor_structer); motor_reg_event_cb(motor_on_event);