]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/ATC-Outputs.cxx
Update 'magic' for more consistant cross platform padding.
[flightgear.git] / src / Network / ATC-Outputs.cxx
index b73637f80715bec4eed61facf342e4e75c370df2..bb3d265c403727c71a17f4ec2cba2150db504d26 100644 (file)
 #  include <sys/types.h>
 #  include <sys/stat.h>
 #  include <fcntl.h>
+#  include <unistd.h>
+#  include <ostream>
 #endif
 
+#include <errno.h>
+#include <math.h>
+
 #include STL_STRING
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/sg_path.hxx>
 
 #include <Main/fg_props.hxx>
 
@@ -47,6 +53,7 @@ SG_USING_STD(string);
 
 // Lock the ATC hardware
 static int ATCLock( int fd ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     // rewind
     lseek( fd, 0, SEEK_SET );
 
@@ -57,11 +64,15 @@ static int ATCLock( int fd ) {
     }
 
     return result;
+#else
+    return -1;
+#endif
 }
 
 
 // Release the ATC hardware
 static int ATCRelease( int fd ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     // rewind
     lseek( fd, 0, SEEK_SET );
 
@@ -74,6 +85,9 @@ static int ATCRelease( int fd ) {
     }
 
     return result;
+#else
+    return -1;
+#endif
 }
 
 
@@ -93,6 +107,7 @@ FGATCOutput::FGATCOutput( const int _board, const SGPath &_config_file ) :
 
 // Write a radios command
 static int ATCSetRadios( int fd, unsigned char data[ATC_RADIO_DISPLAY_BYTES] ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     // rewind
     lseek( fd, 0, SEEK_SET );
 
@@ -103,6 +118,9 @@ static int ATCSetRadios( int fd, unsigned char data[ATC_RADIO_DISPLAY_BYTES] ) {
     }
 
     return result;
+#else
+    return -1;
+#endif
 }
 
 
