Browse Source

update

master
zwsd 3 years ago
parent
commit
1e964e44ae
  1. 32
      main/main.c

32
main/main.c

@ -90,7 +90,27 @@ void construct_get_status_packet_and_report(int index, double motor_position) {
void construct_set_motorCurrentSize_packet_and_report(int index) {
uint8_t buffer[construct_cmd_packet_buffer_size] = {0};
snprintf((char *)buffer, construct_cmd_packet_buffer_size, "{ \"order\": \"receipt\", \"index\": %d }", index);
snprintf((char *)buffer, construct_cmd_packet_buffer_size, "{ \"order\": \"receipt\", \"index\": %d }",
/* index :*/ index //
);
ESP_LOGI(MAIN_LOG_TAG, "report %s", buffer);
bleuart_notify_send(buffer, strlen((char *)buffer));
}
void construct_stop_motor_packet_and_report(int index, bool stop_flag) {
uint8_t buffer[construct_cmd_packet_buffer_size] = {0};
uint8_t *stop_flag_str = "null";
if (stop_flag) {
stop_flag_str = "successful";
} else {
stop_flag_str = "fail";
}
snprintf((char *)buffer, construct_cmd_packet_buffer_size, "{ \"order\": \"receipt\", \"index\": %d \"stopFlag\": %s}",
/* index :*/ index, //
/* stopFlag :*/ stop_flag_str //
);
ESP_LOGI(MAIN_LOG_TAG, "report %s", buffer);
bleuart_notify_send(buffer, strlen((char *)buffer));
}
@ -126,6 +146,12 @@ void process_setMotorCurrentSize(RxContext_t *context, cJSON *rxjson) {
construct_set_motorCurrentSize_packet_and_report(context->index);
}
void process_stopMotor(RxContext_t *context, cJSON *rxjson) {
bool motor_stop_flag;
motor_stop_flag = motor_stop();
construct_stop_motor_packet_and_report(context->index, motor_stop_flag);
}
void processrxjson(cJSON *rxjson) {
if (!cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) {
return;
@ -146,6 +172,8 @@ void processrxjson(cJSON *rxjson) {
process_getStatus(&rxcontext, rxjson);
} else if (strcmp(rxcontext.order, "setMotorCurrentSize") == 0) {
process_setMotorCurrentSize(&rxcontext, rxjson);
} else if (strcmp(rxcontext.order, "stopMotor") == 0) {
process_setMotorCurrentSize(&rxcontext, rxjson);
}
}
@ -191,7 +219,7 @@ void app_main(void) {
while (true) {
if (ble_uart_init_struct.ble_connect_flag == true) {
port_do_debug_light_state(300);
}else{
} else {
port_do_debug_light_state(1000);
}

Loading…
Cancel
Save