X2Sequence.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: X2Sequence.cpp 2834 2011-07-25 15:30:41Z mbratton $"
00002 
00003 
00004 /*
00005 *  X2Sequence.cpp
00006 *     GPS X2 Sequencer.
00007 *     Applied Research Laboratories, The University of Texas at Austin
00008 *     August 2003
00009 */
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    // Language headers
00050 #include <cstring>
00051 #include <stdio.h>
00052 #include <string>
00053 
00054    // Project headers
00055 #include "Exception.hpp"
00056 #include "GenXSequence.hpp"
00057 #include "X2Sequence.hpp"
00058 
00059 namespace gpstk
00060 {
00061       // Static Variable Definition
00062    bool X2Sequence::isInit = false;
00063    uint32_t* X2Sequence::X2Bits = 0;
00064    uint32_t* X2Sequence::X2BitsEOW = 0;
00065 
00066       // See program x2EOW.cpp for derivation of these values
00067    uint32_t X2Sequence::EOWEndOfSequence[LENGTH_OF_EOW_OVERLAP] =
00068    {
00069     0xFA5F8298, 0xB30C04D9, 0xD5CACBCA, 0x0ED47FFF, 0xFFFFFFFF, 0xFFFFFFFF,
00070     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
00071     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
00072     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
00073     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
00074     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
00075    };
00076 
00077    X2Sequence::X2Sequence(  )
00078    {
00079       if (isInit!=true)
00080       {
00081          gpstk::Exception e(
00082             "Must call X2Sequence::allocateMemory() before instantiating a X2Sequence object.");
00083          GPSTK_THROW(e);
00084       }
00085       
00086          // This must be done for each object in order to initialize the
00087          // bitsP pointer to the correct buffer of bits.
00088       setEOWX2Epoch(false);
00089    }
00090    
00091    void X2Sequence::allocateMemory( )
00092    {
00093       int X2Aepoch;
00094       int X2Acount;
00095       int X2Bepoch;
00096       int X2Bcount;
00097       int X2epoch = 1;
00098       long X2Word = 0;
00099       long X2Count = 0;
00100       int lengthOfX2ASequence;
00101       int lengthOfX2BSequence;
00102 
00103       if (isInit==true)
00104       {
00105          gpstk::Exception e ("X2Sequence::allocateMemory() called multiple times");
00106          GPSTK_THROW(e);
00107       }
00108       
00109       X2Bits =    new uint32_t[NUM_X2_WORDS];
00110       X2BitsEOW = new uint32_t[NUM_X2_WORDS];
00111       if (X2Bits==0 || X2BitsEOW==0) 
00112       {
00113          gpstk::Exception e ("X2Sequence::allocateMemory() - allocation failed.");
00114          GPSTK_THROW(e);
00115       }
00116    
00117       for (long ndx = 0; ndx < NUM_X2_WORDS; ndx++)
00118       {
00119          X2Bits[ndx] = 0x00000000;
00120          X2BitsEOW[ndx] = 0x00000000;
00121       }
00122 
00123          // Last words of X2Bits and X2BitsEOW are only partially filled.
00124          // Initialize to 0 to avoid confusion.
00125       X2Bits[NUM_X2_WORDS-1] = 0x00000000;
00126       X2BitsEOW[NUM_X2_WORDS-1] = 0x00000000;
00127    
00128          // Generate the X2A and X2B sequences.
00129       gpstk::GenXSequence X2A( X2A_INIT, X2A_TAPS, XA_COUNT, 
00130                                          XA_EPOCH_DELAY+X2A_EPOCH_DELAY);
00131       gpstk::GenXSequence X2B( X2B_INIT, X2B_TAPS, XB_COUNT, 
00132                                          XB_EPOCH_DELAY+X2A_EPOCH_DELAY);
00133 
00134          /*
00135              In order to handle the beginning of week case, obtain the 
00136              initial X2 bit, then copy this bit into the first 37 bit 
00137              positions of the X2 sequence.
00138          */
00139       uint32_t firstTest = X2A[0] ^ X2B[0];
00140       if (firstTest & 0x80000000 ) 
00141          X2Bits[0] = 0xFFFFFFFF;
00142        else
00143          X2Bits[0] = 0x00000000;
00144 
00145       X2Bits[1] = firstTest >> 5;
00146       X2Bits[1] |= ( X2Bits[0] & 0xF8000000 );
00147    
00148          /*
00149             Previous section handled the beginning of week 37 chip delay 
00150             plus the first 27 chips (64 bits - 37 chip = 27) of the X2
00151             cycle.  Set the counters accordingly and start retrieving bits.
00152             The combination will be performed for four X2 epochs.
00153             This will generate six seconds+ of X2 bits sequence.
00154          */
00155       uint32_t X2Abits;
00156       uint32_t X2Bbits;
00157       X2Aepoch = 1;
00158       X2Acount = 27;
00159       X2Bepoch = 1;
00160       X2Bcount = 27;
00161       X2Word = 2;
00162       X2Count = X2Word * MAX_BIT;
00163    
00164       lengthOfX2ASequence = XA_COUNT;
00165       X2A.setLengthOfSequence( lengthOfX2ASequence );
00166    
00167       lengthOfX2BSequence = XB_COUNT;
00168       X2B.setLengthOfSequence( lengthOfX2BSequence );
00169    
00170       while ( X2Count < MAX_X2_COUNT )
00171       {
00172             // Get 32 X2A bits.  Update counters and handle rollovers.
00173          X2Abits = X2A[X2Acount];
00174          X2Acount += MAX_BIT;
00175       
00176          if ( X2Acount >= lengthOfX2ASequence )
00177          {
00178             X2Acount = X2Acount - lengthOfX2ASequence;
00179             ++X2Aepoch;
00180             if (X2Aepoch>XA_MAX_EPOCH)
00181             {
00182                ++X2epoch;
00183                X2Aepoch = 1;
00184             }
00185             if (X2Aepoch==XA_MAX_EPOCH)
00186                lengthOfX2ASequence = XA_COUNT+X2A_EPOCH_DELAY;
00187             else
00188                lengthOfX2ASequence = XA_COUNT;
00189             X2A.setLengthOfSequence( lengthOfX2ASequence );
00190          }
00191       
00192             // Get 32 X2B bits.  Update counters and handle rollovers
00193          X2Bbits = X2B[X2Bcount];
00194          X2Bcount += MAX_BIT;
00195          if (X2Bcount >= lengthOfX2BSequence )
00196          {  
00197             X2Bcount = X2Bcount - lengthOfX2BSequence;
00198             ++X2Bepoch;
00199             if (X2Bepoch>XB_MAX_EPOCH) X2Bepoch = 1;
00200             if (X2Bepoch==XB_MAX_EPOCH) 
00201                lengthOfX2BSequence = XB_COUNT+XB_EPOCH_DELAY+X2A_EPOCH_DELAY;
00202              else
00203                lengthOfX2BSequence = XB_COUNT;
00204             X2B.setLengthOfSequence( lengthOfX2BSequence );
00205          }
00206          
00207          X2Bits[X2Word++] = X2Abits ^ X2Bbits;
00208          X2Count += MAX_BIT;
00209       }   
00210 
00211          // At this point, the X2Bits array is complete.  Copy the entire
00212          // array into X2BitsEOW, then overlay the EOW section into the
00213          // appropriate place.
00214       const size_t numBytesPerWord = 4;
00215       size_t numBytes = NUM_X2_WORDS * numBytesPerWord;
00216       std::memcpy( X2BitsEOW, X2Bits, numBytes );
00217       numBytes = LENGTH_OF_EOW_OVERLAP * numBytesPerWord;
00218       memcpy( (void *) &X2BitsEOW[OVERLAP_WORD_POSITION], EOWEndOfSequence, numBytes );
00219    
00220       isInit = true;
00221    }
00222 
00223    void X2Sequence::deAllocateMemory()
00224    {
00225       if (isInit!=true || X2Bits==0 || X2BitsEOW==0)
00226       {
00227          gpstk::Exception e("X2Sequence::deAllocateMemory() called when no memory allocated.");
00228          GPSTK_THROW(e);
00229       }
00230       delete [] X2Bits;
00231       delete [] X2BitsEOW;
00232       isInit = false;
00233    }
00234    
00235    void X2Sequence::setEOWX2Epoch( const bool tf )
00236    {
00237       if (tf) bitsP = X2BitsEOW;
00238        else   bitsP = X2Bits;
00239    }
00240 
00241 }  // end of namespace

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