CNav2Filter_T.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 "TestUtil.hpp"
40 #include "NavFilterMgr.hpp"
41 #include "CNavFilterData.hpp"
43 #include "CNav2SanityFilter.hpp"
44 #include "CommonTime.hpp"
45 #include "GPSWeekSecond.hpp"
46 #include "NavFilter.hpp"
47 #include "StringUtils.hpp"
48 #include "TimeString.hpp"
49 #include "TimeSystem.hpp"
50 
51 using namespace std;
52 using namespace gnsstk;
53 
54 
56 {
57 public:
58  CNav2Filter_T();
59  ~CNav2Filter_T();
60 
61  unsigned loadData();
62 
64  unsigned noFilterTest();
66  unsigned testCNav2Sanity();
68  unsigned testCNav2Combined();
69 
70  // This is a list of the PackedNavBit messages that are created from the
71  // static strings contained in the loadData( ) method.
72  list<PackedNavBits*> messageList;
73 
74  // This is a parallel list of CNavFilterData objects created from
75  // the PackedNavBit objects. These are all believed to be valid.
76  list<CNavFilterData> cNavList;
77 };
78 
79 //-------------------------------------------------------------------
82 {
83  // In the case of this test. This method doesn't have to do anything.
84 }
85 
86 
89 {
90  for (auto& mli : messageList)
91  {
92  delete mli;
93  }
94 }
95 
96 
97 //-------------------------------------------------------------------
98 // At the time of the original writing, all these examples are
99 // hand-generated as no validated CNAV-2 data are available at this
100 // time. The following assumputions are made:
101 // 1.) Message data are stored one frame to a PackedNavBits message.
102 // 2.) The TOI, ITOW, week number, PRN, and page number are generated
103 // via the test algorithm. The remaining data are zero except where
104 // modified to exercise the change detection.
105 // 3.) The messages cycle through subframe 3 page 1 - subframe 3 page 6.
106 // NOTE: There is no reason to expect that this will be the
107 // operational pattern. The goal is to exercise all the
108 // valid subframes.
109 //
110 unsigned CNav2Filter_T ::
112 {
113  ObsID oidCNAV2(ObservationType::NavMsg, CarrierBand::L1, TrackingCode::L1CDP);
114  unsigned PRN = 1;
115  SatID sid(PRN,SatelliteSystem::GPS);
116  CommonTime ct = GPSWeekSecond(2000,86400.0);
117  double MESSAGE_INTERVAL = 18.0; // CNAV-2 message rate
118  size_t MAX_PAGE_NUMBER = 6;
119  unsigned pageNum = 1;
120  size_t NUMBER_MESSAGES = 12;
121  string RX_STRING = "unk";
122  unsigned TWO_HOURS = 7200;
123 
124  for (unsigned i=0; i<NUMBER_MESSAGES; i++)
125  {
126 
127  PackedNavBits* pnb = new PackedNavBits(sid,oidCNAV2,RX_STRING,ct);
128 
129  unsigned week = static_cast<GPSWeekSecond>(ct).week;
130  double dSOW = static_cast<GPSWeekSecond>(ct).sow;
131  unsigned SOW = (unsigned) dSOW;
132  SOW += 18;
133  if (SOW>=FULLWEEK)
134  SOW -= FULLWEEK;
135  unsigned ITOW = SOW / TWO_HOURS;
136  unsigned TOI = SOW - (ITOW * TWO_HOURS);
137  TOI = TOI / 18;
138  unsigned long zeroes = 0x00000000L;
139 
140  pnb->addUnsignedLong(TOI,9,1); // Subframe 1
141  // Subframe 2
142  pnb->addUnsignedLong(week,13,1); // Week
143  pnb->addUnsignedLong(ITOW,8,1); // ITOW
144  for (int i1=0;i1<18;i1++) // Add 579 zeroes to pad data space.
145  { // That's 18 32 bits words plus three bits.
146  pnb->addUnsignedLong(zeroes,32,1);
147  }
148  pnb->addUnsignedLong(zeroes,3,1);
149  // Subframe 3
150  pnb->addUnsignedLong(PRN,8,1); // PRN ID
151  pnb->addUnsignedLong(pageNum,6,1); // subframe ID
152  for (int i1=0;i1<8;i1++) // Add 260 zeroes to pad data space.
153  { // That's 8 32 bits, plus 4 bits
154  pnb->addUnsignedLong(zeroes,32,1);
155  }
156  pnb->addUnsignedLong(zeroes,4,1);
157 
158  pnb->trimsize();
159 
160  messageList.push_back(pnb);
161 
162  CNavFilterData cnavFilt(pnb);
163  cNavList.push_back(cnavFilt);
164 
165  pageNum++;
166  if (pageNum>MAX_PAGE_NUMBER)
167  pageNum = 1;
168  ct += MESSAGE_INTERVAL;
169  }
170 
171  return 0;
172 }
173 
174 //-------------------------------------------------------------------
175 unsigned CNav2Filter_T ::
177 {
178  TUDEF("CNav NoFilter", "validate");
179 
180  NavFilterMgr mgr;
181  unsigned long count = 0;
182 
183  list<CNavFilterData>::iterator it;
184  for (it=cNavList.begin(); it!=cNavList.end(); it++)
185  {
186  CNavFilterData& fd = *it;
188  // We could do an assert for each record but that would be
189  // stupid. Just compare the final counts.
190  count += l.size();
191  }
192  int expected = cNavList.size();
193  TUASSERTE(unsigned long, expected, count);
194  TURETURN();
195 }
196 
197 //-------------------------------------------------------------------
198 unsigned CNav2Filter_T ::
200 {
201  TUDEF("CNav2SanityFilter", "validate");
202 
203  NavFilterMgr mgr;
204  unsigned long rejectCount = 0;
205  unsigned long acceptCount = 0;
206  CNav2SanityFilter filtSanity;
207 
208  mgr.addFilter(&filtSanity);
209 
210  // Test with valid data
211  list<CNavFilterData>::iterator it;
212  for (it=cNavList.begin(); it!=cNavList.end(); it++)
213  {
214  CNavFilterData& fd = *it;
216  gnsstk::NavFilter::NavMsgList::const_iterator nmli;
217 
218  acceptCount += l.size();
219  rejectCount += filtSanity.rejected.size();
220  }
221  int expected = cNavList.size();
222  TUASSERTE(unsigned long, expected, acceptCount);
223  TUASSERTE(unsigned long, 0, rejectCount);
224 
225  // Clone a valid message, modify the ITOW, and
226  // verify that the filter rejects the data.
227  acceptCount = 0;
228  rejectCount = 0;
229  list<PackedNavBits*>::iterator it2 = messageList.begin();
230  PackedNavBits* p = *it2;
231 
232  // There are 84 two-hour epochs in a week. That's 54 base 16.
233  // An ITOW of a solid 7 bits would be too large.
234  PackedNavBits* pnb = p->clone();
235  unsigned long wordBad = 0x0000003F;
236  pnb->insertUnsignedLong(wordBad,22,8);
237  CNavFilterData fd(pnb);
239  acceptCount = l.size();
240  rejectCount = filtSanity.rejected.size();
241  TUASSERTE(unsigned long, 0, acceptCount);
242  TUASSERTE(unsigned long, 1, rejectCount);
243  delete pnb;
244 
245  // There are 400 18s intervals in a two-hour period.
246  // 0x190.
247  // An TOI of a 0x1FF is too large.
248  PackedNavBits* pnb2 = p->clone();
249  wordBad = 0x000001FF;
250  pnb2->insertUnsignedLong(wordBad,0,9);
251  CNavFilterData fd2(pnb2);
253  acceptCount = l2.size();
254  rejectCount = filtSanity.rejected.size();
255  TUASSERTE(unsigned long, 0, acceptCount);
256  TUASSERTE(unsigned long, 1, rejectCount);
257  delete pnb2;
258 
259  // The current week is 2000. Reset it to 1999
260  // and verify a failure.
261  // 2000 = 0x7CF.
262  PackedNavBits* pnb3 = p->clone();
263  wordBad = 0x000007CF;
264  pnb3->insertUnsignedLong(wordBad,9,13);
265  CNavFilterData fd3(pnb3);
267  acceptCount = l3.size();
268  rejectCount = filtSanity.rejected.size();
269  TUASSERTE(unsigned long, 0, acceptCount);
270  TUASSERTE(unsigned long, 1, rejectCount);
271  delete pnb3;
272 
273  // A PRN of 0 doesn't match the test value.
274  PackedNavBits* pnb4 = p->clone();
275  wordBad = 0x00000000;
276  unsigned long bitOffset = 609;
277  pnb4->insertUnsignedLong(wordBad,bitOffset,8);
278  CNavFilterData fd4(pnb4);
280  acceptCount = l4.size();
281  rejectCount = filtSanity.rejected.size();
282  TUASSERTE(unsigned long, 0, acceptCount);
283  TUASSERTE(unsigned long, 1, rejectCount);
284  delete pnb4;
285 
286  // A page number of 0 doesn't match the test value.
287  PackedNavBits* pnb5 = p->clone();
288  bitOffset = 609 + 8;
289  pnb5->insertUnsignedLong(wordBad,bitOffset,6);
290  CNavFilterData fd5(pnb5);
292  acceptCount = l5.size();
293  rejectCount = filtSanity.rejected.size();
294  TUASSERTE(unsigned long, 0, acceptCount);
295  TUASSERTE(unsigned long, 1, rejectCount);
296  delete pnb5;
297 
298  TURETURN();
299 }
300 
301 /*
302 //-------------------------------------------------------------------
303 unsigned CNav2Filter_T ::
304 testCNavTOW()
305 {
306  TUDEF("CNavTOWFilter", "validate");
307 
308  NavFilterMgr mgr;
309  unsigned long rejectCount = 0;
310  unsigned long acceptCount = 0;
311  CNavTOWFilter filtTOW;
312 
313  mgr.addFilter(&filtTOW);
314 
315  list<CNavFilterData>::iterator it;
316  for (it=cNavList.begin(); it!=cNavList.end(); it++)
317  {
318  CNavFilterData& fd = *it;
319  gnsstk::NavFilter::NavMsgList l = mgr.validate(&fd);
320  rejectCount += filtTOW.rejected.size();
321  acceptCount += l.size();
322  }
323  int expected = cNavList.size();
324  TUASSERTE(unsigned long, expected, acceptCount);
325  TUASSERTE(unsigned long, 0, rejectCount);
326 
327  // --- NOW GENERATE SOME INVALID MESSAGES AND VERIFY THAT
328  // --- THEY ARE REJECTED
329  // Modify a message to have an invalid TOW count.
330  acceptCount = 0;
331  rejectCount = 0;
332  CNavFilterData fd;
333  list<PackedNavBits*>::iterator it2 = messageList.begin();
334  PackedNavBits* p = *it2;
335 
336  // Message with invalid too large) TOW
337  PackedNavBits* pnbBadTOWMsg = p->clone();
338  unsigned long badTOW = 604800;
339  pnbBadTOWMsg->insertUnsignedLong(badTOW, 20, 17, 6);
340 
341  // Message with invalid preamble
342  PackedNavBits* pnbBadPreamble = p->clone();
343  unsigned long badPre = 0;
344  pnbBadPreamble->insertUnsignedLong(badPre, 0, 8);
345 
346  acceptCount = 0;
347  rejectCount = 0;
348  CNavFilterData fdBadTOW(pnbBadTOWMsg);
349  gnsstk::NavFilter::NavMsgList l = mgr.validate(&fdBadTOW);
350  rejectCount += filtTOW.rejected.size();
351  acceptCount += l.size();
352 
353  CNavFilterData fdBadPreamble(pnbBadPreamble);
354  l = mgr.validate(&fdBadPreamble);
355  rejectCount += filtTOW.rejected.size();
356  acceptCount += l.size();
357 
358  // Bad Message Type tests
359  // Test the invalid MT immediately above/below the valid ranges.
360  unsigned long badMT[] = { 9, 16, 29, 40};
361  int badMTCount = 4;
362  PackedNavBits* pnbBadMT = p->clone();
363  for (int i=0; i<badMTCount; i++)
364  {
365  pnbBadMT->insertUnsignedLong(badMT[i], 14, 6);
366  CNavFilterData fdBadMT(pnbBadMT);
367  l = mgr.validate(&fdBadMT);
368  rejectCount += filtTOW.rejected.size();
369  acceptCount += l.size();
370  }
371 
372  unsigned long expReject = 2 + badMTCount;
373  TUASSERTE(unsigned long, 0, acceptCount);
374  TUASSERTE(unsigned long, expReject, rejectCount);
375 
376  TURETURN();
377 }
378 */
379 //-------------------------------------------------------------------
380 unsigned CNav2Filter_T ::
382 {
383  TUDEF("CNavFilter-Combined", "validate");
384 
385  NavFilterMgr mgr;
386  unsigned long rejectCount = 0;
387  CNav2SanityFilter filtSanity;
388 
389  mgr.addFilter(&filtSanity);
390 
391  list<CNavFilterData>::iterator it;
392  for (it=cNavList.begin(); it!=cNavList.end(); it++)
393  {
394  CNavFilterData& fd = *it;
396  // if l is empty, the subframe was rejected.
397  rejectCount += l.empty();
398  }
399  int expected = cNavList.size();
400  TUASSERTE(unsigned long, 0, rejectCount);
401  TURETURN();
402 }
403 
404 //-------------------------------------------------------------------
405 int main()
406 {
407  unsigned errorTotal = 0;
408 
409  CNav2Filter_T testClass;
410 
411  errorTotal += testClass.loadData();
412  errorTotal += testClass.testCNav2Sanity();
413  errorTotal += testClass.testCNav2Combined();
414 
415  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
416 
417  return errorTotal; // Return the total number of errors
418 }
TimeSystem.hpp
CNav2Filter_T::messageList
list< PackedNavBits * > messageList
Definition: CNav2Filter_T.cpp:72
L1
gnsstk::Matrix< double > L1
Definition: Matrix_LUDecomp_T.cpp:46
StringUtils.hpp
main
int main()
Definition: CNav2Filter_T.cpp:405
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::FULLWEEK
const long FULLWEEK
Seconds per whole week.
Definition: TimeConstants.hpp:60
gnsstk::SatID
Definition: SatID.hpp:89
gnsstk::NavFilter::rejected
NavMsgList rejected
Definition: NavFilter.hpp:137
CNav2Filter_T::loadData
unsigned loadData()
Definition: CNav2Filter_T.cpp:111
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
NavFilter.hpp
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
gnsstk::NavFilterMgr
Definition: NavFilterMgr.hpp:170
CNav2SanityFilter.hpp
CNav2Filter_T::noFilterTest
unsigned noFilterTest()
Test to make sure that with no filters, no data is removed.
Definition: CNav2Filter_T.cpp:176
CNavCrossSourceFilter.hpp
TestUtil.hpp
gnsstk::NavFilterMgr::addFilter
void addFilter(NavFilter *filt)
Definition: NavFilterMgr.cpp:50
gnsstk::PackedNavBits::insertUnsignedLong
void insertUnsignedLong(const unsigned long value, const int startBit, const int numBits, const int scale=1)
Definition: PackedNavBits.cpp:889
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::PackedNavBits::trimsize
void trimsize()
Definition: PackedNavBits.cpp:938
NavFilterMgr.hpp
gnsstk::ObsID
Definition: ObsID.hpp:82
CNav2Filter_T::~CNav2Filter_T
~CNav2Filter_T()
Definition: CNav2Filter_T.cpp:88
gnsstk::CNavFilterData
Definition: CNavFilterData.hpp:48
gnsstk::CommonTime
Definition: CommonTime.hpp:84
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
CNavFilterData.hpp
CNav2Filter_T::testCNav2Combined
unsigned testCNav2Combined()
Test the combination of sanity,and cross-source filters.
Definition: CNav2Filter_T.cpp:381
gnsstk::PackedNavBits::clone
PackedNavBits * clone() const
Definition: PackedNavBits.cpp:174
CNav2Filter_T
Definition: CNav2Filter_T.cpp:55
GPSWeekSecond.hpp
CNav2Filter_T::testCNav2Sanity
unsigned testCNav2Sanity()
Test the CNAV-2 sanity filter.
Definition: CNav2Filter_T.cpp:199
CNav2Filter_T::CNav2Filter_T
CNav2Filter_T()
Definition: CNav2Filter_T.cpp:81
CommonTime.hpp
std
Definition: Angle.hpp:142
gnsstk::NavFilterMgr::validate
NavFilter::NavMsgList validate(NavFilterKey *msgBits)
Definition: NavFilterMgr.cpp:57
CNav2Filter_T::cNavList
list< CNavFilterData > cNavList
Definition: CNav2Filter_T.cpp:76
gnsstk::NavFilter::NavMsgList
std::list< NavFilterKey * > NavMsgList
Definition: NavFilter.hpp:58
gnsstk::PackedNavBits::addUnsignedLong
void addUnsignedLong(const unsigned long value, const int numBits, const int scale)
Definition: PackedNavBits.cpp:613
gnsstk::PackedNavBits
Definition: PackedNavBits.hpp:70
gnsstk::CNav2SanityFilter
Definition: CNav2SanityFilter.hpp:56
TimeString.hpp


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