|
|
@ -58,10 +58,18 @@ void construct_set_position_packet_and_report(int index, uint8_t setPosition_cod |
|
|
|
|
|
|
|
void construct_get_status_packet_and_report(int index, double motor_position) { |
|
|
|
uint8_t buffer[construct_cmd_packet_buffer_size] = {0}; |
|
|
|
snprintf((char *)buffer, construct_cmd_packet_buffer_size, |
|
|
|
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"running\", \"deviceException\": 0, \"deviceExceptionInfo\": " |
|
|
|
", \"position\":%lf }", |
|
|
|
index, motor_position); |
|
|
|
if (motor_turning == false) { |
|
|
|
snprintf((char *)buffer, construct_cmd_packet_buffer_size, |
|
|
|
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"%s\", \"deviceException\": 0, \"deviceExceptionInfo\": " |
|
|
|
", \"position\":%lf }", |
|
|
|
index, "idel", motor_position); |
|
|
|
} else { |
|
|
|
snprintf((char *)buffer, construct_cmd_packet_buffer_size, |
|
|
|
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"%s\", \"deviceException\": 0, \"deviceExceptionInfo\": " |
|
|
|
", \"position\":%lf }", |
|
|
|
index, "rotating", motor_position); |
|
|
|
} |
|
|
|
|
|
|
|
ESP_LOGI(MAIN_LOG_TAG, "report %s", buffer); |
|
|
|
bleuart_notify_send(buffer, strlen((char *)buffer)); |
|
|
|
} |
|
|
@ -96,6 +104,7 @@ void process_setPosition(RxContext_t *context, cJSON *rxjson) { |
|
|
|
} |
|
|
|
ESP_LOGI(MAIN_LOG_TAG, "index = %d,speedLevel = %d,position = %lf,direction = %d", index, speedLevel, position, direction); |
|
|
|
setPosition_code = motor_run_to_postion(1, position, 0); |
|
|
|
motor_turning = true; |
|
|
|
construct_set_position_packet_and_report(index, setPosition_code); |
|
|
|
} |
|
|
|
|
|
|
@ -157,6 +166,7 @@ void motor_on_event(motor_event_t event) { |
|
|
|
//打算使用sprintf |
|
|
|
if (event == kRunToPosition) { |
|
|
|
ESP_LOGI(MAIN_LOG_TAG, "motor_on_event: kRunToPosition"); |
|
|
|
motor_turning = false; |
|
|
|
uint8_t buffer[construct_cmd_packet_buffer_size] = {0}; |
|
|
|
double motor_stop_position = motor_get_position_degree(); |
|
|
|
|
|
|
|