GPSAlmanacStore.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: GPSAlmanacStore.cpp 3184 2012-07-01 13:11:07Z yanweignss $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00020 //  
00021 //  Copyright 2004, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 //============================================================================
00025 //
00026 //This software developed by Applied Research Laboratories at the University of
00027 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00028 //Department of Defense. The U.S. Government retains all rights to use,
00029 //duplicate, distribute, disclose, or release this software. 
00030 //
00031 //Pursuant to DoD Directive 523024 
00032 //
00033 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00034 //                           release, distribution is unlimited.
00035 //
00036 //=============================================================================
00037 
00045 #include "GPSAlmanacStore.hpp"
00046 #include "StringUtils.hpp"
00047 #include "gps_constants.hpp"
00048 #include "CommonTime.hpp"
00049 
00050 namespace gpstk
00051 {
00052    Xvt GPSAlmanacStore::getXvt(const SatID& sat, const CommonTime& t)
00053       const throw(InvalidRequest)
00054    {
00055       AlmOrbit a = findAlmanac(sat, t);
00056       return a.svXvt(t);
00057    }
00058 
00059    Xvt GPSAlmanacStore::getXvtMostRecentXmit(const SatID sat, const CommonTime& t) 
00060          const throw(InvalidRequest)
00061    {
00062       AlmOrbit a = findMostRecentAlmanac(sat, t);
00063       return a.svXvt(t);
00064    }
00065    
00066    short GPSAlmanacStore::getSatHealth(const SatID sat, const CommonTime& t)
00067       const throw(InvalidRequest)
00068    {
00069       AlmOrbit a = findAlmanac(sat, t);
00070       return a.getSVHealth();
00071    }
00072 
00073    bool GPSAlmanacStore::addAlmanac(const AlmOrbit& alm) throw()
00074    {
00075       if ((alm.getPRNID() >= 1) && (alm.getPRNID() <= MAX_PRN_GPS))
00076       {
00077          SatID sat(alm.getPRNID(),SatID::systemGPS);
00078          CommonTime toa = alm.getToaTime();
00079          uba[sat][toa] = alm;
00080          CommonTime tmin(toa - gpstk::HALFWEEK);
00081          CommonTime tmax(toa + gpstk::HALFWEEK);
00082          if (tmin < initialTime)
00083             initialTime = tmin;
00084          if (tmax > finalTime)
00085             finalTime = tmax;
00086          return true;
00087       }
00088       return false;
00089    }
00090 
00091    bool GPSAlmanacStore::addAlmanac(const EngAlmanac& alm) throw()
00092    {
00093       AlmOrbits ao = alm.getAlmOrbElems();
00094       AlmOrbits::const_iterator oci;
00095       for (oci = ao.begin(); oci != ao.end(); oci++)
00096          addAlmanac((*oci).second);
00097 
00098       return true;
00099    }
00100 
00103    AlmOrbit GPSAlmanacStore::findAlmanac(const SatID sat, const CommonTime& t) 
00104       const throw(InvalidRequest)
00105    {
00106       UBAMap::const_iterator satItr = uba.find(sat);
00107       if (satItr == uba.end())
00108       {
00109          InvalidRequest e("No almanacs for satellite " +
00110                         StringUtils::asString(sat));
00111          GPSTK_THROW(e);
00112       }
00113          
00114       const EngAlmMap& eam = satItr->second;
00115 
00116       // find the closest almanac BEFORE t, if any.
00117       EngAlmMap::const_iterator neXvtItr = eam.begin(), almItr = eam.end();
00118          
00119       while ( (neXvtItr != eam.end()) &&
00120               (neXvtItr->first < t) )
00121       {
00122          almItr = neXvtItr;
00123          neXvtItr++;
00124       }
00125 
00126       if (almItr == eam.end())
00127       {
00128          if (neXvtItr == eam.end()) 
00129          {
00130             InvalidRequest e("No almanacs for time " + t.asString());
00131             GPSTK_THROW(e);
00132          }
00133          else
00134          {
00135             almItr = neXvtItr;
00136          }
00137       }
00138 
00139       // check the neXvt almanac (the first one after t's time)
00140       // to see if it's closer than the one before t
00141       if (neXvtItr != eam.end())
00142       {
00143          if ( (neXvtItr->first - t) < (t - almItr->first))
00144             almItr = neXvtItr;
00145       }
00146       return (*almItr).second;
00147    }
00148 
00149    AlmOrbit GPSAlmanacStore::findMostRecentAlmanac(const SatID sat, const CommonTime& t) 
00150          const throw(InvalidRequest)
00151    {
00152       UBAMap::const_iterator satItr = uba.find(sat);
00153       if (satItr == uba.end())
00154       {
00155          InvalidRequest e("No almanacs for satellite " +
00156                         StringUtils::asString(sat));
00157          GPSTK_THROW(e);
00158       }
00159          
00160       const EngAlmMap& eam = satItr->second;
00161 
00162       // find the closest almanac BEFORE t, if any.
00163       EngAlmMap::const_iterator neXvtItr = eam.begin(), almItr = eam.end();
00164          
00165       while ( (neXvtItr != eam.end()) &&
00166               (neXvtItr->second.getTransmitTime() < t) )
00167       {
00168          almItr = neXvtItr;
00169          neXvtItr++;
00170       }
00171 
00172       if (almItr == eam.end())
00173       {
00174          if (neXvtItr == eam.end()) 
00175          {
00176             InvalidRequest e("No almanacs for time " + t.asString());
00177             GPSTK_THROW(e);
00178          }
00179          else
00180          {
00181             almItr = neXvtItr;
00182          }
00183       }
00184       return (*almItr).second;     
00185    }
00186 
00187    AlmOrbits GPSAlmanacStore::findAlmanacs(const CommonTime& t) 
00188       const throw(InvalidRequest)
00189    {
00190       AlmOrbits ao;
00191       UBAMap::const_iterator satItr = uba.begin();
00192       while (satItr != uba.end())
00193       {
00194          try
00195          {
00196             AlmOrbit a = findAlmanac(satItr->first, t);
00197             ao[satItr->first] = a;
00198          }
00201          catch(...)
00202          {}
00203 
00204          satItr++;
00205       }
00206       return ao;
00207    }
00208 
00209 
00210    void GPSAlmanacStore::edit(const CommonTime& tmin, const CommonTime& tmax)
00211       throw()
00212    {
00213       std::cout << "Not yet implimented" << std::endl;
00214    }
00215 
00216 
00217    void GPSAlmanacStore::dump(std::ostream& s, short detail)
00218       const throw()
00219    {
00220       UBAMap::const_iterator i;
00221       EngAlmMap::const_iterator j;
00222       for (i=uba.begin(); i!= uba.end(); i++)
00223       {
00224          const EngAlmMap& eam = i->second;
00225          for (j=eam.begin(); j!=eam.end(); j++)
00226          {
00227             j->second.dump(s, detail);
00228             s << std::endl;
00229          }
00230       }
00231    }
00232    
00233 }

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