1 // atis.cxx - routines to generate the ATIS info string
2 // This is the implementation of the FGATIS class
4 // Written by David Luff, started October 2001.
6 // Copyright (C) 2001 David C Luff - david.luff@nottingham.ac.uk
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <simgear/compiler.h>
29 #include <stdlib.h> // atoi()
30 #include <stdio.h> // sprintf
35 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
39 //#include <simgear/debug/logstream.hxx>
40 //#include <simgear/misc/sgstream.hxx>
41 #include <simgear/misc/sg_path.hxx>
43 //#ifndef FG_NEW_ENVIRONMENT
44 //sorry, that works only with the new weather system
45 #include <WeatherCM/FGLocalWeatherDatabase.h>
47 //# include <Environment/environment.hxx>
50 #include <Main/fg_props.hxx>
51 #include <Main/globals.hxx>
52 #include <Airports/runways.hxx>
55 #include "atislist.hxx"
56 #include "ATCdisplay.hxx"
58 string GetPhoneticIdent(int i) {
59 // TODO - Check i is between 1 and 26 and wrap if necessary
61 case 1 : return("Alpha");
62 case 2 : return("Bravo");
63 case 3 : return("Charlie");
64 case 4 : return("Delta");
65 case 5 : return("Echo");
66 case 6 : return("Foxtrot");
67 case 7 : return("Golf");
68 case 8 : return("Hotel");
69 case 9 : return("Indigo");
70 case 10 : return("Juliet");
71 case 11 : return("Kilo");
72 case 12 : return("Lima");
73 case 13 : return("Mike");
74 case 14 : return("November");
75 case 15 : return("Oscar");
76 case 16 : return("Papa");
77 case 17 : return("Quebec");
78 case 18 : return("Romeo");
79 case 19 : return("Sierra");
80 case 20 : return("Tango");
81 case 21 : return("Uniform");
82 case 22 : return("Victor");
83 case 23 : return("Whiskey");
84 case 24 : return("X-ray");
85 case 25 : return("Yankee");
86 case 26 : return("Zulu");
88 // We shouldn't get here
97 x(0.0), y(0.0), z(0.0),
114 // Main update function - checks whether we are displaying or not the correct message.
115 void FGATIS::Update() {
118 // Check if we need to update the message
119 // - basically every hour and if the weather changes significantly at the station
120 //globals->get_ATC_display()->ChangeRepeatingMessage(transmission);
122 // We need to get and display the message
123 UpdateTransmission();
124 globals->get_ATC_display()->RegisterRepeatingMessage(transmission);
128 // We shouldn't be displaying
130 globals->get_ATC_display()->CancelRepeatingMessage();
136 // Sets the actual broadcast ATIS transmission.
137 void FGATIS::UpdateTransmission() {
138 #if !defined(FG_NEW_ENVIRONMENT)
142 string phonetic_id_string;
143 string time_str = fgGetString("sim/time/gmt-string");
146 sgVec3 position = { lat, lon, elev };
147 FGPhysicalProperty stationweather = WeatherDatabase->get(position);
151 // Start with the transmitted station name.
152 transmission += name;
154 transmission += " Information";
156 //cout << "In atis.cxx, time_str = " << time_str << '\n';
157 // Add the recording identifier
158 // For now we will assume we only transmit every hour
159 hours = atoi((time_str.substr(1,2)).c_str()); //Warning - this is fragile if the
160 //time string format changes
161 //cout << "In atis.cxx, hours = " << hours << endl;
162 phonetic_id = current_atislist->GetCallSign(ident, hours, 0);
163 phonetic_id_string = GetPhoneticIdent(phonetic_id);
165 transmission += phonetic_id_string;
167 // Output the recording time. - we'll just output the last whole hour for now.
168 // FIXME - this only gets GMT time but that appears to be all the clock outputs for now
169 //cout << "in atis.cxx, time = " << time_str << endl;
170 transmission = transmission + " Weather " + time_str.substr(0,3) + "00 hours Zulu";
172 // Get the temperature
173 // (Hardwire it for now since the global property returns the temperature at the current altitude
174 //temperature = fgGetDouble("/environment/weather/temperature-K");
175 sprintf(buf, "%i", int(stationweather.Temperature - 273.15));
176 transmission += " Temperature ";
178 transmission += " degrees Celsius";
180 // Get the pressure / altimeter
181 // pressure is: stationweather.AirPressure in Pascal
183 // Get the visibility
184 visibility = fgGetDouble("/environment/visibility-m");
185 sprintf(buf, "%i", int(visibility/1600));
186 transmission += " Visibility ";
188 transmission += " miles";
191 if(fgGetBool("/environment/clouds/status")) {
192 double cloudbase = fgGetDouble("/environment/clouds/altitude-ft");
193 // For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
195 // cout << "cloudbase = " << cloudbase << endl;
196 sprintf(buf3, "%i", int(cloudbase));
197 transmission = transmission + " Cloudbase " + buf3 + " feet";
200 // Based on the airport-id and wind get the active runway
202 SGPath path( globals->get_fg_root() );
203 path.append( "Airports" );
204 path.append( "runways.mk4" );
205 FGRunways runways( path.c_str() );
207 //Set the heading to into the wind
208 double wind_x = stationweather.Wind[0];
209 double wind_y = stationweather.Wind[1];
211 double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
214 //If no wind use 270degrees
217 transmission += " Winds light and variable";
219 // //normalize the wind to get the direction
220 //wind_x /= speed; wind_y /= speed;
222 hdg = - atan2 ( wind_x, wind_y ) * SG_RADIANS_TO_DEGREES ;
226 //add a description of the wind to the transmission
228 sprintf(buf2, "%s %i %s %i %s", " Winds ", int(speed), " knots from ", int(hdg), " degrees");
229 transmission += buf2;
232 string rwy_no = runways.search(ident, int(hdg));
233 if(rwy_no != (string)"NN") {
234 transmission += " Landing and departing runway ";
235 transmission += rwy_no;
236 //cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
241 transmission += " Advise controller on initial contact you have ";
242 transmission += phonetic_id_string;
245 transmission = "Station unavailable (not supported by FG_NEW_ENVIRONMENT)";
246 //return "Station unavailable (not supported by FG_NEW_ENVIRONMENT)";
247 #endif // FG_NEW_ENVIRONMENT