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 /** 40 * @file CNavUTC.cpp 41 * CNAV UTC data encapsulated in engineering terms 42 */ 43 44 #include <iomanip> 45 #include <cmath> 46 47 #include "CNavUTC.hpp" 48 #include "StringUtils.hpp" 49 #include "TimeString.hpp" 50 51 namespace gpstk 52 { 53 using namespace std; 54 CNavUTC()55 CNavUTC::CNavUTC() 56 :CNavDataElement(), 57 A0(0.0), 58 A1(0.0), 59 A2(0.0), 60 deltaTls(0), 61 Tot(0L), 62 WNot(0), 63 WNlsf(0), 64 DN(0), 65 deltaTlsf(0) 66 { 67 } 68 CNavUTC(const PackedNavBits & message33)69 CNavUTC::CNavUTC(const PackedNavBits& message33) 70 { 71 loadData(message33); 72 } 73 clone() const74 CNavUTC* CNavUTC::clone() const 75 { 76 return new CNavUTC (*this); 77 } 78 isSameData(const CNavDataElement * right) const79 bool CNavUTC::isSameData(const CNavDataElement* right) const 80 { 81 if (const CNavUTC* rp = dynamic_cast<const CNavUTC*>(right)) 82 { 83 if (ctEpoch !=rp->ctEpoch) return false; 84 if (A0 !=rp->A0) return false; 85 if (A1 !=rp->A1) return false; 86 if (A2 !=rp->A2) return false; 87 if (deltaTls !=rp->deltaTls) return false; 88 // Note: Already tested Tot and WNot (indirectly) by ctEpoch test. 89 if (WNlsf !=rp->WNlsf) return false; 90 if (DN !=rp->DN) return false; 91 if (deltaTlsf!=rp->deltaTlsf) return false; 92 return true; 93 } 94 return false; 95 } 96 loadData(const PackedNavBits & message33)97 void CNavUTC::loadData(const PackedNavBits& message33) 98 { 99 // First, verify the correct message type is being passed in. 100 long msgType = message33.asUnsignedLong(14,6,1); 101 if(msgType!=33) 102 { 103 char errStr[80]; 104 sprintf(errStr,"Expected CNAV MsgType 33. Found MsgType %ld",msgType); 105 std::string tstr(errStr); 106 InvalidParameter exc(tstr); 107 GPSTK_THROW(exc); 108 } 109 obsID = message33.getobsID(); 110 satID = message33.getsatSys(); 111 ctXmit = message33.getTransmitTime(); 112 113 A0 = message33.asSignedDouble(127,16,-35); 114 A1 = message33.asSignedDouble(143,13,-51); 115 A2 = message33.asSignedDouble(156, 7,-68); 116 117 deltaTls = message33.asLong(163, 8, 1); 118 Tot = message33.asUnsignedLong(171,16,16); 119 WNot = message33.asUnsignedLong(187,13, 1); 120 WNlsf = message33.asUnsignedLong(200,13, 1); 121 DN = message33.asUnsignedLong(213, 4, 1); 122 deltaTlsf = message33.asLong(217, 8, 1); 123 124 ctEpoch = GPSWeekSecond(WNot, Tot, TimeSystem::GPS); 125 126 dataLoadedFlag = true; 127 } // end of loadData() 128 dumpBody(ostream & s) const129 void CNavUTC::dumpBody(ostream& s) const 130 { 131 if (!dataLoaded()) 132 { 133 InvalidRequest exc("Required data not stored."); 134 GPSTK_THROW(exc); 135 } 136 137 s << endl 138 << " UTC CORRECTION PARAMETERS" 139 << endl 140 << "Parameter Value" << endl; 141 142 s.setf(ios::scientific, ios::floatfield); 143 s.setf(ios::right, ios::adjustfield); 144 s.setf(ios::uppercase); 145 s.precision(8); 146 s.fill(' '); 147 148 s << "A(0-n): " << setw(16) << A0 << " sec" <<endl; 149 s << "A(1-n): " << setw(16) << A1 << " sec/sec" << endl; 150 s << "A(2-n): " << setw(16) << A2 << " sec/sec**2" << endl; 151 152 s.setf(ios::fixed, ios::floatfield); 153 s.precision(0); 154 s << "dT(LS): " << setw(16) << deltaTls << " sec" << endl; 155 s << "WN(LSF): " << setw(16) << WNlsf << " weeks" << endl; 156 s << "DN: " << setw(16) << DN << " days" << endl; 157 s << "dT(LSF): " << setw(16) << deltaTlsf << " sec" << endl; 158 159 } // end of dumpBody() 160 operator <<(ostream & s,const CNavUTC & eph)161 ostream& operator<<(ostream& s, const CNavUTC& eph) 162 { 163 try 164 { 165 eph.dump(s); 166 } 167 catch(gpstk::Exception& ex) 168 { 169 GPSTK_RETHROW(ex); 170 } 171 return s; 172 173 } // end of operator<< 174 175 } // end namespace 176