MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
FlightGearStreamOutputReader Struct Reference

#include <module-flightgear.h>

Inheritance diagram for FlightGearStreamOutputReader:
Collaboration diagram for FlightGearStreamOutputReader:

Public Member Functions

virtual StreamContentRead (DataManager *pDM, MBDynParser &HP)
 
void ReadFlightGearScalarValues (DataManager *pDM, MBDynParser &HP, FlightGearUserChannels &flightGearUserChannels, FieldsDescriptionFG *dataStructureInUse)
 
void setDefaultValues (std::vector< ScalarValue * > &allValues, std::vector< bool > &assignedByUser, FieldsDescriptionFG &fieldsDescriptionFGInUse)
 
bool fieldAlreadyUsed (std::string fieldDescription, FlightGearUserChannels &flightGearUserChannels)
 
StreamContent::ModifierbuildFGStreamContentModifier (FieldsDescriptionFG &fieldsDescriptionFGInUse)
 
- Public Member Functions inherited from StreamOutputContentTypeReader
virtual ~StreamOutputContentTypeReader (void)
 

Detailed Description

Definition at line 43 of file module-flightgear.h.

Member Function Documentation

StreamContent::Modifier * FlightGearStreamOutputReader::buildFGStreamContentModifier ( FieldsDescriptionFG fieldsDescriptionFGInUse)

Definition at line 164 of file sendToFlightgear.cc.

References buildFGBufCast().

Referenced by Read().

164  {
165  StreamContent::Modifier *pSCM(0);
166 
167  std::vector<BufCast *> data(fieldsDescriptionFGInUse.size());
168  buildFGBufCast(data, fieldsDescriptionFGInUse);
169 
170  size_t minsize = data[data.size() - 1]->offset() + data[data.size() - 1]->size();
171  size_t size = minsize;
172 
173  pSCM = new StreamContentCopyCast(0, 0, size, data);
174 
175  return pSCM;
176 }
void buildFGBufCast(std::vector< BufCast * > &data, FieldsDescriptionFG &fieldsDescriptionFGInUse)

Here is the call graph for this function:

bool FlightGearStreamOutputReader::fieldAlreadyUsed ( std::string  fieldDescription,
FlightGearUserChannels flightGearUserChannels 
)

Definition at line 156 of file sendToFlightgear.cc.

Referenced by ReadFlightGearScalarValues().

156  {
157  if(flightGearUserChannels.find(fieldDescription) != flightGearUserChannels.end()){
158  return true;
159  }
160 
161  return false;
162 }
StreamContent * FlightGearStreamOutputReader::Read ( DataManager pDM,
MBDynParser HP 
)
virtual

Implements StreamOutputContentTypeReader.

Definition at line 61 of file sendToFlightgear.cc.

References buildFGStreamContentModifier(), fGNetCtrlsWordSet, fGNetFDMWordSet, fieldsDescriptionFGNetCtrls, fieldsDescriptionFGNetFDM, IncludeParser::GetLineData(), HighParser::IsKeyWord(), MBDYN_EXCEPT_ARGS, printOptionsOnTextFile(), ReadFlightGearScalarValues(), SAFENEWWITHCONSTRUCTOR, and setDefaultValues().

61  {
62  StreamContent* pSC;
63 
64  FieldsDescriptionFG *fieldsDescriptionFGInUse;
65  int totChannels;
66 
67  if(HP.IsKeyWord("NetFDM")){
68  fieldsDescriptionFGInUse = &fieldsDescriptionFGNetFDM;
69  totChannels = fieldsDescriptionFGNetFDM.size();
71  }
72  else if(HP.IsKeyWord("NetCtrls")){
73  fieldsDescriptionFGInUse = &fieldsDescriptionFGNetCtrls;
74  totChannels = fieldsDescriptionFGNetCtrls.size();
76  }
77  else{
78  silent_cerr("invalid FG data structure "
79  "at line " << HP.GetLineData() << std::endl);
81  }
82 
83  if(HP.IsKeyWord("print" "options")){
84  printOptionsOnTextFile("FGNetFDM_options.txt", fieldsDescriptionFGNetFDM);
85  printOptionsOnTextFile("FGNetCtrls_options.txt", fieldsDescriptionFGNetCtrls);
86  silent_cout("Flight Gear options correctly printed on files." << std::endl);
87  }
88 
89  /*map containing descriptions and pointers to ScalarValue specified by user for every field he wants to use*/
90  FlightGearUserChannels flightGearUserChannels;
91  this->ReadFlightGearScalarValues(pDM, HP, flightGearUserChannels, fieldsDescriptionFGInUse);
92 
93  /*bulding of buffer that will be sent to Flight gear*/
94  std::vector<ScalarValue*> allValues(totChannels);
95  std::vector<bool> assignedByUser(totChannels, false);
96 
97  /*modifies user-specified fields in the buffer*/
98  for(FlightGearUserChannels::iterator i = flightGearUserChannels.begin() ; i != flightGearUserChannels.end() ; i++){
99  FieldsDescriptionFG::iterator el = fieldsDescriptionFGInUse->find(i->first);
100  int pos = (el->second.position) -1;
101  allValues.at(pos) = i->second;
102  assignedByUser.at(pos) = true;
103  }
104 
105  /*initializes each remaining field with its default value*/
106  this->setDefaultValues(allValues, assignedByUser, *fieldsDescriptionFGInUse);
107 
108  StreamContent::Modifier *pMod(0);
109  pMod = this->buildFGStreamContentModifier(*fieldsDescriptionFGInUse);
110 
112 
113  return pSC;
114 }
HighParser::WordSet * sendToFGWordSetInUse
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
void printOptionsOnTextFile(const char *fileName, FieldsDescriptionFG &fieldsDescriptionFG)
FGNetCtrlsWordSet fGNetCtrlsWordSet
void ReadFlightGearScalarValues(DataManager *pDM, MBDynParser &HP, FlightGearUserChannels &flightGearUserChannels, FieldsDescriptionFG *dataStructureInUse)
std::map< std::string, ScalarValue * > FlightGearUserChannels
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
StreamContent::Modifier * buildFGStreamContentModifier(FieldsDescriptionFG &fieldsDescriptionFGInUse)
void setDefaultValues(std::vector< ScalarValue * > &allValues, std::vector< bool > &assignedByUser, FieldsDescriptionFG &fieldsDescriptionFGInUse)
FieldsDescriptionFG fieldsDescriptionFGNetCtrls
FGNetFDMWordSet fGNetFDMWordSet
FieldsDescriptionFG fieldsDescriptionFGNetFDM
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
std::map< std::string, FieldInfo > FieldsDescriptionFG

