BinexData.hpp
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 
44 #ifndef GNSSTK_BINEXDATA_HPP
45 #define GNSSTK_BINEXDATA_HPP
46 
47 #include "gnsstkplatform.h"
48 #include "gnsstk_export.h"
49 #include "BinUtils.hpp"
50 #include "FFData.hpp"
51 #include "FFStream.hpp"
52 
53 namespace gnsstk
54 {
56 
57 
65  class BinexData : public FFData
66  {
67  public:
68 
69  // The endianness of the native platform
70  GNSSTK_EXPORT static const bool nativeLittleEndian;
71 
72  typedef uint32_t RecordID;
73  typedef uint8_t SyncByte;
74 
75  GNSSTK_EXPORT static const RecordID INVALID_RECORD_ID;
76 
77  GNSSTK_EXPORT static const SyncByte DEFAULT_RECORD_FLAGS;
78  GNSSTK_EXPORT static const SyncByte VALID_RECORD_FLAGS;
79 
80  // Flags indicating whether a record is reversed, whether a record
81  // is big endian, and whether a record contains an enhanced CRC.
82  // Combining these flags (via bitwise-or) helps create the
83  // synchronization byte(s) for a BINEX record.
85  {
87  eBigEndian = 0x20,
88  eEnhancedCRC = 0x08
89  };
90 
96  class UBNXI
97  {
98  public:
99 
100  GNSSTK_EXPORT static const unsigned long MIN_VALUE;
101  GNSSTK_EXPORT static const unsigned long MAX_VALUE;
102  GNSSTK_EXPORT static const unsigned char MAX_BYTES;
103 
107  UBNXI();
108 
112  UBNXI(const UBNXI& other)
113  {
114  *this = other;
115  };
116 
121  UBNXI(unsigned long ul);
122 
126  inline UBNXI&
127  operator=(const UBNXI& right)
128  {
129  value = right.value;
130  size = right.size;
131  return *this;
132  };
133 
137  inline bool
138  operator==(const UBNXI& other) const
139  {
140  return (value == other.value);
141  };
142 
146  inline bool
147  operator!=(const UBNXI& other) const
148  {
149  return (value != other.value);
150  };
151 
155  inline bool
156  operator<(const UBNXI& other) const
157  {
158  return (value < other.value);
159  };
160 
164  inline bool
165  operator<=(const UBNXI& other) const
166  {
167  return (value <= other.value);
168  };
169 
173  inline bool
174  operator>(const UBNXI& other) const
175  {
176  return (value > other.value);
177  };
178 
182  inline bool
183  operator>=(const UBNXI& other) const
184  {
185  return (value >= other.value);
186  };
187 
191  inline
192  operator unsigned long() const
193  {
194  return value;
195  };
196 
201  inline size_t
202  getSize() const
203  {
204  return size;
205  };
206 
217  size_t
218  decode(const std::string& inBuffer,
219  size_t offset = 0,
220  bool littleEndian = false);
221 
232  size_t
233  encode(std::string& outBuffer,
234  size_t offset = 0,
235  bool littleEndian = false) const;
236 
252  size_t
253  read(std::istream& strm,
254  std::string *outBuffer = NULL,
255  size_t offset = 0,
256  bool reverseBytes = false,
257  bool littleEndian = false);
258 
273  size_t
274  write(std::ostream& strm,
275  std::string *outBuffer = NULL,
276  size_t offset = 0,
277  bool reverseBytes = false,
278  bool littleEndian = false) const;
279 
280  protected:
281 
282  unsigned long value;
283  size_t size;
284  };
285 
293  class MGFZI
294  {
295  public:
296 
297  GNSSTK_EXPORT static const long long MIN_VALUE;
298  GNSSTK_EXPORT static const long long MAX_VALUE;
299  GNSSTK_EXPORT static const unsigned char MAX_BYTES;
300 
304  MGFZI();
305 
309  MGFZI(const MGFZI& other)
310  {
311  *this = other;
312  };
313 
318  MGFZI(long long ll);
319 
323  inline MGFZI&
324  operator=(const MGFZI& right)
325  {
326  value = right.value;
327  size = right.size;
328  return *this;
329  };
330 
334  inline bool
335  operator==(const MGFZI& other) const
336  {
337  return (value == other.value);
338  };
339 
343  inline bool
344  operator!=(const MGFZI& other) const
345  {
346  return (value != other.value);
347  };
348 
352  inline bool
353  operator<(const MGFZI& other) const
354  {
355  return (value < other.value);
356  };
357 
361  inline bool
362  operator<=(const MGFZI& other) const
363  {
364  return (value <= other.value);
365  };
366 
370  inline bool
371  operator>(const MGFZI& other) const
372  {
373  return (value > other.value);
374  };
375 
379  inline bool
380  operator>=(const MGFZI& other) const
381  {
382  return (value >= other.value);
383  };
384 
388  inline
389  operator long long() const
390  {
391  return value;
392  };
393 
398  inline size_t
399  getSize() const
400  {
401  return size;
402  };
403 
414  size_t
415  decode(const std::string& inBuffer,
416  size_t offset = 0,
417  bool littleEndian = false);
418 
428  size_t
429  encode(std::string& outBuffer,
430  size_t offset = 0,
431  bool littleEndian = false) const;
432 
446  size_t
447  read(std::istream& strm,
448  std::string *outBuffer = NULL,
449  size_t offset = 0,
450  bool reverseBytes = false,
451  bool littleEndian = false);
452 
465  size_t
466  write(std::ostream& strm,
467  std::string *outBuffer = NULL,
468  size_t offset = 0,
469  bool reverseBytes = false,
470  bool littleEndian = false) const;
471 
472  protected:
473 
474  long long value;
475  size_t size;
476  };
477 
481  BinexData();
482 
486  BinexData(const BinexData& other);
487 
491  BinexData(RecordID recordID,
492  SyncByte recordFlags = DEFAULT_RECORD_FLAGS)
493  noexcept;
494 
498  BinexData&
499  operator=(const BinexData& right);
500 
504  virtual
506 
510  virtual bool
511  isData(void) const
512  {
513  return true;
514  }
515 
519  virtual void
520  dump(std::ostream& s) const;
521 
527  bool
528  operator==(const BinexData& b) const;
529 
535  inline SyncByte
537  {
538  // Return only essential, valid flag bits listed in recordFlagMask
539  return syncByte & VALID_RECORD_FLAGS;
540  };
541 
554  BinexData&
556 
560  inline RecordID
561  getRecordID() const
562  {
563  return recID;
564  };
565 
570  BinexData&
571  setRecordID(RecordID id);
572 
577  size_t
578  getRecordSize() const;
579 
583  BinexData&
584  clearMessage();
585 
594  BinexData&
595  ensureMessageCapacity(size_t cap);
596 
605  size_t
606  getHeadLength() const;
607 
614  inline size_t
616  {
617  return msg.size();
618  };
619 
628  inline size_t
630  {
632  };
633 
639  inline const std::string&
641  {
642  return msg;
643  };
644 
658  BinexData&
660  size_t& offset,
661  const UBNXI& data);
662 
676  BinexData&
678  size_t& offset,
679  const MGFZI& data);
680 
695  BinexData&
697  size_t& offset,
698  const std::string& data,
699  size_t size);
700 
715  BinexData&
717  size_t& offset,
718  const char *data,
719  size_t size);
720 
737  template<class T>
738  BinexData&
740  size_t& offset,
741  const T& data,
742  size_t size)
743  {
744  if (size > sizeof(T) )
745  {
746  std::ostringstream errStrm;
747  errStrm << "Invalid data size: " << size;
748  InvalidParameter ip(errStrm.str() );
749  GNSSTK_THROW(ip);
750  }
751  bool littleEndian = ( (syncByte & eBigEndian) == 0) ? true : false;
752  msg.replace(offset, size, reinterpret_cast<const char*>(&data), size);
753  if (littleEndian != nativeLittleEndian)
754  {
755  // host endian-ness does not match file endian-ness, so
756  // reverse the bytes
757  std::reverse(msg.begin()+offset, msg.begin()+offset+size);
758  }
759  offset += size;
760  return *this;
761 
762  } // BinexData::updateMessageData()
763 
776  void
778  size_t& offset,
779  UBNXI& data);
780 
793  void
795  size_t& offset,
796  MGFZI& data);
797 
812  void
814  size_t& offset,
815  std::string& data,
816  size_t size) const;
817 
834  template<class T>
835  void
837  size_t& offset,
838  T& data,
839  size_t size) const
840  {
841  if (size > sizeof(T) )
842  {
843  std::ostringstream errStrm;
844  errStrm << "Data size invalid: " << size;
845  InvalidParameter ip(errStrm.str() );
846  GNSSTK_THROW(ip);
847  }
848  if (offset + size > msg.size() )
849  {
850  std::ostringstream errStrm;
851  errStrm << "Message buffer offset invalid: " << offset;
852  InvalidParameter ip(errStrm.str() );
853  GNSSTK_THROW(ip);
854  }
855  bool littleEndian = ( (syncByte & eBigEndian) == 0) ? true : false;
856  if (littleEndian)
857  data = BinUtils::decodeVarLE<T>(msg, offset);
858  else
859  data = BinUtils::decodeVar<T>(msg, offset);
860  offset += size;
861 
862  } // BinexData::extractMessageData()
863 
864 
871  virtual void
872  putRecord(std::ostream& s) const;
873 
881  virtual size_t
882  getRecord(std::istream& s);
883 
884  protected:
885 
892  virtual void
893  reallyPutRecord(FFStream& s) const;
894 
906  virtual void
908 
915  void getCRC(const std::string& head,
916  const std::string& message,
917  std::string& crc) const;
918 
923  size_t
924  getCRCLength(size_t crcDataLen) const;
925 
930  bool
931  isHeadSyncByteValid(SyncByte headSync,
932  SyncByte& expectedTailSync) const;
933 
938  bool
939  isTailSyncByteValid(SyncByte tailSync,
940  SyncByte& expectedHeadSync) const;
950  static unsigned long long
951  parseBuffer(const std::string& buffer,
952  size_t offset,
953  size_t size);
954 
955  private:
956 
957  template <class T>
958  static void reverseBytes(T& val);
959 
968  static void
969  reverseBuffer(std::string& buffer,
970  size_t offset = 0,
971  size_t n = std::string::npos);
972 
975  std::string msg;
976 
977  }; // class BinexData
978 
980 
981 } // namespace gnsstk
982 
983 
984 #endif // GNSSTK_BINEXDATA_HPP
gnsstk::FFData
Definition: FFData.hpp:87
gnsstk::BinexData::MGFZI::value
long long value
Definition: BinexData.hpp:474
gnsstk::BinexData::RecordID
uint32_t RecordID
Record ID type.
Definition: BinexData.hpp:72
gnsstk::BinexData::MGFZI::write
size_t write(std::ostream &strm, std::string *outBuffer=NULL, size_t offset=0, bool reverseBytes=false, bool littleEndian=false) const
Definition: BinexData.cpp:869
gnsstk::BinexData::INVALID_RECORD_ID
static const GNSSTK_EXPORT RecordID INVALID_RECORD_ID
Definition: BinexData.hpp:75
gnsstk::BinexData::getCRC
void getCRC(const std::string &head, const std::string &message, std::string &crc) const
Definition: BinexData.cpp:1428
gnsstk::BinexData::MGFZI::operator=
MGFZI & operator=(const MGFZI &right)
Definition: BinexData.hpp:324
gnsstk::BinexData::eReverseReadable
@ eReverseReadable
Definition: BinexData.hpp:86
gnsstk::FFStream
Definition: FFStream.hpp:119
gnsstk::BinexData::~BinexData
virtual ~BinexData()
Definition: BinexData.hpp:505
gnsstk::BinexData::UBNXI::decode
size_t decode(const std::string &inBuffer, size_t offset=0, bool littleEndian=false)
Definition: BinexData.cpp:119
gnsstk::BinexData::reallyPutRecord
virtual void reallyPutRecord(FFStream &s) const
Definition: BinexData.cpp:1166
gnsstk::BinexData::updateMessageData
BinexData & updateMessageData(size_t &offset, const T &data, size_t size)
Definition: BinexData.hpp:739
gnsstk::BinexData::setRecordFlags
BinexData & setRecordFlags(SyncByte flags=DEFAULT_RECORD_FLAGS)
Definition: BinexData.cpp:974
gnsstkplatform.h
gnsstk::BinexData::parseBuffer
static unsigned long long parseBuffer(const std::string &buffer, size_t offset, size_t size)
Definition: BinexData.cpp:1640
gnsstk::BinexData::clearMessage
BinexData & clearMessage()
Definition: BinexData.cpp:1012
gnsstk::BinexData::MGFZI::operator<=
bool operator<=(const MGFZI &other) const
Definition: BinexData.hpp:362
gnsstk::BinexData::MGFZI::getSize
size_t getSize() const
Definition: BinexData.hpp:399
gnsstk::BinexData::extractMessageData
void extractMessageData(size_t &offset, T &data, size_t size) const
Definition: BinexData.hpp:836
NULL
#define NULL
Definition: getopt1.c:64
gnsstk::BinexData::getCRCLength
size_t getCRCLength(size_t crcDataLen) const
Definition: BinexData.cpp:1530
gnsstk::BinexData::MGFZI::operator>
bool operator>(const MGFZI &other) const
Definition: BinexData.hpp:371
gnsstk::BinexData::UBNXI::MAX_VALUE
static const GNSSTK_EXPORT unsigned long MAX_VALUE
0
Definition: BinexData.hpp:101
gnsstk::BinexData::UBNXI::MAX_BYTES
static const GNSSTK_EXPORT unsigned char MAX_BYTES
536870911
Definition: BinexData.hpp:102
gnsstk::BinexData::reverseBuffer
static void reverseBuffer(std::string &buffer, size_t offset=0, size_t n=std::string::npos)
Definition: BinexData.cpp:1683
gnsstk::BinexData::UBNXI::UBNXI
UBNXI(const UBNXI &other)
Definition: BinexData.hpp:112
gnsstk::BinexData::DEFAULT_RECORD_FLAGS
static const GNSSTK_EXPORT SyncByte DEFAULT_RECORD_FLAGS
0xFFFFFFFF
Definition: BinexData.hpp:77
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::BinexData::UBNXI::operator>
bool operator>(const UBNXI &other) const
Definition: BinexData.hpp:174
gnsstk::BinexData::MGFZI::read
size_t read(std::istream &strm, std::string *outBuffer=NULL, size_t offset=0, bool reverseBytes=false, bool littleEndian=false)
Definition: BinexData.cpp:807
gnsstk::BinexData::MGFZI::operator<
bool operator<(const MGFZI &other) const
Definition: BinexData.hpp:353
gnsstk::BinexData::UBNXI::value
unsigned long value
Definition: BinexData.hpp:282
gnsstk::BinexData::operator=
BinexData & operator=(const BinexData &right)
Definition: BinexData.cpp:939
gnsstk::BinexData::UBNXI::operator!=
bool operator!=(const UBNXI &other) const
Definition: BinexData.hpp:147
gnsstk::BinexData::syncByte
SyncByte syncByte
Flags for endianness, CRC, etc.
Definition: BinexData.hpp:973
gnsstk::BinexData::ensureMessageCapacity
BinexData & ensureMessageCapacity(size_t cap)
Definition: BinexData.cpp:1021
gnsstk::BinexData::nativeLittleEndian
static const GNSSTK_EXPORT bool nativeLittleEndian
Definition: BinexData.hpp:70
gnsstk::BinexData::eEnhancedCRC
@ eEnhancedCRC
Definition: BinexData.hpp:88
gnsstk::BinexData::BinexData
BinexData()
Definition: BinexData.cpp:913
gnsstk::BinexData::recordFlagsEnum
recordFlagsEnum
0x38
Definition: BinexData.hpp:84
gnsstk::BinexData
Definition: BinexData.hpp:65
gnsstk::BinexData::dump
virtual void dump(std::ostream &s) const
Definition: BinexData.cpp:1712
gnsstk::BinexData::isHeadSyncByteValid
bool isHeadSyncByteValid(SyncByte headSync, SyncByte &expectedTailSync) const
Definition: BinexData.cpp:1575
gnsstk::BinexData::msg
std::string msg
Record message (opaque)
Definition: BinexData.hpp:975
gnsstk::BinexData::MGFZI::operator>=
bool operator>=(const MGFZI &other) const
Definition: BinexData.hpp:380
gnsstk::BinexData::eBigEndian
@ eBigEndian
Definition: BinexData.hpp:87
gnsstk::BinexData::getMessageLength
size_t getMessageLength() const
Definition: BinexData.hpp:615
gnsstk::BinexData::MGFZI::MIN_VALUE
static const GNSSTK_EXPORT long long MIN_VALUE
Definition: BinexData.hpp:297
gnsstk::BinexData::getRecordID
RecordID getRecordID() const
Definition: BinexData.hpp:561
gnsstk::BinexData::VALID_RECORD_FLAGS
static const GNSSTK_EXPORT SyncByte VALID_RECORD_FLAGS
0x20
Definition: BinexData.hpp:78
gnsstk::BinexData::UBNXI::getSize
size_t getSize() const
Definition: BinexData.hpp:202
gnsstk::BinexData::MGFZI::MGFZI
MGFZI(const MGFZI &other)
Definition: BinexData.hpp:309
gnsstk::BinexData::getTailLength
size_t getTailLength() const
Definition: BinexData.hpp:629
gnsstk::BinexData::MGFZI::decode
size_t decode(const std::string &inBuffer, size_t offset=0, bool littleEndian=false)
Definition: BinexData.cpp:433
gnsstk::BinexData::UBNXI::operator==
bool operator==(const UBNXI &other) const
Definition: BinexData.hpp:138
gnsstk::BinexData::MGFZI::operator==
bool operator==(const MGFZI &other) const
Definition: BinexData.hpp:335
gnsstk::BinexData::operator==
bool operator==(const BinexData &b) const
Definition: BinexData.cpp:948
gnsstk::BinexData::isData
virtual bool isData(void) const
Definition: BinexData.hpp:511
gnsstk::BinexData::UBNXI
Definition: BinexData.hpp:96
gnsstk::BinexData::MGFZI::encode
size_t encode(std::string &outBuffer, size_t offset=0, bool littleEndian=false) const
Definition: BinexData.cpp:619
gnsstk::BinexData::UBNXI::size
size_t size
Definition: BinexData.hpp:283
gnsstk::BinexData::UBNXI::operator=
UBNXI & operator=(const UBNXI &right)
Definition: BinexData.hpp:127
gnsstk::BinexData::UBNXI::operator<=
bool operator<=(const UBNXI &other) const
Definition: BinexData.hpp:165
BinUtils.hpp
example3.data
data
Definition: example3.py:22
gnsstk::BinexData::reverseBytes
static void reverseBytes(T &val)
Definition: BinexData.cpp:1670
gnsstk::BinexData::updateMessageData
BinexData & updateMessageData(size_t &offset, const UBNXI &data)
Definition: BinexData.cpp:1051
gnsstk::BinexData::UBNXI::operator<
bool operator<(const UBNXI &other) const
Definition: BinexData.hpp:156
gnsstk::BinexData::MGFZI::MAX_VALUE
static const GNSSTK_EXPORT long long MAX_VALUE
-1157442765409226759LL
Definition: BinexData.hpp:298
gnsstk::BinexData::UBNXI::write
size_t write(std::ostream &strm, std::string *outBuffer=NULL, size_t offset=0, bool reverseBytes=false, bool littleEndian=false) const
Definition: BinexData.cpp:331
gnsstk::BinexData::UBNXI::MIN_VALUE
static const GNSSTK_EXPORT unsigned long MIN_VALUE
Definition: BinexData.hpp:100
gnsstk::BinexData::putRecord
virtual void putRecord(std::ostream &s) const
Definition: BinexData.cpp:1179
gnsstk::BinexData::UBNXI::encode
size_t encode(std::string &outBuffer, size_t offset=0, bool littleEndian=false) const
Definition: BinexData.cpp:155
gnsstk::BinexData::MGFZI::operator!=
bool operator!=(const MGFZI &other) const
Definition: BinexData.hpp:344
gnsstk::BinexData::getRecord
virtual size_t getRecord(std::istream &s)
Definition: BinexData.cpp:1267
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::BinexData::reallyGetRecord
virtual void reallyGetRecord(FFStream &s)
Definition: BinexData.cpp:1255
gnsstk::BinexData::getMessageData
const std::string & getMessageData() const
Definition: BinexData.hpp:640
FFStream.hpp
gnsstk::BinexData::recID
RecordID recID
Record ID.
Definition: BinexData.hpp:974
FFData.hpp
gnsstk::BinexData::getHeadLength
size_t getHeadLength() const
Definition: BinexData.cpp:1037
gnsstk::BinexData::MGFZI::size
size_t size
Definition: BinexData.hpp:475
gnsstk::BinexData::SyncByte
uint8_t SyncByte
Synchronization byte (record flags)
Definition: BinexData.hpp:73
gnsstk::BinexData::MGFZI::MGFZI
MGFZI()
8
Definition: BinexData.cpp:373
gnsstk::BinexData::getRecordSize
size_t getRecordSize() const
Definition: BinexData.cpp:989
gnsstk::BinexData::MGFZI
Definition: BinexData.hpp:293
gnsstk::BinexData::extractMessageData
void extractMessageData(size_t &offset, UBNXI &data)
Definition: BinexData.cpp:1111
gnsstk::BinexData::UBNXI::read
size_t read(std::istream &strm, std::string *outBuffer=NULL, size_t offset=0, bool reverseBytes=false, bool littleEndian=false)
Definition: BinexData.cpp:268
gnsstk::BinexData::setRecordID
BinexData & setRecordID(RecordID id)
Definition: BinexData.cpp:958
gnsstk::BinexData::MGFZI::MAX_BYTES
static const GNSSTK_EXPORT unsigned char MAX_BYTES
1157442765409226759LL
Definition: BinexData.hpp:299
gnsstk::BinexData::UBNXI::UBNXI
UBNXI()
4
Definition: BinexData.cpp:77
gnsstk::BinexData::UBNXI::operator>=
bool operator>=(const UBNXI &other) const
Definition: BinexData.hpp:183
gnsstk::BinexData::isTailSyncByteValid
bool isTailSyncByteValid(SyncByte tailSync, SyncByte &expectedHeadSync) const
Definition: BinexData.cpp:1611
gnsstk::BinexData::getRecordFlags
SyncByte getRecordFlags() const
Definition: BinexData.hpp:536


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