43#include "input_output/FGOutputTextFile.h"
44#include "input_output/FGOutputFG.h"
45#include "input_output/FGXMLFileRead.h"
46#include "input_output/FGModelLoader.h"
47#include "input_output/FGLog.h"
48#include "input_output/string_utilities.h"
58FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
63 PropertyManager->Tie<FGOutput,
int>(
"simulation/force-output",
this,
nullptr,
64 &FGOutput::ForceOutput);
73 for (
auto output: OutputTypes)
81bool FGOutput::InitModel(
void)
85 if (!FGModel::InitModel())
return false;
87 for (
auto output: OutputTypes)
88 ret &= output->InitModel();
95bool FGOutput::Run(
bool Holding)
97 if (FDMExec->GetTrimStatus())
return true;
98 if (FGModel::Run(Holding))
return true;
99 if (Holding)
return false;
100 if (!enabled)
return true;
102 for (
auto output: OutputTypes)
103 output->Run(Holding);
110void FGOutput::Print(
void)
112 for (
auto output: OutputTypes)
118void FGOutput::SetStartNewOutput(
void)
120 for (
auto output: OutputTypes)
121 output->SetStartNewOutput();
126bool FGOutput::Toggle(
int idx)
128 if (idx >= (
int)0 && idx < (
int)OutputTypes.size())
129 return OutputTypes[idx]->Toggle();
136void FGOutput::SetRateHz(
double rate)
138 for (
auto output: OutputTypes)
139 output->SetRateHz(rate);
144void FGOutput::ForceOutput(
int idx)
146 if (idx >= (
int)0 && idx < (
int)OutputTypes.size())
147 OutputTypes[idx]->Print();
152bool FGOutput::SetOutputName(
unsigned int idx,
const std::string& name)
154 if (idx >= OutputTypes.size())
return false;
156 OutputTypes[idx]->SetOutputName(name);
162string FGOutput::GetOutputName(
unsigned int idx)
const
166 if (idx < OutputTypes.size())
167 name = OutputTypes[idx]->GetOutputName();
173bool FGOutput::SetDirectivesFile(
const SGPath& fname)
179 err <<
"Could not read directive file: " << fname;
183 bool result = Load(document);
186 log <<
"\nAircraft output element has problems in file " << fname <<
"\n";
194bool FGOutput::Load(
int subSystems, std::string protocol, std::string type,
195 std::string port, std::string name,
double outRate,
196 std::vector<SGPropertyNode_ptr> & outputProperties)
198 size_t idx = OutputTypes.size();
203 log <<
"\n Output data set: " << idx <<
"\n";
206 type = to_upper(type);
211 Output = OutputTextFile;
212 }
else if (type ==
"TABULAR") {
215 Output = OutputTextFile;
216 }
else if (type ==
"SOCKET") {
218 name +=
":" + port +
"/" + protocol;
219 }
else if (type ==
"FLIGHTGEAR") {
221 name +=
":" + port +
"/" + protocol;
222 }
else if (type ==
"TERMINAL") {
224 }
else if (type !=
string(
"NONE")) {
226 log <<
"Unknown type of output specified in config file\n";
229 if (!Output)
return false;
237 OutputTypes.push_back(Output);
245bool FGOutput::Load(
Element* document,
const SGPath& dir)
251 if (!FGModel::Upload(document,
false))
254 size_t idx = OutputTypes.size();
260 log <<
"\n Output data set: " << idx <<
" \n";
263 type = to_upper(type);
267 }
else if (type ==
"TABULAR") {
269 }
else if (type ==
"SOCKET") {
271 }
else if (type ==
"FLIGHTGEAR") {
273 }
else if (type ==
"TERMINAL") {
275 }
else if (type !=
string(
"NONE")) {
277 log <<
"Unknown type of output specified in config file\n";
280 if (!Output)
return false;
283 Output->PreLoad(document, FDMExec);
284 Output->
Load(document);
285 Output->PostLoad(document, FDMExec);
287 OutputTypes.push_back(Output);
295SGPath FGOutput::FindFullPathName(
const SGPath& path)
const
298 if (!includePath.isNull()) {
299 SGPath name = CheckPathName(includePath, path);
300 if (!name.isNull())
return name;
303 return FGModel::FindFullPathName(path);
325void FGOutput::Debug(
int from)
327 if (debug_lvl <= 0)
return;
336 if (debug_lvl & 2 ) {
337 FGLogging log(LogLevel::DEBUG);
338 if (from == 0) log <<
"Instantiated: FGOutput\n";
339 if (from == 1) log <<
"Destroyed: FGOutput\n";
341 if (debug_lvl & 4 ) {
343 if (debug_lvl & 8 ) {
345 if (debug_lvl & 16) {
347 if (debug_lvl & 64) {
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Implements the output to a FlightGear socket.
Implements the output to a socket.
Implements the output to a human readable text file.
void SetDelimiter(const std::string &delim)
Set the delimiter.
Abstract class to provide functions generic to all the output directives.
bool Load(Element *el) override
Init the output directives from an XML file (implement the FGModel interface).
void SetOutputProperties(std::vector< SGPropertyNode_ptr > &outputProperties)
Set the list of properties that should be output for this output instance.
void SetRateHz(double rtHz)
Set the output rate for this output instances.
void SetIdx(unsigned int idx)
Set the idx for this output instance.
virtual void SetOutputName(const std::string &name)
Overwrites the name identifier under which the output will be logged.
void SetSubSystems(int subSystems)
Set the activated subsystems for this output instance.
This class is solely for the purpose of determining what type of file is given on the command line.
Main namespace for the JSBSim Flight Dynamics Model.