Synchronize.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Synchronize.cpp 3140 2012-06-18 15:03:02Z susancummins $"
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00025 //
00026 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2008, 2011
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "Synchronize.hpp"
00032 
00033 
00034 namespace gpstk
00035 {
00036 
00037       // Returns a string identifying this object.
00038    std::string Synchronize::getClassName() const
00039    { return "Synchronize"; }
00040 
00041 
00042 
00043       /* Sets tolerance, in seconds.
00044        *
00045        * @param tol                 Tolerance, in seconds.
00046        */
00047    Synchronize& Synchronize::setTolerance(const double tol)
00048    {
00049 
00050          // Make sure that tolerance is positive
00051       if( tol >= 0.0 )
00052       {
00053          tolerance = tol;
00054       }
00055 
00056       return (*this);
00057 
00058    }  // End of method 'Synchronize::setTolerance()'
00059 
00060 
00061 
00062       /* Returns a gnnsRinex object, adding the new data generated
00063        * when calling this object.
00064        *
00065        * @param gData    Data object holding the data.
00066        */
00067    gnssRinex& Synchronize::Process(gnssRinex& gData)
00068       throw(SynchronizeException)
00069    {
00070       CommonTime time = dynamic_cast<gnssRinex*>(pgRov1)->header.epoch;
00071       Process(time,gData);
00072 
00073       return gData;
00074       
00075    }  // End of method 'Synchronize::Process()'
00076 
00077 
00078 
00079       /* Returns a gnnsSatTypeValue object, adding the new data
00080        * generated when calling this object.
00081        *
00082        * @param gData    Data object holding the data.
00083        */
00084    gnssSatTypeValue& Synchronize::Process(gnssSatTypeValue& gData)
00085       throw(SynchronizeException)
00086    {
00087       CommonTime time(pgRov1->header.epoch);
00088       
00089       gnssRinex gRin;
00090       Process(time,gRin);
00091       
00092       gData.header = gRin.header;
00093       gData.body = gRin.body;
00094 
00095       return gData;
00096 
00097    }  // End of method 'Synchronize::Process()'
00098 
00099 
00100    gnssRinex& Synchronize::Process(CommonTime time, gnssRinex& gData)
00101       throw(SynchronizeException)
00102    {
00103       
00104       if (firstTime)
00105       {
00106          (*pRinexRef) >> gData;      // Get data out of ref station RINEX file
00107 
00108          gnssRinexBuffer.clear();
00109          gnssRinexBuffer.push_back(gData);
00110 
00111          firstTime = false;          // Mark that first data batch was read
00112       }
00113 
00114       gData = gnssRinexBuffer.front();
00115 
00116       if( (gData.header.epoch > time) && 
00117          (std::abs( gData.header.epoch - time ) > tolerance ))
00118       {
00119          // If synchronization is not possible, we issue an exception
00120          SynchronizeException e( "Unable to synchronize data at epoch "
00121             + time.asString() );
00122          GPSTK_THROW(e);
00123       }
00124 
00125       // Check that the reference data time stamp is not less than gData's,
00126       // and that tolerance is within limits. If not, keep reading.
00127       // Note that if reference data time stamp is bigger, it will not
00128       // enter here, "waiting" for gData to catch up.
00129 
00130       while ( ( gData.header.epoch < time ) &&
00131          (std::abs( gData.header.epoch - time ) > tolerance ) )
00132       {
00133          (*pRinexRef) >> gData;   // Get data out of ref station RINEX file
00134       }
00135 
00136 
00137       // If we couldn't synchronize data streams (i.e.: "tolerance"
00138       // is not met), skip this epoch.
00139       if ( std::abs( gData.header.epoch - time ) > tolerance )
00140       {
00141          // If synchronization is not possible, we issue an exception
00142          SynchronizeException e( "Unable to synchronize data at epoch "
00143             + time.asString() );
00144          GPSTK_THROW(e);
00145       }
00146 
00147 
00148       return gData;
00149    }  // End of method 'Synchronize::Process(CommonTime time, gnssRinex& gData)'
00150 
00151 }  // End of namespace gpstk

Generated on Mon May 20 03:31:13 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1