|
@ -30,36 +30,40 @@ bleuart_t ble_uart_init_struct = { |
|
|
.bleName = "yimei_ble", |
|
|
.bleName = "yimei_ble", |
|
|
}; |
|
|
}; |
|
|
motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; |
|
|
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) { |
|
|
void processrxjson(cJSON *rxjson) { |
|
|
if (!cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) { |
|
|
if (!cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const char *order = cJSON_GetStringValue(cJSON_GetObjectItem(rxjson, "order")); |
|
|
const char *order = cJSON_GetStringValue(cJSON_GetObjectItem(rxjson, "order")); |
|
|
|
|
|
|
|
|
if (strcmp(order, "setPosition") == 0) { |
|
|
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) { |
|
|
} else if (strcmp(order, "getStatus") == 0) { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void blerxcb(uint8_t *rxmessage, size_t rxsize) { |
|
|
void blerxcb(uint8_t *rxmessage, size_t rxsize) { |
|
@ -82,8 +86,9 @@ void motor_on_event(motor_event_t event) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void app_main(void) { |
|
|
void app_main(void) { |
|
|
ble_spp_server_demo_app_main(&ble_uart_init_struct); |
|
|
|
|
|
|
|
|
bleuart_init(&ble_uart_init_struct); |
|
|
bleuart_reg_cb(blerxcb); |
|
|
bleuart_reg_cb(blerxcb); |
|
|
|
|
|
|
|
|
motor_init(&ble_uart_motor_structer); |
|
|
motor_init(&ble_uart_motor_structer); |
|
|
motor_reg_event_cb(motor_on_event); |
|
|
motor_reg_event_cb(motor_on_event); |
|
|
|
|
|
|
|
|