3.27_433:添加UART2调试打印、IO监控、指令解析和继电器控制模块。

能够接收UART2指令控制继电器开关,或向UART2发送四路IO输入状态,并使用轮询方式检测IO状态进行及时反馈。
This commit is contained in:
2026-03-27 10:09:13 +08:00
parent f548593c59
commit 71027ebc46
76 changed files with 6789 additions and 1803 deletions

82
Core/Inc/io_monitor.h Normal file
View File

@ -0,0 +1,82 @@
/**
******************************************************************************
* @file io_monitor.h
* @brief IO状态监控模块头文件
* @author Application Layer
* @version 1.0
******************************************************************************
* @attention
* 本模块实现四路数字输入(DI1-DI4)的状态监控
* 采用定时扫描+软件去抖方式检测IO状态变化
* 状态变化时通过UART2_Print上报
******************************************************************************
*/
#ifndef __IO_MONITOR_H
#define __IO_MONITOR_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#define IO_CHANNEL_COUNT 4
#define IO_SCAN_PERIOD_MS 10
#define IO_DEBOUNCE_COUNT 3
/**
* @brief 初始化IO监控模块
* @note 初始化各通道状态读取初始IO电平
* @param 无
* @retval 无
*/
void IO_Monitor_Init(void);
/**
* @brief IO监控任务处理函数
* @note 在主循环中调用每10ms扫描一次IO状态
* 检测到状态变化时自动上报
* @param 无
* @retval 无
*/
void IO_Monitor_Task(void);
/**
* @brief 获取指定通道的IO状态
* @note 返回经过去抖处理后的稳定状态
* @param channel: 通道号(0-3对应DI1-DI4)
* @retval 0: LOW, 1: HIGH
*/
uint8_t IO_Monitor_GetState(uint8_t channel);
/**
* @brief 获取所有IO通道状态
* @note 返回4位状态值每位对应一个通道
* @param 无
* @retval 状态值 (bit0=DI1, bit1=DI2, bit2=DI3, bit3=DI4)
*/
uint8_t IO_Monitor_GetAllStates(void);
/**
* @brief 启用/禁用IO状态变化上报
* @note 禁用后状态变化不会触发上报,但状态仍会更新
* @param enable: true=启用, false=禁用
* @retval 无
*/
void IO_Monitor_EnableReport(bool enable);
/**
* @brief 获取IO状态变化次数统计
* @note 用于调试和诊断
* @param channel: 通道号(0-3)
* @retval 该通道的状态变化次数
*/
uint32_t IO_Monitor_GetChangeCount(uint8_t channel);
#ifdef __cplusplus
}
#endif
#endif