|
|
@@ -1,3 +1,10 @@
|
|
|
+/********************************************************************************
|
|
|
+ * 串口接收支持 JSON 和 TEXT 两种数据格式:
|
|
|
+ * 1. JSON:以 '{' 或 '[' 作为起始字符,按 JSON 语法进行流式解析。
|
|
|
+ * 2. TEXT:由可打印字符组成,可打印字符范围为 0x20~0x7E,但 '{' 和 '[' 保留为 JSON
|
|
|
+ * 报文起始字符,因此 TEXT 中不得包含 '{' 或 '[';TEXT 以串口接收空闲超时或
|
|
|
+ * 收到JSON开始字符作为报文结束标志。
|
|
|
+ *******************************************************************************/
|
|
|
#include "mcu_ctrl_board.h"
|
|
|
#include "../../rtu_linux_modules/swapi/subjects/serial/serial.h"
|
|
|
#include "lwjson/lwjson.h"
|
|
|
@@ -126,14 +133,13 @@ static int comio_data_recv_proc(unsigned long wParam/*传递打开的串口句
|
|
|
if(ch == '{' || ch == '[')
|
|
|
{ // IDLE -> JSON
|
|
|
json_p:
|
|
|
- if(pTextCache->len > 0) consume_cached_text_data(pSerial, pTextCache);
|
|
|
+ if(pTextCache->len > 0) consume_cached_text_info(pSerial, pTextCache);
|
|
|
ret = lwjson_stream_parse(&pComIO->parser, ch); // JSON 1: 已开始解析
|
|
|
if(ret != lwjsonSTREAMINPROG)
|
|
|
{
|
|
|
sw_log_error("[%s] failed to start JSON parsing, lwjson_stream_parse() returned: %d!!", MODULE_NAME, ret);
|
|
|
serial_clear_recv_buffer(pSerial); lwjson_stream_reset(&pComIO->parser); goto recv_p;
|
|
|
}
|
|
|
-
|
|
|
pComIO->recvMode = JSON; xgettickcount(&pComIO->jsonLastCharTick); goto recv_p;
|
|
|
}
|
|
|
else if(xisprint(ch))
|
|
|
@@ -223,7 +229,7 @@ static int comio_data_idle_proc(unsigned long wParam/*传递打开的串口句
|
|
|
xgettickcount(&nowTick);
|
|
|
if(pComIO->textLastCharTick > 0 && (nowTick - pComIO->textLastCharTick) > RECV_IDLE_TIMEOUT)
|
|
|
{ // TEXT -> IDLE
|
|
|
- if(pTextCache->len > 0) { consume_cached_text_data(pSerial, pTextCache); }
|
|
|
+ if(pTextCache->len > 0) { consume_cached_text_info(pSerial, pTextCache); }
|
|
|
pComIO->textLastCharTick = 0; pComIO->recvMode = IDLE;
|
|
|
}
|
|
|
break;
|