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>
39 FGKT_70::FGKT_70(SGPropertyNode *node) :
43 last_ident_btn(false),
44 digit1(1), digit2(2), digit3(0), digit4(0),
58 for ( i = 0; i < node->nChildren(); ++i ) {
59 SGPropertyNode *child = node->getChild(i);
60 string cname = child->getName();
61 string cval = child->getStringValue();
62 if ( cname == "name" ) {
64 } else if ( cname == "number" ) {
65 num = child->getIntValue();
67 SG_LOG( SG_INSTR, SG_WARN,
68 "Error in kt-70 config logic" );
69 if ( name.length() ) {
70 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
79 FGKT_70::~FGKT_70() { }
85 branch = "/instrumentation/" + name;
87 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
89 lon_node = fgGetNode("/position/longitude-deg", true);
90 lat_node = fgGetNode("/position/latitude-deg", true);
91 alt_node = fgGetNode("/position/altitude-ft", true);
92 bus_power = fgGetNode("/systems/electrical/outputs/transponder", true);
93 serviceable_node = (node->getChild("inputs", 0, true))
94 ->getChild("serviceable", 0, true);
95 serviceable_node->setBoolValue(true);
99 void FGKT_70::bind () {
100 std::ostringstream temp;
103 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
109 fgTie((branch + "/inputs/ident-btn").c_str(), this,
110 &FGKT_70::get_ident_btn, &FGKT_70::set_ident_btn);
111 fgSetArchivable((branch + "/inputs/rotation-deg").c_str());
112 fgTie((branch + "/inputs/digit1").c_str(), this,
113 &FGKT_70::get_digit1, &FGKT_70::set_digit1);
114 fgSetArchivable((branch + "/inputs/digit1").c_str());
115 fgTie((branch + "/inputs/digit2").c_str(), this,
116 &FGKT_70::get_digit2, &FGKT_70::set_digit2);
117 fgSetArchivable((branch + "/inputs/digit2").c_str());
118 fgTie((branch + "/inputs/digit3").c_str(), this,
119 &FGKT_70::get_digit3, &FGKT_70::set_digit3);
120 fgSetArchivable((branch + "/inputs/digit3").c_str());
121 fgTie((branch + "/inputs/digit4").c_str(), this,
122 &FGKT_70::get_digit4, &FGKT_70::set_digit4);
123 fgSetArchivable((branch + "/inputs/digit4").c_str());
124 fgTie((branch + "/inputs/func-knob").c_str(), this,
125 &FGKT_70::get_func_knob, &FGKT_70::set_func_knob);
126 fgSetArchivable((branch + "/inputs/func-knob").c_str());
129 fgTie((branch + "/outputs/id-code").c_str(), this,
130 &FGKT_70::get_id_code, &FGKT_70::set_id_code);
131 fgSetArchivable((branch + "/outputs/id-code").c_str());
132 fgTie((branch + "/outputs/flight-level").c_str(), this,
133 &FGKT_70::get_flight_level);
136 fgTie((branch + "/annunciators/fl").c_str(), this,
137 &FGKT_70::get_fl_ann );
138 fgTie((branch + "/annunciators/alt").c_str(), this,
139 &FGKT_70::get_alt_ann );
140 fgTie((branch + "/annunciators/gnd").c_str(), this,
141 &FGKT_70::get_gnd_ann );
142 fgTie((branch + "/annunciators/on").c_str(), this,
143 &FGKT_70::get_on_ann );
144 fgTie((branch + "/annunciators/sby").c_str(), this,
145 &FGKT_70::get_sby_ann );
146 fgTie((branch + "/annunciators/reply").c_str(), this,
147 &FGKT_70::get_reply_ann );
151 void FGKT_70::unbind () {
152 std::ostringstream temp;
155 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
161 fgUntie((branch + "/inputs/ident-btn").c_str());
162 fgUntie((branch + "/inputs/digit1").c_str());
163 fgUntie((branch + "/inputs/digit2").c_str());
164 fgUntie((branch + "/inputs/digit3").c_str());
165 fgUntie((branch + "/inputs/digit4").c_str());
166 fgUntie((branch + "/inputs/func-knob").c_str());
169 fgUntie((branch + "/outputs/id-code").c_str());
170 fgUntie((branch + "/outputs/flight-level").c_str());
173 fgUntie((branch + "/annunciators/fl").c_str());
174 fgUntie((branch + "/annunciators/alt").c_str());
175 fgUntie((branch + "/annunciators/gnd").c_str());
176 fgUntie((branch + "/annunciators/on").c_str());
177 fgUntie((branch + "/annunciators/sby").c_str());
178 fgUntie((branch + "/annunciators/reply").c_str());
182 // Update the various nav values based on position and valid tuned in navs
183 void FGKT_70::update( double dt ) {
184 // start with all annunciators off (reply ann is handled
185 // separately) and then turn on the ones we want
193 if ( has_power() && serviceable_node->getBoolValue() ) {
195 if ( digit1 < 0 ) { digit1 = 0; }
196 if ( digit1 > 7 ) { digit1 = 7; }
197 if ( digit2 < 0 ) { digit2 = 0; }
198 if ( digit2 > 7 ) { digit2 = 7; }
199 if ( digit3 < 0 ) { digit3 = 0; }
200 if ( digit3 > 7 ) { digit3 = 7; }
201 if ( digit4 < 0 ) { digit4 = 0; }
202 if ( digit4 > 7 ) { digit4 = 7; }
204 id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
206 // flight level computation
208 // FIXME!!!! This needs to be computed relative to 29.92 inHg,
209 // but for the moment, until I figure out how to do that, I'll
210 // just use true altitude.
211 flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0);
214 if ( ident_btn && !last_ident_btn ) {
215 // ident button depressed
220 if ( r_flash_time > 18.0 ) {
230 if ( func_knob == 1 ) {
232 } else if ( func_knob == 2 ) { // selftest
241 } else if ( func_knob == 3 ) {
244 } else if ( func_knob == 4 ) {
246 } else if ( func_knob == 5 ) {