zhunk před 13 hodinami
rodič
revize
50b9a39519

+ 9 - 1
Application_cbd_apm32f1/applications/control.c

@@ -1045,7 +1045,15 @@ void WorkTask_BZYV2(void)
             exec_work_done();
         }
     }else{
-        LOG_W("==================!!!设备已待机!!!===================");
+        /* 待机日志限频: 首次进入立即打印一次, 之后每 10s 打印一次, 避免每秒刷屏 */
+        static rt_tick_t idle_log_tick = 0;
+        rt_tick_t now = rt_tick_get();
+
+        if (idle_log_tick == 0 || (now - idle_log_tick) >= (rt_tick_t)(10 * RT_TICK_PER_SECOND))
+        {
+            idle_log_tick = now;
+            LOG_W("==================!!!设备已待机!!!===================");
+        }
     }
 }
 

+ 2 - 2
Application_cbd_apm32f1/applications/control.h

@@ -37,7 +37,7 @@ void  slide_set_record_travel(uint8_t pf_ok);      /* 依据预对焦结果设
 ///
 ///
 ///
-#define VERSION_BZY         "3.7.45"                   //孢子仪
+#define VERSION_BZY         "3.7.46"                   //孢子仪
 
 /* 对焦串口通信异常标志: 串口收到合法 JSON 且含 "focus" 字段时置1(定义于dtu_uart2.c) */
 extern volatile uint8_t focus_valid_flag;
@@ -145,7 +145,7 @@ typedef struct  _packed
     char mqttcfg2[64];         //
     char tempture[8];         //温度
     char humidity[8];         //湿度
-    char csq[8];               //信号强度
+    char csq[32];               //信号强度
     char net[8];               //网络
     char sim[8];               //SIM卡
     char gps[8];               //定位类型

+ 26 - 0
Application_cbd_apm32f1/applications/hmi.c

@@ -2239,6 +2239,32 @@ void SysParamReset_Partial(void)
     device_status.tpl = SYS_RESET_TPL_DEFAULT;      /* 低温保护 */
     ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
     ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
+    /* 2) 采集时间恢复默认 */
+    device_status.collecting_sh1 = 11;
+    device_status.collecting_eh1 = 16;
+    device_status.collecting_sh2 = 0;
+    device_status.collecting_eh2 = 0;
+    device_status.collecting_sh3 = 0;
+    device_status.collecting_eh3 = 0;
+    device_status.collt_min_eh1 = 0;
+    device_status.collt_min_sh1 = 0;
+    device_status.collt_min_eh2 = 0;
+    device_status.collt_min_sh2 = 0;
+    device_status.collt_min_eh3 = 0;
+    device_status.collt_min_sh3 = 0;
+    ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));    //采集时间
+    ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));    //采集时间
+    ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));    //采集时间
+    ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));    //采集时间
+    ef_set_env_blob("collecting_sh3", &device_status.collecting_sh3, sizeof(device_status.collecting_sh3));    //采集时间
+    ef_set_env_blob("collecting_eh3", &device_status.collecting_eh3, sizeof(device_status.collecting_eh3));    //采集时间
+
+    ef_set_env_blob("collt_min_sh1", &device_status.collt_min_sh1, sizeof(device_status.collt_min_sh1));
+    ef_set_env_blob("collt_min_eh1", &device_status.collt_min_eh1, sizeof(device_status.collt_min_eh1));
+    ef_set_env_blob("collt_min_sh2", &device_status.collt_min_sh2, sizeof(device_status.collt_min_sh2));
+    ef_set_env_blob("collt_min_eh2", &device_status.collt_min_eh2, sizeof(device_status.collt_min_eh2));
+    ef_set_env_blob("collt_min_sh3", &device_status.collt_min_sh3, sizeof(device_status.collt_min_sh3));
+    ef_set_env_blob("collt_min_eh3", &device_status.collt_min_eh3, sizeof(device_status.collt_min_eh3));
 
     LOG_I("参数重置(部分): 系统工作时间 worked_day=%d, 温湿度阈值 tph=%d tpl=%d",
           flashdb_value.worked_day, device_status.tph, device_status.tpl);

+ 94 - 1
Application_cbd_apm32f1/drivers/board.c

@@ -11,6 +11,9 @@
 #include <rtthread.h>
 #include <board.h>
 #include <drv_common.h>
+#ifdef RT_USING_DEVICE
+#include <rtdevice.h>
+#endif
 
 
 TIM_HandleTypeDef htim3;
@@ -19,8 +22,92 @@ ADC_HandleTypeDef hadc1;
 SPI_HandleTypeDef hspi1;
 UART_HandleTypeDef huart1;
 