@@ -110,6 +128,7 @@ static int ATCSetRadios( int fd, unsigned char data[ATC_RADIO_DISPLAY_BYTES] ) {
 static int ATCSetStepper( int fd, unsigned char channel,
                              unsigned char value )
 {
+#if defined( unix ) || defined( __CYGWIN__ )
     // rewind
     lseek( fd, 0, SEEK_SET );
 
@@ -125,11 +144,15 @@ static int ATCSetStepper( int fd, unsigned char channel,
     SG_LOG( SG_IO, SG_DEBUG,
            "Sent cmd = " << (int)channel << " value = " << (int)value );
     return result;
+#else
+    return -1;
+#endif
 }
 
 
 // Read status of last stepper written to
 static unsigned char ATCReadStepper( int fd ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     int result;
 
     // rewind
@@ -145,11 +168,15 @@ static unsigned char ATCReadStepper( int fd ) {
     SG_LOG( SG_IO, SG_DEBUG, "Read result = " << (int)buf[0] );
 
     return buf[0];
+#else
+    return 0;
+#endif
 }
 
 
 // Turn a lamp on or off
 void ATCSetLamp( int fd, int channel, bool value ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     // lamp channels 0-63 are written to LampPort0, channels 64-127
     // are written to LampPort1
 
@@ -168,6 +195,7 @@ void ATCSetLamp( int fd, int channel, bool value ) {
         SG_LOG( SG_IO, SG_ALERT,  "Write failed" );
         exit( -1 );
     }
+#endif
 }
 
 
@@ -201,11 +229,14 @@ bool FGATCOutput::open( int lock_fd ) {
     init_config();
 
     SG_LOG( SG_IO, SG_ALERT,
-           "Initializing ATC hardware, please wait ..." );
+           "Initializing ATC output hardware, please wait ..." );
 
-    snprintf( lamps_file, 256, "/proc/atc610x/board%d/lamps", board );
-    snprintf( radio_display_file, 256, "/proc/atc610x/board%d/radios", board );
-    snprintf( stepper_file, 256, "/proc/atc610x/board%d/steppers", board );
+    snprintf( lamps_file, 256,
+              "/proc/atcflightsim/board%d/lamps", board );
+    snprintf( radio_display_file, 256,
+              "/proc/atcflightsim/board%d/radios", board );
+    snprintf( stepper_file, 256,
+              "/proc/atcflightsim/board%d/steppers", board );
 
 #if defined( unix ) || defined( __CYGWIN__ )
 
@@ -242,6 +273,7 @@ bool FGATCOutput::open( int lock_fd ) {
 
 #endif
 
+#ifdef ATCFLIGHTSIM_HAVE_COMPASS
     /////////////////////////////////////////////////////////////////////
     // Home the compass stepper motor
     /////////////////////////////////////////////////////////////////////
@@ -292,6 +324,7 @@ bool FGATCOutput::open( int lock_fd ) {
     }
 
     compass_position = 0.0;
+#endif
 
     /////////////////////////////////////////////////////////////////////
     // Blank the radio display
@@ -327,7 +360,7 @@ bool FGATCOutput::open( int lock_fd ) {
     /////////////////////////////////////////////////////////////////////
 
     SG_LOG( SG_IO, SG_ALERT,
-           "Done initializing ATC hardware." );
+           "Done initializing ATC output hardware." );
 
     is_open = true;
 
@@ -355,7 +388,6 @@ bool FGATCOutput::open( int lock_fd ) {
 /////////////////////////////////////////////////////////////////////
 
 bool FGATCOutput::do_lamps() {
-
     if ( lamps_out_node != NULL ) {
         for ( int i = 0; i < lamps_out_node->nChildren(); ++i ) {
             // read the next config entry from the property tree
@@ -402,7 +434,7 @@ static bool navcom1_has_power() {
     static SGPropertyNode *navcom1_bus_power
         = fgGetNode( "/systems/electrical/outputs/nav[0]", true );
     static SGPropertyNode *navcom1_power_btn
-        = fgGetNode( "/instrumentation/comm[0]/inputs/power-btn", true );
+        = fgGetNode( "/instrumentation/nav[0]/power-btn", true );
 
     return (navcom1_bus_power->getDoubleValue() > 1.0)
         && navcom1_power_btn->getBoolValue();
@@ -412,7 +444,7 @@ static bool navcom2_has_power() {
     static SGPropertyNode *navcom2_bus_power
         = fgGetNode( "/systems/electrical/outputs/nav[1]", true );
     static SGPropertyNode *navcom2_power_btn
-        = fgGetNode( "/instrumentation/comm[1]/inputs/power-btn", true );
+        = fgGetNode( "/instrumentation/nav[1]/power-btn", true );
 
     return (navcom2_bus_power->getDoubleValue() > 1.0)
         && navcom2_power_btn->getBoolValue();
@@ -439,7 +471,7 @@ static bool xpdr_has_power() {
     static SGPropertyNode *xpdr_bus_power
         = fgGetNode( "/systems/electrical/outputs/transponder", true );
     static SGPropertyNode *xpdr_func_knob
-        = fgGetNode( "/instrumentation/kt-70/inputs/func-knob", true );
+        = fgGetNode( "/instrumentation/transponder/inputs/func-knob", true );
 
     return (xpdr_bus_power->getDoubleValue() > 1.0)
         && (xpdr_func_knob->getIntValue() > 0);
@@ -503,13 +535,13 @@ bool FGATCOutput::do_radio_display() {
         = fgGetNode( "/instrumentation/kr-87/outputs/elapsed-timer", true );
 
     static SGPropertyNode *xpdr_serviceable
-        = fgGetNode( "/instrumentation/kt-70/inputs/serviceable", true );
+        = fgGetNode( "/instrumentation/transponder/inputs/serviceable", true );
     static SGPropertyNode *xpdr_func_knob
-        = fgGetNode( "/instrumentation/kt-70/inputs/func-knob", true );
+        = fgGetNode( "/instrumentation/transponder/inputs/func-knob", true );
     static SGPropertyNode *xpdr_flight_level
-        = fgGetNode( "/instrumentation/kt-70/outputs/flight-level", true );
+        = fgGetNode( "/instrumentation/transponder/outputs/flight-level", true );
     static SGPropertyNode *xpdr_id_code
-        = fgGetNode( "/instrumentation/kt-70/outputs/id-code", true );
+        = fgGetNode( "/instrumentation/transponder/outputs/id-code", true );
 
     char digits[10];
     int i;
@@ -905,7 +937,9 @@ bool FGATCOutput::process() {
 
     do_lamps();
     do_radio_display();
+#ifdef ATCFLIGHTSIM_HAVE_COMPASS
     do_steppers();
+#endif
        
     return true;
 }
@@ -915,6 +949,10 @@ bool FGATCOutput::close() {
 
 #if defined( unix ) || defined( __CYGWIN__ )
 
+    if ( !is_open ) {
+        return true;
+    }
+
     int result;
 
     result = ::close( lamps_fd );