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 ) {
51 lseek( fd, 0, SEEK_SET );
54 int result = read( fd, tmp, 1 );
56 SG_LOG( SG_IO, SG_DEBUG, "Lock failed" );
63 // Release the ATC hardware
64 static int ATCRelease( int fd ) {
66 lseek( fd, 0, SEEK_SET );
70 int result = write( fd, tmp, 1 );
73 SG_LOG( SG_IO, SG_DEBUG, "Release failed" );
80 // Constructor: The _board parameter specifies which board to
81 // reference. Possible values are 0 or 1. The _config_file parameter
82 // specifies the location of the output config file (xml)
83 FGATCOutput::FGATCOutput( const int _board, const SGPath &_config_file ) :
86 radio_display_node(NULL),
90 config = _config_file;
94 // Write a radios command
95 static int ATCSetRadios( int fd, unsigned char data[ATC_RADIO_DISPLAY_BYTES] ) {
97 lseek( fd, 0, SEEK_SET );
99 int result = write( fd, data, ATC_RADIO_DISPLAY_BYTES );
101 if ( result != ATC_RADIO_DISPLAY_BYTES ) {
102 SG_LOG( SG_IO, SG_DEBUG, "Write failed" );
109 // Write a stepper command
110 static int ATCSetStepper( int fd, unsigned char channel,
111 unsigned char value )
114 lseek( fd, 0, SEEK_SET );
117 unsigned char buf[3];
121 int result = write( fd, buf, 2 );
123 SG_LOG( SG_IO, SG_INFO, "Write failed" );
125 SG_LOG( SG_IO, SG_DEBUG,
126 "Sent cmd = " << (int)channel << " value = " << (int)value );
131 // Read status of last stepper written to
132 static unsigned char ATCReadStepper( int fd ) {
136 lseek( fd, 0, SEEK_SET );
139 unsigned char buf[2];
140 result = read( fd, buf, 1 );
142 SG_LOG( SG_IO, SG_ALERT, "Read failed" );
145 SG_LOG( SG_IO, SG_DEBUG, "Read result = " << (int)buf[0] );
151 // Turn a lamp on or off
152 void ATCSetLamp( int fd, int channel, bool value ) {
153 // lamp channels 0-63 are written to LampPort0, channels 64-127
154 // are written to LampPort1
156 // bits 0-6 are the lamp address
157 // bit 7 is the value (on/off)
162 unsigned char buf[3];
166 result = write( fd, buf, 2 );
168 SG_LOG( SG_IO, SG_ALERT, "Write failed" );
174 void FGATCOutput::init_config() {
175 #if defined( unix ) || defined( __CYGWIN__ )
176 if ( config.str()[0] != '/' ) {
177 // not an absolute path, prepend the standard location
179 char *envp = ::getenv( "HOME" );
180 if ( envp != NULL ) {
182 tmp.append( ".atcflightsim" );
183 tmp.append( config.str() );
187 readProperties( config.str(), globals->get_props() );
192 // Open and initialize the ATC hardware
193 bool FGATCOutput::open( int lock_fd ) {
195 SG_LOG( SG_IO, SG_ALERT, "This board is already open for output! "
200 // This loads the config parameters generated by "simcal"
203 SG_LOG( SG_IO, SG_ALERT,
204 "Initializing ATC hardware, please wait ..." );
206 snprintf( lamps_file, 256, "/proc/atc610x/board%d/lamps", board );
207 snprintf( radio_display_file, 256, "/proc/atc610x/board%d/radios", board );
208 snprintf( stepper_file, 256, "/proc/atc610x/board%d/steppers", board );
210 #if defined( unix ) || defined( __CYGWIN__ )
212 /////////////////////////////////////////////////////////////////////
213 // Open the /proc files
214 /////////////////////////////////////////////////////////////////////
216 lamps_fd = ::open( lamps_file, O_WRONLY );
217 if ( lamps_fd == -1 ) {
218 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
220 snprintf( msg, 256, "Error opening %s", lamps_file );
225 radio_display_fd = ::open( radio_display_file, O_RDWR );
226 if ( radio_display_fd == -1 ) {
227 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
229 snprintf( msg, 256, "Error opening %s", radio_display_file );
234 stepper_fd = ::open( stepper_file, O_RDWR );
235 if ( stepper_fd == -1 ) {
236 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
238 snprintf( msg, 256, "Error opening %s", stepper_file );
245 /////////////////////////////////////////////////////////////////////
246 // Home the compass stepper motor
247 /////////////////////////////////////////////////////////////////////
249 SG_LOG( SG_IO, SG_ALERT,
250 " - Homing the compass stepper motor" );
252 // Lock the hardware, keep trying until we succeed
253 while ( ATCLock( lock_fd ) <= 0 );
255 // Send the stepper home command
256 ATCSetStepper( stepper_fd, ATC_COMPASS_CH, ATC_STEPPER_HOME );
258 // Release the hardware
259 ATCRelease( lock_fd );
261 SG_LOG( SG_IO, SG_ALERT,
262 " - Waiting for compass to come home." );
265 int timeout = 900; // about 30 seconds
267 while ( ! home && timeout > 0 ) {
268 if ( timeout % 150 == 0 ) {
269 SG_LOG( SG_IO, SG_INFO, "waiting for compass = " << timeout );
271 SG_LOG( SG_IO, SG_DEBUG, "Checking if compass home ..." );
274 while ( ATCLock( lock_fd ) <= 0 );
276 unsigned char result = ATCReadStepper( stepper_fd );
281 ATCRelease( lock_fd );
283 #if defined( _MSC_VER )
284 ulMilliSecondSleep(33);
285 #elif defined (WIN32) && !defined(__CYGWIN__)
294 compass_position = 0.0;
296 /////////////////////////////////////////////////////////////////////
297 // Blank the radio display
298 /////////////////////////////////////////////////////////////////////
300 SG_LOG( SG_IO, SG_ALERT,
301 " - Clearing the radios displays." );
304 unsigned char value = 0xff;
305 for ( int channel = 0; channel < ATC_RADIO_DISPLAY_BYTES; ++channel ) {
306 radio_display_data[channel] = value;
309 // Lock the hardware, keep trying until we succeed
310 while ( ATCLock( lock_fd ) <= 0 );
313 ATCSetRadios( radio_display_fd, radio_display_data );
315 ATCRelease( lock_fd );
317 /////////////////////////////////////////////////////////////////////
319 /////////////////////////////////////////////////////////////////////
321 for ( int i = 0; i < 128; ++i ) {
322 ATCSetLamp( lamps_fd, i, false );
325 /////////////////////////////////////////////////////////////////////
326 // Finished initing hardware
327 /////////////////////////////////////////////////////////////////////
329 SG_LOG( SG_IO, SG_ALERT,
330 "Done initializing ATC hardware." );
334 /////////////////////////////////////////////////////////////////////
335 // Connect up to property values
336 /////////////////////////////////////////////////////////////////////
340 snprintf( base_name, 256, "/output/atc-board[%d]/lamps", board );
341 lamps_out_node = fgGetNode( base_name );
343 snprintf( base_name, 256, "/output/atc-board[%d]/radio-display", board );
344 radio_display_node = fgGetNode( base_name );
346 snprintf( base_name, 256, "/output/atc-board[%d]/steppers", board );
347 steppers_node = fgGetNode( base_name );
353 /////////////////////////////////////////////////////////////////////
355 /////////////////////////////////////////////////////////////////////
357 bool FGATCOutput::do_lamps() {
359 if ( lamps_out_node != NULL ) {
360 for ( int i = 0; i < lamps_out_node->nChildren(); ++i ) {
361 // read the next config entry from the property tree
363 SGPropertyNode *child = lamps_out_node->getChild(i);
364 string cname = child->getName();
365 int index = child->getIndex();
368 SGPropertyNode *src_prop = NULL;
369 if ( cname == "lamp" ) {
370 SGPropertyNode *prop;
371 prop = child->getChild( "name" );
372 if ( prop != NULL ) {
373 name = prop->getStringValue();
375 prop = child->getChild( "type" );
376 if ( prop != NULL ) {
377 type = prop->getStringValue();
379 prop = child->getChild( "prop" );
380 if ( prop != NULL ) {
381 src_prop = fgGetNode( prop->getStringValue(), true );
383 ATCSetLamp( lamps_fd, index, src_prop->getBoolValue() );
385 SG_LOG( SG_IO, SG_DEBUG,
386 "Input config error, expecting 'lamp' but found "
396 /////////////////////////////////////////////////////////////////////
397 // Update the radio display
398 /////////////////////////////////////////////////////////////////////
401 static bool navcom1_has_power() {
402 static SGPropertyNode *navcom1_bus_power
403 = fgGetNode( "/systems/electrical/outputs/nav[0]", true );
404 static SGPropertyNode *navcom1_power_btn
405 = fgGetNode( "/instrumentation/comm[0]/inputs/power-btn", true );
407 return (navcom1_bus_power->getDoubleValue() > 1.0)
408 && navcom1_power_btn->getBoolValue();
411 static bool navcom2_has_power() {
412 static SGPropertyNode *navcom2_bus_power
413 = fgGetNode( "/systems/electrical/outputs/nav[1]", true );
414 static SGPropertyNode *navcom2_power_btn
415 = fgGetNode( "/instrumentation/comm[1]/inputs/power-btn", true );
417 return (navcom2_bus_power->getDoubleValue() > 1.0)
418 && navcom2_power_btn->getBoolValue();
421 static bool dme_has_power() {
422 static SGPropertyNode *dme_bus_power
423 = fgGetNode( "/systems/electrical/outputs/dme", true );
425 return (dme_bus_power->getDoubleValue() > 1.0);
428 static bool adf_has_power() {
429 static SGPropertyNode *adf_bus_power
430 = fgGetNode( "/systems/electrical/outputs/adf", true );
431 static SGPropertyNode *adf_power_btn
432 = fgGetNode( "/instrumentation/kr-87/inputs/power-btn", true );
434 return (adf_bus_power->getDoubleValue() > 1.0)
435 && adf_power_btn->getBoolValue();
438 static bool xpdr_has_power() {
439 static SGPropertyNode *xpdr_bus_power
440 = fgGetNode( "/systems/electrical/outputs/transponder", true );
441 static SGPropertyNode *xpdr_func_knob
442 = fgGetNode( "/instrumentation/kt-70/inputs/func-knob", true );
444 return (xpdr_bus_power->getDoubleValue() > 1.0)
445 && (xpdr_func_knob->getIntValue() > 0);
448 bool FGATCOutput::do_radio_display() {
449 static SGPropertyNode *dme_serviceable
450 = fgGetNode( "/instrumentation/dme/serviceable", true );
451 static SGPropertyNode *dme_in_range
452 = fgGetNode( "/instrumentation/dme/in-range", true );
453 static SGPropertyNode *dme_min
454 = fgGetNode( "/instrumentation/dme/indicated-time-min", true );
455 static SGPropertyNode *dme_kt
456 = fgGetNode( "/instrumentation/dme/indicated-ground-speed-kt", true );
457 static SGPropertyNode *dme_nm
458 = fgGetNode( "/instrumentation/dme/indicated-distance-nm", true );
460 static SGPropertyNode *comm1_serviceable
461 = fgGetNode( "/instrumentation/comm[0]/serviceable", true );
462 static SGPropertyNode *com1_freq
463 = fgGetNode( "/instrumentation/comm[0]/frequencies/selected-mhz", true);
464 static SGPropertyNode *com1_stby_freq
465 = fgGetNode( "/instrumentation/comm[0]/frequencies/standby-mhz", true );
467 static SGPropertyNode *comm2_serviceable
468 = fgGetNode( "/instrumentation/comm[1]/serviceable", true );
469 static SGPropertyNode *com2_freq
470 = fgGetNode( "/instrumentation/comm[1]/frequencies/selected-mhz", true);
471 static SGPropertyNode *com2_stby_freq
472 = fgGetNode( "/instrumentation/comm[1]/frequencies/standby-mhz", true );
474 static SGPropertyNode *nav1_serviceable
475 = fgGetNode( "/instrumentation/nav[0]/serviceable", true );
476 static SGPropertyNode *nav1_freq
477 = fgGetNode( "/instrumentation/nav[0]/frequencies/selected-mhz", true );
478 static SGPropertyNode *nav1_stby_freq
479 = fgGetNode( "/instrumentation/nav[0]/frequencies/standby-mhz", true );
481 static SGPropertyNode *nav2_serviceable
482 = fgGetNode( "/instrumentation/nav[1]/serviceable", true );
483 static SGPropertyNode *nav2_freq
484 = fgGetNode( "/instrumentation/nav[1]/frequencies/selected-mhz", true );
485 static SGPropertyNode *nav2_stby_freq
486 = fgGetNode( "/instrumentation/nav[1]/frequencies/standby-mhz", true );
488 static SGPropertyNode *adf_serviceable
489 = fgGetNode( "/instrumentation/adf/serviceable", true );
490 static SGPropertyNode *adf_freq
491 = fgGetNode( "/instrumentation/kr-87/outputs/selected-khz", true );
492 static SGPropertyNode *adf_stby_freq
493 = fgGetNode( "/instrumentation/kr-87/outputs/standby-khz", true );
494 static SGPropertyNode *adf_stby_mode
495 = fgGetNode( "/instrumentation/kr-87/modes/stby", true );
496 static SGPropertyNode *adf_timer_mode
497 = fgGetNode( "/instrumentation/kr-87/modes/timer", true );
498 // static SGPropertyNode *adf_count_mode
499 // = fgGetNode( "/instrumentation/kr-87/modes/count", true );
500 static SGPropertyNode *adf_flight_timer
501 = fgGetNode( "/instrumentation/kr-87/outputs/flight-timer", true );
502 static SGPropertyNode *adf_elapsed_timer
503 = fgGetNode( "/instrumentation/kr-87/outputs/elapsed-timer", true );
505 static SGPropertyNode *xpdr_serviceable
506 = fgGetNode( "/instrumentation/kt-70/inputs/serviceable", true );
507 static SGPropertyNode *xpdr_func_knob
508 = fgGetNode( "/instrumentation/kt-70/inputs/func-knob", true );
509 static SGPropertyNode *xpdr_flight_level
510 = fgGetNode( "/instrumentation/kt-70/outputs/flight-level", true );
511 static SGPropertyNode *xpdr_id_code
512 = fgGetNode( "/instrumentation/kt-70/outputs/id-code", true );
517 if ( dme_has_power() && dme_serviceable->getBoolValue() ) {
518 if ( dme_in_range->getBoolValue() ) {
520 float minutes = dme_min->getFloatValue();
521 if ( minutes > 999 ) {
524 snprintf(digits, 7, "%03.0f", minutes);
525 for ( i = 0; i < 6; ++i ) {
528 radio_display_data[0] = digits[1] << 4 | digits[2];
529 radio_display_data[1] = 0xf0 | digits[0];
532 float knots = dme_kt->getFloatValue();
536 snprintf(digits, 7, "%03.0f", knots);
537 for ( i = 0; i < 6; ++i ) {
540 radio_display_data[2] = digits[1] << 4 | digits[2];
541 radio_display_data[3] = 0xf0 | digits[0];
544 float nm = dme_nm->getFloatValue();
548 snprintf(digits, 7, "%04.1f", nm);
549 for ( i = 0; i < 6; ++i ) {
552 radio_display_data[4] = digits[1] << 4 | digits[3];
553 radio_display_data[5] = 0x00 | digits[0];
554 // the 0x00 in the upper nibble of the 6th byte of each
555 // display turns on the decimal point
558 radio_display_data[0] = 0xbb;
559 radio_display_data[1] = 0xfb;
560 radio_display_data[2] = 0xbb;
561 radio_display_data[3] = 0xfb;
562 radio_display_data[4] = 0xbb;
563 radio_display_data[5] = 0x0b;
567 for ( i = 0; i < 6; ++i ) {
568 radio_display_data[i] = 0xff;
572 if ( navcom1_has_power() && comm1_serviceable->getBoolValue() ) {
573 // Com1 standby frequency
574 float com1_stby = com1_stby_freq->getFloatValue();
575 if ( fabs(com1_stby) > 999.99 ) {
578 snprintf(digits, 7, "%06.3f", com1_stby);
579 for ( i = 0; i < 6; ++i ) {
582 radio_display_data[6] = digits[4] << 4 | digits[5];
583 radio_display_data[7] = digits[1] << 4 | digits[2];
584 radio_display_data[8] = 0xf0 | digits[0];
586 // Com1 in use frequency
587 float com1 = com1_freq->getFloatValue();
588 if ( fabs(com1) > 999.99 ) {
591 snprintf(digits, 7, "%06.3f", com1);
592 for ( i = 0; i < 6; ++i ) {
595 radio_display_data[9] = digits[4] << 4 | digits[5];
596 radio_display_data[10] = digits[1] << 4 | digits[2];
597 radio_display_data[11] = 0x00 | digits[0];
598 // the 0x00 in the upper nibble of the 6th byte of each display
599 // turns on the decimal point
601 radio_display_data[6] = 0xff;
602 radio_display_data[7] = 0xff;
603 radio_display_data[8] = 0xff;
604 radio_display_data[9] = 0xff;
605 radio_display_data[10] = 0xff;
606 radio_display_data[11] = 0xff;
609 if ( navcom2_has_power() && comm2_serviceable->getBoolValue() ) {
610 // Com2 standby frequency
611 float com2_stby = com2_stby_freq->getFloatValue();
612 if ( fabs(com2_stby) > 999.99 ) {
615 snprintf(digits, 7, "%06.3f", com2_stby);
616 for ( i = 0; i < 6; ++i ) {
619 radio_display_data[18] = digits[4] << 4 | digits[5];
620 radio_display_data[19] = digits[1] << 4 | digits[2];
621 radio_display_data[20] = 0xf0 | digits[0];
623 // Com2 in use frequency
624 float com2 = com2_freq->getFloatValue();
625 if ( fabs(com2) > 999.99 ) {
628 snprintf(digits, 7, "%06.3f", com2);
629 for ( i = 0; i < 6; ++i ) {
632 radio_display_data[21] = digits[4] << 4 | digits[5];
633 radio_display_data[22] = digits[1] << 4 | digits[2];
634 radio_display_data[23] = 0x00 | digits[0];
635 // the 0x00 in the upper nibble of the 6th byte of each display
636 // turns on the decimal point
638 radio_display_data[18] = 0xff;
639 radio_display_data[19] = 0xff;
640 radio_display_data[20] = 0xff;
641 radio_display_data[21] = 0xff;
642 radio_display_data[22] = 0xff;
643 radio_display_data[23] = 0xff;
646 if ( navcom1_has_power() && nav1_serviceable->getBoolValue() ) {
647 // Nav1 standby frequency
648 float nav1_stby = nav1_stby_freq->getFloatValue();
649 if ( fabs(nav1_stby) > 999.99 ) {
652 snprintf(digits, 7, "%06.2f", nav1_stby);
653 for ( i = 0; i < 6; ++i ) {
656 radio_display_data[12] = digits[4] << 4 | digits[5];
657 radio_display_data[13] = digits[1] << 4 | digits[2];
658 radio_display_data[14] = 0xf0 | digits[0];
660 // Nav1 in use frequency
661 float nav1 = nav1_freq->getFloatValue();
662 if ( fabs(nav1) > 999.99 ) {
665 snprintf(digits, 7, "%06.2f", nav1);
666 for ( i = 0; i < 6; ++i ) {
669 radio_display_data[15] = digits[4] << 4 | digits[5];
670 radio_display_data[16] = digits[1] << 4 | digits[2];
671 radio_display_data[17] = 0x00 | digits[0];
672 // the 0x00 in the upper nibble of the 6th byte of each display
673 // turns on the decimal point
675 radio_display_data[12] = 0xff;
676 radio_display_data[13] = 0xff;
677 radio_display_data[14] = 0xff;
678 radio_display_data[15] = 0xff;
679 radio_display_data[16] = 0xff;
680 radio_display_data[17] = 0xff;
683 if ( navcom2_has_power() && nav2_serviceable->getBoolValue() ) {
684 // Nav2 standby frequency
685 float nav2_stby = nav2_stby_freq->getFloatValue();
686 if ( fabs(nav2_stby) > 999.99 ) {
689 snprintf(digits, 7, "%06.2f", nav2_stby);
690 for ( i = 0; i < 6; ++i ) {
693 radio_display_data[24] = digits[4] << 4 | digits[5];
694 radio_display_data[25] = digits[1] << 4 | digits[2];
695 radio_display_data[26] = 0xf0 | digits[0];
697 // Nav2 in use frequency
698 float nav2 = nav2_freq->getFloatValue();
699 if ( fabs(nav2) > 999.99 ) {
702 snprintf(digits, 7, "%06.2f", nav2);
703 for ( i = 0; i < 6; ++i ) {
706 radio_display_data[27] = digits[4] << 4 | digits[5];
707 radio_display_data[28] = digits[1] << 4 | digits[2];
708 radio_display_data[29] = 0x00 | digits[0];
709 // the 0x00 in the upper nibble of the 6th byte of each display
710 // turns on the decimal point
712 radio_display_data[24] = 0xff;
713 radio_display_data[25] = 0xff;
714 radio_display_data[26] = 0xff;
715 radio_display_data[27] = 0xff;
716 radio_display_data[28] = 0xff;
717 radio_display_data[29] = 0xff;
720 // ADF standby frequency / timer
721 if ( adf_has_power() && adf_serviceable->getBoolValue() ) {
722 if ( adf_stby_mode->getIntValue() == 0 ) {
724 float adf_stby = adf_stby_freq->getFloatValue();
725 if ( fabs(adf_stby) > 1799 ) {
728 snprintf(digits, 7, "%04.0f", adf_stby);
729 for ( i = 0; i < 6; ++i ) {
732 radio_display_data[30] = digits[3] << 4 | 0x0f;
733 radio_display_data[31] = digits[1] << 4 | digits[2];
734 if ( digits[0] == 0 ) {
735 radio_display_data[32] = 0xff;
737 radio_display_data[32] = 0xf0 | digits[0];
743 if ( adf_timer_mode->getIntValue() == 0 ) {
744 time = adf_flight_timer->getDoubleValue();
746 time = adf_elapsed_timer->getDoubleValue();
748 // cout << time << endl;
749 hours = (int)(time / 3600.0);
750 time -= hours * 3600.00;
751 min = (int)(time / 60.0);
768 // cout << big << ":" << little << endl;
769 snprintf(digits, 7, "%02d%02d", big, little);
770 for ( i = 0; i < 6; ++i ) {
773 radio_display_data[30] = digits[2] << 4 | digits[3];
774 radio_display_data[31] = digits[0] << 4 | digits[1];
775 radio_display_data[32] = 0xff;
778 // ADF in use frequency
779 float adf = adf_freq->getFloatValue();
780 if ( fabs(adf) > 1799 ) {
783 snprintf(digits, 7, "%04.0f", adf);
784 for ( i = 0; i < 6; ++i ) {
787 radio_display_data[33] = digits[2] << 4 | digits[3];
788 if ( digits[0] == 0 ) {
789 radio_display_data[34] = 0xf0 | digits[1];
791 radio_display_data[34] = digits[0] << 4 | digits[1];
793 if ( adf_stby_mode->getIntValue() == 0 ) {
794 radio_display_data[35] = 0xff;
796 radio_display_data[35] = 0x0f;
799 radio_display_data[30] = 0xff;
800 radio_display_data[31] = 0xff;
801 radio_display_data[32] = 0xff;
802 radio_display_data[33] = 0xff;
803 radio_display_data[34] = 0xff;
804 radio_display_data[35] = 0xff;
807 // Transponder code and flight level
808 if ( xpdr_has_power() && xpdr_serviceable->getBoolValue() ) {
809 if ( xpdr_func_knob->getIntValue() == 2 ) {
811 radio_display_data[36] = 8 << 4 | 8;
812 radio_display_data[37] = 8 << 4 | 8;
813 radio_display_data[38] = 0xff;
814 radio_display_data[39] = 8 << 4 | 0x0f;
815 radio_display_data[40] = 8 << 4 | 8;
818 int id_code = xpdr_id_code->getIntValue();
820 for ( i = 0; i < 4; ++i ) {
821 digits[i] = id_code / place;
822 id_code -= digits[i] * place;
825 radio_display_data[36] = digits[2] << 4 | digits[3];
826 radio_display_data[37] = digits[0] << 4 | digits[1];
827 radio_display_data[38] = 0xff;
829 if ( xpdr_func_knob->getIntValue() == 3 ||
830 xpdr_func_knob->getIntValue() == 5 )
832 // do flight level display
833 snprintf(digits, 7, "%03d", xpdr_flight_level->getIntValue() );
834 for ( i = 0; i < 6; ++i ) {
837 radio_display_data[39] = digits[2] << 4 | 0x0f;
838 radio_display_data[40] = digits[0] << 4 | digits[1];
840 // blank flight level display
841 radio_display_data[39] = 0xff;
842 radio_display_data[40] = 0xff;
847 radio_display_data[36] = 0xff;
848 radio_display_data[37] = 0xff;
849 radio_display_data[38] = 0xff;
850 radio_display_data[39] = 0xff;
851 radio_display_data[40] = 0xff;
854 ATCSetRadios( radio_display_fd, radio_display_data );
860 /////////////////////////////////////////////////////////////////////
861 // Drive the stepper motors
862 /////////////////////////////////////////////////////////////////////
864 bool FGATCOutput::do_steppers() {
865 SGPropertyNode *mag_compass
866 = fgGetNode( "/instrumentation/magnetic-compass/indicated-heading-deg",
869 float diff = mag_compass->getFloatValue() - compass_position;
870 while ( diff < -180.0 ) { diff += 360.0; }
871 while ( diff > 180.0 ) { diff -= 360.0; }
873 int steps = (int)(diff * 4);
874 // cout << "steps = " << steps << endl;
875 if ( steps > 4 ) { steps = 4; }
876 if ( steps < -4 ) { steps = -4; }
878 if ( abs(steps) > 0 ) {
879 unsigned char cmd = 0x80; // stepper command
881 cmd |= 0x20; // go up
883 cmd |= 0x00; // go down
887 // sync compass_position with hardware position
888 compass_position += (float)steps / 4.0;
890 ATCSetStepper( stepper_fd, ATC_COMPASS_CH, cmd );
897 // process the hardware outputs. This code assumes the calling layer
898 // will lock the hardware.
899 bool FGATCOutput::process() {
901 SG_LOG( SG_IO, SG_ALERT, "This board has not been opened for output! "
914 bool FGATCOutput::close() {
916 #if defined( unix ) || defined( __CYGWIN__ )
920 result = ::close( lamps_fd );
921 if ( result == -1 ) {
922 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
924 snprintf( msg, 256, "Error closing %s", lamps_file );
929 result = ::close( radio_display_fd );
930 if ( result == -1 ) {
931 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
933 snprintf( msg, 256, "Error closing %s", radio_display_file );
938 result = ::close( stepper_fd );
939 if ( result == -1 ) {
940 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
942 snprintf( msg, 256, "Error closing %s", stepper_file );