// atis.cxx - routines to generate the ATIS info string
+// This is the implementation of the FGATIS class
//
// Written by David Luff, started October 2001.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifdef HAVE_CONFIG_H
#include <simgear/compiler.h>
+#include <stdlib.h> // atoi()
+#include <stdio.h> // sprintf
#include <string>
SG_USING_STD(string);
-//#include STL_IOSTREAM
-//#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
-//SG_USING_STD(cout);
-//#endif
+#include STL_IOSTREAM
+SG_USING_STD(cout);
-//#include <simgear/debug/logstream.hxx>
-//#include <simgear/misc/sgstream.hxx>
-//#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/sg_path.hxx>
-//#ifndef FG_OLD_WEATHER
-//#include <WeatherCM/FGLocalWeatherDatabase.h>
-//#else
-//# include <Weather/weather.hxx>
-//#endif
+#include <Environment/environment_mgr.hxx>
+#include <Environment/environment.hxx>
#include <Main/fg_props.hxx>
+#include <Main/globals.hxx>
#include <Airports/runways.hxx>
#include "atis.hxx"
-
-// Constructor
-FGATIS::FGATIS() {
+#include "commlist.hxx"
+#include "ATCutils.hxx"
+#include "ATCmgr.hxx"
+
+FGATIS::FGATIS() :
+ transmission(""),
+ trans_ident(""),
+ atis_failed(false),
+ refname("atis")
+ //type(ATIS)
+{
+ _vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS);
+ _voiceOK = (_vPtr == NULL ? false : true);
+ _type = ATIS;
}
-// Destructor
FGATIS::~FGATIS() {
}
-string FGATIS::get_transmission() {
-//void FGATIS::get_transmission() {
-
- string transmission = "";
- double visibility;
- double temperature;
- char buf[10];
+// Main update function - checks whether we are displaying or not the correct message.
+void FGATIS::Update(double dt) {
+ if(_display) {
+ if(_displaying) {
+ // Check if we need to update the message
+ // - basically every hour and if the weather changes significantly at the station
+ } else {
+ // We need to get and display the message
+ UpdateTransmission();
+ //cout << "ATIS.CXX - calling ATCMgr to render transmission..." << endl;
+ Render(transmission, refname, true);
+ _displaying = true;
+ }
+ } else {
+ // We shouldn't be displaying
+ if(_displaying) {
+ //cout << "ATIS.CXX - calling NoRender()..." << endl;
+ NoRender(refname);
+ _displaying = false;
+ }
+ }
+}
-// Only update every so-many loops - FIXME - possibly register this with the event scheduler
-// Ack this doesn't work since the static counter is shared between all instances of FGATIS
-// OK, for now the radiostack is handling only calling this every-so-often but that is not really
-// a proper solution since the atis knows when the transmission is going to change not the radio.
- //static int i=0;
- //if(i == 0) {
+// Sets the actual broadcast ATIS transmission.
+void FGATIS::UpdateTransmission() {
+ double visibility;
+ char buf[10];
+ int phonetic_id;
+ string phonetic_id_string;
+ string time_str = fgGetString("sim/time/gmt-string");
+ int hours;
+ // int minutes;
+
+ FGEnvironment stationweather =
+ ((FGEnvironmentMgr *)globals->get_subsystem("environment"))
+ ->getEnvironment(lat, lon, 0.0);
+
transmission = "";
-
- // Start with the transmitted station name.
+
+ // UK CAA radiotelephony manual indicated ATIS transmissions start with "This is"
+ // Not sure about rest of the world though.
+ transmission += "This_is ";
+ // transmitted station name.
transmission += name;
-
+ // Add "Information"
+ transmission += " information";
+
+ //cout << "In atis.cxx, time_str = " << time_str << '\n';
// Add the recording identifier
- // TODO - this is hardwired for now - ultimately we need to start with a random one and then increment it with each recording
- transmission += " Charlie";
-
+ // For now we will assume we only transmit every hour
+ hours = atoi((time_str.substr(1,2)).c_str()); //Warning - this is fragile if the
+ //time string format changes
+ //cout << "In atis.cxx, hours = " << hours << endl;
+ phonetic_id = current_commlist->GetCallSign(ident, hours, 0);
+ phonetic_id_string = GetPhoneticIdent(phonetic_id);
+ transmission += " ";
+ transmission += phonetic_id_string;
+
// Output the recording time. - we'll just output the last whole hour for now.
- string time_str = fgGetString("sim/time/gmt-string");
// FIXME - this only gets GMT time but that appears to be all the clock outputs for now
//cout << "in atis.cxx, time = " << time_str << endl;
- transmission = transmission + " Weather " + time_str.substr(0,3) + "00 hours Zulu";
-
+ transmission = transmission + " / Weather " + ConvertNumToSpokenDigits((time_str.substr(0,3) + "00")) + " hours zulu";
+
// Get the temperature
- // Hardwire the temperature for now - is the local weather database running yet?
- transmission += " Temperature 25 degrees Celcius";
-
- // Get the pressure / altimeter
+ int temp;
+ temp = (int)stationweather.get_temperature_degc();
+
+ // HACK ALERT - at the moment the new environment subsystem returns bogus temperatures
+ // FIXME - take out this hack when this gets fixed upstream
+ if((temp < -50) || (temp > 60)) {
+ temp = 15;
+ }
+ sprintf(buf, "%i", abs(temp));
+ transmission += " / Temperature ";
+ if(temp < 0) {
+ transmission += "minus ";
+ }
+ string tempstr1 = buf;
+ string tempstr2;
+ transmission += ConvertNumToSpokenDigits(tempstr1);
+ transmission += " degrees_Celsius";
+
// Get the visibility
- visibility = fgGetDouble("/environment/visibility-m");
- sprintf(buf, "%d", int(visibility/1600));
- transmission += " Visibility ";
- transmission += buf;
+ visibility = stationweather.get_visibility_m();
+ sprintf(buf, "%i", int(visibility/1600));
+ transmission += " / Visibility ";
+ tempstr1 = buf;
+ transmission += ConvertNumToSpokenDigits(tempstr1);
transmission += " miles";
-
+
// Get the cloudbase
- if(fgGetBool("/environment/clouds/status")) {
- double cloudbase = fgGetDouble("/environment/clouds/altitude-ft");
- // For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
- char buf3[10];
- cout << "cloudbase = " << cloudbase << endl;
- sprintf(buf3, "%i", int(cloudbase));
- transmission = transmission + " Cloudbase " + buf3 + " feet";
+ // FIXME: kludge for now
+ if (strcmp(fgGetString("/environment/clouds/layer[0]/type"), "clear")) {
+ double cloudbase =
+ fgGetDouble("/environment/clouds/layer[0]/elevation-ft");
+ // For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
+ char buf3[10];
+ char buf4[10];
+ // cout << "cloudbase = " << cloudbase << endl;
+ sprintf(buf3, "%i", int(cloudbase)/1000);
+ sprintf(buf4, "%i", ((int)cloudbase % 1000)/100);
+ transmission += " / Cloudbase";
+ if(int(cloudbase)/1000) {
+ tempstr1 = buf3;
+ transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " thousand";
+ }
+ if(((int)cloudbase % 1000)/100) {
+ tempstr1 = buf4;
+ transmission = transmission + " " + ConvertNumToSpokenDigits(tempstr1) + " hundred";
+ }
+ transmission += " feet";
}
-
+
+ // Get the pressure / altimeter
+ double P = fgGetDouble("/environment/pressure-sea-level-inhg");
+ if(ident.substr(0,2) == "EG" && fgGetBool("/sim/atc/use-millibars") == true) {
+ // Convert to millibars for the UK!
+ P *= 33.864;
+ sprintf(buf, "%.0f", P);
+ } else {
+ sprintf(buf, "%.2f", P);
+ }
+ transmission += " / Altimeter ";
+ tempstr1 = buf;
+ transmission += ConvertNumToSpokenDigits(tempstr1);
+
// Based on the airport-id and wind get the active runway
//FGRunway *r;
- SGPath path( globals->get_fg_root() );
- path.append( "Airports" );
- path.append( "runways.mk4" );
- FGRunways runways( path.c_str() );
-
- //Set the heading to into the wind
- double hdg = fgGetDouble("/environment/wind-from-heading-deg");
- double speed = fgGetDouble("/environment/wind-speed-knots");
-
- //cout << "in atis.cxx, hdg = " << hdg << " speed = " << speed << endl;
-
- //If no wind use 270degrees
- if(speed == 0) {
- hdg = 270;
- transmission += " Winds light and variable";
+ double speed = stationweather.get_wind_speed_kt();
+ double hdg = stationweather.get_wind_from_heading_deg();
+ if (speed == 0) {
+ hdg = 270; // This forces West-facing rwys to be used in no-wind situations
+ // which is consistent with Flightgear's initial setup.
+ transmission += " / Winds_light_and_variable";
} else {
- //add a description of the wind to the transmission
- char buf2[48];
- sprintf(buf2, "%s %i %s %i %s", " Winds ", int(speed), " knots from ", int(hdg), " degrees");
- transmission += buf2;
+ // FIXME: get gust factor in somehow
+ char buf5[10];
+ char buf6[10];
+ sprintf(buf5, "%i", int(speed));
+ sprintf(buf6, "%i", int(hdg));
+ tempstr1 = buf5;
+ tempstr2 = buf6;
+ transmission = transmission + " / Winds " + ConvertNumToSpokenDigits(tempstr1) + " knots from "
+ + ConvertNumToSpokenDigits(tempstr2) + " degrees";
}
-
- string rwy_no = runways.search(ident, hdg);
+
+ string rwy_no = globals->get_runways()->search(ident, int(hdg));
if(rwy_no != "NN") {
- transmission += " Landing and departing runway ";
- transmission += rwy_no;
- //cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
+ transmission += " / Landing_and_departing_runway ";
+ transmission += ConvertRwyNumToSpokenString(atoi(rwy_no.c_str()));
+ //cout << "in atis.cxx, r.rwy_no = " << rwy_no << " r.id = " << r->id << " r.heading = " << r->heading << endl;
}
-
+
// Anything else?
-
- // TODO - unhardwire the identifier
- transmission += " Advise controller on initial contact you have Charlie";
-
- //}
-
-// i++;
-// if(i == 600) {
-// i=0;
-// }
-
- return(transmission);
-}
\ No newline at end of file
+
+ transmission += " / Advise_controller_on_initial_contact_you_have ";
+ transmission += phonetic_id_string;
+ transmission += " /// ";
+}