1 // ATC-Outputs.hxx -- Translate FGFS properties to ATC hardware outputs.
3 // Written by Curtis Olson, started November 2004.
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <simgear/compiler.h>
30 #if defined( unix ) || defined( __CYGWIN__ )
31 # include <sys/types.h>
32 # include <sys/stat.h>
38 #include <simgear/debug/logstream.hxx>
40 #include <Main/fg_props.hxx>
42 #include "ATC-Outputs.hxx"
48 // Lock the ATC hardware
49 static int ATCLock( int fd ) {
50 #if defined( unix ) || defined( __CYGWIN__ )
52 lseek( fd, 0, SEEK_SET );
55 int result = read( fd, tmp, 1 );
57 SG_LOG( SG_IO, SG_DEBUG, "Lock failed" );
67 // Release the ATC hardware
68 static int ATCRelease( int fd ) {
69 #if defined( unix ) || defined( __CYGWIN__ )
71 lseek( fd, 0, SEEK_SET );
75 int result = write( fd, tmp, 1 );
78 SG_LOG( SG_IO, SG_DEBUG, "Release failed" );
88 // Constructor: The _board parameter specifies which board to
89 // reference. Possible values are 0 or 1. The _config_file parameter
90 // specifies the location of the output config file (xml)
91 FGATCOutput::FGATCOutput( const int _board, const SGPath &_config_file ) :
94 radio_display_node(NULL),
98 config = _config_file;
102 // Write a radios command
103 static int ATCSetRadios( int fd, unsigned char data[ATC_RADIO_DISPLAY_BYTES] ) {
104 #if defined( unix ) || defined( __CYGWIN__ )
106 lseek( fd, 0, SEEK_SET );
108 int result = write( fd, data, ATC_RADIO_DISPLAY_BYTES );
110 if ( result != ATC_RADIO_DISPLAY_BYTES ) {
111 SG_LOG( SG_IO, SG_DEBUG, "Write failed" );
121 // Write a stepper command
122 static int ATCSetStepper( int fd, unsigned char channel,
123 unsigned char value )
125 #if defined( unix ) || defined( __CYGWIN__ )
127 lseek( fd, 0, SEEK_SET );
130 unsigned char buf[3];
134 int result = write( fd, buf, 2 );
136 SG_LOG( SG_IO, SG_INFO, "Write failed" );
138 SG_LOG( SG_IO, SG_DEBUG,
139 "Sent cmd = " << (int)channel << " value = " << (int)value );
147 // Read status of last stepper written to
148 static unsigned char ATCReadStepper( int fd ) {
149 #if defined( unix ) || defined( __CYGWIN__ )
153 lseek( fd, 0, SEEK_SET );
156 unsigned char buf[2];
157 result = read( fd, buf, 1 );
159 SG_LOG( SG_IO, SG_ALERT, "Read failed" );
162 SG_LOG( SG_IO, SG_DEBUG, "Read result = " << (int)buf[0] );
171 // Turn a lamp on or off
172 void ATCSetLamp( int fd, int channel, bool value ) {
173 #if defined( unix ) || defined( __CYGWIN__ )
174 // lamp channels 0-63 are written to LampPort0, channels 64-127
175 // are written to LampPort1
177 // bits 0-6 are the lamp address
178 // bit 7 is the value (on/off)
183 unsigned char buf[3];
187 result = write( fd, buf, 2 );
189 SG_LOG( SG_IO, SG_ALERT, "Write failed" );
196 void FGATCOutput::init_config() {
197 #if defined( unix ) || defined( __CYGWIN__ )
198 if ( config.str()[0] != '/' ) {
199 // not an absolute path, prepend the standard location
201 char *envp = ::getenv( "HOME" );
202 if ( envp != NULL ) {
204 tmp.append( ".atcflightsim" );
205 tmp.append( config.str() );
209 readProperties( config.str(), globals->get_props() );
214 // Open and initialize the ATC hardware
215 bool FGATCOutput::open( int lock_fd ) {
217 SG_LOG( SG_IO, SG_ALERT, "This board is already open for output! "
222 // This loads the config parameters generated by "simcal"
225 SG_LOG( SG_IO, SG_ALERT,
226 "Initializing ATC output hardware, please wait ..." );
228 snprintf( lamps_file, 256,
229 "/proc/atcflightsim/board%d/lamps", board );
230 snprintf( radio_display_file, 256,
231 "/proc/atcflightsim/board%d/radios", board );
232 snprintf( stepper_file, 256,
233 "/proc/atcflightsim/board%d/steppers", board );
235 #if defined( unix ) || defined( __CYGWIN__ )
237 /////////////////////////////////////////////////////////////////////
238 // Open the /proc files
239 /////////////////////////////////////////////////////////////////////
241 lamps_fd = ::open( lamps_file, O_WRONLY );
242 if ( lamps_fd == -1 ) {
243 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
245 snprintf( msg, 256, "Error opening %s", lamps_file );
250 radio_display_fd = ::open( radio_display_file, O_RDWR );
251 if ( radio_display_fd == -1 ) {
252 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
254 snprintf( msg, 256, "Error opening %s", radio_display_file );
259 stepper_fd = ::open( stepper_file, O_RDWR );
260 if ( stepper_fd == -1 ) {
261 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
263 snprintf( msg, 256, "Error opening %s", stepper_file );
270 /////////////////////////////////////////////////////////////////////
271 // Home the compass stepper motor
272 /////////////////////////////////////////////////////////////////////
274 SG_LOG( SG_IO, SG_ALERT,
275 " - Homing the compass stepper motor" );
277 // Lock the hardware, keep trying until we succeed
278 while ( ATCLock( lock_fd ) <= 0 );
280 // Send the stepper home command
281 ATCSetStepper( stepper_fd, ATC_COMPASS_CH, ATC_STEPPER_HOME );
283 // Release the hardware
284 ATCRelease( lock_fd );
286 SG_LOG( SG_IO, SG_ALERT,
287 " - Waiting for compass to come home." );
290 int timeout = 900; // about 30 seconds
292 while ( ! home && timeout > 0 ) {
293 if ( timeout % 150 == 0 ) {
294 SG_LOG( SG_IO, SG_INFO, "waiting for compass = " << timeout );
296 SG_LOG( SG_IO, SG_DEBUG, "Checking if compass home ..." );
299 while ( ATCLock( lock_fd ) <= 0 );
301 unsigned char result = ATCReadStepper( stepper_fd );
306 ATCRelease( lock_fd );
308 #if defined( _MSC_VER )
309 ulMilliSecondSleep(33);
310 #elif defined (WIN32) && !defined(__CYGWIN__)
319 compass_position = 0.0;
321 /////////////////////////////////////////////////////////////////////
322 // Blank the radio display
323 /////////////////////////////////////////////////////////////////////
325 SG_LOG( SG_IO, SG_ALERT,
326 " - Clearing the radios displays." );
329 unsigned char value = 0xff;
330 for ( int channel = 0; channel < ATC_RADIO_DISPLAY_BYTES; ++channel ) {
331 radio_display_data[channel] = value;
334 // Lock the hardware, keep trying until we succeed
335 while ( ATCLock( lock_fd ) <= 0 );
338 ATCSetRadios( radio_display_fd, radio_display_data );
340 ATCRelease( lock_fd );
342 /////////////////////////////////////////////////////////////////////
344 /////////////////////////////////////////////////////////////////////
346 for ( int i = 0; i < 128; ++i ) {
347 ATCSetLamp( lamps_fd, i, false );
350 /////////////////////////////////////////////////////////////////////
351 // Finished initing hardware
352 /////////////////////////////////////////////////////////////////////
354 SG_LOG( SG_IO, SG_ALERT,
355 "Done initializing ATC output hardware." );
359 /////////////////////////////////////////////////////////////////////
360 // Connect up to property values
361 /////////////////////////////////////////////////////////////////////
365 snprintf( base_name, 256, "/output/atc-board[%d]/lamps", board );
366 lamps_out_node = fgGetNode( base_name );
368 snprintf( base_name, 256, "/output/atc-board[%d]/radio-display", board );
369 radio_display_node = fgGetNode( base_name );
371 snprintf( base_name, 256, "/output/atc-board[%d]/steppers", board );
372 steppers_node = fgGetNode( base_name );
378 /////////////////////////////////////////////////////////////////////
380 /////////////////////////////////////////////////////////////////////
382 bool FGATCOutput::do_lamps() {
384 if ( lamps_out_node != NULL ) {
385 for ( int i = 0; i < lamps_out_node->nChildren(); ++i ) {
386 // read the next config entry from the property tree
388 SGPropertyNode *child = lamps_out_node->getChild(i);
389 string cname = child->getName();
390 int index = child->getIndex();
393 SGPropertyNode *src_prop = NULL;
394 if ( cname == "lamp" ) {
395 SGPropertyNode *prop;
396 prop = child->getChild( "name" );
397 if ( prop != NULL ) {
398 name = prop->getStringValue();
400 prop = child->getChild( "type" );
401 if ( prop != NULL ) {
402 type = prop->getStringValue();
404 prop = child->getChild( "prop" );
405 if ( prop != NULL ) {
406 src_prop = fgGetNode( prop->getStringValue(), true );
408 ATCSetLamp( lamps_fd, index, src_prop->getBoolValue() );
410 SG_LOG( SG_IO, SG_DEBUG,
411 "Input config error, expecting 'lamp' but found "
421 /////////////////////////////////////////////////////////////////////
422 // Update the radio display
423 /////////////////////////////////////////////////////////////////////
426 static bool navcom1_has_power() {
427 static SGPropertyNode *navcom1_bus_power
428 = fgGetNode( "/systems/electrical/outputs/nav[0]", true );
429 static SGPropertyNode *navcom1_power_btn
430 = fgGetNode( "/instrumentation/nav[0]/power-btn", true );
432 return (navcom1_bus_power->getDoubleValue() > 1.0)
433 && navcom1_power_btn->getBoolValue();
436 static bool navcom2_has_power() {
437 static SGPropertyNode *navcom2_bus_power
438 = fgGetNode( "/systems/electrical/outputs/nav[1]", true );
439 static SGPropertyNode *navcom2_power_btn
440 = fgGetNode( "/instrumentation/nav[1]/power-btn", true );
442 return (navcom2_bus_power->getDoubleValue() > 1.0)
443 && navcom2_power_btn->getBoolValue();
446 static bool dme_has_power() {
447 static SGPropertyNode *dme_bus_power
448 = fgGetNode( "/systems/electrical/outputs/dme", true );
450 return (dme_bus_power->getDoubleValue() > 1.0);
453 static bool adf_has_power() {
454 static SGPropertyNode *adf_bus_power
455 = fgGetNode( "/systems/electrical/outputs/adf", true );
456 static SGPropertyNode *adf_power_btn
457 = fgGetNode( "/instrumentation/kr-87/inputs/power-btn", true );
459 return (adf_bus_power->getDoubleValue() > 1.0)
460 && adf_power_btn->getBoolValue();
463 static bool xpdr_has_power() {
464 static SGPropertyNode *xpdr_bus_power
465 = fgGetNode( "/systems/electrical/outputs/transponder", true );
466 static SGPropertyNode *xpdr_func_knob
467 = fgGetNode( "/instrumentation/transponder/inputs/func-knob", true );
469 return (xpdr_bus_power->getDoubleValue() > 1.0)
470 && (xpdr_func_knob->getIntValue() > 0);
473 bool FGATCOutput::do_radio_display() {
474 static SGPropertyNode *dme_serviceable
475 = fgGetNode( "/instrumentation/dme/serviceable", true );
476 static SGPropertyNode *dme_in_range
477 = fgGetNode( "/instrumentation/dme/in-range", true );
478 static SGPropertyNode *dme_min
479 = fgGetNode( "/instrumentation/dme/indicated-time-min", true );
480 static SGPropertyNode *dme_kt
481 = fgGetNode( "/instrumentation/dme/indicated-ground-speed-kt", true );
482 static SGPropertyNode *dme_nm
483 = fgGetNode( "/instrumentation/dme/indicated-distance-nm", true );
485 static SGPropertyNode *comm1_serviceable
486 = fgGetNode( "/instrumentation/comm[0]/serviceable", true );
487 static SGPropertyNode *com1_freq
488 = fgGetNode( "/instrumentation/comm[0]/frequencies/selected-mhz", true);
489 static SGPropertyNode *com1_stby_freq
490 = fgGetNode( "/instrumentation/comm[0]/frequencies/standby-mhz", true );
492 static SGPropertyNode *comm2_serviceable
493 = fgGetNode( "/instrumentation/comm[1]/serviceable", true );
494 static SGPropertyNode *com2_freq
495 = fgGetNode( "/instrumentation/comm[1]/frequencies/selected-mhz", true);
496 static SGPropertyNode *com2_stby_freq
497 = fgGetNode( "/instrumentation/comm[1]/frequencies/standby-mhz", true );
499 static SGPropertyNode *nav1_serviceable
500 = fgGetNode( "/instrumentation/nav[0]/serviceable", true );
501 static SGPropertyNode *nav1_freq
502 = fgGetNode( "/instrumentation/nav[0]/frequencies/selected-mhz", true );
503 static SGPropertyNode *nav1_stby_freq
504 = fgGetNode( "/instrumentation/nav[0]/frequencies/standby-mhz", true );
506 static SGPropertyNode *nav2_serviceable
507 = fgGetNode( "/instrumentation/nav[1]/serviceable", true );
508 static SGPropertyNode *nav2_freq
509 = fgGetNode( "/instrumentation/nav[1]/frequencies/selected-mhz", true );
510 static SGPropertyNode *nav2_stby_freq
511 = fgGetNode( "/instrumentation/nav[1]/frequencies/standby-mhz", true );
513 static SGPropertyNode *adf_serviceable
514 = fgGetNode( "/instrumentation/adf/serviceable", true );
515 static SGPropertyNode *adf_freq
516 = fgGetNode( "/instrumentation/kr-87/outputs/selected-khz", true );
517 static SGPropertyNode *adf_stby_freq
518 = fgGetNode( "/instrumentation/kr-87/outputs/standby-khz", true );
519 static SGPropertyNode *adf_stby_mode
520 = fgGetNode( "/instrumentation/kr-87/modes/stby", true );
521 static SGPropertyNode *adf_timer_mode
522 = fgGetNode( "/instrumentation/kr-87/modes/timer", true );
523 // static SGPropertyNode *adf_count_mode
524 // = fgGetNode( "/instrumentation/kr-87/modes/count", true );
525 static SGPropertyNode *adf_flight_timer
526 = fgGetNode( "/instrumentation/kr-87/outputs/flight-timer", true );
527 static SGPropertyNode *adf_elapsed_timer
528 = fgGetNode( "/instrumentation/kr-87/outputs/elapsed-timer", true );
530 static SGPropertyNode *xpdr_serviceable
531 = fgGetNode( "/instrumentation/transponder/inputs/serviceable", true );
532 static SGPropertyNode *xpdr_func_knob
533 = fgGetNode( "/instrumentation/transponder/inputs/func-knob", true );
534 static SGPropertyNode *xpdr_flight_level
535 = fgGetNode( "/instrumentation/transponder/outputs/flight-level", true );
536 static SGPropertyNode *xpdr_id_code
537 = fgGetNode( "/instrumentation/transponder/outputs/id-code", true );
542 if ( dme_has_power() && dme_serviceable->getBoolValue() ) {
543 if ( dme_in_range->getBoolValue() ) {
545 float minutes = dme_min->getFloatValue();
546 if ( minutes > 999 ) {
549 snprintf(digits, 7, "%03.0f", minutes);
550 for ( i = 0; i < 6; ++i ) {
553 radio_display_data[0] = digits[1] << 4 | digits[2];
554 radio_display_data[1] = 0xf0 | digits[0];
557 float knots = dme_kt->getFloatValue();
561 snprintf(digits, 7, "%03.0f", knots);
562 for ( i = 0; i < 6; ++i ) {
565 radio_display_data[2] = digits[1] << 4 | digits[2];
566 radio_display_data[3] = 0xf0 | digits[0];
569 float nm = dme_nm->getFloatValue();
573 snprintf(digits, 7, "%04.1f", nm);
574 for ( i = 0; i < 6; ++i ) {
577 radio_display_data[4] = digits[1] << 4 | digits[3];
578 radio_display_data[5] = 0x00 | digits[0];
579 // the 0x00 in the upper nibble of the 6th byte of each
580 // display turns on the decimal point
583 radio_display_data[0] = 0xbb;
584 radio_display_data[1] = 0xfb;
585 radio_display_data[2] = 0xbb;
586 radio_display_data[3] = 0xfb;
587 radio_display_data[4] = 0xbb;
588 radio_display_data[5] = 0x0b;
592 for ( i = 0; i < 6; ++i ) {
593 radio_display_data[i] = 0xff;
597 if ( navcom1_has_power() && comm1_serviceable->getBoolValue() ) {
598 // Com1 standby frequency
599 float com1_stby = com1_stby_freq->getFloatValue();
600 if ( fabs(com1_stby) > 999.99 ) {
603 snprintf(digits, 7, "%06.3f", com1_stby);
604 for ( i = 0; i < 6; ++i ) {
607 radio_display_data[6] = digits[4] << 4 | digits[5];
608 radio_display_data[7] = digits[1] << 4 | digits[2];
609 radio_display_data[8] = 0xf0 | digits[0];
611 // Com1 in use frequency
612 float com1 = com1_freq->getFloatValue();
613 if ( fabs(com1) > 999.99 ) {
616 snprintf(digits, 7, "%06.3f", com1);
617 for ( i = 0; i < 6; ++i ) {
620 radio_display_data[9] = digits[4] << 4 | digits[5];
621 radio_display_data[10] = digits[1] << 4 | digits[2];
622 radio_display_data[11] = 0x00 | digits[0];
623 // the 0x00 in the upper nibble of the 6th byte of each display
624 // turns on the decimal point
626 radio_display_data[6] = 0xff;
627 radio_display_data[7] = 0xff;
628 radio_display_data[8] = 0xff;
629 radio_display_data[9] = 0xff;
630 radio_display_data[10] = 0xff;
631 radio_display_data[11] = 0xff;
634 if ( navcom2_has_power() && comm2_serviceable->getBoolValue() ) {
635 // Com2 standby frequency
636 float com2_stby = com2_stby_freq->getFloatValue();
637 if ( fabs(com2_stby) > 999.99 ) {
640 snprintf(digits, 7, "%06.3f", com2_stby);
641 for ( i = 0; i < 6; ++i ) {
644 radio_display_data[18] = digits[4] << 4 | digits[5];
645 radio_display_data[19] = digits[1] << 4 | digits[2];
646 radio_display_data[20] = 0xf0 | digits[0];
648 // Com2 in use frequency
649 float com2 = com2_freq->getFloatValue();
650 if ( fabs(com2) > 999.99 ) {
653 snprintf(digits, 7, "%06.3f", com2);
654 for ( i = 0; i < 6; ++i ) {
657 radio_display_data[21] = digits[4] << 4 | digits[5];
658 radio_display_data[22] = digits[1] << 4 | digits[2];
659 radio_display_data[23] = 0x00 | digits[0];
660 // the 0x00 in the upper nibble of the 6th byte of each display
661 // turns on the decimal point
663 radio_display_data[18] = 0xff;
664 radio_display_data[19] = 0xff;
665 radio_display_data[20] = 0xff;
666 radio_display_data[21] = 0xff;
667 radio_display_data[22] = 0xff;
668 radio_display_data[23] = 0xff;
671 if ( navcom1_has_power() && nav1_serviceable->getBoolValue() ) {
672 // Nav1 standby frequency
673 float nav1_stby = nav1_stby_freq->getFloatValue();
674 if ( fabs(nav1_stby) > 999.99 ) {
677 snprintf(digits, 7, "%06.2f", nav1_stby);
678 for ( i = 0; i < 6; ++i ) {
681 radio_display_data[12] = digits[4] << 4 | digits[5];
682 radio_display_data[13] = digits[1] << 4 | digits[2];
683 radio_display_data[14] = 0xf0 | digits[0];
685 // Nav1 in use frequency
686 float nav1 = nav1_freq->getFloatValue();
687 if ( fabs(nav1) > 999.99 ) {
690 snprintf(digits, 7, "%06.2f", nav1);
691 for ( i = 0; i < 6; ++i ) {
694 radio_display_data[15] = digits[4] << 4 | digits[5];
695 radio_display_data[16] = digits[1] << 4 | digits[2];
696 radio_display_data[17] = 0x00 | digits[0];
697 // the 0x00 in the upper nibble of the 6th byte of each display
698 // turns on the decimal point
700 radio_display_data[12] = 0xff;
701 radio_display_data[13] = 0xff;
702 radio_display_data[14] = 0xff;
703 radio_display_data[15] = 0xff;
704 radio_display_data[16] = 0xff;
705 radio_display_data[17] = 0xff;
708 if ( navcom2_has_power() && nav2_serviceable->getBoolValue() ) {
709 // Nav2 standby frequency
710 float nav2_stby = nav2_stby_freq->getFloatValue();
711 if ( fabs(nav2_stby) > 999.99 ) {
714 snprintf(digits, 7, "%06.2f", nav2_stby);
715 for ( i = 0; i < 6; ++i ) {
718 radio_display_data[24] = digits[4] << 4 | digits[5];
719 radio_display_data[25] = digits[1] << 4 | digits[2];
720 radio_display_data[26] = 0xf0 | digits[0];
722 // Nav2 in use frequency
723 float nav2 = nav2_freq->getFloatValue();
724 if ( fabs(nav2) > 999.99 ) {
727 snprintf(digits, 7, "%06.2f", nav2);
728 for ( i = 0; i < 6; ++i ) {
731 radio_display_data[27] = digits[4] << 4 | digits[5];
732 radio_display_data[28] = digits[1] << 4 | digits[2];
733 radio_display_data[29] = 0x00 | digits[0];
734 // the 0x00 in the upper nibble of the 6th byte of each display
735 // turns on the decimal point
737 radio_display_data[24] = 0xff;
738 radio_display_data[25] = 0xff;
739 radio_display_data[26] = 0xff;
740 radio_display_data[27] = 0xff;
741 radio_display_data[28] = 0xff;
742 radio_display_data[29] = 0xff;
745 // ADF standby frequency / timer
746 if ( adf_has_power() && adf_serviceable->getBoolValue() ) {
747 if ( adf_stby_mode->getIntValue() == 0 ) {
749 float adf_stby = adf_stby_freq->getFloatValue();
750 if ( fabs(adf_stby) > 1799 ) {
753 snprintf(digits, 7, "%04.0f", adf_stby);
754 for ( i = 0; i < 6; ++i ) {
757 radio_display_data[30] = digits[3] << 4 | 0x0f;
758 radio_display_data[31] = digits[1] << 4 | digits[2];
759 if ( digits[0] == 0 ) {
760 radio_display_data[32] = 0xff;
762 radio_display_data[32] = 0xf0 | digits[0];
768 if ( adf_timer_mode->getIntValue() == 0 ) {
769 time = adf_flight_timer->getDoubleValue();
771 time = adf_elapsed_timer->getDoubleValue();
773 // cout << time << endl;
774 hours = (int)(time / 3600.0);
775 time -= hours * 3600.00;
776 min = (int)(time / 60.0);
793 // cout << big << ":" << little << endl;
794 snprintf(digits, 7, "%02d%02d", big, little);
795 for ( i = 0; i < 6; ++i ) {
798 radio_display_data[30] = digits[2] << 4 | digits[3];
799 radio_display_data[31] = digits[0] << 4 | digits[1];
800 radio_display_data[32] = 0xff;
803 // ADF in use frequency
804 float adf = adf_freq->getFloatValue();
805 if ( fabs(adf) > 1799 ) {
808 snprintf(digits, 7, "%04.0f", adf);
809 for ( i = 0; i < 6; ++i ) {
812 radio_display_data[33] = digits[2] << 4 | digits[3];
813 if ( digits[0] == 0 ) {
814 radio_display_data[34] = 0xf0 | digits[1];
816 radio_display_data[34] = digits[0] << 4 | digits[1];
818 if ( adf_stby_mode->getIntValue() == 0 ) {
819 radio_display_data[35] = 0xff;
821 radio_display_data[35] = 0x0f;
824 radio_display_data[30] = 0xff;
825 radio_display_data[31] = 0xff;
826 radio_display_data[32] = 0xff;
827 radio_display_data[33] = 0xff;
828 radio_display_data[34] = 0xff;
829 radio_display_data[35] = 0xff;
832 // Transponder code and flight level
833 if ( xpdr_has_power() && xpdr_serviceable->getBoolValue() ) {
834 if ( xpdr_func_knob->getIntValue() == 2 ) {
836 radio_display_data[36] = 8 << 4 | 8;
837 radio_display_data[37] = 8 << 4 | 8;
838 radio_display_data[38] = 0xff;
839 radio_display_data[39] = 8 << 4 | 0x0f;
840 radio_display_data[40] = 8 << 4 | 8;
843 int id_code = xpdr_id_code->getIntValue();
845 for ( i = 0; i < 4; ++i ) {
846 digits[i] = id_code / place;
847 id_code -= digits[i] * place;
850 radio_display_data[36] = digits[2] << 4 | digits[3];
851 radio_display_data[37] = digits[0] << 4 | digits[1];
852 radio_display_data[38] = 0xff;
854 if ( xpdr_func_knob->getIntValue() == 3 ||
855 xpdr_func_knob->getIntValue() == 5 )
857 // do flight level display
858 snprintf(digits, 7, "%03d", xpdr_flight_level->getIntValue() );
859 for ( i = 0; i < 6; ++i ) {
862 radio_display_data[39] = digits[2] << 4 | 0x0f;
863 radio_display_data[40] = digits[0] << 4 | digits[1];
865 // blank flight level display
866 radio_display_data[39] = 0xff;
867 radio_display_data[40] = 0xff;
872 radio_display_data[36] = 0xff;
873 radio_display_data[37] = 0xff;
874 radio_display_data[38] = 0xff;
875 radio_display_data[39] = 0xff;
876 radio_display_data[40] = 0xff;
879 ATCSetRadios( radio_display_fd, radio_display_data );
885 /////////////////////////////////////////////////////////////////////
886 // Drive the stepper motors
887 /////////////////////////////////////////////////////////////////////
889 bool FGATCOutput::do_steppers() {
890 SGPropertyNode *mag_compass
891 = fgGetNode( "/instrumentation/magnetic-compass/indicated-heading-deg",
894 float diff = mag_compass->getFloatValue() - compass_position;
895 while ( diff < -180.0 ) { diff += 360.0; }
896 while ( diff > 180.0 ) { diff -= 360.0; }
898 int steps = (int)(diff * 4);
899 // cout << "steps = " << steps << endl;
900 if ( steps > 4 ) { steps = 4; }
901 if ( steps < -4 ) { steps = -4; }
903 if ( abs(steps) > 0 ) {
904 unsigned char cmd = 0x80; // stepper command
906 cmd |= 0x20; // go up
908 cmd |= 0x00; // go down
912 // sync compass_position with hardware position
913 compass_position += (float)steps / 4.0;
915 ATCSetStepper( stepper_fd, ATC_COMPASS_CH, cmd );
922 // process the hardware outputs. This code assumes the calling layer
923 // will lock the hardware.
924 bool FGATCOutput::process() {
926 SG_LOG( SG_IO, SG_ALERT, "This board has not been opened for output! "
939 bool FGATCOutput::close() {
941 #if defined( unix ) || defined( __CYGWIN__ )
949 result = ::close( lamps_fd );
950 if ( result == -1 ) {
951 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
953 snprintf( msg, 256, "Error closing %s", lamps_file );
958 result = ::close( radio_display_fd );
959 if ( result == -1 ) {
960 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
962 snprintf( msg, 256, "Error closing %s", radio_display_file );
967 result = ::close( stepper_fd );
968 if ( result == -1 ) {
969 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
971 snprintf( msg, 256, "Error closing %s", stepper_file );