X2Sequence.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: X2Sequence.hpp 2943 2011-10-25 17:17:11Z yanweignss $"
00002 
00003 
00004 //  X2Sequence.hpp - GPS X2 Sequencer
00005 
00006 #ifndef X2SEQUENCE_HPP
00007 #define X2SEQUENCE_HPP
00008 
00009 //============================================================================
00010 //
00011 //  This file is part of GPSTk, the GPS Toolkit.
00012 //
00013 //  The GPSTk is free software; you can redistribute it and/or modify
00014 //  it under the terms of the GNU Lesser General Public License as published
00015 //  by the Free Software Foundation; either version 2.1 of the License, or
00016 //  any later version.
00017 //
00018 //  The GPSTk is distributed in the hope that it will be useful,
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //  GNU Lesser General Public License for more details.
00022 //
00023 //  You should have received a copy of the GNU Lesser General Public
00024 //  License along with GPSTk; if not, write to the Free Software Foundation,
00025 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 //  
00027 //  Copyright 2004, The University of Texas at Austin
00028 //
00029 //============================================================================
00030 
00031 //============================================================================
00032 //
00033 //This software developed by Applied Research Laboratories at the University of
00034 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00035 //Department of Defense. The U.S. Government retains all rights to use,
00036 //duplicate, distribute, disclose, or release this software. 
00037 //
00038 //Pursuant to DoD Directive 523024 
00039 //
00040 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00041 //                           release, distribution is unlimited.
00042 //
00043 //=============================================================================
00044 
00045 
00046 
00047 
00048 
00049 
00050    // Local headers
00051 
00052 #include "gpstkplatform.h"
00053 #include "PCodeConst.hpp"
00054 #include "mergePCodeWords.h"
00055 
00056 namespace gpstk
00057 {
00060       
00061       /*
00062          The following constants are derived in x2EOW.cpp and
00063          used as literals here.
00064       */
00065    const long LENGTH_OF_EOW_OVERLAP =      34;
00066    const long OVERLAP_WORD_POSITION = 1451897;
00067       // Maximum number of X2 chips (exclusive of BOW delay chips)
00068    const long MAX_X2_TEST = 4 * ((XA_COUNT * XA_MAX_EPOCH) + X2A_EPOCH_DELAY); 
00069       // Maximum number of X2 chips
00070    const long MAX_X2_COUNT = X2A_EPOCH_DELAY + MAX_X2_TEST;
00071 
00142    class X2Sequence
00143    {
00144       public:
00150          X2Sequence();
00151          ~X2Sequence( ) {};
00152     
00170          static void allocateMemory( );
00171          static void deAllocateMemory( );
00172          
00185          uint32_t operator[]( long i );
00186 
00191          void setEOWX2Epoch( const bool tf );
00192 
00193       private:
00194          uint32_t *bitsP;
00195          static uint32_t* X2Bits;
00196          static uint32_t* X2BitsEOW;
00197          static uint32_t EOWEndOfSequence[LENGTH_OF_EOW_OVERLAP];
00198          static bool isInit; 
00199    };
00200 
00201        /*
00202           Given a bit position within the X2 sequence (numbered starting at -37),
00203           return the next 32 bits.  Note: if there are insufficient bits left
00204           to fill the request, wrap around to the beginning of the sequence.
00205        */
00206    inline uint32_t X2Sequence::operator[] ( long i )
00207    {
00208       long adjustedCount = i + X2A_EPOCH_DELAY;
00209    
00210       uint32_t retArg = 0L;
00211       int ndx1 = adjustedCount / MAX_BIT;
00212       int offset = adjustedCount - (ndx1 * MAX_BIT);
00213       if ( (adjustedCount+MAX_BIT) <= MAX_X2_COUNT )
00214       {
00215          if (offset==0) retArg = bitsP[ndx1];
00216          else           retArg = merge( bitsP[ndx1], bitsP[ndx1+1], offset );
00217       }
00218          /*
00219             Complicated case when coming up to end of sequence.  May have to
00220             put together parts of up to three words to get 32 bits.  The problem 
00221             is complicated because the word at the end of the array is partial
00222             AND the beginning of sequence (BOW) occurs in mid-word due to the
00223             PRN offset.  Some numbers:
00224          
00225             Number of bits available in word N : 25
00226             Number of bits available in word at BOS : 27
00227                   
00228             Possible cases:
00229             1.) Combine bits from [n-1], [n], and [BOS] - word n will provide
00230                 25 bits.  Therefore, some combination of (n-1,BOS) from the 
00231                 choice of (1,4), (2,3), (3,2), (4,1).
00232              
00233             2.) Combine bits from [n-1] and [BOS] - word n-1 will provide 25-5 
00234                 bits.  Therefore, BOS will provide 7-27 bits. 
00235          
00236             3.) Combine bits from [n-1], [BOS], and [BOS+1] - word n-1 provides
00237                 4-1 bits.  BOS provides 27 bits (running total to 31-28 bits).
00238                 BOS+1 provides 1-4 bits.
00239          */
00240       else
00241       {
00242          int numRemainingInSequence = MAX_X2_COUNT - adjustedCount;
00243          int numRemainingInWord;
00244          int numFilled = 0;
00245 
00246             // Handle word n-1
00247          if (ndx1==NUM_X2_WORDS-2)
00248          {
00249             numRemainingInWord = MAX_BIT - offset;
00250             retArg = bitsP[ndx1++] << offset;
00251             numFilled = numRemainingInWord;
00252             numRemainingInSequence -= numRemainingInWord;
00253          }
00254       
00255             // Handle word n
00256          uint32_t temp = bitsP[ndx1];
00257          numRemainingInWord = numRemainingInSequence;
00258          temp >>= (MAX_BIT-numRemainingInWord);
00259          temp <<= (MAX_BIT-(numRemainingInWord+numFilled));
00260          retArg |= temp;
00261          numFilled += numRemainingInSequence;
00262       
00263             //   Wrap to front.  Recall that "front" is actually bit
00264             //   37 in sequence due to "beginning of week" delay
00265          numRemainingInWord = (2 * MAX_BIT) - X2A_EPOCH_DELAY;
00266          int numNeeded = MAX_BIT - numFilled;
00267       
00268             // Case where all bits needed are in word 1 of sequence array
00269             //(which only has 27 "useful" bits)
00270          if (numNeeded <= numRemainingInWord)
00271          {
00272             temp = bitsP[1] << (MAX_BIT - numRemainingInWord);
00273             temp >>= (MAX_BIT - numNeeded);
00274             retArg |= temp;
00275          }
00276             // Case where all bits in word 1 are needed plus some bits in word 2.
00277          else
00278          {
00279                // Clearing high-order bits
00280             temp = bitsP[1] << (MAX_BIT - numRemainingInWord);
00281             temp >>= (MAX_BIT - numRemainingInWord);
00282             temp <<= (MAX_BIT - (numRemainingInWord+numFilled));
00283             retArg |= temp;
00284          
00285                // Fetch remaining bits from next word 
00286             numFilled += numRemainingInWord;
00287             numNeeded = MAX_BIT - numFilled;
00288             temp = bitsP[2] >> (MAX_BIT - numNeeded);
00289             retArg |= temp;
00290          }
00291       }
00292       return(retArg);
00293    }
00295 }  // end of namespace
00296 
00297 #endif // X2SEQUENCE_HPP

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