[2904] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncEphUser
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Base for Classes that use Ephemerides
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 27-Jan-2011
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[2907] | 41 | #include <iostream>
|
---|
| 42 |
|
---|
[2904] | 43 | #include "bncephuser.h"
|
---|
| 44 | #include "bncapp.h"
|
---|
| 45 |
|
---|
| 46 | using namespace std;
|
---|
| 47 |
|
---|
| 48 | // Constructor
|
---|
| 49 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3640] | 50 | bncEphUser::bncEphUser(bool connectSlots) {
|
---|
[2904] | 51 |
|
---|
[3640] | 52 | if (connectSlots) {
|
---|
| 53 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
| 54 | this, SLOT(slotNewEphGPS(gpsephemeris)), Qt::DirectConnection);
|
---|
| 55 |
|
---|
| 56 | connect(((bncApp*)qApp), SIGNAL(newEphGlonass(glonassephemeris)),
|
---|
| 57 | this, SLOT(slotNewEphGlonass(glonassephemeris)), Qt::DirectConnection);
|
---|
| 58 |
|
---|
| 59 | connect(((bncApp*)qApp), SIGNAL(newEphGalileo(galileoephemeris)),
|
---|
| 60 | this, SLOT(slotNewEphGalileo(galileoephemeris)), Qt::DirectConnection);
|
---|
| 61 | }
|
---|
[2904] | 62 | }
|
---|
| 63 |
|
---|
| 64 | // Destructor
|
---|
| 65 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 66 | bncEphUser::~bncEphUser() {
|
---|
| 67 | QMapIterator<QString, t_ephPair*> it(_eph);
|
---|
| 68 | while (it.hasNext()) {
|
---|
| 69 | it.next();
|
---|
| 70 | delete it.value();
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | //
|
---|
| 75 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 76 | void bncEphUser::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
| 77 | QMutexLocker locker(&_mutex);
|
---|
| 78 |
|
---|
| 79 | QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
|
---|
| 80 |
|
---|
| 81 | if (_eph.contains(prn)) {
|
---|
| 82 | t_ephGPS* eLast = static_cast<t_ephGPS*>(_eph.value(prn)->last);
|
---|
[4018] | 83 | bncTime toc(gpseph.GPSweek, gpseph.TOC);
|
---|
| 84 | if (eLast->TOC() < toc) {
|
---|
[2904] | 85 | delete static_cast<t_ephGPS*>(_eph.value(prn)->prev);
|
---|
| 86 | _eph.value(prn)->prev = _eph.value(prn)->last;
|
---|
| 87 | _eph.value(prn)->last = new t_ephGPS();
|
---|
| 88 | static_cast<t_ephGPS*>(_eph.value(prn)->last)->set(&gpseph);
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | else {
|
---|
| 92 | t_ephGPS* eLast = new t_ephGPS();
|
---|
| 93 | eLast->set(&gpseph);
|
---|
[3012] | 94 | _eph.insert(prn, new t_ephPair(eLast));
|
---|
[2904] | 95 | }
|
---|
[3246] | 96 | ephBufferChanged();
|
---|
[2904] | 97 | }
|
---|
| 98 |
|
---|
| 99 | //
|
---|
| 100 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 101 | void bncEphUser::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
| 102 | QMutexLocker locker(&_mutex);
|
---|
| 103 |
|
---|
| 104 | QString prn = QString("R%1").arg(gloeph.almanac_number, 2, 10, QChar('0'));
|
---|
| 105 |
|
---|
| 106 | if (_eph.contains(prn)) {
|
---|
| 107 | int ww = gloeph.GPSWeek;
|
---|
| 108 | int tow = gloeph.GPSTOW;
|
---|
| 109 | updatetime(&ww, &tow, gloeph.tb*1000, 0); // Moscow -> GPS
|
---|
| 110 | t_ephGlo* eLast = static_cast<t_ephGlo*>(_eph.value(prn)->last);
|
---|
[4018] | 111 | bncTime toc(ww, tow);
|
---|
| 112 | if (eLast->TOC() < toc) {
|
---|
[2904] | 113 | delete static_cast<t_ephGlo*>(_eph.value(prn)->prev);
|
---|
| 114 | _eph.value(prn)->prev = _eph.value(prn)->last;
|
---|
| 115 | _eph.value(prn)->last = new t_ephGlo();
|
---|
| 116 | static_cast<t_ephGlo*>(_eph.value(prn)->last)->set(&gloeph);
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | else {
|
---|
| 120 | t_ephGlo* eLast = new t_ephGlo();
|
---|
| 121 | eLast->set(&gloeph);
|
---|
[3012] | 122 | _eph.insert(prn, new t_ephPair(eLast));
|
---|
[2904] | 123 | }
|
---|
[3246] | 124 | ephBufferChanged();
|
---|
[2904] | 125 | }
|
---|
| 126 |
|
---|
| 127 | //
|
---|
| 128 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 129 | void bncEphUser::slotNewEphGalileo(galileoephemeris galeph) {
|
---|
| 130 | QMutexLocker locker(&_mutex);
|
---|
| 131 |
|
---|
| 132 | QString prn = QString("E%1").arg(galeph.satellite, 2, 10, QChar('0'));
|
---|
| 133 |
|
---|
| 134 | if (_eph.contains(prn)) {
|
---|
| 135 | t_ephGal* eLast = static_cast<t_ephGal*>(_eph.value(prn)->last);
|
---|
[4018] | 136 | bncTime toc(galeph.Week, galeph.TOC);
|
---|
| 137 | if (eLast->TOC() < toc) {
|
---|
[2904] | 138 | delete static_cast<t_ephGal*>(_eph.value(prn)->prev);
|
---|
| 139 | _eph.value(prn)->prev = _eph.value(prn)->last;
|
---|
| 140 | _eph.value(prn)->last = new t_ephGal();
|
---|
| 141 | static_cast<t_ephGal*>(_eph.value(prn)->last)->set(&galeph);
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | else {
|
---|
| 145 | t_ephGal* eLast = new t_ephGal();
|
---|
| 146 | eLast->set(&galeph);
|
---|
[3012] | 147 | _eph.insert(prn, new t_ephPair(eLast));
|
---|
[2904] | 148 | }
|
---|
[3246] | 149 | ephBufferChanged();
|
---|
[2904] | 150 | }
|
---|
[2911] | 151 |
|
---|
| 152 | //
|
---|
| 153 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3671] | 154 | t_irc bncEphUser::putNewEph(t_eph* newEph) {
|
---|
[3670] | 155 |
|
---|
| 156 | QMutexLocker locker(&_mutex);
|
---|
| 157 |
|
---|
| 158 | if (!newEph) {
|
---|
[3671] | 159 | return failure;
|
---|
[3670] | 160 | }
|
---|
| 161 |
|
---|
| 162 | QString prn = newEph->prn();
|
---|
| 163 |
|
---|
[3671] | 164 | t_irc irc = failure;
|
---|
| 165 |
|
---|
[3670] | 166 | if (_eph.contains(prn)) {
|
---|
| 167 | t_eph* eLast = _eph.value(prn)->last;
|
---|
| 168 | if (newEph->isNewerThan(eLast)) {
|
---|
| 169 | delete _eph.value(prn)->prev;
|
---|
| 170 | _eph.value(prn)->prev = _eph.value(prn)->last;
|
---|
| 171 | _eph.value(prn)->last = newEph;
|
---|
[3671] | 172 | irc = success;
|
---|
[3670] | 173 | }
|
---|
| 174 | }
|
---|
| 175 | else {
|
---|
| 176 | _eph.insert(prn, new t_ephPair(newEph));
|
---|
[3671] | 177 | irc = success;
|
---|
[3670] | 178 | }
|
---|
[3671] | 179 |
|
---|
| 180 | if (irc == success) {
|
---|
| 181 | ephBufferChanged();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | return irc;
|
---|
[3670] | 185 | }
|
---|
| 186 |
|
---|
| 187 | //
|
---|
| 188 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2912] | 189 | t_irc t_corr::readLine(const QString& line) {
|
---|
[2911] | 190 |
|
---|
[2912] | 191 | if (line[0] == '!') {
|
---|
| 192 | return failure;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[2911] | 195 | QTextStream in(line.toAscii());
|
---|
| 196 |
|
---|
| 197 | int messageType;
|
---|
[2912] | 198 | in >> messageType;
|
---|
| 199 |
|
---|
| 200 | if (!relevantMessageType(messageType)) {
|
---|
| 201 | return failure;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[2911] | 204 | int updateInterval;
|
---|
| 205 | int GPSweek;
|
---|
| 206 | double GPSweeks;
|
---|
[2912] | 207 | in >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
[2911] | 208 |
|
---|
| 209 | if ( messageType == COTYPE_GPSCOMBINED ||
|
---|
| 210 | messageType == COTYPE_GLONASSCOMBINED ) {
|
---|
| 211 | rao.ReSize(3); rao = 0.0;
|
---|
| 212 | dotRao.ReSize(3); dotRao = 0.0;
|
---|
| 213 | dotDotRao.ReSize(3); dotDotRao = 0.0;
|
---|
| 214 | dClk = 0.0;
|
---|
| 215 | dotDClk = 0.0;
|
---|
| 216 | dotDotDClk = 0.0;
|
---|
| 217 | in >> iod
|
---|
| 218 | >> dClk >> rao[0] >> rao[1] >> rao[2]
|
---|
| 219 | >> dotDClk >> dotRao[0] >> dotRao[1] >> dotRao[2]
|
---|
| 220 | >> dotDotDClk >> dotDotRao[0] >> dotDotRao[1] >> dotDotRao[2];
|
---|
| 221 | dClk /= t_CST::c;
|
---|
| 222 | dotDClk /= t_CST::c;
|
---|
| 223 | dotDotDClk /= t_CST::c;
|
---|
[3751] | 224 |
|
---|
| 225 | tClk.set(GPSweek, GPSweeks);
|
---|
| 226 | tRao.set(GPSweek, GPSweeks);
|
---|
[2911] | 227 | }
|
---|
| 228 | else if ( messageType == COTYPE_GPSORBIT ||
|
---|
| 229 | messageType == COTYPE_GLONASSORBIT ) {
|
---|
| 230 | rao.ReSize(3); rao = 0.0;
|
---|
| 231 | dotRao.ReSize(3); dotRao = 0.0;
|
---|
| 232 | dotDotRao.ReSize(3); dotDotRao = 0.0;
|
---|
| 233 | in >> iod
|
---|
| 234 | >> rao[0] >> rao[1] >> rao[2]
|
---|
| 235 | >> dotRao[0] >> dotRao[1] >> dotRao[2]
|
---|
| 236 | >> dotDotRao[0] >> dotDotRao[1] >> dotDotRao[2];
|
---|
[3751] | 237 |
|
---|
| 238 | tRao.set(GPSweek, GPSweeks);
|
---|
[3752] | 239 |
|
---|
| 240 | dClk = 0.0;
|
---|
| 241 | dotDClk = 0.0;
|
---|
| 242 | dotDotDClk = 0.0;
|
---|
| 243 | tClk.reset();
|
---|
[2911] | 244 | }
|
---|
| 245 | else if ( messageType == COTYPE_GPSCLOCK ||
|
---|
| 246 | messageType == COTYPE_GLONASSCLOCK ) {
|
---|
[3751] | 247 | if (tRao.valid()) {
|
---|
| 248 | int dummyIOD;
|
---|
| 249 | dClk = 0.0;
|
---|
| 250 | dotDClk = 0.0;
|
---|
| 251 | dotDotDClk = 0.0;
|
---|
| 252 | in >> dummyIOD >> dClk >> dotDClk >> dotDotDClk;
|
---|
| 253 | dClk /= t_CST::c;
|
---|
| 254 | dotDClk /= t_CST::c;
|
---|
| 255 | dotDotDClk /= t_CST::c;
|
---|
| 256 |
|
---|
| 257 | tClk.set(GPSweek, GPSweeks);
|
---|
| 258 | }
|
---|
[2911] | 259 | }
|
---|
[3491] | 260 | else if ( messageType == COTYPE_GPSHR ||
|
---|
| 261 | messageType == COTYPE_GLONASSHR ) {
|
---|
[3751] | 262 | if (tRao.valid() && tClk.valid()) {
|
---|
| 263 | int dummyIOD;
|
---|
| 264 | in >> dummyIOD >> hrClk;
|
---|
| 265 | hrClk /= t_CST::c;
|
---|
| 266 | }
|
---|
[3491] | 267 | }
|
---|
[2912] | 268 |
|
---|
| 269 | return success;
|
---|
[2911] | 270 | }
|
---|