#include "XNWeightBalance.h" #include "XNWeightBalance_p.h" #include #include #include XN_DLL_INITIALIZE(XNWeightBalance) XN_REGISTER_PARTICIPANT_BEGIN(XNWeightBalance) XN_PUBLISHTOPIC(XNSim::ATA04::WeightBalance_output) XN_PUBLISHTOPIC(XNSim::ATA04::WeightBalance_heartbeat) XN_SUBSCRIBETOPIC(XNSim::ATA04::WeightBalance_input, &XNWeightBalance::OnInput) XN_REGISTER_PARTICIPANT_END(XNWeightBalance) XNWeightBalance::XNWeightBalance(QObject *parent) : XNModelObject(*new XNWeightBalancePrivate(this), parent) { } XNWeightBalance::~XNWeightBalance() { Q_D(XNWeightBalance); // 释放输入数组内存 if (d->_data.input_weight) { delete[] d->_data.input_weight->l_04_i_wbcomac_acset_tankfuel_f4; delete[] d->_data.input_weight->l_04_i_wbcomac_eng_efsep_l1; delete[] d->_data.input_weight->l_04_i_wbcomac_fuel_f8; delete[] d->_data.input_weight->l_04_i_wbcomac_kice_f8; delete d->_data.input_weight; } // 释放输出数组内存 if (d->_data.output_weight) { delete[] d->_data.output_weight->l_04_o_wbcomac_fuel_cmd_f8; delete[] d->_data.output_weight->l_04_o_wbcomac_ice_eng_f8; delete d->_data.output_weight; } } XNWeightBalance::XNWeightBalance(XNWeightBalancePrivate &dd, QObject *parent) : XNModelObject(dd, parent) { } void XNWeightBalance::OnInitialize() { Q_D(XNWeightBalance); XNModelObject::OnInitialize(); if (d->_dynamicLib) { d->_fun = reinterpret_cast( d->_dynamicLib->resolve("_Z28SACSCWeightBalanceEntryPointP20ComacDataStructure_S")); if (!d->_fun) { LOG_WARNING("Failed to resolve function SACSCWeightBalanceEntryPoint"); } } //add other initial code here } void XNWeightBalance::OnPrepareForExecute() { Q_D(XNWeightBalance); XNModelObject::OnPrepareForExecute(); //add your initial data code here d->_data.input_weight = new input_weight_S(); d->_data.input_weight->l_04_i_wbcomac_acset_tankfuel_f4 = new float[20]; d->_data.input_weight->l_04_i_wbcomac_eng_efsep_l1 = new unsigned char[4]; d->_data.input_weight->l_04_i_wbcomac_fuel_f8 = new double[20]; d->_data.input_weight->l_04_i_wbcomac_kice_f8 = new double[20]; d->_data.output_weight = new output_weight_S(); d->_data.output_weight->l_04_o_wbcomac_fuel_cmd_f8 = new double[20]; d->_data.output_weight->l_04_o_wbcomac_ice_eng_f8 = new double[4]; } void XNWeightBalance::StepUpdate() { Q_D(XNWeightBalance); XNModelObject::StepUpdate(); if (d->_fun) { QMutexLocker locker(&d->_mutex); d->_fun(&d->_data); } OnOutput(); } void XNWeightBalance::OnInput(const XNSim::ATA04::WeightBalance_input &input) { Q_D(XNWeightBalance); QMutexLocker locker(&d->_mutex); if (input.l_04_i_wbcomac_theta_deg_f8()) { d->_data.input_weight->l_04_i_wbcomac_theta_deg_f8 = input.l_04_i_wbcomac_theta_deg_f8().value(); } if (input.l_04_i_wbcomac_gear_mode_l1()) { d->_data.input_weight->l_04_i_wbcomac_gear_mode_l1 = input.l_04_i_wbcomac_gear_mode_l1().value(); } if (input.l_04_i_wbcomac_acset_gw_f8()) { d->_data.input_weight->l_04_i_wbcomac_acset_gw_f8 = input.l_04_i_wbcomac_acset_gw_f8().value(); } if (input.l_04_i_wbcomac_acset_cg_f8()) { d->_data.input_weight->l_04_i_wbcomac_acset_cg_f8 = input.l_04_i_wbcomac_acset_cg_f8().value(); } if (input.l_04_i_wbcomac_acset_tankfuel_f4()) { for (int i = 0; i < 20; i++) { d->_data.input_weight->l_04_i_wbcomac_acset_tankfuel_f4[i] = input.l_04_i_wbcomac_acset_tankfuel_f4().value()[i]; } } if (input.l_04_i_wbcomac_acset_totfuel_f8()) { d->_data.input_weight->l_04_i_wbcomac_acset_totfuel_f8 = input.l_04_i_wbcomac_acset_totfuel_f8().value(); } if (input.l_04_i_wbcomac_acset_zfw_f8()) { d->_data.input_weight->l_04_i_wbcomac_acset_zfw_f8 = input.l_04_i_wbcomac_acset_zfw_f8().value(); } if (input.l_04_i_wbcomac_acset_zfwcg_f8()) { d->_data.input_weight->l_04_i_wbcomac_acset_zfwcg_f8 = input.l_04_i_wbcomac_acset_zfwcg_f8().value(); } if (input.l_04_i_wbcomac_eng_efsep_l1()) { for (int i = 0; i < 4; i++) { d->_data.input_weight->l_04_i_wbcomac_eng_efsep_l1[i] = input.l_04_i_wbcomac_eng_efsep_l1().value()[i]; } } if (input.l_04_i_wbcomac_fuel_f8()) { for (int i = 0; i < 20; i++) { d->_data.input_weight->l_04_i_wbcomac_fuel_f8[i] = input.l_04_i_wbcomac_fuel_f8().value()[i]; } } if (input.l_04_i_wbcomac_gear_avg_f8()) { d->_data.input_weight->l_04_i_wbcomac_gear_avg_f8 = input.l_04_i_wbcomac_gear_avg_f8().value(); } if (input.l_04_i_wbcomac_kice_f8()) { for (int i = 0; i < 20; i++) { d->_data.input_weight->l_04_i_wbcomac_kice_f8[i] = input.l_04_i_wbcomac_kice_f8().value()[i]; } } if (input.l_04_i_wbcomac_bycglim_l1()) { d->_data.input_weight->l_04_i_wbcomac_bycglim_l1 = input.l_04_i_wbcomac_bycglim_l1().value(); } if (input.l_04_i_wbcomac_bygwlim_l1()) { d->_data.input_weight->l_04_i_wbcomac_bygwlim_l1 = input.l_04_i_wbcomac_bygwlim_l1().value(); } if (input.l_04_i_wbcomac_frz_l1()) { d->_data.input_weight->l_04_i_wbcomac_frz_l1 = input.l_04_i_wbcomac_frz_l1().value(); } if (input.l_04_i_wbcomac_zcgfrz_l1()) { d->_data.input_weight->l_04_i_wbcomac_zcgfrz_l1 = input.l_04_i_wbcomac_zcgfrz_l1().value(); } if (input.l_04_i_wbcomac_zcgfrz_grfx_l1()) { d->_data.input_weight->l_04_i_wbcomac_zcgfrz_grfx_l1 = input.l_04_i_wbcomac_zcgfrz_grfx_l1().value(); } if (input.l_04_i_wbcomac_ycgfrz_l1()) { d->_data.input_weight->l_04_i_wbcomac_ycgfrz_l1 = input.l_04_i_wbcomac_ycgfrz_l1().value(); } if (input.l_04_i_wbcomac_inertfrz_l1()) { d->_data.input_weight->l_04_i_wbcomac_inertfrz_l1 = input.l_04_i_wbcomac_inertfrz_l1().value(); } if (input.l_04_i_wbcomac_potreq_gw_f8()) { d->_data.input_weight->l_04_i_wbcomac_potreq_gw_f8 = input.l_04_i_wbcomac_potreq_gw_f8().value(); } if (input.l_04_i_wbcomac_potreq_gwcg_f8()) { d->_data.input_weight->l_04_i_wbcomac_potreq_gwcg_f8 = input.l_04_i_wbcomac_potreq_gwcg_f8().value(); } if (input.l_04_i_wbcomac_phi_deg_f8()) { d->_data.input_weight->l_04_i_wbcomac_phi_deg_f8 = input.l_04_i_wbcomac_phi_deg_f8().value(); } if (input.l_04_i_wbcomac_psi_deg_f8()) { d->_data.input_weight->l_04_i_wbcomac_psi_deg_f8 = input.l_04_i_wbcomac_psi_deg_f8().value(); } } void XNWeightBalance::OnOutput() { Q_D(XNWeightBalance); QMutexLocker locker(&d->_mutex); //DDS心跳 XNSim::ATA04::WeightBalance_heartbeat heartbeat; heartbeat.weightbody_model_heartbeat(d->_data.weightbody_model_heartbeat); d->_dataWriters["XNSim::ATA04::WeightBalance_heartbeat"]->write(&heartbeat); //DDS数据发布 XNSim::ATA04::WeightBalance_output output; output.l_04_o_wbcomac_gw_f4(d->_data.output_weight->l_04_o_wbcomac_gw_f4); output.l_04_o_wbcomac_cg_f4(d->_data.output_weight->l_04_o_wbcomac_cg_f4); output.l_04_o_wbcomac_xcg_f8(d->_data.output_weight->l_04_o_wbcomac_xcg_f8); output.l_04_o_wbcomac_blcg_f8(d->_data.output_weight->l_04_o_wbcomac_blcg_f8); output.l_04_o_wbcomac_bscg_f8(d->_data.output_weight->l_04_o_wbcomac_bscg_f8); output.l_04_o_wbcomac_wlcg_f8(d->_data.output_weight->l_04_o_wbcomac_wlcg_f8); output.l_04_o_wbcomac_ixx_f8(d->_data.output_weight->l_04_o_wbcomac_ixx_f8); output.l_04_o_wbcomac_iyy_f8(d->_data.output_weight->l_04_o_wbcomac_iyy_f8); output.l_04_o_wbcomac_izz_f8(d->_data.output_weight->l_04_o_wbcomac_izz_f8); output.l_04_o_wbcomac_ixy_f8(d->_data.output_weight->l_04_o_wbcomac_ixy_f8); output.l_04_o_wbcomac_ixz_f8(d->_data.output_weight->l_04_o_wbcomac_ixz_f8); output.l_04_o_wbcomac_iyz_f8(d->_data.output_weight->l_04_o_wbcomac_iyz_f8); output.l_04_o_wbcomac_zfw_f4(d->_data.output_weight->l_04_o_wbcomac_zfw_f4); output.l_04_o_wbcomac_zfwcg_f4(d->_data.output_weight->l_04_o_wbcomac_zfwcg_f4); output.l_04_o_wbcomac_zfw_blcg_f4(d->_data.output_weight->l_04_o_wbcomac_zfw_blcg_f4); output.l_04_o_wbcomac_zfw_wlcg_f4(d->_data.output_weight->l_04_o_wbcomac_zfw_wlcg_f4); std::array l_04_o_wbcomac_fuel_cmd_f8; for (int i = 0; i < 3; i++) { l_04_o_wbcomac_fuel_cmd_f8[i] = d->_data.output_weight->l_04_o_wbcomac_fuel_cmd_f8[i]; } output.l_04_o_wbcomac_fuel_cmd_f8(l_04_o_wbcomac_fuel_cmd_f8); output.l_04_o_wbcomac_fuel_mode_i4(d->_data.output_weight->l_04_o_wbcomac_fuel_mode_i4); output.l_04_o_wbcomac_fuel_ixx_f8(d->_data.output_weight->l_04_o_wbcomac_fuel_ixx_f8); output.l_04_o_wbcomac_fuel_ixy_f8(d->_data.output_weight->l_04_o_wbcomac_fuel_ixy_f8); output.l_04_o_wbcomac_fuel_ixz_f8(d->_data.output_weight->l_04_o_wbcomac_fuel_ixz_f8); output.l_04_o_wbcomac_fuel_iyy_f8(d->_data.output_weight->l_04_o_wbcomac_fuel_iyy_f8); output.l_04_o_wbcomac_fuel_iyz_f8(d->_data.output_weight->l_04_o_wbcomac_fuel_iyz_f8); output.l_04_o_wbcomac_fuel_izz_f8(d->_data.output_weight->l_04_o_wbcomac_fuel_izz_f8); output.l_04_o_wbcomac_l_wt_fuel_f8(d->_data.output_weight->l_04_o_wbcomac_l_wt_fuel_f8); output.l_04_o_wbcomac_ice_airframe_total_f8( d->_data.output_weight->l_04_o_wbcomac_ice_airframe_total_f8); std::array l_04_o_wbcomac_ice_eng_f8; for (int i = 0; i < 2; i++) { l_04_o_wbcomac_ice_eng_f8[i] = d->_data.output_weight->l_04_o_wbcomac_ice_eng_f8[i]; } output.l_04_o_wbcomac_ice_eng_f8(l_04_o_wbcomac_ice_eng_f8); output.l_04_o_wbcomac_ice_eng_total_f8(d->_data.output_weight->l_04_o_wbcomac_ice_eng_total_f8); output.l_04_o_wbcomac_ice_fuselage_f8(d->_data.output_weight->l_04_o_wbcomac_ice_fuselage_f8); output.l_04_o_wbcomac_ice_stab_left_f8(d->_data.output_weight->l_04_o_wbcomac_ice_stab_left_f8); output.l_04_o_wbcomac_ice_stab_right_f8( d->_data.output_weight->l_04_o_wbcomac_ice_stab_right_f8); output.l_04_o_wbcomac_ice_stab_total_f8( d->_data.output_weight->l_04_o_wbcomac_ice_stab_total_f8); output.l_04_o_wbcomac_ice_total_f8(d->_data.output_weight->l_04_o_wbcomac_ice_total_f8); output.l_04_o_wbcomac_ice_total_frac_f8( d->_data.output_weight->l_04_o_wbcomac_ice_total_frac_f8); output.l_04_o_wbcomac_ice_vert_tail_f8(d->_data.output_weight->l_04_o_wbcomac_ice_vert_tail_f8); output.l_04_o_wbcomac_ice_wing_left_f8(d->_data.output_weight->l_04_o_wbcomac_ice_wing_left_f8); output.l_04_o_wbcomac_ice_wing_right_f8( d->_data.output_weight->l_04_o_wbcomac_ice_wing_right_f8); output.l_04_o_wbcomac_ice_wing_total_f8( d->_data.output_weight->l_04_o_wbcomac_ice_wing_total_f8); output.l_04_o_wbcomac_frz_l1(d->_data.output_weight->l_04_o_wbcomac_frz_l1); output.l_04_o_wbcomac_zcgfrz_l1(d->_data.output_weight->l_04_o_wbcomac_zcgfrz_l1); output.l_04_o_wbcomac_zcgfrz_grfx_l1(d->_data.output_weight->l_04_o_wbcomac_zcgfrz_grfx_l1); output.l_04_o_wbcomac_ycgfrz_l1(d->_data.output_weight->l_04_o_wbcomac_ycgfrz_l1); output.l_04_o_wbcomac_inertfrz_l1(d->_data.output_weight->l_04_o_wbcomac_inertfrz_l1); output.l_04_o_wbcomac_init_l1(d->_data.output_weight->l_04_o_wbcomac_init_l1); output.l_04_o_wbcomac_min_gw_f4(d->_data.output_weight->l_04_o_wbcomac_min_gw_f4); output.l_04_o_wbcomac_max_gw_f4(d->_data.output_weight->l_04_o_wbcomac_max_gw_f4); output.l_04_o_wbcomac_min_cg_f4(d->_data.output_weight->l_04_o_wbcomac_min_cg_f4); output.l_04_o_wbcomac_max_cg_f4(d->_data.output_weight->l_04_o_wbcomac_max_cg_f4); output.l_04_o_wbcomac_min_zfw_f4(d->_data.output_weight->l_04_o_wbcomac_min_zfw_f4); output.l_04_o_wbcomac_max_zfw_f4(d->_data.output_weight->l_04_o_wbcomac_max_zfw_f4); output.l_04_o_wbcomac_min_zfwcg_f4(d->_data.output_weight->l_04_o_wbcomac_min_zfwcg_f4); output.l_04_o_wbcomac_max_zfwcg_f4(d->_data.output_weight->l_04_o_wbcomac_max_zfwcg_f4); output.l_04_o_wbcomac_potmin_gw_f8(d->_data.output_weight->l_04_o_wbcomac_potmin_gw_f8); output.l_04_o_wbcomac_potmax_gw_f8(d->_data.output_weight->l_04_o_wbcomac_potmax_gw_f8); output.l_04_o_wbcomac_potmin_gwcg_f8(d->_data.output_weight->l_04_o_wbcomac_potmin_gwcg_f8); output.l_04_o_wbcomac_potmax_gwcg_f8(d->_data.output_weight->l_04_o_wbcomac_potmax_gwcg_f8); d->_dataWriters["XNSim::ATA04::WeightBalance_output"]->write(&output); }