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_SATMETADATASTORE_HPP 40 #define GPSTK_SATMETADATASTORE_HPP 41 42 #include <map> 43 #include <set> 44 #include "SatMetaData.hpp" 45 #include "SatMetaDataSort.hpp" 46 #include "NavID.hpp" 47 48 namespace gpstk 49 { 50 /** Provide a class for reading satellite metadata from a CSV 51 * file and provide methods for looking up information in that 52 * file. 53 */ 54 class SatMetaDataStore 55 { 56 public: 57 /// Specifies a single GNSS signal. 58 struct Signal 59 { 60 CarrierBand carrier; ///< Carrier frequency. 61 gpstk::TrackingCode code; ///< Tracking code. 62 gpstk::NavType nav; ///< Navigation code. 63 }; 64 /// Key of GNSS and satellite block 65 class SystemBlock 66 { 67 public: 68 inline bool operator<(const SystemBlock& right) const; 69 SatelliteSystem sys; 70 std::string blk; 71 }; 72 /// Like SatID but for SVN which is a string 73 class SVNID 74 { 75 public: 76 SVNID(); 77 SVNID(SatelliteSystem sys, const std::string& svn); 78 SatelliteSystem system; 79 std::string id; 80 bool operator<(const SVNID& right) const; 81 }; 82 /// Launch configuration 83 class LaunchConfig 84 { 85 public: 86 SVNID svn; 87 gpstk::CommonTime launchTime; 88 std::string type; ///< Typically block number. 89 std::string mission; ///< Mission number. 90 }; 91 /// Set of signals that may be transmitted by a satellite. 92 using SignalSet = std::set<Signal>; 93 /// Map of signal set name to signal set. 94 using SignalMap = std::map<std::string, SignalSet>; 95 /// Set of satellites ordered by PRN or channel/slotID. 96 using SatSet = std::multiset<SatMetaData, SatMetaDataSort>; 97 /// Satellites grouped by system. 98 using SatMetaMap = std::map<SatelliteSystem, SatSet>; 99 /// Types of clocks on a satellite (hardware-specific positional idx). 100 using ClockVec = std::vector<SatMetaData::ClockType>; 101 /// Clock configuration information 102 using ClockConfigMap = std::map<SystemBlock, ClockVec>; 103 /// Map SVN to launch time. 104 using LaunchMap = std::map<SVNID, LaunchConfig>; 105 /// Map SVN to NORAD ID. 106 using NORADMap = std::map<SVNID, unsigned long>; 107 108 /// Nothin doin. 109 SatMetaDataStore() = default; 110 111 /** Attempt to load satellite metadata from the store. 112 * The format of the input file is CSV, the values being 113 * \li SAT (literal) 114 * \li GNSS name 115 * \li svn 116 * \li prn 117 * \li FDMA channel (0 if n/a) 118 * \li FDMA slot ID (0 if n/a) 119 * \li start time year 120 * \li start time day of year 121 * \li start time seconds of day 122 * \li end time year 123 * \li end time day of year 124 * \li end time seconds of day 125 * \li orbital plane 126 * \li orbital slot 127 * \li signal set name 128 * \li satellite status 129 * \li active clock number 130 * 131 * Mapping system satellite number to NORAD identifier: 132 * \li NORAD (literal) 133 * \li GNSS name 134 * \li svn 135 * \li NORAD ID 136 * 137 * Satellite launch time: 138 * \li LAUNCH (literal) 139 * \li GNSS name 140 * \li svn 141 * \li launch time year 142 * \li launch time day of year 143 * \li launch time seconds of day 144 * \li satellite block/type 145 * \li mission number 146 * 147 * Clock configuration: 148 * \li CLOCK (literal) 149 * \li GNSS name 150 * \li satellite type/block 151 * \li clock type 1 152 * \li clock type 2 153 * \li clock type 3 154 * \li clock type 4 155 * 156 * Signal sets are defined using multiple SIG records as follows 157 * \li SIG (literal) 158 * \li signal set name 159 * \li carrier band name 160 * \li tracking code name 161 * \li navigation code name 162 * 163 * @param[in] sourceName The path to the input CSV-format file. 164 * @return true if successful, false on error. 165 */ 166 virtual bool loadData(const std::string& sourceName); 167 168 /** Find a satellite in the map by searching by PRN. 169 * @param[in] sys The GNSS of the desired satellite. 170 * @param[in] prn The pseudo-random number identifying the 171 * desired satellite. 172 * @param[in] when The time of interest of the desired satellite. 173 * @param[out] sat If found the satellite's metadata. 174 * @return true if the requested satellite mapping was found. 175 */ 176 bool findSat(SatelliteSystem sys, uint32_t prn, 177 const gpstk::CommonTime& when, 178 SatMetaData& sat) 179 const; 180 181 /** Find a satellite in the map by searching by PRN. 182 * @param[in] prn The satellite to find, identified by PRN 183 * (i.e. not FDMA channel/slot). 184 * @param[in] when The time of interest of the desired satellite. 185 * @param[out] sat If found the satellite's metadata. 186 * @return true if the requested satellite mapping was found. 187 */ findSat(const SatID & prn,const gpstk::CommonTime & when,SatMetaData & sat) const188 bool findSat(const SatID& prn, 189 const gpstk::CommonTime& when, 190 SatMetaData& sat) 191 const 192 { return findSat(prn.system, prn.id, when, sat); } 193 194 /** Get the space vehicle number of a satellite in the map by 195 * searching by PRN. 196 * @param[in] sys The GNSS of the desired satellite. 197 * @param[in] prn The pseudo-random number identifying the 198 * desired satellite. 199 * @param[in] when The time of interest of the desired satellite. 200 * @param[out] svn If found the satellite's vehicle number. 201 * @return true if the requested satellite mapping was found. 202 */ 203 bool getSVN(SatelliteSystem sys, uint32_t prn, 204 const gpstk::CommonTime& when, 205 std::string& svn) 206 const; 207 208 /** Get the space vehicle number of a satellite in the map by 209 * searching by PRN. 210 * @param[in] sat The ID of the desired satellite. 211 * @param[in] when The time of interest of the desired satellite. 212 * @param[out] svn If found the satellite's vehicle number. 213 * @return true if the requested satellite mapping was found. 214 */ getSVN(const SatID & sat,const gpstk::CommonTime & when,std::string & svn) const215 bool getSVN(const SatID& sat, const gpstk::CommonTime& when, 216 std::string& svn) 217 const 218 { return getSVN(sat.system, sat.id, when, svn); } 219 220 /** Find a satellite in the map by searching by SVN. 221 * @param[in] sys The GNSS of the desired satellite. 222 * @param[in] svn The system-unique space vehicle number 223 * identifying the desired satellite. 224 * @param[in] when The time of interest of the desired satellite. 225 * @param[out] sat If found the satellite's metadata. 226 * @return true if the requested satellite mapping was found. 227 */ 228 bool findSatBySVN(SatelliteSystem sys, const std::string& svn, 229 const gpstk::CommonTime& when, 230 SatMetaData& sat) 231 const; 232 233 /** Find a GLONASS satellite in the map by searching by 234 * its orbit slotID and FDMA channel. To be a unique 235 * identification, both are necessary. 236 * This is only applicable to GLONASS FDMA SVs 237 * @param[in] slotID The GLONASS orbit slot ID 238 * identifying the desired satellite. 239 * @param[in] channel The FDMA channel 240 * identifying the desired satellite. 241 * @param[in] when The time of interest of the desired satellite. 242 * @param[out] sat If found the satellite's metadata. 243 * @return true if the requested satellite mapping was found. 244 */ 245 bool findSatBySlotFdma(uint32_t slotID, 246 int32_t channel, 247 const gpstk::CommonTime& when, 248 SatMetaData& sat) 249 const; 250 251 /** Get the pseudo-random number of a satellite in the map by 252 * searching by SVN. 253 * @param[in] sys The GNSS of the desired satellite. 254 * @param[in] svn The space vehicle number identifying the 255 * desired satellite. 256 * @param[in] when The time of interest of the desired satellite. 257 * @param[out] prn If found the satellite's pseudo-random number. 258 * @return true if the requested satellite mapping was found. 259 */ 260 bool getPRN(SatelliteSystem sys, const std::string& svn, 261 const gpstk::CommonTime& when, 262 uint32_t& prn) 263 const; 264 265 /// Storage of all the satellite metadata. 266 SatMetaMap satMap; 267 /// Map signal set name to the actual signals. 268 SignalMap sigMap; 269 /// Map satellite block to clock types. 270 ClockConfigMap clkMap; 271 /// Launch time of satellites. 272 LaunchMap launchMap; 273 /// Map SVN to NORAD ID. 274 NORADMap noradMap; 275 276 protected: 277 /** Convert a SAT record to a SatMetaData record and store it. 278 * @param[in] vals SAT record in the form of an array of columns. 279 * @param[in] lineNo The line number of the input file being processed. 280 * @return true if successful, false on error. 281 */ 282 bool addSat(const std::vector<std::string>& vals, unsigned long lineNo); 283 /** Convert a SIG record to a Signal object and store it. 284 * @param[in] vals SIG record in the form of an array of columns. 285 * @param[in] lineNo The line number of the input file being processed. 286 * @return true if successful, false on error. 287 */ 288 bool addSignal(const std::vector<std::string>& vals, 289 unsigned long lineNo); 290 /** Add a CLOCK record to clkMap. 291 * @param[in] vals CLOCK record in the form of an array of columns. 292 * @param[in] lineNo The line number of the input file being processed. 293 * @return true if successful, false on error. 294 */ 295 bool addClock(const std::vector<std::string>& vals, unsigned long lineNo); 296 /** Add a LAUNCH record to launchMap. 297 * @param[in] vals LAUNCH record in the form of an array of columns. 298 * @param[in] lineNo The line number of the input file being processed. 299 * @return true if successful, false on error. 300 */ 301 bool addLaunch(const std::vector<std::string>& vals, 302 unsigned long lineNo); 303 /** Add a NORAD record to noradMap. 304 * @param[in] vals NORAD record in the form of an array of columns. 305 * @param[in] lineNo The line number of the input file being processed. 306 * @return true if successful, false on error. 307 */ 308 bool addNORAD(const std::vector<std::string>& vals, unsigned long lineNo); 309 }; // class SatMetaDataStore 310 311 312 bool SatMetaDataStore::SystemBlock :: operator <(const SatMetaDataStore::SystemBlock & right) const313 operator<(const SatMetaDataStore::SystemBlock& right) 314 const 315 { 316 if (static_cast<int>(sys) < static_cast<int>(right.sys)) 317 return true; 318 if (static_cast<int>(sys) > static_cast<int>(right.sys)) 319 return false; 320 return blk < right.blk; 321 } 322 323 operator <<(std::ostream & s,const SatMetaDataStore::SystemBlock & sblk)324 inline std::ostream& operator<<(std::ostream& s, 325 const SatMetaDataStore::SystemBlock& sblk) 326 { 327 s << gpstk::StringUtils::asString(sblk.sys) << " " << sblk.blk; 328 return s; 329 } 330 331 operator <<(std::ostream & s,const SatMetaDataStore::SVNID & svn)332 inline std::ostream& operator<<(std::ostream& s, 333 const SatMetaDataStore::SVNID& svn) 334 { 335 s << gpstk::StringUtils::asString(svn.system) << " " << svn.id; 336 return s; 337 } 338 339 } // namespace gpstk 340 341 #endif // GPSTK_SATMETADATASTORE_HPP 342