SEMNavDataFactory.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 //
28 // This software was developed by Applied Research Laboratories at the
29 // University of Texas at Austin, under contract to an agency or agencies
30 // within the U.S. Department of Defense. The U.S. Government retains all
31 // rights to use, duplicate, distribute, disclose, or release this software.
32 //
33 // Pursuant to DoD Directive 523024
34 //
35 // DISTRIBUTION STATEMENT A: This software has been approved for public
36 // release, distribution is unlimited.
37 //
38 //==============================================================================
39 #include "SEMNavDataFactory.hpp"
40 #include "SEMStream.hpp"
41 #include "SEMHeader.hpp"
42 #include "GPSLNavHealth.hpp"
43 #include "GPSWeekSecond.hpp"
45 
46 using namespace std;
47 
48 namespace gnsstk
49 {
50  SEMNavDataFactory ::
51  SEMNavDataFactory()
52  {
53  supportedSignals.insert(NavSignalID(SatelliteSystem::GPS,
55  TrackingCode::CA,
56  NavType::GPSLNAV));
57  }
58 
59 
60  bool SEMNavDataFactory ::
61  loadIntoMap(const std::string& filename, NavMessageMap& navMap,
62  NavNearMessageMap& navNearMap, OffsetCvtMap& ofsMap)
63  {
64  gnsstk::NavDataFactoryStoreCallback cb(this, navMap, navNearMap, ofsMap);
65  return process(filename, cb);
66  }
67 
68 
69  bool SEMNavDataFactory ::
70  process(const std::string& filename,
72  {
73  bool rv = true;
74  bool processAlm = (procNavTypes.count(NavMessageType::Almanac) > 0);
75  bool processHea = (procNavTypes.count(NavMessageType::Health) > 0);
76  try
77  {
78  SEMStream is(filename.c_str(), ios::in);
79  SEMHeader head;
80  SEMData data;
81  if (!is)
82  return false;
83  is >> head;
84  if (!is)
85  return false;
86  while (is)
87  {
88  is >> data;
89  if (!is)
90  {
91  if (is.eof())
92  break;
93  else
94  return false; // some other error
95  }
96  NavDataPtr alm, health;
97  if (processAlm)
98  {
99  if (!convertToOrbit(data, alm))
100  return false;
101  }
102  if (processHea)
103  {
104  if (!convertToHealth(data, health))
105  return false;
106  }
107  // check the validity
108  bool check = false;
109  bool expect = false;
110  switch (navValidity)
111  {
112  case NavValidityType::ValidOnly:
113  check = true;
114  expect = true;
115  break;
116  case NavValidityType::InvalidOnly:
117  check = true;
118  expect = false;
119  break;
120  // Just treat everything else like All, which is to
121  // say, no checks.
122  default:
123  break;
124  }
125  if (check)
126  {
127  if (processAlm)
128  {
129  if (alm->validate() == expect)
130  {
131  if (!cb.process(alm))
132  return false;
133  }
134  }
135  if (processHea)
136  {
137  if (health->validate() == expect)
138  {
139  if (!cb.process(health))
140  return false;
141  }
142  }
143  }
144  else
145  {
146  if (processAlm)
147  {
148  if (!cb.process(alm))
149  return false;
150  }
151  if (processHea)
152  {
153  if (!cb.process(health))
154  return false;
155  }
156  }
157  }
158  }
159  catch (gnsstk::Exception& exc)
160  {
161  rv = false;
162  cerr << exc << endl;
163  }
164  catch (std::exception& exc)
165  {
166  rv = false;
167  cerr << exc.what() << endl;
168  }
169  catch (...)
170  {
171  rv = false;
172  cerr << "Unknown exception" << endl;
173  }
174  return rv;
175  }
176 
177 
178  std::string SEMNavDataFactory ::
179  getFactoryFormats() const
180  {
181  if (procNavTypes.empty() ||
182  (procNavTypes.count(NavMessageType::Almanac) > 0) ||
183  (procNavTypes.count(NavMessageType::Health) > 0))
184  {
185  return "SEM";
186  }
187  return "";
188  }
189 
190 
191  bool SEMNavDataFactory ::
192  convertToOrbit(const SEMData& navIn, NavDataPtr& navOut)
193  {
194  bool rv = true;
195  GPSLNavAlm *gps;
196  navOut = std::make_shared<GPSLNavAlm>();
197  gps = dynamic_cast<GPSLNavAlm*>(navOut.get());
198  // NavData
199  fillNavData(navIn, navOut);
200  // OrbitDataKepler
201  gps->Toe = GPSWeekSecond(navIn.week, navIn.Toa);
202  // Toc, which is used to generate the clock corrections
203  // using af0 and af1, is the same as Toa in the almanac
204  // context.
205  gps->Toc = gps->Toe;
206  gps->fixFit();
207  // Transmit time is set to beginFit so that User-type
208  // searches will work. SEMData has a xmit_time field
209  // but it's always set to 0. Not sure why it's even
210  // there.
211  gps->xmitTime = gps->beginFit;
212  gps->timeStamp = gps->xmitTime;
213  gps->health = ((navIn.SV_health == 0) ? SVHealth::Healthy :
214  SVHealth::Unhealthy);
215  // not in almanac data.
216  gps->Cuc = 0.0;
217  gps->Cus = 0.0;
218  gps->Crc = 0.0;
219  gps->Crs = 0.0;
220  gps->Cic = 0.0;
221  gps->Cis = 0.0;
222  gps->M0 = navIn.M0;
223  gps->dn = 0.0;
224  gps->dndot = 0.0; // no dndot in SEM or in GPS LNav
225  gps->ecc = navIn.ecc;
226  gps->Ahalf = navIn.Ahalf;
227  gps->A = navIn.Ahalf * navIn.Ahalf;
228  gps->Adot = 0.0; // no Adot in SEM or in GPS LNav
229  gps->OMEGA0 = navIn.OMEGA0;
230  gps->i0 = navIn.i_total;
231  gps->w = navIn.w;
232  gps->OMEGAdot = navIn.OMEGAdot;
233  gps->idot = navIn.i_offset;
234  gps->af0 = navIn.AF0;
235  gps->af1 = navIn.AF1;
236  gps->af2 = 0.0;
237  gps->tlm = 0; // tlm not available in SEM nav
238  return rv;
239  }
240 
241 
242  bool SEMNavDataFactory ::
243  convertToHealth(const SEMData& navIn, NavDataPtr& healthOut)
244  {
245  bool rv = true;
246  GPSLNavHealth *gps;
247  healthOut = std::make_shared<GPSLNavHealth>();
248  gps = dynamic_cast<GPSLNavHealth*>(healthOut.get());
249  // NavData
250  fillNavData(navIn, healthOut);
251  // this is the only timestamp we have from SEM
252  gps->timeStamp = GPSWeekSecond(navIn.week, navIn.Toa);
253  // GPSLNavHealth
254  gps->svHealth = navIn.SV_health;
255  return rv;
256  }
257 
258 
259  void SEMNavDataFactory ::
260  fillNavData(const SEMData& navIn, NavDataPtr& navOut)
261  {
262  // NavData
263  // SEM isn't really transmitted, so we set the sats the same
264  navOut->signal.sat = SatID(navIn.PRN,SatelliteSystem::GPS);
265  navOut->signal.xmitSat = SatID(navIn.PRN,SatelliteSystem::GPS);
266  // we can't obtain these from SEM nav, so just assume L1 C/A
267  navOut->signal.obs = ObsID(ObservationType::NavMsg, CarrierBand::L1,
268  TrackingCode::CA);
269  navOut->signal.nav = NavType::GPSLNAV;
270  }
271 }
gnsstk::NavDataPtr
std::shared_ptr< NavData > NavDataPtr
Factories instantiate these in response to find() requests.
Definition: NavData.hpp:62
gnsstk::OrbitDataKepler::idot
double idot
Rate of inclination angle (rad/sec)
Definition: OrbitDataKepler.hpp:193
gnsstk::GPSLNavHealth::svHealth
uint8_t svHealth
6-bit or 8-bit health.
Definition: GPSLNavHealth.hpp:80
gnsstk::SEMData::AF1
FormattedDouble AF1
sec/sec
Definition: SEMData.hpp:96
gnsstk::NavDataFactoryCallback::process
virtual bool process(const NavDataPtr &navOut)
Definition: NavDataFactoryCallback.hpp:60
gnsstk::SEMData::i_offset
FormattedDouble i_offset
redians
Definition: SEMData.hpp:88
gnsstk::OrbitDataKepler::Cis
double Cis
Sine inclination (rad)
Definition: OrbitDataKepler.hpp:180
gnsstk::OrbitDataKepler::A
double A
Semi-major axis (m)
Definition: OrbitDataKepler.hpp:186
L1
gnsstk::Matrix< double > L1
Definition: Matrix_LUDecomp_T.cpp:46
gnsstk::OrbitDataKepler::af2
double af2
SV clock drift rate (sec/sec**2)
Definition: OrbitDataKepler.hpp:197
gnsstk::SEMData::week
short week
Definition: SEMData.hpp:103
gnsstk::NavDataFactoryWithStore::OffsetCvtMap
std::map< TimeCvtKey, OffsetEpochMap > OffsetCvtMap
Map from the time system conversion pair to the conversion objects.
Definition: NavDataFactoryWithStore.hpp:74
gnsstk::NavMessageMap
std::map< NavMessageType, NavSatMap > NavMessageMap
Map nav message type to the rest of the storage.
Definition: NavData.hpp:71
gnsstk::OrbitDataKepler::ecc
double ecc
Eccentricity.
Definition: OrbitDataKepler.hpp:185
NavDataFactoryStoreCallback.hpp
gnsstk::SEMStream
Definition: SEMStream.hpp:68
gnsstk::SEMData
Definition: SEMData.hpp:73
gnsstk::SEMData::w
FormattedDouble w
radians
Definition: SEMData.hpp:93
gnsstk::SEMData::PRN
short PRN
Definition: SEMData.hpp:84
gnsstk::OrbitDataKepler::OMEGAdot
double OMEGAdot
Rate of Rt ascension (rad/sec)
Definition: OrbitDataKepler.hpp:192
SEMHeader.hpp
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
gnsstk::SatID
Definition: SatID.hpp:89
gnsstk::SEMData::ecc
FormattedDouble ecc
no units
Definition: SEMData.hpp:87
gnsstk::OrbitDataKepler::Cuc
double Cuc
Cosine latitude (rad)
Definition: OrbitDataKepler.hpp:175
GPSLNavHealth.hpp
gnsstk::SEMData::AF0
FormattedDouble AF0
sec
Definition: SEMData.hpp:95
gnsstk::GPSLNavData::tlm
uint32_t tlm
The TLM message from word 1 of the subframe.
Definition: GPSLNavData.hpp:81
gnsstk::OrbitDataKepler::w
double w
Argument of perigee (rad)
Definition: OrbitDataKepler.hpp:191
gnsstk::OrbitDataKepler::Toe
CommonTime Toe
Orbit epoch.
Definition: OrbitDataKepler.hpp:171
gnsstk::OrbitDataKepler::Crs
double Crs
Sine radius (m)
Definition: OrbitDataKepler.hpp:178
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
gnsstk::OrbitDataKepler::xmitTime
CommonTime xmitTime
Time of transmission of the start of the data.
Definition: OrbitDataKepler.hpp:170
gnsstk::NavData::timeStamp
CommonTime timeStamp
Definition: NavData.hpp:173
gnsstk::OrbitDataKepler::Adot
double Adot
Rate of semi-major axis (m/sec)
Definition: OrbitDataKepler.hpp:188
gnsstk::NavDataFactoryCallback
Definition: NavDataFactoryCallback.hpp:54
gnsstk::OrbitDataKepler::M0
double M0
Mean anomaly (rad)
Definition: OrbitDataKepler.hpp:182
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::SEMHeader
Definition: SEMHeader.hpp:72
gnsstk::NavDataFactoryStoreCallback
Definition: NavDataFactoryStoreCallback.hpp:52
gnsstk::OrbitDataKepler::dndot
double dndot
Rate of correction to mean motion (rad/sec/sec)
Definition: OrbitDataKepler.hpp:184
gnsstk::SEMData::OMEGAdot
FormattedDouble OMEGAdot
redians
Definition: SEMData.hpp:90
gnsstk::OrbitDataKepler::Cus
double Cus
Sine latitude (rad)
Definition: OrbitDataKepler.hpp:176
gnsstk::ObsID
Definition: ObsID.hpp:82
gnsstk::OrbitDataKepler::Ahalf
double Ahalf
Square Root of semi-major axis (m**.5)
Definition: OrbitDataKepler.hpp:187
gnsstk::OrbitDataKepler::Toc
CommonTime Toc
Clock epoch.
Definition: OrbitDataKepler.hpp:172
gnsstk::SEMData::i_total
double i_total
radians
Definition: SEMData.hpp:89
gnsstk::NavFit::beginFit
CommonTime beginFit
Time at beginning of fit interval.
Definition: NavFit.hpp:54
gnsstk::SEMData::Ahalf
FormattedDouble Ahalf
m**0.5
Definition: SEMData.hpp:91
gnsstk::SEMData::M0
FormattedDouble M0
radians
Definition: SEMData.hpp:94
gnsstk::SEMData::Toa
long Toa
Definition: SEMData.hpp:102
gnsstk::GPSLNavAlm::fixFit
void fixFit()
Fill the beginFit and endFit values for this object.
Definition: GPSLNavAlm.cpp:65
gnsstk::SEMData::SV_health
short SV_health
Definition: SEMData.hpp:97
gnsstk::OrbitDataKepler::i0
double i0
Inclination (rad)
Definition: OrbitDataKepler.hpp:190
example3.data
data
Definition: example3.py:22
gnsstk::OrbitDataKepler::Cic
double Cic
Cosine inclination (rad)
Definition: OrbitDataKepler.hpp:179
gnsstk::OrbitDataKepler::Crc
double Crc
Cosine radius (m)
Definition: OrbitDataKepler.hpp:177
gnsstk::NavSignalID
Class used to identify navigation data signal types.
Definition: NavSignalID.hpp:54
GPSWeekSecond.hpp
std
Definition: Angle.hpp:142
gnsstk::OrbitDataKepler::af0
double af0
SV clock error (sec)
Definition: OrbitDataKepler.hpp:195
SEMStream.hpp
SEMNavDataFactory.hpp
gnsstk::OrbitDataKepler::health
SVHealth health
SV health status.
Definition: OrbitDataKepler.hpp:173
gnsstk::NavNearMessageMap
std::map< NavMessageType, NavNearSatMap > NavNearMessageMap
Map nav message type to the rest of the storage.
Definition: NavData.hpp:81
gnsstk::OrbitDataKepler::OMEGA0
double OMEGA0
Longitude of ascending node at weekly epoch (rad)
Definition: OrbitDataKepler.hpp:189
gnsstk::GPSLNavAlm
Class containing data elements unique to GPS LNav almanac pages.
Definition: GPSLNavAlm.hpp:50
gnsstk::SEMData::OMEGA0
FormattedDouble OMEGA0
radians
Definition: SEMData.hpp:92
gnsstk::OrbitDataKepler::af1
double af1
SV clock drift (sec/sec)
Definition: OrbitDataKepler.hpp:196
gnsstk::OrbitDataKepler::dn
double dn
Correction to mean motion (rad/sec)
Definition: OrbitDataKepler.hpp:183
gnsstk::GPSLNavHealth
Definition: GPSLNavHealth.hpp:51


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