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/string_utilities.h"
57FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
62 PropertyManager->Tie<FGOutput,
int>(
"simulation/force-output",
this,
nullptr,
63 &FGOutput::ForceOutput);
72 for (
auto output: OutputTypes)
80bool FGOutput::InitModel(
void)
84 if (!FGModel::InitModel())
return false;
86 for (
auto output: OutputTypes)
87 ret &= output->InitModel();
94bool FGOutput::Run(
bool Holding)
96 if (FDMExec->GetTrimStatus())
return true;
97 if (FGModel::Run(Holding))
return true;
98 if (Holding)
return false;
99 if (!enabled)
return true;
101 for (
auto output: OutputTypes)
102 output->Run(Holding);
109void FGOutput::Print(
void)
111 for (
auto output: OutputTypes)
117void FGOutput::SetStartNewOutput(
void)
119 for (
auto output: OutputTypes)
120 output->SetStartNewOutput();
125bool FGOutput::Toggle(
int idx)
127 if (idx >= (
int)0 && idx < (
int)OutputTypes.size())
128 return OutputTypes[idx]->Toggle();
135void FGOutput::SetRateHz(
double rate)
137 for (
auto output: OutputTypes)
138 output->SetRateHz(rate);
143void FGOutput::ForceOutput(
int idx)
145 if (idx >= (
int)0 && idx < (
int)OutputTypes.size())
146 OutputTypes[idx]->Print();
151bool FGOutput::SetOutputName(
unsigned int idx,
const std::string& name)
153 if (idx >= OutputTypes.size())
return false;
155 OutputTypes[idx]->SetOutputName(name);
161string FGOutput::GetOutputName(
unsigned int idx)
const
165 if (idx < OutputTypes.size())
166 name = OutputTypes[idx]->GetOutputName();
172bool FGOutput::SetDirectivesFile(
const SGPath& fname)
178 s <<
"Could not read directive file: " << fname;
182 bool result = Load(document);
184 cerr << endl <<
"Aircraft output element has problems in file " << fname << endl;
191bool FGOutput::Load(
int subSystems, std::string protocol, std::string type,
192 std::string port, std::string name,
double outRate,
193 std::vector<SGPropertyNode_ptr> & outputProperties)
195 size_t idx = OutputTypes.size();
198 if (debug_lvl > 0) cout << endl <<
" Output data set: " << idx << endl;
200 type = to_upper(type);
205 Output = OutputTextFile;
206 }
else if (type ==
"TABULAR") {
209 Output = OutputTextFile;
210 }
else if (type ==
"SOCKET") {
212 name +=
":" + port +
"/" + protocol;
213 }
else if (type ==
"FLIGHTGEAR") {
215 name +=
":" + port +
"/" + protocol;
216 }
else if (type ==
"TERMINAL") {
218 }
else if (type !=
string(
"NONE")) {
219 cerr <<
"Unknown type of output specified in config file" << endl;
222 if (!Output)
return false;
230 OutputTypes.push_back(Output);
238bool FGOutput::Load(
Element* document,
const SGPath& dir)
244 if (!FGModel::Upload(document,
false))
247 size_t idx = OutputTypes.size();
251 if (debug_lvl > 0) cout << endl <<
" Output data set: " << idx <<
" " << endl;
253 type = to_upper(type);
257 }
else if (type ==
"TABULAR") {
259 }
else if (type ==
"SOCKET") {
261 }
else if (type ==
"FLIGHTGEAR") {
263 }
else if (type ==
"TERMINAL") {
265 }
else if (type !=
string(
"NONE")) {
266 cerr <<
"Unknown type of output specified in config file" << endl;
269 if (!Output)
return false;
272 Output->PreLoad(document, FDMExec);
273 Output->
Load(document);
274 Output->PostLoad(document, FDMExec);
276 OutputTypes.push_back(Output);
284SGPath FGOutput::FindFullPathName(
const SGPath& path)
const
287 if (!includePath.isNull()) {
288 SGPath name = CheckPathName(includePath, path);
289 if (!name.isNull())
return name;
292 return FGModel::FindFullPathName(path);
314void FGOutput::Debug(
int from)
316 if (debug_lvl <= 0)
return;
325 if (debug_lvl & 2 ) {
326 if (from == 0) cout <<
"Instantiated: FGOutput" << endl;
327 if (from == 1) cout <<
"Destroyed: FGOutput" << endl;
329 if (debug_lvl & 4 ) {
331 if (debug_lvl & 8 ) {
333 if (debug_lvl & 16) {
335 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.