TimeCorrection.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 #include "TimeCorrection.hpp"
40 #include "SystemTime.hpp"
41 #include "GPSWeekSecond.hpp"
42 
43 namespace gnsstk
44 {
45 
46  long timeAdjustWeekRollover(long toCorrectWeek, long& refWeek)
47  {
48  // gotta use signed ints so that the weeks can actually go
49  // negative when doing subtraction and comparison.
50  long rv = toCorrectWeek;
51  if (refWeek == 0)
52  {
53  // One might be inclined to try to cache the refWeek value
54  // from the clock internally, but that would mean that
55  // applications would be unable to process data from
56  // different epochs. An unusual situation, to be sure,
57  // but I'd rather not make assumptions about everyone's
58  // use cases.
60  refWeek = ref.week;
61  }
62  // GPS_WEEK_PER_EPOCH >> 1 is the same as /2, i.e. half-epoch.
63  // The while loops allow us to correct data that's more than
64  // one "epoch" out.
65  while (refWeek - rv > (GPS_WEEK_PER_EPOCH>>1))
66  {
67  rv += GPS_WEEK_PER_EPOCH;
68  }
69  while (refWeek - rv < -(GPS_WEEK_PER_EPOCH>>1))
70  {
71  rv -= GPS_WEEK_PER_EPOCH;
72  }
73  return rv;
74  }
75 
76 
77  long timeAdjust8BitWeekRollover(long toCorrectWeek, long& refWeek)
78  {
79  // gotta use signed ints so that the weeks can actually go
80  // negative when doing subtraction and comparison.
81  long rv = toCorrectWeek;
82  if (refWeek == 0)
83  {
84  // One might be inclined to try to cache the refWeek value
85  // from the clock internally, but that would mean that
86  // applications would be unable to process data from
87  // different epochs. An unusual situation, to be sure,
88  // but I'd rather not make assumptions about everyone's
89  // use cases.
91  refWeek = ref.week;
92  }
93  // 128 is half an 8-bit week epoch. The while loops allow us
94  // to correct data that's more than one "epoch" out.
95  while (refWeek - rv > 128)
96  {
97  rv += 256;
98  }
99  while (refWeek - rv < -128)
100  {
101  rv -= 256;
102  }
103  return rv;
104  }
105 
106 } // namespace gnsstk
gnsstk::UnixTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: UnixTime.cpp:54
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
SystemTime.hpp
gnsstk::timeAdjustWeekRollover
long timeAdjustWeekRollover(long toCorrectWeek, long &refWeek)
Definition: TimeCorrection.cpp:46
gnsstk::SystemTime
Definition: SystemTime.hpp:54
gnsstk::timeAdjust8BitWeekRollover
long timeAdjust8BitWeekRollover(long toCorrectWeek, long &refWeek)
Definition: TimeCorrection.cpp:77
gnsstk::Week::week
int week
Full week number.
Definition: Week.hpp:267
GPSWeekSecond.hpp
gnsstk::GPS_WEEK_PER_EPOCH
const long GPS_WEEK_PER_EPOCH
Weeks per GPS Epoch.
Definition: TimeConstants.hpp:85
TimeCorrection.hpp


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