]> git.mxchange.org Git - flightgear.git/commitdiff
Add support for sending out a requested aircraft weight to an external FDM
authorcurt <curt>
Mon, 10 Nov 2003 21:56:32 +0000 (21:56 +0000)
committercurt <curt>
Mon, 10 Nov 2003 21:56:32 +0000 (21:56 +0000)
via the "pipe" interface.

src/FDM/ExternalPipe/ExternalPipe.cxx

index 12a738bf639e2743bd518e29339fba1854eb5d89..3ebb328128de8afa0e25709a87b159823c84ea91 100644 (file)
@@ -1,4 +1,4 @@
-// ExternalPipe.hxx -- a "pipe" interface to an external flight dynamics model
+// ExternalPipe.cxx -- a "pipe" interface to an external flight dynamics model
 //
 // Written by Curtis Olson, started March 2003.
 //
@@ -117,6 +117,7 @@ void FGExternalPipe::init() {
     double ground = fgGetDouble( "/environment/ground-elevation-m" );
     double heading = fgGetDouble("/sim/presets/heading-deg");
     double speed = fgGetDouble( "/sim/presets/airspeed-kt" );
+    double weight = fgGetDouble( "/sim/aircraft-weight-lbs" );
 
 #ifdef HAVE_MKFIFO
 
@@ -159,6 +160,14 @@ void FGExternalPipe::init() {
         SG_LOG( SG_IO, SG_ALERT, "Write error to named pipe: " << fifo_name_1 );
     }
 
+    if ( weight > 1000.0 ) {
+      sprintf( cmd, "1aircraft-weight-lbs=%.2f", weight );
+      result = write( pd1, cmd, strlen(cmd) );
+      if ( result == -1 ) {
+        SG_LOG( SG_IO, SG_ALERT, "Write error to named pipe: " << fifo_name_1 );
+      }
+    }
+
     SG_LOG( SG_IO, SG_INFO, "before sending reset command." );
 
     if( fgGetBool("/sim/presets/onground") ) {
@@ -183,13 +192,25 @@ void FGExternalPipe::update( double dt ) {
 
     int length;
     int result;
-
+    
     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 ) {
+      char cmd[256];
+      sprintf( cmd, "1aircraft-weight-lbs=%.2f", weight );
+      result = write( pd1, cmd, strlen(cmd) );
+      if ( result == -1 ) {
+        SG_LOG( SG_IO, SG_ALERT, "Write error to named pipe: " << fifo_name_1 );
+      }
+    }
+    last_weight = weight;
+
     // Send control positions to remote fdm
     length = sizeof(ctrls);
     FGProps2NetCtrls( &ctrls, true, false );
@@ -205,6 +226,7 @@ void FGExternalPipe::update( double dt ) {
                 << fifo_name_1 );
     }
 
+    // Read fdm values
     length = sizeof(fdm);
     result = read( pd2, (char *)(& fdm), length );
     if ( result == -1 ) {