From: Torsten Dreyer Date: Sat, 1 Mar 2014 11:44:01 +0000 (+0100) Subject: New ATIS System: Fallback for no-realwx and some fixes X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0c7f21a2592d1b502ad8e85033a68d3f211b6f78;p=flightgear.git 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 --- diff --git a/src/ATC/ATISEncoder.cxx b/src/ATC/ATISEncoder.cxx index 5edc4b232..debc002d4 100644 --- a/src/ATC/ATISEncoder.cxx +++ b/src/ATC/ATISEncoder.cxx @@ -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; } diff --git a/src/ATC/CMakeLists.txt b/src/ATC/CMakeLists.txt index 35b48884a..b3795c951 100644 --- a/src/ATC/CMakeLists.txt +++ b/src/ATC/CMakeLists.txt @@ -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}") diff --git a/src/ATC/CurrentWeatherATISInformationProvider.cxx b/src/ATC/CurrentWeatherATISInformationProvider.cxx new file mode 100644 index 000000000..b2c0ca629 --- /dev/null +++ b/src/ATC/CurrentWeatherATISInformationProvider.cxx @@ -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
+ +using std::string; + +CurrentWeatherATISInformationProvider::CurrentWeatherATISInformationProvider( const std::string & airportId ) : + _airportId(airportId), + _environment(fgGetNode("/environment")) +{ +} + +static inline int roundToInt( double d ) +{ + return (static_cast(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"; +} + diff --git a/src/ATC/CurrentWeatherATISInformationProvider.hxx b/src/ATC/CurrentWeatherATISInformationProvider.hxx new file mode 100644 index 000000000..f3d7fdbb9 --- /dev/null +++ b/src/ATC/CurrentWeatherATISInformationProvider.hxx @@ -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 +#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 diff --git a/src/ATC/MetarPropertiesATISInformationProvider.cxx b/src/ATC/MetarPropertiesATISInformationProvider.cxx index 4a68792fa..d32033a53 100644 --- a/src/ATC/MetarPropertiesATISInformationProvider.cxx +++ b/src/ATC/MetarPropertiesATISInformationProvider.cxx @@ -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 ) { diff --git a/src/ATC/MetarPropertiesATISInformationProvider.hxx b/src/ATC/MetarPropertiesATISInformationProvider.hxx index 95b2b4deb..2df6e6263 100644 --- a/src/ATC/MetarPropertiesATISInformationProvider.hxx +++ b/src/ATC/MetarPropertiesATISInformationProvider.hxx @@ -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; }; diff --git a/src/Instrumentation/commradio.cxx b/src/Instrumentation/commradio.cxx index ae631cd8b..de9c9f035 100644 --- a/src/Instrumentation/commradio.cxx +++ b/src/Instrumentation/commradio.cxx @@ -34,6 +34,7 @@ #include #include +#include #include #include
#include @@ -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(