45 #include "FGOutputFG.h" 46 #include "FGFDMExec.h" 47 #include "models/FGAerodynamics.h" 48 #include "models/FGAuxiliary.h" 49 #include "models/FGPropulsion.h" 50 #include "models/FGMassBalance.h" 51 #include "models/FGPropagate.h" 52 #include "models/FGGroundReactions.h" 53 #include "models/FGFCS.h" 54 #include "models/propulsion/FGPiston.h" 55 #include "models/propulsion/FGTank.h" 57 #if defined(WIN32) && !defined(__CYGWIN__) 60 # include <netinet/in.h> 64 # define min(X,Y) X<Y?X:Y 67 static const int endianTest = 1;
68 #define isLittleEndian (*((char *) &endianTest ) != 0) 74 IDENT(IdSrc,
"$Id: FGOutputFG.cpp,v 1.9 2014/02/17 05:01:55 jberndt Exp $");
75 IDENT(IdHdr,ID_OUTPUTFG);
87 static void htond (
double &x)
89 if ( isLittleEndian ) {
93 Double_Overlay = (
int *) &x;
94 Holding_Buffer = Double_Overlay [0];
96 Double_Overlay [0] = htonl (Double_Overlay [1]);
97 Double_Overlay [1] = htonl (Holding_Buffer);
104 static void htonf (
float &x)
106 if ( isLittleEndian ) {
110 Float_Overlay = (
int *) &x;
111 Holding_Buffer = Float_Overlay [0];
113 Float_Overlay [0] = htonl (Holding_Buffer);
127 memset(&fgSockBuf, 0x0,
sizeof(fgSockBuf));
132 void FGOutputFG::SocketDataFill(FGNetFDM* net)
137 net->version = FG_NET_FDM_VERSION;
140 net->longitude = Propagate->GetLocation().
GetLongitude();
143 net->agl = (float)(Propagate->GetDistanceAGL()*0.3048);
145 net->phi = (float)(Propagate->
GetEuler(ePhi));
146 net->theta = (float)(Propagate->
GetEuler(eTht));
147 net->psi = (float)(Propagate->
GetEuler(ePsi));
149 net->alpha = (float)(Auxiliary->Getalpha());
150 net->beta = (float)(Auxiliary->Getbeta());
153 net->phidot = (float)(Auxiliary->GetEulerRates(ePhi));
154 net->thetadot = (float)(Auxiliary->GetEulerRates(eTht));
155 net->psidot = (float)(Auxiliary->GetEulerRates(ePsi));
157 net->climb_rate = (float)(Propagate->
Gethdot());
158 net->v_north = (float)(Propagate->
GetVel(eNorth));
159 net->v_east = (float)(Propagate->
GetVel(eEast));
160 net->v_down = (float)(Propagate->
GetVel(eDown));
162 net->v_body_u = (float)(Propagate->
GetUVW(1));
163 net->v_body_v = (float)(Propagate->
GetUVW(2));
164 net->v_body_w = (float)(Propagate->
GetUVW(3));
167 net->A_X_pilot = (float)(Auxiliary->GetPilotAccel(1));
168 net->A_Y_pilot = (float)(Auxiliary->GetPilotAccel(2));
169 net->A_Z_pilot = (float)(Auxiliary->GetPilotAccel(3));
172 net->stall_warning = 0.0;
173 net->slip_deg = (float)(Auxiliary->Getbeta(inDegrees));
177 cerr <<
"This vehicle has " << Propulsion->
GetNumEngines() <<
" engines, but the current " << endl
178 <<
"version of FlightGear's FGNetFDM only supports " << FGNetFDM::FG_MAX_ENGINES <<
" engines." << endl
179 <<
"Only the first " << FGNetFDM::FG_MAX_ENGINES <<
" engines will be used." << endl;
181 net->num_engines = min(FGNetFDM::FG_MAX_ENGINES,Propulsion->
GetNumEngines());
183 for (i=0; i<net->num_engines; i++) {
184 if (Propulsion->
GetEngine(i)->GetRunning())
185 net->eng_state[i] = 2;
186 else if (Propulsion->
GetEngine(i)->GetCranking())
187 net->eng_state[i] = 1;
189 net->eng_state[i] = 0;
191 switch (Propulsion->
GetEngine(i)->GetType()) {
192 case (FGEngine::etRocket):
194 case (FGEngine::etPiston):
196 net->fuel_flow[i] = (float)(((
FGPiston *)Propulsion->
GetEngine(i))->getFuelFlow_gph());
199 net->cht[i] = (float)(((
FGPiston *)Propulsion->
GetEngine(i))->getCylinderHeadTemp_degF());
200 net->mp_osi[i] = (float)(((
FGPiston *)Propulsion->
GetEngine(i))->getManifoldPressure_inHg());
201 net->oil_temp[i] = (float)(((
FGPiston *)Propulsion->
GetEngine(i))->getOilTemp_degF());
202 net->oil_px[i] = (float)(((
FGPiston *)Propulsion->
GetEngine(i))->getOilPressure_psi());
205 case (FGEngine::etTurbine):
207 case (FGEngine::etTurboprop):
209 case (FGEngine::etElectric):
211 case (FGEngine::etUnknown):
218 cerr <<
"This vehicle has " << Propulsion->
GetNumTanks() <<
" tanks, but the current " << endl
219 <<
"version of FlightGear's FGNetFDM only supports " << FGNetFDM::FG_MAX_TANKS <<
" tanks." << endl
220 <<
"Only the first " << FGNetFDM::FG_MAX_TANKS <<
" tanks will be used." << endl;
222 net->num_tanks = min(FGNetFDM::FG_MAX_TANKS, Propulsion->
GetNumTanks());
224 for (i=0; i<net->num_tanks; i++) {
225 net->fuel_quantity[i] = (float)(((
FGTank *)Propulsion->
GetTank(i))->GetContents());
229 if (GroundReactions->GetNumGearUnits() > FGNetFDM::FG_MAX_WHEELS && FDMExec->
GetSimTime() == 0.0)
230 cerr <<
"This vehicle has " << GroundReactions->GetNumGearUnits() <<
" bogeys, but the current " << endl
231 <<
"version of FlightGear's FGNetFDM only supports " << FGNetFDM::FG_MAX_WHEELS <<
" bogeys." << endl
232 <<
"Only the first " << FGNetFDM::FG_MAX_WHEELS <<
" bogeys will be used." << endl;
234 net->num_wheels = min(FGNetFDM::FG_MAX_WHEELS, GroundReactions->GetNumGearUnits());
236 for (i=0; i<net->num_wheels; i++) {
238 if (GroundReactions->
GetGearUnit(i)->GetGearUnitDown())
239 net->gear_pos[i] = 1;
241 net->gear_pos[i] = 0;
242 net->gear_steer[i] = (
float)(GroundReactions->
GetGearUnit(i)->GetSteerNorm());
247 net->cur_time = (
long int)1234567890;
249 net->visibility = 25000.0;
252 net->elevator = (float)(FCS->
GetDePos(ofNorm));
254 net->left_flap = (float)(FCS->
GetDfPos(ofNorm));
255 net->right_flap = (float)(FCS->
GetDfPos(ofNorm));
256 net->left_aileron = (float)(FCS->
GetDaLPos(ofNorm));
257 net->right_aileron = (float)(FCS->
GetDaRPos(ofNorm));
258 net->rudder = (float)(FCS->
GetDrPos(ofNorm));
259 net->nose_wheel = (float)(FCS->
GetDrPos(ofNorm));
260 net->speedbrake = (float)(FCS->
GetDsbPos(ofNorm));
261 net->spoilers = (float)(FCS->
GetDspPos(ofNorm));
264 if ( isLittleEndian ) {
265 net->version = htonl(net->version);
267 htond(net->longitude);
268 htond(net->latitude);
269 htond(net->altitude);
278 htonf(net->thetadot);
281 htonf(net->climb_rate);
285 htonf(net->v_body_u);
286 htonf(net->v_body_v);
287 htonf(net->v_body_w);
289 htonf(net->A_X_pilot);
290 htonf(net->A_Y_pilot);
291 htonf(net->A_Z_pilot);
293 htonf(net->stall_warning);
294 htonf(net->slip_deg);
296 for (i=0; i<net->num_engines; ++i ) {
297 net->eng_state[i] = htonl(net->eng_state[i]);
299 htonf(net->fuel_flow[i]);
300 htonf(net->fuel_px[i]);
303 htonf(net->mp_osi[i]);
305 htonf(net->oil_temp[i]);
306 htonf(net->oil_px[i]);
308 net->num_engines = htonl(net->num_engines);
310 for (i=0; i<net->num_tanks; ++i ) {
311 htonf(net->fuel_quantity[i]);
313 net->num_tanks = htonl(net->num_tanks);
315 for (i=0; i<net->num_wheels; ++i ) {
316 net->wow[i] = htonl(net->wow[i]);
317 htonf(net->gear_pos[i]);
318 htonf(net->gear_steer[i]);
319 htonf(net->gear_compression[i]);
321 net->num_wheels = htonl(net->num_wheels);
323 net->cur_time = htonl( net->cur_time );
324 net->warp = htonl( net->warp );
325 htonf(net->visibility);
327 htonf(net->elevator);
328 htonf(net->elevator_trim_tab);
329 htonf(net->left_flap);
330 htonf(net->right_flap);
331 htonf(net->left_aileron);
332 htonf(net->right_aileron);
334 htonf(net->nose_wheel);
335 htonf(net->speedbrake);
336 htonf(net->spoilers);
344 int length =
sizeof(fgSockBuf);
346 if (socket == 0)
return;
347 if (!socket->GetConnectStatus())
return;
349 SocketDataFill(&fgSockBuf);
350 socket->Send((
char *)&fgSockBuf, length);
FGTank * GetTank(unsigned int index) const
Retrieves a tank object pointer from the list of tanks.
double GetDfPos(int form=ofRad) const
Gets the flaps position.
double GetDePos(int form=ofRad) const
Gets the elevator position.
double GetDaLPos(int form=ofRad) const
Gets the left aileron position.
double GetCompLen(void) const
Gets the current compressed length of the gear in feet.
FGEngine * GetEngine(unsigned int index) const
Retrieves an engine object pointer from the list of engines.
double GetAltitudeASL(void) const
Returns the current altitude above sea level.
const FGColumnVector3 & GetUVW(void) const
Retrieves the body frame vehicle velocity vector.
double GetPitchTrimCmd(void) const
Gets the pitch trim command.
double GetLongitude() const
Get the longitude.
virtual void Print(void)
Generate the output.
const FGColumnVector3 & GetVel(void) const
Retrieves the velocity vector.
double GetDsbPos(int form=ofRad) const
Gets the speedbrake position.
const FGColumnVector3 & GetEuler(void) const
Retrieves the Euler angles that define the vehicle orientation.
double GetGeodLatitudeRad(void) const
Get the geodetic latitude.
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
double Gethdot(void) const
Returns the current altitude rate.
Implements the output to a socket.
unsigned int GetNumTanks(void) const
Retrieves the number of tanks defined for the aircraft.
Models a Supercharged Piston engine.
double GetDspPos(int form=ofRad) const
Gets the spoiler position.
FGLGear * GetGearUnit(int gear) const
Gets a gear instance.
double GetVcalibratedKTS(void) const
Returns Calibrated airspeed in knots.
Encapsulates the JSBSim simulation executive.
bool GetWOW(void) const
Gets the Weight On Wheels flag value.
double GetDaRPos(int form=ofRad) const
Gets the right aileron position.
double GetDrPos(int form=ofRad) const
Gets the rudder position.
unsigned int GetNumEngines(void) const
Retrieves the number of engines defined for the aircraft.