]> git.mxchange.org Git - flightgear.git/blob - src/ATC/atis.cxx
a couple of minor modifications, including hardwiring temperature again
[flightgear.git] / src / ATC / atis.cxx
1 // atis.cxx - routines to generate the ATIS info string
2 //
3 // Written by David Luff, started October 2001.
4 //
5 // Copyright (C) 2001  David C Luff - david.luff@nottingham.ac.uk
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
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include <simgear/compiler.h>
27
28 #include <stdlib.h>     // atoi()
29 #include <string>
30 SG_USING_STD(string);
31
32 #include STL_IOSTREAM
33 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
34 SG_USING_STD(cout);
35 #endif
36
37 //#include <simgear/debug/logstream.hxx>
38 //#include <simgear/misc/sgstream.hxx>
39 #include <simgear/misc/sg_path.hxx>
40
41 //#ifndef FG_OLD_WEATHER
42 //#include <WeatherCM/FGLocalWeatherDatabase.h>
43 //#else
44 //#  include <Weather/weather.hxx>
45 //#endif
46
47 #include <Main/fg_props.hxx>
48 #include <Airports/runways.hxx>
49
50 #include "atis.hxx"
51 #include "atislist.hxx"
52
53 string GetPhoneticIdent(int i) {
54 // TODO - Check i is between 1 and 26 and wrap if necessary
55     switch(i) {
56     case 1 : return("Alpha");
57     case 2 : return("Bravo");
58     case 3 : return("Charlie");
59     case 4 : return("Delta");
60     case 5 : return("Echo");
61     case 6 : return("Foxtrot");
62     case 7 : return("Golf");
63     case 8 : return("Hotel");
64     case 9 : return("Indigo");
65     case 10 : return("Juliet");
66     case 11 : return("Kilo");
67     case 12 : return("Lima");
68     case 13 : return("Mike");
69     case 14 : return("November");
70     case 15 : return("Oscar");
71     case 16 : return("Papa");
72     case 17 : return("Quebec");
73     case 18 : return("Romeo");
74     case 19 : return("Sierra");
75     case 20 : return("Tango");
76     case 21 : return("Uniform");
77     case 22 : return("Victor");
78     case 23 : return("Whiskey");
79     case 24 : return("X-ray");
80     case 25 : return("Yankee");
81     case 26 : return("Zulu");
82     }
83     // We shouldn't get here
84     return("Error");
85 }
86
87 // Constructor
88 FGATIS::FGATIS() {
89 }
90
91 // Destructor
92 FGATIS::~FGATIS() {
93 }
94
95 string FGATIS::get_transmission() {
96 //void FGATIS::get_transmission() {
97
98     string transmission = "";
99     double visibility;
100     double temperature;
101     char buf[10];
102     int phonetic_id;
103     string phonetic_id_string;
104     string time_str = fgGetString("sim/time/gmt-string");
105     int hours;
106     int minutes;
107
108 // Only update every so-many loops - FIXME - possibly register this with the event scheduler
109 // Ack this doesn't work since the static counter is shared between all instances of FGATIS
110 // OK, for now the radiostack is handling only calling this every-so-often but that is not really 
111 // a proper solution since the atis knows when the transmission is going to change not the radio.
112     //static int i=0;
113     //if(i == 0) {
114         transmission = "";
115
116         // Start with the transmitted station name.
117         transmission += name;
118         // Add "Information"
119         transmission += " Information";
120
121         //cout << "In atis.cxx, time_str = " << time_str << '\n';
122         // Add the recording identifier
123         // For now we will assume we only transmit every hour
124         hours = atoi((time_str.substr(1,2)).c_str());   //Warning - this is fragile if the 
125                                                         //time string format changes
126         //cout << "In atis.cxx, hours = " << hours << endl;
127         phonetic_id = current_atislist->GetCallSign(ident, hours, 0);
128         phonetic_id_string = GetPhoneticIdent(phonetic_id);
129         transmission += " ";
130         transmission += phonetic_id_string;
131
132         // Output the recording time. - we'll just output the last whole hour for now.
133         // FIXME - this only gets GMT time but that appears to be all the clock outputs for now
134         //cout << "in atis.cxx, time = " << time_str << endl;
135         transmission = transmission + "  Weather " + time_str.substr(0,3) + "00 hours Zulu";
136
137         // Get the temperature
138         // (Hardwire it for now since the global property returns the temperature at the current altitude
139         //temperature = fgGetDouble("/environment/weather/temperature-K");
140         temperature = 15 + 273.15;
141         sprintf(buf, "%i", int(temperature - 273.15));
142         transmission += "  Temperature ";
143         transmission += buf;
144         transmission += " degrees Celcius";
145
146         // Get the pressure / altimeter
147
148         // Get the visibility
149         visibility = fgGetDouble("/environment/visibility-m");
150         sprintf(buf, "%i", int(visibility/1600));
151         transmission += "  Visibility ";
152         transmission += buf;
153         transmission += " miles";
154
155         // Get the cloudbase
156         if(fgGetBool("/environment/clouds/status")) {
157             double cloudbase = fgGetDouble("/environment/clouds/altitude-ft");
158             // For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
159             char buf3[10];
160             cout << "cloudbase = " << cloudbase << endl;
161             sprintf(buf3, "%i", int(cloudbase));
162             transmission = transmission + "  Cloudbase " + buf3 + " feet";
163         }
164
165         // Based on the airport-id and wind get the active runway
166         //FGRunway *r;
167         SGPath path( globals->get_fg_root() );
168         path.append( "Airports" );
169         path.append( "runways.mk4" );
170         FGRunways runways( path.c_str() );
171
172         //Set the heading to into the wind
173         double hdg = fgGetDouble("/environment/wind-from-heading-deg");
174         double speed = fgGetDouble("/environment/wind-speed-knots");
175
176         //cout << "in atis.cxx, hdg = " << hdg << " speed = " << speed << endl;
177
178         //If no wind use 270degrees
179         if(speed == 0) {
180             hdg = 270;
181             transmission += "  Winds light and variable";
182         } else {
183             //add a description of the wind to the transmission
184             char buf2[72];
185             sprintf(buf2, "%s %i %s %i %s", "  Winds ", int(speed), " knots from ", int(hdg), " degrees");
186             transmission += buf2;
187         }
188
189         string rwy_no = runways.search(ident, hdg);
190         if(rwy_no != "NN") {
191             transmission += "  Landing and departing runway ";
192             transmission += rwy_no;
193             //cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
194         }
195
196         // Anything else?
197
198         // TODO - unhardwire the identifier
199         transmission += "  Advise controller on initial contact you have ";
200         transmission += phonetic_id_string;
201
202     //}
203
204 //    i++;
205 //    if(i == 600) {
206 //      i=0;
207 //    }
208
209     return(transmission);
210 }