]> git.mxchange.org Git - flightgear.git/commitdiff
New ATIS System: Fallback for no-realwx and some fixes
authorTorsten Dreyer <torsten@t3r.de>
Sat, 1 Mar 2014 11:44:01 +0000 (12:44 +0100)
committerTorsten Dreyer <torsten@t3r.de>
Sat, 1 Mar 2014 11:44:01 +0000 (12:44 +0100)
Added the fallback for realweather fetch disabled, creating
ATIS from present weather
Fixed some formatting errors, mainly missing spaces
Some code cleanup

src/ATC/ATISEncoder.cxx
src/ATC/CMakeLists.txt
src/ATC/CurrentWeatherATISInformationProvider.cxx [new file with mode: 0644]
src/ATC/CurrentWeatherATISInformationProvider.hxx [new file with mode: 0644]
src/ATC/MetarPropertiesATISInformationProvider.cxx
src/ATC/MetarPropertiesATISInformationProvider.hxx
src/Instrumentation/commradio.cxx

index 5edc4b2322f28c4ff7784a35efcd5dbe521dade7..debc002d4fd925d62913c19cfbff333e49e2c917 100644 (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;
 }
index 35b48884a82e0f58ec896e2216e64ec53c4354de..b3795c951abfd064cfb1d51e430269746744e077 100644 (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}")
diff --git a/src/ATC/CurrentWeatherATISInformationProvider.cxx b/src/ATC/CurrentWeatherATISInformationProvider.cxx
new file mode 100644 (file)
index 0000000..b2c0ca6
--- /dev/null
@@ -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";
+}
+
diff --git a/src/ATC/CurrentWeatherATISInformationProvider.hxx b/src/ATC/CurrentWeatherATISInformationProvider.hxx
new file mode 100644 (file)
index 0000000..f3d7fdb
--- /dev/null
@@ -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
index 4a68792fa305f95a4bc4e2741a612cc19bcbaf12..d32033a53ce1424b0b84501ac6ea8e958d9398f2 100644 (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 )
 {
index 95b2b4deb71d2a71aa0dd8298d9a3861f74637ea..2df6e626330f971cb3b5705593e6df8c87bdcc80 100644 (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;
 };
index ae631cd8bc88ca2125e50be77d8ce5ad142e7487..de9c9f035e8f3f286a4f248d1934b1628041bb30 100644 (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(