From e98331d16e5cac627bc02db0b79d8537cbff844d Mon Sep 17 00:00:00 2001 From: jinchao <383321154@qq.com> Date: Thu, 22 May 2025 10:54:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BA=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=A8=A1=E5=9E=8B=E7=9A=84=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Release/Scenario/testGRD.xml | 1 + Release/include/XNCore/XNDDSInterface.h | 29 +- XNCore/CMakeLists.txt | 1 + XNCore/XNDDSInterface.cpp | 42 +- XNCore/XNDDSInterface.h | 29 +- XNModels/XNATA04DataProcessor/CMakeLists.txt | 7 - .../XNATA04DataProcessor.cpp | 2420 +++++++---------- .../XNATA04DataProcessor.h | 52 +- .../XNATA04DataProcessor_global.h | 6 +- .../XNATA04DataProcessor_p.h | 42 +- .../XNGroundHandling/XNGroundHandling.cpp | 6 +- .../XNGroundHandlingInterface.cxx | 105 +- .../XNGroundHandlingInterface.hpp | 6 +- 13 files changed, 1219 insertions(+), 1527 deletions(-) diff --git a/Release/Scenario/testGRD.xml b/Release/Scenario/testGRD.xml index aea91ed..412a4cf 100755 --- a/Release/Scenario/testGRD.xml +++ b/Release/Scenario/testGRD.xml @@ -5,5 +5,6 @@ + diff --git a/Release/include/XNCore/XNDDSInterface.h b/Release/include/XNCore/XNDDSInterface.h index 36bccd7..ae49489 100644 --- a/Release/include/XNCore/XNDDSInterface.h +++ b/Release/include/XNCore/XNDDSInterface.h @@ -20,7 +20,7 @@ public: * @brief 初始化 * @param framework: 框架 */ - virtual void Initialize(XNFrameworkPtr framework, uint32_t modelID) = 0; + virtual void Initialize(XNFrameworkPtr framework, uint32_t modelID, uint32_t DDS_type) = 0; /** * @brief 获取该接口的UDP包 @@ -28,6 +28,12 @@ public: */ XNByteArray getUDPPackage(); + /** + * @brief 通过UDP包设置数据 + * @param package: UDP包 + */ + void setDataByUDPPackage(const XNByteArray &package); + /** * @brief 批量获取指定变量的数据 * @param varNames: 变量名列表 @@ -305,18 +311,23 @@ protected: virtual void sendOutData() {} protected: - struct ByteArrayFunc { + struct GetByteArrayFunc { std::function func; size_t size; }; + struct SetByteArrayFunc { + std::function func; + size_t size; + }; + std::unordered_map> getDataFunction; std::unordered_map> setDataFunction; - std::vector getByteArrayFunction; - std::unordered_map> setByteArrayFunction; + std::vector getByteArrayFunction; + std::unordered_map setByteArrayFunction; std::mutex mutex; - uint8_t header[5]{}; // 固定大小的头部 - size_t headerSize = 5; + uint8_t header[8]{0}; // 固定大小的头部 + size_t headerSize = 8; FAST_DDS_MACRO::DataWriter *dataWriter; }; @@ -327,6 +338,6 @@ protected: }; \ getByteArrayFunction.push_back( \ {[this]() { return getByteArray(data.NAME()); }, getTypeSize()}); \ - setByteArrayFunction[#NAME] = [this](XNByteArray byteArray) { \ - setByteArray(data.NAME(), byteArray); \ - } + setByteArrayFunction[#NAME] = { \ + [this](XNByteArray byteArray) { setByteArray(out_data.NAME(), byteArray); }, \ + getTypeSize()}; diff --git a/XNCore/CMakeLists.txt b/XNCore/CMakeLists.txt index 8404cf9..45c95cf 100755 --- a/XNCore/CMakeLists.txt +++ b/XNCore/CMakeLists.txt @@ -64,6 +64,7 @@ add_library(XNCore SHARED XNServiceObject_p.h XNServiceObject.cpp XNDDSInterface.h + XNDDSInterface.cpp ${DDS_XNIDL_SOURCES_CXX} ) diff --git a/XNCore/XNDDSInterface.cpp b/XNCore/XNDDSInterface.cpp index 9b8fbc6..92d8175 100644 --- a/XNCore/XNDDSInterface.cpp +++ b/XNCore/XNDDSInterface.cpp @@ -11,10 +11,8 @@ XNByteArray XNDDSInterface::getUDPPackage() size_t currentPos = 0; // 复制头部 - if (headerSize >= 5) { - result.append(header, 5); - currentPos = 5; - } + result.append(header, headerSize); + currentPos = headerSize; // 复制数据 for (auto func : getByteArrayFunction) { @@ -27,13 +25,45 @@ XNByteArray XNDDSInterface::getUDPPackage() } // 更新包大小 - if (currentPos >= 5) { - result[4] = static_cast(currentPos); + if (currentPos >= 8 && currentPos < MAX_UDP_PACKET_SIZE) { + result[6] = static_cast((currentPos >> 8) & 0xFF); + result[7] = static_cast(currentPos & 0xFF); } return result; } +void XNDDSInterface::setDataByUDPPackage(const XNByteArray &package) +{ + clearOutData(); + if (package.size() < headerSize) { + return; + } + + // 获取包大小 + uint16_t packageSize = (package[6] << 8) | package[7]; + if (packageSize > MAX_UDP_PACKET_SIZE) { + return; + } + + size_t currentPos = 8; + + // 获取数据 + for (auto func : setByteArrayFunction) { + if (currentPos + func.second.size <= packageSize) { + XNByteArray byteArray(func.second.size); + for (size_t i = 0; i < func.second.size; i++) { + byteArray[i] = package[currentPos + i]; + } + func.second.func(byteArray); + currentPos += func.second.size; + } else { + break; + } + } + sendOutData(); +} + std::unordered_map XNDDSInterface::getStringData(std::vector varNames) { diff --git a/XNCore/XNDDSInterface.h b/XNCore/XNDDSInterface.h index 36bccd7..ae49489 100644 --- a/XNCore/XNDDSInterface.h +++ b/XNCore/XNDDSInterface.h @@ -20,7 +20,7 @@ public: * @brief 初始化 * @param framework: 框架 */ - virtual void Initialize(XNFrameworkPtr framework, uint32_t modelID) = 0; + virtual void Initialize(XNFrameworkPtr framework, uint32_t modelID, uint32_t DDS_type) = 0; /** * @brief 获取该接口的UDP包 @@ -28,6 +28,12 @@ public: */ XNByteArray getUDPPackage(); + /** + * @brief 通过UDP包设置数据 + * @param package: UDP包 + */ + void setDataByUDPPackage(const XNByteArray &package); + /** * @brief 批量获取指定变量的数据 * @param varNames: 变量名列表 @@ -305,18 +311,23 @@ protected: virtual void sendOutData() {} protected: - struct ByteArrayFunc { + struct GetByteArrayFunc { std::function func; size_t size; }; + struct SetByteArrayFunc { + std::function func; + size_t size; + }; + std::unordered_map> getDataFunction; std::unordered_map> setDataFunction; - std::vector getByteArrayFunction; - std::unordered_map> setByteArrayFunction; + std::vector getByteArrayFunction; + std::unordered_map setByteArrayFunction; std::mutex mutex; - uint8_t header[5]{}; // 固定大小的头部 - size_t headerSize = 5; + uint8_t header[8]{0}; // 固定大小的头部 + size_t headerSize = 8; FAST_DDS_MACRO::DataWriter *dataWriter; }; @@ -327,6 +338,6 @@ protected: }; \ getByteArrayFunction.push_back( \ {[this]() { return getByteArray(data.NAME()); }, getTypeSize()}); \ - setByteArrayFunction[#NAME] = [this](XNByteArray byteArray) { \ - setByteArray(data.NAME(), byteArray); \ - } + setByteArrayFunction[#NAME] = { \ + [this](XNByteArray byteArray) { setByteArray(out_data.NAME(), byteArray); }, \ + getTypeSize()}; diff --git a/XNModels/XNATA04DataProcessor/CMakeLists.txt b/XNModels/XNATA04DataProcessor/CMakeLists.txt index 2db544b..507ef49 100755 --- a/XNModels/XNATA04DataProcessor/CMakeLists.txt +++ b/XNModels/XNATA04DataProcessor/CMakeLists.txt @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.16) project(XNATA04DataProcessor LANGUAGES CXX) -set(CMAKE_AUTOUIC ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -18,9 +15,6 @@ endif() # 添加 XNCore_PATH 下的 include 目录为包含目录 include_directories(${XNCore_PATH}/include) -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) - add_library(XNATA04DataProcessor SHARED XNATA04DataProcessor_global.h XNATA04DataProcessor.cpp @@ -29,7 +23,6 @@ add_library(XNATA04DataProcessor SHARED ) target_link_libraries(XNATA04DataProcessor PRIVATE - Qt${QT_VERSION_MAJOR}::Core ${XNCore_PATH}/lib/libXNCore.so ${XNCore_PATH}/Models/libXNAerodynamicsInterface.so ${XNCore_PATH}/Models/libXNGroundHandlingInterface.so diff --git a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.cpp b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.cpp index 80902f8..3169166 100755 --- a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.cpp +++ b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.cpp @@ -2,24 +2,11 @@ #include "XNATA04DataProcessor_p.h" #include #include -#include #include -XN_DLL_INITIALIZE(XNATA04DataProcessor) -XN_REGISTER_PARTICIPANT_BEGIN(XNATA04DataProcessor) -XN_PUBLISHTOPIC(XNSim::ATA04::Aerodynamics_input) -XN_PUBLISHTOPIC(XNSim::ATA04::WeightBalance_input) -XN_PUBLISHTOPIC(XNSim::ATA04::GroundHandling_input) -XN_SUBSCRIBETOPIC(XNSim::ATA04::WeightBalance_output, &XNATA04DataProcessor::OnWbOutput) -XN_SUBSCRIBETOPIC(XNSim::ATA04::GroundHandling_output, &XNATA04DataProcessor::OnGhOutput) -XN_SUBSCRIBETOPIC(XNSim::ATA04::Aerodynamics_output, &XNATA04DataProcessor::OnAeroOutput) -XN_SUBSCRIBETOPIC(XNSim::ATA04::Aerodynamics_heartbeat, &XNATA04DataProcessor::OnAeroHeartbeat) -XN_SUBSCRIBETOPIC(XNSim::ATA04::WeightBalance_heartbeat, &XNATA04DataProcessor::OnWbHeartbeat) -XN_SUBSCRIBETOPIC(XNSim::ATA04::GroundHandling_heartbeat, &XNATA04DataProcessor::OnGhHeartbeat) -XN_REGISTER_PARTICIPANT_END(XNATA04DataProcessor) +XN_MODEL_INITIALIZE(XNATA04DataProcessor) -XNATA04DataProcessor::XNATA04DataProcessor(QObject *parent) - : XNModelObject(*new XNATA04DataProcessorPrivate(this), parent) +XNATA04DataProcessor::XNATA04DataProcessor() : XNModelObject(new XNATA04DataProcessorPrivate()) { } @@ -27,1447 +14,1068 @@ XNATA04DataProcessor::~XNATA04DataProcessor() { } -XNATA04DataProcessor::XNATA04DataProcessor(XNATA04DataProcessorPrivate &dd, QObject *parent) - : XNModelObject(dd, parent) +XNATA04DataProcessor::XNATA04DataProcessor(PrivateType *p) : XNModelObject(p) { } -void XNATA04DataProcessor::OnInitialize() +void XNATA04DataProcessor::Initialize() { - Q_D(XNATA04DataProcessor); - XNModelObject::OnInitialize(); + T_D(); + XNModelObject::Initialize(); } -void XNATA04DataProcessor::OnPrepareForExecute() +void XNATA04DataProcessor::PrepareForExecute() { - Q_D(XNATA04DataProcessor); - XNModelObject::OnPrepareForExecute(); - RegisterRTEventHandler("ATA04AeroInput", std::bind(&XNATA04DataProcessor::OnAeroInput, this, - std::placeholders::_1)); - RegisterRTEventHandler( - "ATA04WbInput", std::bind(&XNATA04DataProcessor::OnWbInput, this, std::placeholders::_1)); + 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() { - Q_D(XNATA04DataProcessor); + T_D(); XNModelObject::StepUpdate(); SendUdpData(); - SendUdpTestData(); + //SendUdpTestData(); } void XNATA04DataProcessor::SendUdpData() { - Q_D(XNATA04DataProcessor); - SendAeroOutput(); - SendWbOutput(); + T_D(); + // SendAeroOutput(); + // SendWbOutput(); SendGhOutput(); - SendAeroHeartbeat(); - SendWbHeartbeat(); + // SendAeroHeartbeat(); + // SendWbHeartbeat(); SendGhHeartbeat(); } -void XNATA04DataProcessor::SendAeroOutput() -{ - Q_D(XNATA04DataProcessor); - 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; - } +// 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; // 低字节 +// 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)); -} +// TriggerRTEvent("SendUDPData", QVariant::fromValue(outputData)); +// } void XNATA04DataProcessor::SendGhOutput() { - Q_D(XNATA04DataProcessor); - QMutexLocker locker(&d->_ghOutputMutex); - QByteArray outputData; - QDataStream outputStream(&outputData, QIODevice::WriteOnly); - outputStream.setByteOrder(QDataStream::LittleEndian); - quint8 header[6] = {0x0a, 0x04, 0x01, 0x01, 0x00, 0x00}; // 最后两个字节用于大小 - outputStream << header[0] << header[1] << header[2] << header[3] << header[4] << header[5]; - if (d->_ghOutput.l_04_o_gdcomac_frz_l1()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_frz_l1().value(); - } else { - outputStream << (quint8)0; - } - if (d->_ghOutput.l_04_o_gdcomac_ac_on_ground_l1()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_ac_on_ground_l1().value(); - } else { - outputStream << (quint8)0; - } - if (d->_ghOutput.l_04_o_gdcomac_ac_stationary_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_ac_stationary_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_alt_tire_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_alt_tire_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_zcg_to_tire_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_zcg_to_tire_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_fxb_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_fxb_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_fyb_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_fyb_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_fzb_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_fzb_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_mxb_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_mxb_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_myb_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_myb_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_mzb_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_mzb_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_fygs_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_fygs_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_mzgs_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_mzgs_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_mu_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_mu_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_dstroke_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_dstroke_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_sr_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_sr_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_sy_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_sy_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_sx_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_sx_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_xft_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_xft_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_yft_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_yft_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_zft_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_zft_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_distngrxcg_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_distngrxcg_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_distmgrxcg_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_distmgrxcg_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_distmgrzcg_f8()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_distmgrzcg_f8().value(); - } else { - outputStream << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_tire_vel_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_tire_vel_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_tire_temp_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_tire_temp_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_tire_burst_l1()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_tire_burst_l1().value()[i][j]; - } - } - } else { - outputStream << (quint8)0 << (quint8)0 << (quint8)0 << (quint8)0 << (quint8)0 << (quint8)0; - } - if (d->_ghOutput.l_04_o_gdcomac_wow_l1()) { - outputStream << d->_ghOutput.l_04_o_gdcomac_wow_l1().value(); - } else { - outputStream << (quint8)0; - } - if (d->_ghOutput.l_04_o_gdcomac_utirew_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_utirew_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_vtirew_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_vtirew_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_whl_omega_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_whl_omega_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_dstruc_f8()) { - for (int i = 0; i < 6; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_dstruc_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_nd_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_nd_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_wor_par_f8()) { - for (int i = 0; i < 3; i++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_wor_par_f8().value()[i]; - } - } else { - outputStream << (double)0 << (double)0 << (double)0; - } - if (d->_ghOutput.l_04_o_gdcomac_vczt_f8()) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - outputStream << d->_ghOutput.l_04_o_gdcomac_vczt_f8().value()[i][j]; - } - } - } else { - outputStream << (double)0 << (double)0 << (double)0 << (double)0 << (double)0 << (double)0; - } - // 更新数据包大小(使用两个字节) - auto size = outputData.size(); - outputData[4] = (size >> 8) & 0xFF; // 高字节 - outputData[5] = size & 0xFF; // 低字节 + T_D(); + XNByteArray outputData = d->_ghOutputInterface.getUDPPackage(); + //填写数据方向 + outputData[5] = 0x01; - TriggerRTEvent("SendUDPData", QVariant::fromValue(outputData)); + 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; // 低字节 +// 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)); -} +// 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; // 低字节 +// 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)); -} +// TriggerRTEvent("SendUDPData", QVariant::fromValue(heartbeatData)); +// } void XNATA04DataProcessor::SendGhHeartbeat() { - Q_D(XNATA04DataProcessor); - QMutexLocker locker(&d->_ghHeartbeatMutex); - QByteArray heartbeatData; - QDataStream heartbeatStream(&heartbeatData, QIODevice::WriteOnly); - heartbeatStream.setByteOrder(QDataStream::LittleEndian); - quint8 header[6] = {0x0a, 0x04, 0x01, 0x02, 0x00, 0x00}; // 最后两个字节用于大小 - heartbeatStream << header[0] << header[1] << header[2] << header[3] << header[4] << header[5]; - heartbeatStream << d->_ghHeartbeat.groundhandling_model_heartbeat(); - // 更新数据包大小(使用两个字节) - auto size = heartbeatData.size(); - heartbeatData[4] = (size >> 8) & 0xFF; // 高字节 - heartbeatData[5] = size & 0xFF; // 低字节 + T_D(); + XNByteArray outputData = d->_ghHeartbeatInterface.getUDPPackage(); + //填写数据方向 + outputData[5] = 0x01; - TriggerRTEvent("SendUDPData", QVariant::fromValue(heartbeatData)); + 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; // 低字节 +// 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)); -} +// TriggerRTEvent("SendUDPData", QVariant::fromValue(heartbeatData)); +// } -void XNATA04DataProcessor::OnWbInput(const QVariant &data) +// 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 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 ucarray4; +// for (int i = 0; i < 4; i++) { +// inputStream >> ucarray4[i]; +// } +// d->_wbInput.l_04_i_wbcomac_eng_efsep_l1(ucarray4); +// std::array 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) { - Q_D(XNATA04DataProcessor); - QByteArray inputData = data.toByteArray(); + T_D(); + XNByteArray inputData = std::any_cast(data); // 检查数据包头 - if (inputData[0] != 0x0b || inputData[1] != 0x04 || inputData[2] != 0x02 - || inputData[3] != 0x00) { - LOG_WARNING("ATA04DataProcessor::OnWbInput: invalid input data header"); + if (inputData[0] != 0xa6) { + LOG_WARNING("接收到不是XNSim的数据包!"); return; } - - // 读取两个字节的大小字段 - quint16 size = ((quint16)(quint8)inputData[4] << 8) | (quint16)(quint8)inputData[5]; + 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( - "ATA04DataProcessor::OnWbInput: invalid data size. Expected %d bytes, got %d bytes", - size, inputData.size()); + LOG_WARNING("接收到的数据包大小不正确!"); 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 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 ucarray4; - for (int i = 0; i < 4; i++) { - inputStream >> ucarray4[i]; - } - d->_wbInput.l_04_i_wbcomac_eng_efsep_l1(ucarray4); - std::array 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); + d->_ghInputInterface.setDataByUDPPackage(inputData); } -void XNATA04DataProcessor::OnGhInput(const QVariant &data) -{ - Q_D(XNATA04DataProcessor); - QByteArray inputData = data.toByteArray(); - - // 检查数据包头 - if (inputData[0] != 0x0b || inputData[1] != 0x04 || inputData[2] != 0x01 - || inputData[3] != 0x00) { - LOG_WARNING("ATA04DataProcessor::OnGhInput: invalid input data header"); - return; - } - - // 读取两个字节的大小字段 - quint16 size = ((quint16)(quint8)inputData[4] << 8) | (quint16)(quint8)inputData[5]; - if (size != inputData.size()) { - LOG_WARNING( - "ATA04DataProcessor::OnGhInput: 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->_ghInputMutex); - quint8 uchartmp; - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_frz_l1(uchartmp); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_chocks_l1(uchartmp); - double doubleTmp; - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_alt_agl_f8(doubleTmp); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_frzflt_l1(uchartmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_p_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_q_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_r_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_ug_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_vg_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_wg_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_blcg_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_bscg_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_wlcg_f8(doubleTmp); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_pb_active_l1(uchartmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_pb_towforce_f8(doubleTmp); - std::array, 3> tmpArray32; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - inputStream >> tmpArray32[i][j]; - } - } - d->_ghInput.l_04_i_gdcomac_brake_torq_f8(tmpArray32); - std::array tmpArray3; - for (int i = 0; i < 3; i++) { - inputStream >> tmpArray3[i]; - } - d->_ghInput.l_04_i_gdcomac_gear_f8(tmpArray3); - for (int i = 0; i < 3; i++) { - inputStream >> tmpArray3[i]; - } - std::array tmpArray10; - for (int i = 0; i < 10; i++) { - inputStream >> tmpArray10[i]; - } - d->_ghInput.l_04_i_gdcomac_gsteer_f8(tmpArray10); - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - inputStream >> tmpArray32[i][j]; - } - } - d->_ghInput.l_04_i_gdcomac_tire_pres_f8(tmpArray32); - std::array tmpArray4; - for (int i = 0; i < 4; i++) { - inputStream >> tmpArray4[i]; - } - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_onjax_l1(uchartmp); - std::array tmpArray7; - for (int i = 0; i < 7; i++) { - inputStream >> tmpArray7[i]; - } - d->_ghInput.l_04_i_gdcomac_contdep_f8(tmpArray7); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_thetag_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_phig_f8(doubleTmp); - qint32 intTmp; - inputStream >> intTmp; - d->_ghInput.l_04_i_gdcomac_rwyrgh_i2(intTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_rwyhdg_f8(doubleTmp); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_reset_braketemp_l1(uchartmp); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_reset_tirepress_l1(uchartmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_temp_c_f8(doubleTmp); - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - inputStream >> tmpArray32[i][j]; - } - } - d->_ghInput.l_04_i_gdcomac_brake_temp_f8(tmpArray32); - std::array, 3> tmpArray322; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - inputStream >> tmpArray322[i][j]; - } - } - d->_ghInput.l_04_i_gdcomac_tire_tburst_l1(tmpArray322); - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - inputStream >> tmpArray322[i][j]; - } - } - d->_ghInput.l_04_i_gdcomac_tire_tflat_l1(tmpArray322); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_brk_reset_tpres_l1(uchartmp); - std::array tmpArray14; - for (int i = 0; i < 14; i++) { - inputStream >> tmpArray14[i]; - } - d->_ghInput.l_04_i_gdcomac_rcon_ci_f8(tmpArray14); - inputStream >> intTmp; - d->_ghInput.l_04_i_gdcomac_gsteer_state_i4(intTmp); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_trim_active_l1(uchartmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_phi_deg_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_theta_deg_f8(doubleTmp); - inputStream >> doubleTmp; - d->_ghInput.l_04_i_gdcomac_psi_deg_f8(doubleTmp); - inputStream >> uchartmp; - d->_ghInput.l_04_i_gdcomac_resetint_l1(uchartmp); - d->_dataWriters["XNSim::ATA04::GroundHandling_input"]->write(&d->_ghInput); -} - -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 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 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 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 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 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 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 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 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 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::OnGhOutput(const XNSim::ATA04::GroundHandling_output &input) -{ - Q_D(XNATA04DataProcessor); - QMutexLocker locker(&d->_ghOutputMutex); - d->_ghOutput = 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::OnGhHeartbeat(const XNSim::ATA04::GroundHandling_heartbeat &input) -{ - Q_D(XNATA04DataProcessor); - QMutexLocker locker(&d->_ghHeartbeatMutex); - d->_ghHeartbeat = 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)); -} +// 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 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 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 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 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 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 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 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 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 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)); +// } diff --git a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.h b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.h index 2455ac5..53e26fc 100755 --- a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.h +++ b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor.h @@ -1,66 +1,50 @@ #pragma once #include "XNATA04DataProcessor_global.h" #include -#include "../XNAerodynamics/XNAerodynamicsInterface/XNAerodynamicsPubSubTypes.hpp" -#include "../XNWeightBalance/XNWeightBalanceInterface/XNWeightBalancePubSubTypes.hpp" -#include "../XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingPubSubTypes.hpp" -#include +// #include "../XNAerodynamics/XNAerodynamicsInterface/XNAerodynamicsPubSubTypes.hpp" +// #include "../XNWeightBalance/XNWeightBalanceInterface/XNWeightBalancePubSubTypes.hpp" class XNATA04DataProcessorPrivate; class XNATA04DATAPROCESSOR_EXPORT XNATA04DataProcessor : public XNModelObject { - Q_OBJECT - Q_DISABLE_COPY(XNATA04DataProcessor) - Q_DECLARE_PRIVATE(XNATA04DataProcessor) - XN_DECLARE_DDS() + XN_METATYPE(XNATA04DataProcessor, XNModelObject) + XN_DECLARE_PRIVATE(XNATA04DataProcessor) public: - explicit XNATA04DataProcessor(QObject *parent = nullptr); + XNATA04DataProcessor(); virtual ~XNATA04DataProcessor(); protected: - XNATA04DataProcessor(XNATA04DataProcessorPrivate &dd, QObject *parent = nullptr); + XNATA04DataProcessor(PrivateType *p); -public slots: - virtual void OnInitialize() override; - virtual void OnPrepareForExecute() override; +public: + virtual void Initialize() override; + virtual void PrepareForExecute() override; public: virtual void StepUpdate() override; private: - void OnWbOutput(const XNSim::ATA04::WeightBalance_output &output); + // void OnAeroInput(const QVariant &data); - void OnGhOutput(const XNSim::ATA04::GroundHandling_output &output); + // void OnWbInput(const QVariant &data); - void OnAeroOutput(const XNSim::ATA04::Aerodynamics_output &output); - - void OnAeroHeartbeat(const XNSim::ATA04::Aerodynamics_heartbeat &heartbeat); - - void OnWbHeartbeat(const XNSim::ATA04::WeightBalance_heartbeat &heartbeat); - - void OnGhHeartbeat(const XNSim::ATA04::GroundHandling_heartbeat &heartbeat); - - void OnAeroInput(const QVariant &data); - - void OnWbInput(const QVariant &data); - - void OnGhInput(const QVariant &data); + void OnGhInput(const std::any &data); void SendUdpData(); - void SendAeroOutput(); + // void SendAeroOutput(); - void SendWbOutput(); + // void SendWbOutput(); void SendGhOutput(); - void SendAeroHeartbeat(); + // void SendAeroHeartbeat(); - void SendWbHeartbeat(); + // void SendWbHeartbeat(); void SendGhHeartbeat(); - void SendUdpTestData(); + //void SendUdpTestData(); }; -Q_DECLARE_METATYPE(XNATA04DataProcessor) +XNCLASS_PTR_DECLARE(XNATA04DataProcessor) diff --git a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_global.h b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_global.h index 5459522..20f91ed 100755 --- a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_global.h +++ b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_global.h @@ -1,12 +1,10 @@ #ifndef XNATA04DATAPROCESSOR_GLOBAL_H #define XNATA04DATAPROCESSOR_GLOBAL_H -#include - #if defined(XNATA04DATAPROCESSOR_LIBRARY) -# define XNATA04DATAPROCESSOR_EXPORT Q_DECL_EXPORT +# define XNATA04DATAPROCESSOR_EXPORT __attribute__((visibility("default"))) #else -# define XNATA04DATAPROCESSOR_EXPORT Q_DECL_IMPORT +# define XNATA04DATAPROCESSOR_EXPORT __attribute__((visibility("default"))) #endif #endif // XNATA04DATAPROCESSOR_GLOBAL_H diff --git a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_p.h b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_p.h index 6645e43..c06ce6b 100755 --- a/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_p.h +++ b/XNModels/XNATA04DataProcessor/XNATA04DataProcessor_p.h @@ -1,30 +1,22 @@ #pragma once #include -#include +#include "../XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.hpp" -class XNATA04DataProcessorPrivate : public XNModelObjectPrivate -{ -public: - Q_DECLARE_PUBLIC(XNATA04DataProcessor) +struct XNATA04DataProcessorPrivate : public XNModelObjectPrivate { + // XNSim::C909::ATA04::Aerodynamics_input _aeroInput; + // XNSim::C909::ATA04::Aerodynamics_output _aeroOutput; + // XNSim::C909::ATA04::WeightBalance_input _wbInput; + // XNSim::C909::ATA04::WeightBalance_output _wbOutput; + XNSim::C909::ATA04::GroundHandling_input _ghInput; + XNSim::C909::ATA04::GroundHandling_output _ghOutput; + // XNSim::C909::ATA04::Aerodynamics_heartbeat _aeroHeartbeat; + // XNSim::C909::ATA04::WeightBalance_heartbeat _wbHeartbeat; + XNSim::C909::ATA04::GroundHandling_heartbeat _ghHeartbeat; - XNATA04DataProcessorPrivate(XNATA04DataProcessor *q) : XNModelObjectPrivate(q) {} - - XNSim::ATA04::Aerodynamics_input _aeroInput; - XNSim::ATA04::Aerodynamics_output _aeroOutput; - XNSim::ATA04::WeightBalance_input _wbInput; - XNSim::ATA04::WeightBalance_output _wbOutput; - XNSim::ATA04::GroundHandling_input _ghInput; - XNSim::ATA04::GroundHandling_output _ghOutput; - XNSim::ATA04::Aerodynamics_heartbeat _aeroHeartbeat; - XNSim::ATA04::WeightBalance_heartbeat _wbHeartbeat; - XNSim::ATA04::GroundHandling_heartbeat _ghHeartbeat; - QMutex _wbOutputMutex; - QMutex _ghOutputMutex; - QMutex _aeroOutputMutex; - QMutex _aeroHeartbeatMutex; - QMutex _wbHeartbeatMutex; - QMutex _ghHeartbeatMutex; - QMutex _aeroInputMutex; - QMutex _wbInputMutex; - QMutex _ghInputMutex; + XNSim::C909::ATA04::GroundHandling_input_Interface _ghInputInterface; + XNSim::C909::ATA04::GroundHandling_output_Interface _ghOutputInterface; + XNSim::C909::ATA04::GroundHandling_heartbeat_Interface _ghHeartbeatInterface; + std::mutex _ghOutputMutex; + std::mutex _ghHeartbeatMutex; + std::mutex _ghInputMutex; }; diff --git a/XNModels/XNGroundHandling/XNGroundHandling/XNGroundHandling.cpp b/XNModels/XNGroundHandling/XNGroundHandling/XNGroundHandling.cpp index a06d5b5..c6f98ca 100755 --- a/XNModels/XNGroundHandling/XNGroundHandling/XNGroundHandling.cpp +++ b/XNModels/XNGroundHandling/XNGroundHandling/XNGroundHandling.cpp @@ -111,9 +111,9 @@ void XNGroundHandling::PrepareForExecute() for (int i = 0; i < 3; i++) { d->_data.output_ground->l_04_o_gdcomac_vczt_f8[i] = new double[2]; } - d->_inputInterface.Initialize(GetFramework(), GetUniqueId()); - d->_outputInterface.Initialize(GetFramework(), GetUniqueId()); - d->_heartbeatInterface.Initialize(GetFramework(), GetUniqueId()); + d->_inputInterface.Initialize(GetFramework(), GetUniqueId(), 1); + d->_outputInterface.Initialize(GetFramework(), GetUniqueId(), 2); + d->_heartbeatInterface.Initialize(GetFramework(), GetUniqueId(), 2); } void XNGroundHandling::StepUpdate() diff --git a/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.cxx b/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.cxx index 5d054db..fd46d08 100755 --- a/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.cxx +++ b/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.cxx @@ -43,24 +43,46 @@ GroundHandling_input_Interface::GroundHandling_input_Interface() MAP_DATA_FUNC(l_04_i_gdcomac_theta_deg_f8); MAP_DATA_FUNC(l_04_i_gdcomac_psi_deg_f8); MAP_DATA_FUNC(l_04_i_gdcomac_resetint_l1); + this->header[0] = 0xa6; // XNSim头,0xa6 + this->header[1] = 0xc0; // 机型头,0xc0表示C909 + this->header[2] = 0x04; // 章节头,0x04表示ATA04 + this->header[3] = 0x01; // 模型头,0x01表示GroundHandling + this->header[4] = 0x00; // 结构体头,0x00表示输入结构体 + this->header[5] = 0x00; // 数据方向,0x00表示外部输入 + this->header[6] = 0x00; // 数据大小 + this->header[7] = 0x00; // 数据大小 } GroundHandling_input_Interface::~GroundHandling_input_Interface() { } -void GroundHandling_input_Interface::Initialize(XNFrameworkPtr framework, uint32_t modelId) +void GroundHandling_input_Interface::Initialize(XNFrameworkPtr framework, uint32_t modelId, + uint32_t DDS_type) { auto ddsManager = framework->GetDDSManager(); if (!ddsManager) { LOG_ERROR("DDSManager is nullptr"); return; } - dataWriter = ddsManager->RegisterPublisher( - "XNSim::C909::ATA04::GroundHandling_input", modelId); - ddsManager->RegisterSubscriber( - "XNSim::C909::ATA04::GroundHandling_input", modelId, - std::bind(&GroundHandling_input_Interface::inputDataListener, this, std::placeholders::_1)); + if (DDS_type == 0) { // 读取与发送都进行 + dataWriter = + ddsManager->RegisterPublisher( + "XNSim::C909::ATA04::GroundHandling_input", modelId); + ddsManager->RegisterSubscriber( + "XNSim::C909::ATA04::GroundHandling_input", modelId, + std::bind(&GroundHandling_input_Interface::inputDataListener, this, + std::placeholders::_1)); + } else if (DDS_type == 1) { // 只读取 + ddsManager->RegisterSubscriber( + "XNSim::C909::ATA04::GroundHandling_input", modelId, + std::bind(&GroundHandling_input_Interface::inputDataListener, this, + std::placeholders::_1)); + } else if (DDS_type == 2) { // 只发送 + dataWriter = + ddsManager->RegisterPublisher( + "XNSim::C909::ATA04::GroundHandling_input", modelId); + } } void GroundHandling_input_Interface::clearOutData() @@ -116,25 +138,46 @@ GroundHandling_output_Interface::GroundHandling_output_Interface() MAP_DATA_FUNC(l_04_o_gdcomac_wor_par_f8); MAP_DATA_FUNC(l_04_o_gdcomac_nd_f8); MAP_DATA_FUNC(l_04_o_gdcomac_vczt_f8); + this->header[0] = 0xa6; // XNSim头,0xa6 + this->header[1] = 0xc0; // 机型头,0xc0表示C909 + this->header[2] = 0x04; // 章节头,0x04表示ATA04 + this->header[3] = 0x01; // 模型头,0x01表示GroundHandling + this->header[4] = 0x01; // 结构体头,0x01表示输出结构体 + this->header[5] = 0x00; // 数据方向,0x00表示外部输入 + this->header[6] = 0x00; // 数据大小 + this->header[7] = 0x00; // 数据大小 } GroundHandling_output_Interface::~GroundHandling_output_Interface() { } -void GroundHandling_output_Interface::Initialize(XNFrameworkPtr framework, uint32_t modelId) +void GroundHandling_output_Interface::Initialize(XNFrameworkPtr framework, uint32_t modelId, + uint32_t DDS_type) { auto ddsManager = framework->GetDDSManager(); if (!ddsManager) { LOG_ERROR("DDSManager is nullptr"); return; } - dataWriter = ddsManager->RegisterPublisher( - "XNSim::C909::ATA04::GroundHandling_output", modelId); - ddsManager->RegisterSubscriber( - "XNSim::C909::ATA04::GroundHandling_output", modelId, - std::bind(&GroundHandling_output_Interface::outputDataListener, this, - std::placeholders::_1)); + if (DDS_type == 0) { // 读取与发送都进行 + dataWriter = + ddsManager->RegisterPublisher( + "XNSim::C909::ATA04::GroundHandling_output", modelId); + ddsManager->RegisterSubscriber( + "XNSim::C909::ATA04::GroundHandling_output", modelId, + std::bind(&GroundHandling_output_Interface::outputDataListener, this, + std::placeholders::_1)); + } else if (DDS_type == 1) { // 只读取 + ddsManager->RegisterSubscriber( + "XNSim::C909::ATA04::GroundHandling_output", modelId, + std::bind(&GroundHandling_output_Interface::outputDataListener, this, + std::placeholders::_1)); + } else if (DDS_type == 2) { // 只发送 + dataWriter = + ddsManager->RegisterPublisher( + "XNSim::C909::ATA04::GroundHandling_output", modelId); + } } void GroundHandling_output_Interface::clearOutData() @@ -156,26 +199,46 @@ void GroundHandling_output_Interface::outputDataListener( GroundHandling_heartbeat_Interface::GroundHandling_heartbeat_Interface() { MAP_DATA_FUNC(groundhandling_model_heartbeat); + this->header[0] = 0xa6; // XNSim头,0xa6 + this->header[1] = 0xc0; // 机型头,0xc0表示C909 + this->header[2] = 0x04; // 章节头,0x04表示ATA04 + this->header[3] = 0x01; // 模型头,0x01表示GroundHandling + this->header[4] = 0x02; // 结构体头,0x02表示心跳结构体 + this->header[5] = 0x00; // 数据方向,0x00表示外部输入 + this->header[6] = 0x00; // 数据大小 + this->header[7] = 0x00; // 数据大小 } GroundHandling_heartbeat_Interface::~GroundHandling_heartbeat_Interface() { } -void GroundHandling_heartbeat_Interface::Initialize(XNFrameworkPtr framework, uint32_t modelId) +void GroundHandling_heartbeat_Interface::Initialize(XNFrameworkPtr framework, uint32_t modelId, + uint32_t DDS_type) { auto ddsManager = framework->GetDDSManager(); if (!ddsManager) { LOG_ERROR("DDSManager is nullptr"); return; } - dataWriter = - ddsManager->RegisterPublisher( - "XNSim::C909::ATA04::GroundHandling_heartbeat", modelId); - ddsManager->RegisterSubscriber( - "XNSim::C909::ATA04::GroundHandling_heartbeat", modelId, - std::bind(&GroundHandling_heartbeat_Interface::heartbeatListener, this, - std::placeholders::_1)); + if (DDS_type == 0) { // 读取与发送都进行 + dataWriter = + ddsManager->RegisterPublisher( + "XNSim::C909::ATA04::GroundHandling_heartbeat", modelId); + ddsManager->RegisterSubscriber( + "XNSim::C909::ATA04::GroundHandling_heartbeat", modelId, + std::bind(&GroundHandling_heartbeat_Interface::heartbeatListener, this, + std::placeholders::_1)); + } else if (DDS_type == 1) { // 只读取 + ddsManager->RegisterSubscriber( + "XNSim::C909::ATA04::GroundHandling_heartbeat", modelId, + std::bind(&GroundHandling_heartbeat_Interface::heartbeatListener, this, + std::placeholders::_1)); + } else if (DDS_type == 2) { // 只发送 + dataWriter = + ddsManager->RegisterPublisher( + "XNSim::C909::ATA04::GroundHandling_heartbeat", modelId); + } } void GroundHandling_heartbeat_Interface::clearOutData() diff --git a/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.hpp b/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.hpp index bc82c9e..7a17cc9 100755 --- a/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.hpp +++ b/XNModels/XNGroundHandling/XNGroundHandlingInterface/XNGroundHandlingInterface.hpp @@ -10,7 +10,7 @@ public: GroundHandling_input_Interface(); virtual ~GroundHandling_input_Interface(); - virtual void Initialize(XNFrameworkPtr framework, uint32_t modelId) override; + virtual void Initialize(XNFrameworkPtr framework, uint32_t modelId, uint32_t DDS_type) override; virtual void clearOutData() override; virtual void sendOutData() override; @@ -145,7 +145,7 @@ class GroundHandling_output_Interface final : public XNDDSInterface public: GroundHandling_output_Interface(); virtual ~GroundHandling_output_Interface(); - virtual void Initialize(XNFrameworkPtr framework, uint32_t modelId) override; + virtual void Initialize(XNFrameworkPtr framework, uint32_t modelId, uint32_t DDS_type) override; void outputDataListener(const XNSim::C909::ATA04::GroundHandling_output &output); virtual void clearOutData() override; virtual void sendOutData() override; @@ -263,7 +263,7 @@ class GroundHandling_heartbeat_Interface final : public XNDDSInterface public: GroundHandling_heartbeat_Interface(); virtual ~GroundHandling_heartbeat_Interface(); - virtual void Initialize(XNFrameworkPtr framework, uint32_t modelId) override; + virtual void Initialize(XNFrameworkPtr framework, uint32_t modelId, uint32_t DDS_type) override; void heartbeatListener(const XNSim::C909::ATA04::GroundHandling_heartbeat &heartbeat); virtual void clearOutData() override; virtual void sendOutData() override;