SVPCodeGen.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: SVPCodeGen.cpp 2834 2011-07-25 15:30:41Z mbratton $"
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //  
00021 //  Copyright 2004, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00025 //============================================================================
00026 //
00027 //This software developed by Applied Research Laboratories at the University of
00028 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00029 //Department of Defense. The U.S. Government retains all rights to use,
00030 //duplicate, distribute, disclose, or release this software. 
00031 //
00032 //Pursuant to DoD Directive 523024 
00033 //
00034 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00035 //                           release, distribution is unlimited.
00036 //
00037 //=============================================================================
00038 
00039 
00040 #include <iostream>
00041 #include "SVPCodeGen.hpp"
00042 
00043 using namespace std;
00044 namespace gpstk
00045 {
00046    const long LAST_6SEC_ZCOUNT_OF_WEEK = 403200 - 4;
00047 
00048    SVPCodeGen::SVPCodeGen( const int SVPRNID, const gpstk::DayTime& dt )
00049    {
00050       if (SVPRNID < 1 || SVPRNID > 210)
00051       {
00052          gpstk::Exception e("Must provide a prn between 1 and 210");
00053          GPSTK_THROW(e);
00054       }
00055       currentZTime = dt;
00056       PRNID = SVPRNID;
00057    }
00058 
00059    void SVPCodeGen::getCurrentSixSeconds( CodeBuffer& pcb )
00060    {
00061          // Compute appropriate X2A offset
00062       long X2count;
00063       long X1count = currentZTime.GPSzcount();
00064       int dayAdvance;
00065       int EffPRNID;
00066    
00067          /*
00068             Trivial, but special, case for beginning of week.  This
00069             can't be simplified into the general case due to the beginning
00070             of week chip delays that are equivalent to the PRNID.  These
00071             chips are stored at the beginning of the X2 chips sequence.  This
00072             is the only time the X2count should be "negative".  The offset is
00073             handled within the X2Sequence::operator[] method.
00074          */
00075       if (X1count==0 && PRNID <= 37) X2count = -PRNID;
00076    
00077          /*
00078             At the beginning of an X1 epoch, the previous X2 epoch
00079             will still be unfinished due to delays.  The accumulated
00080             delay is based on the PRNID and the delay per X1 epoch.
00081             Subtract this delay from the max length of the X2 sequence
00082             to determine the current chip within the X2 sequence.
00083          */
00084       else
00085       {
00086          dayAdvance = (PRNID - 1) / 37;
00087          EffPRNID = PRNID - dayAdvance * 37;
00088          long cumulativeX2Delay = X1count * X2A_EPOCH_DELAY + dayAdvance * X1_PER_DAY * X2A_EPOCH_DELAY + EffPRNID;
00089          X2count = MAX_X2_TEST - cumulativeX2Delay;
00090          if (X2count<0) X2count += MAX_X2_TEST;
00091       }
00092 
00093          /*
00094             If this if the final six-second interval of the week, 
00095             signal the X2 bit sequence generator to use the "end of week"
00096             sequence.  Otherwise, use the "regular" sequence.
00097          */
00098       if ( X1count==LAST_6SEC_ZCOUNT_OF_WEEK) X2Seq.setEOWX2Epoch(true);
00099        else X2Seq.setEOWX2Epoch(false);
00100    
00101          // Update the time and code state in the CodeBuffer object
00102       pcb.updateBufferStatus( currentZTime, P_CODE );
00103    
00104          // Starting at the beginning of the interval, step through
00105          // the six second period loading the code buffer as we go.
00106       for ( long i=0;i<NUM_6SEC_WORDS;++i )
00107       {
00108          pcb[i] = X1Seq[i] ^ X2Seq[X2count];
00109          X2count += MAX_BIT;
00110          if (X2count>=MAX_X2_TEST) X2count -= MAX_X2_TEST;
00111       }
00112    }
00113 
00114    void SVPCodeGen::increment4ZCounts( )
00115    {
00116       currentZTime += 6;    // 6 seconds == 4 Zcounts.
00117    }
00118    
00119    void SVPCodeGen::setCurrentZCount(const gpstk::GPSZcount& z)
00120    {
00121       GPSZcount z2 = z - z%4;
00122       currentZTime = z2;
00123    }
00124 }     // end of namespace

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