✨ feat(gps): 集成GPS模块支持数据采集系统

- 新增GPS驱动模块,支持NMEA GPGGA/GNGGA语句解析
- 修改USART3配置,波特率从2000000调整为115200用于GPS数据接收
- 新增带GPS信息的校正数据包结构`CorrectedDataPacketWithGPS_t`
- 在ADC数据处理流程中集成GPS数据获取和打包
- 更新数据包处理函数,支持GPS时间戳和经纬度信息
- 新增GPS驱动使用指南和集成说明文档
- 修改主循环,添加GPS数据处理调用
- 更新中断处理,添加GPS UART接收回调支持

📝 docs(gps): 添加GPS驱动和集成说明文档

- 新增`GPS_Driver_Guide.md`详细说明GPS驱动API和使用方法
- 新增`GPS_Integration_Guide.md`说明GPS数据集成到采集系统的实现细节
- 文档包含硬件连接、数据格式、使用示例和故障排除等内容

♻️ refactor(data): 重构数据包结构以支持GPS信息

- 修改`DataPacket_t`和`CorrectedDataPacket_t`结构,添加GPS时间戳和经纬度字段
- 新增`CorrectedDataPacketWithGPS_t`结构用于带完整GPS信息的数据包
- 更新数据打包函数,支持GPS参数传递
- 简化数据包验证逻辑,移除校验和检查以提高处理速度

🔧 chore(config): 更新硬件配置文件