+#if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE) && \
+    (defined(RT_USING_SERIAL_V1) || defined(RT_USING_SERIAL_V2))
+/* ================= 双调试串口 (2026-11-27) =================
+ * 主控制台仍然是 uart1(RT_CONSOLE_DEVICE_NAME):shell 的输入/输出、rt_console_set_device()
+ * 的语义完全不变;这里额外把 rt_kprintf()/rt_kputs() 的每段日志镜像到 uart2,
+ * 使 uart1 / uart2 可以同时接调试工具看同一份日志。
+ *
+ * 注意:
+ *  1) 发送不走 rt_device_write(),而是直接调用串口 ops->putc 轮询发送,并自行补 '\r'。
+ *     原因:本工程 BSP_UART2_TX_USING_DMA 使能,drv_usart_v2.c 的 RT_DEVICE_CHECK_OPTMODE
+ *     会把 uart2 的 TX 判定为 NO_BUFFER 模式,serial_v2 就会走
+ *     _serial_fifo_tx_blocking_nbuf() -> rt_completion_wait();该分支没有
+ *     "调度器未启动"的保护,rt_hw_board_init() 里打开 uart2 后第一次 rt_kprintf()
+ *     (rt_show_version 的 banner)就会触发
+ *     "rt_completion_wait shall not be used before scheduler start" 断言。
+ *     用 putc 轮询与 uart1 控制台的发送方式一致,任何时刻(含调度器启动前)都可用;
+ *  2) 中断上下文不镜像:115200 下轮询发 1 字节约 87us,在 ISR 内输出整行会明显拉长中断;
+ *  3) 多线程同时输出时与 uart1 一样可能字符级交错,需要严格成行请改用
+ *     "环形缓冲 + 转发线程"的转发方案;
+ *  4) uart2 被本功能常开占用;若后续业务要把它当普通通信串口使用,需先 rt_device_close()
+ *     并重新打开(本功能检测到 ref_count 为 0 会立即停止镜像,不会在关闭后卡死);
+ *  5) finsh 的提示符/回显本身用 rt_kprintf 输出,因此 uart2 也会看到同一份 shell 会话;
+ *     但 shell 的输入设备仍是 uart1(rt_console_get_device),uart2 只做单向输出。 */
+#define DBG_CONSOLE2_NAME       "uart2"
+
+static struct rt_serial_device *_dbg_serial2 = RT_NULL;
+
+static void dbg_console2_init(void)
+{
+    rt_device_t dev;
+    struct rt_serial_device *serial;
+
+    dev = rt_device_find(DBG_CONSOLE2_NAME);
+    if (dev == RT_NULL)
+    {
+        return;
+    }
+
+    /* 打开失败则降级为单控制台(uart1),不影响系统启动 */
+    if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM) != RT_EOK)
+    {
+        return;
+    }
+
+    serial = (struct rt_serial_device *)dev;
+    if (serial->ops == RT_NULL || serial->ops->putc == RT_NULL)
+    {
+        rt_device_close(dev);
+        return;
+    }
+
+    _dbg_serial2 = serial;
+}
 
-
+/* 由 kservice.c 的 rt_kprintf()/rt_kputs() 在写完主控制台后回调(覆盖弱符号) */
+void rt_console_output_mirror(const char *str, rt_size_t len)
+{
+    rt_size_t i;
+
+    if (_dbg_serial2 == RT_NULL || str == RT_NULL || len == 0)
+    {
+        return;
+    }
+
+    /* 业务已把 uart2 关闭(DeInit)时不能再 putc,否则会卡在等待 TC 标志 */
+    if (_dbg_serial2->parent.ref_count == 0)
+    {
+        return;
+    }
+
+    /* 中断里只保证 uart1 有输出 */
+    if (rt_interrupt_get_nest() > 0)
+    {
+        return;
+    }
+
+    for (i = 0; i < len; i++)
+    {
+        if (str[i] == '\n')
+        {
+            _dbg_serial2->ops->putc(_dbg_serial2, '\r');
+        }
+        _dbg_serial2->ops->putc(_dbg_serial2, str[i]);
+    }
+}
+#endif /* RT_USING_DEVICE && RT_USING_CONSOLE && RT_USING_SERIAL */
 
 RT_WEAK void rt_hw_board_init()
 {
@@ -43,6 +130,12 @@ RT_WEAK void rt_hw_board_init()
     rt_components_board_init();
 #endif
 
+#if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE)
+    /* 必须在 rt_components_board_init() 之后: UART_INIT(Usart_Init) 里才使能
+     * USART2 时钟并配置 PA2/PA3; 提前打开会因时钟未开导致 uart2 无法输出。 */
+    dbg_console2_init();
+#endif
+
 }
 
 void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)