Here is the call graph for this function:

void FlightGearStreamOutputReader::ReadFlightGearScalarValues ( DataManager pDM,
MBDynParser HP,
FlightGearUserChannels flightGearUserChannels,
FieldsDescriptionFG dataStructureInUse 
)

Definition at line 116 of file sendToFlightgear.cc.

References fieldAlreadyUsed(), IncludeParser::GetLineData(), HighParser::IsWord(), MBDYN_EXCEPT_ARGS, and ReadScalarValue().

Referenced by Read().

117  {
118  const char *fieldDescription;//field the user has written in MBDyn input file
119  ScalarValue *scalarValue;
120  std::string *s;
121 
122  while((fieldDescription = HP.IsWord(*sendToFGWordSetInUse)) != NULL){
123  s = new std::string(fieldDescription);
124  if(this->fieldAlreadyUsed(std::string(fieldDescription), flightGearUserChannels)){
125  silent_cerr("field of FGNetFDM already used "
126  "at line " << HP.GetLineData() << std::endl);
128  }
129 
130  scalarValue = ReadScalarValue(pDM, HP);
131  flightGearUserChannels.insert(FlightGearUserChannels::value_type(*s, scalarValue));
132  }
133 }
HighParser::WordSet * sendToFGWordSetInUse
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual const char * IsWord(const HighParser::WordSet &ws)
Definition: parser.cc:977
ScalarValue * ReadScalarValue(DataManager *pDM, MBDynParser &HP)
Definition: scalarvalue.cc:80
bool fieldAlreadyUsed(std::string fieldDescription, FlightGearUserChannels &flightGearUserChannels)
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697

Here is the call graph for this function:

void FlightGearStreamOutputReader::setDefaultValues ( std::vector< ScalarValue * > &  allValues,
std::vector< bool > &  assignedByUser,
FieldsDescriptionFG fieldsDescriptionFGInUse 
)

Definition at line 135 of file sendToFlightgear.cc.

References FGNetCtrlsCurVersion, fGNetCtrlsWordSet, FGNetFDMCurVersion, fGNetFDMWordSet, SAFENEW, and SAFENEWWITHCONSTRUCTOR.

Referenced by Read().

135  {
136  DriveCaller *pDC = 0;
137 
138  if(!assignedByUser.at(fieldsDescriptionFGInUse.find("version")->second.position-1)){
141  allValues.at(fieldsDescriptionFGInUse.find("version")->second.position-1) = new ScalarDriveValue(pDC); //version
144  allValues.at(fieldsDescriptionFGInUse.find("version")->second.position-1) = new ScalarDriveValue(pDC); //version
145  }
146  }
147 
148  for (int i=1 ; i < allValues.size() ; i++){
149  if(!assignedByUser.at(i)){
150  SAFENEW(pDC, NullDriveCaller);
151  allValues.at(i) = new ScalarDriveValue(pDC);
152  }
153  }
154 }
HighParser::WordSet * sendToFGWordSetInUse
FGNetCtrlsWordSet fGNetCtrlsWordSet
int FGNetCtrlsCurVersion
int FGNetFDMCurVersion
#define SAFENEW(pnt, item)
Definition: mynewmem.h:695
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
FGNetFDMWordSet fGNetFDMWordSet

The documentation for this struct was generated from the following files: