27#include <simgear/compiler.h>
29#if defined( unix ) || defined( __CYGWIN__ )
30# include <sys/types.h>
46#include <simgear/debug/logstream.hxx>
47#include <simgear/misc/sg_path.hxx>
48#include <simgear/props/props_io.hxx>
60#if defined( unix ) || defined( __CYGWIN__ )
62 lseek( fd, 0, SEEK_SET );
65 int result = read( fd, tmp, 1 );
67 SG_LOG( SG_IO, SG_DEBUG,
"Lock failed" );
79#if defined( unix ) || defined( __CYGWIN__ )
81 lseek( fd, 0, SEEK_SET );
85 int result = write( fd, tmp, 1 );
88 SG_LOG( SG_IO, SG_DEBUG,
"Release failed" );
103 analog_out_node(NULL),
104 lamps_out_node(NULL),
105 radio_display_node(NULL),
109 config = _config_file;
117#if defined( unix ) || defined( __CYGWIN__ )
119 lseek( fd, 0, SEEK_SET );
124 SG_LOG( SG_IO, SG_DEBUG,
"Write failed" );
136#if defined( unix ) || defined( __CYGWIN__ )
138 lseek( fd, 0, SEEK_SET );
143 SG_LOG( SG_IO, SG_DEBUG,
"Write failed" );
155 unsigned char value )
157#if defined( unix ) || defined( __CYGWIN__ )
159 lseek( fd, 0, SEEK_SET );
162 unsigned char buf[3];
166 int result = write( fd, buf, 2 );
168 SG_LOG( SG_IO, SG_INFO,
"Write failed" );
170 SG_LOG( SG_IO, SG_DEBUG,
171 "Sent cmd = " << (
int)channel <<
" value = " << (
int)value );
179#ifdef ATCFLIGHTSIM_HAVE_COMPASS
181static unsigned char ATCReadStepper(
int fd ) {
182#if defined( unix ) || defined( __CYGWIN__ )
186 lseek( fd, 0, SEEK_SET );
189 unsigned char buf[2];
190 result = read( fd, buf, 1 );
192 SG_LOG( SG_IO, SG_ALERT,
"Read failed" );
195 SG_LOG( SG_IO, SG_DEBUG,
"Read result = " << (
int)buf[0] );
207#if defined( unix ) || defined( __CYGWIN__ )
217 unsigned char buf[3];
221 result = write( fd, buf, 2 );
223 SG_LOG( SG_IO, SG_ALERT,
"Write failed" );
230void FGATCOutput::init_config() {
231#if defined( unix ) || defined( __CYGWIN__ )
232 if (!config.isAbsolute()) {
233 SGPath tmp = SGPath::home();
234 tmp.append(
".atcflightsim" );
235 tmp.append( config.utf8Str() );
247 SG_LOG( SG_IO, SG_ALERT,
"This board is already open for output! "
255 SG_LOG( SG_IO, SG_ALERT,
256 "Initializing ATC output hardware, please wait ..." );
258 snprintf( analog_out_file, 256,
259 "/proc/atcflightsim/board%d/analog_out", board );
260 snprintf( lamps_file, 256,
261 "/proc/atcflightsim/board%d/lamps", board );
262 snprintf( radio_display_file, 256,
263 "/proc/atcflightsim/board%d/radios", board );
264 snprintf( stepper_file, 256,
265 "/proc/atcflightsim/board%d/steppers", board );
267#if defined( unix ) || defined( __CYGWIN__ )
273 analog_out_fd =
::open( analog_out_file, O_WRONLY );
274 if ( analog_out_fd == -1 ) {
275 SG_LOG( SG_IO, SG_ALERT,
"errno = " << errno );
277 snprintf( msg, 300,
"Error opening %s", analog_out_file );
282 lamps_fd =
::open( lamps_file, O_WRONLY );
283 if ( lamps_fd == -1 ) {
284 SG_LOG( SG_IO, SG_ALERT,
"errno = " << errno );
286 snprintf( msg, 300,
"Error opening %s", lamps_file );
291 radio_display_fd =
::open( radio_display_file, O_RDWR );
292 if ( radio_display_fd == -1 ) {
293 SG_LOG( SG_IO, SG_ALERT,
"errno = " << errno );
295 snprintf( msg, 300,
"Error opening %s", radio_display_file );
300 stepper_fd =
::open( stepper_file, O_RDWR );
301 if ( stepper_fd == -1 ) {
302 SG_LOG( SG_IO, SG_ALERT,
"errno = " << errno );
304 snprintf( msg, 300,
"Error opening %s", stepper_file );
311#ifdef ATCFLIGHTSIM_HAVE_COMPASS
316 SG_LOG( SG_IO, SG_ALERT,
317 " - Homing the compass stepper motor" );
320 while (
ATCLock( lock_fd ) <= 0 );
328 SG_LOG( SG_IO, SG_ALERT,
329 " - Waiting for compass to come home." );
334 while ( ! home && timeout > 0 ) {
335 if ( timeout % 150 == 0 ) {
336 SG_LOG( SG_IO, SG_INFO,
"waiting for compass = " << timeout );
338 SG_LOG( SG_IO, SG_DEBUG,
"Checking if compass home ..." );
341 while (
ATCLock( lock_fd ) <= 0 );
343 unsigned char result = ATCReadStepper( stepper_fd );
351 using namespace std::chrono_literals;
352 std::this_thread::sleep_for(std::chrono::milliseconds(33ms));
358 compass_position = 0.0;
362 while (
ATCLock( lock_fd ) <= 0 );
368 SG_LOG( SG_IO, SG_ALERT,
369 " - Zeroing Analog Outputs." );
372 analog_out_data[2*channel] = 0;
373 analog_out_data[2*channel + 1] = 0;
382 SG_LOG( SG_IO, SG_ALERT,
383 " - Clearing the radios displays." );
386 unsigned char value = 0xff;
388 radio_display_data[channel] = value;
398 for (
int i = 0;
i < 128; ++
i ) {
406 SG_LOG( SG_IO, SG_ALERT,
407 "Done initializing ATC output hardware." );
417 snprintf( base_name, 256,
"/output/atc-board[%d]/analog-outputs", board );
418 analog_out_node =
fgGetNode( base_name );
420 snprintf( base_name, 256,
"/output/atc-board[%d]/lamps", board );
423 snprintf( base_name, 256,
"/output/atc-board[%d]/radio-display", board );
424 radio_display_node =
fgGetNode( base_name );
426 snprintf( base_name, 256,
"/output/atc-board[%d]/steppers", board );
437bool FGATCOutput::do_analog_out() {
438 if ( analog_out_node != NULL ) {
439 for (
int i = 0;
i < analog_out_node->nChildren(); ++
i ) {
442 SGPropertyNode *child = analog_out_node->getChild(
i);
443 string cname = child->getNameString();
444 int index = child->getIndex();
447 SGPropertyNode *src_prop = NULL;
448 double x0 = 0.0, y0 = 0.0, x1 = 0.0, y1 = 0.0;
449 if ( cname ==
"analog-out" ) {
450 SGPropertyNode *prop;
451 prop = child->getChild(
"name" );
452 if ( prop != NULL ) {
453 name = prop->getStringValue();
455 prop = child->getChild(
"type" );
456 if ( prop != NULL ) {
457 type = prop->getStringValue();
459 prop = child->getChild(
"prop" );
460 if ( prop != NULL ) {
461 src_prop =
fgGetNode( prop->getStringValue(),
true );
463 prop = child->getChild(
"value-lo" );
464 if ( prop != NULL ) {
465 x0 = prop->getDoubleValue();
467 prop = child->getChild(
"meter-lo" );
468 if ( prop != NULL ) {
469 y0 = prop->getDoubleValue();
471 prop = child->getChild(
"value-hi" );
472 if ( prop != NULL ) {
473 x1 = prop->getDoubleValue();
475 prop = child->getChild(
"meter-hi" );
476 if ( prop != NULL ) {
477 y1 = prop->getDoubleValue();
482 double slope = dy / dx;
483 double value = src_prop->getDoubleValue();
484 int meter = (value - x0) * slope + y0;
485 if ( meter < 0 ) { meter = 0; }
486 if ( meter > 1023 ) { meter = 1023; }
487 analog_out_data[2*index] = meter / 256;
488 analog_out_data[2*index + 1] = meter - analog_out_data[2*index] * 256;
490 SG_LOG( SG_IO, SG_DEBUG,
491 "Input config error, expecting 'analog-out' but found "
506bool FGATCOutput::do_lamps() {
507 if ( lamps_out_node != NULL ) {
508 for (
int i = 0;
i < lamps_out_node->nChildren(); ++
i ) {
511 SGPropertyNode *child = lamps_out_node->getChild(
i);
512 string cname = child->getNameString();
513 int index = child->getIndex();
516 SGPropertyNode *src_prop = NULL;
517 if ( cname ==
"lamp" ) {
518 SGPropertyNode *prop;
519 prop = child->getChild(
"name" );
520 if ( prop != NULL ) {
521 name = prop->getStringValue();
523 prop = child->getChild(
"type" );
524 if ( prop != NULL ) {
525 type = prop->getStringValue();
527 prop = child->getChild(
"prop" );
528 if ( prop != NULL ) {
529 src_prop =
fgGetNode( prop->getStringValue(),
true );
531 ATCSetLamp( lamps_fd, index, src_prop->getBoolValue() );
533 SG_LOG( SG_IO, SG_DEBUG,
534 "Input config error, expecting 'lamp' but found "
550 static SGPropertyNode *navcom1_bus_power
551 =
fgGetNode(
"/systems/electrical/outputs/nav[0]",
true );
552 static SGPropertyNode *navcom1_power_btn
553 =
fgGetNode(
"/instrumentation/nav[0]/power-btn",
true );
555 return (navcom1_bus_power->getDoubleValue() > 1.0)
556 && navcom1_power_btn->getBoolValue();
560 static SGPropertyNode *navcom2_bus_power
561 =
fgGetNode(
"/systems/electrical/outputs/nav[1]",
true );
562 static SGPropertyNode *navcom2_power_btn
563 =
fgGetNode(
"/instrumentation/nav[1]/power-btn",
true );
565 return (navcom2_bus_power->getDoubleValue() > 1.0)
566 && navcom2_power_btn->getBoolValue();
570 static SGPropertyNode *dme_bus_power
571 =
fgGetNode(
"/systems/electrical/outputs/dme",
true );
573 return (dme_bus_power->getDoubleValue() > 1.0);
577 static SGPropertyNode *adf_bus_power
578 =
fgGetNode(
"/systems/electrical/outputs/adf",
true );
579 static SGPropertyNode *adf_power_btn
580 =
fgGetNode(
"/instrumentation/kr-87/inputs/power-btn",
true );
582 return (adf_bus_power->getDoubleValue() > 1.0)
583 && adf_power_btn->getBoolValue();
587 static SGPropertyNode *xpdr_bus_power
588 =
fgGetNode(
"/systems/electrical/outputs/transponder",
true );
589 static SGPropertyNode *xpdr_func_knob
590 =
fgGetNode(
"/instrumentation/transponder/inputs/func-knob",
true );
592 return (xpdr_bus_power->getDoubleValue() > 1.0)
593 && (xpdr_func_knob->getIntValue() > 0);
596bool FGATCOutput::do_radio_display() {
597 static SGPropertyNode *dme_serviceable
598 =
fgGetNode(
"/instrumentation/dme/serviceable",
true );
599 static SGPropertyNode *dme_in_range
600 =
fgGetNode(
"/instrumentation/dme/in-range",
true );
601 static SGPropertyNode *dme_min
602 =
fgGetNode(
"/instrumentation/dme/indicated-time-min",
true );
603 static SGPropertyNode *dme_kt
604 =
fgGetNode(
"/instrumentation/dme/indicated-ground-speed-kt",
true );
605 static SGPropertyNode *dme_nm
606 =
fgGetNode(
"/instrumentation/dme/indicated-distance-nm",
true );
608 static SGPropertyNode *comm1_serviceable
609 =
fgGetNode(
"/instrumentation/comm[0]/serviceable",
true );
610 static SGPropertyNode *com1_freq
611 =
fgGetNode(
"/instrumentation/comm[0]/frequencies/selected-mhz",
true);
612 static SGPropertyNode *com1_stby_freq
613 =
fgGetNode(
"/instrumentation/comm[0]/frequencies/standby-mhz",
true );
615 static SGPropertyNode *comm2_serviceable
616 =
fgGetNode(
"/instrumentation/comm[1]/serviceable",
true );
617 static SGPropertyNode *com2_freq
618 =
fgGetNode(
"/instrumentation/comm[1]/frequencies/selected-mhz",
true);
619 static SGPropertyNode *com2_stby_freq
620 =
fgGetNode(
"/instrumentation/comm[1]/frequencies/standby-mhz",
true );
622 static SGPropertyNode *nav1_serviceable
623 =
fgGetNode(
"/instrumentation/nav[0]/serviceable",
true );
624 static SGPropertyNode *nav1_freq
625 =
fgGetNode(
"/instrumentation/nav[0]/frequencies/selected-mhz",
true );
626 static SGPropertyNode *nav1_stby_freq
627 =
fgGetNode(
"/instrumentation/nav[0]/frequencies/standby-mhz",
true );
629 static SGPropertyNode *nav2_serviceable
630 =
fgGetNode(
"/instrumentation/nav[1]/serviceable",
true );
631 static SGPropertyNode *nav2_freq
632 =
fgGetNode(
"/instrumentation/nav[1]/frequencies/selected-mhz",
true );
633 static SGPropertyNode *nav2_stby_freq
634 =
fgGetNode(
"/instrumentation/nav[1]/frequencies/standby-mhz",
true );
636 static SGPropertyNode *adf_serviceable
637 =
fgGetNode(
"/instrumentation/adf/serviceable",
true );
638 static SGPropertyNode *adf_freq
639 =
fgGetNode(
"/instrumentation/kr-87/outputs/selected-khz",
true );
640 static SGPropertyNode *adf_stby_freq
641 =
fgGetNode(
"/instrumentation/kr-87/outputs/standby-khz",
true );
642 static SGPropertyNode *adf_stby_mode
643 =
fgGetNode(
"/instrumentation/kr-87/modes/stby",
true );
644 static SGPropertyNode *adf_timer_mode
645 =
fgGetNode(
"/instrumentation/kr-87/modes/timer",
true );
648 static SGPropertyNode *adf_flight_timer
649 =
fgGetNode(
"/instrumentation/kr-87/outputs/flight-timer",
true );
650 static SGPropertyNode *adf_elapsed_timer
651 =
fgGetNode(
"/instrumentation/kr-87/outputs/elapsed-timer",
true );
653 static SGPropertyNode *xpdr_serviceable
654 =
fgGetNode(
"/instrumentation/transponder/inputs/serviceable",
true );
655 static SGPropertyNode *xpdr_func_knob
656 =
fgGetNode(
"/instrumentation/transponder/inputs/func-knob",
true );
657 static SGPropertyNode *xpdr_flight_level
658 =
fgGetNode(
"/instrumentation/transponder/outputs/flight-level",
true );
659 static SGPropertyNode *xpdr_id_code
660 =
fgGetNode(
"/instrumentation/transponder/outputs/id-code",
true );
666 if ( dme_in_range->getBoolValue() ) {
668 float minutes = dme_min->getFloatValue();
669 if ( minutes > 999 ) {
672 snprintf(digits, 7,
"%03.0f", minutes);
673 for (
i = 0;
i < 6; ++
i ) {
676 radio_display_data[0] = digits[1] << 4 | digits[2];
677 radio_display_data[1] = 0xf0 | digits[0];
680 float knots = dme_kt->getFloatValue();
684 snprintf(digits, 7,
"%03.0f", knots);
685 for (
i = 0;
i < 6; ++
i ) {
688 radio_display_data[2] = digits[1] << 4 | digits[2];
689 radio_display_data[3] = 0xf0 | digits[0];
692 float nm = dme_nm->getFloatValue();
696 snprintf(digits, 7,
"%04.1f", nm);
697 for (
i = 0;
i < 6; ++
i ) {
700 radio_display_data[4] = digits[1] << 4 | digits[3];
701 radio_display_data[5] = 0x00 | digits[0];
706 radio_display_data[0] = 0xbb;
707 radio_display_data[1] = 0xfb;
708 radio_display_data[2] = 0xbb;
709 radio_display_data[3] = 0xfb;
710 radio_display_data[4] = 0xbb;
711 radio_display_data[5] = 0x0b;
715 for (
i = 0;
i < 6; ++
i ) {
716 radio_display_data[
i] = 0xff;
722 float com1_stby = com1_stby_freq->getFloatValue();
723 if ( fabs(com1_stby) > 999.99 ) {
726 snprintf(digits, 7,
"%06.3f", com1_stby);
727 for (
i = 0;
i < 6; ++
i ) {
730 radio_display_data[6] = digits[4] << 4 | digits[5];
731 radio_display_data[7] = digits[1] << 4 | digits[2];
732 radio_display_data[8] = 0xf0 | digits[0];
735 float com1 = com1_freq->getFloatValue();
736 if ( fabs(com1) > 999.99 ) {
739 snprintf(digits, 7,
"%06.3f", com1);
740 for (
i = 0;
i < 6; ++
i ) {
743 radio_display_data[9] = digits[4] << 4 | digits[5];
744 radio_display_data[10] = digits[1] << 4 | digits[2];
745 radio_display_data[11] = 0x00 | digits[0];
749 radio_display_data[6] = 0xff;
750 radio_display_data[7] = 0xff;
751 radio_display_data[8] = 0xff;
752 radio_display_data[9] = 0xff;
753 radio_display_data[10] = 0xff;
754 radio_display_data[11] = 0xff;
759 float com2_stby = com2_stby_freq->getFloatValue();
760 if ( fabs(com2_stby) > 999.99 ) {
763 snprintf(digits, 7,
"%06.3f", com2_stby);
764 for (
i = 0;
i < 6; ++
i ) {
767 radio_display_data[18] = digits[4] << 4 | digits[5];
768 radio_display_data[19] = digits[1] << 4 | digits[2];
769 radio_display_data[20] = 0xf0 | digits[0];
772 float com2 = com2_freq->getFloatValue();
773 if ( fabs(com2) > 999.99 ) {
776 snprintf(digits, 7,
"%06.3f", com2);
777 for (
i = 0;
i < 6; ++
i ) {
780 radio_display_data[21] = digits[4] << 4 | digits[5];
781 radio_display_data[22] = digits[1] << 4 | digits[2];
782 radio_display_data[23] = 0x00 | digits[0];
786 radio_display_data[18] = 0xff;
787 radio_display_data[19] = 0xff;
788 radio_display_data[20] = 0xff;
789 radio_display_data[21] = 0xff;
790 radio_display_data[22] = 0xff;
791 radio_display_data[23] = 0xff;
796 float nav1_stby = nav1_stby_freq->getFloatValue();
797 if ( fabs(nav1_stby) > 999.99 ) {
800 snprintf(digits, 7,
"%06.2f", nav1_stby);
801 for (
i = 0;
i < 6; ++
i ) {
804 radio_display_data[12] = digits[4] << 4 | digits[5];
805 radio_display_data[13] = digits[1] << 4 | digits[2];
806 radio_display_data[14] = 0xf0 | digits[0];
809 float nav1 = nav1_freq->getFloatValue();
810 if ( fabs(nav1) > 999.99 ) {
813 snprintf(digits, 7,
"%06.2f", nav1);
814 for (
i = 0;
i < 6; ++
i ) {
817 radio_display_data[15] = digits[4] << 4 | digits[5];
818 radio_display_data[16] = digits[1] << 4 | digits[2];
819 radio_display_data[17] = 0x00 | digits[0];
823 radio_display_data[12] = 0xff;
824 radio_display_data[13] = 0xff;
825 radio_display_data[14] = 0xff;
826 radio_display_data[15] = 0xff;
827 radio_display_data[16] = 0xff;
828 radio_display_data[17] = 0xff;
833 float nav2_stby = nav2_stby_freq->getFloatValue();
834 if ( fabs(nav2_stby) > 999.99 ) {
837 snprintf(digits, 7,
"%06.2f", nav2_stby);
838 for (
i = 0;
i < 6; ++
i ) {
841 radio_display_data[24] = digits[4] << 4 | digits[5];
842 radio_display_data[25] = digits[1] << 4 | digits[2];
843 radio_display_data[26] = 0xf0 | digits[0];
846 float nav2 = nav2_freq->getFloatValue();
847 if ( fabs(nav2) > 999.99 ) {
850 snprintf(digits, 7,
"%06.2f", nav2);
851 for (
i = 0;
i < 6; ++
i ) {
854 radio_display_data[27] = digits[4] << 4 | digits[5];
855 radio_display_data[28] = digits[1] << 4 | digits[2];
856 radio_display_data[29] = 0x00 | digits[0];
860 radio_display_data[24] = 0xff;
861 radio_display_data[25] = 0xff;
862 radio_display_data[26] = 0xff;
863 radio_display_data[27] = 0xff;
864 radio_display_data[28] = 0xff;
865 radio_display_data[29] = 0xff;
870 if ( adf_stby_mode->getIntValue() == 0 ) {
872 float adf_stby = adf_stby_freq->getFloatValue();
873 if ( fabs(adf_stby) > 1799 ) {
876 snprintf(digits, 7,
"%04.0f", adf_stby);
877 for (
i = 0;
i < 6; ++
i ) {
880 radio_display_data[30] = digits[3] << 4 | 0x0f;
881 radio_display_data[31] = digits[1] << 4 | digits[2];
882 if ( digits[0] == 0 ) {
883 radio_display_data[32] = 0xff;
885 radio_display_data[32] = 0xf0 | digits[0];
890 unsigned hours,
min, sec;
891 if ( adf_timer_mode->getIntValue() == 0 ) {
892 time = adf_flight_timer->getDoubleValue();
894 time = adf_elapsed_timer->getDoubleValue();
897 hours = (int)(time / 3600.0);
898 time -= hours * 3600.00;
899 min = (int)(time / 60.0);
902 unsigned big, little;
917 snprintf(digits, 7,
"%02d%02d", big, little);
918 for (
i = 0;
i < 6; ++
i ) {
921 radio_display_data[30] = digits[2] << 4 | digits[3];
922 radio_display_data[31] = digits[0] << 4 | digits[1];
923 radio_display_data[32] = 0xff;
927 float adf = adf_freq->getFloatValue();
928 if ( fabs(adf) > 1799 ) {
931 snprintf(digits, 7,
"%04.0f", adf);
932 for (
i = 0;
i < 6; ++
i ) {
935 radio_display_data[33] = digits[2] << 4 | digits[3];
936 if ( digits[0] == 0 ) {
937 radio_display_data[34] = 0xf0 | digits[1];
939 radio_display_data[34] = digits[0] << 4 | digits[1];
941 if ( adf_stby_mode->getIntValue() == 0 ) {
942 radio_display_data[35] = 0xff;
944 radio_display_data[35] = 0x0f;
947 radio_display_data[30] = 0xff;
948 radio_display_data[31] = 0xff;
949 radio_display_data[32] = 0xff;
950 radio_display_data[33] = 0xff;
951 radio_display_data[34] = 0xff;
952 radio_display_data[35] = 0xff;
957 if ( xpdr_func_knob->getIntValue() == 2 ) {
959 radio_display_data[36] = 8 << 4 | 8;
960 radio_display_data[37] = 8 << 4 | 8;
961 radio_display_data[38] = 0xff;
962 radio_display_data[39] = 8 << 4 | 0x0f;
963 radio_display_data[40] = 8 << 4 | 8;
966 int id_code = xpdr_id_code->getIntValue();
968 for (
i = 0;
i < 4; ++
i ) {
969 digits[
i] = id_code / place;
970 id_code -= digits[
i] * place;
973 radio_display_data[36] = digits[2] << 4 | digits[3];
974 radio_display_data[37] = digits[0] << 4 | digits[1];
975 radio_display_data[38] = 0xff;
977 if ( xpdr_func_knob->getIntValue() == 3 ||
978 xpdr_func_knob->getIntValue() == 5 )
981 snprintf(digits, 7,
"%03d", xpdr_flight_level->getIntValue() );
982 for (
i = 0;
i < 6; ++
i ) {
985 radio_display_data[39] = digits[2] << 4 | 0x0f;
986 radio_display_data[40] = digits[0] << 4 | digits[1];
989 radio_display_data[39] = 0xff;
990 radio_display_data[40] = 0xff;
995 radio_display_data[36] = 0xff;
996 radio_display_data[37] = 0xff;
997 radio_display_data[38] = 0xff;
998 radio_display_data[39] = 0xff;
999 radio_display_data[40] = 0xff;
1012bool FGATCOutput::do_steppers() {
1013 SGPropertyNode *mag_compass
1014 =
fgGetNode(
"/instrumentation/magnetic-compass/indicated-heading-deg",
1017 float diff = mag_compass->getFloatValue() - compass_position;
1018 while ( diff < -180.0 ) { diff += 360.0; }
1019 while ( diff > 180.0 ) { diff -= 360.0; }
1021 int steps = (int)(diff * 4);
1023 if ( steps > 4 ) { steps = 4; }
1024 if ( steps < -4 ) { steps = -4; }
1026 if (
abs(steps) > 0 ) {
1027 unsigned char cmd = 0x80;
1036 compass_position += (float)steps / 4.0;
1049 SG_LOG( SG_IO, SG_ALERT,
"This board has not been opened for output! "
1057#ifdef ATCFLIGHTSIM_HAVE_COMPASS
1067#if defined( unix ) || defined( __CYGWIN__ )
1076 if ( result == -1 ) {
1077 SG_LOG( SG_IO, SG_ALERT,
"errno = " << errno );
1079 snprintf( msg, 300,
"Error closing %s", lamps_file );
1084 result =
::close( radio_display_fd );
1085 if ( result == -1 ) {
1086 SG_LOG( SG_IO, SG_ALERT,
"errno = " << errno );
1088 snprintf( msg, 300,
"Error closing %s", radio_display_file );
1093 result =
::close( stepper_fd );
1094 if ( result == -1 ) {
1095 SG_LOG( SG_IO, SG_ALERT,
"errno = " << errno );
1097 snprintf( msg, 300,
"Error closing %s", stepper_file );
static int ATCRelease(int fd)
static int ATCSetAnalogOut(int fd, unsigned char data[48 *2])
static bool navcom2_has_power()
static bool xpdr_has_power()
static bool navcom1_has_power()
static int ATCLock(int fd)
static bool adf_has_power()
void ATCSetLamp(int fd, int channel, bool value)
static int ATCSetRadios(int fd, unsigned char data[48])
static int ATCSetStepper(int fd, unsigned char channel, unsigned char value)
static bool dme_has_power()
#define ATC_RADIO_DISPLAY_BYTES
#define ATC_ANALOG_OUT_CHANNELS
FGATCOutput(const int _board, const SGPath &_config_file)
SGPropertyNode * get_props()
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.