X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FExternalNet.cxx;h=49e432096240de1f3504a8b5c7f2a9fdc1204a5c;hb=ee98995d30e75cda88c9866f3cb6a761fda7d078;hp=3fc4aa0c63a787242913057abdbf687b4350f0e8;hpb=bdca06f9ba587d2d7902a0443360a929e062b54b;p=flightgear.git diff --git a/src/FDM/ExternalNet.cxx b/src/FDM/ExternalNet.cxx index 3fc4aa0c6..49e432096 100644 --- a/src/FDM/ExternalNet.cxx +++ b/src/FDM/ExternalNet.cxx @@ -65,38 +65,34 @@ static void htond (double &x) static void global2raw( FGRawCtrls *raw ) { int i; - static const SGPropertyNode *aileron - = fgGetNode("/controls/aileron"); - static const SGPropertyNode *elevator - = fgGetNode("/controls/elevator"); - static const SGPropertyNode *elevator_trim - = fgGetNode("/controls/elevator-trim"); - static const SGPropertyNode *rudder - = fgGetNode("/controls/rudder"); - static const SGPropertyNode *flaps - = fgGetNode("/controls/flaps"); - char buf[256]; - // fill in values + SGPropertyNode * node = fgGetNode("/controls", true); raw->version = FG_RAW_CTRLS_VERSION; - raw->aileron = fgGetDouble( "/controls/aileron" ); - raw->elevator = fgGetDouble( "/controls/elevator" ); - raw->elevator_trim = fgGetDouble( "/controls/elevator-trim" ); - raw->rudder = fgGetDouble( "/controls/rudder" ); - raw->flaps = fgGetDouble( "/controls/flaps" ); - for ( i = 0; i < FG_MAX_ENGINES; ++i ) { - sprintf( buf, "/controls/throttle[%d]", i ); - raw->throttle[i] = fgGetDouble( buf ); - sprintf( buf, "/controls/mixture[%d]", i ); - raw->mixture[i] = fgGetDouble( buf ); - sprintf( buf, "/controls/propeller-pitch[%d]", i ); - raw->prop_advance[i] = fgGetDouble( buf ); + raw->aileron = node->getDoubleValue( "aileron" ); + raw->elevator = node->getDoubleValue( "elevator" ); + raw->elevator_trim = node->getDoubleValue( "elevator-trim" ); + raw->rudder = node->getDoubleValue( "rudder" ); + raw->flaps = node->getDoubleValue( "flaps" ); + for ( i = 0; i < FGRawCtrls::FG_MAX_ENGINES; ++i ) { + raw->throttle[i] = node->getDoubleValue( "throttle", 0.0 ); + raw->mixture[i] = node->getDoubleValue( "mixture", 0.0 ); + raw->prop_advance[i] = node->getDoubleValue( "propeller-pitch", 0.0 ); + raw->magnetos[i] = node->getIntValue( "magnetos", 0 ); + if ( i == 0 ) { + // cout << "Magnetos -> " << node->getIntValue( "magnetos", 0 ); + } + raw->starter[i] = node->getBoolValue( "starter", false ); + if ( i == 0 ) { + // cout << " Starter -> " << node->getIntValue( "stater", false ) + // << endl; + } } - for ( i = 0; i < FG_MAX_WHEELS; ++i ) { - sprintf( buf, "/controls/brakes[%d]", i ); - raw->brake[i] = fgGetDouble( buf ); + for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) { + raw->brake[i] = node->getDoubleValue( "brakes", 0.0 ); } raw->hground = fgGetDouble( "/environment/ground-elevation-m" ); + raw->magvar = fgGetDouble("/environment/magnetic-variation-deg"); + raw->speedup = fgGetInt("/sim/speed-up"); // convert to network byte order raw->version = htonl(raw->version); @@ -105,37 +101,72 @@ static void global2raw( FGRawCtrls *raw ) { htond(raw->elevator_trim); htond(raw->rudder); htond(raw->flaps); - for ( i = 0; i < FG_MAX_ENGINES; ++i ) { + for ( i = 0; i < FGRawCtrls::FG_MAX_ENGINES; ++i ) { htond(raw->throttle[i]); htond(raw->mixture[i]); htond(raw->prop_advance[i]); + htonl(raw->magnetos[i]); + htonl(raw->starter[i]); } - for ( i = 0; i < FG_MAX_WHEELS; ++i ) { + for ( i = 0; i < FGRawCtrls::FG_MAX_WHEELS; ++i ) { htond(raw->brake[i]); } htond(raw->hground); - + htond(raw->magvar); + raw->speedup = htonl(raw->speedup); } static void net2global( FGNetFDM *net ) { + int i; + // Convert to the net buffer from network format net->version = ntohl(net->version); + htond(net->longitude); htond(net->latitude); htond(net->altitude); htond(net->phi); htond(net->theta); htond(net->psi); + + htond(net->phidot); + htond(net->thetadot); + htond(net->psidot); htond(net->vcas); htond(net->climb_rate); + + htond(net->A_X_pilot); + htond(net->A_Y_pilot); + htond(net->A_Z_pilot); + + net->num_engines = htonl(net->num_engines); + for ( i = 0; i < net->num_engines; ++i ) { + htonl(net->eng_state[i]); + htond(net->rpm[i]); + htond(net->fuel_flow[i]); + htond(net->EGT[i]); + htond(net->oil_temp[i]); + htond(net->oil_px[i]); + } + + net->num_tanks = htonl(net->num_tanks); + for ( i = 0; i < net->num_tanks; ++i ) { + htond(net->fuel_quantity[i]); + } + + net->num_wheels = htonl(net->num_wheels); + // I don't need to convert the Wow flags, since they are one byte in size + htond(net->flap_deflection); + net->cur_time = ntohl(net->cur_time); net->warp = ntohl(net->warp); htond(net->visibility); if ( net->version == FG_NET_FDM_VERSION ) { // cout << "pos = " << net->longitude << " " << net->latitude << endl; - // cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius() << endl; + // cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius() + // << endl; cur_fdm_state->_updateGeodeticPosition( net->latitude, net->longitude, net->altitude @@ -143,8 +174,62 @@ static void net2global( FGNetFDM *net ) { cur_fdm_state->_set_Euler_Angles( net->phi, net->theta, net->psi ); + cur_fdm_state->_set_Euler_Rates( net->phidot, + net->thetadot, + net->psidot ); cur_fdm_state->_set_V_calibrated_kts( net->vcas ); cur_fdm_state->_set_Climb_Rate( net->climb_rate ); + cur_fdm_state->_set_Accels_Pilot_Body( net->A_X_pilot, + net->A_Y_pilot, + net->A_Z_pilot ); + + for ( i = 0; i < net->num_engines; ++i ) { + SGPropertyNode *node = fgGetNode( "engines/engine", i, true ); + + // node->setBoolValue("running", t->isRunning()); + // node->setBoolValue("cranking", t->isCranking()); + + // cout << net->eng_state[i] << endl; + if ( net->eng_state[i] == 0 ) { + node->setBoolValue( "cranking", false ); + node->setBoolValue( "running", false ); + } else if ( net->eng_state[i] == 1 ) { + node->setBoolValue( "cranking", true ); + node->setBoolValue( "running", false ); + } else if ( net->eng_state[i] == 2 ) { + node->setBoolValue( "cranking", false ); + node->setBoolValue( "running", true ); + } + + node->setDoubleValue( "rpm", net->rpm[i] ); + node->setDoubleValue( "fuel-flow-gph", net->fuel_flow[i] ); + node->setDoubleValue( "egt-degf", net->EGT[i] ); + node->setDoubleValue( "oil-temperature-degf", net->oil_temp[i] ); + node->setDoubleValue( "oil-pressure-psi", net->oil_px[i] ); + } + + for (i = 0; i < net->num_tanks; ++i ) { + SGPropertyNode * node + = fgGetNode("/consumables/fuel/tank", i, true); + node->setDoubleValue("level-gal_us", net->fuel_quantity[i] ); + } + + for (i = 0; i < net->num_wheels; ++i ) { + SGPropertyNode * node + = fgGetNode("/gear/gear", i, true); + node->setDoubleValue("wow", net->wow[i] ); + } + + fgSetDouble("/surface-positions/flap-pos-norm", net->flap_deflection); + SGPropertyNode * node = fgGetNode("/controls", true); + fgSetDouble("/surface-positions/elevator-pos-norm", + node->getDoubleValue( "elevator" )); + fgSetDouble("/surface-positions/rudder-pos-norm", + node->getDoubleValue( "rudder" )); + fgSetDouble("/surface-positions/left-aileron-pos-norm", + node->getDoubleValue( "aileron" )); + fgSetDouble("/surface-positions/right-aileron-pos-norm", + -node->getDoubleValue( "aileron" )); /* these are ignored for now ... */ /* @@ -165,10 +250,9 @@ static void net2global( FGNetFDM *net ) { } -FGExternalNet::FGExternalNet( double dt, int dop, int dip, int cp, - string host ) +FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp ) { - set_delta_t( dt ); +// set_delta_t( dt ); valid = true; @@ -261,13 +345,14 @@ void FGExternalNet::init() { } -// Run an iteration of the EOM. This is a NOP here because the flight -// model values are getting filled in elsewhere (most likely from some -// external source.) -void FGExternalNet::update( int multiloop ) { +// Run an iteration of the EOM. +void FGExternalNet::update( double dt ) { int length; int result; + if (is_suspended()) + return; + // Send control positions to remote fdm length = sizeof(ctrls); global2raw( &ctrls ); @@ -277,7 +362,7 @@ void FGExternalNet::update( int multiloop ) { // Read next set of FDM data (blocking enabled to maintain 'sync') length = sizeof(fdm); - if ( (result = data_server.recv( (char *)(& fdm), length, 0)) >= 0 ) { + while ( (result = data_server.recv( (char *)(& fdm), length, 0)) >= 0 ) { SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); net2global( &fdm ); }