Add complete data acquisition pipeline with LTC2508 ADC drivers, correction algorithms, data storage, and system monitoring. Includes ARM DSP optimized matrix operations for sensor calibration, SD card data logging with USB mass storage, and robust error handling with validation throughout the processing chain. - Add LTC2508 multi-channel SPI driver with DMA support and error recovery - Implement correction module with ARM DSP matrix operations for sensor calibration - Add data storage system with SD card logging and configurable file management - Integrate system monitor for health tracking and error reporting - Enhance data packet structure with CRC validation and timestamps - Add USB mass storage interface for SD card access - Implement comprehensive error handling and statistics collection
113 lines
2.4 KiB
C
113 lines
2.4 KiB
C
#include "system_monitor.h"
|
|
#include <string.h>
|
|
|
|
// 静态变量
|
|
static SystemMonitorStats_t g_system_stats = {0};
|
|
static uint32_t g_last_update_tick = 0;
|
|
|
|
/**
|
|
* @brief 初始化系统监控模块
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void SystemMonitor_Init(void)
|
|
{
|
|
memset(&g_system_stats, 0, sizeof(SystemMonitorStats_t));
|
|
g_system_stats.current_state = SYSTEM_STATE_INIT;
|
|
g_last_update_tick = HAL_GetTick();
|
|
}
|
|
|
|
/**
|
|
* @brief 更新系统监控状态
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void SystemMonitor_Update(void)
|
|
{
|
|
uint32_t current_tick = HAL_GetTick();
|
|
|
|
// 更新运行时间
|
|
if (current_tick >= g_last_update_tick) {
|
|
g_system_stats.uptime_seconds = current_tick / 1000;
|
|
}
|
|
|
|
// 获取LTC2508统计信息
|
|
LTC2508_StatsTypeDef ltc_stats;
|
|
LTC2508_GetStats(<c_stats);
|
|
g_system_stats.total_samples = ltc_stats.total_samples;
|
|
|
|
// 检查ADC错误
|
|
if (ltc_stats.error_count > 0) {
|
|
SystemMonitor_ReportError(SYSTEM_ERROR_ADC);
|
|
}
|
|
|
|
g_last_update_tick = current_tick;
|
|
}
|
|
|
|
/**
|
|
* @brief 获取当前系统状态
|
|
* @param None
|
|
* @retval SystemState_t
|
|
*/
|
|
SystemState_t SystemMonitor_GetState(void)
|
|
{
|
|
return g_system_stats.current_state;
|
|
}
|
|
|
|
/**
|
|
* @brief 设置系统状态
|
|
* @param new_state: 新的系统状态
|
|
* @retval None
|
|
*/
|
|
void SystemMonitor_SetState(SystemState_t new_state)
|
|
{
|
|
g_system_stats.current_state = new_state;
|
|
}
|
|
|
|
/**
|
|
* @brief 报告系统错误
|
|
* @param error: 错误类型
|
|
* @retval None
|
|
*/
|
|
void SystemMonitor_ReportError(SystemError_t error)
|
|
{
|
|
g_system_stats.last_error = error;
|
|
g_system_stats.error_count++;
|
|
|
|
// 根据错误类型设置系统状态
|
|
if (error == SYSTEM_ERROR_CRITICAL) {
|
|
g_system_stats.current_state = SYSTEM_STATE_ERROR;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 获取系统统计信息
|
|
* @param stats: 统计信息结构体指针
|
|
* @retval None
|
|
*/
|
|
void SystemMonitor_GetStats(SystemMonitorStats_t *stats)
|
|
{
|
|
if (stats != NULL) {
|
|
memcpy(stats, &g_system_stats, sizeof(SystemMonitorStats_t));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 检查系统健康状态
|
|
* @param None
|
|
* @retval uint8_t: 1-健康, 0-异常
|
|
*/
|
|
uint8_t SystemMonitor_IsHealthy(void)
|
|
{
|
|
// 检查系统状态
|
|
if (g_system_stats.current_state == SYSTEM_STATE_ERROR) {
|
|
return 0;
|
|
}
|
|
|
|
// 检查错误计数
|
|
if (g_system_stats.error_count > 10) {
|
|
return 0;
|
|
}
|
|
|
|
return 1; // 系统健康
|
|
} |