1 // transponder.cxx -- class to impliment a transponder
3 // Written by Roy Vegard Ovesen, started September 2004.
5 // Copyright (C) 2004 Roy Vegard Ovesen - rvovesen@tiscali.no
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.
25 #include "transponder.hxx"
27 Transponder::Transponder(SGPropertyNode *node)
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"))
37 Transponder::~Transponder()
42 void Transponder::init()
45 branch = "/instrumentation/" + _name;
47 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
49 pressureAltitudeNode = fgGetNode(_mode_c_altitude.c_str(), true);
50 busPowerNode = fgGetNode("/systems/electrical/outputs/transponder", true);
51 serviceableNode = node->getChild("serviceable", 0, true);
53 idCodeNode = node->getChild("id-code", 0, true);
54 flightLevelNode = node->getChild("flight-level", 0, true);
58 void Transponder::update(double dt)
60 if (serviceableNode->getBoolValue())
62 int idCode = idCodeNode->getIntValue();
65 int firstDigit = idCode % 10;
66 int secondDigit = (idCode/10) % 10;
67 int thirdDigit = (idCode/100) % 10;
68 int fourthDigit = (idCode/1000) % 10;
71 idCode -= firstDigit-7;
72 if (secondDigit-7 > 0)
73 idCode -= (secondDigit-7) * 10;
75 idCode -= (thirdDigit-7) * 100;
76 if (fourthDigit-7 > 0)
77 idCode -= (fourthDigit-7) * 1000;
84 idCodeNode->setIntValue(idCode);
86 int pressureAltitude = pressureAltitudeNode->getIntValue();
87 int flightLevel = pressureAltitude / 100;
88 flightLevelNode->setIntValue(flightLevel);