diff --git a/main/main.c b/main/main.c index ed4a1b0..64dc2b9 100644 --- a/main/main.c +++ b/main/main.c @@ -165,6 +165,29 @@ bool parse_json_to_struct(cJSON *ch) { return ble_uart_receive_data.cmd_flag; } +void receipt_json_get_status() { + cJSON *pRoot = cJSON_CreateObject(); //创建一个对象 + if (!pRoot) { + return; + } + + cJSON_AddStringToObject(pRoot, "order", "receipt"); //添加一个节点 + cJSON_AddNumberToObject(pRoot, "index", ble_uart_receive_data.index); + cJSON_AddStringToObject(pRoot, "deviceState", ble_uart_receive_data.deviceState); + cJSON_AddNumberToObject(pRoot, "deviceException", ble_uart_receive_data.deviceException); + cJSON_AddStringToObject(pRoot, "deviceExceptionInfo", ble_uart_receive_data.deviceExceptionInfo); + cJSON_AddNumberToObject(pRoot, "position", ble_uart_receive_data.position); + + char *szJson = cJSON_Print(pRoot); + + if (szJson != NULL) { + ESP_LOGI(MAIN_LOG_TAG, "%s", szJson); + free(szJson); + } + + cJSON_Delete(pRoot); +} + void processing_uart_rx_data() { if (ble_rx_buffer_off != 0) { modbus_uart_rx_off_before = ble_rx_buffer_off; @@ -199,10 +222,10 @@ void processing_uart_rx_data() { // receipt_json_set_position(); } - // if (strcmp(ble_uart_receive_data.order, get_status) == 0) { - // ESP_LOGI(MAIN_LOG_TAG, get_status); - // receipt_json_get_status(); - // } + if (strcmp(ble_uart_receive_data.order, get_status) == 0) { + ESP_LOGI(MAIN_LOG_TAG, get_status); + receipt_json_get_status(); + } if (strcmp(ble_uart_receive_data.order, set_motor_current_size) == 0) { ESP_LOGI(MAIN_LOG_TAG, set_motor_current_size); motor_set_zero_point();