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/misc/sg_path.hxx>
40 # include <WeatherCM/FGLocalWeatherDatabase.h>
42 # include <Environment/environment_mgr.hxx>
43 # include <Environment/environment.hxx>
46 #include <Main/fg_props.hxx>
47 #include <Main/globals.hxx>
48 #include <Airports/runways.hxx>
51 #include "commlist.hxx"
52 #include "ATCdisplay.hxx"
53 #include "ATCutils.hxx"
65 vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS);
66 voiceOK = (vPtr == NULL ? false : true);
73 // Main update function - checks whether we are displaying or not the correct message.
74 void FGATIS::Update(double dt) {
77 // Check if we need to update the message
78 // - basically every hour and if the weather changes significantly at the station
79 //globals->get_ATC_display()->ChangeRepeatingMessage(transmission);
81 // We need to get and display the message
83 //cout << "ATIS.CXX - calling ATCMgr to render transmission..." << endl;
84 Render(transmission, refname, true);
88 // We shouldn't be displaying
90 //cout << "ATIS.CXX - calling NoRender()..." << endl;
97 // Sets the actual broadcast ATIS transmission.
98 void FGATIS::UpdateTransmission() {
102 string phonetic_id_string;
103 string time_str = fgGetString("sim/time/gmt-string");
108 sgVec3 position = { lat, lon, elev };
109 FGPhysicalProperty stationweather = WeatherDatabase->get(position);
111 FGEnvironment stationweather =
112 ((FGEnvironmentMgr *)globals->get_subsystem("environment"))
113 ->getEnvironment(lat, lon, elev);
118 // UK CAA radiotelephony manual indicated ATIS transmissions start with "This is"
119 // Not sure about rest of the world though.
120 transmission += "This_is ";
121 // transmitted station name.
122 transmission += name;
124 transmission += " information";
126 //cout << "In atis.cxx, time_str = " << time_str << '\n';
127 // Add the recording identifier
128 // For now we will assume we only transmit every hour
129 hours = atoi((time_str.substr(1,2)).c_str()); //Warning - this is fragile if the
130 //time string format changes
131 //cout << "In atis.cxx, hours = " << hours << endl;
132 phonetic_id = current_commlist->GetCallSign(ident, hours, 0);
133 phonetic_id_string = GetPhoneticIdent(phonetic_id);
135 transmission += phonetic_id_string;
137 // Output the recording time. - we'll just output the last whole hour for now.
138 // FIXME - this only gets GMT time but that appears to be all the clock outputs for now
139 //cout << "in atis.cxx, time = " << time_str << endl;
140 transmission = transmission + " / Weather " + ConvertNumToSpokenDigits((time_str.substr(0,3) + "00")) + " hours zulu";
142 // Get the temperature
145 temp = int(stationweather.Temperature - 273.15);
147 temp = (int)stationweather.get_temperature_degc();
150 // HACK ALERT - at the moment the new environment subsystem returns bogus temperatures
151 // FIXME - take out this hack when this gets fixed upstream
152 if((temp < -50) || (temp > 60)) {
156 sprintf(buf, "%i", abs(temp));
157 transmission += " / Temperature ";
159 transmission += "minus ";
161 string tempstr1 = buf;
163 transmission += ConvertNumToSpokenDigits(tempstr1);
164 transmission += " degrees_Celsius";
166 // Get the visibility
168 visibility = fgGetDouble("/environment/visibility-m");
170 visibility = stationweather.get_visibility_m();
172 sprintf(buf, "%i", int(visibility/1600));
173 transmission += " / Visibility ";
175 transmission += ConvertNumToSpokenDigits(tempstr1);
176 transmission += " miles";
179 // FIXME: kludge for now
180 if (strcmp(fgGetString("/environment/clouds/layer[0]/type"), "clear")) {
182 fgGetDouble("/environment/clouds/layer[0]/elevation-ft");
183 // For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
186 // cout << "cloudbase = " << cloudbase << endl;
187 sprintf(buf3, "%i", int(cloudbase)/1000);
188 sprintf(buf4, "%i", ((int)cloudbase % 1000)/100);
189 transmission += " / Cloudbase";
190 if(int(cloudbase)/1000) {
192 transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " thousand";
194 if(((int)cloudbase % 1000)/100) {
196 transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " hundred";
198 transmission += " feet";
201 // Get the pressure / altimeter
204 double altimeter = stationweather.get_pressure_sea_level_inhg();
205 sprintf(buf, "%.2f", altimeter);
206 transmission += " / Altimeter ";
208 transmission += ConvertNumToSpokenDigits(tempstr1);
211 // Based on the airport-id and wind get the active runway
215 //Set the heading to into the wind
216 double wind_x = stationweather.Wind[0];
217 double wind_y = stationweather.Wind[1];
219 double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
222 //If no wind use 270degrees
225 transmission += " / Winds_light_and_variable";
227 // //normalize the wind to get the direction
228 //wind_x /= speed; wind_y /= speed;
230 hdg = - atan2 ( wind_x, wind_y ) * SG_RADIANS_TO_DEGREES ;
234 //add a description of the wind to the transmission
237 sprintf(buf5, "%i", int(speed));
238 sprintf(buf6, "%i", int(hdg));
241 transmission = transmission + " / Winds " + ConvertNumToSpokenDigits(tempstr1) + " knots from "
242 + ConvertNumToSpokenDigits(tempstr2) + " degrees";
245 double speed = stationweather.get_wind_speed_kt();
246 double hdg = stationweather.get_wind_from_heading_deg();
248 hdg = 270; // This forces West-facing rwys to be used in no-wind situations
249 // which is consistent with Flightgear's initial setup.
250 transmission += " / Winds_light_and_variable";
252 // FIXME: get gust factor in somehow
255 sprintf(buf5, "%i", int(speed));
256 sprintf(buf6, "%i", int(hdg));
259 transmission = transmission + " / Winds " + ConvertNumToSpokenDigits(tempstr1) + " knots from "
260 + ConvertNumToSpokenDigits(tempstr2) + " degrees";
264 string rwy_no = globals->get_runways()->search(ident, int(hdg));
266 transmission += " / Landing_and_departing_runway ";
267 transmission += ConvertRwyNumToSpokenString(atoi(rwy_no.c_str()));
268 //cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
273 transmission += " / Advise_controller_on_initial_contact_you_have ";
274 transmission += phonetic_id_string;
275 transmission += " /// ";