- 更新STM32CubeMX项目文件,修改USART3波特率配置
- 在中断处理文件中添加GPS驱动头文件包含
This commit is contained in:
2026-02-07 19:34:48 +08:00
parent 3c0acaa176
commit 5b245f89c1
10 changed files with 1288 additions and 72 deletions
+56 -20
View File
@@ -36,6 +36,7 @@
#include "data_storage.h"
#include "system_monitor.h"
#include "config_manager.h"
#include "gps_driver.h"
#include <stdio.h>
#include <string.h>
/* USER CODE END Includes */
@@ -79,6 +80,7 @@ CorrectionParams_t g_correction_params;
// 数据包
DataPacket_t g_data_packet;
CorrectedDataPacket_t g_corrected_packet;
CorrectedDataPacketWithGPS_t g_corrected_packet_with_gps; // 带GPS信息的数据包
// 数据存储句柄
DataStorageHandle_t g_data_storage;
// 系统状态
@@ -156,7 +158,7 @@ static void ProcessAdcData(void)
// 检查存储缓冲区是否可用(用于决定是否存储数据)
uint8_t can_store_data = 0;
if (g_recording_enabled) {
uint32_t max_packet_size = sizeof(CorrectedDataPacket_t);
uint32_t max_packet_size = sizeof(CorrectedDataPacketWithGPS_t); // 使用带GPS的数据包大小
can_store_data = DataStorage_IsBufferAvailable(&g_data_storage, max_packet_size);
}
@@ -170,6 +172,10 @@ static void ProcessAdcData(void)
raw_adc[i] = (int32_t)(((uint32_t)ready_buffer->data[i][0] << 16) | ready_buffer->data[i][1]);
}
// 2. 获取当前GPS数据
GPS_Data_t current_gps_data;
uint8_t gps_valid = GPS_GetData(&current_gps_data);
// 3. 应用校正算法
CorrectionResult_t correction_result;
uint8_t correction_applied = 0;
@@ -178,24 +184,38 @@ static void ProcessAdcData(void)
Apply_Correction(raw_adc[0], raw_adc[1], raw_adc[2],
&correction_result, &g_correction_params) == HAL_OK) {
// 4a. 打包校正后的数据
PackCorrectedData(&g_corrected_packet,
// 4a. 打包校正后的数据(带GPS关键信息:仅经纬度)
float lat = gps_valid ? (float)current_gps_data.position.latitude : 0.0f;
float lon = gps_valid ? (float)current_gps_data.position.longitude : 0.0f;
uint32_t gps_time = gps_valid ? (current_gps_data.time.hour * 10000 +
current_gps_data.time.minute * 100 +
current_gps_data.time.second) : 0;
PackCorrectedDataWithGPS(&g_corrected_packet_with_gps,
correction_result.corrected_x,
correction_result.corrected_y,
correction_result.corrected_z);
correction_result.corrected_z,
gps_time,
lat,
lon);
correction_applied = 1;
// 发送校正后的数据包到串口(运行时配置)
if (Config_IsUartOutputEnabled()) {
RS485_SendData((uint8_t*)&g_corrected_packet, sizeof(CorrectedDataPacket_t));
RS485_SendData((uint8_t*)&g_corrected_packet_with_gps, sizeof(CorrectedDataPacketWithGPS_t));
}
} else {
// 4b. 校正失败或未启用,使用原始数据
PackData(&g_data_packet, raw_adc[0], raw_adc[1], raw_adc[2]);
float lat = gps_valid ? (float)current_gps_data.position.latitude : 0.0f;
float lon = gps_valid ? (float)current_gps_data.position.longitude : 0.0f;
uint32_t gps_time = gps_valid ? (current_gps_data.time.hour * 10000 +
current_gps_data.time.minute * 100 +
current_gps_data.time.second) : 0;
PackData(&g_data_packet, raw_adc[0], raw_adc[1], raw_adc[2], gps_time, lat, lon);
// 发送原始数据包到串口(运行时配置)
if (Config_IsUartOutputEnabled()) {
@@ -207,8 +227,8 @@ static void ProcessAdcData(void)
if (Config_IsStorageEnabled() && g_recording_enabled) {
if (can_store_data) {
if (correction_applied) {
// 存储校正后的数据
DataStorage_WriteCorrectedData(&g_data_storage, &g_corrected_packet);
// 存储校正后的数据(带GPS信息)
DataStorage_WriteCorrectedData(&g_data_storage, (CorrectedDataPacket_t*)&g_corrected_packet_with_gps);
} else {
// 存储原始数据
DataStorage_WriteData(&g_data_storage, &g_data_packet);
@@ -229,30 +249,30 @@ static void ProcessAdcData(void)
}
/**
* @brief 初始化调试输出
* @brief 初始化调试输出和GPS
* @retval None
*/
static void DebugOutput_Init(void)
{
// USART3已在MX_USART3_UART_Init()中初始化
#if ENABLE_SYSTEM_MONITOR
DebugOutput_SendString("\r\n=== System Debug Output Initialized ===\r\n");
#endif
// USART3现在用于GPS接收,不再用于调试输出
// 初始化GPS驱动
if (GPS_Init() == HAL_OK) {
// GPS初始化成功
// 注意:GPS初始化后,USART3将用于接收GPS数据
}
}
/**
* @brief 通过USART3发送字符串
* @brief 通过USART3发送字符串(已禁用,USART3用于GPS)
* @param str: 要发送的字符串
* @retval None
*/
static void DebugOutput_SendString(const char* str)
{
#if ENABLE_SYSTEM_MONITOR
if (str == NULL) {
return;
}
HAL_UART_Transmit(&huart3, (uint8_t*)str, strlen(str), 100);
// USART3现在用于GPS接收,调试输出已禁用
// 如需调试输出,请使用USART1或其他串口
(void)str; // 避免未使用参数警告
#endif
}
@@ -594,6 +614,9 @@ int main(void)
// }
}
// GPS数据处理
GPS_Process();
// 定期输出调试信息 (每1秒输出一次)
#if ENABLE_SYSTEM_MONITOR
if (current_tick - g_last_debug_output >= DEBUG_OUTPUT_INTERVAL_MS) {
@@ -751,6 +774,19 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
}
}
/**
* @brief UART接收完成回调函数
* @param huart: UART句柄指针
* @retval None
*/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart == &huart3) {
// GPS数据接收回调
GPS_UART_RxCpltCallback(huart);
}
}
/* USER CODE END 4 */
/**
+1
View File
@@ -24,6 +24,7 @@
/* USER CODE BEGIN Includes */
#include "ltc2508_driver.h"
#include "rs485_driver.h"
#include "gps_driver.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
+1 -1
View File
@@ -70,7 +70,7 @@ void MX_USART3_UART_Init(void)
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 2000000;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;