]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/transponder.cxx
#346 related: missing status message for property server
[flightgear.git] / src / Instrumentation / transponder.cxx
1 // transponder.cxx -- class to impliment a transponder
2 //
3 // Written by Roy Vegard Ovesen, started September 2004.
4 //
5 // Copyright (C) 2004  Roy Vegard Ovesen - rvovesen@tiscali.no
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 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include "transponder.hxx"
26
27 Transponder::Transponder(SGPropertyNode *node)
28     :
29     _name(node->getStringValue("name", "transponder")),
30     _num(node->getIntValue("number", 0)),
31     _mode_c_altitude(node->getStringValue("mode-c-altitude", 
32                                           "/instrumentation/encoder/mode-c-alt-ft"))
33 {
34 }
35
36
37 Transponder::~Transponder()
38 {
39 }
40
41
42 void Transponder::init()
43 {
44     string branch;
45     branch = "/instrumentation/" + _name;
46
47     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
48     // Inputs
49     pressureAltitudeNode = fgGetNode(_mode_c_altitude.c_str(), true);
50     busPowerNode = fgGetNode("/systems/electrical/outputs/transponder", true);
51     serviceableNode = node->getChild("serviceable", 0, true);
52     // Outputs
53     idCodeNode = node->getChild("id-code", 0, true);
54     flightLevelNode = node->getChild("flight-level", 0, true);
55 }
56
57
58 void Transponder::update(double dt)
59 {
60     if (serviceableNode->getBoolValue())
61     {
62         int idCode = idCodeNode->getIntValue();
63         if (idCode < 0)
64             idCode = 0;
65         int firstDigit  = idCode % 10;
66         int secondDigit = (idCode/10) % 10;
67         int thirdDigit  = (idCode/100) % 10;
68         int fourthDigit = (idCode/1000) % 10;
69
70         if (firstDigit-7 > 0)
71             idCode -= firstDigit-7;
72         if (secondDigit-7 > 0)
73             idCode -= (secondDigit-7) * 10;
74         if (thirdDigit-7 > 0)
75             idCode -= (thirdDigit-7) * 100;
76         if (fourthDigit-7 > 0)
77             idCode -= (fourthDigit-7) * 1000;
78
79         if (idCode > 7777)
80             idCode = 7777;
81         else if (idCode < 0)
82             idCode = 0;
83
84         idCodeNode->setIntValue(idCode);
85
86         int pressureAltitude = pressureAltitudeNode->getIntValue();
87         int flightLevel = pressureAltitude / 100;
88         flightLevelNode->setIntValue(flightLevel);
89     }
90 }