132 lines
4.0 KiB
C++
132 lines
4.0 KiB
C++
#include <stdint.h>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#pragma pack(push, 1)
|
||
|
||
// 位参数状态结构体(必须与发送端完全一致)
|
||
typedef union {
|
||
uint8_t ext;
|
||
struct {
|
||
uint8_t str_state1_data4 : 1;
|
||
uint8_t str_state1_data3 : 1;
|
||
uint8_t str_state1_data2 : 2;
|
||
uint8_t str_state1_data1 : 4;
|
||
};
|
||
} Bitpara_State;
|
||
|
||
#pragma pack(push, 1) // 确保1字节对齐
|
||
typedef struct {
|
||
uint8_t wheel_id; // 飞轮号
|
||
uint8_t mode; // 控制模式
|
||
uint8_t reserved; // 保留字节
|
||
float torque; // 力矩
|
||
float speed; // 速度
|
||
} Flywheel_Command;
|
||
#pragma pack(pop)
|
||
|
||
|
||
// 星敏感器遥测数据帧(必须与发送端完全一致)
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
// 设备标识
|
||
uint8_t star_type; // 星敏类型 (0=NANO, 1=PICO)
|
||
uint8_t star_num; // 星敏序号 (1~8)
|
||
|
||
// 四元数数据
|
||
float q0, q1, q2, q3;
|
||
|
||
// 角速度
|
||
float wx, wy, wz;
|
||
|
||
// 定姿星数
|
||
uint8_t star_num_d; // 定姿星数
|
||
|
||
// 错误计数部分
|
||
uint16_t header_err_cnt; // 帧头错误累计
|
||
uint16_t check_err_cnt; // 校验错误累计
|
||
uint16_t length_err_cnt; // 长度错误累计
|
||
uint16_t uart_reset_cnt; // 串口复位累计
|
||
uint16_t fault_cnt; // 故障计数(所有错误的总和)
|
||
} Star_sensorHS_Frame;
|
||
#pragma pack(pop)
|
||
|
||
// 陀螺仪数据帧
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
float x_angle_delta; // X轴角速度(度/秒)
|
||
float y_angle_delta; // Y轴角速度(度/秒)
|
||
float z_angle_delta; // Z轴角速度(度/秒)
|
||
uint16_t header_err_cnt; // 帧头错误累计
|
||
uint16_t check_err_cnt; // 校验错误累计
|
||
uint16_t length_err_cnt; // 长度错误累计
|
||
uint16_t uart_reset_cnt; // 串口复位累计
|
||
uint16_t fault_cnt; // 故障计数
|
||
} GYRO_Info_Frame;
|
||
#pragma pack(pop)
|
||
|
||
// MEMS数据帧
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
// 角增量数据 (rad)
|
||
float x_angle_delta;
|
||
float y_angle_delta;
|
||
float z_angle_delta;
|
||
uint16_t header_err_cnt; // 帧头错误累计
|
||
uint16_t check_err_cnt; // 校验错误累计
|
||
uint16_t length_err_cnt; // 长度错误累计
|
||
uint16_t uart_reset_cnt; // 串口复位累计
|
||
uint16_t fault_cnt; // 故障计数(所有错误的总和)
|
||
} MEMS_Info_Frame;
|
||
#pragma pack(pop)
|
||
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
// 设备标识
|
||
uint8_t wheel_id; // 逻辑ID
|
||
uint8_t hardware_id; // 硬件ID
|
||
|
||
// 状态数据
|
||
float rotate_speed; // 转速 (rpm)
|
||
float current; // 电流
|
||
float acc_torque; // 加速度矩
|
||
|
||
// 控制信息
|
||
uint16_t cmd_cnt; // 命令计数器
|
||
uint8_t soft_err; // 软件错误码
|
||
uint8_t soft_ver; // 软件版本
|
||
|
||
// 设备状态
|
||
uint8_t on_off_status; // 开关状态
|
||
|
||
// 错误统计
|
||
uint16_t header_err_cnt; // 帧头错误累计
|
||
uint16_t check_err_cnt; // 校验错误累计
|
||
uint16_t length_err_cnt; // 长度错误累计
|
||
uint16_t uart_reset_cnt; // 串口复位累计
|
||
uint16_t fault_cnt; // 故障计数
|
||
|
||
// 响应信息
|
||
uint8_t req_type; // 请求类型
|
||
int16_t error_code; // 错误码
|
||
} FLYWHEEL_Info_Frame;
|
||
#pragma pack(pop)
|
||
|
||
#pragma pack(pop)
|
||
|
||
void GncSWriteLog(const std::string &msg);
|
||
|
||
void GncS_init(uint8_t domainid, std::string appname);
|
||
|
||
void command_callback(std::string src, std::string dest, std::string type,
|
||
std::string reserve1, std::string reserve2,
|
||
std::vector<uint8_t>& data);
|
||
|
||
void telemetry_callback(std::string src, std::string dest, std::string type,
|
||
std::string reserve1, std::string reserve2,
|
||
std::vector<uint8_t>& data);
|
||
|
||
void GncS_command_Pub(uint8_t* data, std::string dest, uint16_t len);
|
||
|
||
void GncS_telemetry_Pub(uint8_t* data, std::string dest, uint16_t len);
|