X1Sequence.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: X1Sequence.cpp 2834 2011-07-25 15:30:41Z mbratton $"
00002 
00003 
00004 /*
00005 *  X1Sequence.cpp
00006 *
00007 *     GPS X1 Sequencer.
00008 *     Applied Research Laboratories, The University of Texas at Austin
00009 *     August 2003
00010 */
00011 //============================================================================
00012 //
00013 //  This file is part of GPSTk, the GPS Toolkit.
00014 //
00015 //  The GPSTk is free software; you can redistribute it and/or modify
00016 //  it under the terms of the GNU Lesser General Public License as published
00017 //  by the Free Software Foundation; either version 2.1 of the License, or
00018 //  any later version.
00019 //
00020 //  The GPSTk is distributed in the hope that it will be useful,
00021 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 //  GNU Lesser General Public License for more details.
00024 //
00025 //  You should have received a copy of the GNU Lesser General Public
00026 //  License along with GPSTk; if not, write to the Free Software Foundation,
00027 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //  
00029 //  Copyright 2004, The University of Texas at Austin
00030 //
00031 //============================================================================
00032 
00033 //============================================================================
00034 //
00035 //This software developed by Applied Research Laboratories at the University of
00036 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00037 //Department of Defense. The U.S. Government retains all rights to use,
00038 //duplicate, distribute, disclose, or release this software. 
00039 //
00040 //Pursuant to DoD Directive 523024 
00041 //
00042 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00043 //                           release, distribution is unlimited.
00044 //
00045 //=============================================================================
00046 
00047 
00048 
00049 
00050 
00051    // Project headers
00052 #include "Exception.hpp"
00053 #include "X1Sequence.hpp"
00054 #include "GenXSequence.hpp"
00055 
00056 namespace gpstk
00057 {
00058       //   Static Variable Definition
00059    bool X1Sequence::isInit = false;
00060    uint32_t* X1Sequence::X1Bits = 0;
00061 
00062    X1Sequence::X1Sequence(  )
00063    {
00064       if (isInit!=true)
00065       {
00066          gpstk::Exception e(
00067             "Must call X1Sequence::allocateMemory() before instantiating a X1Sequence object.");
00068          GPSTK_THROW(e);
00069       }
00070    }
00071    
00072    void X1Sequence::allocateMemory( )
00073    {
00074       int X1Aepoch;
00075       int X1Acount;
00076       int X1Bepoch;
00077       int X1Bcount;
00078       int X1epoch = 1;
00079       long X1Word = 0;
00080       int lengthOfX1BSequence;
00081    
00082       if (isInit==true)
00083       {
00084          gpstk::Exception e ("X1Sequence::allocateMemory() called multiple times");
00085          GPSTK_THROW(e);
00086       }
00087       
00088       X1Bits = new uint32_t[NUM_6SEC_WORDS];
00089       if (X1Bits==0) 
00090       {
00091          gpstk::Exception e ("X1Sequence::allocateMemory() - allocation failed.");
00092          GPSTK_THROW(e);
00093       }
00094    
00095          // Generate the X1A and X1B sequences.
00096       gpstk::GenXSequence X1A( X1A_INIT, X1A_TAPS, XA_COUNT, XA_EPOCH_DELAY);
00097       gpstk::GenXSequence X1B( X1B_INIT, X1B_TAPS, XB_COUNT, XB_EPOCH_DELAY);
00098    
00099          // Combination will be performed for four X1 epochs.
00100          // This will generate six seconds of X1 bits sequence
00101          // that will end on an even 32-bit boundary.
00102       uint32_t X1Abits;
00103       uint32_t X1Bbits;
00104       X1Aepoch = 1;
00105       X1Acount = 0;
00106       X1Bepoch = 1;
00107       X1Bcount = 0;
00108       lengthOfX1BSequence = XB_COUNT;
00109    
00110       while ( X1Word < NUM_6SEC_WORDS )
00111       {
00112             // Get 32 X1A bits.  Update counters and handle rollovers.
00113          X1Abits = X1A[X1Acount];
00114          X1Acount += MAX_BIT;
00115       
00116          if ( X1Acount >= XA_COUNT )
00117          {
00118             ++X1Aepoch;
00119             if (X1Aepoch>XA_MAX_EPOCH)
00120             {
00121                ++X1epoch;
00122                X1Aepoch = 1;
00123             }
00124             X1Acount = X1Acount - XA_COUNT;
00125          }
00126       
00127             // Get 32 X1B bits.  Update counters and handle rollovers
00128          X1Bbits = X1B[X1Bcount];
00129          X1Bcount += MAX_BIT;
00130          if (X1Bcount >= lengthOfX1BSequence )
00131          {
00132             X1Bcount = X1Bcount - lengthOfX1BSequence;
00133             ++X1Bepoch;
00134             if (X1Bepoch>XB_MAX_EPOCH) X1Bepoch = 1;
00135             if (X1Bepoch==XB_MAX_EPOCH) 
00136                lengthOfX1BSequence = XB_COUNT+XB_EPOCH_DELAY;
00137              else
00138                lengthOfX1BSequence = XB_COUNT;
00139             X1B.setLengthOfSequence( lengthOfX1BSequence );
00140          }
00141          
00142          X1Bits[X1Word++] = X1Abits ^ X1Bbits;
00143       }   
00144    
00145       isInit = true;
00146    }
00147 
00148    void X1Sequence::deAllocateMemory()
00149    {
00150       if (isInit!=true || X1Bits==0)
00151       {
00152          gpstk::Exception e("X1Sequence::deAllocateMemory() called when no memory allocated.");
00153          GPSTK_THROW(e);
00154       }
00155       delete [] X1Bits;
00156       isInit = false;
00157    }
00158    
00159 }     // end of namespace
00160 

Generated on Wed Feb 8 03:31:04 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1