00001 #pragma ident "$Id: X1Sequence.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
00051
00052 #include "Exception.hpp"
00053 #include "X1Sequence.hpp"
00054 #include "GenXSequence.hpp"
00055
00056 namespace gpstk
00057 {
00058
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
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
00100
00101
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
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
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 }
00160