2001-11-07 17:55:04 +00:00
|
|
|
// atis.cxx - routines to generate the ATIS info string
|
2002-03-01 17:39:52 +00:00
|
|
|
// This is the implementation of the FGATIS class
|
2001-11-07 17:55:04 +00:00
|
|
|
//
|
|
|
|
// Written by David Luff, started October 2001.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001 David C Luff - david.luff@nottingham.ac.uk
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
2001-11-19 23:53:36 +00:00
|
|
|
#include <stdlib.h> // atoi()
|
2002-02-05 15:57:46 +00:00
|
|
|
#include <stdio.h> // sprintf
|
2001-11-07 17:55:04 +00:00
|
|
|
#include <string>
|
|
|
|
SG_USING_STD(string);
|
|
|
|
|
2001-11-19 23:53:36 +00:00
|
|
|
#include STL_IOSTREAM
|
|
|
|
SG_USING_STD(cout);
|
2001-11-07 17:55:04 +00:00
|
|
|
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
|
2004-03-16 20:19:07 +00:00
|
|
|
#include <Environment/environment_mgr.hxx>
|
|
|
|
#include <Environment/environment.hxx>
|
2001-11-07 17:55:04 +00:00
|
|
|
|
|
|
|
#include <Main/fg_props.hxx>
|
2002-03-01 17:39:52 +00:00
|
|
|
#include <Main/globals.hxx>
|
2001-11-07 17:55:04 +00:00
|
|
|
#include <Airports/runways.hxx>
|
|
|
|
|
|
|
|
#include "atis.hxx"
|
2003-02-06 10:42:43 +00:00
|
|
|
#include "commlist.hxx"
|
2002-03-01 17:39:52 +00:00
|
|
|
#include "ATCdisplay.hxx"
|
2002-10-02 15:27:49 +00:00
|
|
|
#include "ATCutils.hxx"
|
2002-12-04 19:51:21 +00:00
|
|
|
#include "ATCmgr.hxx"
|
2001-11-07 17:55:04 +00:00
|
|
|
|
2003-02-06 10:42:43 +00:00
|
|
|
FGATIS::FGATIS() :
|
2003-10-06 15:19:42 +00:00
|
|
|
transmission(""),
|
|
|
|
trans_ident(""),
|
|
|
|
atis_failed(false),
|
|
|
|
refname("atis")
|
|
|
|
//type(ATIS)
|
2002-03-30 12:50:30 +00:00
|
|
|
{
|
2003-02-18 10:44:01 +00:00
|
|
|
vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS);
|
|
|
|
voiceOK = (vPtr == NULL ? false : true);
|
2004-01-23 17:18:24 +00:00
|
|
|
_type = ATIS;
|
2001-11-07 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGATIS::~FGATIS() {
|
|
|
|
}
|
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
// Main update function - checks whether we are displaying or not the correct message.
|
2003-03-27 15:44:35 +00:00
|
|
|
void FGATIS::Update(double dt) {
|
2004-03-10 16:01:17 +00:00
|
|
|
if(_display) {
|
|
|
|
if(_displaying) {
|
2002-12-04 19:51:21 +00:00
|
|
|
// 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;
|
2003-02-18 10:44:01 +00:00
|
|
|
Render(transmission, refname, true);
|
2004-03-10 16:01:17 +00:00
|
|
|
_displaying = true;
|
2002-12-04 19:51:21 +00:00
|
|
|
}
|
2002-03-01 17:39:52 +00:00
|
|
|
} else {
|
2002-12-04 19:51:21 +00:00
|
|
|
// We shouldn't be displaying
|
2004-03-10 16:01:17 +00:00
|
|
|
if(_displaying) {
|
2002-12-04 19:51:21 +00:00
|
|
|
//cout << "ATIS.CXX - calling NoRender()..." << endl;
|
2003-02-18 10:44:01 +00:00
|
|
|
NoRender(refname);
|
2004-03-10 16:01:17 +00:00
|
|
|
_displaying = false;
|
2002-12-04 19:51:21 +00:00
|
|
|
}
|
2002-03-01 17:39:52 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-07 17:55:04 +00:00
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
// Sets the actual broadcast ATIS transmission.
|
|
|
|
void FGATIS::UpdateTransmission() {
|
2002-12-04 19:51:21 +00:00
|
|
|
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 =
|
2003-06-08 14:47:03 +00:00
|
|
|
((FGEnvironmentMgr *)globals->get_subsystem("environment"))
|
|
|
|
->getEnvironment(lat, lon, elev);
|
2002-12-04 19:51:21 +00:00
|
|
|
|
|
|
|
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;
|
2003-02-06 10:42:43 +00:00
|
|
|
phonetic_id = current_commlist->GetCallSign(ident, hours, 0);
|
2002-12-04 19:51:21 +00:00
|
|
|
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
|
2003-01-13 19:03:36 +00:00
|
|
|
int temp;
|
|
|
|
temp = (int)stationweather.get_temperature_degc();
|
|
|
|
|
2002-12-04 19:51:21 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2003-01-13 19:03:36 +00:00
|
|
|
|
|
|
|
sprintf(buf, "%i", abs(temp));
|
2002-12-04 19:51:21 +00:00
|
|
|
transmission += " / Temperature ";
|
|
|
|
if(temp < 0) {
|
|
|
|
transmission += "minus ";
|
|
|
|
}
|
|
|
|
string tempstr1 = buf;
|
|
|
|
string tempstr2;
|
|
|
|
transmission += ConvertNumToSpokenDigits(tempstr1);
|
|
|
|
transmission += " degrees_Celsius";
|
|
|
|
|
2001-11-07 17:55:04 +00:00
|
|
|
// Get the visibility
|
2002-12-04 19:51:21 +00:00
|
|
|
visibility = stationweather.get_visibility_m();
|
2001-11-19 23:53:36 +00:00
|
|
|
sprintf(buf, "%i", int(visibility/1600));
|
2002-12-04 19:51:21 +00:00
|
|
|
transmission += " / Visibility ";
|
|
|
|
tempstr1 = buf;
|
|
|
|
transmission += ConvertNumToSpokenDigits(tempstr1);
|
2001-11-07 17:55:04 +00:00
|
|
|
transmission += " miles";
|
2002-12-04 19:51:21 +00:00
|
|
|
|
2001-11-07 17:55:04 +00:00
|
|
|
// Get the cloudbase
|
2002-05-17 19:02:43 +00:00
|
|
|
// FIXME: kludge for now
|
2002-07-26 02:48:56 +00:00
|
|
|
if (strcmp(fgGetString("/environment/clouds/layer[0]/type"), "clear")) {
|
2002-12-04 19:51:21 +00:00
|
|
|
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";
|
2001-11-07 17:55:04 +00:00
|
|
|
}
|
2002-12-04 19:51:21 +00:00
|
|
|
|
2002-07-26 02:48:56 +00:00
|
|
|
// Get the pressure / altimeter
|
2004-03-23 23:36:27 +00:00
|
|
|
double P = fgGetDouble("/environment/pressure-sea-level-inhg");
|
|
|
|
if(ident.substr(0,2) == "EG") {
|
|
|
|
// Convert to millibars for the UK!
|
|
|
|
P *= 33.864;
|
|
|
|
sprintf(buf, "%.1f", P);
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "%.2f", P);
|
|
|
|
}
|
2004-03-23 23:25:37 +00:00
|
|
|
transmission += " / Altimeter ";
|
|
|
|
tempstr1 = buf;
|
|
|
|
transmission += ConvertNumToSpokenDigits(tempstr1);
|
2002-12-04 19:51:21 +00:00
|
|
|
|
2001-11-07 17:55:04 +00:00
|
|
|
// Based on the airport-id and wind get the active runway
|
|
|
|
//FGRunway *r;
|
2002-05-12 00:12:19 +00:00
|
|
|
double speed = stationweather.get_wind_speed_kt();
|
|
|
|
double hdg = stationweather.get_wind_from_heading_deg();
|
|
|
|
if (speed == 0) {
|
2003-03-05 21:40:24 +00:00
|
|
|
hdg = 270; // This forces West-facing rwys to be used in no-wind situations
|
|
|
|
// which is consistent with Flightgear's initial setup.
|
2002-12-04 19:51:21 +00:00
|
|
|
transmission += " / Winds_light_and_variable";
|
2002-05-12 00:12:19 +00:00
|
|
|
} else {
|
2002-12-04 19:51:21 +00:00
|
|
|
// 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";
|
2002-05-12 00:12:19 +00:00
|
|
|
}
|
2002-12-04 19:51:21 +00:00
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
string rwy_no = globals->get_runways()->search(ident, int(hdg));
|
2003-10-16 14:14:03 +00:00
|
|
|
if(rwy_no != "NN") {
|
2002-12-04 19:51:21 +00:00
|
|
|
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;
|
2001-11-07 17:55:04 +00:00
|
|
|
}
|
2002-12-04 19:51:21 +00:00
|
|
|
|
2001-11-07 17:55:04 +00:00
|
|
|
// Anything else?
|
2002-12-04 19:51:21 +00:00
|
|
|
|
|
|
|
transmission += " / Advise_controller_on_initial_contact_you_have ";
|
2001-11-19 23:53:36 +00:00
|
|
|
transmission += phonetic_id_string;
|
2002-12-04 19:51:21 +00:00
|
|
|
transmission += " /// ";
|
2001-11-19 23:53:36 +00:00
|
|
|
}
|