00001 #pragma ident "$Id: X2Sequence.cpp 2834 2011-07-25 15:30:41Z mbratton $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <cstring>
00051 #include <stdio.h>
00052 #include <string>
00053
00054
00055 #include "Exception.hpp"
00056 #include "GenXSequence.hpp"
00057 #include "X2Sequence.hpp"
00058
00059 namespace gpstk
00060 {
00061
00062 bool X2Sequence::isInit = false;
00063 uint32_t* X2Sequence::X2Bits = 0;
00064 uint32_t* X2Sequence::X2BitsEOW = 0;
00065
00066
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
00087
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
00124
00125 X2Bits[NUM_X2_WORDS-1] = 0x00000000;
00126 X2BitsEOW[NUM_X2_WORDS-1] = 0x00000000;
00127
00128
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
00136
00137
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
00150
00151
00152
00153
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
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
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
00212
00213
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 }