CNavParityFilter.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 "CNavParityFilter.hpp"
40 #include "CNavFilterData.hpp"
41 
42 namespace gnsstk
43 {
44 
45  class CRC24Q
46  {
47  public:
48  static const std::size_t bit_count = 24;
49 
50  // 0,1,3,4,5,6,7,10,11,14,17,18,23,24
51  //1000 0110 0100 1100 1111 1011: 0x864cfb
53  : rem(0) , poly(0x864cfb)
54  {};
55 
56  void process_bit( bool bit)
57  {
58  rem ^= ( bit ? 0x00800000 : 0 );
59  bool const pdiv = static_cast<bool>( rem & 0x00800000 );
60  rem <<= 1;
61  if ( pdiv )
62  rem ^= poly;
63  };
64 
65  void process_bits( uint8_t bits, std::size_t bit_count = 8)
66  {
67  bits <<= 8 - bit_count;
68 
69  for ( std::size_t i = bit_count ; i > 0u ; --i, bits <<= 1u )
70  process_bit( static_cast<bool>(bits & 0x80) );
71  };
72 
73  void process_bytes( void const *buffer, std::size_t byte_count)
74  {
75  uint8_t const *b = static_cast<uint8_t const *>(buffer);
76  for (int i=0; i<byte_count; i++)
77  process_bits(*b++);
78  };
79 
80  uint32_t checksum() const
81  { return rem & 0x00ffffff; };
82 
83  private:
84  uint32_t rem;
85  const uint32_t poly;
86  };
87 
88 
91  {
92  }
93 
95  validate(NavMsgList& msgBitsIn, NavMsgList& msgBitsOut)
96  {
97  NavMsgList::iterator i;
98  // check parity of each subframe and put the valid ones in
99  // the output
100  for (i = msgBitsIn.begin(); i != msgBitsIn.end(); i++)
101  {
102  CNavFilterData *fd = dynamic_cast<CNavFilterData*>(*i);
103 
104  CRC24Q crc;
105  int numBits = fd->pnb->getNumBits();
106  for (int n=0; n < numBits; n++)
107  crc.process_bit(fd->pnb->asBool(n));
108 
109  if (crc.checksum()==0)
110  accept(*i, msgBitsOut);
111  else
112  reject(*i);
113  }
114  }
115 }
CNavParityFilter.hpp
gnsstk::CRC24Q::bit_count
static const std::size_t bit_count
Definition: CNavParityFilter.cpp:48
gnsstk::CRC24Q::CRC24Q
CRC24Q()
Definition: CNavParityFilter.cpp:52
gnsstk::CRC24Q::checksum
uint32_t checksum() const
Definition: CNavParityFilter.cpp:80
gnsstk::CRC24Q::process_bytes
void process_bytes(void const *buffer, std::size_t byte_count)
Definition: CNavParityFilter.cpp:73
gnsstk::NavFilter::reject
void reject(NavFilterKey *data)
Definition: NavFilter.hpp:185
gnsstk::CRC24Q::poly
const uint32_t poly
Definition: CNavParityFilter.cpp:85
gnsstk::CRC24Q
Definition: CNavParityFilter.cpp:45
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::CRC24Q::process_bit
void process_bit(bool bit)
Definition: CNavParityFilter.cpp:56
gnsstk::CNavParityFilter::CNavParityFilter
CNavParityFilter()
Definition: CNavParityFilter.cpp:90
gnsstk::CNavFilterData
Definition: CNavFilterData.hpp:48
gnsstk::PackedNavBits::asBool
bool asBool(const unsigned bitNum) const
Definition: PackedNavBits.cpp:606
CNavFilterData.hpp
gnsstk::CNavParityFilter::validate
virtual void validate(NavMsgList &msgBitsIn, NavMsgList &msgBitsOut)
Definition: CNavParityFilter.cpp:95
gnsstk::CRC24Q::process_bits
void process_bits(uint8_t bits, std::size_t bit_count=8)
Definition: CNavParityFilter.cpp:65
gnsstk::NavFilter::NavMsgList
std::list< NavFilterKey * > NavMsgList
Definition: NavFilter.hpp:58
gnsstk::NavFilter::accept
void accept(NavFilterKey *data, NavMsgList &msgBitsOut)
Definition: NavFilter.hpp:172
gnsstk::CNavFilterData::pnb
PackedNavBits * pnb
Definition: CNavFilterData.hpp:57
gnsstk::PackedNavBits::getNumBits
size_t getNumBits() const
Definition: PackedNavBits.cpp:240
gnsstk::CRC24Q::rem
uint32_t rem
Definition: CNavParityFilter.cpp:81


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