]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/radiostack.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / Cockpit / radiostack.cxx
1 // radiostack.cxx -- class to manage an instance of the radio stack
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <stdio.h>      // snprintf
29
30 #include <simgear/compiler.h>
31 #include <simgear/math/sg_random.h>
32
33 #include <Aircraft/aircraft.hxx>
34 #include <Navaids/ilslist.hxx>
35 #include <Navaids/mkrbeacons.hxx>
36 #include <Navaids/navlist.hxx>
37 #include <Time/FGEventMgr.hxx>
38
39 #include "radiostack.hxx"
40
41 #include <string>
42 SG_USING_STD(string);
43
44
45 FGRadioStack *current_radiostack;
46
47
48 // Constructor
49 FGRadioStack::FGRadioStack() {
50 }
51
52
53 // Destructor
54 FGRadioStack::~FGRadioStack() 
55 {
56     adf.unbind();
57     beacon.unbind();
58     navcom1.unbind();
59     navcom2.unbind();
60     xponder.unbind();
61 }
62
63
64 void
65 FGRadioStack::init ()
66 {
67     navcom1.set_bind_index( 0 );
68     navcom1.init();
69
70     navcom2.set_bind_index( 1 );
71     navcom2.init();
72
73     adf.init();
74     beacon.init();
75     xponder.init();
76
77     search();
78     update(0);                  // FIXME: use dt
79
80     // Search radio database once per second
81     global_events.Register( "fgRadioSearch()",
82                             current_radiostack, &FGRadioStack::search,
83                             1000 );
84 }
85
86
87 void
88 FGRadioStack::bind ()
89 {
90     adf.bind();
91     beacon.bind();
92     dme.bind();
93     navcom1.set_bind_index( 0 );
94     navcom1.bind();
95     navcom2.set_bind_index( 1 );
96     navcom2.bind();
97     xponder.bind();
98 }
99
100
101 void
102 FGRadioStack::unbind ()
103 {
104     adf.unbind();
105     beacon.unbind();
106     dme.unbind();
107     navcom1.unbind();
108     navcom2.unbind();
109     xponder.unbind();
110 }
111
112
113 // Update the various nav values based on position and valid tuned in navs
114 void 
115 FGRadioStack::update(double dt) 
116 {
117     adf.update( dt );
118     beacon.update( dt );
119     navcom1.update( dt );
120     navcom2.update( dt );
121     dme.update( dt );           // dme is updated after the navcom's
122     xponder.update( dt );
123 }
124
125
126 // Update current nav/adf radio stations based on current postition
127 void FGRadioStack::search() 
128 {
129     adf.search();
130     beacon.search();
131     navcom1.search();
132     navcom2.search();
133     dme.search();
134     xponder.search();
135 }