1
0
Fork 0

New ATIS System: Fallback for no-realwx and some fixes

Added the fallback for realweather fetch disabled, creating
ATIS from present weather
Fixed some formatting errors, mainly missing spaces
Some code cleanup
This commit is contained in:
Torsten Dreyer 2014-03-01 12:44:01 +01:00
parent 5e080c1e37
commit 0c7f21a259
7 changed files with 216 additions and 30 deletions

View file

@ -407,14 +407,14 @@ string ATISEncoder::getCavok( SGPropertyNode_ptr )
string ATISEncoder::getVisibilityMetric( SGPropertyNode_ptr )
{
string m = globals->get_locale()->getLocalizedString("meters", "atc", "meters" );
string km = globals->get_locale()->getLocalizedString("kilometersmeters", "atc", "kilometersmeters" );
string km = globals->get_locale()->getLocalizedString("kilometers", "atc", "kilometers" );
string or_more = globals->get_locale()->getLocalizedString("ormore", "atc", "or more" );
int v = _atis->getVisibilityMeters();
string reply;
if( v < 5000 ) return reply.append( getSpokenAltitude( v ) ).SPACE.append( m );
if( v >= 10000 ) return reply.append( getSpokenNumber(10) ).SPACE.append( km ).SPACE.append(or_more);
return reply.append( getSpokenNumber( v/1000 ).append( km ) );
if( v >= 9999 ) return reply.append( getSpokenNumber(10) ).SPACE.append( km ).SPACE.append(or_more);
return reply.append( getSpokenNumber( v/1000 ).SPACE.append( km ) );
}
string ATISEncoder::getPhenomena( SGPropertyNode_ptr )
@ -461,7 +461,7 @@ string ATISEncoder::getInhg( SGPropertyNode_ptr )
string reply;
reply.append( getSpokenNumber( (int)intpart ) )
.append( DECIMAL ).SPACE
.SPACE.append( DECIMAL ).SPACE
.append( getSpokenNumber( fractpart ) );
return reply;
}

View file

