AshtechData.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 "StringUtils.hpp"
40 #include "BinUtils.hpp"
41 
42 #include "AshtechData.hpp"
43 #include "AshtechStream.hpp"
44 
45 using namespace std;
46 
47 namespace gnsstk
48  {
49  //---------------------------------------------------------------------------
50  //---------------------------------------------------------------------------
51  // This is the string that preceeds every message from the receiver.
52  const string AshtechData::preamble("$PASHR,");
53 
54  // This is the string that is at the end of every message.
55  const string AshtechData::trailer("\015\012");
56 
57  // Set to zero for no debugging output
58  // set to 1 to output text messages about decode/format/range errors
59  // set to 2 to add a hex dump of those messages
60  // set to 3+ to add the tossed bytes whether or not they are bad
61  int AshtechData::debugLevel = 0;
62 
63  // set true to print a hex dump of every message to cout
64  bool AshtechData::hexDump = false;
65 
66 
67  //---------------------------------------------------------------------------
68  void AshtechData::reallyGetRecord(FFStream& ffs)
69  {
70  // Note that this will generate a bad_cast exception if it doesn't work.
71  AshtechStream& stream=dynamic_cast<AshtechStream&>(ffs);
72 
73  // make sure the object is reset before starting the search
74  clear(fmtbit | lenbit | crcbit);
75  id.clear();
76 
77  readHeader(stream);
78  } // AshtechData::reallyGetRecord()
79 
80 
81  //---------------------------------------------------------------------------
82  void AshtechData::readHeader(AshtechStream& stream)
83  {
84  string& rawData = stream.rawData;
85  size_t i;
86 
87  while (stream)
88  {
89  if (rawData.length() < preamble.length()+4)
90  {
91  char buff[512];
92  stream.read(buff, sizeof(buff));
93  rawData.append(buff, stream.gcount());
94  }
95 
96  if (stream.header)
97  i = rawData.find(preamble, preamble.length());
98  else
99  i = rawData.find(preamble);
100  stream.header = false;
101 
102  if (i)
103  {
104  i = min (rawData.length(), i);
105  if (debugLevel>2)
106  cout << "Tossing " << i
107  << " bytes at offset: 0x" << hex << stream.getRawPos() << dec
108  << endl;
109  if (hexDump)
110  StringUtils::hexDumpData(cout, rawData.substr(0,i));
111  rawData.erase(0, i);
112  }
113  else
114  {
115  id = rawData.substr(7,3);
116  break;
117  }
118  }
119  stream.header = true;
120  }
121 
122  //---------------------------------------------------------------------------
123  void AshtechData::readBody(AshtechStream& stream)
124  {
125  string& rawData = stream.rawData;
126  const static string term = trailer+preamble;
127  size_t term_pos = rawData.find(term);
128 
129  while (stream)
130  {
131  term_pos = rawData.find(term);
132  if (term_pos > 0 && term_pos < rawData.length())
133  break;
134 
135  if (stream)
136  {
137  char cbuff[512];
138  stream.read(cbuff, sizeof(cbuff));
139  rawData.append(cbuff, stream.gcount());
140  }
141  else
142  break;
143  }
144 
145  term_pos += trailer.length();
146  if (hexDump)
147  StringUtils::hexDumpData(cout, rawData.substr(0,term_pos));
148 
149  decode(rawData.substr(0, term_pos));
150 
151  if (!good() && debugLevel>1)
152  cout << "bad decode starting at at offset 0x"
153  << hex << stream.getRawPos() << dec
154  << endl;
155 
156  rawData.erase(0, term_pos);
157  stream.header=false;
158  }
159 
160 
161  //---------------------------------------------------------------------------
162  void AshtechData::dump(ostream& out) const noexcept
163  {
164  ostringstream oss;
165  oss << getName() << " : id:" << id
166  << " checksum:" << hex << checksum
167  << " rdstate:" << rdstate() << dec;
168  if (crcerr())
169  oss << "-crc";
170  if (fmterr())
171  oss << "-fmt";
172  if (lenerr())
173  oss << "-len";
174  if (parerr())
175  oss << "-par";
176 
177  out << oss.str() << endl;
178  } // AshtechData::dump()
179 } // namespace gnsstk
gnsstk::dump
void dump(vector< SatPass > &SatPassList, ostream &os, bool rev, bool dbug)
Definition: SatPassUtilities.cpp:59
AshtechData.hpp
gnsstk::lenbit
static const std::ios_base::iostate lenbit
Definition: DataStatus.hpp:88
gnsstk::FFStream
Definition: FFStream.hpp:119
StringUtils.hpp
gnsstk::crcbit
static const std::ios_base::iostate crcbit
Define additional/other bits are the data requires.
Definition: DataStatus.hpp:86
gnsstk::fmtbit
static const std::ios_base::iostate fmtbit
Definition: DataStatus.hpp:87
AshtechStream.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::AshtechStream
Definition: AshtechStream.hpp:54
gnsstk::StringUtils::hexDumpData
void hexDumpData(const std::string &data, std::ostream &s, const HexDumpDataConfig &cfg)
Definition: StringUtils.cpp:62
gnsstk::min
T min(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
Definition: SparseMatrix.hpp:858
gnsstk::AshtechStream::header
bool header
Definition: AshtechStream.hpp:82
BinUtils.hpp
std
Definition: Angle.hpp:142
gnsstk::AshtechStream::rawData
std::string rawData
The raw bytes read from the file.
Definition: AshtechStream.hpp:78
gnsstk::AshtechStream::getRawPos
std::streampos getRawPos()
Definition: AshtechStream.hpp:85


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