1 //==============================================================================
2 //
3 //  This file is part of GPSTk, the GPS Toolkit.
4 //
5 //  The GPSTk 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 GPSTk 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 GPSTk; 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-2020, 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 #ifndef GPSTK_SATID_HPP
40 #define GPSTK_SATID_HPP
41 
42 #include <iostream>
43 #include <iomanip>
44 #include <sstream>
45 #include "gps_constants.hpp"
46 #include "SatelliteSystem.hpp"
47 
48 /**
49  * @file SatID.hpp
50  * gpstk::SatID - navigation system-independent representation of a satellite.
51  */
52 
53 namespace gpstk
54 {
55       // forward declarations
56    class SatID;
57 //   std::istream& operator<<(std::istream& s, SatID& p);
58 
59       /// @ingroup GNSSEph
60       //@{
61 
62       /// Satellite identifier consisting of a satellite number (PRN, etc.)
63       /// and a satellite system. For GLONASS (systemGlonass), the identifier
64       /// is the slot number as per section 3.5 of the RINEX 3 spec.
65       /// For SBAS (systemGeosync), the id is the PRN-100.
66    class SatID
67    {
68    public:
69          /// empty constructor, creates an invalid object
SatID()70       SatID() { id=-1; system=SatelliteSystem::GPS; }
71 
72          /// explicit constructor, no defaults
73          /// @note if s is given a default value here,
74          /// some compilers will silently cast int to SatID.
SatID(int p,SatelliteSystem s)75       SatID(int p, SatelliteSystem s) { id=p; system=s; }
76 
77          // operator=, copy constructor and destructor built by compiler
78 
79 
80          /// Convenience output method.
dump(std::ostream & s) const81       void dump(std::ostream& s) const
82       {
83          s << convertSatelliteSystemToString(system) << " " << id;
84       }
85 
86          /// operator == for SatID
operator ==(const SatID & right) const87       bool operator==(const SatID& right) const
88       { return ((system == right.system) && (id == right.id)); }
89 
90          /// operator != for SatID
operator !=(const SatID & right) const91       bool operator!=(const SatID& right) const
92       { return !(operator==(right)); }
93 
94          /// operator < for SatID : order by system, then number
operator <(const SatID & right) const95       bool operator<(const SatID& right) const
96       {
97          if (system==right.system)
98             return (id<right.id);
99          return (system<right.system);
100       }
101 
102          /// operator > for SatID
operator >(const SatID & right) const103       bool operator>(const SatID& right) const
104       {  return (!operator<(right) && !operator==(right)); }
105 
106          /// operator <= for SatID
operator <=(const SatID & right) const107       bool operator<=(const SatID& right) const
108       { return (operator<(right) || operator==(right)); }
109 
110          /// operator >= for SatID
operator >=(const SatID & right) const111       bool operator>=(const SatID& right) const
112       { return !(operator<(right)); }
113 
114          /// return true if this is a valid SatID
115          /// @note assumes all id's are positive and less than 100;
116          ///     plus GPS id's are less than or equal to MAX_PRN (32).
117          /// @note this is not used internally in the gpstk library
isValid() const118       bool isValid() const
119       {
120          switch(system)
121          {
122             case SatelliteSystem::GPS: return (id > 0 && id <= MAX_PRN);
123                   //case SatelliteSystem::Galileo:
124                   //case SatelliteSystem::Glonass:
125                   //case SatelliteSystem::Geosync:
126                   //case SatelliteSystem::LEO:
127                   //case SatelliteSystem::Transit:
128             default: return (id > 0 && id < 100);
129          }
130       }
131 
132       int id;                   ///< satellite identifier, e.g. PRN
133       SatelliteSystem system;   ///< system for this satellite
134 
135    }; // class SatID
136 
137       /// stream output for SatID
operator <<(std::ostream & s,const SatID & p)138    inline std::ostream& operator<<(std::ostream& s, const SatID& p)
139    {
140       p.dump(s);
141       return s;
142    }
143 
144       //@}
145 
146    namespace StringUtils
147    {
148          /// @ingroup StringUtils
149          //@{
150 
151          /// SatID as a string
asString(const SatID & p)152       inline std::string asString(const SatID& p)
153       {
154          std::ostringstream oss;
155          p.dump(oss);
156          return oss.str();
157       }
158    }
159 
160 } // namespace gpstk
161 
162 #endif
163