@ -7,6 +7,7 @@ set(SOURCES
CommStation.cxx
ATISEncoder.cxx
MetarPropertiesATISInformationProvider.cxx
CurrentWeatherATISInformationProvider.cxx
)
set(HEADERS
@ -16,6 +17,7 @@ set(HEADERS
CommStation.hxx
ATISEncoder.hxx
MetarPropertiesATISInformationProvider.hxx
CurrentWeatherATISInformationProvider.hxx
)
flightgear_component(ATC "${SOURCES}" "${HEADERS}")

View file

@ -0,0 +1,138 @@
/*
Provide Data for the ATIS Encoder from metarproperties
Copyright (C) 2014 Torsten Dreyer
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "CurrentWeatherATISInformationProvider.hxx"
#include <Main/fg_props.hxx>
using std::string;
CurrentWeatherATISInformationProvider::CurrentWeatherATISInformationProvider( const std::string & airportId ) :
_airportId(airportId),
_environment(fgGetNode("/environment"))
{
}
static inline int roundToInt( double d )
{
return (static_cast<int>(10.0 * (d + .5))) / 10;
}
static inline int roundToInt( SGPropertyNode_ptr n )
{
return roundToInt( n->getDoubleValue() );
}
static inline int roundToInt( SGPropertyNode_ptr n, const char * child )
{
return roundToInt( n->getNode(child,true) );
}
CurrentWeatherATISInformationProvider::~CurrentWeatherATISInformationProvider()
{
}
bool CurrentWeatherATISInformationProvider::isValid()
{
return true;
}
string CurrentWeatherATISInformationProvider::airportId()
{
return _airportId;
}
long CurrentWeatherATISInformationProvider::getTime()
{
int h = fgGetInt( "/sim/time/utc/hour", 12 );
int m = 20 + fgGetInt( "/sim/time/utc/minute", 0 ) / 30 ; // fake twice per hour
return makeAtisTime( 0, h, m );
}
int CurrentWeatherATISInformationProvider::getWindDeg()
{
// round to 10 degs
int i = 5 + roundToInt( _environment->getNode("config/boundary/entry[0]/wind-from-heading-deg",true) );
i /= 10;
return i*10;
}
int CurrentWeatherATISInformationProvider::getWindSpeedKt()
{
return roundToInt( _environment, "config/boundary/entry[0]/wind-speed-kt" );
}
int CurrentWeatherATISInformationProvider::getGustsKt()
{
return 0;
}
int CurrentWeatherATISInformationProvider::getQnh()
{
return roundToInt( _environment->getNode("pressure-sea-level-inhg",true)->getDoubleValue() * SG_INHG_TO_PA / 100 );
}
bool CurrentWeatherATISInformationProvider::isCavok()
{
return false;
}
int CurrentWeatherATISInformationProvider::getVisibilityMeters()
{
return roundToInt( _environment, "ground-visibility-m" );
}
string CurrentWeatherATISInformationProvider::getPhenomena()
{
return "";
}
ATISInformationProvider::CloudEntries CurrentWeatherATISInformationProvider::getClouds()
{
using simgear::PropertyList;
ATISInformationProvider::CloudEntries cloudEntries;
PropertyList layers = _environment->getNode("clouds",true)->getChildren("layer");
for( PropertyList::iterator it = layers.begin(); it != layers.end(); ++it ) {
string coverage = (*it)->getStringValue( "coverage", "clear" );
int alt = roundToInt( (*it)->getDoubleValue("elevation-ft", -9999 ) ) / 100;
alt *= 100;
if( coverage != "clear" && alt > 0 )
cloudEntries[alt] = coverage;
}
return cloudEntries;
}
int CurrentWeatherATISInformationProvider::getTemperatureDeg()
{
return roundToInt( _environment, "temperature-sea-level-degc" );
}
int CurrentWeatherATISInformationProvider::getDewpointDeg()
{
return roundToInt( _environment, "dewpoint-sea-level-degc" );
}
string CurrentWeatherATISInformationProvider::getTrend()
{
return "nosig";
}

View file

@ -0,0 +1,55 @@
/*
Provide Data for the ATIS Encoder from metarproperties
Copyright (C) 2014 Torsten Dreyer
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __CURRENTWEATHER_ATIS_ENCODER_HXX
#define __CURRENTWEATHER_ATIS_ENCODER_HXX
/* ATIS encoder from current weather */
#include <string>
#include "ATISEncoder.hxx"
class CurrentWeatherATISInformationProvider : public ATISInformationProvider
{
public:
CurrentWeatherATISInformationProvider( const std::string & airportId );
virtual ~CurrentWeatherATISInformationProvider();
protected:
virtual bool isValid();
virtual std::string airportId();
virtual long getTime();
virtual int getWindDeg();
virtual int getWindSpeedKt();
virtual int getGustsKt();
virtual int getQnh();
virtual bool isCavok();
virtual int getVisibilityMeters();
virtual std::string getPhenomena();
virtual CloudEntries getClouds();
virtual int getTemperatureDeg();
virtual int getDewpointDeg();
virtual std::string getTrend();
private:
std::string _airportId;
SGPropertyNode_ptr _environment;
};
#endif

View file

@ -23,8 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
using std::string;
static string EMPTY("");
static string CAVOK("cavok");
MetarPropertiesATISInformationProvider::MetarPropertiesATISInformationProvider( SGPropertyNode_ptr metar ) :
_metar( metar )
{

View file

@ -48,26 +48,6 @@ protected:
virtual int getTemperatureDeg();
virtual int getDewpointDeg();
virtual std::string getTrend();
#if 0
virtual std::string getStationId();
virtual std::string getAtisId();
virtual std::string getTime();
virtual std::string getApproachType();
virtual std::string getLandingRunway();
virtual std::string getTakeoffRunway();
virtual std::string getTransitionLevel();
virtual std::string getWindDirection();
virtual std::string getWindspeedKnots();
virtual std::string getGustsKnots();
virtual std::string getVisibilityMetric();
virtual std::string getPhenomena();
virtual std::string getClouds();
virtual std::string getCavok();
virtual std::string getTemperatureDeg();
virtual std::string getDewpointDeg();
virtual std::string getQnh();
virtual std::string getTrend();
#endif
private:
SGPropertyNode_ptr _metar;
};

View file

@ -34,6 +34,7 @@
#include <ATC/CommStation.hxx>
#include <ATC/MetarPropertiesATISInformationProvider.hxx>
#include <ATC/CurrentWeatherATISInformationProvider.hxx>
#include <Airports/airport.hxx>
#include <Main/fg_props.hxx>
#include <Navaids/navlist.hxx>
@ -169,6 +170,7 @@ protected:
private:
std::string _requestedId;
SGPropertyNode_ptr _realWxEnabledNode;
SGPropertyNode_ptr _metarPropertiesNode;
SGPropertyNode * _atisNode;
ATISEncoder _atisEncoder;
@ -186,6 +188,7 @@ MetarBridge::~MetarBridge()
void MetarBridge::bind()
{
_realWxEnabledNode = fgGetNode( "/environment/realwx/enabled", true );
_metarPropertiesNode->getNode( "valid", true )->addChangeListener( this );
}
@ -199,9 +202,19 @@ void MetarBridge::requestMetarForId( std::string & id )
std::string uppercaseId = simgear::strutils::uppercase( id );
if( _requestedId == uppercaseId ) return;
_requestedId = uppercaseId;
_metarPropertiesNode->getNode( "station-id", true )->setStringValue( uppercaseId );
_metarPropertiesNode->getNode( "valid", true )->setBoolValue( false );
_metarPropertiesNode->getNode( "time-to-live", true )->setDoubleValue( 0.0 );
if( _realWxEnabledNode->getBoolValue() ) {
// trigger a METAR request for the associated metarproperties
_metarPropertiesNode->getNode( "station-id", true )->setStringValue( uppercaseId );
_metarPropertiesNode->getNode( "valid", true )->setBoolValue( false );
_metarPropertiesNode->getNode( "time-to-live", true )->setDoubleValue( 0.0 );
} else {
// use the present weather to generate the ATIS.
if( NULL != _atisNode && false == _requestedId.empty() ) {
CurrentWeatherATISInformationProvider provider( _requestedId );
_atisNode->setStringValue( _atisEncoder.encodeATIS( &provider ) );
}
}
}
void MetarBridge::clearMetar()
@ -213,7 +226,7 @@ void MetarBridge::clearMetar()
void MetarBridge::valueChanged(SGPropertyNode * node )
{
// check for raising edge of valid flag
if( NULL == node || false == node->getBoolValue() )
if( NULL == node || false == node->getBoolValue() || false == _realWxEnabledNode->getBoolValue() )
return;
std::string responseId = simgear::strutils::uppercase(