BrcClockCorrection.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 
44 #include "StringUtils.hpp"
45 #include "BrcClockCorrection.hpp"
46 #include "GPS_URA.hpp"
47 #include <cmath>
48 
49 namespace gnsstk
50 {
51  using namespace std;
52  using namespace gnsstk;
53 
55  noexcept
56  {
57  dataLoaded = false;
58 
59  PRNID = 0;
60 
61  satSys = "";
62 
63  healthy = false;
64 
65  URAoc = -16;
66  URAoc1 = URAoc2 = 0;
67  af0 = af1 = af2 = 0.0;
68  }
69 
70  BrcClockCorrection::BrcClockCorrection(const std::string satSysArg,
71  const ObsID obsIDArg,
72  const short PRNIDArg,
73  const CommonTime TocArg,
74  const CommonTime TopArg,
75  const short URAocArg,
76  const short URAoc1Arg,
77  const short URAoc2Arg,
78  const bool healthyArg,
79  const double af0Arg,
80  const double af1Arg,
81  const double af2Arg )
82  {
83  loadData(satSysArg, obsIDArg, PRNIDArg, TocArg, TopArg, URAocArg,
84  URAoc1Arg, URAoc2Arg, healthyArg, af0Arg, af1Arg, af2Arg );
85  }
86 
89  const short PRNID,
90  const short fullweeknum,
91  const long subframe1[10] )
92  {
93  loadData(obsIDArg, PRNID,fullweeknum,subframe1 );
94  }
95 
96 
98  noexcept
99  {
100  // EngNav has no data
101  return ((dataLoaded == right.dataLoaded) &&
102  (satSys == right.satSys) &&
103  (obsID == right.obsID) &&
104  (PRNID == right.PRNID) &&
105  (Toc == right.Toc) &&
106  (Top == right.Top) &&
107  (URAoc == right.URAoc) &&
108  (URAoc1 == right.URAoc1) &&
109  (URAoc2 == right.URAoc2) &&
110  (healthy == right.healthy) &&
111  (af0 == right.af0) &&
112  (af1 == right.af1) &&
113  (af2 == right.af2));
114  }
115 
116 
117  void BrcClockCorrection::loadData(const std::string satSysArg,
118  const ObsID obsIDArg,
119  const short PRNIDArg,
120  const CommonTime TocArg,
121  const short URAocArg,
122  const bool healthyArg,
123  const double af0Arg,
124  const double af1Arg,
125  const double af2Arg )
126  {
127  const CommonTime TopArg;
128  const short URAoc1Arg = 0;
129  const short URAoc2Arg = 0;
130 
131  loadData(satSysArg, obsIDArg, PRNIDArg, TocArg, TopArg, URAocArg,
132  URAoc1Arg, URAoc2Arg, healthyArg, af0Arg, af1Arg, af2Arg );
133  }
134 
135  void BrcClockCorrection::loadData(const std::string satSysArg,
136  const ObsID obsIDArg,
137  const short PRNIDArg,
138  const CommonTime TocArg,
139  const CommonTime TopArg,
140  const short URAocArg,
141  const short URAoc1Arg,
142  const short URAoc2Arg,
143  const bool healthyArg,
144  const double af0Arg,
145  const double af1Arg,
146  const double af2Arg )
147  {
148  satSys = satSysArg;
149  obsID = obsIDArg;
150  PRNID = PRNIDArg;
151  Toc = TocArg;
152  Top = TopArg;
153  URAoc = URAocArg;
154  URAoc1 = URAoc1Arg;
155  URAoc2 = URAoc2Arg;
156  healthy = healthyArg;
157  af0 = af0Arg;
158  af1 = af1Arg;
159  af2 = af2Arg;
160  dataLoaded = true;
161  }
162 
163  void BrcClockCorrection::loadData(const ObsID obsIDArg, const short PRNIDArg,
164  const short fullweeknum,
165  const long subframe1[10] )
166  {
167  double ficked[60];
168 
169  //Load overhead members
170  satSys = "G";
171  obsID = obsIDArg;
172  PRNID = PRNIDArg;
173 
174  //Convert Subframe 1
175  if (!subframeConvert(subframe1, fullweeknum, ficked))
176  {
177  InvalidParameter exc("Subframe 1 not valid.");
178  GNSSTK_THROW(exc);
179  }
180  double Txmit = ficked[2]; // Time of week from handover word
181  short weeknum = static_cast<short>( ficked[5] );
182  short accFlag = static_cast<short>( ficked[7] );
183  short health = static_cast<short>( ficked[8] );
184  double TocSOW = ficked[12];
185  af2 = ficked[13];
186  af1 = ficked[14];
187  af0 = ficked[15];
188 
189  double diff = Txmit - TocSOW;
190  // NOTE: This USED to be in DayTime, but DayTime is going
191  // away. Where is it now?
192  if (diff > HALFWEEK)
193  {
194  // Convert week # of transmission to week # of epoch time
195  // when Toc is forward across a week boundary
196  weeknum++;
197  }
198  else if (diff < -HALFWEEK)
199  {
200  // Convert week # of transmission to week # of epoch time
201  // when Toc is back across a week boundary
202  weeknum--;
203  }
204 
205  Toc = GPSWeekSecond( weeknum, TocSOW, TimeSystem::GPS );
206  URAoc = accFlag; //Store L1 C/A URA as URAoc
207  URAoc1 = 0;
208  URAoc2 = 0;
209  healthy = false;
210  if (health == 0)
211  healthy = true;
212  dataLoaded = true;
213  return;
214  }
215 
217  {
218  return(dataLoaded);
219  }
220 
222  {
223  return Toc;
224  }
225 
227  {
228  double dtc,elaptc;
229  elaptc = t - getEpochTime();
230  dtc = af0 + elaptc * ( af1 + elaptc * af2 );
231  return dtc;
232  }
233 
235  {
236  double ret = svClockBias(t);
237  ret = ret*C_MPS;
238  return (ret);
239  }
240 
242  {
243  double drift,elaptc;
244  elaptc = t - getEpochTime();
245  drift = af1 + elaptc * af2;
246  return drift;
247  }
248 
250  {
251  if(!dataLoaded)
252  {
253  InvalidRequest exc("Required data not stored.");
254  GNSSTK_THROW(exc);
255  }
256  return PRNID;
257  }
258 
260  {
261  if(!dataLoaded)
262  {
263  InvalidRequest exc("Required data not stored.");
264  GNSSTK_THROW(exc);
265  }
266  return obsID;
267  }
268 
270  {
271  if (!dataLoaded)
272  {
273  InvalidRequest exc("Required data not stored.");
274  GNSSTK_THROW(exc);
275  }
276  GPSWeekSecond gpsws(Toc);
277  return (gpsws.week);
278  }
279 
281  {
282  double accuracy;
283 
284  if (!dataLoaded)
285  {
286  InvalidRequest exc("Required data not stored.");
287  GNSSTK_THROW(exc);
288  }
289  //if (obsID.code == "tcCA" ) // L1 C/A
290  accuracy = ura2accuracy(URAoc);
291  //else
292 
293  // deleted because algorithms in -705 and -800 changed
294  // accuracy = uraoc2CNAVaccuracy(URAoc, URAoc1, URAoc2, t, Top);
295  return accuracy;
296  }
297 
298  short BrcClockCorrection::getURAoc(const short& ndx) const
299  {
300  if (!dataLoaded)
301  {
302  InvalidRequest exc("Required data not stored.");
303  }
304  if (ndx == 0) return URAoc;
305  else if (ndx == 1) return URAoc1;
306  else if (ndx == 2) return URAoc2;
307  InvalidParameter exc ("Required data not stored.");
308  GNSSTK_THROW(exc);
309  }
310 
312  {
313  if (!dataLoaded)
314  {
315  InvalidRequest exc("Required data not stored.");
316  GNSSTK_THROW(exc);
317  }
318  GPSWeekSecond gpsws(Toc);
319  return gpsws.sow;
320  }
321 
323  {
324  if (!dataLoaded)
325  {
326  InvalidRequest exc("Required data not stored.");
327  GNSSTK_THROW(exc);
328  }
329  return af0;
330  }
331 
333  {
334  if (!dataLoaded)
335  {
336  InvalidRequest exc("Required data not stored.");
337  GNSSTK_THROW(exc);
338  }
339  return af1;
340  }
341 
343  {
344  if (!dataLoaded)
345  {
346  InvalidRequest exc("Required data not stored.");
347  GNSSTK_THROW(exc);
348  }
349  return af2;
350  }
351 
352  static void timeDisplay( ostream & os, const CommonTime& t )
353  {
354  // Convert to CommonTime struct from GPS wk,SOW to M/D/Y, H:M:S.
355  GPSWeekSecond dummyTime;
356  dummyTime = GPSWeekSecond(t);
357  os << setw(4) << dummyTime.week << "(";
358  os << setw(4) << (dummyTime.week & 0x03FF) << ") ";
359  os << setw(6) << setfill(' ') << dummyTime.sow << " ";
360 
361  switch (dummyTime.getDayOfWeek())
362  {
363  case 0: os << "Sun-0"; break;
364  case 1: os << "Mon-1"; break;
365  case 2: os << "Tue-2"; break;
366  case 3: os << "Wed-3"; break;
367  case 4: os << "Thu-4"; break;
368  case 5: os << "Fri-5"; break;
369  case 6: os << "Sat-6"; break;
370  default: break;
371  }
372  os << " " << (static_cast<YDSTime>(t)).printf("%3j %5.0s ")
373  << (static_cast<CivilTime>(t)).printf("%02m/%02d/%04Y %02H:%02M:%02S");
374  }
375 #pragma clang diagnostic push
376 #pragma clang diagnostic ignored "-Wunused-function"
377  static void shortcut(ostream & os, const long HOW )
378  {
379  short DOW, hour, min, sec;
380  long SOD, SOW;
381  short SOH;
382 
383  SOW = static_cast<long>( HOW );
384  DOW = static_cast<short>( SOW / SEC_PER_DAY );
385  SOD = SOW - static_cast<long>( DOW * SEC_PER_DAY );
386  hour = static_cast<short>( SOD/3600 );
387 
388  SOH = static_cast<short>( SOD - (hour*3600) );
389  min = SOH/60;
390 
391  sec = SOH - min * 60;
392  switch (DOW)
393  {
394  case 0: os << "Sun-0"; break;
395  case 1: os << "Mon-1"; break;
396  case 2: os << "Tue-2"; break;
397  case 3: os << "Wed-3"; break;
398  case 4: os << "Thu-4"; break;
399  case 5: os << "Fri-5"; break;
400  case 6: os << "Sat-6"; break;
401  default: break;
402  }
403 
404  os << ":" << setfill('0')
405  << setw(2) << hour
406  << ":" << setw(2) << min
407  << ":" << setw(2) << sec
408  << setfill(' ');
409  }
410 #pragma clang diagnostic pop
411  void BrcClockCorrection::dump(ostream& s) const
412  {
413  const ios::fmtflags oldFlags = s.flags();
414  s.setf(ios::fixed, ios::floatfield);
415  s.setf(ios::right, ios::adjustfield);
416  s.setf(ios::uppercase);
417  s.precision(0);
418  s.fill(' ');
419 
420  s << "****************************************************************"
421  << "************" << endl
422  << "Broadcast Ephemeris (Engineering Units)" << endl
423  << endl
424  << "PRN : " << setw(2) << PRNID << endl
425  << endl;
426 
427  s << " Week(10bt) SOW DOW UTD SOD"
428  << " MM/DD/YYYY HH:MM:SS\n";
429  s << "Clock Epoch: ";
430 
431  timeDisplay(s, getEpochTime());
432  s << endl;
433 
434  s.setf(ios::scientific, ios::floatfield);
435  s.precision(11);
436 
437  s << endl
438  << " CLOCK"
439  << endl
440  << endl
441  << "Bias T0: " << setw(18) << af0 << " sec" << endl
442  << "Drift: " << setw(18) << af1 << " sec/sec" << endl
443  << "Drift rate: " << setw(18) << af2 << " sec/(sec**2)" << endl;
444 
445  s << "****************************************************************"
446  << "************" << endl;
447 
448  s.flags(oldFlags);
449  }
450 
451  ostream& operator<<(ostream& s, const BrcClockCorrection& eph)
452  {
453  eph.dump(s);
454  return s;
455  } // end of operator<<
456 
457 } // namespace
gnsstk::BrcClockCorrection::getAf1
double getAf1() const
Definition: BrcClockCorrection.cpp:332
gnsstk::HALFWEEK
const long HALFWEEK
Seconds per half week.
Definition: TimeConstants.hpp:58
gnsstk::BrcClockCorrection::dump
void dump(std::ostream &s=std::cout) const
Definition: BrcClockCorrection.cpp:411
gnsstk::BrcClockCorrection::svClockDrift
double svClockDrift(const CommonTime &t) const
Definition: BrcClockCorrection.cpp:241
StringUtils.hpp
gnsstk::SEC_PER_DAY
const long SEC_PER_DAY
Seconds per day.
Definition: TimeConstants.hpp:63
gnsstk::shortcut
static void shortcut(ostream &os, const long HOW)
Definition: BrcClockCorrection.cpp:377
gnsstk::YDSTime
Definition: YDSTime.hpp:58
GPS_URA.hpp
gnsstk::BrcClockCorrection::svClockBias
double svClockBias(const CommonTime &t) const
Definition: BrcClockCorrection.cpp:226
gnsstk::BrcClockCorrection::BrcClockCorrection
BrcClockCorrection() noexcept
Default constructor.
Definition: BrcClockCorrection.cpp:54
example6.hour
hour
Definition: example6.py:67
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
gnsstk::BrcClockCorrection::hasData
bool hasData() const
Definition: BrcClockCorrection.cpp:216
gnsstk::WeekSecond::getDayOfWeek
virtual unsigned int getDayOfWeek() const
Force this interface on this classes descendants.
Definition: WeekSecond.hpp:134
gnsstk::BrcClockCorrection::getURAoc
short getURAoc(const short &ndx) const
Definition: BrcClockCorrection.cpp:298
gnsstk::C_MPS
const double C_MPS
m/s, speed of light; this value defined by GPS but applies to GAL and GLO.
Definition: GNSSconstants.hpp:74
gnsstk::ObsID
Definition: ObsID.hpp:82
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::WeekSecond::sow
double sow
Definition: WeekSecond.hpp:155
gnsstk::min
T min(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
Definition: SparseMatrix.hpp:858
gnsstk::BrcClockCorrection::getEpochTime
CommonTime getEpochTime() const
Definition: BrcClockCorrection.cpp:221
gnsstk::BrcClockCorrection::loadData
void loadData(const std::string satSysArg, const ObsID obsIDArg, const short PRNIDArg, const CommonTime TocArg, const CommonTime TopArg, const short URAocArg, const short URAoc1Arg, const short URAoc2Arg, const bool healthyArg, const double af0Arg, const double af1Arg, const double af2Arg)
Definition: BrcClockCorrection.cpp:135
gnsstk::BrcClockCorrection::getAf2
double getAf2() const
Definition: BrcClockCorrection.cpp:342
gnsstk::Week::week
int week
Full week number.
Definition: Week.hpp:267
gnsstk::BrcClockCorrection::getAf0
double getAf0() const
Definition: BrcClockCorrection.cpp:322
gnsstk::CivilTime
Definition: CivilTime.hpp:55
gnsstk::BrcClockCorrection::getPRNID
short getPRNID() const
Definition: BrcClockCorrection.cpp:249
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
std
Definition: Angle.hpp:142
gnsstk::timeDisplay
static void timeDisplay(ostream &os, const CommonTime &t)
Definition: BrcClockCorrection.cpp:352
gnsstk::BrcClockCorrection::getAccuracy
double getAccuracy(const CommonTime &t) const
Definition: BrcClockCorrection.cpp:280
gnsstk::BrcClockCorrection::svClockBiasM
double svClockBiasM(const CommonTime &t) const
Definition: BrcClockCorrection.cpp:234
gnsstk::BrcClockCorrection
Definition: BrcClockCorrection.hpp:76
gnsstk::BrcClockCorrection::getObsID
ObsID getObsID() const
Definition: BrcClockCorrection.cpp:259
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::BrcClockCorrection::operator==
bool operator==(const BrcClockCorrection &right) const noexcept
Definition: BrcClockCorrection.cpp:97
gnsstk::BrcClockCorrection::getFullWeek
short getFullWeek() const
Definition: BrcClockCorrection.cpp:269
BrcClockCorrection.hpp
gnsstk::ura2accuracy
double ura2accuracy(short ura) noexcept
Definition: GPS_URA.hpp:124
gnsstk::BrcClockCorrection::getToc
double getToc() const
Definition: BrcClockCorrection.cpp:311


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