extern_interface/include/telemetry.h

197 lines
7.4 KiB
C
Raw Normal View History

2024-11-28 08:31:00 +00:00
#ifndef _INCLUDE_TELEMETRY_
#define _INCLUDE_TELEMETRY_
#include <stdint.h>
#include <stddef.h>
#include "comframe.h"
#define TELEMETRY_REQUEST_PAYLOAD 0xFF11
#define TELEMETRY_STATUS_OK 0xAA
#define TELEMETRY_STATUS_ERROR 0x55
#define TELEMETRY_ERROR_TYPE 0x00E1
#define TELEMETRY_ERROR_CHECKSUM 0x00E2
#define TELEMETRY_SEND_COMMAND_INFO_LENGTH 5
#define TELEMETRY_ALARM_TC_A_PRESS 0x00610061
#define TELEMETRY_ALARM_TC_B_PRESS 0x00620062
#define TELEMETRY_ALARM_SUBSYS_PARAM_ERR 0x00630063
#define TELEMETRY_ALARM_WATER_TANK_FULL 0x00640064
#define TELEMETRY_ALARM_N2_PRESS_LOW 0x00650065
#define TELEMETRY_ALARM_O2_PRESS_LOW 0x00660066
#define TELEMETRY_ALARM_RETURN_CAB_FIRE 0x00670067
#define TELEMETRY_ALARM_RETURN_CAB_TOTAL_PRESS 0x00680068
#define TELEMETRY_ALARM_RETURN_CAB_O2_PART_PRESS 0x00690069
#define TELEMETRY_ALARM_RETURN_CAB_CO2_PART_PRESS 0x00700070
#define TELEMETRY_ALARM_INT_PUMP_B_SPEED 0x00710071
#define TELEMETRY_ALARM_CIRC_FAN_SPEED 0x00720072
#define TELEMETRY_ALARM_LND_SEAL_CAB_TOTAL_PRESS 0x00730073
#define TELEMETRY_ALARM_LND_SEAL_CAB_O2_PART_PRESS 0x00740074
#define TELEMETRY_ALARM_LND_SEAL_CAB_CO2_PART_PRESS 0x00750075
#define TELEMETRY_ALARM_LND_SEAL_CAB_FIRE 0x00760076
#define TELEMETRY_ALARM_LND_RAD_LEAK 0x00770077
#define TELEMETRY_ALARM_TAKEOFF 0x00010001
#define TELEMETRY_ALARM_SEP 0x00020002
#define TELEMETRY_ALARM_COMP_DOCK 0x00030003
#define TELEMETRY_ALARM_COMP_SEP 0x00040004
#define TELEMETRY_ALARM_RET_SEP 0x00050005
#define TELEMETRY_ALARM_REC_START 0x00060006
#define TELEMETRY_ALARM_LND 0x00070007
#define TELEMETRY_ALARM_ESC_TOWER_ESC 0x00080008
#define TELEMETRY_ALARM_RESERVED_1 0x00090009
#define TELEMETRY_ALARM_ESC_TOWER_SEP 0x000A000A
#define TELEMETRY_ALARM_VESSEL_ESC 0x00110011
#define TELEMETRY_ALARM_PREP_5_MIN 0x17711771
#define TELEMETRY_ALARM_PREP_1_MIN 0x17721772
#define TELEMETRY_ALARM_DOCK_PREP 0x17731773
#define TELEMETRY_ALARM_DOCK_RING_CONTACT 0x17741774
#define TELEMETRY_ALARM_SEP_COMPLETE 0x17751775
#define TELEMETRY_ALARM_PAYLOAD_SEP 0x17761776
#define TELEMETRY_ALARM_SAILS_DEPLOY 0x17771777
#define TELEMETRY_ALARM_SEP_PREP 0x17781778
#define TELEMETRY_ALARM_SAILS_DEPLOY_PREP 0x17791779
#define TELEMETRY_ALARM_RESERVED_2 0x177A177A
#define TELEMETRY_ALARM_ORBIT_CHG_30_MIN 0x177B177B
#define TELEMETRY_ALARM_ORBIT_CHG_10_MIN 0x177C177C
#define TELEMETRY_ALARM_ORBIT_CHG_5_MIN 0x177D177D
#define TELEMETRY_ALARM_ENGINE_START_CMD 0x177E177E
#define TELEMETRY_ALARM_ENGINE_STOP_CMD 0x177F177F
#define TELEMETRY_ALARM_ORBIT_CHG_END 0x17801780
#define TELEMETRY_ALARM_GNC_SELF_CTRL_MODE 0x17811781
#define TELEMETRY_ALARM_APPROACH_FLIGHT_START 0x17821782
#define TELEMETRY_ALARM_YAW_ADJ_START 0x17831783
#define TELEMETRY_ALARM_YAW_ADJ_COMPLETE 0x17841784
#define TELEMETRY_ALARM_TRANSLATION_PHASE 0x17851785
#define TELEMETRY_ALARM_DOCK_POINT_ENTRY 0x17861786
#define TELEMETRY_ALARM_APPROACH_FLIGHT_CONTINUE 0x17871787
#define TELEMETRY_ALARM_PITCH_ADJ_START 0x17881788
#define TELEMETRY_ALARM_PITCH_ADJ_COMPLETE 0x17891789
#define TELEMETRY_ALARM_FINAL_APPROACH_FLIGHT 0x178A178A
#define ComFrameTelemetry_STATUS_OK(status) ((status) == TELEMETRY_STATUS_OK)
#define ComFrameTelemetry_STATUS_ERR(status) ((status) == TELEMETRY_STATUS_ERROR)
#define ComFrameTelemetry_STATUS_STR(status) ( \
ComFrameTelemetry_STATUS_OK(status) ? "ok" : \
(ComFrameTelemetry_STATUS_ERR(status) ? "error" : "unknown") \
)
#ifdef __cplusplus
extern "C" {
#endif
struct TelemetryCommandInfo {
uint32_t time;
uint8_t code[2];
uint16_t seqid;
} __attribute__((packed));
struct TelemetrySendCommandInfo {
uint8_t seqid;
uint8_t flag;
uint32_t time;
uint8_t code[2];
} __attribute__((packed));
struct TelemetryData4UpperHost { // upper
uint8_t work_status;
uint8_t com_status;
uint8_t coprocessor1_status;
uint8_t coprocessor2_status;
uint8_t voice_circuit_status;
//uint8_t work_status_backup;
uint8_t telemetry_count;
uint8_t voice_mode;
uint8_t recognition_status;
uint8_t recognition_info[8];
uint8_t particle_detection1;
uint8_t particle_detection2;
uint8_t particle_detection3;
// 2024.10.25
struct TelemetryCommandInfo receive_command;
struct TelemetryCommandInfo send_command;
uint8_t volume_key_status;
uint8_t wake_key_status;
uint8_t key_status_backup;
uint8_t current_volume;
uint8_t system_version_high;
uint8_t system_version_low;
uint8_t application_version_high;
uint8_t application_version_low;
uint8_t alarm_code[4];
uint8_t telemetry_backup[5];
} __attribute__((packed));
struct TelemetryData { // telemetry
uint8_t work_status;
uint8_t com_status;
uint8_t coprocessor1_status;
uint8_t coprocessor2_status;
uint8_t voice_circuit_status;
//uint8_t work_status_backup;
uint8_t telemetry_count;
uint8_t voice_mode;
uint8_t recognition_status;
uint8_t recognition_info[8];
uint8_t particle_detection1;
uint8_t particle_detection2;
uint8_t particle_detection3;
// 2024.10.25
struct TelemetryCommandInfo receive_command;
struct TelemetrySendCommandInfo send_command[TELEMETRY_SEND_COMMAND_INFO_LENGTH];
uint8_t volume_key_status;
uint8_t wake_key_status;
uint8_t key_status_backup;
uint8_t current_volume;
uint8_t system_version_high;
uint8_t system_version_low;
uint8_t application_version_high;
uint8_t application_version_low;
uint8_t send_count;
} __attribute__((packed));
static __inline void UpperHostTelemetryData_SwapEndian(struct TelemetryData4UpperHost* tele_data) {
tele_data->receive_command.seqid = byteswaps(tele_data->receive_command.seqid);
tele_data->receive_command.time = byteswapl(tele_data->receive_command.time);
tele_data->send_command.seqid = byteswaps(tele_data->send_command.seqid);
tele_data->send_command.time = byteswapl(tele_data->send_command.time);
}
static __inline void TelemetryData_SwapEndian(struct TelemetryData* tele_data) {
tele_data->receive_command.seqid = byteswaps(tele_data->receive_command.seqid);
tele_data->receive_command.time = byteswapl(tele_data->receive_command.time);
for (size_t i = 0; i < TELEMETRY_SEND_COMMAND_INFO_LENGTH; i++) {
tele_data->send_command[i].time = byteswapl(tele_data->send_command[i].time);
}
}
static __inline ComFrame* NewTelemetryRequestMsg(uint16_t address, const bool swap_endian) {
uint16_t tele_request_payload = (swap_endian) ? byteswaps(TELEMETRY_REQUEST_PAYLOAD) : TELEMETRY_REQUEST_PAYLOAD;
return ComFrame_New(address, COM_FRAME_TYPE_TELEMETRY_REQUEST, &tele_request_payload, sizeof(uint16_t), swap_endian);
}
static __inline ComFrame* NewTelemetryAnswerData(uint16_t address, const struct TelemetryData4UpperHost* tele_data, const bool swap_endian) {
ComFrame* frame = ComFrame_New(address, COM_FRAME_TYPE_TELEMETRY_ANSWER, tele_data, sizeof(struct TelemetryData4UpperHost), swap_endian);
if (swap_endian)
UpperHostTelemetryData_SwapEndian((struct TelemetryData4UpperHost*)(frame->payload));
return frame;
}
static __inline ComFrame* NewTelemetryErrorMsg(uint16_t address, uint16_t code, const bool swap_endian) {
uint16_t tele_error_payload = (swap_endian) ? byteswaps(code) : code;
return ComFrame_New(address, COM_FRAME_TYPE_TELEMETRY_REQUEST, &tele_error_payload, sizeof(uint16_t), swap_endian);
}
ssize_t SendTelemetryErrorMsg(int tty_id, uint16_t address, uint16_t code, const bool swap_endian);
#ifdef __cplusplus
}
#endif
#endif