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., 675 Mass Ave, Cambridge, MA 02139, 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);
100 void FGKT_70::bind () {
101 std::ostringstream temp;
104 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
110 fgTie((branch + "/inputs/ident-btn").c_str(), this,
111 &FGKT_70::get_ident_btn, &FGKT_70::set_ident_btn);
112 fgSetArchivable((branch + "/inputs/rotation-deg").c_str());
113 fgTie((branch + "/inputs/digit1").c_str(), this,
114 &FGKT_70::get_digit1, &FGKT_70::set_digit1);
115 fgSetArchivable((branch + "/inputs/digit1").c_str());
116 fgTie((branch + "/inputs/digit2").c_str(), this,
117 &FGKT_70::get_digit2, &FGKT_70::set_digit2);
118 fgSetArchivable((branch + "/inputs/digit2").c_str());
119 fgTie((branch + "/inputs/digit3").c_str(), this,
120 &FGKT_70::get_digit3, &FGKT_70::set_digit3);
121 fgSetArchivable((branch + "/inputs/digit3").c_str());
122 fgTie((branch + "/inputs/digit4").c_str(), this,
123 &FGKT_70::get_digit4, &FGKT_70::set_digit4);
124 fgSetArchivable((branch + "/inputs/digit4").c_str());
125 fgTie((branch + "/inputs/func-knob").c_str(), this,
126 &FGKT_70::get_func_knob, &FGKT_70::set_func_knob);
127 fgSetArchivable((branch + "/inputs/func-knob").c_str());
130 fgTie((branch + "/outputs/id-code").c_str(), this,
131 &FGKT_70::get_id_code, &FGKT_70::set_id_code);
132 fgSetArchivable((branch + "/outputs/id-code").c_str());
133 fgTie((branch + "/outputs/flight-level").c_str(), this,
134 &FGKT_70::get_flight_level);
137 fgTie((branch + "/annunciators/fl").c_str(), this,
138 &FGKT_70::get_fl_ann );
139 fgTie((branch + "/annunciators/alt").c_str(), this,
140 &FGKT_70::get_alt_ann );
141 fgTie((branch + "/annunciators/gnd").c_str(), this,
142 &FGKT_70::get_gnd_ann );
143 fgTie((branch + "/annunciators/on").c_str(), this,
144 &FGKT_70::get_on_ann );
145 fgTie((branch + "/annunciators/sby").c_str(), this,
146 &FGKT_70::get_sby_ann );
147 fgTie((branch + "/annunciators/reply").c_str(), this,
148 &FGKT_70::get_reply_ann );
152 void FGKT_70::unbind () {
153 std::ostringstream temp;
156 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
162 fgUntie((branch + "/inputs/ident-btn").c_str());
163 fgUntie((branch + "/inputs/digit1").c_str());
164 fgUntie((branch + "/inputs/digit2").c_str());
165 fgUntie((branch + "/inputs/digit3").c_str());
166 fgUntie((branch + "/inputs/digit4").c_str());
167 fgUntie((branch + "/inputs/func-knob").c_str());
170 fgUntie((branch + "/outputs/id-code").c_str());
171 fgUntie((branch + "/outputs/flight-level").c_str());
174 fgUntie((branch + "/annunciators/fl").c_str());
175 fgUntie((branch + "/annunciators/alt").c_str());
176 fgUntie((branch + "/annunciators/gnd").c_str());
177 fgUntie((branch + "/annunciators/on").c_str());
178 fgUntie((branch + "/annunciators/sby").c_str());
179 fgUntie((branch + "/annunciators/reply").c_str());
183 // Update the various nav values based on position and valid tuned in navs
184 void FGKT_70::update( double dt ) {
185 // start with all annunciators off (reply ann is handled
186 // separately) and then turn on the ones we want
194 if ( has_power() && serviceable_node->getBoolValue() ) {
196 if ( digit1 < 0 ) { digit1 = 0; }
197 if ( digit1 > 7 ) { digit1 = 7; }
198 if ( digit2 < 0 ) { digit2 = 0; }
199 if ( digit2 > 7 ) { digit2 = 7; }
200 if ( digit3 < 0 ) { digit3 = 0; }
201 if ( digit3 > 7 ) { digit3 = 7; }
202 if ( digit4 < 0 ) { digit4 = 0; }
203 if ( digit4 > 7 ) { digit4 = 7; }
205 id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
207 // flight level computation
209 // FIXME!!!! This needs to be computed relative to 29.92 inHg,
210 // but for the moment, until I figure out how to do that, I'll
211 // just use true altitude.
212 flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0);
215 if ( ident_btn && !last_ident_btn ) {
216 // ident button depressed
221 if ( r_flash_time > 18.0 ) {
231 if ( func_knob == 1 ) {
233 } else if ( func_knob == 2 ) {
240 } else if ( func_knob == 3 ) {
243 } else if ( func_knob == 4 ) {
245 } else if ( func_knob == 5 ) {