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 output hardware, please wait ..." );
206 snprintf( lamps_file, 256,
207 "/proc/atcflightsim/board%d/lamps", board );
208 snprintf( radio_display_file, 256,
209 "/proc/atcflightsim/board%d/radios", board );
210 snprintf( stepper_file, 256,
211 "/proc/atcflightsim/board%d/steppers", board );
213 #if defined( unix ) || defined( __CYGWIN__ )
215 /////////////////////////////////////////////////////////////////////
216 // Open the /proc files
217 /////////////////////////////////////////////////////////////////////
219 lamps_fd = ::open( lamps_file, O_WRONLY );
220 if ( lamps_fd == -1 ) {
221 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
223 snprintf( msg, 256, "Error opening %s", lamps_file );
228 radio_display_fd = ::open( radio_display_file, O_RDWR );
229 if ( radio_display_fd == -1 ) {
230 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
232 snprintf( msg, 256, "Error opening %s", radio_display_file );
237 stepper_fd = ::open( stepper_file, O_RDWR );
238 if ( stepper_fd == -1 ) {
239 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
241 snprintf( msg, 256, "Error opening %s", stepper_file );
248 /////////////////////////////////////////////////////////////////////
249 // Home the compass stepper motor
250 /////////////////////////////////////////////////////////////////////
252 SG_LOG( SG_IO, SG_ALERT,
253 " - Homing the compass stepper motor" );
255 // Lock the hardware, keep trying until we succeed
256 while ( ATCLock( lock_fd ) <= 0 );
258 // Send the stepper home command
259 ATCSetStepper( stepper_fd, ATC_COMPASS_CH, ATC_STEPPER_HOME );
261 // Release the hardware
262 ATCRelease( lock_fd );
264 SG_LOG( SG_IO, SG_ALERT,
265 " - Waiting for compass to come home." );
268 int timeout = 900; // about 30 seconds
270 while ( ! home && timeout > 0 ) {
271 if ( timeout % 150 == 0 ) {
272 SG_LOG( SG_IO, SG_INFO, "waiting for compass = " << timeout );
274 SG_LOG( SG_IO, SG_DEBUG, "Checking if compass home ..." );
277 while ( ATCLock( lock_fd ) <= 0 );
279 unsigned char result = ATCReadStepper( stepper_fd );
284 ATCRelease( lock_fd );
286 #if defined( _MSC_VER )
287 ulMilliSecondSleep(33);
288 #elif defined (WIN32) && !defined(__CYGWIN__)
297 compass_position = 0.0;
299 /////////////////////////////////////////////////////////////////////
300 // Blank the radio display
301 /////////////////////////////////////////////////////////////////////
303 SG_LOG( SG_IO, SG_ALERT,
304 " - Clearing the radios displays." );
307 unsigned char value = 0xff;
308 for ( int channel = 0; channel < ATC_RADIO_DISPLAY_BYTES; ++channel ) {
309 radio_display_data[channel] = value;
312 // Lock the hardware, keep trying until we succeed
313 while ( ATCLock( lock_fd ) <= 0 );
316 ATCSetRadios( radio_display_fd, radio_display_data );
318 ATCRelease( lock_fd );
320 /////////////////////////////////////////////////////////////////////
322 /////////////////////////////////////////////////////////////////////
324 for ( int i = 0; i < 128; ++i ) {
325 ATCSetLamp( lamps_fd, i, false );
328 /////////////////////////////////////////////////////////////////////
329 // Finished initing hardware
330 /////////////////////////////////////////////////////////////////////
332 SG_LOG( SG_IO, SG_ALERT,
333 "Done initializing ATC output hardware." );
337 /////////////////////////////////////////////////////////////////////
338 // Connect up to property values
339 /////////////////////////////////////////////////////////////////////
343 snprintf( base_name, 256, "/output/atc-board[%d]/lamps", board );
344 lamps_out_node = fgGetNode( base_name );
346 snprintf( base_name, 256, "/output/atc-board[%d]/radio-display", board );
347 radio_display_node = fgGetNode( base_name );
349 snprintf( base_name, 256, "/output/atc-board[%d]/steppers", board );
350 steppers_node = fgGetNode( base_name );
356 /////////////////////////////////////////////////////////////////////
358 /////////////////////////////////////////////////////////////////////
360 bool FGATCOutput::do_lamps() {
362 if ( lamps_out_node != NULL ) {
363 for ( int i = 0; i < lamps_out_node->nChildren(); ++i ) {
364 // read the next config entry from the property tree
366 SGPropertyNode *child = lamps_out_node->getChild(i);
367 string cname = child->getName();
368 int index = child->getIndex();
371 SGPropertyNode *src_prop = NULL;
372 if ( cname == "lamp" ) {
373 SGPropertyNode *prop;
374 prop = child->getChild( "name" );
375 if ( prop != NULL ) {
376 name = prop->getStringValue();
378 prop = child->getChild( "type" );
379 if ( prop != NULL ) {
380 type = prop->getStringValue();
382 prop = child->getChild( "prop" );
383 if ( prop != NULL ) {
384 src_prop = fgGetNode( prop->getStringValue(), true );
386 ATCSetLamp( lamps_fd, index, src_prop->getBoolValue() );
388 SG_LOG( SG_IO, SG_DEBUG,
389 "Input config error, expecting 'lamp' but found "
399 /////////////////////////////////////////////////////////////////////
400 // Update the radio display
401 /////////////////////////////////////////////////////////////////////
404 static bool navcom1_has_power() {
405 static SGPropertyNode *navcom1_bus_power
406 = fgGetNode( "/systems/electrical/outputs/nav[0]", true );
407 static SGPropertyNode *navcom1_power_btn
408 = fgGetNode( "/instrumentation/nav[0]/power-btn", true );
410 return (navcom1_bus_power->getDoubleValue() > 1.0)
411 && navcom1_power_btn->getBoolValue();
414 static bool navcom2_has_power() {
415 static SGPropertyNode *navcom2_bus_power
416 = fgGetNode( "/systems/electrical/outputs/nav[1]", true );
417 static SGPropertyNode *navcom2_power_btn
418 = fgGetNode( "/instrumentation/nav[1]/power-btn", true );
420 return (navcom2_bus_power->getDoubleValue() > 1.0)
421 && navcom2_power_btn->getBoolValue();
424 static bool dme_has_power() {
425 static SGPropertyNode *dme_bus_power
426 = fgGetNode( "/systems/electrical/outputs/dme", true );
428 return (dme_bus_power->getDoubleValue() > 1.0);
431 static bool adf_has_power() {
432 static SGPropertyNode *adf_bus_power
433 = fgGetNode( "/systems/electrical/outputs/adf", true );
434 static SGPropertyNode *adf_power_btn
435 = fgGetNode( "/instrumentation/kr-87/inputs/power-btn", true );
437 return (adf_bus_power->getDoubleValue() > 1.0)
438 && adf_power_btn->getBoolValue();
441 static bool xpdr_has_power() {
442 static SGPropertyNode *xpdr_bus_power
443 = fgGetNode( "/systems/electrical/outputs/transponder", true );
444 static SGPropertyNode *xpdr_func_knob
445 = fgGetNode( "/instrumentation/kt-70/inputs/func-knob", true );
447 return (xpdr_bus_power->getDoubleValue() > 1.0)
448 && (xpdr_func_knob->getIntValue() > 0);
451 bool FGATCOutput::do_radio_display() {
452 static SGPropertyNode *dme_serviceable
453 = fgGetNode( "/instrumentation/dme/serviceable", true );
454 static SGPropertyNode *dme_in_range
455 = fgGetNode( "/instrumentation/dme/in-range", true );
456 static SGPropertyNode *dme_min
457 = fgGetNode( "/instrumentation/dme/indicated-time-min", true );
458 static SGPropertyNode *dme_kt
459 = fgGetNode( "/instrumentation/dme/indicated-ground-speed-kt", true );
460 static SGPropertyNode *dme_nm
461 = fgGetNode( "/instrumentation/dme/indicated-distance-nm", true );
463 static SGPropertyNode *comm1_serviceable
464 = fgGetNode( "/instrumentation/comm[0]/serviceable", true );
465 static SGPropertyNode *com1_freq
466 = fgGetNode( "/instrumentation/comm[0]/frequencies/selected-mhz", true);
467 static SGPropertyNode *com1_stby_freq
468 = fgGetNode( "/instrumentation/comm[0]/frequencies/standby-mhz", true );
470 static SGPropertyNode *comm2_serviceable
471 = fgGetNode( "/instrumentation/comm[1]/serviceable", true );
472 static SGPropertyNode *com2_freq
473 = fgGetNode( "/instrumentation/comm[1]/frequencies/selected-mhz", true);
474 static SGPropertyNode *com2_stby_freq
475 = fgGetNode( "/instrumentation/comm[1]/frequencies/standby-mhz", true );
477 static SGPropertyNode *nav1_serviceable
478 = fgGetNode( "/instrumentation/nav[0]/serviceable", true );
479 static SGPropertyNode *nav1_freq
480 = fgGetNode( "/instrumentation/nav[0]/frequencies/selected-mhz", true );
481 static SGPropertyNode *nav1_stby_freq
482 = fgGetNode( "/instrumentation/nav[0]/frequencies/standby-mhz", true );
484 static SGPropertyNode *nav2_serviceable
485 = fgGetNode( "/instrumentation/nav[1]/serviceable", true );
486 static SGPropertyNode *nav2_freq
487 = fgGetNode( "/instrumentation/nav[1]/frequencies/selected-mhz", true );
488 static SGPropertyNode *nav2_stby_freq
489 = fgGetNode( "/instrumentation/nav[1]/frequencies/standby-mhz", true );
491 static SGPropertyNode *adf_serviceable
492 = fgGetNode( "/instrumentation/adf/serviceable", true );
493 static SGPropertyNode *adf_freq
494 = fgGetNode( "/instrumentation/kr-87/outputs/selected-khz", true );
495 static SGPropertyNode *adf_stby_freq
496 = fgGetNode( "/instrumentation/kr-87/outputs/standby-khz", true );
497 static SGPropertyNode *adf_stby_mode
498 = fgGetNode( "/instrumentation/kr-87/modes/stby", true );
499 static SGPropertyNode *adf_timer_mode
500 = fgGetNode( "/instrumentation/kr-87/modes/timer", true );
501 // static SGPropertyNode *adf_count_mode
502 // = fgGetNode( "/instrumentation/kr-87/modes/count", true );
503 static SGPropertyNode *adf_flight_timer
504 = fgGetNode( "/instrumentation/kr-87/outputs/flight-timer", true );
505 static SGPropertyNode *adf_elapsed_timer
506 = fgGetNode( "/instrumentation/kr-87/outputs/elapsed-timer", true );
508 static SGPropertyNode *xpdr_serviceable
509 = fgGetNode( "/instrumentation/kt-70/inputs/serviceable", true );
510 static SGPropertyNode *xpdr_func_knob
511 = fgGetNode( "/instrumentation/kt-70/inputs/func-knob", true );
512 static SGPropertyNode *xpdr_flight_level
513 = fgGetNode( "/instrumentation/kt-70/outputs/flight-level", true );
514 static SGPropertyNode *xpdr_id_code
515 = fgGetNode( "/instrumentation/kt-70/outputs/id-code", true );
520 if ( dme_has_power() && dme_serviceable->getBoolValue() ) {
521 if ( dme_in_range->getBoolValue() ) {
523 float minutes = dme_min->getFloatValue();
524 if ( minutes > 999 ) {
527 snprintf(digits, 7, "%03.0f", minutes);
528 for ( i = 0; i < 6; ++i ) {
531 radio_display_data[0] = digits[1] << 4 | digits[2];
532 radio_display_data[1] = 0xf0 | digits[0];
535 float knots = dme_kt->getFloatValue();
539 snprintf(digits, 7, "%03.0f", knots);
540 for ( i = 0; i < 6; ++i ) {
543 radio_display_data[2] = digits[1] << 4 | digits[2];
544 radio_display_data[3] = 0xf0 | digits[0];
547 float nm = dme_nm->getFloatValue();
551 snprintf(digits, 7, "%04.1f", nm);
552 for ( i = 0; i < 6; ++i ) {
555 radio_display_data[4] = digits[1] << 4 | digits[3];
556 radio_display_data[5] = 0x00 | digits[0];
557 // the 0x00 in the upper nibble of the 6th byte of each
558 // display turns on the decimal point
561 radio_display_data[0] = 0xbb;
562 radio_display_data[1] = 0xfb;
563 radio_display_data[2] = 0xbb;
564 radio_display_data[3] = 0xfb;
565 radio_display_data[4] = 0xbb;
566 radio_display_data[5] = 0x0b;
570 for ( i = 0; i < 6; ++i ) {
571 radio_display_data[i] = 0xff;
575 if ( navcom1_has_power() && comm1_serviceable->getBoolValue() ) {
576 // Com1 standby frequency
577 float com1_stby = com1_stby_freq->getFloatValue();
578 if ( fabs(com1_stby) > 999.99 ) {
581 snprintf(digits, 7, "%06.3f", com1_stby);
582 for ( i = 0; i < 6; ++i ) {
585 radio_display_data[6] = digits[4] << 4 | digits[5];
586 radio_display_data[7] = digits[1] << 4 | digits[2];
587 radio_display_data[8] = 0xf0 | digits[0];
589 // Com1 in use frequency
590 float com1 = com1_freq->getFloatValue();
591 if ( fabs(com1) > 999.99 ) {
594 snprintf(digits, 7, "%06.3f", com1);
595 for ( i = 0; i < 6; ++i ) {
598 radio_display_data[9] = digits[4] << 4 | digits[5];
599 radio_display_data[10] = digits[1] << 4 | digits[2];
600 radio_display_data[11] = 0x00 | digits[0];
601 // the 0x00 in the upper nibble of the 6th byte of each display
602 // turns on the decimal point
604 radio_display_data[6] = 0xff;
605 radio_display_data[7] = 0xff;
606 radio_display_data[8] = 0xff;
607 radio_display_data[9] = 0xff;
608 radio_display_data[10] = 0xff;
609 radio_display_data[11] = 0xff;
612 if ( navcom2_has_power() && comm2_serviceable->getBoolValue() ) {
613 // Com2 standby frequency
614 float com2_stby = com2_stby_freq->getFloatValue();
615 if ( fabs(com2_stby) > 999.99 ) {
618 snprintf(digits, 7, "%06.3f", com2_stby);
619 for ( i = 0; i < 6; ++i ) {
622 radio_display_data[18] = digits[4] << 4 | digits[5];
623 radio_display_data[19] = digits[1] << 4 | digits[2];
624 radio_display_data[20] = 0xf0 | digits[0];
626 // Com2 in use frequency
627 float com2 = com2_freq->getFloatValue();
628 if ( fabs(com2) > 999.99 ) {
631 snprintf(digits, 7, "%06.3f", com2);
632 for ( i = 0; i < 6; ++i ) {
635 radio_display_data[21] = digits[4] << 4 | digits[5];
636 radio_display_data[22] = digits[1] << 4 | digits[2];
637 radio_display_data[23] = 0x00 | digits[0];
638 // the 0x00 in the upper nibble of the 6th byte of each display
639 // turns on the decimal point
641 radio_display_data[18] = 0xff;
642 radio_display_data[19] = 0xff;
643 radio_display_data[20] = 0xff;
644 radio_display_data[21] = 0xff;
645 radio_display_data[22] = 0xff;
646 radio_display_data[23] = 0xff;
649 if ( navcom1_has_power() && nav1_serviceable->getBoolValue() ) {
650 // Nav1 standby frequency
651 float nav1_stby = nav1_stby_freq->getFloatValue();
652 if ( fabs(nav1_stby) > 999.99 ) {
655 snprintf(digits, 7, "%06.2f", nav1_stby);
656 for ( i = 0; i < 6; ++i ) {
659 radio_display_data[12] = digits[4] << 4 | digits[5];
660 radio_display_data[13] = digits[1] << 4 | digits[2];
661 radio_display_data[14] = 0xf0 | digits[0];
663 // Nav1 in use frequency
664 float nav1 = nav1_freq->getFloatValue();
665 if ( fabs(nav1) > 999.99 ) {
668 snprintf(digits, 7, "%06.2f", nav1);
669 for ( i = 0; i < 6; ++i ) {
672 radio_display_data[15] = digits[4] << 4 | digits[5];
673 radio_display_data[16] = digits[1] << 4 | digits[2];
674 radio_display_data[17] = 0x00 | digits[0];
675 // the 0x00 in the upper nibble of the 6th byte of each display
676 // turns on the decimal point
678 radio_display_data[12] = 0xff;
679 radio_display_data[13] = 0xff;
680 radio_display_data[14] = 0xff;
681 radio_display_data[15] = 0xff;
682 radio_display_data[16] = 0xff;
683 radio_display_data[17] = 0xff;
686 if ( navcom2_has_power() && nav2_serviceable->getBoolValue() ) {
687 // Nav2 standby frequency
688 float nav2_stby = nav2_stby_freq->getFloatValue();
689 if ( fabs(nav2_stby) > 999.99 ) {
692 snprintf(digits, 7, "%06.2f", nav2_stby);
693 for ( i = 0; i < 6; ++i ) {
696 radio_display_data[24] = digits[4] << 4 | digits[5];
697 radio_display_data[25] = digits[1] << 4 | digits[2];
698 radio_display_data[26] = 0xf0 | digits[0];
700 // Nav2 in use frequency
701 float nav2 = nav2_freq->getFloatValue();
702 if ( fabs(nav2) > 999.99 ) {
705 snprintf(digits, 7, "%06.2f", nav2);
706 for ( i = 0; i < 6; ++i ) {
709 radio_display_data[27] = digits[4] << 4 | digits[5];
710 radio_display_data[28] = digits[1] << 4 | digits[2];
711 radio_display_data[29] = 0x00 | digits[0];
712 // the 0x00 in the upper nibble of the 6th byte of each display
713 // turns on the decimal point
715 radio_display_data[24] = 0xff;
716 radio_display_data[25] = 0xff;
717 radio_display_data[26] = 0xff;
718 radio_display_data[27] = 0xff;
719 radio_display_data[28] = 0xff;
720 radio_display_data[29] = 0xff;
723 // ADF standby frequency / timer
724 if ( adf_has_power() && adf_serviceable->getBoolValue() ) {
725 if ( adf_stby_mode->getIntValue() == 0 ) {
727 float adf_stby = adf_stby_freq->getFloatValue();
728 if ( fabs(adf_stby) > 1799 ) {
731 snprintf(digits, 7, "%04.0f", adf_stby);
732 for ( i = 0; i < 6; ++i ) {
735 radio_display_data[30] = digits[3] << 4 | 0x0f;
736 radio_display_data[31] = digits[1] << 4 | digits[2];
737 if ( digits[0] == 0 ) {
738 radio_display_data[32] = 0xff;
740 radio_display_data[32] = 0xf0 | digits[0];
746 if ( adf_timer_mode->getIntValue() == 0 ) {
747 time = adf_flight_timer->getDoubleValue();
749 time = adf_elapsed_timer->getDoubleValue();
751 // cout << time << endl;
752 hours = (int)(time / 3600.0);
753 time -= hours * 3600.00;
754 min = (int)(time / 60.0);
771 // cout << big << ":" << little << endl;
772 snprintf(digits, 7, "%02d%02d", big, little);
773 for ( i = 0; i < 6; ++i ) {
776 radio_display_data[30] = digits[2] << 4 | digits[3];
777 radio_display_data[31] = digits[0] << 4 | digits[1];
778 radio_display_data[32] = 0xff;
781 // ADF in use frequency
782 float adf = adf_freq->getFloatValue();
783 if ( fabs(adf) > 1799 ) {
786 snprintf(digits, 7, "%04.0f", adf);
787 for ( i = 0; i < 6; ++i ) {
790 radio_display_data[33] = digits[2] << 4 | digits[3];
791 if ( digits[0] == 0 ) {
792 radio_display_data[34] = 0xf0 | digits[1];
794 radio_display_data[34] = digits[0] << 4 | digits[1];
796 if ( adf_stby_mode->getIntValue() == 0 ) {
797 radio_display_data[35] = 0xff;
799 radio_display_data[35] = 0x0f;
802 radio_display_data[30] = 0xff;
803 radio_display_data[31] = 0xff;
804 radio_display_data[32] = 0xff;
805 radio_display_data[33] = 0xff;
806 radio_display_data[34] = 0xff;
807 radio_display_data[35] = 0xff;
810 // Transponder code and flight level
811 if ( xpdr_has_power() && xpdr_serviceable->getBoolValue() ) {
812 if ( xpdr_func_knob->getIntValue() == 2 ) {
814 radio_display_data[36] = 8 << 4 | 8;
815 radio_display_data[37] = 8 << 4 | 8;
816 radio_display_data[38] = 0xff;
817 radio_display_data[39] = 8 << 4 | 0x0f;
818 radio_display_data[40] = 8 << 4 | 8;
821 int id_code = xpdr_id_code->getIntValue();
823 for ( i = 0; i < 4; ++i ) {
824 digits[i] = id_code / place;
825 id_code -= digits[i] * place;
828 radio_display_data[36] = digits[2] << 4 | digits[3];
829 radio_display_data[37] = digits[0] << 4 | digits[1];
830 radio_display_data[38] = 0xff;
832 if ( xpdr_func_knob->getIntValue() == 3 ||
833 xpdr_func_knob->getIntValue() == 5 )
835 // do flight level display
836 snprintf(digits, 7, "%03d", xpdr_flight_level->getIntValue() );
837 for ( i = 0; i < 6; ++i ) {
840 radio_display_data[39] = digits[2] << 4 | 0x0f;
841 radio_display_data[40] = digits[0] << 4 | digits[1];
843 // blank flight level display
844 radio_display_data[39] = 0xff;
845 radio_display_data[40] = 0xff;
850 radio_display_data[36] = 0xff;
851 radio_display_data[37] = 0xff;
852 radio_display_data[38] = 0xff;
853 radio_display_data[39] = 0xff;
854 radio_display_data[40] = 0xff;
857 ATCSetRadios( radio_display_fd, radio_display_data );
863 /////////////////////////////////////////////////////////////////////
864 // Drive the stepper motors
865 /////////////////////////////////////////////////////////////////////
867 bool FGATCOutput::do_steppers() {
868 SGPropertyNode *mag_compass
869 = fgGetNode( "/instrumentation/magnetic-compass/indicated-heading-deg",
872 float diff = mag_compass->getFloatValue() - compass_position;
873 while ( diff < -180.0 ) { diff += 360.0; }
874 while ( diff > 180.0 ) { diff -= 360.0; }
876 int steps = (int)(diff * 4);
877 // cout << "steps = " << steps << endl;
878 if ( steps > 4 ) { steps = 4; }
879 if ( steps < -4 ) { steps = -4; }
881 if ( abs(steps) > 0 ) {
882 unsigned char cmd = 0x80; // stepper command
884 cmd |= 0x20; // go up
886 cmd |= 0x00; // go down
890 // sync compass_position with hardware position
891 compass_position += (float)steps / 4.0;
893 ATCSetStepper( stepper_fd, ATC_COMPASS_CH, cmd );
900 // process the hardware outputs. This code assumes the calling layer
901 // will lock the hardware.
902 bool FGATCOutput::process() {
904 SG_LOG( SG_IO, SG_ALERT, "This board has not been opened for output! "
917 bool FGATCOutput::close() {
919 #if defined( unix ) || defined( __CYGWIN__ )
927 result = ::close( lamps_fd );
928 if ( result == -1 ) {
929 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
931 snprintf( msg, 256, "Error closing %s", lamps_file );
936 result = ::close( radio_display_fd );
937 if ( result == -1 ) {
938 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
940 snprintf( msg, 256, "Error closing %s", radio_display_file );
945 result = ::close( stepper_fd );
946 if ( result == -1 ) {
947 SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
949 snprintf( msg, 256, "Error closing %s", stepper_file );