XNSim/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.cpp

1082 lines
35 KiB
C++
Executable File
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.

#include "XNATA04DataProcessor.h"
#include "XNATA04DataProcessor_p.h"
#include <XNCore/XNModelManager.h>
#include <XNCore/XNDDSManager.h>
#include <iostream>
XN_MODEL_INITIALIZE(XNATA04DataProcessor)
XNATA04DataProcessor::XNATA04DataProcessor() : XNModelObject(new XNATA04DataProcessorPrivate())
{
}
XNATA04DataProcessor::~XNATA04DataProcessor()
{
}
XNATA04DataProcessor::XNATA04DataProcessor(PrivateType *p) : XNModelObject(p)
{
}
void XNATA04DataProcessor::Initialize()
{
T_D();
XNModelObject::Initialize();
}
void XNATA04DataProcessor::PrepareForExecute()
{
T_D();
XNModelObject::PrepareForExecute();
// RegisterRTEventHandler("ATA04AeroInput", std::bind(&XNATA04DataProcessor::OnAeroInput, this,
// std::placeholders::_1));
// RegisterRTEventHandler(
// "ATA04WbInput", std::bind(&XNATA04DataProcessor::OnWbInput, this, std::placeholders::_1));
RegisterRTEventHandler(
"ATA04GhInput", std::bind(&XNATA04DataProcessor::OnGhInput, this, std::placeholders::_1));
d->_ghInputInterface.Initialize(GetFramework(), GetUniqueId(), 2);
d->_ghOutputInterface.Initialize(GetFramework(), GetUniqueId(), 1);
d->_ghHeartbeatInterface.Initialize(GetFramework(), GetUniqueId(), 1);
}
void XNATA04DataProcessor::StepUpdate()
{
T_D();
XNModelObject::StepUpdate();
SendUdpData();
//SendUdpTestData();
}
void XNATA04DataProcessor::SendUdpData()
{
T_D();
// SendAeroOutput();
// SendWbOutput();
SendGhOutput();
// SendAeroHeartbeat();
// SendWbHeartbeat();
SendGhHeartbeat();
}
// void XNATA04DataProcessor::SendAeroOutput()
// {
// T_D();
// QMutexLocker locker(&d->_aeroOutputMutex);
// QByteArray outputData;
// QDataStream outputStream(&outputData, QIODevice::WriteOnly);
// outputStream.setByteOrder(QDataStream::LittleEndian);
// quint8 header[6] = {0x0a, 0x04, 0x00, 0x01, 0x00, 0x00}; // 最后两个字节用于大小
// outputStream << header[0] << header[1] << header[2] << header[3] << header[4] << header[5];
// //outputData.append(getQByteArray(d->_aeroOutput.l_04_o_aerocomac_fxb_f8()));
// if (d->_aeroOutput.l_04_o_aerocomac_fxb_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_fxb_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_fyb_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_fyb_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_fzb_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_fzb_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_mxb_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_mxb_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_myb_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_myb_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_mzb_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_mzb_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_cls_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_cls_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_cl_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_cl_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_cd_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_cd_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_cm_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_cm_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_cr_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_cr_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_cy_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_cy_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_aeroOutput.l_04_o_aerocomac_cn_f8()) {
// outputStream << d->_aeroOutput.l_04_o_aerocomac_cn_f8().value();
// } else {
// outputStream << (double)0;
// }
// // 更新数据包大小(使用两个字节)
// auto size = outputData.size();
// outputData[4] = (size >> 8) & 0xFF; // 高字节
// outputData[5] = size & 0xFF; // 低字节
// TriggerRTEvent("SendUDPData", QVariant::fromValue(outputData));
// }
void XNATA04DataProcessor::SendGhOutput()
{
T_D();
XNByteArray outputData = d->_ghOutputInterface.getUDPPackage();
//填写数据方向
outputData[5] = 0x01;
TriggerRTEvent("SendUDPData", std::any(outputData));
}
// void XNATA04DataProcessor::SendWbOutput()
// {
// Q_D(XNATA04DataProcessor);
// QMutexLocker locker(&d->_wbOutputMutex);
// QByteArray outputData;
// QDataStream outputStream(&outputData, QIODevice::WriteOnly);
// outputStream.setByteOrder(QDataStream::LittleEndian);
// quint8 header[6] = {0x0a, 0x04, 0x02, 0x01, 0x00, 0x00}; // 最后两个字节用于大小
// outputStream << header[0] << header[1] << header[2] << header[3] << header[4] << header[5];
// if (d->_wbOutput.l_04_o_wbcomac_gw_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_gw_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_cg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_cg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_xcg_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_xcg_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_blcg_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_blcg_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_bscg_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_bscg_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_wlcg_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_wlcg_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ixx_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ixx_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_iyy_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_iyy_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_izz_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_izz_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ixy_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ixy_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ixz_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ixz_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_iyz_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_iyz_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_zfw_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_zfw_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_zfwcg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_zfwcg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_zfw_blcg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_zfw_blcg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_zfw_wlcg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_zfw_wlcg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_cmd_f8()) {
// for (int i = 0; i < 3; i++) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_cmd_f8().value()[i];
// }
// } else {
// outputStream << (double)0 << (double)0 << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_mode_i4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_mode_i4().value();
// } else {
// outputStream << (int)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_ixx_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_ixx_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_ixy_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_ixy_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_ixz_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_ixz_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_iyy_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_iyy_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_iyz_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_iyz_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_fuel_izz_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_fuel_izz_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_l_wt_fuel_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_l_wt_fuel_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_airframe_total_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_airframe_total_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_eng_f8()) {
// for (int i = 0; i < 2; i++) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_eng_f8().value()[i];
// }
// } else {
// outputStream << (double)0 << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_eng_total_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_eng_total_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_fuselage_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_fuselage_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_stab_left_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_stab_left_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_stab_right_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_stab_right_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_stab_total_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_stab_total_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_total_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_total_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_total_frac_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_total_frac_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_vert_tail_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_vert_tail_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_wing_left_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_wing_left_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_wing_right_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_wing_right_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ice_wing_total_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ice_wing_total_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_frz_l1()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_frz_l1().value();
// } else {
// outputStream << (quint8)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_zcgfrz_l1()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_zcgfrz_l1().value();
// } else {
// outputStream << (quint8)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_zcgfrz_grfx_l1()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_zcgfrz_grfx_l1().value();
// } else {
// outputStream << (quint8)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_ycgfrz_l1()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_ycgfrz_l1().value();
// } else {
// outputStream << (quint8)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_inertfrz_l1()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_inertfrz_l1().value();
// } else {
// outputStream << (quint8)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_init_l1()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_init_l1().value();
// } else {
// outputStream << (quint8)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_min_gw_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_min_gw_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_max_gw_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_max_gw_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_min_cg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_min_cg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_max_cg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_max_cg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_min_zfw_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_min_zfw_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_max_zfw_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_max_zfw_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_min_zfwcg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_min_zfwcg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_max_zfwcg_f4()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_max_zfwcg_f4().value();
// } else {
// outputStream << (float)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_potmin_gw_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_potmin_gw_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_potmax_gw_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_potmax_gw_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_potmin_gwcg_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_potmin_gwcg_f8().value();
// } else {
// outputStream << (double)0;
// }
// if (d->_wbOutput.l_04_o_wbcomac_potmax_gwcg_f8()) {
// outputStream << d->_wbOutput.l_04_o_wbcomac_potmax_gwcg_f8().value();
// } else {
// outputStream << (double)0;
// }
// // 更新数据包大小(使用两个字节)
// auto size = outputData.size();
// outputData[4] = (size >> 8) & 0xFF; // 高字节
// outputData[5] = size & 0xFF; // 低字节
// TriggerRTEvent("SendUDPData", QVariant::fromValue(outputData));
// }
// void XNATA04DataProcessor::SendAeroHeartbeat()
// {
// Q_D(XNATA04DataProcessor);
// QMutexLocker locker(&d->_aeroHeartbeatMutex);
// QByteArray heartbeatData;
// QDataStream heartbeatStream(&heartbeatData, QIODevice::WriteOnly);
// heartbeatStream.setByteOrder(QDataStream::LittleEndian);
// quint8 header[6] = {0x0a, 0x04, 0x00, 0x02, 0x00, 0x00}; // 最后两个字节用于大小
// heartbeatStream << header[0] << header[1] << header[2] << header[3] << header[4] << header[5];
// heartbeatStream << d->_aeroHeartbeat.aero_model_heartbeat();
// // 更新数据包大小(使用两个字节)
// auto size = heartbeatData.size();
// heartbeatData[4] = (size >> 8) & 0xFF; // 高字节
// heartbeatData[5] = size & 0xFF; // 低字节
// TriggerRTEvent("SendUDPData", QVariant::fromValue(heartbeatData));
// }
void XNATA04DataProcessor::SendGhHeartbeat()
{
T_D();
XNByteArray outputData = d->_ghHeartbeatInterface.getUDPPackage();
//填写数据方向
outputData[5] = 0x01;
TriggerRTEvent("SendUDPData", std::any(outputData));
}
// void XNATA04DataProcessor::SendWbHeartbeat()
// {
// Q_D(XNATA04DataProcessor);
// QMutexLocker locker(&d->_wbHeartbeatMutex);
// QByteArray heartbeatData;
// QDataStream heartbeatStream(&heartbeatData, QIODevice::WriteOnly);
// heartbeatStream.setByteOrder(QDataStream::LittleEndian);
// quint8 header[6] = {0x0a, 0x04, 0x02, 0x02, 0x00, 0x00}; // 最后两个字节用于大小
// heartbeatStream << header[0] << header[1] << header[2] << header[3] << header[4] << header[5];
// heartbeatStream << d->_wbHeartbeat.weightbody_model_heartbeat();
// // 更新数据包大小(使用两个字节)
// auto size = heartbeatData.size();
// heartbeatData[4] = (size >> 8) & 0xFF; // 高字节
// heartbeatData[5] = size & 0xFF; // 低字节
// TriggerRTEvent("SendUDPData", QVariant::fromValue(heartbeatData));
// }
// void XNATA04DataProcessor::OnWbInput(const QVariant &data)
// {
// Q_D(XNATA04DataProcessor);
// QByteArray inputData = data.toByteArray();
// // 检查数据包头
// if (inputData[0] != 0x0b || inputData[1] != 0x04 || inputData[2] != 0x02
// || inputData[3] != 0x00) {
// LOG_WARNING("ATA04DataProcessor::OnWbInput: invalid input data header");
// return;
// }
// // 读取两个字节的大小字段
// quint16 size = ((quint16)(quint8)inputData[4] << 8) | (quint16)(quint8)inputData[5];
// if (size != inputData.size()) {
// LOG_WARNING(
// "ATA04DataProcessor::OnWbInput: invalid data size. Expected %d bytes, got %d bytes",
// size, inputData.size());
// return;
// }
// QDataStream inputStream(&inputData, QIODevice::ReadOnly);
// inputStream.setByteOrder(QDataStream::LittleEndian);
// inputStream.setVersion(QDataStream::Qt_6_0);
// // 跳过6字节的头
// for (int i = 0; i < 6; i++) {
// char tmp;
// inputStream >> tmp;
// }
// QMutexLocker locker(&d->_wbInputMutex);
// double dTmp;
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_theta_deg_f8(dTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_phi_deg_f8(dTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_psi_deg_f8(dTmp);
// quint8 ucTmp;
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_gear_mode_l1(ucTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_acset_gw_f8(dTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_acset_cg_f8(dTmp);
// std::array<float, 20> farray20;
// for (int i = 0; i < 20; i++) {
// inputStream >> farray20[i];
// }
// d->_wbInput.l_04_i_wbcomac_acset_tankfuel_f4(farray20);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_acset_totfuel_f8(dTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_acset_zfw_f8(dTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_acset_zfwcg_f8(dTmp);
// std::array<char, 4> ucarray4;
// for (int i = 0; i < 4; i++) {
// inputStream >> ucarray4[i];
// }
// d->_wbInput.l_04_i_wbcomac_eng_efsep_l1(ucarray4);
// std::array<double, 20> darray20;
// for (int i = 0; i < 20; i++) {
// inputStream >> darray20[i];
// }
// d->_wbInput.l_04_i_wbcomac_fuel_f8(darray20);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_gear_avg_f8(dTmp);
// for (int i = 0; i < 20; i++) {
// inputStream >> darray20[i];
// }
// d->_wbInput.l_04_i_wbcomac_kice_f8(darray20);
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_bycglim_l1(ucTmp);
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_bygwlim_l1(ucTmp);
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_frz_l1(ucTmp);
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_zcgfrz_l1(ucTmp);
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_zcgfrz_grfx_l1(ucTmp);
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_ycgfrz_l1(ucTmp);
// inputStream >> ucTmp;
// d->_wbInput.l_04_i_wbcomac_inertfrz_l1(ucTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_potreq_gw_f8(dTmp);
// inputStream >> dTmp;
// d->_wbInput.l_04_i_wbcomac_potreq_gwcg_f8(dTmp);
// d->_dataWriters["XNSim::ATA04::WeightBalance_input"]->write(&d->_wbInput);
// }
void XNATA04DataProcessor::OnGhInput(const std::any &data)
{
T_D();
XNByteArray inputData = std::any_cast<XNByteArray>(data);
// 检查数据包头
if (inputData[0] != 0xa6) {
LOG_WARNING("接收到不是XNSim的数据包");
return;
}
if (inputData[1] != 0xc0) {
LOG_WARNING("接收到不是C909的数据包");
return;
}
if (inputData[2] != 0x04) {
LOG_WARNING("接收到不是ATA04的数据包");
return;
}
if (inputData[3] != 0x01) {
LOG_WARNING("接收到不是GroundHandling的数据包");
return;
}
if (inputData[4] != 0x00) {
LOG_WARNING("接收到不是输入结构体的数据包!");
return;
}
if (inputData[5] != 0x00) {
LOG_WARNING("接收到不是输入数据包!");
return;
}
size_t size = inputData[6];
size = size << 8 | inputData[7];
if (size != inputData.size()) {
LOG_WARNING("接收到的数据包大小不正确!");
return;
}
d->_ghInputInterface.setDataByUDPPackage(inputData);
}
// void XNATA04DataProcessor::OnAeroInput(const QVariant &data)
// {
// Q_D(XNATA04DataProcessor);
// QByteArray inputData = data.toByteArray();
// // 现在我们知道数据包确实以0b 04 00开头
// if (inputData[0] != 0x0b || inputData[1] != 0x04 || inputData[2] != 0x00
// || inputData[3] != 0x00) {
// LOG_WARNING("ATA04DataProcessor::OnAeroInput: invalid input data");
// return;
// }
// // 读取两个字节的大小字段
// quint16 size = ((quint16)(quint8)inputData[4] << 8) | (quint16)(quint8)inputData[5];
// if (size != inputData.size()) {
// LOG_WARNING(
// "ATA04DataProcessor::OnAeroInput: invalid data size. Expected %1 bytes, got %2 bytes",
// size, inputData.size());
// return;
// }
// // 使用与发送方相同版本的QDataStream读取数据
// QDataStream inputStream(&inputData, QIODevice::ReadOnly);
// inputStream.setByteOrder(QDataStream::LittleEndian);
// inputStream.setVersion(QDataStream::Qt_6_0);
// // 跳过6字节的头
// for (int i = 0; i < 6; i++) {
// char tmp;
// inputStream >> tmp;
// }
// QMutexLocker locker(&d->_aeroInputMutex);
// // 尝试读取数据,并添加异常处理
// try {
// double tmp;
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_alpha_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_alpdot_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_beta_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_press_alt_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_tas_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_mach_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_nx_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_ny_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_nz_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_p_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_q_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_r_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_qbar_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_blcg_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_bscg_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_wlcg_f8(tmp);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_stab_f8(tmp);
// // ail_f8 (10个double)
// std::array<double, 10> ailArray;
// for (int i = 0; i < 10; i++) {
// inputStream >> ailArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_ail_f8(ailArray);
// // elv_f8 (4个double)
// std::array<double, 4> elvArray;
// for (int i = 0; i < 4; i++) {
// inputStream >> elvArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_elv_f8(elvArray);
// // rud_f8 (2个double)
// std::array<double, 2> rudArray;
// for (int i = 0; i < 2; i++) {
// inputStream >> rudArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_rud_f8(rudArray);
// // gear_f8 (7个double)
// std::array<double, 7> gearArray;
// for (int i = 0; i < 7; i++) {
// inputStream >> gearArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_gear_f8(gearArray);
// // flap_f8 (10个double)
// std::array<double, 10> flapArray;
// for (int i = 0; i < 10; i++) {
// inputStream >> flapArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_flap_f8(flapArray);
// // slat_f8 (20个double)
// std::array<double, 20> slatArray;
// for (int i = 0; i < 20; i++) {
// inputStream >> slatArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_slat_f8(slatArray);
// // spl_f8 (20个double)
// std::array<double, 20> splArray;
// for (int i = 0; i < 20; i++) {
// inputStream >> splArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_spl_f8(splArray);
// // tnet_f8 (4个double)
// std::array<double, 4> tnetArray;
// for (int i = 0; i < 4; i++) {
// inputStream >> tnetArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_tnet_f8(tnetArray);
// // kice_f8 (20个double)
// std::array<double, 20> kiceArray;
// for (int i = 0; i < 20; i++) {
// inputStream >> kiceArray[i];
// }
// d->_aeroInput.l_04_i_aerocomac_kice_f8(kiceArray);
// inputStream >> tmp;
// d->_aeroInput.l_04_i_aerocomac_alt_agl_f8(tmp);
// d->_dataWriters["XNSim::ATA04::Aerodynamics_input"]->write(&d->_aeroInput);
// } catch (const std::exception &e) {
// LOG_WARNING("ATA04DataProcessor::OnAeroInput: exception during data parsing: %s", e.what());
// return;
// } catch (...) {
// LOG_WARNING("ATA04DataProcessor::OnAeroInput: unknown exception during data parsing");
// return;
// }
// }
// void XNATA04DataProcessor::OnWbOutput(const XNSim::ATA04::WeightBalance_output &input)
// {
// Q_D(XNATA04DataProcessor);
// QMutexLocker locker(&d->_wbOutputMutex);
// d->_wbOutput = input;
// }
// void XNATA04DataProcessor::OnAeroOutput(const XNSim::ATA04::Aerodynamics_output &input)
// {
// Q_D(XNATA04DataProcessor);
// QMutexLocker locker(&d->_aeroOutputMutex);
// d->_aeroOutput = input;
// }
// void XNATA04DataProcessor::OnAeroHeartbeat(const XNSim::ATA04::Aerodynamics_heartbeat &input)
// {
// Q_D(XNATA04DataProcessor);
// QMutexLocker locker(&d->_aeroHeartbeatMutex);
// d->_aeroHeartbeat = input;
// }
// void XNATA04DataProcessor::OnWbHeartbeat(const XNSim::ATA04::WeightBalance_heartbeat &input)
// {
// Q_D(XNATA04DataProcessor);
// QMutexLocker locker(&d->_wbHeartbeatMutex);
// d->_wbHeartbeat = input;
// }
// void XNATA04DataProcessor::SendUdpTestData()
// {
// Q_D(XNATA04DataProcessor);
// // 创建气动输入(AeroInput)数据包
// QByteArray aeroData;
// QDataStream aeroStream(&aeroData, QIODevice::WriteOnly);
// aeroStream.setByteOrder(QDataStream::LittleEndian);
// aeroStream.setVersion(QDataStream::Qt_6_0);
// // 气动输入数据包头 (0x0b=从外部输入, 0x04=ATA04, 0x00=气动模型, 0x00=输入数据)
// quint8 aeroHeader[6] = {0x0b, 0x04, 0x00, 0x00, 0x00, 0x00}; // 最后两个字节用于大小
// aeroStream << aeroHeader[0] << aeroHeader[1] << aeroHeader[2] << aeroHeader[3] << aeroHeader[4]
// << aeroHeader[5];
// // 气动数据字段
// aeroStream << (double)-2.0; // alpha
// aeroStream << (double)0.0; // alpdot
// aeroStream << (double)0.0; // beta
// aeroStream << (double)10000.0; // press_alt
// aeroStream << (double)360.0; // tas
// aeroStream << (double)0.3; // mach
// aeroStream << (double)0.0; // nx
// aeroStream << (double)0.0; // ny
// aeroStream << (double)1.0; // nz
// aeroStream << (double)0.0; // p
// aeroStream << (double)0.0; // q
// aeroStream << (double)0.0; // r
// aeroStream << (double)110.0; // qbar
// aeroStream << (double)0.0; // blcg
// aeroStream << (double)650.0; // bscg
// aeroStream << (double)7.0; // wlcg
// aeroStream << (double)-2.0; // stab
// // ail_f8 数组需要10个double
// for (int i = 0; i < 10; i++) {
// aeroStream << (double)0.0;
// }
// // elv_f8 数组需要4个double
// for (int i = 0; i < 4; i++) {
// aeroStream << (double)0.0;
// }
// // rud_f8 数组需要2个double
// for (int i = 0; i < 2; i++) {
// aeroStream << (double)0.0;
// }
// // gear_f8 数组需要7个double
// for (int i = 0; i < 7; i++) {
// aeroStream << (double)1.0;
// }
// // flap_f8 数组需要10个double
// for (int i = 0; i < 10; i++) {
// aeroStream << (double)41.5;
// }
// // slat_f8 数组需要20个double
// for (int i = 0; i < 20; i++) {
// aeroStream << (double)20.855;
// }
// // spl_f8 数组需要20个double
// for (int i = 0; i < 20; i++) {
// aeroStream << (double)0.0;
// }
// // tnet_f8 数组需要4个double
// for (int i = 0; i < 4; i++) {
// aeroStream << (double)8000.0;
// }
// // kice_f8 数组需要20个double
// for (int i = 0; i < 20; i++) {
// aeroStream << (double)0.0;
// }
// // alt_agl
// aeroStream << (double)2500.0;
// // 更新数据包大小(使用两个字节)
// quint16 size = aeroData.size();
// aeroData[4] = (size >> 8) & 0xFF; // 高字节
// aeroData[5] = size & 0xFF; // 低字节
// // 创建地面操作输入(GhInput)数据包
// QByteArray ghData;
// QDataStream ghStream(&ghData, QIODevice::WriteOnly);
// ghStream.setByteOrder(QDataStream::LittleEndian);
// ghStream.setVersion(QDataStream::Qt_6_0);
// // 地面操作输入数据包头 (0x0b=从外部输入, 0x04=ATA04, 0x01=地面操作模型, 0x00=输入数据)
// quint8 ghHeader[6] = {0x0b, 0x04, 0x01, 0x00, 0x00, 0x00}; // 最后两个字节用于大小
// ghStream << ghHeader[0] << ghHeader[1] << ghHeader[2] << ghHeader[3] << ghHeader[4]
// << ghHeader[5];
// // 地面操作数据字段
// ghStream << (quint8)0; // frz_l1
// ghStream << (quint8)0; // chocks_l1
// ghStream << (double)8.0; // alt_agl_f8
// ghStream << (quint8)0; // frzflt_l1
// ghStream << (double)0.0; // p_f8
// ghStream << (double)0.0; // q_f8
// ghStream << (double)0.0; // r_f8
// ghStream << (double)50.0; // ug_f8
// ghStream << (double)0.0; // vg_f8
// ghStream << (double)0.0; // wg_f8
// ghStream << (double)0.0; // blcg_f8
// ghStream << (double)649.3; // bscg_f8
// ghStream << (double)10.0; // wlcg_f8
// ghStream << (quint8)0; // pb_active_l1
// ghStream << (double)0.0; // pb_towforce_f8
// // brake_torq_f8 数组 3x2
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 2; j++) {
// ghStream << (double)0.0;
// }
// }
// // gear_f8 数组需要3个double
// for (int i = 0; i < 3; i++) {
// ghStream << (double)1.0;
// }
// // gsteer_f8 数组需要10个double
// for (int i = 0; i < 10; i++) {
// ghStream << (double)0.0;
// }
// // tire_pres_f8 数组 3x2
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 2; j++) {
// if (i == 0) {
// ghStream << (double)98.0; // 98 kpa的胎压
// } else {
// ghStream << (double)140.0; // 140 kpa的胎压
// }
// }
// }
// // 4个double数组
// for (int i = 0; i < 4; i++) {
// ghStream << (double)0.0;
// }
// ghStream << (quint8)0; // onjax_l1
// // contdep_f8 数组需要7个double
// ghStream << (double)1.0;
// for (int i = 1; i < 7; i++) {
// ghStream << (double)0.0;
// }
// ghStream << (double)0.0; // thetag_f8
// ghStream << (double)0.0; // phig_f8
// ghStream << (qint32)0; // rwyrgh_i2
// ghStream << (double)0.0; // rwyhdg_f8
// ghStream << (quint8)0; // reset_braketemp_l1
// ghStream << (quint8)0; // reset_tirepress_l1
// ghStream << (double)16.0; // temp_c_f8
// // brake_temp_f8 数组 3x2
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 2; j++) {
// ghStream << (double)16.0; // 16度的刹车温度
// }
// }
// // tire_tburst_l1 数组 3x2
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 2; j++) {
// ghStream << (char)0;
// }
// }
// // tire_tflat_l1 数组 3x2
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 2; j++) {
// ghStream << (char)0;
// }
// }
// ghStream << (quint8)0; // brk_reset_tpres_l1
// // rcon_ci_f8 数组需要14个double
// ghStream << (double)1.0;
// for (int i = 1; i < 14; i++) {
// ghStream << (double)0.0;
// }
// ghStream << (qint32)2; // gsteer_state_i4
// ghStream << (quint8)1; // trim_active_l1
// ghStream << (double)0.0; // phi_deg_f8
// ghStream << (double)0.0; // theta_deg_f8
// ghStream << (double)0.0; // psi_deg_f8
// ghStream << (quint8)1; // resetint_l1
// // 更新数据包大小(使用两个字节)
// size = ghData.size();
// ghData[4] = (size >> 8) & 0xFF; // 高字节
// ghData[5] = size & 0xFF; // 低字节
// // 创建重量平衡输入(WbInput)数据包
// QByteArray wbData;
// QDataStream wbStream(&wbData, QIODevice::WriteOnly);
// wbStream.setByteOrder(QDataStream::LittleEndian);
// wbStream.setVersion(QDataStream::Qt_6_0);
// // 重量平衡输入数据包头 (0x0b=从外部输入, 0x04=ATA04, 0x02=重量平衡模型, 0x00=输入数据)
// quint8 wbHeader[6] = {0x0b, 0x04, 0x02, 0x00, 0x00, 0x00}; // 最后两个字节用于大小
// wbStream << wbHeader[0] << wbHeader[1] << wbHeader[2] << wbHeader[3] << wbHeader[4]
// << wbHeader[5];
// // 重量平衡数据字段
// wbStream << (double)0.0; // theta_deg_f8
// wbStream << (double)0.0; // phi_deg_f8
// wbStream << (double)0.0; // psi_deg_f8
// wbStream << (quint8)0; // gear_mode_l1
// wbStream << (double)82574.0; // acset_gw_f8 (60000kg飞机重量)
// wbStream << (double)0.1215; // acset_cg_f8 (25%MAC重心位置)
// // acset_tankfuel_f4 数组需要20个float
// for (int i = 0; i < 20; i++) {
// wbStream << (double)(i < 2 ? 4541.0 : 0.0); // 前2个油箱各4541kg
// }
// wbStream << (double)9082.0; // acset_totfuel_f8 (总油量9082kg)
// wbStream << (double)73492.0; // acset_zfw_f8 (零油重73492kg)
// wbStream << (double)0.12; // acset_zfwcg_f8 (零油重重心24%MAC)
// // eng_efsep_l1 数组需要4个char
// for (int i = 0; i < 4; i++) {
// wbStream << (char)0;
// }
// // fuel_f8 数组需要20个double
// for (int i = 0; i < 20; i++) {
// wbStream << (double)(i < 2 ? 4541.0 : 0.0); // 前2个油箱各4541kg
// }
// wbStream << (double)1.0; // gear_avg_f8
// // kice_f8 数组需要20个double
// for (int i = 0; i < 20; i++) {
// wbStream << (double)0.0;
// }
// wbStream << (quint8)1; // bycglim_l1
// wbStream << (quint8)1; // bygwlim_l1
// wbStream << (quint8)0; // frz_l1
// wbStream << (quint8)0; // zcgfrz_l1
// wbStream << (quint8)0; // zcgfrz_grfx_l1
// wbStream << (quint8)0; // ycgfrz_l1
// wbStream << (quint8)0; // inertfrz_l1
// wbStream << (double)80000.0; // potreq_gw_f8
// wbStream << (double)0.2; // potreq_gwcg_f8
// // 更新数据包大小(使用两个字节)
// size = wbData.size();
// wbData[4] = (size >> 8) & 0xFF; // 高字节
// wbData[5] = size & 0xFF; // 低字节
// // 发送测试数据包
// TriggerRTEvent("SendTestUDPData", QVariant::fromValue(aeroData));
// TriggerRTEvent("SendTestUDPData", QVariant::fromValue(ghData));
// TriggerRTEvent("SendTestUDPData", QVariant::fromValue(wbData));
// }