✨ feat(config): 新增运行时配置管理功能
- 新增配置管理器模块,支持从SD卡加载运行时配置 - 将数据输出模式从编译时宏改为运行时配置,提高灵活性 - 新增配置文件 `CONFIG.TXT`,支持串口输出和存储功能的动态开关 - 集成配置管理器到主程序,在系统启动时自动加载配置 - 更新数据存储模块,使用配置管理器管理会话序号 🐛 fix(usart): 修复USART3中断配置并优化波特率 - 添加USART3中断处理函数声明和实现 - 将USART3波特率从921600提升至2000000以提高通信速率 - 调整USART1中断优先级从2改为11,优化中断响应 - 在USART3 MSP初始化和反初始化中添加中断配置 📝 docs(user): 新增功能说明文档 - 新增《配置管理功能说明》文档,详细说明运行时配置的使用方法 - 新增《串口发送监控功能说明》文档,说明新增的串口统计功能 - 文档包含配置项说明、文件格式、使用示例和注意事项 ✨ feat(monitor): 增强系统监控功能 - 在系统监控统计中添加串口发送监控字段(发送次数、字节数、错误数) - 新增串口发送统计报告函数,集成到RS485驱动中 - 优化监控状态保存格式,采用精简格式减少文件写入阻塞时间 - 监控数据现在包含串口统计信息,便于性能分析和故障排查 ♻️ refactor(main): 重构主程序配置处理逻辑 - 移除编译时宏 `DATA_OUTPUT_MODE_UART` 和 `DATA_OUTPUT_MODE_STORAGE` - 使用 `Config_IsUartOutputEnabled()` 和 `Config_IsStorageEnabled()` 函数替代 - 优化数据存储启动逻辑,仅在存储功能启用时开始记录 - 添加配置加载成功/失败的调试输出信息
This commit is contained in:
+29
-18
@@ -35,6 +35,7 @@
|
||||
#include "correction.h"
|
||||
#include "data_storage.h"
|
||||
#include "system_monitor.h"
|
||||
#include "config_manager.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
@@ -51,10 +52,10 @@
|
||||
#define DEBUG_OUTPUT_INTERVAL_MS 1000 // 调试输出间隔(毫秒)
|
||||
#define MONITOR_SAVE_INTERVAL_MS 10000 // 监控状态保存间隔(毫秒) - 10秒
|
||||
|
||||
// 数据输出模式选择(可以同时启用)
|
||||
#define DATA_OUTPUT_MODE_UART 1 // 0=禁用, 1=启用串口输出数据
|
||||
#define DATA_OUTPUT_MODE_STORAGE 0 // 0=禁用, 1=启用存储到卡
|
||||
// 注意:两个模式可以同时启用,但会增加系统负载
|
||||
// 数据输出模式选择(运行时配置,从SD卡加载)
|
||||
// 注意:DATA_OUTPUT_MODE_UART 和 DATA_OUTPUT_MODE_STORAGE 已改为运行时配置
|
||||
// 使用 Config_IsUartOutputEnabled() 和 Config_IsStorageEnabled() 来检查状态
|
||||
// 配置文件:0:/CONFIG.TXT
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -186,25 +187,24 @@ static void ProcessAdcData(void)
|
||||
|
||||
correction_applied = 1;
|
||||
|
||||
#if DATA_OUTPUT_MODE_UART
|
||||
// 发送校正后的数据包到串口
|
||||
RS485_SendData((uint8_t*)&g_corrected_packet, sizeof(CorrectedDataPacket_t));
|
||||
#endif
|
||||
// 发送校正后的数据包到串口(运行时配置)
|
||||
if (Config_IsUartOutputEnabled()) {
|
||||
RS485_SendData((uint8_t*)&g_corrected_packet, sizeof(CorrectedDataPacket_t));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// 4b. 校正失败或未启用,使用原始数据
|
||||
PackData(&g_data_packet, raw_adc[0], raw_adc[1], raw_adc[2]);
|
||||
|
||||
#if DATA_OUTPUT_MODE_UART
|
||||
// 发送原始数据包到串口
|
||||
RS485_SendData((uint8_t*)&g_data_packet, sizeof(DataPacket_t));
|
||||
#endif
|
||||
// 发送原始数据包到串口(运行时配置)
|
||||
if (Config_IsUartOutputEnabled()) {
|
||||
RS485_SendData((uint8_t*)&g_data_packet, sizeof(DataPacket_t));
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 存储数据到SD卡 (如果启用记录且缓冲区可用)
|
||||
#if DATA_OUTPUT_MODE_STORAGE
|
||||
if (g_recording_enabled) {
|
||||
// 6. 存储数据到SD卡 (如果启用记录且缓冲区可用,运行时配置)
|
||||
if (Config_IsStorageEnabled() && g_recording_enabled) {
|
||||
if (can_store_data) {
|
||||
if (correction_applied) {
|
||||
// 存储校正后的数据
|
||||
@@ -220,7 +220,6 @@ static void ProcessAdcData(void)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// 7. 释放已处理的缓冲区
|
||||
LTC2508_ReleaseBuffer(LTC2508_GetCurrentReadBuffer());
|
||||
@@ -500,6 +499,9 @@ int main(void)
|
||||
// 初始化调试输出
|
||||
DebugOutput_Init();
|
||||
|
||||
// 初始化配置管理器(设置默认值)
|
||||
Config_Init();
|
||||
|
||||
// 初始化RS485通信
|
||||
RS485_Init(&huart1, RS485_DE_RE_PORT, RS485_DE_RE_PIN);
|
||||
|
||||
@@ -513,10 +515,19 @@ int main(void)
|
||||
if (!g_usb_connected) {
|
||||
// USB未连接,挂载文件系统用于数据采集
|
||||
if (MountFileSystemForSampling() == HAL_OK) {
|
||||
// 从SD卡加载配置
|
||||
if (Config_Load() == HAL_OK) {
|
||||
DebugOutput_SendString("Config loaded from SD card\r\n");
|
||||
} else {
|
||||
DebugOutput_SendString("Using default config\r\n");
|
||||
}
|
||||
|
||||
// 初始化数据存储
|
||||
if (DataStorage_Init(&g_data_storage) == HAL_OK) {
|
||||
// 开始数据记录
|
||||
StartRecording();
|
||||
// 开始数据记录(如果存储功能已启用)
|
||||
if (Config_IsStorageEnabled()) {
|
||||
StartRecording();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -68,6 +68,7 @@ extern DMA_HandleTypeDef hdma_spi3_rx;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern DMA_HandleTypeDef hdma_usart1_tx;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
extern UART_HandleTypeDef huart3;
|
||||
/* USER CODE BEGIN EV */
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern SPI_HandleTypeDef hspi2;
|
||||
@@ -283,6 +284,20 @@ void USART1_IRQHandler(void)
|
||||
/* USER CODE END USART1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART3 global interrupt.
|
||||
*/
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART3_IRQn 0 */
|
||||
|
||||
/* USER CODE END USART3_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart3);
|
||||
/* USER CODE BEGIN USART3_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART3_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SDIO global interrupt.
|
||||
*/
|
||||
|
||||
+7
-2
@@ -70,7 +70,7 @@ void MX_USART3_UART_Init(void)
|
||||
|
||||
/* USER CODE END USART3_Init 1 */
|
||||
huart3.Instance = USART3;
|
||||
huart3.Init.BaudRate = 921600;
|
||||
huart3.Init.BaudRate = 2000000;
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart3.Init.StopBits = UART_STOPBITS_1;
|
||||
huart3.Init.Parity = UART_PARITY_NONE;
|
||||
@@ -131,7 +131,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
__HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx);
|
||||
|
||||
/* USART1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 11, 0);
|
||||
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||
/* USER CODE BEGIN USART1_MspInit 1 */
|
||||
|
||||
@@ -157,6 +157,9 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* USART3 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART3_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(USART3_IRQn);
|
||||
/* USER CODE BEGIN USART3_MspInit 1 */
|
||||
|
||||
/* USER CODE END USART3_MspInit 1 */
|
||||
@@ -203,6 +206,8 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
|
||||
|
||||
/* USART3 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(USART3_IRQn);
|
||||
/* USER CODE BEGIN USART3_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END USART3_MspDeInit 1 */
|
||||
|
||||
Reference in New Issue
Block a user