2004-12-24 01:23:27 +00:00
|
|
|
// ATC-Outputs.hxx -- Translate FGFS properties to ATC hardware outputs.
|
2002-02-05 04:42:39 +00:00
|
|
|
//
|
2004-12-24 01:23:27 +00:00
|
|
|
// Written by Curtis Olson, started November 2004.
|
2002-02-05 04:42:39 +00:00
|
|
|
//
|
2004-12-24 01:23:27 +00:00
|
|
|
// Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
|
2002-02-05 04:42:39 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
#if defined( unix ) || defined( __CYGWIN__ )
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <fcntl.h>
|
2002-02-08 00:07:53 +00:00
|
|
|
#endif
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
#include STL_STRING
|
|
|
|
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
#include "ATC-Outputs.hxx"
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
SG_USING_STD(string);
|
|
|
|
|
2002-12-16 01:12:10 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
|
|
|
|
// Lock the ATC hardware
|
|
|
|
static int ATCLock( int fd ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
// rewind
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
|
|
|
|
char tmp[2];
|
|
|
|
int result = read( fd, tmp, 1 );
|
|
|
|
if ( result != 1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, "Lock failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
// Release the ATC hardware
|
|
|
|
static int ATCRelease( int fd ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
// rewind
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
|
|
|
|
char tmp[2];
|
|
|
|
tmp[0] = tmp[1] = 0;
|
|
|
|
int result = write( fd, tmp, 1 );
|
|
|
|
|
|
|
|
if ( result != 1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, "Release failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
// Constructor: The _board parameter specifies which board to
|
|
|
|
// reference. Possible values are 0 or 1. The _config_file parameter
|
|
|
|
// specifies the location of the output config file (xml)
|
|
|
|
FGATCOutput::FGATCOutput( const int _board, const SGPath &_config_file ) :
|
|
|
|
is_open(false),
|
|
|
|
lamps_out_node(NULL),
|
|
|
|
radio_display_node(NULL),
|
|
|
|
steppers_node(NULL)
|
2002-02-05 04:42:39 +00:00
|
|
|
{
|
2004-12-24 01:23:27 +00:00
|
|
|
board = _board;
|
|
|
|
config = _config_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write a radios command
|
|
|
|
static int ATCSetRadios( int fd, unsigned char data[ATC_RADIO_DISPLAY_BYTES] ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
// rewind
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
|
|
|
|
int result = write( fd, data, ATC_RADIO_DISPLAY_BYTES );
|
|
|
|
|
|
|
|
if ( result != ATC_RADIO_DISPLAY_BYTES ) {
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, "Write failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write a stepper command
|
2004-12-24 01:23:27 +00:00
|
|
|
static int ATCSetStepper( int fd, unsigned char channel,
|
2002-02-05 04:42:39 +00:00
|
|
|
unsigned char value )
|
|
|
|
{
|
|
|
|
// rewind
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
|
|
|
|
// Write the value
|
|
|
|
unsigned char buf[3];
|
|
|
|
buf[0] = channel;
|
|
|
|
buf[1] = value;
|
|
|
|
buf[2] = 0;
|
|
|
|
int result = write( fd, buf, 2 );
|
|
|
|
if ( result != 2 ) {
|
|
|
|
SG_LOG( SG_IO, SG_INFO, "Write failed" );
|
|
|
|
}
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG,
|
|
|
|
"Sent cmd = " << (int)channel << " value = " << (int)value );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Read status of last stepper written to
|
2004-12-24 01:23:27 +00:00
|
|
|
static unsigned char ATCReadStepper( int fd ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
// rewind
|
|
|
|
lseek( fd, 0, SEEK_SET );
|
|
|
|
|
|
|
|
// Write the value
|
|
|
|
unsigned char buf[2];
|
|
|
|
result = read( fd, buf, 1 );
|
|
|
|
if ( result != 1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "Read failed" );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, "Read result = " << (int)buf[0] );
|
|
|
|
|
|
|
|
return buf[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-05 05:22:42 +00:00
|
|
|
// Turn a lamp on or off
|
2004-12-24 01:23:27 +00:00
|
|
|
void ATCSetLamp( int fd, int channel, bool value ) {
|
2002-06-05 05:22:42 +00:00
|
|
|
// lamp channels 0-63 are written to LampPort0, channels 64-127
|
|
|
|
// are written to LampPort1
|
|
|
|
|
|
|
|
// bits 0-6 are the lamp address
|
|
|
|
// bit 7 is the value (on/off)
|
|
|
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
// Write the value
|
|
|
|
unsigned char buf[3];
|
|
|
|
buf[0] = channel;
|
|
|
|
buf[1] = value;
|
|
|
|
buf[2] = 0;
|
|
|
|
result = write( fd, buf, 2 );
|
|
|
|
if ( result != 2 ) {
|
2002-06-05 17:44:09 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT, "Write failed" );
|
2002-06-05 05:22:42 +00:00
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
void FGATCOutput::init_config() {
|
2002-09-12 03:15:27 +00:00
|
|
|
#if defined( unix ) || defined( __CYGWIN__ )
|
2004-12-24 01:23:27 +00:00
|
|
|
if ( config.str()[0] != '/' ) {
|
|
|
|
// not an absolute path, prepend the standard location
|
|
|
|
SGPath tmp;
|
|
|
|
char *envp = ::getenv( "HOME" );
|
|
|
|
if ( envp != NULL ) {
|
|
|
|
tmp = envp;
|
|
|
|
tmp.append( ".atcflightsim" );
|
|
|
|
tmp.append( config.str() );
|
|
|
|
config = tmp;
|
|
|
|
}
|
2002-09-12 03:15:27 +00:00
|
|
|
}
|
2004-12-24 01:23:27 +00:00
|
|
|
readProperties( config.str(), globals->get_props() );
|
2002-09-12 03:15:27 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
// Open and initialize the ATC hardware
|
|
|
|
bool FGATCOutput::open( int lock_fd ) {
|
|
|
|
if ( is_open ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "This board is already open for output! "
|
|
|
|
<< board );
|
2002-02-05 04:42:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-09-12 03:15:27 +00:00
|
|
|
// This loads the config parameters generated by "simcal"
|
|
|
|
init_config();
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
2004-12-30 14:57:58 +00:00
|
|
|
"Initializing ATC output hardware, please wait ..." );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-30 14:57:58 +00:00
|
|
|
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 );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
#if defined( unix ) || defined( __CYGWIN__ )
|
|
|
|
|
2002-02-05 04:42:39 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Open the /proc files
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-06-05 05:22:42 +00:00
|
|
|
lamps_fd = ::open( lamps_file, O_WRONLY );
|
|
|
|
if ( lamps_fd == -1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
|
|
|
|
char msg[256];
|
|
|
|
snprintf( msg, 256, "Error opening %s", lamps_file );
|
|
|
|
perror( msg );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
radio_display_fd = ::open( radio_display_file, O_RDWR );
|
|
|
|
if ( radio_display_fd == -1 ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
|
|
|
|
char msg[256];
|
2004-12-24 01:23:27 +00:00
|
|
|
snprintf( msg, 256, "Error opening %s", radio_display_file );
|
2002-02-05 04:42:39 +00:00
|
|
|
perror( msg );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
stepper_fd = ::open( stepper_file, O_RDWR );
|
|
|
|
if ( stepper_fd == -1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
|
|
|
|
char msg[256];
|
|
|
|
snprintf( msg, 256, "Error opening %s", stepper_file );
|
|
|
|
perror( msg );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
#endif
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Home the compass stepper motor
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
|
|
|
" - Homing the compass stepper motor" );
|
|
|
|
|
|
|
|
// Lock the hardware, keep trying until we succeed
|
2004-12-24 01:23:27 +00:00
|
|
|
while ( ATCLock( lock_fd ) <= 0 );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
// Send the stepper home command
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCSetStepper( stepper_fd, ATC_COMPASS_CH, ATC_STEPPER_HOME );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
// Release the hardware
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCRelease( lock_fd );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2002-05-14 05:22:52 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
|
|
|
" - Waiting for compass to come home." );
|
|
|
|
|
2002-02-05 04:42:39 +00:00
|
|
|
bool home = false;
|
2002-05-14 05:22:52 +00:00
|
|
|
int timeout = 900; // about 30 seconds
|
2002-10-16 03:46:05 +00:00
|
|
|
timeout = 0;
|
2002-06-05 05:22:42 +00:00
|
|
|
while ( ! home && timeout > 0 ) {
|
2002-05-14 05:22:52 +00:00
|
|
|
if ( timeout % 150 == 0 ) {
|
|
|
|
SG_LOG( SG_IO, SG_INFO, "waiting for compass = " << timeout );
|
|
|
|
} else {
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, "Checking if compass home ..." );
|
|
|
|
}
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
while ( ATCLock( lock_fd ) <= 0 );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
unsigned char result = ATCReadStepper( stepper_fd );
|
2002-02-05 04:42:39 +00:00
|
|
|
if ( result == 0 ) {
|
|
|
|
home = true;
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCRelease( lock_fd );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2002-02-11 15:24:08 +00:00
|
|
|
#if defined( _MSC_VER )
|
2002-02-08 00:07:53 +00:00
|
|
|
ulMilliSecondSleep(33);
|
2002-02-11 15:25:19 +00:00
|
|
|
#elif defined (WIN32) && !defined(__CYGWIN__)
|
|
|
|
Sleep (33);
|
2002-02-08 00:07:53 +00:00
|
|
|
#else
|
2002-02-05 04:42:39 +00:00
|
|
|
usleep(33);
|
2002-02-08 00:07:53 +00:00
|
|
|
#endif
|
2002-05-14 05:22:52 +00:00
|
|
|
|
|
|
|
--timeout;
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
compass_position = 0.0;
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Blank the radio display
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
|
|
|
" - Clearing the radios displays." );
|
|
|
|
|
|
|
|
// Prepair the data
|
|
|
|
unsigned char value = 0xff;
|
|
|
|
for ( int channel = 0; channel < ATC_RADIO_DISPLAY_BYTES; ++channel ) {
|
|
|
|
radio_display_data[channel] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock the hardware, keep trying until we succeed
|
2004-12-24 01:23:27 +00:00
|
|
|
while ( ATCLock( lock_fd ) <= 0 );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
// Set radio display
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCSetRadios( radio_display_fd, radio_display_data );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCRelease( lock_fd );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2002-06-05 05:22:42 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Blank the lamps
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
for ( int i = 0; i < 128; ++i ) {
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCSetLamp( lamps_fd, i, false );
|
2002-06-05 05:22:42 +00:00
|
|
|
}
|
|
|
|
|
2002-02-05 04:42:39 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Finished initing hardware
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SG_LOG( SG_IO, SG_ALERT,
|
2004-12-30 14:57:58 +00:00
|
|
|
"Done initializing ATC output hardware." );
|
2004-12-24 01:23:27 +00:00
|
|
|
|
|
|
|
is_open = true;
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Connect up to property values
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
char base_name[256];
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
snprintf( base_name, 256, "/output/atc-board[%d]/lamps", board );
|
|
|
|
lamps_out_node = fgGetNode( base_name );
|
2002-09-23 18:44:09 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
snprintf( base_name, 256, "/output/atc-board[%d]/radio-display", board );
|
|
|
|
radio_display_node = fgGetNode( base_name );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
snprintf( base_name, 256, "/output/atc-board[%d]/steppers", board );
|
|
|
|
steppers_node = fgGetNode( base_name );
|
2002-07-04 21:38:37 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-12-16 01:12:10 +00:00
|
|
|
|
2002-09-12 03:15:27 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Write the lights
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2002-09-12 03:15:27 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
SGPropertyNode *child = lamps_out_node->getChild(i);
|
|
|
|
string cname = child->getName();
|
|
|
|
int index = child->getIndex();
|
|
|
|
string name = "";
|
|
|
|
string type = "";
|
|
|
|
SGPropertyNode *src_prop = NULL;
|
|
|
|
if ( cname == "lamp" ) {
|
|
|
|
SGPropertyNode *prop;
|
|
|
|
prop = child->getChild( "name" );
|
|
|
|
if ( prop != NULL ) {
|
|
|
|
name = prop->getStringValue();
|
|
|
|
}
|
|
|
|
prop = child->getChild( "type" );
|
|
|
|
if ( prop != NULL ) {
|
|
|
|
type = prop->getStringValue();
|
|
|
|
}
|
|
|
|
prop = child->getChild( "prop" );
|
|
|
|
if ( prop != NULL ) {
|
|
|
|
src_prop = fgGetNode( prop->getStringValue(), true );
|
|
|
|
}
|
|
|
|
ATCSetLamp( lamps_fd, index, src_prop->getBoolValue() );
|
|
|
|
} else {
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG,
|
|
|
|
"Input config error, expecting 'lamp' but found "
|
|
|
|
<< cname );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-27 02:57:31 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-03-27 02:57:31 +00:00
|
|
|
|
2002-09-12 03:15:27 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Update the radio display
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2002-09-12 03:15:27 +00:00
|
|
|
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static bool navcom1_has_power() {
|
|
|
|
static SGPropertyNode *navcom1_bus_power
|
|
|
|
= fgGetNode( "/systems/electrical/outputs/nav[0]", true );
|
|
|
|
static SGPropertyNode *navcom1_power_btn
|
2004-12-30 14:57:58 +00:00
|
|
|
= fgGetNode( "/instrumentation/nav[0]/power-btn", true );
|
2002-09-12 03:15:27 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
return (navcom1_bus_power->getDoubleValue() > 1.0)
|
|
|
|
&& navcom1_power_btn->getBoolValue();
|
|
|
|
}
|
2002-12-16 01:12:10 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static bool navcom2_has_power() {
|
|
|
|
static SGPropertyNode *navcom2_bus_power
|
|
|
|
= fgGetNode( "/systems/electrical/outputs/nav[1]", true );
|
|
|
|
static SGPropertyNode *navcom2_power_btn
|
2004-12-30 14:57:58 +00:00
|
|
|
= fgGetNode( "/instrumentation/nav[1]/power-btn", true );
|
2004-02-12 20:56:24 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
return (navcom2_bus_power->getDoubleValue() > 1.0)
|
|
|
|
&& navcom2_power_btn->getBoolValue();
|
|
|
|
}
|
2002-09-12 03:15:27 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static bool dme_has_power() {
|
|
|
|
static SGPropertyNode *dme_bus_power
|
|
|
|
= fgGetNode( "/systems/electrical/outputs/dme", true );
|
|
|
|
|
|
|
|
return (dme_bus_power->getDoubleValue() > 1.0);
|
|
|
|
}
|
2004-11-18 05:04:35 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static bool adf_has_power() {
|
|
|
|
static SGPropertyNode *adf_bus_power
|
|
|
|
= fgGetNode( "/systems/electrical/outputs/adf", true );
|
|
|
|
static SGPropertyNode *adf_power_btn
|
|
|
|
= fgGetNode( "/instrumentation/kr-87/inputs/power-btn", true );
|
2002-09-12 03:15:27 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
return (adf_bus_power->getDoubleValue() > 1.0)
|
|
|
|
&& adf_power_btn->getBoolValue();
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
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 );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
return (xpdr_bus_power->getDoubleValue() > 1.0)
|
|
|
|
&& (xpdr_func_knob->getIntValue() > 0);
|
|
|
|
}
|
2002-06-05 05:22:42 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
bool FGATCOutput::do_radio_display() {
|
|
|
|
static SGPropertyNode *dme_serviceable
|
|
|
|
= fgGetNode( "/instrumentation/dme/serviceable", true );
|
|
|
|
static SGPropertyNode *dme_in_range
|
|
|
|
= fgGetNode( "/instrumentation/dme/in-range", true );
|
|
|
|
static SGPropertyNode *dme_min
|
|
|
|
= fgGetNode( "/instrumentation/dme/indicated-time-min", true );
|
|
|
|
static SGPropertyNode *dme_kt
|
|
|
|
= fgGetNode( "/instrumentation/dme/indicated-ground-speed-kt", true );
|
|
|
|
static SGPropertyNode *dme_nm
|
|
|
|
= fgGetNode( "/instrumentation/dme/indicated-distance-nm", true );
|
|
|
|
|
|
|
|
static SGPropertyNode *comm1_serviceable
|
|
|
|
= fgGetNode( "/instrumentation/comm[0]/serviceable", true );
|
|
|
|
static SGPropertyNode *com1_freq
|
|
|
|
= fgGetNode( "/instrumentation/comm[0]/frequencies/selected-mhz", true);
|
|
|
|
static SGPropertyNode *com1_stby_freq
|
|
|
|
= fgGetNode( "/instrumentation/comm[0]/frequencies/standby-mhz", true );
|
2002-07-04 21:38:37 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static SGPropertyNode *comm2_serviceable
|
|
|
|
= fgGetNode( "/instrumentation/comm[1]/serviceable", true );
|
|
|
|
static SGPropertyNode *com2_freq
|
|
|
|
= fgGetNode( "/instrumentation/comm[1]/frequencies/selected-mhz", true);
|
|
|
|
static SGPropertyNode *com2_stby_freq
|
|
|
|
= fgGetNode( "/instrumentation/comm[1]/frequencies/standby-mhz", true );
|
2002-06-05 05:22:42 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static SGPropertyNode *nav1_serviceable
|
|
|
|
= fgGetNode( "/instrumentation/nav[0]/serviceable", true );
|
|
|
|
static SGPropertyNode *nav1_freq
|
|
|
|
= fgGetNode( "/instrumentation/nav[0]/frequencies/selected-mhz", true );
|
|
|
|
static SGPropertyNode *nav1_stby_freq
|
|
|
|
= fgGetNode( "/instrumentation/nav[0]/frequencies/standby-mhz", true );
|
2002-06-05 05:22:42 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static SGPropertyNode *nav2_serviceable
|
|
|
|
= fgGetNode( "/instrumentation/nav[1]/serviceable", true );
|
|
|
|
static SGPropertyNode *nav2_freq
|
|
|
|
= fgGetNode( "/instrumentation/nav[1]/frequencies/selected-mhz", true );
|
|
|
|
static SGPropertyNode *nav2_stby_freq
|
|
|
|
= fgGetNode( "/instrumentation/nav[1]/frequencies/standby-mhz", true );
|
|
|
|
|
|
|
|
static SGPropertyNode *adf_serviceable
|
|
|
|
= fgGetNode( "/instrumentation/adf/serviceable", true );
|
|
|
|
static SGPropertyNode *adf_freq
|
|
|
|
= fgGetNode( "/instrumentation/kr-87/outputs/selected-khz", true );
|
|
|
|
static SGPropertyNode *adf_stby_freq
|
|
|
|
= fgGetNode( "/instrumentation/kr-87/outputs/standby-khz", true );
|
|
|
|
static SGPropertyNode *adf_stby_mode
|
|
|
|
= fgGetNode( "/instrumentation/kr-87/modes/stby", true );
|
|
|
|
static SGPropertyNode *adf_timer_mode
|
|
|
|
= fgGetNode( "/instrumentation/kr-87/modes/timer", true );
|
|
|
|
// static SGPropertyNode *adf_count_mode
|
|
|
|
// = fgGetNode( "/instrumentation/kr-87/modes/count", true );
|
|
|
|
static SGPropertyNode *adf_flight_timer
|
|
|
|
= fgGetNode( "/instrumentation/kr-87/outputs/flight-timer", true );
|
|
|
|
static SGPropertyNode *adf_elapsed_timer
|
|
|
|
= fgGetNode( "/instrumentation/kr-87/outputs/elapsed-timer", true );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
static SGPropertyNode *xpdr_serviceable
|
|
|
|
= fgGetNode( "/instrumentation/kt-70/inputs/serviceable", true );
|
|
|
|
static SGPropertyNode *xpdr_func_knob
|
|
|
|
= fgGetNode( "/instrumentation/kt-70/inputs/func-knob", true );
|
|
|
|
static SGPropertyNode *xpdr_flight_level
|
|
|
|
= fgGetNode( "/instrumentation/kt-70/outputs/flight-level", true );
|
|
|
|
static SGPropertyNode *xpdr_id_code
|
|
|
|
= fgGetNode( "/instrumentation/kt-70/outputs/id-code", true );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
char digits[10];
|
2002-02-05 15:57:46 +00:00
|
|
|
int i;
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2003-07-30 00:43:25 +00:00
|
|
|
if ( dme_has_power() && dme_serviceable->getBoolValue() ) {
|
2003-04-01 03:42:51 +00:00
|
|
|
if ( dme_in_range->getBoolValue() ) {
|
|
|
|
// DME minutes
|
|
|
|
float minutes = dme_min->getFloatValue();
|
|
|
|
if ( minutes > 999 ) {
|
|
|
|
minutes = 999.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%03.0f", minutes);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[0] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[1] = 0xf0 | digits[0];
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2003-04-01 03:42:51 +00:00
|
|
|
// DME knots
|
|
|
|
float knots = dme_kt->getFloatValue();
|
|
|
|
if ( knots > 999 ) {
|
|
|
|
knots = 999.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%03.0f", knots);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[2] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[3] = 0xf0 | digits[0];
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2003-04-01 03:42:51 +00:00
|
|
|
// DME distance (nm)
|
|
|
|
float nm = dme_nm->getFloatValue();
|
|
|
|
if ( nm > 99 ) {
|
|
|
|
nm = 99.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%04.1f", nm);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[4] = digits[1] << 4 | digits[3];
|
|
|
|
radio_display_data[5] = 0x00 | digits[0];
|
|
|
|
// the 0x00 in the upper nibble of the 6th byte of each
|
|
|
|
// display turns on the decimal point
|
|
|
|
} else {
|
|
|
|
// out of range
|
2003-04-23 18:31:22 +00:00
|
|
|
radio_display_data[0] = 0xbb;
|
|
|
|
radio_display_data[1] = 0xfb;
|
|
|
|
radio_display_data[2] = 0xbb;
|
|
|
|
radio_display_data[3] = 0xfb;
|
|
|
|
radio_display_data[4] = 0xbb;
|
|
|
|
radio_display_data[5] = 0x0b;
|
2003-04-01 03:42:51 +00:00
|
|
|
}
|
2002-02-05 04:42:39 +00:00
|
|
|
} else {
|
|
|
|
// blank dem display
|
2002-02-05 15:57:46 +00:00
|
|
|
for ( i = 0; i < 6; ++i ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
radio_display_data[i] = 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-30 00:43:25 +00:00
|
|
|
if ( navcom1_has_power() && comm1_serviceable->getBoolValue() ) {
|
2002-09-23 18:44:09 +00:00
|
|
|
// Com1 standby frequency
|
|
|
|
float com1_stby = com1_stby_freq->getFloatValue();
|
|
|
|
if ( fabs(com1_stby) > 999.99 ) {
|
|
|
|
com1_stby = 0.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.3f", com1_stby);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[6] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[7] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[8] = 0xf0 | digits[0];
|
|
|
|
|
|
|
|
// Com1 in use frequency
|
|
|
|
float com1 = com1_freq->getFloatValue();
|
|
|
|
if ( fabs(com1) > 999.99 ) {
|
|
|
|
com1 = 0.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.3f", com1);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[9] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[10] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[11] = 0x00 | digits[0];
|
|
|
|
// the 0x00 in the upper nibble of the 6th byte of each display
|
|
|
|
// turns on the decimal point
|
|
|
|
} else {
|
|
|
|
radio_display_data[6] = 0xff;
|
|
|
|
radio_display_data[7] = 0xff;
|
|
|
|
radio_display_data[8] = 0xff;
|
|
|
|
radio_display_data[9] = 0xff;
|
|
|
|
radio_display_data[10] = 0xff;
|
|
|
|
radio_display_data[11] = 0xff;
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
|
|
|
|
2003-07-30 00:43:25 +00:00
|
|
|
if ( navcom2_has_power() && comm2_serviceable->getBoolValue() ) {
|
2002-09-23 18:44:09 +00:00
|
|
|
// Com2 standby frequency
|
|
|
|
float com2_stby = com2_stby_freq->getFloatValue();
|
|
|
|
if ( fabs(com2_stby) > 999.99 ) {
|
|
|
|
com2_stby = 0.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.3f", com2_stby);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[18] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[19] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[20] = 0xf0 | digits[0];
|
|
|
|
|
|
|
|
// Com2 in use frequency
|
|
|
|
float com2 = com2_freq->getFloatValue();
|
|
|
|
if ( fabs(com2) > 999.99 ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
com2 = 0.0;
|
2002-09-23 18:44:09 +00:00
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.3f", com2);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[21] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[22] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[23] = 0x00 | digits[0];
|
|
|
|
// the 0x00 in the upper nibble of the 6th byte of each display
|
|
|
|
// turns on the decimal point
|
|
|
|
} else {
|
|
|
|
radio_display_data[18] = 0xff;
|
|
|
|
radio_display_data[19] = 0xff;
|
|
|
|
radio_display_data[20] = 0xff;
|
|
|
|
radio_display_data[21] = 0xff;
|
|
|
|
radio_display_data[22] = 0xff;
|
|
|
|
radio_display_data[23] = 0xff;
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
2002-09-23 18:44:09 +00:00
|
|
|
|
2003-07-30 00:43:25 +00:00
|
|
|
if ( navcom1_has_power() && nav1_serviceable->getBoolValue() ) {
|
2002-09-23 18:44:09 +00:00
|
|
|
// Nav1 standby frequency
|
|
|
|
float nav1_stby = nav1_stby_freq->getFloatValue();
|
|
|
|
if ( fabs(nav1_stby) > 999.99 ) {
|
2002-02-05 04:42:39 +00:00
|
|
|
nav1_stby = 0.0;
|
2002-09-23 18:44:09 +00:00
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.2f", nav1_stby);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[12] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[13] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[14] = 0xf0 | digits[0];
|
|
|
|
|
|
|
|
// Nav1 in use frequency
|
|
|
|
float nav1 = nav1_freq->getFloatValue();
|
|
|
|
if ( fabs(nav1) > 999.99 ) {
|
|
|
|
nav1 = 0.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.2f", nav1);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[15] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[16] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[17] = 0x00 | digits[0];
|
|
|
|
// the 0x00 in the upper nibble of the 6th byte of each display
|
|
|
|
// turns on the decimal point
|
|
|
|
} else {
|
|
|
|
radio_display_data[12] = 0xff;
|
|
|
|
radio_display_data[13] = 0xff;
|
|
|
|
radio_display_data[14] = 0xff;
|
|
|
|
radio_display_data[15] = 0xff;
|
|
|
|
radio_display_data[16] = 0xff;
|
|
|
|
radio_display_data[17] = 0xff;
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
2002-09-23 18:44:09 +00:00
|
|
|
|
2003-07-30 00:43:25 +00:00
|
|
|
if ( navcom2_has_power() && nav2_serviceable->getBoolValue() ) {
|
2002-09-23 18:44:09 +00:00
|
|
|
// Nav2 standby frequency
|
|
|
|
float nav2_stby = nav2_stby_freq->getFloatValue();
|
|
|
|
if ( fabs(nav2_stby) > 999.99 ) {
|
|
|
|
nav2_stby = 0.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.2f", nav2_stby);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[24] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[25] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[26] = 0xf0 | digits[0];
|
|
|
|
|
|
|
|
// Nav2 in use frequency
|
|
|
|
float nav2 = nav2_freq->getFloatValue();
|
|
|
|
if ( fabs(nav2) > 999.99 ) {
|
|
|
|
nav2 = 0.0;
|
|
|
|
}
|
|
|
|
snprintf(digits, 7, "%06.2f", nav2);
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[27] = digits[4] << 4 | digits[5];
|
|
|
|
radio_display_data[28] = digits[1] << 4 | digits[2];
|
|
|
|
radio_display_data[29] = 0x00 | digits[0];
|
|
|
|
// the 0x00 in the upper nibble of the 6th byte of each display
|
|
|
|
// turns on the decimal point
|
|
|
|
} else {
|
|
|
|
radio_display_data[24] = 0xff;
|
|
|
|
radio_display_data[25] = 0xff;
|
|
|
|
radio_display_data[26] = 0xff;
|
|
|
|
radio_display_data[27] = 0xff;
|
|
|
|
radio_display_data[28] = 0xff;
|
|
|
|
radio_display_data[29] = 0xff;
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
|
|
|
|
2002-06-30 22:46:34 +00:00
|
|
|
// ADF standby frequency / timer
|
2003-07-30 00:43:25 +00:00
|
|
|
if ( adf_has_power() && adf_serviceable->getBoolValue() ) {
|
2002-06-30 22:46:34 +00:00
|
|
|
if ( adf_stby_mode->getIntValue() == 0 ) {
|
|
|
|
// frequency
|
|
|
|
float adf_stby = adf_stby_freq->getFloatValue();
|
|
|
|
if ( fabs(adf_stby) > 1799 ) {
|
|
|
|
adf_stby = 1799;
|
|
|
|
}
|
2002-07-05 13:56:46 +00:00
|
|
|
snprintf(digits, 7, "%04.0f", adf_stby);
|
2002-06-30 22:46:34 +00:00
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[30] = digits[3] << 4 | 0x0f;
|
|
|
|
radio_display_data[31] = digits[1] << 4 | digits[2];
|
|
|
|
if ( digits[0] == 0 ) {
|
|
|
|
radio_display_data[32] = 0xff;
|
|
|
|
} else {
|
|
|
|
radio_display_data[32] = 0xf0 | digits[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// timer
|
|
|
|
double time;
|
|
|
|
int hours, min, sec;
|
|
|
|
if ( adf_timer_mode->getIntValue() == 0 ) {
|
|
|
|
time = adf_flight_timer->getDoubleValue();
|
|
|
|
} else {
|
|
|
|
time = adf_elapsed_timer->getDoubleValue();
|
|
|
|
}
|
|
|
|
// cout << time << endl;
|
|
|
|
hours = (int)(time / 3600.0);
|
|
|
|
time -= hours * 3600.00;
|
|
|
|
min = (int)(time / 60.0);
|
|
|
|
time -= min * 60.0;
|
|
|
|
sec = (int)time;
|
2002-07-05 05:23:53 +00:00
|
|
|
int big, little;
|
2002-06-30 22:46:34 +00:00
|
|
|
if ( hours > 0 ) {
|
|
|
|
big = hours;
|
|
|
|
if ( big > 99 ) {
|
|
|
|
big = 99;
|
|
|
|
}
|
2002-07-05 05:23:53 +00:00
|
|
|
little = min;
|
2002-06-30 22:46:34 +00:00
|
|
|
} else {
|
|
|
|
big = min;
|
2002-07-05 05:23:53 +00:00
|
|
|
little = sec;
|
2002-06-30 22:46:34 +00:00
|
|
|
}
|
|
|
|
if ( big > 99 ) {
|
|
|
|
big = 99;
|
|
|
|
}
|
2002-07-05 05:23:53 +00:00
|
|
|
// cout << big << ":" << little << endl;
|
2002-07-05 13:56:46 +00:00
|
|
|
snprintf(digits, 7, "%02d%02d", big, little);
|
2002-06-30 22:46:34 +00:00
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
2002-12-16 01:12:10 +00:00
|
|
|
radio_display_data[30] = digits[2] << 4 | digits[3];
|
|
|
|
radio_display_data[31] = digits[0] << 4 | digits[1];
|
|
|
|
radio_display_data[32] = 0xff;
|
2002-06-30 22:46:34 +00:00
|
|
|
}
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2002-06-30 22:46:34 +00:00
|
|
|
// ADF in use frequency
|
|
|
|
float adf = adf_freq->getFloatValue();
|
|
|
|
if ( fabs(adf) > 1799 ) {
|
|
|
|
adf = 1799;
|
|
|
|
}
|
2002-07-05 13:56:46 +00:00
|
|
|
snprintf(digits, 7, "%04.0f", adf);
|
2002-06-30 22:46:34 +00:00
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[33] = digits[2] << 4 | digits[3];
|
|
|
|
if ( digits[0] == 0 ) {
|
|
|
|
radio_display_data[34] = 0xf0 | digits[1];
|
|
|
|
} else {
|
|
|
|
radio_display_data[34] = digits[0] << 4 | digits[1];
|
|
|
|
}
|
2002-10-16 03:46:05 +00:00
|
|
|
if ( adf_stby_mode->getIntValue() == 0 ) {
|
|
|
|
radio_display_data[35] = 0xff;
|
|
|
|
} else {
|
|
|
|
radio_display_data[35] = 0x0f;
|
|
|
|
}
|
2002-06-30 22:46:34 +00:00
|
|
|
} else {
|
|
|
|
radio_display_data[30] = 0xff;
|
|
|
|
radio_display_data[31] = 0xff;
|
|
|
|
radio_display_data[32] = 0xff;
|
|
|
|
radio_display_data[33] = 0xff;
|
|
|
|
radio_display_data[34] = 0xff;
|
2002-10-16 03:46:05 +00:00
|
|
|
radio_display_data[35] = 0xff;
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
2002-06-30 22:46:34 +00:00
|
|
|
|
2002-07-04 21:38:37 +00:00
|
|
|
// Transponder code and flight level
|
2003-07-30 00:43:25 +00:00
|
|
|
if ( xpdr_has_power() && xpdr_serviceable->getBoolValue() ) {
|
2002-09-26 17:26:34 +00:00
|
|
|
if ( xpdr_func_knob->getIntValue() == 2 ) {
|
|
|
|
// test mode
|
|
|
|
radio_display_data[36] = 8 << 4 | 8;
|
|
|
|
radio_display_data[37] = 8 << 4 | 8;
|
|
|
|
radio_display_data[38] = 0xff;
|
|
|
|
radio_display_data[39] = 8 << 4 | 0x0f;
|
|
|
|
radio_display_data[40] = 8 << 4 | 8;
|
2002-07-04 21:38:37 +00:00
|
|
|
} else {
|
2002-09-26 17:26:34 +00:00
|
|
|
// other on modes
|
|
|
|
int id_code = xpdr_id_code->getIntValue();
|
|
|
|
int place = 1000;
|
|
|
|
for ( i = 0; i < 4; ++i ) {
|
|
|
|
digits[i] = id_code / place;
|
|
|
|
id_code -= digits[i] * place;
|
|
|
|
place /= 10;
|
|
|
|
}
|
|
|
|
radio_display_data[36] = digits[2] << 4 | digits[3];
|
|
|
|
radio_display_data[37] = digits[0] << 4 | digits[1];
|
|
|
|
radio_display_data[38] = 0xff;
|
|
|
|
|
|
|
|
if ( xpdr_func_knob->getIntValue() == 3 ||
|
|
|
|
xpdr_func_knob->getIntValue() == 5 )
|
|
|
|
{
|
|
|
|
// do flight level display
|
|
|
|
snprintf(digits, 7, "%03d", xpdr_flight_level->getIntValue() );
|
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
digits[i] -= '0';
|
|
|
|
}
|
|
|
|
radio_display_data[39] = digits[2] << 4 | 0x0f;
|
|
|
|
radio_display_data[40] = digits[0] << 4 | digits[1];
|
|
|
|
} else {
|
|
|
|
// blank flight level display
|
|
|
|
radio_display_data[39] = 0xff;
|
|
|
|
radio_display_data[40] = 0xff;
|
|
|
|
}
|
2002-07-04 21:38:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// off
|
|
|
|
radio_display_data[36] = 0xff;
|
|
|
|
radio_display_data[37] = 0xff;
|
|
|
|
radio_display_data[38] = 0xff;
|
|
|
|
radio_display_data[39] = 0xff;
|
|
|
|
radio_display_data[40] = 0xff;
|
|
|
|
}
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCSetRadios( radio_display_fd, radio_display_data );
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Drive the stepper motors
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
bool FGATCOutput::do_steppers() {
|
|
|
|
SGPropertyNode *mag_compass
|
|
|
|
= fgGetNode( "/instrumentation/magnetic-compass/indicated-heading-deg",
|
|
|
|
true );
|
|
|
|
|
2002-02-05 04:42:39 +00:00
|
|
|
float diff = mag_compass->getFloatValue() - compass_position;
|
|
|
|
while ( diff < -180.0 ) { diff += 360.0; }
|
|
|
|
while ( diff > 180.0 ) { diff -= 360.0; }
|
|
|
|
|
|
|
|
int steps = (int)(diff * 4);
|
|
|
|
// cout << "steps = " << steps << endl;
|
|
|
|
if ( steps > 4 ) { steps = 4; }
|
|
|
|
if ( steps < -4 ) { steps = -4; }
|
|
|
|
|
|
|
|
if ( abs(steps) > 0 ) {
|
|
|
|
unsigned char cmd = 0x80; // stepper command
|
|
|
|
if ( steps > 0 ) {
|
|
|
|
cmd |= 0x20; // go up
|
|
|
|
} else {
|
|
|
|
cmd |= 0x00; // go down
|
|
|
|
}
|
|
|
|
cmd |= abs(steps);
|
|
|
|
|
|
|
|
// sync compass_position with hardware position
|
|
|
|
compass_position += (float)steps / 4.0;
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
ATCSetStepper( stepper_fd, ATC_COMPASS_CH, cmd );
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
// process the hardware outputs. This code assumes the calling layer
|
|
|
|
// will lock the hardware.
|
|
|
|
bool FGATCOutput::process() {
|
|
|
|
if ( !is_open ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "This board has not been opened for output! "
|
|
|
|
<< board );
|
|
|
|
return false;
|
|
|
|
}
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
do_lamps();
|
|
|
|
do_radio_display();
|
|
|
|
do_steppers();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-11-16 19:47:11 +00:00
|
|
|
|
2004-11-18 05:04:35 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
bool FGATCOutput::close() {
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
#if defined( unix ) || defined( __CYGWIN__ )
|
|
|
|
|
2004-12-30 14:57:58 +00:00
|
|
|
if ( !is_open ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
result = ::close( lamps_fd );
|
|
|
|
if ( result == -1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
|
|
|
|
char msg[256];
|
|
|
|
snprintf( msg, 256, "Error closing %s", lamps_file );
|
|
|
|
perror( msg );
|
|
|
|
exit( -1 );
|
2002-02-05 04:42:39 +00:00
|
|
|
}
|
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
result = ::close( radio_display_fd );
|
|
|
|
if ( result == -1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
|
|
|
|
char msg[256];
|
|
|
|
snprintf( msg, 256, "Error closing %s", radio_display_file );
|
|
|
|
perror( msg );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
2002-02-05 04:42:39 +00:00
|
|
|
|
2004-12-24 01:23:27 +00:00
|
|
|
result = ::close( stepper_fd );
|
|
|
|
if ( result == -1 ) {
|
|
|
|
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
|
|
|
|
char msg[256];
|
|
|
|
snprintf( msg, 256, "Error closing %s", stepper_file );
|
|
|
|
perror( msg );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2002-02-05 04:42:39 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|