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
37 //#include <simgear/debug/logstream.hxx>
38 //#include <simgear/misc/sgstream.hxx>
39 #include <simgear/misc/sg_path.hxx>
42 # include <WeatherCM/FGLocalWeatherDatabase.h>
44 # include <Environment/environment_mgr.hxx>
45 # include <Environment/environment.hxx>
48 #include <Main/fg_props.hxx>
49 #include <Main/globals.hxx>
50 #include <Airports/runways.hxx>
53 #include "atislist.hxx"
54 #include "ATCdisplay.hxx"
55 #include "ATCutils.hxx"
63 x(0.0), y(0.0), z(0.0),
81 // Main update function - checks whether we are displaying or not the correct message.
82 void FGATIS::Update() {
85 // Check if we need to update the message
86 // - basically every hour and if the weather changes significantly at the station
87 //globals->get_ATC_display()->ChangeRepeatingMessage(transmission);
89 // We need to get and display the message
91 //cout << "ATIS.CXX - calling ATCMgr to render transmission..." << endl;
92 globals->get_ATC_mgr()->Render(transmission, refname, true);
96 // We shouldn't be displaying
98 //cout << "ATIS.CXX - calling NoRender()..." << endl;
99 globals->get_ATC_mgr()->NoRender(refname);
105 // Sets the actual broadcast ATIS transmission.
106 void FGATIS::UpdateTransmission() {
110 string phonetic_id_string;
111 string time_str = fgGetString("sim/time/gmt-string");
116 sgVec3 position = { lat, lon, elev };
117 FGPhysicalProperty stationweather = WeatherDatabase->get(position);
119 FGEnvironment stationweather =
120 globals->get_environment_mgr()->getEnvironment(lat, lon, elev);
125 // UK CAA radiotelephony manual indicated ATIS transmissions start with "This is"
126 // Not sure about rest of the world though.
127 transmission += "This_is ";
128 // transmitted station name.
129 transmission += name;
131 transmission += " information";
133 //cout << "In atis.cxx, time_str = " << time_str << '\n';
134 // Add the recording identifier
135 // For now we will assume we only transmit every hour
136 hours = atoi((time_str.substr(1,2)).c_str()); //Warning - this is fragile if the
137 //time string format changes
138 //cout << "In atis.cxx, hours = " << hours << endl;
139 phonetic_id = current_atislist->GetCallSign(ident, hours, 0);
140 phonetic_id_string = GetPhoneticIdent(phonetic_id);
142 transmission += phonetic_id_string;
144 // Output the recording time. - we'll just output the last whole hour for now.
145 // FIXME - this only gets GMT time but that appears to be all the clock outputs for now
146 //cout << "in atis.cxx, time = " << time_str << endl;
147 transmission = transmission + " / Weather " + ConvertNumToSpokenDigits((time_str.substr(0,3) + "00")) + " hours zulu";
149 // Get the temperature
150 // (Hardwire it for now since the global property returns the temperature at the current altitude
151 //temperature = fgGetDouble("/environment/weather/temperature-K");
153 sprintf(buf, "%i", int(stationweather.Temperature - 273.15));
155 // HACK ALERT - at the moment the new environment subsystem returns bogus temperatures
156 // FIXME - take out this hack when this gets fixed upstream
157 int temp = (int)stationweather.get_temperature_degc();
158 if((temp < -50) || (temp > 60)) {
162 //sprintf(buf, "%d", int(stationweather.get_temperature_degc()));
164 sprintf(buf, "%d", temp);
166 transmission += " / Temperature ";
168 transmission += "minus ";
170 string tempstr1 = buf;
172 transmission += ConvertNumToSpokenDigits(tempstr1);
173 transmission += " degrees_Celsius";
175 // Get the visibility
177 visibility = fgGetDouble("/environment/visibility-m");
179 visibility = stationweather.get_visibility_m();
181 sprintf(buf, "%i", int(visibility/1600));
182 transmission += " / Visibility ";
184 transmission += ConvertNumToSpokenDigits(tempstr1);
185 transmission += " miles";
188 // FIXME: kludge for now
189 if (strcmp(fgGetString("/environment/clouds/layer[0]/type"), "clear")) {
191 fgGetDouble("/environment/clouds/layer[0]/elevation-ft");
192 // 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)/1000);
197 sprintf(buf4, "%i", ((int)cloudbase % 1000)/100);
198 transmission += " / Cloudbase";
199 if(int(cloudbase)/1000) {
201 transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " thousand";
203 if(((int)cloudbase % 1000)/100) {
205 transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " hundred";
207 transmission += " feet";
210 // Get the pressure / altimeter
213 double altimeter = stationweather.get_pressure_sea_level_inhg();
214 sprintf(buf, "%.2f", altimeter);
215 transmission += " / Altimeter ";
217 transmission += ConvertNumToSpokenDigits(tempstr1);
220 // Based on the airport-id and wind get the active runway
222 SGPath path( globals->get_fg_root() );
223 path.append( "Airports" );
224 path.append( "runways.mk4" );
225 FGRunways runways( path.c_str() );
228 //Set the heading to into the wind
229 double wind_x = stationweather.Wind[0];
230 double wind_y = stationweather.Wind[1];
232 double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
235 //If no wind use 270degrees
238 transmission += " / Winds_light_and_variable";
240 // //normalize the wind to get the direction
241 //wind_x /= speed; wind_y /= speed;
243 hdg = - atan2 ( wind_x, wind_y ) * SG_RADIANS_TO_DEGREES ;
247 //add a description of the wind to the transmission
250 sprintf(buf5, "%i", int(speed));
251 sprintf(buf6, "%i", int(hdg));
254 transmission = transmission + " / Winds " + ConvertNumToSpokenDigits(tempstr1) + " knots from "
255 + ConvertNumToSpokenDigits(tempstr2) + " degrees";
258 double speed = stationweather.get_wind_speed_kt();
259 double hdg = stationweather.get_wind_from_heading_deg();
261 transmission += " / Winds_light_and_variable";
263 // FIXME: get gust factor in somehow
266 sprintf(buf5, "%i", int(speed));
267 sprintf(buf6, "%i", int(hdg));
270 transmission = transmission + " / Winds " + ConvertNumToSpokenDigits(tempstr1) + " knots from "
271 + ConvertNumToSpokenDigits(tempstr2) + " degrees";
275 string rwy_no = runways.search(ident, int(hdg));
276 if(rwy_no != (string)"NN") {
277 transmission += " / Landing_and_departing_runway ";
278 transmission += ConvertRwyNumToSpokenString(atoi(rwy_no.c_str()));
279 //cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
284 transmission += " / Advise_controller_on_initial_contact_you_have ";
285 transmission += phonetic_id_string;
286 transmission += " /// ";