X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2FATC-Main.cxx;h=b70b4abf36eb584ce1d6ffd726a8d093000c1f64;hb=c47d4f2f3024336c4e11b769880ca6fbefda082d;hp=45f491d363f52ca13eeb7295907806f1dfeb77d9;hpb=ec827732226e905a8a0ce9af700b63b183b18c5c;p=flightgear.git diff --git a/src/Network/ATC-Main.cxx b/src/Network/ATC-Main.cxx index 45f491d36..b70b4abf3 100644 --- a/src/Network/ATC-Main.cxx +++ b/src/Network/ATC-Main.cxx @@ -16,7 +16,7 @@ // // 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$ @@ -32,15 +32,16 @@ #include #include #include //snprintf -#if defined( _MSC_VER ) || defined(__MINGW32__) +#ifdef _WIN32 # include //lseek, read, write #endif -#include STL_STRING +#include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ #include "ATC-Main.hxx" -SG_USING_STD(string); +using std::string; // Lock the ATC hardware @@ -94,7 +95,15 @@ void FGATCMain::init_config() { if ( envp != NULL ) { SGPath atcsim_config( envp ); atcsim_config.append( ".fgfs-atc610x.xml" ); - readProperties( atcsim_config.str(), globals->get_props() ); + try { + SG_LOG(SG_GENERAL, SG_ALERT, + "Warning: loading deprecated config file: " << + atcsim_config.str() ); + readProperties( atcsim_config.str(), globals->get_props() ); + } catch (const sg_exception &e) { + // fail silently, this is an old style config file I want to continue + // to support if it exists. + } } #endif } @@ -118,8 +127,8 @@ bool FGATCMain::open() { // Open the /proc files ///////////////////////////////////////////////////////////////////// - string lock0_file = "/proc/atc610x/board0/lock"; - string lock1_file = "/proc/atc610x/board1/lock"; + string lock0_file = "/proc/atcflightsim/board0/lock"; + string lock1_file = "/proc/atcflightsim/board1/lock"; lock0_fd = ::open( lock0_file.c_str(), O_RDWR ); if ( lock0_fd == -1 ) { @@ -171,21 +180,35 @@ bool FGATCMain::open() { bool FGATCMain::process() { - // Lock the hardware, skip if it's not ready yet - if ( fgATCMainLock( lock0_fd ) <= 0 ) { - return false; + // cout << "Main::process()\n"; + + bool board0_locked = false; + bool board1_locked = false; + + if ( input0 != NULL || output0 != NULL ) { + // Lock board0 if we have a configuration for it + if ( fgATCMainLock( lock0_fd ) > 0 ) { + board0_locked = true; + } } - if ( fgATCMainLock( lock1_fd ) <= 0 ) { - // lock0 will be locked here, so release before we return - fgATCMainRelease( lock0_fd ); - return false; + + if ( input1 != NULL || output1 != NULL ) { + // Lock board1 if we have a configuration for it + if ( fgATCMainLock( lock1_fd ) > 0 ) { + board1_locked = true; + } } + // cout << " locks: "; + // if ( board0_locked ) { cout << "board0 "; } + // if ( board1_locked ) { cout << "board1 "; } + // cout << endl; + // process the ATC inputs - if ( input0 != NULL ) { + if ( input0 != NULL && board0_locked ) { input0->process(); } - if ( input1 != NULL ) { + if ( input1 != NULL && board1_locked ) { input1->process(); } @@ -197,30 +220,48 @@ bool FGATCMain::process() { // directly provide. FGNasalSys *n = (FGNasalSys*)globals->get_subsystem("nasal"); - bool result = n->parseAndRun( "atcsim.do_hardware()" ); + bool result = n->parseAndRun( "atcsim.update()" ); if ( !result ) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Nasal: atcsim.do_hardware() failed!" ); + SG_LOG( SG_GENERAL, SG_ALERT, "Nasal: atcsim.update() failed!" ); } // process the ATC outputs - if ( output0 != NULL ) { + if ( output0 != NULL && board0_locked ) { output0->process(); } - if ( output1 != NULL ) { + if ( output1 != NULL && board1_locked ) { output1->process(); } - fgATCMainRelease( lock0_fd ); - fgATCMainRelease( lock1_fd ); + if ( board0_locked ) { + fgATCMainRelease( lock0_fd ); + } + if ( board1_locked ) { + fgATCMainRelease( lock1_fd ); + } return true; } bool FGATCMain::close() { + cout << "FGATCMain::close()" << endl; + int result; + if ( input0 != NULL ) { + input0->close(); + } + if ( input1 != NULL ) { + input1->close(); + } + if ( output0 != NULL ) { + output0->close(); + } + if ( output1 != NULL ) { + output1->close(); + } + result = ::close( lock0_fd ); if ( result == -1 ) { SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );