43 #include "input_output/FGOutputTextFile.h"
44 #include "input_output/FGOutputFG.h"
45 #include "input_output/FGXMLFileRead.h"
46 #include "input_output/FGModelLoader.h"
56 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
58 typedef int (FGOutput::*iOPV)(void)
const;
63 PropertyManager->Tie(
"simulation/force-output",
this, (iOPV)0, &FGOutput::ForceOutput);
72 for (
auto output: OutputTypes)
80 bool FGOutput::InitModel(
void)
84 if (!FGModel::InitModel())
return false;
86 for (
auto output: OutputTypes)
87 ret &= output->InitModel();
94 bool 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)
109 void FGOutput::Print(
void)
111 for (
auto output: OutputTypes)
117 void FGOutput::SetStartNewOutput(
void)
119 for (
auto output: OutputTypes)
120 output->SetStartNewOutput();
125 bool FGOutput::Toggle(
int idx)
127 if (idx >= (
int)0 && idx < (
int)OutputTypes.size())
128 return OutputTypes[idx]->Toggle();
135 void FGOutput::SetRateHz(
double rate)
137 for (
auto output: OutputTypes)
138 output->SetRateHz(rate);
143 void FGOutput::ForceOutput(
int idx)
145 if (idx >= (
int)0 && idx < (
int)OutputTypes.size())
146 OutputTypes[idx]->Print();
151 bool FGOutput::SetOutputName(
unsigned int idx,
const std::string& name)
153 if (idx >= OutputTypes.size())
return false;
155 OutputTypes[idx]->SetOutputName(name);
161 string FGOutput::GetOutputName(
unsigned int idx)
const
165 if (idx < OutputTypes.size())
166 name = OutputTypes[idx]->GetOutputName();
172 bool 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;
191 bool FGOutput::Load(
int subSystems, std::string protocol, std::string type,
192 std::string port, std::string name,
double outRate,
193 std::vector<FGPropertyNode_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);
238 bool 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);
284 SGPath 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);
314 void 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 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.
void SetOutputProperties(std::vector< FGPropertyNode_ptr > &outputProperties)
Set the list of properties that should be output for this output instance.
This class is solely for the purpose of determining what type of file is given on the command line.