+
+
+// Process remote FDM "set" commands
+
+void FGExternalPipe::process_set_command( const string_list &tokens ) {
+ if ( tokens[1] == "geodetic_position" ) {
+ double lat_rad = atof( tokens[2].c_str() );
+ double lon_rad = atof( tokens[3].c_str() );
+ double alt_m = atof( tokens[4].c_str() );
+ _updateGeodeticPosition( lat_rad, lon_rad,
+ alt_m * SG_METER_TO_FEET );
+
+ double agl_m = alt_m - get_Runway_altitude_m();
+ _set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
+ } else if ( tokens[1] == "euler_angles" ) {
+ double phi_rad = atof( tokens[2].c_str() );
+ double theta_rad = atof( tokens[3].c_str() );
+ double psi_rad = atof( tokens[4].c_str() );
+ _set_Euler_Angles( phi_rad, theta_rad, psi_rad );
+ } else if ( tokens[1] == "euler_rates" ) {
+ double phidot = atof( tokens[2].c_str() );
+ double thetadot = atof( tokens[3].c_str() );
+ double psidot = atof( tokens[4].c_str() );
+ _set_Euler_Rates( phidot, thetadot, psidot );
+ } else if ( tokens[1] == "ned" ) {
+ double north_fps = atof( tokens[2].c_str() );
+ double east_fps = atof( tokens[3].c_str() );
+ double down_fps = atof( tokens[4].c_str() );
+ _set_Velocities_Local( north_fps, east_fps, down_fps );
+ } else if ( tokens[1] == "alpha" ) {
+ _set_Alpha( atof(tokens[2].c_str()) );
+ } else if ( tokens[1] == "beta" ) {
+ _set_Beta( atof(tokens[2].c_str()) );
+
+#if 0
+ _set_V_calibrated_kts( net->vcas );
+ _set_Climb_Rate( net->climb_rate );
+ _set_Velocities_Local( net->v_north,
+ net->v_east,
+ net->v_down );
+ _set_Velocities_Wind_Body( net->v_wind_body_north,
+ net->v_wind_body_east,
+ net->v_wind_body_down );
+
+ _set_Accels_Pilot_Body( net->A_X_pilot,
+ net->A_Y_pilot,
+ net->A_Z_pilot );
+#endif
+ } else {
+ fgSetString( tokens[1].c_str(), tokens[2].c_str() );
+ }
+}
+
+
+// Run an iteration of the EOM.
+void FGExternalPipe::update_property( double dt ) {
+ // cout << "update_property()" << endl;
+
+#ifdef HAVE_MKFIFO
+ // SG_LOG( SG_IO, SG_INFO, "Start FGExternalPipe::udpate()" );
+
+ int result;
+ char cmd[256];
+
+ if ( is_suspended() ) {
+ return;
+ }
+
+ int iterations = _calc_multiloop(dt);
+
+ double weight = fgGetDouble( "/sim/aircraft-weight-lbs" );
+ static double last_weight = 0.0;
+ if ( fabs( weight - last_weight ) > 0.01 ) {
+ sprintf( cmd, "init aircraft-weight-lbs=%.2f", weight );
+ result = write_property( pd1, cmd );
+ }
+ last_weight = weight;
+
+ double cg_offset = fgGetDouble( "/sim/aircraft-cg-offset-inches" );
+ if ( fabs( cg_offset - last_cg_offset ) > 0.01 ) {
+ sprintf( cmd, "init aircraft-cg-offset-inches=%.2f", cg_offset );
+ result = write_property( pd1, cmd );
+ }
+ last_cg_offset = cg_offset;
+
+ // Send requested property values to fdm
+ for ( unsigned int i = 0; i < nodes.size(); i++ ) {
+ sprintf( cmd, "set %s %s", property_names[i].c_str(),
+ nodes[i]->getStringValue() );
+ // cout << " sending " << cmd << endl;
+ result = write_property( pd1, cmd );
+ }
+
+ sprintf( cmd, "update %d", iterations );
+ write_property( pd1, cmd );
+
+ fflush( pd1 );
+
+ // Read FDM response
+ // cout << "ready to read fdm response" << endl;
+ bool done = false;
+ while ( !done ) {
+ if ( fgets( cmd, 256, pd2 ) == NULL ) {
+ cout << "Error reading data" << endl;
+ } else {
+ // cout << " read " << strlen(cmd) << " bytes" << endl;
+ // cout << cmd << endl;
+ }
+
+ // chop trailing newline
+ cmd[strlen(cmd)-1] = '\0';
+
+ // cout << cmd << endl;
+ string_list tokens = simgear::strutils::split( cmd, " " );
+
+ if ( tokens[0] == "request" ) {
+ // save the long form name
+ property_names.push_back( tokens[1] );
+
+ // now do the property name lookup and cache the pointer
+ SGPropertyNode *node = fgGetNode( tokens[1].c_str() );
+ if ( node == NULL ) {
+ // node doesn't exist so create with requested type
+ node = fgGetNode( tokens[1].c_str(), true );
+ if ( tokens[2] == "bool" ) {
+ node->setBoolValue(false);
+ } else if ( tokens[2] == "int" ) {
+ node->setIntValue(0);
+ } else if ( tokens[2] == "double" ) {
+ node->setDoubleValue(0.0);
+ } else if ( tokens[2] == "string" ) {
+ node->setStringValue("");
+ } else {
+ cout << "Unknown data type: " << tokens[2]
+ << " for " << tokens[1] << endl;
+ }
+ }
+ nodes.push_back( node );
+ } else if ( tokens[0] == "set" ) {
+ process_set_command( tokens );
+ } else if ( tokens[0] == "update" ) {
+ done = true;
+ } else {
+ cout << "unknown command = " << cmd << endl;
+ }
+ }
+
+#endif
+}
+
+