//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
# include <unistd.h> // unlink()
#endif
+#include <cstring>
#include <stdio.h> // FILE*, fopen(), fread(), fwrite(), et. al.
+#include <iostream> // for cout, endl
#include <simgear/debug/logstream.hxx>
#include <simgear/io/lowlevel.hxx> // endian tests
#include "ExternalPipe.hxx"
+using std::cout;
+using std::endl;
static const int MAX_BUF = 32768;
memcpy( buf + 3, cmd, len );
if ( cmd_type == '1' ) {
- cout << "writing '";
- for ( int i = 0; i < len + 3; ++i ) {
+ cout << "writing ";
+ cout << (int)hi << " ";
+ cout << (int)lo << " '";
+ for ( int i = 2; i < len + 3; ++i ) {
cout << buf[i];
}
cout << "' (" << cmd << ")" << endl;
} else if ( cmd_type == '2' ) {
- cout << "writing controls packet" << endl;
+ // cout << "writing controls packet" << endl;
} else {
cout << "writing unknown command?" << endl;
}
double lon = fgGetDouble( "/sim/presets/longitude-deg" );
double lat = fgGetDouble( "/sim/presets/latitude-deg" );
double alt = fgGetDouble( "/sim/presets/altitude-ft" );
- double ground = fgGetDouble( "/environment/ground-elevation-m" );
+ double ground = get_Runway_altitude_m();
double heading = fgGetDouble("/sim/presets/heading-deg");
double speed = fgGetDouble( "/sim/presets/airspeed-kt" );
double weight = fgGetDouble( "/sim/aircraft-weight-lbs" );
double lon = fgGetDouble( "/sim/presets/longitude-deg" );
double lat = fgGetDouble( "/sim/presets/latitude-deg" );
double alt = fgGetDouble( "/sim/presets/altitude-ft" );
- double ground = fgGetDouble( "/environment/ground-elevation-m" );
+ double ground = get_Runway_altitude_m();
double heading = fgGetDouble("/sim/presets/heading-deg");
double speed = fgGetDouble( "/sim/presets/airspeed-kt" );
double weight = fgGetDouble( "/sim/aircraft-weight-lbs" );
// cout << "iterations = " << iterations << endl;
ptr += sizeof(int);
memcpy( ptr, (char *)(&ctrls), length );
- cout << "writing control structure, size = "
- << length + sizeof(int) << endl;
+ // cout << "writing control structure, size = "
+ // << length + sizeof(int) << endl;
result = write_binary( '2', pd1, buf, length + sizeof(int) );
fflush( pd1 );
// Read fdm values
length = sizeof(fdm);
- cout << "about to read fdm data from remote fdm." << endl;
+ // cout << "about to read fdm data from remote fdm." << endl;
result = fread( (char *)(& fdm), length, 1, pd2 );
if ( result != 1 ) {
SG_LOG( SG_IO, SG_ALERT, "Read error from named pipe: "
<< fifo_name_2 << " expected 1 item, but got " << result );
} else {
- cout << " read successful." << endl;
+ // cout << " read successful." << endl;
+ FGNetFDM2Props( &fdm, false );
}
- FGNetFDM2Props( &fdm, false );
#endif
}
// Process remote FDM "set" commands
-static void process_set_command( const string_list &tokens ) {
+
+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() );
- cur_fdm_state->_updateGeodeticPosition( lat_rad, lon_rad,
+ _updateGeodeticPosition( lat_rad, lon_rad,
alt_m * SG_METER_TO_FEET );
- double agl_m = alt_m - cur_fdm_state->get_Runway_altitude_m();
- cur_fdm_state->_set_Altitude_AGL( agl_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() );
- cur_fdm_state->_set_Euler_Angles( phi_rad, theta_rad, psi_rad );
+ _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() );
- cur_fdm_state->_set_Euler_Rates( phidot, thetadot, psidot );
+ _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" ) {
- cur_fdm_state->_set_Alpha( atof(tokens[2].c_str()) );
+ _set_Alpha( atof(tokens[2].c_str()) );
} else if ( tokens[1] == "beta" ) {
- cur_fdm_state->_set_Beta( atof(tokens[2].c_str()) );
+ _set_Beta( atof(tokens[2].c_str()) );
#if 0
- cur_fdm_state->_set_V_calibrated_kts( net->vcas );
- cur_fdm_state->_set_Climb_Rate( net->climb_rate );
- cur_fdm_state->_set_Velocities_Local( net->v_north,
+ _set_V_calibrated_kts( net->vcas );
+ _set_Climb_Rate( net->climb_rate );
+ _set_Velocities_Local( net->v_north,
net->v_east,
net->v_down );
- cur_fdm_state->_set_Velocities_Wind_Body( net->v_wind_body_north,
+ _set_Velocities_Wind_Body( net->v_wind_body_north,
net->v_wind_body_east,
net->v_wind_body_down );
- cur_fdm_state->_set_Accels_Pilot_Body( net->A_X_pilot,
+ _set_Accels_Pilot_Body( net->A_X_pilot,
net->A_Y_pilot,
net->A_Z_pilot );
#endif
cout << "Error reading data" << endl;
} else {
// cout << " read " << strlen(cmd) << " bytes" << endl;
+ // cout << cmd << endl;
}
// chop trailing newline
// node doesn't exist so create with requested type
node = fgGetNode( tokens[1].c_str(), true );
if ( tokens[2] == "bool" ) {
- node->setBoolValue(true);
+ node->setBoolValue(false);
} else if ( tokens[2] == "int" ) {
node->setIntValue(0);
} else if ( tokens[2] == "double" ) {