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., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "transponder.hxx"
27 Transponder::Transponder(SGPropertyNode *node)
31 encoder("/instrumentation/encoder")
34 for ( i = 0; i < node->nChildren(); ++i ) {
35 SGPropertyNode *child = node->getChild(i);
36 string cname = child->getName();
37 string cval = child->getStringValue();
38 if ( cname == "name" ) {
40 } else if ( cname == "number" ) {
41 num = child->getIntValue();
42 } else if ( cname == "encoder" ) {
45 SG_LOG( SG_INSTR, SG_WARN,
46 "Error in transponder config logic" );
47 if ( name.length() ) {
48 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
55 Transponder::~Transponder()
60 void Transponder::init()
63 branch = "/instrumentation/" + name;
64 encoder += "/mode-c-alt-ft";
66 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
68 pressureAltitudeNode = fgGetNode(encoder.c_str(), true);
69 busPowerNode = fgGetNode("/systems/electrical/outputs/transponder", true);
70 serviceableNode = node->getChild("serviceable", 0, true);
72 idCodeNode = node->getChild("id-code", 0, true);
73 flightLevelNode = node->getChild("flight-level", 0, true);
77 void Transponder::update(double dt)
79 if (serviceableNode->getBoolValue())
81 int idCode = idCodeNode->getIntValue();
84 int firstDigit = idCode % 10;
85 int secondDigit = (idCode/10) % 10;
86 int thirdDigit = (idCode/100) % 10;
87 int fourthDigit = (idCode/1000) % 10;
90 idCode -= firstDigit-7;
91 if (secondDigit-7 > 0)
92 idCode -= (secondDigit-7) * 10;
94 idCode -= (thirdDigit-7) * 100;
95 if (fourthDigit-7 > 0)
96 idCode -= (fourthDigit-7) * 1000;
103 idCodeNode->setIntValue(idCode);
105 int pressureAltitude = pressureAltitudeNode->getIntValue();
106 int flightLevel = pressureAltitude / 100;
107 flightLevelNode->setIntValue(flightLevel);