Synchronize.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Synchronize.cpp 2584 2011-05-04 01:58:57Z yanweignss $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2008
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "Synchronize.hpp"
00032 
00033 
00034 namespace gpstk
00035 {
00036 
00037       // Index initially assigned to this class
00038    int Synchronize::classIndex = 8100000;
00039 
00040 
00041       // Returns an index identifying this object.
00042    int Synchronize::getIndex(void) const
00043    { return index; }
00044 
00045 
00046       // Returns a string identifying this object.
00047    std::string Synchronize::getClassName() const
00048    { return "Synchronize"; }
00049 
00050 
00051 
00052       /* Sets tolerance, in seconds.
00053        *
00054        * @param tol                 Tolerance, in seconds.
00055        */
00056    Synchronize& Synchronize::setTolerance(const double tol)
00057    {
00058 
00059          // Make sure that tolerance is positive
00060       if( tol >= 0.0 )
00061       {
00062          tolerance = tol;
00063       }
00064 
00065       return (*this);
00066 
00067    }  // End of method 'Synchronize::setTolerance()'
00068 
00069 
00070 
00071       /* Returns a gnnsRinex object, adding the new data generated
00072        * when calling this object.
00073        *
00074        * @param gData    Data object holding the data.
00075        */
00076    gnssRinex& Synchronize::Process(gnssRinex& gData)
00077       throw(SynchronizeException)
00078    {
00079       DayTime time = dynamic_cast<gnssRinex*>(pgRov1)->header.epoch;
00080       Process(time,gData);
00081 
00082       return gData;
00083       
00084    }  // End of method 'Synchronize::Process()'
00085 
00086 
00087 
00088       /* Returns a gnnsSatTypeValue object, adding the new data
00089        * generated when calling this object.
00090        *
00091        * @param gData    Data object holding the data.
00092        */
00093    gnssSatTypeValue& Synchronize::Process(gnssSatTypeValue& gData)
00094       throw(SynchronizeException)
00095    {
00096       DayTime time(pgRov1->header.epoch);
00097       
00098       gnssRinex gRin;
00099       Process(time,gRin);
00100       
00101       gData.header = gRin.header;
00102       gData.body = gRin.body;
00103 
00104       return gData;
00105 
00106    }  // End of method 'Synchronize::Process()'
00107 
00108 
00109    gnssRinex& Synchronize::Process(DayTime time, gnssRinex& gData)
00110       throw(SynchronizeException)
00111    {
00112       
00113       if (firstTime)
00114       {
00115          (*pRinexRef) >> gData;      // Get data out of ref station RINEX file
00116 
00117          gnssRinexBuffer.clear();
00118          gnssRinexBuffer.push_back(gData);
00119 
00120          firstTime = false;          // Mark that first data batch was read
00121       }
00122 
00123       gData = gnssRinexBuffer.front();
00124 
00125       if( (gData.header.epoch > time) && 
00126          (std::abs( gData.header.epoch - time ) > tolerance ))
00127       {
00128          // If synchronization is not possible, we issue an exception
00129          SynchronizeException e( "Unable to synchronize data at epoch "
00130             + time.asString() );
00131          GPSTK_THROW(e);
00132       }
00133 
00134       // Check that the reference data time stamp is not less than gData's,
00135       // and that tolerance is within limits. If not, keep reading.
00136       // Note that if reference data time stamp is bigger, it will not
00137       // enter here, "waiting" for gData to catch up.
00138 
00139       while ( ( gData.header.epoch < time ) &&
00140          (std::abs( gData.header.epoch - time ) > tolerance ) )
00141       {
00142          (*pRinexRef) >> gData;   // Get data out of ref station RINEX file
00143       }
00144 
00145 
00146       // If we couldn't synchronize data streams (i.e.: "tolerance"
00147       // is not met), skip this epoch.
00148       if ( std::abs( gData.header.epoch - time ) > tolerance )
00149       {
00150          // If synchronization is not possible, we issue an exception
00151          SynchronizeException e( "Unable to synchronize data at epoch "
00152             + time.asString() );
00153          GPSTK_THROW(e);
00154       }
00155 
00156 
00157       return gData;
00158    }
00159 
00160 
00161 }  // End of namespace gpstk

Generated on Tue May 22 03:31:02 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1