182 lines
7.4 KiB
C
182 lines
7.4 KiB
C
|
|
#ifndef COMHS_H
|
||
|
|
#define COMHS_H
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
// 遥测cmd定义
|
||
|
|
#define CON_TELEMETRY 0x0F //常规遥测查询
|
||
|
|
#define TELECONTROL_CMD 0x1E //遥控指令
|
||
|
|
#define QUERY_TELECMD 0x4B //遥控指令查询
|
||
|
|
#define SEND_TELEMETRY 0x5A //发送遥测
|
||
|
|
|
||
|
|
// 星间通信机子遥测
|
||
|
|
typedef union {
|
||
|
|
uint8_t ext[9]; //72位数据的联合体
|
||
|
|
struct __attribute__((__packed__)) {
|
||
|
|
unsigned int temperature : 12; //温度遥测
|
||
|
|
unsigned int temperature_calibrated : 12; //温度遥测标校
|
||
|
|
unsigned int transmission_power : 12; //12V电源遥测
|
||
|
|
unsigned int power_supply_5v4 : 12; //5.4V电源遥测
|
||
|
|
unsigned int power_supply_2v5 : 12; //2.5V电源遥测
|
||
|
|
unsigned int power_supply_1v2 : 12; //1.2V电源遥测
|
||
|
|
};
|
||
|
|
} s_comm_telemetry_t;
|
||
|
|
|
||
|
|
// 星间通信机子遥测
|
||
|
|
typedef union {
|
||
|
|
uint8_t ext;
|
||
|
|
struct __attribute__((__packed__)) {
|
||
|
|
unsigned int loadNo : 2; //加载程序编号
|
||
|
|
unsigned int loadMode : 2; //加载模式
|
||
|
|
unsigned int AorB : 1; //AB机状态
|
||
|
|
unsigned int FPGAFresh : 1; //FPGA刷新状态
|
||
|
|
unsigned int zaiboSync : 1; //信息载波同步
|
||
|
|
unsigned int weimaSync : 1; //信息伪码同步
|
||
|
|
};
|
||
|
|
} s_comm_para0;
|
||
|
|
|
||
|
|
// 星间通信机子遥测
|
||
|
|
typedef union {
|
||
|
|
uint8_t ext;
|
||
|
|
struct __attribute__((__packed__)) {
|
||
|
|
unsigned int recDampCtrlMode : 1; //接收衰减控制模式
|
||
|
|
unsigned int recDampCtrl : 3; //接收衰减控制字
|
||
|
|
unsigned int trans : 1; //发射通道开关
|
||
|
|
unsigned int transDampCtrl : 3; //发射衰减控制字
|
||
|
|
};
|
||
|
|
} s_comm_para2;
|
||
|
|
|
||
|
|
// 星间通信机子遥测
|
||
|
|
typedef union {
|
||
|
|
uint8_t ext;
|
||
|
|
struct __attribute__((__packed__)) {
|
||
|
|
unsigned int recStatus : 1; // 接收缓存状态
|
||
|
|
unsigned int workmode : 2; //工作模式
|
||
|
|
unsigned int sendStatus : 1; //发射缓存状态
|
||
|
|
unsigned int antsChoice : 1; //天线选择
|
||
|
|
unsigned int FreqChoice : 1; //频点选择
|
||
|
|
unsigned int telem_MM_Mode : 1; //遥测明/密状态
|
||
|
|
unsigned int telec_MM_Mode : 1; //遥控明/密状态
|
||
|
|
};
|
||
|
|
} s_comm_para3;
|
||
|
|
|
||
|
|
// S通信机遥测结构体
|
||
|
|
typedef struct __attribute__((packed)){
|
||
|
|
uint8_t packet_cnt_1; // 遥测包计数
|
||
|
|
uint8_t cmd1_success_count; //接收指令1正确计数
|
||
|
|
uint8_t cmd1_err_type1_count; //接收指令1错误类型1计数
|
||
|
|
uint8_t cmd2_success_count; //接收指令2正确计数
|
||
|
|
uint8_t cmd2_err_count; //接收指令2错误计数
|
||
|
|
uint8_t reset_count; //复位计数
|
||
|
|
uint8_t refresh_count; //刷新状态计数
|
||
|
|
s_comm_para0 para0; //
|
||
|
|
uint8_t para1; //
|
||
|
|
int8_t dopplerFreqInfoChannel; //信息通道多普勒频偏
|
||
|
|
int8_t dopplerFreqMeasureChannel; //测量通道多普勒频偏
|
||
|
|
uint8_t snrInfoChannel; //信息通道接收信噪比
|
||
|
|
uint8_t snrMeasureChannel; //测量通道接收信噪比
|
||
|
|
uint8_t receive_RSSI; //接收RSSI
|
||
|
|
uint8_t generalQueryCount; //常规遥测查询计数
|
||
|
|
uint8_t forwardcmdcnt; //转发遥控指令计数
|
||
|
|
uint8_t cmdinquiryCount; //空空接收后遥控计数
|
||
|
|
uint8_t teletransmissionCount; //转发遥测计数
|
||
|
|
uint8_t res0[2]; //LVDS预留参数,不使用
|
||
|
|
s_comm_para2 para2; //
|
||
|
|
s_comm_telemetry_t s_telemetry;
|
||
|
|
uint8_t AD9364_configuration_count; //AD9364配置计数
|
||
|
|
s_comm_para3 para3;
|
||
|
|
uint8_t res1[3]; //预留参数,CJB不使用
|
||
|
|
uint8_t cmd1_err_type2_count; //接收指令1错误类型2计数
|
||
|
|
uint16_t teletransmission_secretkey; //遥测当前密钥
|
||
|
|
uint16_t telecmd_secretkey; //遥控当前密钥
|
||
|
|
} S_Comm_telemetry_data_t;
|
||
|
|
|
||
|
|
// 指令/注数单元格式
|
||
|
|
typedef struct __attribute__((__packed__)){
|
||
|
|
uint8_t cmd_type; //指令类型
|
||
|
|
uint8_t cmd_len; //指令长度 数据内容+4
|
||
|
|
uint8_t device; //设备号
|
||
|
|
uint8_t REMAIN; //保留字
|
||
|
|
uint8_t data[255]; //数据内容 最大60
|
||
|
|
} CMD_unit;
|
||
|
|
|
||
|
|
// 遥控包 仅单指令
|
||
|
|
typedef struct __attribute__((__packed__)) {
|
||
|
|
uint8_t serve_type; //服务类型 全为50H实时指令
|
||
|
|
uint8_t cmd_num; //指令数
|
||
|
|
CMD_unit cmd_unit; //指令单元
|
||
|
|
} CMD_pack_t;
|
||
|
|
|
||
|
|
/*所占bit长度定义*/
|
||
|
|
#define EPDU_ID_VERSION_SIZE 3 //版本号
|
||
|
|
#define EPDU_ID_TYPE_SIZE 1 //类型
|
||
|
|
#define EPDU_ID_HEAD_SIZE 1 //副导头
|
||
|
|
#define EPDU_APID 11 //APID
|
||
|
|
|
||
|
|
#define EPDU_CONTROL_GROUPID_SIZE 2 //分组标识
|
||
|
|
#define EPDU_CONTROL_COUNT_SIZE 14 //包序列计数
|
||
|
|
|
||
|
|
#define MULTI_EPDU_LENS 244
|
||
|
|
|
||
|
|
/*包识别*/
|
||
|
|
typedef union{
|
||
|
|
uint16_t ext; //16位数据的联合体
|
||
|
|
struct __attribute__((__packed__)) {
|
||
|
|
unsigned int version : EPDU_ID_VERSION_SIZE; //版本号
|
||
|
|
unsigned int type : EPDU_ID_TYPE_SIZE; //类型
|
||
|
|
unsigned int subhead : EPDU_ID_HEAD_SIZE; //副导头
|
||
|
|
unsigned int reserve : EPDU_APID; //应用过程标识符
|
||
|
|
};
|
||
|
|
} packet_id_t;
|
||
|
|
|
||
|
|
/*包序列控制*/
|
||
|
|
typedef union{
|
||
|
|
uint16_t ext; // 16位数据的联合体
|
||
|
|
struct __attribute__((__packed__)) {
|
||
|
|
unsigned int groupid : EPDU_CONTROL_GROUPID_SIZE; //分组标识
|
||
|
|
unsigned int count : EPDU_CONTROL_COUNT_SIZE; //包序列计数
|
||
|
|
};
|
||
|
|
} sequence_control_t;
|
||
|
|
|
||
|
|
/*E-PDU源包格式*/
|
||
|
|
typedef struct __attribute__((__packed__)) {
|
||
|
|
packet_id_t id; //包识别
|
||
|
|
sequence_control_t seq; //包控制序列
|
||
|
|
uint16_t length; //包长
|
||
|
|
uint8_t data[MULTI_EPDU_LENS];
|
||
|
|
} EPDU_packet_t;
|
||
|
|
|
||
|
|
typedef struct __attribute__((__packed__)) {
|
||
|
|
uint16_t epdu_len;
|
||
|
|
EPDU_packet_t epdu;
|
||
|
|
} Multi_EPDU_packet_t;
|
||
|
|
|
||
|
|
// 声明ComHS接口函数
|
||
|
|
void ComHSWriteLog(const std::string &msg);
|
||
|
|
void ComHS_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 ComHS_command_Pub(uint8_t* data, std::string dest, uint16_t len);
|
||
|
|
void ComHS_telemetry_Pub(uint8_t* data, std::string dest, uint16_t len);
|
||
|
|
|
||
|
|
// 声明串口操作函数
|
||
|
|
int scomm_uart_init(const char *dev_telec, const char *dev_telem, int baudrate);
|
||
|
|
void send_S_COMM_Cmder(uint8_t *cmd, uint16_t len);
|
||
|
|
void Get_S_COMM_Telemetry_Data(void);
|
||
|
|
void Get_S_COMM_UP_CMD(void);
|
||
|
|
void Send_Telemetry_From_S(uint8_t *tele, uint16_t len);
|
||
|
|
void S_UART_TELEMETRY_SEND(uint8_t cmd, uint16_t len, uint8_t *nums);
|
||
|
|
int read_scomm_response(void);
|
||
|
|
int process_received_data(uint8_t *data, uint16_t size);
|
||
|
|
|
||
|
|
// 声明运行控制函数
|
||
|
|
void start_scomm_service(const char *dev_telec, const char *dev_telem, int baudrate);
|
||
|
|
void stop_scomm_service(void);
|
||
|
|
|
||
|
|
#endif // COMHS_H
|