]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/atis.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / ATC / atis.cxx
index 0b2007aa0c0900373a7c09b21edb99dcfe4217b2..0021875dc2740f4f69b28bff5e21b8c52008cea9 100644 (file)
@@ -32,9 +32,7 @@
 SG_USING_STD(string);
 
 #include STL_IOSTREAM
-#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
 SG_USING_STD(cout);
-#endif
 
 //#include <simgear/debug/logstream.hxx>
 //#include <simgear/misc/sgstream.hxx>
@@ -52,26 +50,24 @@ SG_USING_STD(cout);
 #include <Airports/runways.hxx>
 
 #include "atis.hxx"
-#include "atislist.hxx"
+#include "commlist.hxx"
+//#include "atislist.hxx"
 #include "ATCdisplay.hxx"
 #include "ATCutils.hxx"
+#include "ATCmgr.hxx"
 
 // Constructor
-FGATIS::FGATIS()
-  : type(0),
-    lon(0.0), lat(0.0),
-    elev(0.0),
-    x(0.0), y(0.0), z(0.0),
-    freq(0),
-    range(0),
-    display(false),
-    displaying(false),
-    ident(""),
-    name(""),
-    transmission(""),
-    trans_ident(""),
-    atis_failed(false)
+FGATIS::FGATIS() :
+display(false),
+displaying(false),
+transmission(""),
+trans_ident(""),
+atis_failed(false),
+refname("atis")
+//type(ATIS)
 {
+       vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS);
+       voiceOK = (vPtr == NULL ? false : true);
 }
 
 // Destructor
@@ -79,167 +75,209 @@ FGATIS::~FGATIS() {
 }
 
 // Main update function - checks whether we are displaying or not the correct message.
-void FGATIS::Update() {
-    if(display) {
-       if(displaying) {
-           // Check if we need to update the message
-           // - basically every hour and if the weather changes significantly at the station
-           //globals->get_ATC_display()->ChangeRepeatingMessage(transmission);
+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
+                       //globals->get_ATC_display()->ChangeRepeatingMessage(transmission);
+               } 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 need to get and display the message
-           UpdateTransmission();
-           globals->get_ATC_display()->RegisterRepeatingMessage(transmission);
-           displaying = true;
-       }
-    } else {
-       // We shouldn't be displaying
-       if(displaying) {
-           globals->get_ATC_display()->CancelRepeatingMessage();
-           displaying = false;
+               // We shouldn't be displaying
+               if(displaying) {
+                       //cout << "ATIS.CXX - calling NoRender()..." << endl;
+                       NoRender(refname);
+                       displaying = false;
+               }
        }
-    }
 }
 
 // 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;
-
-#ifdef FG_WEATHERCM
-    sgVec3 position = { lat, lon, elev };
-    FGPhysicalProperty stationweather = WeatherDatabase->get(position);
-#else
-    FGEnvironment stationweather =
-      globals->get_environment_mgr()->getEnvironment(lat, lon, elev);
-#endif
-
-    transmission = "";
-
-    // Start with the transmitted station name.
-    transmission += name;
-    // Add "Information"
-    transmission += " Information";
-
-    //cout << "In atis.cxx, time_str = " << time_str << '\n';
-    // Add the recording identifier
-    // 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_atislist->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.
-    // 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";
-
-    // Get the temperature
-    // (Hardwire it for now since the global property returns the temperature at the current altitude
-    //temperature = fgGetDouble("/environment/weather/temperature-K");
-#ifdef FG_WEATHERCM
-    sprintf(buf, "%i", int(stationweather.Temperature - 273.15));
-#else
-    sprintf(buf, "%d", int(stationweather.get_temperature_degc()));
-#endif
-    transmission += "  Temperature ";
-    transmission += buf;
-    transmission += " degrees Celsius";
+       double visibility;
+       char buf[10];
+       int phonetic_id;
+       string phonetic_id_string;
+       string time_str = fgGetString("sim/time/gmt-string");
+       int hours;
+       // int minutes;
+       
+       #ifdef FG_WEATHERCM
+       sgVec3 position = { lat, lon, elev };
+       FGPhysicalProperty stationweather = WeatherDatabase->get(position);
+       #else
+       FGEnvironment stationweather =
+       globals->get_environment_mgr()->getEnvironment(lat, lon, elev);
+       #endif
+       
+       transmission = "";
+       
+       // 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
+       // 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.
+       // 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 " + ConvertNumToSpokenDigits((time_str.substr(0,3) + "00")) + " hours zulu";
+       
+       // Get the temperature
+       int temp;
+       #ifdef FG_WEATHERCM
+       temp = int(stationweather.Temperature - 273.15);
+       #else
+       temp = (int)stationweather.get_temperature_degc();
+       #endif
+       
+       // 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
-#ifdef FG_WEATHERCM
+       #ifdef FG_WEATHERCM
        visibility = fgGetDouble("/environment/visibility-m");
