1 // kt-70.cxx -- class to impliment the King KT 70 panel-m transponder
3 // Written by Curtis Olson, started July 2002.
5 // Copyright (C) 2002 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <simgear/compiler.h>
33 #include <simgear/math/sg_random.h>
35 #include <Aircraft/aircraft.hxx>
41 FGKT_70::FGKT_70(SGPropertyNode *node) :
45 last_ident_btn(false),
46 digit1(1), digit2(2), digit3(0), digit4(0),
60 for ( i = 0; i < node->nChildren(); ++i ) {
61 SGPropertyNode *child = node->getChild(i);
62 string cname = child->getName();
63 string cval = child->getStringValue();
64 if ( cname == "name" ) {
66 } else if ( cname == "number" ) {
67 num = child->getIntValue();
69 SG_LOG( SG_INSTR, SG_WARN,
70 "Error in kt-70 config logic" );
71 if ( name.length() ) {
72 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
81 FGKT_70::~FGKT_70() { }
87 branch = "/instrumentation/" + name;
89 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
91 lon_node = fgGetNode("/position/longitude-deg", true);
92 lat_node = fgGetNode("/position/latitude-deg", true);
93 alt_node = fgGetNode("/position/altitude-ft", true);
94 bus_power = fgGetNode("/systems/electrical/outputs/transponder", true);
95 serviceable_node = (node->getChild("inputs", 0, true))
96 ->getChild("serviceable", 0, true);
97 serviceable_node->setBoolValue(true);
101 void FGKT_70::bind () {
102 std::ostringstream temp;
105 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
111 fgTie((branch + "/inputs/ident-btn").c_str(), this,
112 &FGKT_70::get_ident_btn, &FGKT_70::set_ident_btn);
113 fgSetArchivable((branch + "/inputs/rotation-deg").c_str());
114 fgTie((branch + "/inputs/digit1").c_str(), this,
115 &FGKT_70::get_digit1, &FGKT_70::set_digit1);
116 fgSetArchivable((branch + "/inputs/digit1").c_str());
117 fgTie((branch + "/inputs/digit2").c_str(), this,
118 &FGKT_70::get_digit2, &FGKT_70::set_digit2);
119 fgSetArchivable((branch + "/inputs/digit2").c_str());
120 fgTie((branch + "/inputs/digit3").c_str(), this,
121 &FGKT_70::get_digit3, &FGKT_70::set_digit3);
122 fgSetArchivable((branch + "/inputs/digit3").c_str());
123 fgTie((branch + "/inputs/digit4").c_str(), this,
124 &FGKT_70::get_digit4, &FGKT_70::set_digit4);
125 fgSetArchivable((branch + "/inputs/digit4").c_str());
126 fgTie((branch + "/inputs/func-knob").c_str(), this,
127 &FGKT_70::get_func_knob, &FGKT_70::set_func_knob);
128 fgSetArchivable((branch + "/inputs/func-knob").c_str());
131 fgTie((branch + "/outputs/id-code").c_str(), this,
132 &FGKT_70::get_id_code, &FGKT_70::set_id_code);
133 fgSetArchivable((branch + "/outputs/id-code").c_str());
134 fgTie((branch + "/outputs/flight-level").c_str(), this,
135 &FGKT_70::get_flight_level);
138 fgTie((branch + "/annunciators/fl").c_str(), this,
139 &FGKT_70::get_fl_ann );
140 fgTie((branch + "/annunciators/alt").c_str(), this,
141 &FGKT_70::get_alt_ann );
142 fgTie((branch + "/annunciators/gnd").c_str(), this,
143 &FGKT_70::get_gnd_ann );
144 fgTie((branch + "/annunciators/on").c_str(), this,
145 &FGKT_70::get_on_ann );
146 fgTie((branch + "/annunciators/sby").c_str(), this,
147 &FGKT_70::get_sby_ann );
148 fgTie((branch + "/annunciators/reply").c_str(), this,
149 &FGKT_70::get_reply_ann );
153 void FGKT_70::unbind () {
154 std::ostringstream temp;
157 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
163 fgUntie((branch + "/inputs/ident-btn").c_str());
164 fgUntie((branch + "/inputs/digit1").c_str());
165 fgUntie((branch + "/inputs/digit2").c_str());
166 fgUntie((branch + "/inputs/digit3").c_str());
167 fgUntie((branch + "/inputs/digit4").c_str());
168 fgUntie((branch + "/inputs/func-knob").c_str());
171 fgUntie((branch + "/outputs/id-code").c_str());
172 fgUntie((branch + "/outputs/flight-level").c_str());
175 fgUntie((branch + "/annunciators/fl").c_str());
176 fgUntie((branch + "/annunciators/alt").c_str());
177 fgUntie((branch + "/annunciators/gnd").c_str());
178 fgUntie((branch + "/annunciators/on").c_str());
179 fgUntie((branch + "/annunciators/sby").c_str());
180 fgUntie((branch + "/annunciators/reply").c_str());
184 // Update the various nav values based on position and valid tuned in navs
185 void FGKT_70::update( double dt ) {
186 // start with all annunciators off (reply ann is handled
187 // separately) and then turn on the ones we want
195 if ( has_power() && serviceable_node->getBoolValue() ) {
197 if ( digit1 < 0 ) { digit1 = 0; }
198 if ( digit1 > 7 ) { digit1 = 7; }
199 if ( digit2 < 0 ) { digit2 = 0; }
200 if ( digit2 > 7 ) { digit2 = 7; }
201 if ( digit3 < 0 ) { digit3 = 0; }
202 if ( digit3 > 7 ) { digit3 = 7; }
203 if ( digit4 < 0 ) { digit4 = 0; }
204 if ( digit4 > 7 ) { digit4 = 7; }
206 id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
208 // flight level computation
210 // FIXME!!!! This needs to be computed relative to 29.92 inHg,
211 // but for the moment, until I figure out how to do that, I'll
212 // just use true altitude.
213 flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0);
216 if ( ident_btn && !last_ident_btn ) {
217 // ident button depressed
222 if ( r_flash_time > 18.0 ) {
232 if ( func_knob == 1 ) {
234 } else if ( func_knob == 2 ) {
241 } else if ( func_knob == 3 ) {
244 } else if ( func_knob == 4 ) {
246 } else if ( func_knob == 5 ) {