Files
GPS-Navigator-/ETH/UdpServer/app/app_data_processing.h

171 lines
4.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef APP_DATA_PROCESSING_H
#define APP_DATA_PROCESSING_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "app_frm_monitor.h"
#include "app_frm_signal.h"
#include "app_frm_timer.h"
#define RM3100_TIME 1000
#define GGA_BUF_SIZE 128
#define VTG_BUF_SIZE 64
#define IMU_IIM46234_HEADER1 0x23
#define IMU_IIM46234_HEADER2 0x23
#define IMU_YIS321_HEADER1 0x59
#define IMU_YIS321_HEADER2 0x53
#define SWAP_ENDIAN_16(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
#define SWAP_ENDIAN_32(x) (((x) << 24) | (((x) & 0xFF00) << 8) | (((x) >> 8) & 0xFF00) | ((x) >> 24))
#pragma pack(1)//数据结构一个字节对齐
/*
* @brief YIS协议标准数据帧结构
*/
typedef struct {
/*---------- 协议头 ----------*/
uint16_t header; ///< 固定值0x59 0x53协议6.3.1.1
/*---------- 元数据 ----------*/
uint16_t frame_number; ///< 帧序号1-60000小端存储协议6.3.1.3
uint8_t data_length; ///< 数据域长度0-255字节
/*---------- 有效载荷 ----------*/
// 加速度计数据ID 0x10
uint8_t acc_id; ///< 标识符0x10协议附录A.1
uint8_t acc_len; ///< 数据长度12字节
int32_t acc_x; ///< X轴加速度精度 0.000001 单位 m/s2
int32_t acc_y; ///< Y轴加速度 精度 0.000001 单位 m/s2
int32_t acc_z; ///< Z轴加速度 精度 0.000001 单位 m/s2
// 陀螺仪数据ID 0x20
uint8_t gyro_id; ///< 标识符0x20
uint8_t gyro_len; ///< 数据长度12字节
int32_t gyro_x; ///< X轴角速度 精度 0.000001 单位 deg/s
int32_t gyro_y; ///< Y轴角速度 精度 0.000001 单位 deg/s
int32_t gyro_z; ///< Z轴角速度 精度 0.000001 单位 deg/s
// 欧拉角数据ID 0x40[1,2](@ref)
uint8_t euler_id; ///< 标识符固定值0x40协议附录A.4Tait-Bryan角约定
uint8_t euler_len; ///< 数据长度3轴×4字节=12字节协议6.3.2.6
// 遵循Z-Y-X旋转顺序内旋系统角度值采用Q24定点数存储[2](@ref)
int32_t pitch; ///< X轴俯仰角单位0.000001°,转换公式:(raw × 1e-6)°
int32_t roll; ///< Y轴横滚角范围±90
int32_t yaw; ///< Z轴偏航角
// 四元数数据ID 0x41
uint8_t quat_id; ///< 标识符0x41
uint8_t quat_len; ///< 数据长度16字节
int32_t q0; ///< 精度 0.000001
int32_t q1; ///< 精度 0.000001
int32_t q2; ///< 精度 0.000001
int32_t q3; ///< 精度 0.000001
// 温度数据ID 0x01
uint8_t temp_id; ///< 标识符0x01
uint8_t temp_len; ///< 数据长度2字节
uint16_t temperature; ///< IMU温度 精度 0.01 单位:℃
// 时间戳协议6.3.3
uint8_t sampletime_id; ///< 标识符0x51
uint8_t sampletime_len; ///< 数据长度4字节
uint32_t sampletime; ///< 采样时间戳±1μs同步精度
uint8_t rady_time_id; ///< 标识符0x52
uint8_t rady_time_len; ///< 数据长度4字节
uint32_t rady_time; ///< 采样时间戳±1μs同步精度
/*---------- 校验区 ----------*/
uint16_t checksum1; ///< 校验码1协议6.3.1.2
} StrProtocolFrame;
typedef union _UnInfProtocolFrame
{
StrProtocolFrame bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrProtocolFrame)]; // 通过结构体类型确定大小
} UnInfProtocolFrame;
#pragma pack()
/* 定义GGA数据结构体 */
typedef struct {
double utc_time; // UTC时间HHMMSS.SSS格式
double latitude; // 纬度(十进制度)
char lat_dir; // 纬度方向N/S
double longitude; // 经度(十进制度)
char lon_dir; // 经度方向E/W
char fix_quality; // 定位质量0-5
char satellites; // 使用卫星数量
float hdop; // 水平精度因子
float altitude; // 海拔高度(米)
} GGA_Data;
/* 定义RMC数据结构体 */
typedef struct {
double utc_tim;
char status; // 定位状态(A=有效)
double latitude;
char lat_dir;
double longitude;
char lon_dir;
double speed; // 地面速度(节)
double course; // 地面航向(度)
char date[7]; // 日期DDMMYY
} RMC_Data;
// VTG数据结构体定义地面航向及速度信息
typedef struct {
float course_true; // 真北航向(单位:度)
float course_magnetic; // 磁北航向(单位:度)
float speed_knots; // 地面速度(单位:节)
float speed_kmh; // 地面速度(单位:公里/小时)
char mode; // 模式指示A=有效V=无效)
} VTG_Data;
// THS数据结构体定义
typedef struct {
float heading; // 航向(单位:度)
char mode; // 模式A/E/M/S/V
} THS_Data;
// 将度分格式转换为十进制函数
double nmea_to_decimal(double dm, char direction);
void gnggaProcess(void *signal_id);
void dataProcessingAppInit(void);
#ifdef __cplusplus
}
#endif
#endif // APP_DATA_PROCESSING_H