SVPCodeGen.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: SVPCodeGen.cpp 3348 2013-04-09 16:03:11Z ajoplin $"
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 //
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 #include "GPSWeekZcount.hpp"
00043 
00044 using namespace std;
00045 namespace gpstk
00046 {
00047    const long LAST_6SEC_ZCOUNT_OF_WEEK = 403200 - 4;
00048 
00049    SVPCodeGen::SVPCodeGen( const int SVPRNID, const gpstk::CommonTime& dt )
00050    {
00051       if (SVPRNID < 1 || SVPRNID > 210)
00052       {
00053          gpstk::Exception e("Must provide a prn between 1 and 210");
00054          GPSTK_THROW(e);
00055       }
00056       currentZTime = dt;
00057       PRNID = SVPRNID;
00058    }
00059 
00060    void SVPCodeGen::getCurrentSixSeconds( CodeBuffer& pcb )
00061    {
00062          // Compute appropriate X2A offset
00063       int dayAdvance = (PRNID - 1) / 37;
00064       int EffPRNID = PRNID - dayAdvance * 37;
00065       long X1count = GPSWeekZcount(currentZTime + dayAdvance*86400.0).zcount;
00066       long X2count;
00067    
00068          /*
00069             Trivial, but special, case for beginning of week.  This
00070             can't be simplified into the general case due to the beginning
00071             of week chip delays that are equivalent to the PRNID.  These
00072             chips are stored at the beginning of the X2 chips sequence.  This
00073             is the only time the X2count should be "negative".  The offset is
00074             handled within the X2Sequence::operator[] method.
00075          */
00076       if (X1count==0 && PRNID <= 37) X2count = -PRNID;
00077    
00078          /*
00079             At the beginning of an X1 epoch, the previous X2 epoch
00080             will still be unfinished due to delays.  The accumulated
00081             delay is based on the PRNID and the delay per X1 epoch.
00082             Subtract this delay from the max length of the X2 sequence
00083             to determine the current chip within the X2 sequence.
00084          */
00085       else
00086       {
00087          long cumulativeX2Delay = X1count * X2A_EPOCH_DELAY + EffPRNID;
00088          X2count = MAX_X2_TEST - cumulativeX2Delay;
00089          if (X2count<0) X2count += MAX_X2_TEST;
00090       }
00091 
00092          /*
00093             If this if the final six-second interval of the week, 
00094             signal the X2 bit sequence generator to use the "end of week"
00095             sequence.  Otherwise, use the "regular" sequence.
00096          */
00097       if ( X1count==LAST_6SEC_ZCOUNT_OF_WEEK) X2Seq.setEOWX2Epoch(true);
00098        else X2Seq.setEOWX2Epoch(false);
00099    
00100          // Update the time and code state in the CodeBuffer object
00101       pcb.updateBufferStatus( currentZTime, P_CODE );
00102    
00103          // Starting at the beginning of the interval, step through
00104          // the six second period loading the code buffer as we go.
00105       for ( long i=0;i<NUM_6SEC_WORDS;++i )
00106       {
00107          pcb[i] = X1Seq[i] ^ X2Seq[X2count];
00108          X2count += MAX_BIT;
00109          if (X2count>=MAX_X2_TEST) X2count -= MAX_X2_TEST;
00110       }
00111    }
00112 
00113    void SVPCodeGen::increment4ZCounts( )
00114    {
00115       currentZTime += 6;    // 6 seconds == 4 Zcounts.
00116    }
00117    
00118    void SVPCodeGen::setCurrentZCount(const gpstk::GPSZcount& z)
00119    {
00120       GPSZcount z2 = z - z%4;
00121       currentZTime = GPSWeekZcount(z2.getWeek(), z2.getZcount());
00122    }
00123 }     // end of namespace

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