-#else
-        visibility = stationweather.get_visibility_m();
-#endif
+       #else
+       visibility = stationweather.get_visibility_m();
+       #endif
        sprintf(buf, "%i", int(visibility/1600));
-       transmission += "  Visibility ";
-       transmission += buf;
+       transmission += " / Visibility ";
+       tempstr1 = buf;
+       transmission += ConvertNumToSpokenDigits(tempstr1);
        transmission += " miles";
-
+       
        // Get the cloudbase
        // 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];
-           // cout << "cloudbase = " << cloudbase << endl;
-           sprintf(buf3, "%i", int(cloudbase));
-           transmission = transmission + "  Cloudbase " + buf3 + " feet";
+               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
-
-#ifndef FG_WEATHERCM
-      double altimeter = stationweather.get_pressure_sea_level_inhg();
-      sprintf(buf, "%.2f", altimeter);
-      transmission += "  Altimeter ";
-      transmission += buf;
-#endif
-
+       
+       #ifndef FG_WEATHERCM
+       double altimeter = stationweather.get_pressure_sea_level_inhg();
+       sprintf(buf, "%.2f", altimeter);
+       transmission += " / Altimeter ";
+       tempstr1 = buf;
+       transmission += ConvertNumToSpokenDigits(tempstr1);
+       #endif
+       
        // 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() );
-
-#ifdef FG_WEATHERCM
+       
+       #ifdef FG_WEATHERCM
        //Set the heading to into the wind
-        double wind_x = stationweather.Wind[0];
-        double wind_y = stationweather.Wind[1];
-
-        double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
-        double hdg;
-
+       double wind_x = stationweather.Wind[0];
+       double wind_y = stationweather.Wind[1];
+       
+       double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
+       double hdg;
+       
        //If no wind use 270degrees
        if(speed == 0) {
-           hdg = 270;
-           transmission += "  Winds light and variable";
+               hdg = 270;
+               transmission += " / Winds_light_and_variable";
        } else {
-            // //normalize the wind to get the direction
-            //wind_x /= speed; wind_y /= speed;
-
-            hdg = - atan2 ( wind_x, wind_y ) * SG_RADIANS_TO_DEGREES ;
-            if (hdg < 0.0)
-              hdg += 360.0;
-
-           //add a description of the wind to the transmission
-           char buf2[72];
-           sprintf(buf2, "%s %i %s %i %s", "  Winds ", int(speed), " knots from ", int(hdg), " degrees");
-           transmission += buf2;
+               // //normalize the wind to get the direction
+               //wind_x /= speed; wind_y /= speed;
+               
+               hdg = - atan2 ( wind_x, wind_y ) * SG_RADIANS_TO_DEGREES ;
+               if (hdg < 0.0)
+                       hdg += 360.0;
+               
+               //add a description of the wind to the transmission
+               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";
        }
-#else
+       #else
        double speed = stationweather.get_wind_speed_kt();
        double hdg = stationweather.get_wind_from_heading_deg();
        if (speed == 0) {
-         transmission += "  Winds light and variable";
+               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 {
-                               // FIXME: get gust factor in somehow
-           char buf2[72];
-           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";
        }
-#endif
-
+       #endif
+       
        string rwy_no = runways.search(ident, int(hdg));
        if(rwy_no != (string)"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?
-
-       transmission += "  Advise controller on initial contact you have ";
+       
+       transmission += " / Advise_controller_on_initial_contact_you_have ";
        transmission += phonetic_id_string;
+       transmission += " /// ";
 }