]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/kt_70.cxx
Make hardcoded error values configurable.
[flightgear.git] / src / Instrumentation / kt_70.cxx
1 // kt-70.cxx -- class to impliment the King KT 70 panel-m transponder
2 //
3 // Written by Curtis Olson, started July 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson - http://www.flightgear.org/~curt
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <iostream>
29 #include <string>
30 #include <sstream>
31
32 #include <simgear/compiler.h>
33 #include <simgear/math/sg_random.h>
34
35 #include <Aircraft/aircraft.hxx>
36
37 #include "kt_70.hxx"
38
39
40 // Constructor
41 FGKT_70::FGKT_70(SGPropertyNode *node) :
42     r_flash_time(0.0),
43     ident_mode(false),
44     ident_btn(false),
45     last_ident_btn(false),
46     digit1(1), digit2(2), digit3(0), digit4(0),
47     func_knob(4),
48     id_code(1200),
49     flight_level(0),
50     fl_ann(0),
51     alt_ann(0),
52     gnd_ann(0),
53     on_ann(0),
54     sby_ann(0),
55     reply_ann(0),
56     name("kt-70"),
57     num(0)
58 {
59     int i;
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" ) {
65             name = cval;
66         } else if ( cname == "number" ) {
67             num = child->getIntValue();
68         } else {
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 );
73             }
74         }
75     }
76
77 }
78
79
80 // Destructor
81 FGKT_70::~FGKT_70() { }
82
83
84 void FGKT_70::init ()
85 {
86     string branch;
87     branch = "/instrumentation/" + name;
88
89     SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
90     // Inputs
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);
98 }
99
100
101 void FGKT_70::bind () {
102     std::ostringstream temp;
103     string branch;
104     temp << num;
105     branch = "/instrumentation/" + name + "[" + temp.str() + "]";
106     // internal values
107
108     // modes
109
110     // input and buttons
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());
129
130     // outputs
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);
136
137     // annunciators
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 );
150 }
151
152
153 void FGKT_70::unbind () {
154     std::ostringstream temp;
155     string branch;
156     temp << num;
157     branch = "/instrumentation/" + name + "[" + temp.str() + "]";
158     // internal values
159
160     // modes
161
162     // input and buttons
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());
169
170     // outputs
171     fgUntie((branch + "/outputs/id-code").c_str());
172     fgUntie((branch + "/outputs/flight-level").c_str());
173
174     // annunciators
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());
181 }
182
183
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
188     fl_ann = false;
189     alt_ann = false;
190     gnd_ann = false;
191     on_ann = false;
192     sby_ann = false;
193     reply_ann = false;
194
195     if ( has_power() && serviceable_node->getBoolValue() ) {
196         // sanity checks
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; }
205
206         id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
207
208         // flight level computation
209
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);
214
215         // ident button
216         if ( ident_btn && !last_ident_btn ) {
217             // ident button depressed
218             r_flash_time = 0.0;
219             ident_mode = true;
220         }
221         r_flash_time += dt;
222         if ( r_flash_time > 18.0 ) {
223             ident_mode = false;
224         }
225     
226         if ( ident_mode ) {
227             reply_ann = true;
228         } else {
229             reply_ann = false;
230         }
231
232         if ( func_knob == 1 ) {
233             sby_ann = true;
234         } else if ( func_knob == 2 ) {
235             fl_ann = true;
236             alt_ann = true;
237             gnd_ann = true;
238             on_ann = true;
239             sby_ann = true;
240             reply_ann = true;
241         } else if ( func_knob == 3 ) {
242             fl_ann = true;
243             gnd_ann = true;
244         } else if ( func_knob == 4 ) {
245             on_ann = true;
246         } else if ( func_knob == 5 ) {
247             fl_ann = true;
248             alt_ann = true;
249         }
250     }
251 }