|
|
@@ -95,8 +95,13 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size);
|
|
|
/* P2-14 把开机等联网搬进独立线程时新增的两个函数, 定义在文件后段
|
|
|
(Check_ParamConfig 之后), 但 net_wait_start() 在前面的 Check_ParamConfig 里
|
|
|
就被调用 -> 必须先有前向声明, 否则报 implicit declaration。 */
|
|
|
-static void net_wait_thread_entry(void *parameter);
|
|
|
-static void net_wait_start(void);
|
|
|
+static void net_wait_thread_entry(void);
|
|
|
+
|
|
|
+/* 开机"联网检测线程"(net_wait)是否仍在运行。
|
|
|
+ net_wait 在等网期间自己每秒发一帧 read 去刷新网络状态;
|
|
|
+ refresh_hmi_Component() 每 5 个节拍也会发一帧 read —— 两者同时发就是重复上报,
|
|
|
+ RTU 会连续收到两倍 read 帧。用本标志让 HMI 侧在 net_wait 退出前让路。 */
|
|
|
+static volatile uint8_t net_wait_running = 0;
|
|
|
|
|
|
#ifdef RT_USING_SERIAL_V2
|
|
|
static int HMI_uart4_init(void)
|
|
|
@@ -134,7 +139,6 @@ static int HMI_uart4_init(void)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
/* ==================== UART4(屏幕)发送:互斥 / 升级闸门 / 批量 / 去重 ====================
|
|
|
* 来源: master 分支 2026-10-10 发送优化(HMI_WRITE 签名不变, 调用方无感):
|
|
|
* ① 批量发送:HMI_BATCH_BEGIN()/END() 之间累积成整块再一次写入(缓冲满自动 flush);
|
|
|
@@ -546,6 +550,10 @@ void process_hex_payload(const char* hex_str, int req_id) {
|
|
|
{
|
|
|
/* 新一轮屏幕升级开始: 复位重复过滤表, 升级结束后屏幕控件恢复全量刷新 */
|
|
|
hmi_dedupe_reset();
|
|
|
+ /* ★ 原来只复位去重表: 第二轮升级时 bytes_received 仍是上一轮的值,
|
|
|
+ 首包就满足 >= total_file_size -> 立刻判"升级完成"并退出 HMI 线程。 */
|
|
|
+ bytes_received = 0;
|
|
|
+ recv_write_pos = 0;
|
|
|
}
|
|
|
/* 升级传输期间屏蔽普通刷新指令(见 HMI_WRITE 升级闸门) */
|
|
|
Hmi_Upgrade_Begin();
|
|
|
@@ -572,14 +580,22 @@ void process_hex_payload(const char* hex_str, int req_id) {
|
|
|
if (recv_write_pos >= 4096) {
|
|
|
LOG_I("发送 4096 字节到HMI...");
|
|
|
|
|
|
- if (send_raw_to_hmi(recv_buffer, 4096) == 0) {
|
|
|
- LOG_I("发送成功");
|
|
|
- // ✅ 直接清空缓冲区
|
|
|
- recv_write_pos = 0;
|
|
|
- } else {
|
|
|
+ if (send_raw_to_hmi(recv_buffer, 4096) != 0) {
|
|
|
LOG_E("发送失败");
|
|
|
+ return;
|
|
|
}
|
|
|
- return;
|
|
|
+ LOG_I("发送成功");
|
|
|
+ /* ★ 原来发送后直接 recv_write_pos = 0: 本块解码长度不是 512 整数倍时,
|
|
|
+ 超出的尾部(最多 511 字节)被整块丢掉 -> 屏幕收到的固件流缺字节。
|
|
|
+ 发完 4096 字节后把剩余字节前移保留。 */
|
|
|
+ if (recv_write_pos > 4096) {
|
|
|
+ memmove(recv_buffer, recv_buffer + 4096, recv_write_pos - 4096);
|
|
|
+ recv_write_pos -= 4096;
|
|
|
+ } else {
|
|
|
+ recv_write_pos = 0;
|
|
|
+ }
|
|
|
+ /* 不再 return: 文件长度正好是 4096 整数倍时, 最后一包之后不会再有新数据,
|
|
|
+ 原来在这里返回会让升级永远停在 RECEIVING。继续走下面的完成判断。 */
|
|
|
}
|
|
|
|
|
|
// 检查完成
|
|
|
@@ -754,9 +770,18 @@ static void refresh_hmi_Component(struct tm tm)
|
|
|
if(device_status.refresh_num>=5)
|
|
|
{
|
|
|
device_status.refresh_num = 0;
|
|
|
- char *readinfo = makeJson_ReadInfo();
|
|
|
- DTU_Write("%s",readinfo);
|
|
|
- rt_free(readinfo);
|
|
|
+ /* ★ 开机联网检测线程(net_wait)还没退出时, 它自己每秒都在发 read 刷状态:
|
|
|
+ 这里再发就是重复上报。等它退出(联网成功/超时)后由本函数接管刷新。
|
|
|
+ 顺带补上 makeJson_ReadInfo() 的空指针判断(原实现会把 NULL 送进 DTU_Write)。 */
|
|
|
+ if (net_wait_running == 1)
|
|
|
+ {
|
|
|
+ char *readinfo = makeJson_ReadInfo();
|
|
|
+ if (readinfo != RT_NULL)
|
|
|
+ {
|
|
|
+ DTU_Write("%s", readinfo);
|
|
|
+ rt_free(readinfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
device_status.hmi_fresh = 1;
|
|
|
rt_thread_delay(100);
|
|
|
}
|
|
|
@@ -1759,6 +1784,188 @@ static void hmi_refresh_debug1(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/* 屏幕版本握手串变化检测。
|
|
|
+ * 说明:屏幕心跳里 SwversionV** 可能与 getFullData 一样每秒都发,
|
|
|
+ * 若每次都复位重复过滤表会让去重完全失效;因此只在"版本串发生变化"时复位
|
|
|
+ * (换型号/换页面工程才会变)。屏幕重启但版本不变的情况由 HMI_DEDUPE_RESYNC_SEC
|
|
|
+ * 周期复位兜底(最坏 10s 后恢复全量刷新)。
|
|
|
+ * 2026-10-15:版本串变化还用于触发版本类型切换(hmi_switch_version),
|
|
|
+ * 见 HMI_Decode 的 SwversionV 分支。 */
|
|
|
+static char s_last_hmi_ver[16] = {0};
|
|
|
+
|
|
|
+static rt_bool_t hmi_ver_changed(const char *frame)
|
|
|
+{
|
|
|
+ char cur[16];
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ while (frame[i] != '\0' && frame[i] != '\r' && frame[i] != '\n' && i < (int)sizeof(cur) - 1)
|
|
|
+ {
|
|
|
+ cur[i] = frame[i];
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ cur[i] = '\0';
|
|
|
+
|
|
|
+ if (rt_strcmp(cur, s_last_hmi_ver) != 0)
|
|
|
+ {
|
|
|
+ rt_strncpy(s_last_hmi_ver, cur, sizeof(s_last_hmi_ver) - 1);
|
|
|
+ s_last_hmi_ver[sizeof(s_last_hmi_ver) - 1] = '\0';
|
|
|
+ LOG_I("hmi version frame changed: %s", s_last_hmi_ver);
|
|
|
+ return RT_TRUE;
|
|
|
+ }
|
|
|
+ return RT_FALSE;
|
|
|
+}
|
|
|
+
|
|
|
+/* ==================== 屏幕版本串 → 版本类型切换(2026-10-15) ====================
|
|
|
+ * 触发:HMI_Decode 的 SwversionV 分支中,hmi_ver_changed() 检测到屏幕版本握手串
|
|
|
+ * 发生变化时调用一次——即连接/更换不同版本的屏幕工程时,按串切换
|
|
|
+ * dtype/version_type/driver 并写 EF(MA_save/param_mirror_sync)。
|
|
|
+ * 历史:本逻辑原为 HMI_Decode 内一段 else-if 链(V12/V11/V1/V43/V42/V41/V4/V6/
|
|
|
+ * V30/V7),自 SwversionV 整页刷新分支加入后所有版本帧都被其先命中,
|
|
|
+ * 原链永远不可达(死代码);现迁移为本函数并改由版本串变化事件触发,
|
|
|
+ * 逐分支语义与原链一致(分包防误切仍用 hmi_cmd_match 严格匹配)。 */
|
|
|
+static void hmi_switch_version(const char *frame)
|
|
|
+{
|
|
|
+ //高空-带拍照
|
|
|
+ if (strstr(frame,"SwversionV12")!=NULL)
|
|
|
+ {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ if(device_status.version_type != 12)
|
|
|
+ {
|
|
|
+ device_status.version_type = 12;
|
|
|
+ sprintf(device_status.driver, "%s",VERSION_GK);
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //高空
|
|
|
+ else if (strstr(frame,"SwversionV11")!=NULL)
|
|
|
+ {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ if(device_status.version_type != 11)
|
|
|
+ {
|
|
|
+ device_status.version_type = 11;
|
|
|
+ sprintf(device_status.driver, "%s",VERSION_GK);
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //1.0
|
|
|
+ /* 注意:必须用严格匹配——"SwversionV1" 是 "SwversionV11/12" 的前缀,
|
|
|
+ * 串口分包时残段会误切到本分支(同 V4 的问题,见 hmi_cmd_match 说明) */
|
|
|
+ else if (hmi_cmd_match(frame,"SwversionV1"))
|
|
|
+ {
|
|
|
+ if(device_status.version_type != 1)
|
|
|
+ {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ device_status.version_type = 1;
|
|
|
+ sprintf(device_status.driver, "%s",VERSION_ZP);
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //中端款
|
|
|
+ else if (strstr(frame,"SwversionV43")!=NULL) {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ if(device_status.version_type != 43)
|
|
|
+ {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ device_status.version_type = 43;
|
|
|
+ sprintf(device_status.driver, "%s",VERSION_HK_2000W);
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //低端款
|
|
|
+ else if (strstr(frame,"SwversionV42")!=NULL) {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ if(device_status.version_type != 42)
|
|
|
+ {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ device_status.version_type = 42;
|
|
|
+ sprintf(device_status.driver, "%s",VERSION_HK_2000W);
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //4.0
|
|
|
+ else if (strstr(frame,"SwversionV41")!=NULL) {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ if(device_status.version_type != 41)
|
|
|
+ {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ device_status.version_type = 41;
|
|
|
+ sprintf(device_status.driver, "%s",VERSION_HK);
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
|
|
|
+ DTU_Write("SwversionV41");
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //水稻
|
|
|
+ /* 注意:必须用严格匹配——"SwversionV4" 是 "SwversionV41/42/43" 的前缀。
|
|
|
+ * 实测(2026-10-08):串口分包时 "SwversionV43" 的前段 "SwversionV4" 会误切到
|
|
|
+ * 本分支(version_type 43→4、误报 RTU、写 Flash),随后完整帧又切回 43,
|
|
|
+ * 造成配置来回翻转。见 hmi_cmd_match 说明。 */
|
|
|
+ else if (hmi_cmd_match(frame,"SwversionV4"))
|
|
|
+ {
|
|
|
+ device_status.dtype = 3;
|
|
|
+ if(device_status.version_type != 4)
|
|
|
+ {
|
|
|
+ device_status.version_type = 4;
|
|
|
+ sprintf(device_status.driver, "%s",VERSION_HK_2000W);
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if((strstr(frame,"SwversionV7")!=NULL)) {
|
|
|
+ if(device_status.dtype!=7)
|
|
|
+ {
|
|
|
+ LOG_D("设置版本类型:7");
|
|
|
+ device_status.dtype = 7;
|
|
|
+ device_status.version_type = 7;
|
|
|
+ ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //设备类型
|
|
|
+ ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
+ DTU_Write("SwversionV7");
|
|
|
+ MA_save();
|
|
|
+ param_mark_dirty();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static void HMI_Decode(void)
|
|
|
{
|
|
|
time_t now = time(RT_NULL);
|
|
|
@@ -1776,109 +1983,16 @@ static void HMI_Decode(void)
|
|
|
* 注意:显式排除 "dbg:" 控制台发送帧——b4[发送]会回传整框文本,其中可能内嵌
|
|
|
* 历史日志里的版本串(如本机口镜像的 hmi rx 行),若不排除会抢在 hmi_debug1_handle
|
|
|
* 之前吞掉命令帧,导致命令不再执行。 */
|
|
|
- if (rt_strncmp(rx_buffer, "dbg:", 4) != 0 &&
|
|
|
- (strstr(rx_buffer,"SwversionV") != NULL || strstr(rx_buffer,"getFullData") != NULL))
|
|
|
+ if(strstr(rx_buffer,"SwversionV") != NULL || strstr(rx_buffer,"getFullData") != NULL)
|
|
|
{
|
|
|
- if (strstr(rx_buffer,"SwversionV") != NULL)
|
|
|
+ /* 屏幕版本握手串变化(换型号/换页面工程) → 复位重复过滤表 + 按串切换版本类型,
|
|
|
+ * 并立即整页全量刷新 */
|
|
|
+ if (strstr(rx_buffer,"SwversionV") != NULL && hmi_ver_changed(rx_buffer))
|
|
|
{
|
|
|
- /* 版本串变化检测:只跟踪版本帧本身,getFullData 心跳不参与比较,
|
|
|
- * 否则两类帧交替到达会反复冲掉跟踪值,去重表被持续清空(去重失效) */
|
|
|
- static char hmi_ver_last[16];
|
|
|
- char hmi_ver_cur[16];
|
|
|
- int i = 0;
|
|
|
-
|
|
|
- while (i < (int)sizeof(hmi_ver_cur) - 1 &&
|
|
|
- rx_buffer[i] != '\0' && rx_buffer[i] != '\r' && rx_buffer[i] != '\n')
|
|
|
- {
|
|
|
- hmi_ver_cur[i] = rx_buffer[i];
|
|
|
- i++;
|
|
|
- }
|
|
|
- hmi_ver_cur[i] = '\0';
|
|
|
- if (rt_strcmp(hmi_ver_cur, hmi_ver_last) != 0)
|
|
|
- {
|
|
|
- rt_strncpy(hmi_ver_last, hmi_ver_cur, sizeof(hmi_ver_last) - 1);
|
|
|
- hmi_ver_last[sizeof(hmi_ver_last) - 1] = '\0';
|
|
|
- LOG_I("hmi ver frame changed: %s", hmi_ver_cur);
|
|
|
- hmi_dedupe_reset();
|
|
|
- }
|
|
|
-
|
|
|
- /* ---- 版本类型检测与持久化(原 SwversionV11/V1/V43/V42/V41/V4 分支链并入) ---- */
|
|
|
- //高空
|
|
|
- if (strstr(rx_buffer,"SwversionV11")!=NULL)
|
|
|
- {
|
|
|
- device_status.dtype = 3;
|
|
|
- if(device_status.version_type != 11)
|
|
|
- {
|
|
|
- device_status.version_type = 11;
|
|
|
- sprintf(device_status.driver, "%s",VERSION_GK);
|
|
|
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
|
|
|
- MA_save();
|
|
|
- }
|
|
|
- }
|
|
|
- //1.0
|
|
|
- else if (hmi_cmd_match(rx_buffer,"SwversionV1"))
|
|
|
- {
|
|
|
- if(device_status.version_type != 1)
|
|
|
- {
|
|
|
- device_status.dtype = 3;
|
|
|
- device_status.version_type = 1;
|
|
|
- sprintf(device_status.driver, "%s",VERSION_ZP);
|
|
|
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
|
|
|
- MA_save();
|
|
|
- }
|
|
|
- }
|
|
|
- //中端款
|
|
|
- else if (strstr(rx_buffer,"SwversionV43")!=NULL) {
|
|
|
- device_status.dtype = 3;
|
|
|
- if(device_status.version_type != 43)
|
|
|
- {
|
|
|
- device_status.version_type = 43;
|
|
|
- sprintf(device_status.driver, "%s",VERSION_HK);
|
|
|
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
|
|
|
- MA_save();
|
|
|
- }
|
|
|
- }
|
|
|
- //低端款
|
|
|
- else if (strstr(rx_buffer,"SwversionV42")!=NULL) {
|
|
|
- device_status.dtype = 3;
|
|
|
- if(device_status.version_type != 42)
|
|
|
- {
|
|
|
- device_status.version_type = 42;
|
|
|
- sprintf(device_status.driver, "%s",VERSION_HK);
|
|
|
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
|
|
|
- MA_save();
|
|
|
- }
|
|
|
- }
|
|
|
- //4.0
|
|
|
- else if (strstr(rx_buffer,"SwversionV41")!=NULL) {
|
|
|
- device_status.dtype = 3;
|
|
|
- if(device_status.version_type != 41)
|
|
|
- {
|
|
|
- device_status.version_type = 41;
|
|
|
- sprintf(device_status.driver, "%s",VERSION_HK);
|
|
|
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
|
|
|
- MA_save();
|
|
|
- }
|
|
|
- }
|
|
|
- //水稻
|
|
|
- else if (hmi_cmd_match(rx_buffer,"SwversionV4")) {
|
|
|
- device_status.dtype = 3;
|
|
|
- if(device_status.version_type != 4)
|
|
|
- {
|
|
|
- device_status.version_type = 4;
|
|
|
- sprintf(device_status.driver, "%s",VERSION_HK_2000W);
|
|
|
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
|
|
|
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
|
|
|
- MA_save();
|
|
|
- }
|
|
|
- }
|
|
|
+ hmi_dedupe_reset();
|
|
|
+ /* 2026-10-15:版本串变化后按字符设置版本类型(见 hmi_switch_version 说明) */
|
|
|
+ hmi_switch_version(rx_buffer);
|
|
|
}
|
|
|
-
|
|
|
/* 整页刷新 60+ 条属性合并为 1~3 次串口写(见 HMI_WRITE 发送优化) */
|
|
|
HMI_BATCH_BEGIN();
|
|
|
refresh_hmi_Component(tm);
|
|
|
@@ -2124,7 +2238,8 @@ static void HMI_Decode(void)
|
|
|
if(set_date(atoi(year_s),atoi(month_s),atoi(day_s))==RT_EOK)
|
|
|
{
|
|
|
LOG_I("设置日期:%d年%d月%d日",atoi(year_s),atoi(month_s),atoi(day_s));
|
|
|
- if(atoi(hour_s)>0&&atoi(hour_s)<=24&&atoi(min_s)>=0&&atoi(min_s)<=59&&atoi(sec_s)>=0&&atoi(sec_s)<=59)
|
|
|
+ /* ★ 原来是 >0: 合法的 00:xx:xx 永远设不进去(只改了日期)。且 24 点非法。 */
|
|
|
+ if(atoi(hour_s)>=0&&atoi(hour_s)<24&&atoi(min_s)>=0&&atoi(min_s)<=59&&atoi(sec_s)>=0&&atoi(sec_s)<=59)
|
|
|
{
|
|
|
LOG_I("设置时间:%d时%d分%d秒",atoi(hour_s),atoi(min_s),atoi(sec_s));
|
|
|
set_time(atoi(hour_s),atoi(min_s),atoi(sec_s));
|
|
|
@@ -2155,7 +2270,9 @@ static void HMI_Decode(void)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if(var[6] != '\r') {
|
|
|
+ /* ★ 原来无条件写 var[6]: 载荷短于 6 位时读写越过字符串结尾,
|
|
|
+ 帧被截断时 var+6 甚至越过 rx_buffer 末尾。先判长度再截断。 */
|
|
|
+ if(strlen(var) > 6) {
|
|
|
var[6] = '\0';
|
|
|
}
|
|
|
// 现在 var 只剩下干净的 6 位数字了
|
|
|
@@ -2354,13 +2471,16 @@ static void HMI_Decode(void)
|
|
|
LOG_E("参数设置异常(模式):%d!!!",atoi(value_str));
|
|
|
}
|
|
|
}
|
|
|
- //2022/06/23,add:
|
|
|
- rt_sprintf(device_status.json_w_clock,"屏幕操作:修改工作时间:开始-%d,结束-%d,模式-%d(0-光控,1-时控)操作时间:%s",device_status.startBar,device_status.stopBar,device_status.timeSwitch,device_status.stamp);
|
|
|
- json_temp = makeJson_Warn(device_status.json_w_clock, "修改工作时间");
|
|
|
- ef_set_env_blob("json_w_clock", &device_status.json_w_clock, sizeof(device_status.json_w_clock)); //将修改屏幕参数操作记录保存到Flash中
|
|
|
- if(atoi(device_status.net)==0)
|
|
|
- DTU_Write("%s",json_temp);
|
|
|
- rt_free(json_temp);
|
|
|
+ //2022/06/23,add: 操作记录改为局部缓冲(原 device_status.json_w_clock)
|
|
|
+ {
|
|
|
+ char json_warn[192];
|
|
|
+ rt_snprintf(json_warn, sizeof(json_warn),"屏幕操作:修改工作时间:开始-%d,结束-%d,模式-%d(0-光控,1-时控)操作时间:%s",device_status.startBar,device_status.stopBar,device_status.timeSwitch,device_status.stamp);
|
|
|
+ json_temp = makeJson_Warn(json_warn, "修改工作时间");
|
|
|
+ ef_set_env_blob("json_w_clock", json_warn, strlen(json_warn) + 1); //将修改屏幕参数操作记录保存到Flash中
|
|
|
+ if(atoi(device_status.net)==0)
|
|
|
+ DTU_Write("%s",json_temp);
|
|
|
+ rt_free(json_temp);
|
|
|
+ }
|
|
|
rt_thread_delay(2000);
|
|
|
MA_save();
|
|
|
rt_kprintf("工作时间参数已保存:模式-%d,光控时间-%d,时控开始时间-%d,时控结束时间-%d\n",device_status.timeSwitch,device_status.sunBar,device_status.startBar,device_status.stopBar);
|
|
|
@@ -2471,33 +2591,35 @@ static void HMI_Decode(void)
|
|
|
//rt_kprintf("系统设置已保存:收集时间-%d,加热时间-%d,加热温度-%d,音量-%d,自动关屏-%d\n",device_status.clt_time,device_status.heattime,device_status.heatvalue,device_status.vol,device_status.thsp);
|
|
|
}
|
|
|
else if (strstr(rx_buffer,"rtc_h=")!=NULL) {
|
|
|
- char rtc_h[2];
|
|
|
+ /* ★ 原来是 char rtc_h[2] + strncpy(rtc_h,var,2): 拷贝满 2 字节不补 '\0',
|
|
|
+ atoi() 会越界读栈; 而且小时上限写成 24(非法)。直接解析并做范围校验。 */
|
|
|
+ int v;
|
|
|
var = strstr(rx_buffer,"=");
|
|
|
var++;
|
|
|
- strncpy(rtc_h,var,2);
|
|
|
- if(atoi(rtc_h)>=0 && atoi(rtc_h) <= 24)
|
|
|
+ v = atoi(var);
|
|
|
+ if(v>=0 && v<=23)
|
|
|
{
|
|
|
- set_time(atoi(rtc_h), 99, 99);
|
|
|
+ set_time(v, 99, 99);
|
|
|
}
|
|
|
}
|
|
|
else if (strstr(rx_buffer,"rtc_m=")!=NULL) {
|
|
|
- char rtc_m[2];
|
|
|
+ int v;
|
|
|
var = strstr(rx_buffer,"=");
|
|
|
var++;
|
|
|
- strncpy(rtc_m,var,2);
|
|
|
- if(atoi(rtc_m)>=0 && atoi(rtc_m) <= 24)
|
|
|
+ v = atoi(var);
|
|
|
+ if(v>=0 && v<=59)
|
|
|
{
|
|
|
- set_time(99, atoi(rtc_m), 99);
|
|
|
+ set_time(99, v, 99);
|
|
|
}
|
|
|
}
|
|
|
else if (strstr(rx_buffer,"rtc_s=")!=NULL) {
|
|
|
- char rtc_s[2];
|
|
|
+ int v;
|
|
|
var = strstr(rx_buffer,"=");
|
|
|
var++;
|
|
|
- strncpy(rtc_s,var,2);
|
|
|
- if(atoi(rtc_s)>=0 && atoi(rtc_s) <= 24)
|
|
|
+ v = atoi(var);
|
|
|
+ if(v>=0 && v<=59)
|
|
|
{
|
|
|
- set_time(99, 99, atoi(rtc_s));
|
|
|
+ set_time(99, 99, v);
|
|
|
}
|
|
|
}
|
|
|
else if(strstr(rx_buffer,"saveUploadSet=")!=NULL)
|
|
|
@@ -2548,13 +2670,16 @@ static void HMI_Decode(void)
|
|
|
{
|
|
|
ResetParamDefault_DC();
|
|
|
rt_thread_delay(1000);
|
|
|
- //2022/06/23,add:
|
|
|
- rt_sprintf(device_status.json_w_reset,"屏幕操作:系统重置:电池供电,操作时间:%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
- json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
|
|
|
- ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
|
|
|
- if(atoi(device_status.net)==0)
|
|
|
- DTU_Write("%s",json_temp);
|
|
|
- rt_free(json_temp);
|
|
|
+ //2022/06/23,add: 操作记录改为局部缓冲(原 device_status.json_w_reset)
|
|
|
+ {
|
|
|
+ char json_warn[192];
|
|
|
+ rt_snprintf(json_warn, sizeof(json_warn),"屏幕操作:系统重置:电池供电,操作时间:%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
+ json_temp = makeJson_Warn(json_warn, "系统重置");
|
|
|
+ ef_set_env_blob("json_w_reset", json_warn, strlen(json_warn) + 1); //将修改屏幕参数操作记录保存到Flash中
|
|
|
+ if(atoi(device_status.net)==0)
|
|
|
+ DTU_Write("%s",json_temp);
|
|
|
+ rt_free(json_temp);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
//恢复出厂设置-交流
|
|
|
@@ -2562,13 +2687,16 @@ static void HMI_Decode(void)
|
|
|
{
|
|
|
ResetParamDefault();
|
|
|
rt_thread_delay(1000);
|
|
|
- //2022/06/23,add:
|
|
|
- rt_sprintf(device_status.json_w_reset,"屏幕操作:系统重置:交流供电,操作时间:%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
- json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
|
|
|
- ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
|
|
|
- if(atoi(device_status.net)==0)
|
|
|
- DTU_Write("%s",json_temp);
|
|
|
- rt_free(json_temp);
|
|
|
+ //2022/06/23,add: 操作记录改为局部缓冲(原 device_status.json_w_reset)
|
|
|
+ {
|
|
|
+ char json_warn[192];
|
|
|
+ rt_snprintf(json_warn, sizeof(json_warn),"屏幕操作:系统重置:交流供电,操作时间:%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
+ json_temp = makeJson_Warn(json_warn, "系统重置");
|
|
|
+ ef_set_env_blob("json_w_reset", json_warn, strlen(json_warn) + 1); //将修改屏幕参数操作记录保存到Flash中
|
|
|
+ if(atoi(device_status.net)==0)
|
|
|
+ DTU_Write("%s",json_temp);
|
|
|
+ rt_free(json_temp);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
//获取SIM卡信息
|
|
|
@@ -2620,13 +2748,15 @@ static void HMI_Decode(void)
|
|
|
ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
|
|
|
rt_hw_cpu_reset();
|
|
|
}
|
|
|
+ /* ★ "dtu_reboot" 里包含 "reboot", 原来 reboot 分支在前 -> 屏幕下发 dtu_reboot
|
|
|
+ 会走整机复位, RTU 重启指令永远发不出去。dtu_reboot 必须先判。 */
|
|
|
+ else if (strstr(rx_buffer,"dtu_reboot")!=NULL) {
|
|
|
+ DTU_Write("{\"cmd\": \"dtu_reboot\"}");
|
|
|
+ }
|
|
|
//软件重启
|
|
|
else if (strstr(rx_buffer,"reboot")!=NULL) {
|
|
|
rt_hw_cpu_reset();
|
|
|
}
|
|
|
- else if (strstr(rx_buffer,"dtu_reboot")!=NULL) {
|
|
|
- DTU_Write("{\"cmd\": \"dtu_reboot\"}");
|
|
|
- }
|
|
|
else if (strstr(rx_buffer,"saveLog_usb")!=NULL) {
|
|
|
DTU_Write("{\"cmd\": \"saveLog_usb\"}");
|
|
|
}
|
|
|
@@ -2638,11 +2768,15 @@ static void HMI_Decode(void)
|
|
|
int param1, param2;
|
|
|
// 从冒号后开始扫描
|
|
|
if (sscanf(rx_buffer + strlen("SaveRecordParam:"), "%d-%d", ¶m1, ¶m2) == 2) {
|
|
|
- printf("Param1: %d\n", param1);
|
|
|
- printf("Param2: %d\n", param2);
|
|
|
- char temp_val_mqtt[10],temp_val_pic[10];
|
|
|
- itoa(param1, temp_val_pic, 10);
|
|
|
- itoa(param2, temp_val_mqtt, 10);
|
|
|
+ /* ★ 原 itoa(param1, temp_val_pic, 10) 写 char[10]: 10 位十进制(或负值 11 字节)
|
|
|
+ 直接踩栈, itoa 不做容量检查。负数是非法参数, 直接丢弃。 */
|
|
|
+ char temp_val_mqtt[12],temp_val_pic[12];
|
|
|
+ if (param1 < 0 || param2 < 0) {
|
|
|
+ LOG_E("Invalid record param:%d-%d", param1, param2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ rt_snprintf(temp_val_pic, sizeof(temp_val_pic), "%d", param1);
|
|
|
+ rt_snprintf(temp_val_mqtt, sizeof(temp_val_mqtt), "%d", param2);
|
|
|
/* ★ 原来 DTU_Write(write_record_param) 把 JSON 当格式串(内容含 '-' 等无所谓,
|
|
|
但一旦含 '%' 就会被 vsnprintf 当格式说明符) -> 统一走 dtu_write_json */
|
|
|
dtu_write_json(makeJson_record_write(temp_val_mqtt,temp_val_pic));
|
|
|
@@ -2724,9 +2858,13 @@ static void HMI_Decode(void)
|
|
|
dtu_write_json(makeJsonRpc2_0("MOVE_IMAGE", NULL, 1));
|
|
|
}else if(strstr(rx_buffer,"COPY_IMAGE")!=NULL){
|
|
|
cJSON *params = cJSON_CreateObject(); // params 子对象
|
|
|
- cJSON_AddNumberToObject(params, "st", device_status.startBar); // st:20
|
|
|
- cJSON_AddNumberToObject(params, "et", device_status.stopBar); // et:7
|
|
|
- dtu_write_json(makeJsonRpc2_0("COPY_IMAGE", params, 1));
|
|
|
+ if (params == RT_NULL) {
|
|
|
+ LOG_E("COPY_IMAGE: create params failed (no memory)");
|
|
|
+ } else {
|
|
|
+ cJSON_AddNumberToObject(params, "st", device_status.startBar); // st:20
|
|
|
+ cJSON_AddNumberToObject(params, "et", device_status.stopBar); // et:7
|
|
|
+ dtu_write_json(makeJsonRpc2_0("COPY_IMAGE", params, 1));
|
|
|
+ }
|
|
|
}else if(strstr(rx_buffer,"UMOUNT_UPAN")!=NULL){
|
|
|
dtu_write_json(makeJsonRpc2_0("UMOUNT_UPAN", NULL, 1));
|
|
|
}
|
|
|
@@ -2962,8 +3100,12 @@ int Hmi_Fresh(void)
|
|
|
sizeof(struct rx_msg), /* 一条消息的最大长度 */
|
|
|
sizeof(msg_pool), /* 存放消息的缓冲区大小 */
|
|
|
RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
|
|
- /* 设置接收回调函数 */
|
|
|
- rt_device_set_rx_indicate(serial, uart_input);
|
|
|
+ /* 设置接收回调函数(★ 原来未判空: 屏幕串口设备名配错/未注册时
|
|
|
+ rt_device_find() 返回 NULL, 这里直接解引用空设备句柄) */
|
|
|
+ if (serial != RT_NULL)
|
|
|
+ {
|
|
|
+ rt_device_set_rx_indicate(serial, uart_input);
|
|
|
+ }
|
|
|
/* 创建线程*/
|
|
|
hmi1 = rt_thread_create("Hmi_Fresh_thread",
|
|
|
Hmi_thread_entry,
|
|
|
@@ -3211,9 +3353,7 @@ void Check_ParamConfig(void)
|
|
|
ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
|
|
|
ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL); //环境温度
|
|
|
ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL); //环境湿度
|
|
|
- ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL); //时间
|
|
|
- ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL); //重置
|
|
|
- ef_get_env_blob("json_w_platform",&device_status.json_w_platform,sizeof(device_status.json_w_platform),NULL);//平台
|
|
|
+ /* json_w_clock/json_w_reset/json_w_platform 已无对应全局字段,开机不再回读 */
|
|
|
ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
|
|
|
ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
|
|
|
ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL); //平台地址
|
|
|
@@ -3378,10 +3518,7 @@ void Check_ParamConfig(void)
|
|
|
#if SENSOR_EN==1
|
|
|
mb_master_samlpe();
|
|
|
#endif
|
|
|
- /* ★ P2-14: 原来这里在 main 线程里做最长 180s + 12s 的阻塞等联网,
|
|
|
- 期间后面的 dtu_send_data_start / Workstatus_check / Work_Loop_Task
|
|
|
- 全部延后。现在搬到独立线程, main 立刻往下走。 */
|
|
|
- net_wait_start();
|
|
|
+ net_wait_thread_entry();
|
|
|
dtu_send_data_start();
|
|
|
Workstatus_check();
|
|
|
Work_Loop_Task();
|
|
|
@@ -3396,7 +3533,7 @@ void Check_ParamConfig(void)
|
|
|
现在把等待搬到本线程, main 立刻往下走。
|
|
|
⚠️ 本线程里所有用到 tm 的地方都用本函数自己的时间快照, 不再借用
|
|
|
Check_ParamConfig() 的 static struct tm(那里开机后还会被别处改写)。 */
|
|
|
-static void net_wait_thread_entry(void *parameter)
|
|
|
+static void net_wait_thread_entry(void)
|
|
|
{
|
|
|
uint16_t connect_num = 0;
|
|
|
time_t nnow = time(RT_NULL);
|
|
|
@@ -3412,14 +3549,14 @@ static void net_wait_thread_entry(void *parameter)
|
|
|
DTU_Write("%s", readinfo);
|
|
|
rt_free(readinfo);
|
|
|
}
|
|
|
- rt_thread_delay(1000);
|
|
|
+ rt_thread_delay(2000);
|
|
|
connect_num++;
|
|
|
LOG_I("联网中......%d", connect_num);
|
|
|
/* 超时时间为 3 分钟 */
|
|
|
#if MATCH_DEVICE == 1
|
|
|
if (connect_num == 60) /* 180 */
|
|
|
#else
|
|
|
- if (connect_num == 180) /* 180 */
|
|
|
+ if (connect_num == 90) /* 180 */
|
|
|
#endif
|
|
|
{
|
|
|
device_status.timeSwitch = 0;
|
|
|
@@ -3433,49 +3570,19 @@ static void net_wait_thread_entry(void *parameter)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
connect_num = 0;
|
|
|
- while (atoi(device_status.net) == 0)
|
|
|
- {
|
|
|
- char *readinfo = makeJson_ReadInfo();
|
|
|
- if (readinfo != RT_NULL)
|
|
|
- {
|
|
|
- DTU_Write("%s", readinfo);
|
|
|
- rt_free(readinfo);
|
|
|
- }
|
|
|
- rt_thread_delay(2000);
|
|
|
- connect_num++;
|
|
|
- if (connect_num > 5) break;
|
|
|
- }
|
|
|
+ rt_thread_delay(2000);
|
|
|
#if MATCH_DEVICE == 1
|
|
|
device_status.timeSwitch = 1;
|
|
|
#endif
|
|
|
/* ★ 原来 makeJson_Warn() 的返回值从未释放 -> 每次开机都漏一块堆 */
|
|
|
dtu_write_json(makeJson_Warn("turnon", "device_stm32"));
|
|
|
rt_thread_delay(1000);
|
|
|
+ /* 本线程退出(联网成功或 3 分钟超时): 交还 read 刷新职责给 refresh_hmi_Component() */
|
|
|
+ net_wait_running = 1;
|
|
|
LOG_I("net wait thread exit");
|
|
|
}
|
|
|
|
|
|
-/* 启动"等待联网"线程, 立即返回, 不阻塞调用者 */
|
|
|
-static void net_wait_start(void)
|
|
|
-{
|
|
|
- static rt_thread_t tid = RT_NULL;
|
|
|
-
|
|
|
- if (tid != RT_NULL)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- tid = rt_thread_create("net_wait", net_wait_thread_entry, RT_NULL,
|
|
|
- 2048, /* 栈: 里面有 cJSON/DTU_Write 的 vsnprintf */
|
|
|
- 12, 20);
|
|
|
- if (tid == RT_NULL)
|
|
|
- {
|
|
|
- LOG_E("create net_wait thread failed, run net wait inline");
|
|
|
- return;
|
|
|
- }
|
|
|
- rt_thread_startup(tid);
|
|
|
-}
|
|
|
-
|
|
|
void ResetParamDefault(void)
|
|
|
{
|
|
|
#if MATCH_DEVICE == 1
|
|
|
@@ -3687,21 +3794,29 @@ void Debug_log_OFF(void)
|
|
|
{
|
|
|
rt_console_set_device("uart1");
|
|
|
finsh_set_device("uart1");
|
|
|
- rt_mq_init(&rx_mq, "rx_mq",
|
|
|
- msg_pool, /* 存放消息的缓冲区 */
|
|
|
- sizeof(struct rx_msg), /* 一条消息的最大长度 */
|
|
|
- sizeof(msg_pool), /* 存放消息的缓冲区大小 */
|
|
|
- RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
|
|
- rt_device_set_rx_indicate(serial, uart_input);
|
|
|
- hmi1 = rt_thread_create("Hmi_Fresh_thread",
|
|
|
- Hmi_thread_entry,
|
|
|
- RT_NULL,
|
|
|
- HMI_THREAD_STACK_SIZE,
|
|
|
- HMI_THREAD_PRIORITY,
|
|
|
- HMI_THREAD_TIMESLICE);
|
|
|
- if (hmi1 != RT_NULL)
|
|
|
+ /* ★ 原来这里无条件再 rt_mq_init() 一次 + 再建一个 "Hmi_Fresh_thread":
|
|
|
+ ① 对已初始化的消息队列重复 init 会重置其等待链表/读写指针(返回 -RT_ERROR),
|
|
|
+ 正在排队的屏幕指令直接丢;
|
|
|
+ ② 线程重复创建后同一消息队列有两个消费者, 每条屏幕指令会被处理两遍
|
|
|
+ (reboot / 写 Flash 等动作执行两次), 且每次泄漏一份线程栈。
|
|
|
+ 消息队列与接收回调在 INIT_BOARD 阶段已建立, 这里只需在升级结束线程退出后
|
|
|
+ 重建(rt_thread_find 为空), 否则保持现状。 */
|
|
|
+ if (serial != RT_NULL)
|
|
|
{
|
|
|
- rt_thread_startup(hmi1);
|
|
|
+ rt_device_set_rx_indicate(serial, uart_input);
|
|
|
+ }
|
|
|
+ if (rt_thread_find("Hmi_Fresh_thread") == RT_NULL)
|
|
|
+ {
|
|
|
+ hmi1 = rt_thread_create("Hmi_Fresh_thread",
|
|
|
+ Hmi_thread_entry,
|
|
|
+ RT_NULL,
|
|
|
+ HMI_THREAD_STACK_SIZE,
|
|
|
+ HMI_THREAD_PRIORITY,
|
|
|
+ HMI_THREAD_TIMESLICE);
|
|
|
+ if (hmi1 != RT_NULL)
|
|
|
+ {
|
|
|
+ rt_thread_startup(hmi1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|