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>
39 #include <Environment/environment_mgr.hxx>
40 #include <Environment/environment.hxx>
42 #include <Main/fg_props.hxx>
43 #include <Main/globals.hxx>
44 #include <Airports/runways.hxx>
47 #include "commlist.hxx"
48 #include "ATCdisplay.hxx"
49 #include "ATCutils.hxx"
59 _vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS);
60 _voiceOK = (_vPtr == NULL ? false : true);
67 // Main update function - checks whether we are displaying or not the correct message.
68 void FGATIS::Update(double dt) {
71 // Check if we need to update the message
72 // - basically every hour and if the weather changes significantly at the station
73 //globals->get_ATC_display()->ChangeRepeatingMessage(transmission);
75 // We need to get and display the message
77 //cout << "ATIS.CXX - calling ATCMgr to render transmission..." << endl;
78 Render(transmission, refname, true);
82 // We shouldn't be displaying
84 //cout << "ATIS.CXX - calling NoRender()..." << endl;
91 // Sets the actual broadcast ATIS transmission.
92 void FGATIS::UpdateTransmission() {
96 string phonetic_id_string;
97 string time_str = fgGetString("sim/time/gmt-string");
101 FGEnvironment stationweather =
102 ((FGEnvironmentMgr *)globals->get_subsystem("environment"))
103 ->getEnvironment(lat, lon, 0.0);
107 // UK CAA radiotelephony manual indicated ATIS transmissions start with "This is"
108 // Not sure about rest of the world though.
109 transmission += "This_is ";
110 // transmitted station name.
111 transmission += name;
113 transmission += " information";
115 //cout << "In atis.cxx, time_str = " << time_str << '\n';
116 // Add the recording identifier
117 // For now we will assume we only transmit every hour
118 hours = atoi((time_str.substr(1,2)).c_str()); //Warning - this is fragile if the
119 //time string format changes
120 //cout << "In atis.cxx, hours = " << hours << endl;
121 phonetic_id = current_commlist->GetCallSign(ident, hours, 0);
122 phonetic_id_string = GetPhoneticIdent(phonetic_id);
124 transmission += phonetic_id_string;
126 // Output the recording time. - we'll just output the last whole hour for now.
127 // FIXME - this only gets GMT time but that appears to be all the clock outputs for now
128 //cout << "in atis.cxx, time = " << time_str << endl;
129 transmission = transmission + " / Weather " + ConvertNumToSpokenDigits((time_str.substr(0,3) + "00")) + " hours zulu";
131 // Get the temperature
133 temp = (int)stationweather.get_temperature_degc();
135 // HACK ALERT - at the moment the new environment subsystem returns bogus temperatures
136 // FIXME - take out this hack when this gets fixed upstream
137 if((temp < -50) || (temp > 60)) {
141 sprintf(buf, "%i", abs(temp));
142 transmission += " / Temperature ";
144 transmission += "minus ";
146 string tempstr1 = buf;
148 transmission += ConvertNumToSpokenDigits(tempstr1);
149 transmission += " degrees_Celsius";
151 // Get the visibility
152 visibility = stationweather.get_visibility_m();
153 sprintf(buf, "%i", int(visibility/1600));
154 transmission += " / Visibility ";
156 transmission += ConvertNumToSpokenDigits(tempstr1);
157 transmission += " miles";
160 // FIXME: kludge for now
161 if (strcmp(fgGetString("/environment/clouds/layer[0]/type"), "clear")) {
163 fgGetDouble("/environment/clouds/layer[0]/elevation-ft");
164 // For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
167 // cout << "cloudbase = " << cloudbase << endl;
168 sprintf(buf3, "%i", int(cloudbase)/1000);
169 sprintf(buf4, "%i", ((int)cloudbase % 1000)/100);
170 transmission += " / Cloudbase";
171 if(int(cloudbase)/1000) {
173 transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " thousand";
175 if(((int)cloudbase % 1000)/100) {
177 transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " hundred";
179 transmission += " feet";
182 // Get the pressure / altimeter
183 double P = fgGetDouble("/environment/pressure-sea-level-inhg");
184 if(ident.substr(0,2) == "EG" && fgGetBool("/sim/atc/use-millibars") == true) {
185 // Convert to millibars for the UK!
187 sprintf(buf, "%.0f", P);
189 sprintf(buf, "%.2f", P);
191 transmission += " / Altimeter ";
193 transmission += ConvertNumToSpokenDigits(tempstr1);
195 // Based on the airport-id and wind get the active runway
197 double speed = stationweather.get_wind_speed_kt();
198 double hdg = stationweather.get_wind_from_heading_deg();
200 hdg = 270; // This forces West-facing rwys to be used in no-wind situations
201 // which is consistent with Flightgear's initial setup.
202 transmission += " / Winds_light_and_variable";
204 // FIXME: get gust factor in somehow
207 sprintf(buf5, "%i", int(speed));
208 sprintf(buf6, "%i", int(hdg));
211 transmission = transmission + " / Winds " + ConvertNumToSpokenDigits(tempstr1) + " knots from "
212 + ConvertNumToSpokenDigits(tempstr2) + " degrees";
215 string rwy_no = globals->get_runways()->search(ident, int(hdg));
217 transmission += " / Landing_and_departing_runway ";
218 transmission += ConvertRwyNumToSpokenString(atoi(rwy_no.c_str()));
219 //cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
224 transmission += " / Advise_controller_on_initial_contact_you_have ";
225 transmission += phonetic_id_string;
226 transmission += " /// ";