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
|
|
|
|
#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
|
|
|
|
SG_USING_STD(cout);
|
|
|
|
#endif
|
2001-11-07 17:55:04 +00:00
|
|
|
|
|
|
|
//#include <simgear/debug/logstream.hxx>
|
|
|
|
//#include <simgear/misc/sgstream.hxx>
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
|
2002-05-12 00:12:19 +00:00
|
|
|
#ifdef FG_WEATHERCM
|
|
|
|
# include <WeatherCM/FGLocalWeatherDatabase.h>
|
|
|
|
#else
|
2002-05-11 23:22:24 +00:00
|
|
|
# include <Environment/environment_mgr.hxx>
|
|
|
|
# include <Environment/environment.hxx>
|
|
|
|
#endif
|
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"
|
2001-11-19 23:53:36 +00:00
|
|
|
#include "atislist.hxx"
|
2002-03-01 17:39:52 +00:00
|
|
|
#include "ATCdisplay.hxx"
|
2002-10-02 15:27:49 +00:00
|
|
|
#include "ATCutils.hxx"
|
2001-11-07 17:55:04 +00:00
|
|
|
|
|
|
|
// Constructor
|
2002-03-30 12:50:30 +00:00
|
|
|
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)
|
|
|
|
{
|
2001-11-07 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
FGATIS::~FGATIS() {
|
|
|
|
}
|
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
// 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);
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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() {
|
2001-11-07 17:55:04 +00:00
|
|
|
double visibility;
|
|
|
|
char buf[10];
|
2001-11-19 23:53:36 +00:00
|
|
|
int phonetic_id;
|
|
|
|
string phonetic_id_string;
|
|
|
|
string time_str = fgGetString("sim/time/gmt-string");
|
|
|
|
int hours;
|
2002-02-01 23:13:48 +00:00
|
|
|
// int minutes;
|
2002-05-11 23:22:24 +00:00
|
|
|
|
2002-05-12 00:12:19 +00:00
|
|
|
#ifdef FG_WEATHERCM
|
2002-02-01 23:13:48 +00:00
|
|
|
sgVec3 position = { lat, lon, elev };
|
|
|
|
FGPhysicalProperty stationweather = WeatherDatabase->get(position);
|
2002-05-12 00:12:19 +00:00
|
|
|
#else
|
|
|
|
FGEnvironment stationweather =
|
|
|
|
globals->get_environment_mgr()->getEnvironment(lat, lon, elev);
|
2002-05-11 23:22:24 +00:00
|
|
|
#endif
|
2001-11-07 17:55:04 +00:00
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
transmission = "";
|
2001-11-07 17:55:04 +00:00
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
// Start with the transmitted station name.
|
|
|
|
transmission += name;
|
|
|
|
// Add "Information"
|
|
|
|
transmission += " Information";
|
2001-11-07 17:55:04 +00:00
|
|
|
|
2002-03-01 17:39:52 +00:00
|
|
|
//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");
|
2002-05-12 00:12:19 +00:00
|
|
|
#ifdef FG_WEATHERCM
|
2002-03-01 17:39:52 +00:00
|
|
|
sprintf(buf, "%i", int(stationweather.Temperature - 273.15));
|
2002-05-12 00:12:19 +00:00
|
|
|
#else
|
2002-07-26 02:48:56 +00:00
|
|
|
sprintf(buf, "%d", int(stationweather.get_temperature_degc()));
|
2002-05-11 23:22:24 +00:00
|
|
|
#endif
|
2002-03-01 17:39:52 +00:00
|
|
|
transmission += " Temperature ";
|
|
|
|
transmission += buf;
|
|
|
|
transmission += " degrees Celsius";
|
2001-11-07 17:55:04 +00:00
|
|
|
|
|
|
|
// Get the visibility
|
2002-05-12 00:12:19 +00:00
|
|
|
#ifdef FG_WEATHERCM
|
2001-11-07 17:55:04 +00:00
|
|
|
visibility = fgGetDouble("/environment/visibility-m");
|
2002-05-12 00:12:19 +00:00
|
|
|
#else
|
|
|
|
visibility = stationweather.get_visibility_m();
|
2002-05-11 23:22:24 +00:00
|
|
|
#endif
|
2001-11-19 23:53:36 +00:00
|
|
|
sprintf(buf, "%i", int(visibility/1600));
|
2001-11-07 17:55:04 +00:00
|
|
|
transmission += " Visibility ";
|
|
|
|
transmission += buf;
|
|
|
|
transmission += " miles";
|
|
|
|
|
|
|
|
// 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-05-17 19:02:43 +00:00
|
|
|
double cloudbase =
|
|
|
|
fgGetDouble("/environment/clouds/layer[0]/elevation-ft");
|
2001-11-07 17:55:04 +00:00
|
|
|
// For some reason the altitude returned doesn't seem to correspond to the actual cloud altitude.
|
|
|
|
char buf3[10];
|
2002-02-13 18:17:04 +00:00
|
|
|
// cout << "cloudbase = " << cloudbase << endl;
|
2001-11-07 17:55:04 +00:00
|
|
|
sprintf(buf3, "%i", int(cloudbase));
|
|
|
|
transmission = transmission + " Cloudbase " + buf3 + " feet";
|
|
|
|
}
|
|
|
|
|
2002-07-26 02:48:56 +00:00
|
|
|
// Get the pressure / altimeter
|
|
|
|
|
|
|
|
#ifndef FG_WEATHERCM
|
|
|
|
double altimeter = stationweather.get_pressure_sea_level_inhg();
|
|
|
|
sprintf(buf, "%.2f", altimeter);
|
|
|
|
transmission += " Altimeter ";
|
|
|
|
transmission += buf;
|
|
|
|
#endif
|
|
|
|
|
2001-11-07 17:55:04 +00:00
|
|
|
// 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() );
|
|
|
|
|
2002-05-12 00:12:19 +00:00
|
|
|
#ifdef FG_WEATHERCM
|
2001-11-07 17:55:04 +00:00
|
|
|
//Set the heading to into the wind
|
2002-02-01 23:13:48 +00:00
|
|
|
double wind_x = stationweather.Wind[0];
|
|
|
|
double wind_y = stationweather.Wind[1];
|
2001-11-07 17:55:04 +00:00
|
|
|
|
2002-02-01 23:13:48 +00:00
|
|
|
double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
|
|
|
|
double hdg;
|
2001-11-07 17:55:04 +00:00
|
|
|
|
|
|
|
//If no wind use 270degrees
|
|
|
|
if(speed == 0) {
|
|
|
|
hdg = 270;
|
|
|
|
transmission += " Winds light and variable";
|
|
|
|
} else {
|
2002-02-01 23:13:48 +00:00
|
|
|
// //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;
|
|
|
|
|
2001-11-07 17:55:04 +00:00
|
|
|
//add a description of the wind to the transmission
|
2001-11-19 23:53:36 +00:00
|
|
|
char buf2[72];
|
2001-11-07 17:55:04 +00:00
|
|
|
sprintf(buf2, "%s %i %s %i %s", " Winds ", int(speed), " knots from ", int(hdg), " degrees");
|
|
|
|
transmission += buf2;
|
|
|
|
}
|
2002-05-12 00:12:19 +00:00
|
|
|
#else
|
|
|
|
double speed = stationweather.get_wind_speed_kt();
|
|
|
|
double hdg = stationweather.get_wind_from_heading_deg();
|
|
|
|
if (speed == 0) {
|
|
|
|
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");
|
2002-07-26 02:48:56 +00:00
|
|
|
transmission += buf2;
|
2002-05-12 00:12:19 +00:00
|
|
|
}
|
2002-05-11 23:22:24 +00:00
|
|
|
#endif
|
2001-11-07 17:55:04 +00:00
|
|
|
|
2002-02-13 23:57:31 +00:00
|
|
|
string rwy_no = runways.search(ident, int(hdg));
|
2001-12-17 17:41:02 +00:00
|
|
|
if(rwy_no != (string)"NN") {
|
2001-11-07 17:55:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Anything else?
|
|
|
|
|
2001-11-19 23:53:36 +00:00
|
|
|
transmission += " Advise controller on initial contact you have ";
|
|
|
|
transmission += phonetic_id_string;
|
|
|
|
}
|