|
|
@ -73,12 +73,39 @@ bleuart_t ble_uart_init_struct = { |
|
|
|
}; |
|
|
|
motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; |
|
|
|
|
|
|
|
void order_receipt_setPosition(int index, uint8_t setPosition_code) { |
|
|
|
uint8_t buffer[256] = {0}; |
|
|
|
|
|
|
|
ESP_LOGI(MAIN_LOG_TAG, "Command setPosition execution complete!"); |
|
|
|
|
|
|
|
if (setPosition_code == 0) { |
|
|
|
sprintf((char *)buffer, "{ \"order\": \"receipt\", \"code\": %d, \"info\": \"success\", \"index\": %d }", setPosition_code, index); |
|
|
|
bleuart_notify_send(buffer, strlen((char *)buffer)); |
|
|
|
} else { |
|
|
|
sprintf((char *)buffer, "{ \"order\": \"receipt\", \"code\": %d, \"info\": \"error\", \"index\": %d }", setPosition_code, index); |
|
|
|
bleuart_notify_send(buffer, strlen((char *)buffer)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void order_receipt_getStatus(int index) { |
|
|
|
ESP_LOGI(MAIN_LOG_TAG, "Command getStatus execution complete!"); |
|
|
|
uint8_t buffer[256] = {0}; |
|
|
|
double motor_position = motor_get_position_degree(); |
|
|
|
|
|
|
|
sprintf((char *)buffer, |
|
|
|
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"running\", \"deviceException\": 0, \"deviceExceptionInfo\": " |
|
|
|
", \"position\":%lf }", |
|
|
|
index, motor_position); |
|
|
|
bleuart_notify_send(buffer, strlen((char *)buffer)); |
|
|
|
} |
|
|
|
|
|
|
|
void process_setPosition(cJSON *rxjson) { |
|
|
|
// { "order": "setPosition", "ble_uart_index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } |
|
|
|
int index = 0; |
|
|
|
int speedLevel = 0; |
|
|
|
float position = 0; |
|
|
|
int direction = 0; |
|
|
|
uint8_t setPosition_code; |
|
|
|
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "position"))) { |
|
|
|
position = cJSON_GetObjectItem(rxjson, "position")->valuedouble; |
|
|
|
} |
|
|
@ -92,7 +119,16 @@ void process_setPosition(cJSON *rxjson) { |
|
|
|
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) { |
|
|
|
direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction")); |
|
|
|
} |
|
|
|
motor_run_to_postion(1, position, 0); |
|
|
|
setPosition_code = motor_run_to_postion(1, position, 0); |
|
|
|
order_receipt_setPosition(index, setPosition_code); |
|
|
|
} |
|
|
|
|
|
|
|
void process_getStatus(cJSON *rxjson) { |
|
|
|
int index = 0; |
|
|
|
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "index"))) { |
|
|
|
index = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "index")); |
|
|
|
} |
|
|
|
order_receipt_getStatus(index); |
|
|
|
} |
|
|
|
|
|
|
|
void processrxjson(cJSON *rxjson) { |
|
|
@ -106,6 +142,7 @@ void processrxjson(cJSON *rxjson) { |
|
|
|
process_setPosition(rxjson); |
|
|
|
|
|
|
|
} else if (strcmp(order, "getStatus") == 0) { |
|
|
|
process_getStatus(rxjson); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|