]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/radiostack.cxx
3123cc0207a966fbb0709495dc9abceed7075a4d
[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 #include <Navaids/ilslist.hxx>
25 #include <Navaids/navlist.hxx>
26
27 #include "radiostack.hxx"
28
29
30 FGRadioStack *current_radiostack;
31
32
33 // Constructor
34 FGRadioStack::FGRadioStack() {
35     need_update = true;
36 }
37
38
39 // Destructor
40 FGRadioStack::~FGRadioStack() {
41 }
42
43
44 // Update nav/adf radios based on current postition
45 void FGRadioStack::update( double lon, double lat, double elev ) {
46     need_update = false;
47
48     // nav1
49     FGILS ils;
50     FGNav nav;
51
52     if ( current_ilslist->query( lon, lat, elev, nav1_freq,
53                                  &ils, &nav1_heading, &nav1_dist) ) {
54         nav1_inrange = true;
55         nav1_loc = true;
56         nav1_lon = ils.get_loclon();
57         nav1_lat = ils.get_loclat();
58         nav1_elev = ils.get_gselev();
59         nav1_target_gs = ils.get_gsangle();
60         nav1_radial = ils.get_locheading() + 180.0;
61         while ( nav1_radial <   0.0 ) { nav1_radial += 360.0; }
62         while ( nav1_radial > 360.0 ) { nav1_radial -= 360.0; }
63         // cout << "Found a vor station in range" << endl;
64         // cout << " id = " << ils.get_locident() << endl;
65         // cout << " heading = " << nav1_heading
66         //      << " dist = " << nav1_dist << endl;
67     } else if ( current_navlist->query( lon, lat, elev, nav1_freq,
68                                  &nav, &nav1_heading, &nav1_dist) ) {
69                                 // not ILS
70         nav1_inrange = true;
71         nav1_loc = false;
72         nav1_lon = nav.get_lon();
73         nav1_lat = nav.get_lat();
74         nav1_elev = nav.get_elev();
75         nav1_target_gs = 0.0;
76         nav1_radial = nav1_sel_radial;
77     } else {
78         nav1_inrange = false;
79         // cout << "not picking up vor. :-(" << endl;
80     }
81
82     // nav2
83     if ( current_navlist->query( lon, lat, elev, nav2_freq,
84                                  &nav, &nav2_heading, &nav2_dist) ) {
85         nav2_inrange = true;
86         nav2_loc = false;
87         nav2_lon = nav.get_lon();
88         nav2_lat = nav.get_lat();
89         nav2_elev = nav.get_elev();
90         nav2_radial = nav2_sel_radial;
91     } else {
92         nav2_inrange = false;
93         // cout << "not picking up vor. :-(" << endl;
94     }
95
96     // adf
97     double junk;
98     if ( current_navlist->query( lon, lat, elev, adf_freq,
99                                  &nav, &adf_heading, &junk) ) {
100         adf_inrange = true;
101         adf_lon = nav.get_lon();
102         adf_lat = nav.get_lat();
103         adf_elev = nav.get_elev();
104         // cout << "Found an adf station in range" << endl;
105         // cout << " id = " << nav.get_ident() << endl;
106         // cout << " heading = " << adf_heading
107         //      << " dist = " << junk << endl;
108     } else {
109         adf_inrange = false;
110         // cout << "not picking up adf. :-(" << endl;
111     }
112 }
113