XNSim/XNModels/XNWeightBalance/XNWeightBalance.cpp

108 lines
3.1 KiB
C++
Raw Normal View History

#include "XNWeightBalance.h"
#include "XNWeightBalance_p.h"
#include <XNCore/XNModelManager.h>
XN_MODEL_INITIALIZE(XNWeightBalance)
XNWeightBalance::XNWeightBalance() : XNModelObject(new XNWeightBalancePrivate())
{
}
XNWeightBalance::~XNWeightBalance()
{
T_D();
// 释放输入数组内存
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(PrivateType *p) : XNModelObject(p)
{
}
void XNWeightBalance::Initialize()
{
T_D();
XNModelObject::Initialize();
if (d->_dynamicLib) {
d->_fun = (FunctionType)dlsym(d->_dynamicLib, d->_entryPointName.c_str());
if (!d->_fun) {
LOG_WARNING("Failed to resolve SACSCGroundHandlingEntry");
}
}
//add other initial code here
}
void XNWeightBalance::PrepareForExecute()
{
T_D();
XNModelObject::PrepareForExecute();
}
void XNWeightBalance::StepUpdate()
{
T_D();
XNModelObject::StepUpdate();
if (d->_fun) {
d->_inputInterface.getData(d->_data.input_weight);
d->_fun(&d->_data);
d->_outputInterface.setData(d->_data.output_weight);
d->_heartbeatInterface.setData(&d->_data);
}
}
void XNWeightBalance::InitializeData()
{
T_D();
//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::ReleaseData()
{
T_D();
//add your release data code here
if (d->_data.input_weight) {
if (d->_data.input_weight->l_04_i_wbcomac_acset_tankfuel_f4) {
delete[] d->_data.input_weight->l_04_i_wbcomac_acset_tankfuel_f4;
}
if (d->_data.input_weight->l_04_i_wbcomac_eng_efsep_l1) {
delete[] d->_data.input_weight->l_04_i_wbcomac_eng_efsep_l1;
}
if (d->_data.input_weight->l_04_i_wbcomac_fuel_f8) {
delete[] d->_data.input_weight->l_04_i_wbcomac_fuel_f8;
}
if (d->_data.input_weight->l_04_i_wbcomac_kice_f8) {
delete[] d->_data.input_weight->l_04_i_wbcomac_kice_f8;
}
delete d->_data.input_weight;
}
if (d->_data.output_weight) {
if (d->_data.output_weight->l_04_o_wbcomac_fuel_cmd_f8) {
delete[] d->_data.output_weight->l_04_o_wbcomac_fuel_cmd_f8;
}
if (d->_data.output_weight->l_04_o_wbcomac_ice_eng_f8) {
delete[] d->_data.output_weight->l_04_o_wbcomac_ice_eng_f8;
}
}
}