GenXSequence.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  * GenXSequence.cpp - Generate GPS X-register sequences
41  */
42 
43  // Local headers
44 #include <string>
45 #include "GenXSequence.hpp"
46 
47 using namespace std;
48 namespace gnsstk
49 {
50  // Constructor
51  GenXSequence::GenXSequence( const unsigned int initialState,
52  const unsigned int tapRegister,
53  const int initialLengthOfSequence,
54  const int maxDelay )
55  {
56 
57  /*
58  * NOTE: the x register functions assume a LSB-to-MSB shift. Therefore,
59  * the tap register definition and the initialization definition for the
60  * X register correspond to the diagrams in ICD-GPS-200, assuming
61  * "stage 0" is the LSB. That means the diagrams have to be read from
62  * LSB (LEFT) -> MSB (RIGHT). The corresponding text doesn't have this
63  * problem.
64  */
65  unsigned int mask12bits[12] = { 0x0001, 0x0002, 0x0004, 0x0008,
66  0x0010, 0x0020, 0x0040, 0x0080,
67  0x0100, 0x0200, 0x0400, 0x0800 };
68 
69  unsigned int reg = initialState;
70  lengthOfSequence = initialLengthOfSequence;
71  maxOfSequence = lengthOfSequence + maxDelay;
72 
73  uint32_t output = 0;
74  word_num = 0;
75  bit_num = 0;
76  int andBits;
77  int i;
78 
79  // Clear the output array
80  for ( i=0; i<MAX_WORD; ++i ) bits[i] = 0x00000000;
81  debugPrint = false;
82 
83  for ( i=0; i<lengthOfSequence ; ++i)
84  {
85  // Get current output and store it away
86  if ( (reg & 0x0800) != 0 ) output = 0x00000001;
87  else output = 0x00000000;
88  addBitToSequence( output );
89 
90  // Calculate next input bit
91  andBits = reg & tapRegister;
92  reg <<= 1;
93  reg &= 0x0FFF;
94  int cnt = 0;
95  for ( int bit12cnt=0; bit12cnt<12; ++bit12cnt)
96  {
97  if (( andBits & mask12bits[bit12cnt] ) != 0) ++cnt;
98  }
99  int newBit = cnt % 2;
100  reg |= newBit;
101  }
102 
103  // Fill delay bits with copies of the last ouptut bit
104  for ( i=0; i<maxDelay; ++i) addBitToSequence( output );
105 
106  // When finished, make sure the last word (which is probably
107  // a partially-filled word) is left-justified.
108  if (bit_num>0) bits[word_num] <<= (MAX_BIT-bit_num);
109  }
110 
111  // Private helper method to avoid duplicate code.
112  void GenXSequence::addBitToSequence( uint32_t newBit )
113  {
114  // Left shift any pre-existing data, then OR on the new
115  // data (assumed to be right-justified).
116  bits[word_num] <<= 1;
117  bits[word_num] |= newBit;
118 
119  /*
120  Increment bit pointer and check for word overflow.
121  NOTE: Overflow of the WORD pointer is a "programming problem"
122  that is unrecoverable and should NEVER happen in production.
123  */
124  ++bit_num;
125  if (bit_num>=MAX_BIT)
126  {
127  ++word_num;
128  bit_num=0;
129  }
130  }
131 
132  /*
133  Given a bit position within the X sequence (numbered starting at 0),
134  return the next 32 bits. Note: if there are insufficient bits left
135  to fill the request, wrap around to the beginning of the sequence.
136  Note that the location of the wrap around can be modified using the
137  function GenXSequence::setEndOfSequence( int los );
138  */
139  uint32_t GenXSequence::operator[] ( int ia )
140  {
141  uint32_t retArg = 0x00000000;
142  int i = ia;
143  if (i >= lengthOfSequence) i = i % lengthOfSequence;
144  int ndx1 = i / MAX_BIT;
145  int offset = i % MAX_BIT;
146  if ( (i+MAX_BIT) <= lengthOfSequence )
147  {
148  if (offset==0) retArg = bits[ndx1];
149  else retArg = merge( bits[ndx1], bits[ndx1+1], offset );
150  }
151  /*
152  Complicated case when coming up to end of sequence. May have to
153  put together parts of up to three words to get 32 bits. Two words
154  at the end of sequence plus "wrap around" bits from beginning of
155  sequence.
156  First: If end of sequence doesn't fall in current word, use up
157  remaining bits in the current word.
158  Second: use bits up to the end of sequence.
159  Third: fill remaining bits from the beginning of the sequence.
160  */
161  else
162  {
163  int numRemainingInSequence = lengthOfSequence - i;
164  int numRemainingInWord = MAX_BIT - offset;
165  int numFilled = 0;
166 
167  /*
168  Get bits (if any) from next-to-last word.
169  */
170  if (numRemainingInWord<numRemainingInSequence)
171  {
172  retArg = bits[ndx1++] << offset;
173  numRemainingInSequence -= numRemainingInWord;
174  numFilled = numRemainingInWord;
175  }
176 
177  uint32_t temp = bits[ndx1];
178  /*
179  Get bits from last word
180  Case 1: No bits from previous word, need only "middle" section
181  from last word.
182  Case 2: Need all bits available from final word (may or
183  may not have bits from preceding word)
184  */
185  if (numFilled==0 && offset!=0)
186  {
187  temp <<= offset; // Move to left to clear excess msb
188  temp >>= (MAX_BIT-numRemainingInSequence); // Shift right to clear excess lsb
189  temp <<= (MAX_BIT - (numRemainingInSequence+numFilled) );
190  retArg |= temp;
191  }
192  else
193  {
194  temp >>= (MAX_BIT-numRemainingInSequence);
195  temp <<= (MAX_BIT-(numRemainingInSequence+numFilled));
196  retArg |= temp;
197  }
198 
199  // Finally, add bits from the "wraparound" word at the
200  // beginning of the array.
201  retArg |= bits[0] >> (numRemainingInSequence+numFilled);
202  }
203  return(retArg);
204  }
205 
206  void GenXSequence::setLengthOfSequence( int los )
207  {
208  lengthOfSequence = los;
209  return;
210  }
211 } // end of namespace
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
example4.temp
temp
Definition: example4.py:35
gnsstk::MAX_WORD
const int MAX_WORD
Definition: GenXSequence.hpp:54
merge
uint32_t merge(uint32_t w1, uint32_t w2, int first_bit)
Definition: mergePCodeWords.h:52
gnsstk::MAX_BIT
const int MAX_BIT
Number of bits assumed to be in a unsigned long int.
Definition: PCodeConst.hpp:55
GenXSequence.hpp
std
Definition: Angle.hpp:142


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