MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
recFromFlightgear.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-flightgear/recFromFlightgear.cc,v 1.1 2017/08/25 14:16:20 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33 
34 //#include <cstdint>
35 #include <unistd.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <fcntl.h>
39 
40 #include <fstream>
41 
42 #include "userelem.h"
43 #include "socketstream_out_elem.h"
44 #include "socketstreamdrive.h"
45 #include "bufmod.h"
46 #include "drive_.h"
47 #include "streamdrive.h"
48 
49 #include "module-flightgear.h"
50 
51 /*FileDrive content-type-------------------------------------------------------------------------------*/
52 
53 StreamDrive::Modifier * FlightGearFileDriveReader::Read(std::vector<doublereal> &v0, MBDynParser& HP, int &idrives){
54  StreamDrive::Modifier *pMod = 0;
55 
56  FieldsDescriptionFG *fieldsDescriptionFGInUse;
57 
58  if(HP.IsKeyWord("NetFDM")){
59  fieldsDescriptionFGInUse = &fieldsDescriptionFGNetFDM;
60  idrives = fieldsDescriptionFGNetFDM.size();
61  }
62  else if(HP.IsKeyWord("NetCtrls")){
63  fieldsDescriptionFGInUse = &fieldsDescriptionFGNetCtrls;
64  idrives = fieldsDescriptionFGNetCtrls.size();
65  }
66  else{
67  silent_cerr("invalid FG data structure "
68  "at line " << HP.GetLineData() << std::endl);
70  }
71 
72  if(HP.IsKeyWord("print" "options")){
73  printOptionsOnTextFile("FGNetFDM_options.txt", fieldsDescriptionFGNetFDM);
74  printOptionsOnTextFile("FGNetCtrls_options.txt", fieldsDescriptionFGNetCtrls);
75  silent_cout("Flight Gear options correctly printed on files." << std::endl);
76  }
77 
78  pMod = this->buildFGStreamDriveModifier(fieldsDescriptionFGInUse);
79 
80  return pMod;
81 }
82 
84  StreamDrive::Modifier *pSDM(0);
85 
86  std::vector<BufCast *> data(fieldsDescriptionFGInUse->size());
87  buildFGBufCast(data, *fieldsDescriptionFGInUse);
88  size_t minsize = data[data.size() - 1]->offset() + data[data.size() - 1]->size();
89  size_t size = minsize;
90 
91  if(fieldsDescriptionFGInUse == &fieldsDescriptionFGNetFDM){
92  pSDM = new FGNetFDMStreamDriveCopyCast(size, data);
93  }else if(fieldsDescriptionFGInUse == &fieldsDescriptionFGNetCtrls){
94  pSDM = new FGNetCtrlsStreamDriveCopyCast(size, data);
95  }else{
96  silent_cerr("FlightGearFileDriveReader::buildFGStreamDriveModifier internal error: unknown fieldsDescriptionFGInUse " << std::endl);
98  }
99 
100  return pSDM;
101 }
102 
103 /*FileDriveCaller type----------------------------------------------------------------------------------*/
105  FieldsDescriptionFG *fieldsDescriptionFGInUse;
106  HighParser::WordSet *FGWordSetInUse;
107  std::string FGStructureName;
108  const char *s;
109 
110  const StreamDrive *pDrv_StreamDrive = dynamic_cast<StreamDrive*>(pDrv);
111  const StreamDrive::Modifier *pMod = pDrv_StreamDrive->pGetModifier();
112 
113  if(pMod != 0 && dynamic_cast<const FGNetFDMStreamDriveCopyCast*>(pMod) != 0){
114  fieldsDescriptionFGInUse = &fieldsDescriptionFGNetFDM;
115  FGWordSetInUse = &fGNetFDMWordSet;
116  FGStructureName = "NetFDM";
117  }else if(pMod != 0 && dynamic_cast<const FGNetCtrlsStreamDriveCopyCast*>(pMod) != 0){
118  fieldsDescriptionFGInUse = &fieldsDescriptionFGNetCtrls;
119  FGWordSetInUse = &fGNetCtrlsWordSet;
120  FGStructureName = "NetCtrls";
121  }else{
122  silent_cerr("error: specified FileDrive does not receive Flight Gear data structure. Please check it out. "
123  "error at line " << HP.GetLineData() << std::endl);
125  }
126 
127  if((s = HP.IsWord(*FGWordSetInUse)) != NULL){
128  FieldsDescriptionFG::iterator it = fieldsDescriptionFGInUse->find(std::string(s));
129  return it->second.position;
130  }else{
131  silent_cerr("FlightGearFileDriveCallerTypeReader: unknown FG field of " << FGStructureName
132  << " at line " << HP.GetLineData()
133  << std::endl);
135  }
136 }
137 
138 FGNetFDMStreamDriveCopyCast::FGNetFDMStreamDriveCopyCast(size_t size, const std::vector<BufCast *>& data):StreamDriveCopyCast(size, data){}
140 
141 FGNetCtrlsStreamDriveCopyCast::FGNetCtrlsStreamDriveCopyCast(size_t size, const std::vector<BufCast *>& data):StreamDriveCopyCast(size, data){}
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
FGNetCtrlsStreamDriveCopyCast(size_t size, const std::vector< BufCast * > &data)
virtual const char * IsWord(const HighParser::WordSet &ws)
Definition: parser.cc:977
void printOptionsOnTextFile(const char *fileName, FieldsDescriptionFG &fieldsDescriptionFG)
void buildFGBufCast(std::vector< BufCast * > &data, FieldsDescriptionFG &fieldsDescriptionFGInUse)
FGNetCtrlsWordSet fGNetCtrlsWordSet
StreamDrive::Modifier * buildFGStreamDriveModifier(FieldsDescriptionFG *fieldsDescriptionFGInUse)
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
const StreamDrive::Modifier * pGetModifier(void) const
Definition: streamdrive.cc:80
virtual integer Read(const DataManager *pDM, MBDynParser &HP, FileDrive *pDrv)
FieldsDescriptionFG fieldsDescriptionFGNetCtrls
virtual StreamDrive::Modifier * Read(std::vector< doublereal > &v0, MBDynParser &HP, int &idrives)
static const std::vector< doublereal > v0
Definition: fixedstep.cc:45
FGNetFDMWordSet fGNetFDMWordSet
long int integer
Definition: colamd.c:51
FieldsDescriptionFG fieldsDescriptionFGNetFDM
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
FGNetFDMStreamDriveCopyCast(size_t size, const std::vector< BufCast * > &data)
std::map< std::string, FieldInfo > FieldsDescriptionFG