SVPCodeGen.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 #include <iostream>
41 #include "SVPCodeGen.hpp"
42 #include "GPSWeekZcount.hpp"
43 
44 using namespace std;
45 namespace gnsstk
46 {
47  const long LAST_6SEC_ZCOUNT_OF_WEEK = 403200 - 4;
48 
49  SVPCodeGen::SVPCodeGen( const int SVPRNID, const gnsstk::CommonTime& dt )
50  {
51  if (SVPRNID < 0 || SVPRNID > 210)
52  {
53  gnsstk::Exception e("Must provide a prn between 0 and 210");
54  GNSSTK_THROW(e);
55  }
56  currentZTime = dt;
57  PRNID = SVPRNID;
58  }
59 
60  void SVPCodeGen::getCurrentSixSeconds( CodeBuffer& pcb )
61  {
62  // Compute appropriate X2A offset
63  int dayAdvance = (PRNID - 1) / 37;
64  int EffPRNID = PRNID - dayAdvance * 37;
65  long X1count = GPSWeekZcount(currentZTime + dayAdvance*86400.0).zcount;
66  long X2count;
67 
68  /*
69  Trivial, but special, case for beginning of week. This
70  can't be simplified into the general case due to the beginning
71  of week chip delays that are equivalent to the PRNID. These
72  chips are stored at the beginning of the X2 chips sequence. This
73  is the only time the X2count should be "negative". The offset is
74  handled within the X2Sequence::operator[] method.
75  */
76  if (X1count==0 && PRNID <= 37) X2count = -PRNID;
77 
78  /*
79  At the beginning of an X1 epoch, the previous X2 epoch
80  will still be unfinished due to delays. The accumulated
81  delay is based on the PRNID and the delay per X1 epoch.
82  Subtract this delay from the max length of the X2 sequence
83  to determine the current chip within the X2 sequence.
84  */
85  else
86  {
87  long cumulativeX2Delay = X1count * X2A_EPOCH_DELAY + EffPRNID;
88  X2count = MAX_X2_TEST - cumulativeX2Delay;
89  if (X2count<0) X2count += MAX_X2_TEST;
90  }
91 
92  /*
93  If this if the final six-second interval of the week,
94  signal the X2 bit sequence generator to use the "end of week"
95  sequence. Otherwise, use the "regular" sequence.
96  */
97  if ( X1count==LAST_6SEC_ZCOUNT_OF_WEEK) X2Seq.setEOWX2Epoch(true);
98  else X2Seq.setEOWX2Epoch(false);
99 
100  // Update the time and code state in the CodeBuffer object
101  pcb.updateBufferStatus( currentZTime, P_CODE );
102 
103  // Starting at the beginning of the interval, step through
104  // the six second period loading the code buffer as we go.
105  for ( long i=0;i<NUM_6SEC_WORDS;++i )
106  {
107  pcb[i] = X1Seq[i] ^ X2Seq[X2count];
108  X2count += MAX_BIT;
109  if (X2count>=MAX_X2_TEST) X2count -= MAX_X2_TEST;
110  }
111  }
112 
113  void SVPCodeGen::increment4ZCounts( )
114  {
115  currentZTime += 6; // 6 seconds == 4 Zcounts.
116  }
117 
118  void SVPCodeGen::setCurrentZCount(const gnsstk::GPSZcount& z)
119  {
120  GPSZcount z2 = z - z%4;
121  currentZTime = GPSWeekZcount(z2.getWeek(), z2.getZcount());
122  }
123 } // end of namespace
GPSWeekZcount.hpp
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::CodeBuffer::updateBufferStatus
void updateBufferStatus(const gnsstk::CommonTime &dt, const codeType PYFlag)
Definition: CodeBuffer.cpp:65
gnsstk::GPSWeekZcount::zcount
unsigned int zcount
Definition: GPSWeekZcount.hpp:371
gnsstk::NUM_6SEC_WORDS
const long NUM_6SEC_WORDS
Number of 4 byte unsigned ints necessary to hold 6 sec of P-code.
Definition: PCodeConst.hpp:64
gnsstk::GPSZcount::getZcount
long getZcount() const
GPS Z-count accessor.
Definition: GPSZcount.hpp:117
gnsstk::LAST_6SEC_ZCOUNT_OF_WEEK
const long LAST_6SEC_ZCOUNT_OF_WEEK
Definition: SVPCodeGen.cpp:47
gnsstk::MAX_X2_TEST
const long MAX_X2_TEST
Definition: X2Sequence.hpp:61
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::GPSZcount
Definition: GPSZcount.hpp:75
gnsstk::GPSZcount::getWeek
short getWeek() const
GPS week accessor.
Definition: GPSZcount.hpp:113
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::GPSWeekZcount
Definition: GPSWeekZcount.hpp:55
gnsstk::MAX_BIT
const int MAX_BIT
Number of bits assumed to be in a unsigned long int.
Definition: PCodeConst.hpp:55
std
Definition: Angle.hpp:142
gnsstk::P_CODE
@ P_CODE
Definition: PCodeConst.hpp:52
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
SVPCodeGen.hpp
gnsstk::CodeBuffer
Definition: CodeBuffer.hpp:73


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