From 5f37f2eaa5241e6b68f5b9449050ce7329bdc25d Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 4 Jul 2002 21:37:34 +0000 Subject: [PATCH] Initial revision of a Bendix/King KT 70 transponder. --- src/Cockpit/Makefile.am | 1 + src/Cockpit/kt_70.cxx | 212 +++++++++++++++++++++++++++++++++++++ src/Cockpit/kt_70.hxx | 117 ++++++++++++++++++++ src/Cockpit/radiostack.cxx | 8 ++ src/Cockpit/radiostack.hxx | 2 + src/Cockpit/steam.cxx | 66 ------------ 6 files changed, 340 insertions(+), 66 deletions(-) create mode 100644 src/Cockpit/kt_70.cxx create mode 100644 src/Cockpit/kt_70.hxx diff --git a/src/Cockpit/Makefile.am b/src/Cockpit/Makefile.am index f1deeb23c..707ab999b 100644 --- a/src/Cockpit/Makefile.am +++ b/src/Cockpit/Makefile.am @@ -8,6 +8,7 @@ libCockpit_a_SOURCES = \ hud_lat.cxx hud_lon.cxx \ hud_scal.cxx hud_tbi.cxx \ kr_87.cxx kr_87.hxx \ + kt_70.cxx kt_70.hxx \ panel.cxx panel.hxx \ panel_io.cxx panel_io.hxx \ radiostack.cxx radiostack.hxx \ diff --git a/src/Cockpit/kt_70.cxx b/src/Cockpit/kt_70.cxx new file mode 100644 index 000000000..00ff0c5be --- /dev/null +++ b/src/Cockpit/kt_70.cxx @@ -0,0 +1,212 @@ +// kt-70.cxx -- class to impliment the King KT 70 panel-m transponder +// +// Written by Curtis Olson, started July 2002. +// +// Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include // snprintf + +#include +#include + +#include + +#include "kt_70.hxx" + + +// Constructor +FGKT_70::FGKT_70() : + lon_node(fgGetNode("/position/longitude-deg", true)), + lat_node(fgGetNode("/position/latitude-deg", true)), + alt_node(fgGetNode("/position/altitude-ft", true)), + r_flash_time(0.0), + ident_mode(false), + ident_btn(false), + last_ident_btn(false), + digit1(1), digit2(2), digit3(0), digit4(0), + func_knob(4), + id_code(1200), + flight_level(0), + fl_ann(0), + alt_ann(0), + gnd_ann(0), + on_ann(0), + sby_ann(0), + reply_ann(0) +{ +} + + +// Destructor +FGKT_70::~FGKT_70() { } + + +void FGKT_70::init () { + update(0); // FIXME: use dt +} + + +void FGKT_70::bind () { + // internal values + + // modes + + // input and buttons + fgTie("/radios/kt-70/inputs/ident-btn", this, + &FGKT_70::get_ident_btn, &FGKT_70::set_ident_btn); + fgSetArchivable("/radios/kt-70/inputs/rotation-deg"); + fgTie("/radios/kt-70/inputs/digit1", this, + &FGKT_70::get_digit1, &FGKT_70::set_digit1); + fgSetArchivable("/radios/kt-70/inputs/digit1"); + fgTie("/radios/kt-70/inputs/digit2", this, + &FGKT_70::get_digit2, &FGKT_70::set_digit2); + fgSetArchivable("/radios/kt-70/inputs/digit2"); + fgTie("/radios/kt-70/inputs/digit3", this, + &FGKT_70::get_digit3, &FGKT_70::set_digit3); + fgSetArchivable("/radios/kt-70/inputs/digit3"); + fgTie("/radios/kt-70/inputs/digit4", this, + &FGKT_70::get_digit4, &FGKT_70::set_digit4); + fgSetArchivable("/radios/kt-70/inputs/digit4"); + fgTie("/radios/kt-70/inputs/func-knob", this, + &FGKT_70::get_func_knob, &FGKT_70::set_func_knob); + fgSetArchivable("/radios/kt-70/inputs/func-knob"); + + // outputs + fgTie("/radios/kt-70/outputs/id-code", this, + &FGKT_70::get_id_code, &FGKT_70::set_id_code); + fgSetArchivable("/radios/kt-70/outputs/id-code"); + fgTie("/radios/kt-70/outputs/flight-level", this, + &FGKT_70::get_flight_level); + + // annunciators + fgTie("/radios/kt-70/annunciators/fl", this, &FGKT_70::get_fl_ann ); + fgTie("/radios/kt-70/annunciators/alt", this, &FGKT_70::get_alt_ann ); + fgTie("/radios/kt-70/annunciators/gnd", this, &FGKT_70::get_gnd_ann ); + fgTie("/radios/kt-70/annunciators/on", this, &FGKT_70::get_on_ann ); + fgTie("/radios/kt-70/annunciators/sby", this, &FGKT_70::get_sby_ann ); + fgTie("/radios/kt-70/annunciators/reply", this, &FGKT_70::get_reply_ann ); +} + + +void FGKT_70::unbind () { + // internal values + + // modes + + // input and buttons + fgUntie("/radios/kt-70/inputs/ident-btn"); + fgUntie("/radios/kt-70/inputs/digit1"); + fgUntie("/radios/kt-70/inputs/digit2"); + fgUntie("/radios/kt-70/inputs/digit3"); + fgUntie("/radios/kt-70/inputs/digit4"); + fgUntie("/radios/kt-70/inputs/func-knob"); + + // outputs + fgUntie("/radios/kt-70/outputs/id-code"); + fgUntie("/radios/kt-70/outputs/flight-level"); + + // annunciators + fgUntie("/radios/kt-70/annunciators/fl"); + fgUntie("/radios/kt-70/annunciators/alt"); + fgUntie("/radios/kt-70/annunciators/gnd"); + fgUntie("/radios/kt-70/annunciators/on"); + fgUntie("/radios/kt-70/annunciators/sby"); + fgUntie("/radios/kt-70/annunciators/reply"); +} + + +// Update the various nav values based on position and valid tuned in navs +void FGKT_70::update( double dt ) { + double acft_lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; + double acft_lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; + double acft_elev = alt_node->getDoubleValue() * SG_FEET_TO_METER; + + Point3D aircraft = sgGeodToCart( Point3D( acft_lon, acft_lat, acft_elev ) ); + + // sanity checks + if ( digit1 < 0 ) { digit1 = 0; } + if ( digit1 > 7 ) { digit1 = 7; } + if ( digit2 < 0 ) { digit2 = 0; } + if ( digit2 > 7 ) { digit2 = 7; } + if ( digit3 < 0 ) { digit3 = 0; } + if ( digit3 > 7 ) { digit3 = 7; } + if ( digit4 < 0 ) { digit4 = 0; } + if ( digit4 > 7 ) { digit4 = 7; } + + id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4; + + // flight level computation + + // FIXME!!!! This needs to be computed relative to 29.92 inHg, but + // for the moment, until I figure out how to do that, I'll just + // use true altitude. + flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0); + + // ident button + if ( ident_btn && !last_ident_btn ) { + // ident button depressed + r_flash_time = 0.0; + ident_mode = true; + } + r_flash_time += dt; + if ( r_flash_time > 18.0 ) { + ident_mode = false; + } + + // start with all annunciators off (reply ann is handled + // separately) and then turn on the ones we want + fl_ann = false; + alt_ann = false; + gnd_ann = false; + on_ann = false; + sby_ann = false; + + if ( ident_mode ) { + reply_ann = true; + } else { + reply_ann = false; + } + + if ( func_knob == 0 ) { + // leave everything off + } else if ( func_knob == 1 ) { + sby_ann = true; + } else if ( func_knob == 2 ) { + fl_ann = true; + alt_ann = true; + gnd_ann = true; + on_ann = true; + sby_ann = true; + reply_ann = true; + } else if ( func_knob == 3 ) { + fl_ann = true; + gnd_ann = true; + } else if ( func_knob == 4 ) { + on_ann = true; + } else if ( func_knob == 5 ) { + fl_ann = true; + alt_ann = true; + } + +} diff --git a/src/Cockpit/kt_70.hxx b/src/Cockpit/kt_70.hxx new file mode 100644 index 000000000..2dca70308 --- /dev/null +++ b/src/Cockpit/kt_70.hxx @@ -0,0 +1,117 @@ +// kt-70.hxx -- class to impliment the King KT 70 panel-m transponder +// +// Written by Curtis Olson, started July 2002. +// +// Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifndef _FG_KT_70_HXX +#define _FG_KT_70_HXX + + +#include
+#include
+ +#include + +#include +#include + +#include +#include +#include + + +class FGKT_70 : public FGSubsystem +{ + SGPropertyNode *lon_node; + SGPropertyNode *lat_node; + SGPropertyNode *alt_node; + + // internal values + double r_flash_time; + + // modes + bool ident_mode; // false = normal, true = ident/squawk + + // input and buttons + bool ident_btn; + bool last_ident_btn; + int digit1, digit2, digit3, digit4; + int func_knob; // 0 = OFF, 1 = SBY, 2 = TST, 3 = GND, 4 = ON, + // 5 = ALT + + // outputs + int id_code; + int flight_level; + + // annunciators + bool fl_ann; // flight level + bool alt_ann; // altitude + bool gnd_ann; // ground + bool on_ann; // on + bool sby_ann; // standby + bool reply_ann; // reply + +public: + + FGKT_70(); + ~FGKT_70(); + + void init (); + void bind (); + void unbind (); + void update (double dt); + void search () { /* empty placeholder */ } + + // internal values + + // modes + // inline int get_stby_mode() const { return stby_mode; } + + // input and buttons + inline bool get_ident_btn() const { return ident_btn; } + inline void set_ident_btn( bool val ) { ident_btn = val; } + inline int get_digit1() const { return digit1; } + inline void set_digit1( int val ) { digit1 = val; } + inline int get_digit2() const { return digit2; } + inline void set_digit2( int val ) { digit2 = val; } + inline int get_digit3() const { return digit3; } + inline void set_digit3( int val ) { digit3 = val; } + inline int get_digit4() const { return digit4; } + inline void set_digit4( int val ) { digit4 = val; } + inline int get_func_knob() const { return func_knob; } + inline void set_func_knob( int val ) { func_knob = val; } + + // outputs + inline int get_id_code () const { return id_code; } + inline void set_id_code( int c ) { id_code = c; } + inline int get_flight_level () const { return flight_level; } + + // annunciators + inline bool get_fl_ann() const { return fl_ann; } + inline bool get_alt_ann() const { return alt_ann; } + inline bool get_gnd_ann() const { return gnd_ann; } + inline bool get_on_ann() const { return on_ann; } + inline bool get_sby_ann() const { return sby_ann; } + inline bool get_reply_ann() const { return reply_ann; } +}; + + +#endif // _FG_KT_70_HXX diff --git a/src/Cockpit/radiostack.cxx b/src/Cockpit/radiostack.cxx index fd9dd25ff..54f235b47 100644 --- a/src/Cockpit/radiostack.cxx +++ b/src/Cockpit/radiostack.cxx @@ -123,6 +123,7 @@ FGRadioStack::FGRadioStack() : FGRadioStack::~FGRadioStack() { adf.unbind(); + xponder.unbind(); unbind(); // FIXME: should be called externally delete term_tbl; @@ -135,6 +136,7 @@ void FGRadioStack::init () { adf.init(); + xponder.init(); morse.init(); beacon.init(); @@ -142,9 +144,11 @@ FGRadioStack::init () search(); adf.search(); + xponder.search(); update(0); // FIXME: use dt adf.update(0); + xponder.update(0); // Search radio database once per second global_events.Register( "fgRadioSearch()", @@ -265,6 +269,7 @@ FGRadioStack::bind () &FGRadioStack::get_outer_blink); adf.bind(); + xponder.bind(); } void @@ -317,6 +322,7 @@ FGRadioStack::unbind () fgUntie("/radios/marker-beacon/outer"); adf.unbind(); + xponder.unbind(); } @@ -685,6 +691,7 @@ FGRadioStack::update(double dt) // cout << outer_blink << " " << middle_blink << " " << inner_blink << endl; adf.update( dt ); + xponder.update( dt ); } @@ -1085,6 +1092,7 @@ void FGRadioStack::search() last_beacon = beacon_type; adf.search(); + xponder.search(); } diff --git a/src/Cockpit/radiostack.hxx b/src/Cockpit/radiostack.hxx index ebad51f1a..eb4c32e0a 100644 --- a/src/Cockpit/radiostack.hxx +++ b/src/Cockpit/radiostack.hxx @@ -39,6 +39,7 @@ #include #include "kr_87.hxx" // ADF +#include "kt_70.hxx" // Transponder class FGRadioStack : public FGSubsystem { @@ -178,6 +179,7 @@ class FGRadioStack : public FGSubsystem bool inner_blink; FGKR_87 adf; // King KR 87 Digital ADF model + FGKT_70 xponder; // Bendix/King KT 70 Panel-Mounted Transponder // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8 double adjustNavRange( double stationElev, double aircraftElev, diff --git a/src/Cockpit/steam.cxx b/src/Cockpit/steam.cxx index e2049a2d1..e3ab19b95 100644 --- a/src/Cockpit/steam.cxx +++ b/src/Cockpit/steam.cxx @@ -392,76 +392,10 @@ void FGSteam::_CatchUp() // Everything below is a transient hack; expect it to disappear //////////////////////////////////////////////////////////////////////// - -#if 0 - -double FGSteam::get_HackGS_deg () { - if ( current_radiostack->get_nav1_inrange() && - current_radiostack->get_nav1_has_gs() ) - { - double x = current_radiostack->get_nav1_gs_dist(); - double y = (fgGetDouble("/position/altitude-ft") - - current_radiostack->get_nav1_elev()) - * SG_FEET_TO_METER; - double angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES; - return (current_radiostack->get_nav1_target_gs() - angle) * 5.0; - } else { - return 0.0; - } -} - - -double FGSteam::get_HackVOR1_deg () { - double r; - - if ( current_radiostack->get_nav1_inrange() ) { - r = current_radiostack->get_nav1_heading() - - current_radiostack->get_nav1_radial(); - // cout << "Radial = " << current_radiostack->get_nav1_radial() - // << " Bearing = " << current_radiostack->get_nav1_heading() - // << endl; - - if (r> 180.0) r-=360.0; else - if (r<-180.0) r+=360.0; - if ( fabs(r) > 90.0 ) - r = ( r<0.0 ? -r-180.0 : -r+180.0 ); - // According to Robin Peel, the ILS is 4x more sensitive than a vor - if ( current_radiostack->get_nav1_loc() ) r *= 4.0; - } else { - r = 0.0; - } - - return r; -} - - -double FGSteam::get_HackVOR2_deg () { - double r; - - if ( current_radiostack->get_nav2_inrange() ) { - r = current_radiostack->get_nav2_heading() - - current_radiostack->get_nav2_radial(); - // cout << "Radial = " << current_radiostack->get_nav1_radial() - // << " Bearing = " << current_radiostack->get_nav1_heading() << endl; - - if (r> 180.0) r-=360.0; else - if (r<-180.0) r+=360.0; - if ( fabs(r) > 90.0 ) - r = ( r<0.0 ? -r-180.0 : -r+180.0 ); - } else { - r = 0.0; - } - - return r; -} -#endif - - double FGSteam::get_HackOBS1_deg () { return current_radiostack->get_nav1_radial(); } - double FGSteam::get_HackOBS2_deg () { return current_radiostack->get_nav2_radial(); }