X2Sequence.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 /*
40 * X2Sequence.cpp
41 * GPS X2 Sequencer.
42 * Applied Research Laboratories, The University of Texas at Austin
43 * August 2003
44 */
45 
46  // Language headers
47 #include <cstring>
48 #include <stdio.h>
49 #include <string>
50 
51  // Project headers
52 #include "Exception.hpp"
53 #include "GenXSequence.hpp"
54 #include "X2Sequence.hpp"
55 
56 namespace gnsstk
57 {
58  // Static Variable Definition
59  bool X2Sequence::isInit = false;
60  uint32_t* X2Sequence::X2Bits = 0;
61  uint32_t* X2Sequence::X2BitsEOW = 0;
62 
63  // See program x2EOW.cpp for derivation of these values
65  {
66  0xFA5F8298, 0xB30C04D9, 0xD5CACBCA, 0x0ED47FFF, 0xFFFFFFFF, 0xFFFFFFFF,
67  0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
68  0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
69  0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
70  0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
71  0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
72  };
73 
75  {
76  if (isInit!=true)
77  {
79  "Must call X2Sequence::allocateMemory() before instantiating a X2Sequence object.");
80  GNSSTK_THROW(e);
81  }
82 
83  // This must be done for each object in order to initialize the
84  // bitsP pointer to the correct buffer of bits.
85  setEOWX2Epoch(false);
86  }
87 
89  {
90  int X2Aepoch;
91  int X2Acount;
92  int X2Bepoch;
93  int X2Bcount;
94  int X2epoch = 1;
95  long X2Word = 0;
96  long X2Count = 0;
97  int lengthOfX2ASequence;
98  int lengthOfX2BSequence;
99 
100  if (isInit==true)
101  {
102  gnsstk::Exception e ("X2Sequence::allocateMemory() called multiple times");
103  GNSSTK_THROW(e);
104  }
105 
106  X2Bits = new uint32_t[NUM_X2_WORDS];
107  X2BitsEOW = new uint32_t[NUM_X2_WORDS];
108  if (X2Bits==0 || X2BitsEOW==0)
109  {
110  gnsstk::Exception e ("X2Sequence::allocateMemory() - allocation failed.");
111  GNSSTK_THROW(e);
112  }
113 
114  for (long ndx = 0; ndx < NUM_X2_WORDS; ndx++)
115  {
116  X2Bits[ndx] = 0x00000000;
117  X2BitsEOW[ndx] = 0x00000000;
118  }
119 
120  // Last words of X2Bits and X2BitsEOW are only partially filled.
121  // Initialize to 0 to avoid confusion.
122  X2Bits[NUM_X2_WORDS-1] = 0x00000000;
123  X2BitsEOW[NUM_X2_WORDS-1] = 0x00000000;
124 
125  // Generate the X2A and X2B sequences.
130 
131  /*
132  In order to handle the beginning of week case, obtain the
133  initial X2 bit, then copy this bit into the first 37 bit
134  positions of the X2 sequence.
135  */
136  uint32_t firstTest = X2A[0] ^ X2B[0];
137  if (firstTest & 0x80000000 )
138  X2Bits[0] = 0xFFFFFFFF;
139  else
140  X2Bits[0] = 0x00000000;
141 
142  X2Bits[1] = firstTest >> 5;
143  X2Bits[1] |= ( X2Bits[0] & 0xF8000000 );
144 
145  /*
146  Previous section handled the beginning of week 37 chip delay
147  plus the first 27 chips (64 bits - 37 chip = 27) of the X2
148  cycle. Set the counters accordingly and start retrieving bits.
149  The combination will be performed for four X2 epochs.
150  This will generate six seconds+ of X2 bits sequence.
151  */
152  uint32_t X2Abits;
153  uint32_t X2Bbits;
154  X2Aepoch = 1;
155  X2Acount = 27;
156  X2Bepoch = 1;
157  X2Bcount = 27;
158  X2Word = 2;
159  X2Count = X2Word * MAX_BIT;
160 
161  lengthOfX2ASequence = XA_COUNT;
162  X2A.setLengthOfSequence( lengthOfX2ASequence );
163 
164  lengthOfX2BSequence = XB_COUNT;
165  X2B.setLengthOfSequence( lengthOfX2BSequence );
166 
167  while ( X2Count < MAX_X2_COUNT )
168  {
169  // Get 32 X2A bits. Update counters and handle rollovers.
170  X2Abits = X2A[X2Acount];
171  X2Acount += MAX_BIT;
172 
173  if ( X2Acount >= lengthOfX2ASequence )
174  {
175  X2Acount = X2Acount - lengthOfX2ASequence;
176  ++X2Aepoch;
177  if (X2Aepoch>XA_MAX_EPOCH)
178  {
179  ++X2epoch;
180  X2Aepoch = 1;
181  }
182  if (X2Aepoch==XA_MAX_EPOCH)
183  lengthOfX2ASequence = XA_COUNT+X2A_EPOCH_DELAY;
184  else
185  lengthOfX2ASequence = XA_COUNT;
186  X2A.setLengthOfSequence( lengthOfX2ASequence );
187  }
188 
189  // Get 32 X2B bits. Update counters and handle rollovers
190  X2Bbits = X2B[X2Bcount];
191  X2Bcount += MAX_BIT;
192  if (X2Bcount >= lengthOfX2BSequence )
193  {
194  X2Bcount = X2Bcount - lengthOfX2BSequence;
195  ++X2Bepoch;
196  if (X2Bepoch>XB_MAX_EPOCH) X2Bepoch = 1;
197  if (X2Bepoch==XB_MAX_EPOCH)
198  lengthOfX2BSequence = XB_COUNT+XB_EPOCH_DELAY+X2A_EPOCH_DELAY;
199  else
200  lengthOfX2BSequence = XB_COUNT;
201  X2B.setLengthOfSequence( lengthOfX2BSequence );
202  }
203 
204  X2Bits[X2Word++] = X2Abits ^ X2Bbits;
205  X2Count += MAX_BIT;
206  }
207 
208  // At this point, the X2Bits array is complete. Copy the entire
209  // array into X2BitsEOW, then overlay the EOW section into the
210  // appropriate place.
211  const size_t numBytesPerWord = 4;
212  size_t numBytes = NUM_X2_WORDS * numBytesPerWord;
213  std::memcpy( X2BitsEOW, X2Bits, numBytes );
214  numBytes = LENGTH_OF_EOW_OVERLAP * numBytesPerWord;
215  memcpy( (void *) &X2BitsEOW[OVERLAP_WORD_POSITION], EOWEndOfSequence, numBytes );
216 
217  isInit = true;
218  }
219 
221  {
222  if (isInit!=true || X2Bits==0 || X2BitsEOW==0)
223  {
224  gnsstk::Exception e("X2Sequence::deAllocateMemory() called when no memory allocated.");
225  GNSSTK_THROW(e);
226  }
227  delete [] X2Bits;
228  delete [] X2BitsEOW;
229  isInit = false;
230  }
231 
232  void X2Sequence::setEOWX2Epoch( const bool tf )
233  {
234  if (tf) bitsP = X2BitsEOW;
235  else bitsP = X2Bits;
236  }
237 
238 } // end of namespace
gnsstk::X2Sequence::deAllocateMemory
static void deAllocateMemory()
Definition: X2Sequence.cpp:220
gnsstk::X2A_EPOCH_DELAY
const long X2A_EPOCH_DELAY
The 37 chip delay at the end of every X2A epoch.
Definition: PCodeConst.hpp:97
gnsstk::X2A_TAPS
const unsigned int X2A_TAPS
Definition: PCodeConst.hpp:78
gnsstk::NUM_X2_WORDS
const long NUM_X2_WORDS
Number of 4 byte unsigned ints necessary to hold an X2 sequence (with leading delay)
Definition: PCodeConst.hpp:67
gnsstk::MAX_X2_COUNT
const long MAX_X2_COUNT
Definition: X2Sequence.hpp:63
gnsstk::X2B_INIT
const unsigned int X2B_INIT
Definition: PCodeConst.hpp:73
gnsstk::XB_EPOCH_DELAY
const long XB_EPOCH_DELAY
Definition: PCodeConst.hpp:94
gnsstk::X2Sequence::X2Bits
static uint32_t * X2Bits
Definition: X2Sequence.hpp:188
gnsstk::XA_MAX_EPOCH
const int XA_MAX_EPOCH
X?_MAX_EPOCH is the maximum number of epochs in a sequence.
Definition: PCodeConst.hpp:82
gnsstk::XA_EPOCH_DELAY
const long XA_EPOCH_DELAY
Definition: PCodeConst.hpp:93
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::X2Sequence::setEOWX2Epoch
void setEOWX2Epoch(const bool tf)
Definition: X2Sequence.cpp:232
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::X2Sequence::bitsP
uint32_t * bitsP
Definition: X2Sequence.hpp:187
gnsstk::LENGTH_OF_EOW_OVERLAP
const long LENGTH_OF_EOW_OVERLAP
Definition: X2Sequence.hpp:58
X2Sequence.hpp
gnsstk::X2Sequence::isInit
static bool isInit
Definition: X2Sequence.hpp:191
gnsstk::GenXSequence
Definition: GenXSequence.hpp:96
gnsstk::XA_COUNT
const int XA_COUNT
X?_COUNT is the number of bits in an epoch.
Definition: PCodeConst.hpp:86
gnsstk::MAX_BIT
const int MAX_BIT
Number of bits assumed to be in a unsigned long int.
Definition: PCodeConst.hpp:55
Exception.hpp
GenXSequence.hpp
gnsstk::X2Sequence::X2BitsEOW
static uint32_t * X2BitsEOW
Definition: X2Sequence.hpp:189
gnsstk::X2Sequence::X2Sequence
X2Sequence()
Definition: X2Sequence.cpp:74
gnsstk::X2B_TAPS
const unsigned int X2B_TAPS
Definition: PCodeConst.hpp:79
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::X2A_INIT
const unsigned int X2A_INIT
Definition: PCodeConst.hpp:72
gnsstk::XB_MAX_EPOCH
const int XB_MAX_EPOCH
Definition: PCodeConst.hpp:83
gnsstk::GenXSequence::setLengthOfSequence
void setLengthOfSequence(int i)
Set the end of sequence for the current cycle.
Definition: GenXSequence.cpp:206
gnsstk::XB_COUNT
const int XB_COUNT
Definition: PCodeConst.hpp:87
gnsstk::X2Sequence::EOWEndOfSequence
static uint32_t EOWEndOfSequence[LENGTH_OF_EOW_OVERLAP]
Definition: X2Sequence.hpp:190
gnsstk::OVERLAP_WORD_POSITION
const long OVERLAP_WORD_POSITION
Definition: X2Sequence.hpp:59
gnsstk::X2Sequence::allocateMemory
static void allocateMemory()
Definition: X2Sequence.cpp:88


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42