+ 23 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,26 @@
+# 2026-11-27 更新说明(3.7.46 双调试串口 uart1+uart2)
+	#define VERSION_BZY         "3.7.46"                   //孢子仪
+	1、【取消】re_console_log 日志串口重定向指令(dtu_uart2.c):
+		删除 method=="re_console_log" 分支及 console_name_is / report_console_log_result,
+		不再支持运行时把主控制台切到 uart2 或其它串口,避免切换后 shell/日志落错口。
+	2、【新增】uart1、uart2 同时作为调试串口输出调试信息:
+		· rt-thread/src/kservice.c 增加弱钩子 rt_console_output_mirror(),rt_kprintf/rt_kputs
+		  在写完主控制台后回调同一段数据;rthw.h 中补充声明;
+		· drivers/board.c 实现该钩子:启动时以 RDWR|STREAM 常开 uart2,并逐字符调用
+		  ops->putc 轮询发送(自行把 '\n' 补成 "\r\n");
+		  初始化放在 rt_components_board_init() 之后,确保 UART_INIT(Usart_Init) 已使能
+		  USART2 时钟、配置好 PA2/PA3,否则 uart2 无输出;
+		· shell 输入仍只走 uart1,uart2 为单向输出(finsh 提示符/回显走 rt_kprintf,也会镜像)。
+	3、注意:
+		· 不能用 rt_device_write() 向 uart2 镜像:BSP_UART2_TX_USING_DMA 使能后,
+		  drv_usart_v2.c 的 CHECK_OPTMODE 把 uart2 TX 判为 NO_BUFFER,serial_v2 走
+		  _serial_fifo_tx_blocking_nbuf() -> rt_completion_wait(),该分支缺少"调度器未启动"
+		  保护,rt_hw_board_init() 后第一次 rt_kprintf()(启动 banner) 即触发
+		  "rt_completion_wait shall not be used before scheduler start" 断言;改用 putc 后正常。
+		· 中断上下文不镜像(115200 轮询发送 1 字节约 87us,ISR 内输出整行会拉长中断);
+		· 主控制台与镜像口都是轮询发送,日志吞吐约减半;uart2 被常开占用,后续若要作
+		  通信串口需先 rt_device_close()(镜像侧检测到 ref_count=0 会自动停止输出)。
+
 # 2026-11-10 更新说明(3.7.45 系统设置参数重置协议)
 	#define VERSION_BZY         "3.7.45"                   //孢子仪
 	配套工控机 app_bzy_armhf_7 版本 2.8.40(删除滤网界面与功能 / GPS 状态移入定位信息)

+ 5 - 0
Application_cbd_apm32f1/rt-thread/include/rthw.h

@@ -124,6 +124,11 @@ void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to);
 
 void rt_hw_console_output(const char *str);
 
+#ifdef RT_USING_CONSOLE
+/* 可选: 第二调试串口的镜像输出钩子, 由应用层实现(强符号) */
+void rt_console_output_mirror(const char *str, rt_size_t len);
+#endif
+
 void rt_hw_backtrace(rt_uint32_t *fp, rt_ubase_t thread_entry);
 void rt_hw_show_memory(rt_uint32_t addr, rt_size_t size);
 

+ 25 - 0
Application_cbd_apm32f1/rt-thread/src/kservice.c

@@ -1274,6 +1274,27 @@ RT_WEAK void rt_hw_console_output(const char *str)
 RTM_EXPORT(rt_hw_console_output);
 
 /**
+ * This function is an optional hook for a second console output device.
+ * When the application implements it (a strong symbol), rt_kputs() and
+ * rt_kprintf() will pass the same data to it after writing to the main
+ * console device, so that two UARTs can output the debug log at the same
+ * time. The default weak implementation does nothing, keeping the original
+ * single-console behavior.
+ *
+ * @param str is the string that has just been written to the console.
+ * @param len is the length of the string.
+ *
+ * @note The implementation must not call rt_kprintf()/rt_kputs() again,
+ *       otherwise the output will recurse infinitely.
+ */
+RT_WEAK void rt_console_output_mirror(const char *str, rt_size_t len)
+{
+    (void)str;
+    (void)len;
+}
+RTM_EXPORT(rt_console_output_mirror);
+
+/**
  * This function will put string to the console.
  *
  * @param str is the string output to the console.
@@ -1294,6 +1315,8 @@ void rt_kputs(const char *str)
 #else
     rt_hw_console_output(str);
 #endif /* RT_USING_DEVICE */
+
+    rt_console_output_mirror(str, rt_strlen(str));
 }
 
 /**
@@ -1330,6 +1353,8 @@ RT_WEAK int rt_kprintf(const char *fmt, ...)
 #else
     rt_hw_console_output(rt_log_buf);
 #endif /* RT_USING_DEVICE */
+
+    rt_console_output_mirror(rt_log_buf, length);
     va_end(args);
 
     return length;