| 1 |
|
|---|
| 2 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 3 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 4 | //
|
|---|
| 5 | // Copyright (C) 2007
|
|---|
| 6 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 7 | // http://www.bkg.bund.de
|
|---|
| 8 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 9 | // http://www.fsv.cvut.cz
|
|---|
| 10 | //
|
|---|
| 11 | // Email: euref-ip@bkg.bund.de
|
|---|
| 12 | //
|
|---|
| 13 | // This program is free software; you can redistribute it and/or
|
|---|
| 14 | // modify it under the terms of the GNU General Public License
|
|---|
| 15 | // as published by the Free Software Foundation, version 2.
|
|---|
| 16 | //
|
|---|
| 17 | // This program is distributed in the hope that it will be useful,
|
|---|
| 18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 20 | // GNU General Public License for more details.
|
|---|
| 21 | //
|
|---|
| 22 | // You should have received a copy of the GNU General Public License
|
|---|
| 23 | // along with this program; if not, write to the Free Software
|
|---|
| 24 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 25 |
|
|---|
| 26 | /* -------------------------------------------------------------------------
|
|---|
| 27 | * BKG NTRIP Client
|
|---|
| 28 | * -------------------------------------------------------------------------
|
|---|
| 29 | *
|
|---|
| 30 | * Class: t_pppThread, t_pppRun
|
|---|
| 31 | *
|
|---|
| 32 | * Purpose: Single PPP Client (running in its own thread)
|
|---|
| 33 | *
|
|---|
| 34 | * Author: L. Mervart
|
|---|
| 35 | *
|
|---|
| 36 | * Created: 29-Jul-2014
|
|---|
| 37 | *
|
|---|
| 38 | * Changes:
|
|---|
| 39 | *
|
|---|
| 40 | * -----------------------------------------------------------------------*/
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | #include <iostream>
|
|---|
| 44 | #include <iomanip>
|
|---|
| 45 | #include <string.h>
|
|---|
| 46 | #include <map>
|
|---|
| 47 |
|
|---|
| 48 | #include "pppThread.h"
|
|---|
| 49 | #include "bnccore.h"
|
|---|
| 50 | #include "bncephuser.h"
|
|---|
| 51 |
|
|---|
| 52 | using namespace BNC_PPP;
|
|---|
| 53 | using namespace std;
|
|---|
| 54 |
|
|---|
| 55 | // Constructor
|
|---|
| 56 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 57 | t_pppThread::t_pppThread(const t_pppOptions* opt) : QThread(0) {
|
|---|
| 58 | _opt = opt;
|
|---|
| 59 | _pppRun = 0;
|
|---|
| 60 | connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
|
|---|
| 61 |
|
|---|
| 62 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
|---|
| 63 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | // Destructor
|
|---|
| 67 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 68 | t_pppThread::~t_pppThread() {
|
|---|
| 69 | delete _pppRun;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | // Run (virtual)
|
|---|
| 73 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 74 | void t_pppThread::run() {
|
|---|
| 75 | try {
|
|---|
| 76 | _pppRun = new t_pppRun(_opt);
|
|---|
| 77 | QThread::exec();
|
|---|
| 78 | }
|
|---|
| 79 | catch (t_except exc) {
|
|---|
| 80 | _pppRun = 0;
|
|---|
| 81 | emit newMessage(QByteArray(exc.what().c_str()), true);
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | // Constructor
|
|---|
| 86 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 87 | t_pppRun::t_pppRun(const t_pppOptions* opt) {
|
|---|
| 88 | _opt = opt;
|
|---|
| 89 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
|---|
| 90 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
|---|
| 91 | if (_opt->_realTime) {
|
|---|
| 92 | connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
|
|---|
| 93 | this, SLOT(slotNewObs(QByteArray, QList<t_obs>)));
|
|---|
| 94 |
|
|---|
| 95 | connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
|
|---|
| 96 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
|---|
| 97 |
|
|---|
| 98 | connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
|
|---|
| 99 | this, SLOT(slotNewEphGlonass(glonassephemeris)));
|
|---|
| 100 |
|
|---|
| 101 | connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
|
|---|
| 102 | this, SLOT(slotNewEphGalileo(galileoephemeris)));
|
|---|
| 103 |
|
|---|
| 104 | connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
|
|---|
| 105 | this, SLOT(slotNewCorrections(QStringList)));
|
|---|
| 106 |
|
|---|
| 107 | for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
|
|---|
| 108 | _lastOrbCorrIOD[iPrn] = -1;
|
|---|
| 109 | _lastClkCorrValue[iPrn] = 0.0;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | _pppClient = new t_pppClient(_opt);
|
|---|
| 113 | }
|
|---|
| 114 | else {
|
|---|
| 115 | throw t_except("t_pppRun: post-processing not yet implemented");
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | // Destructor
|
|---|
| 120 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 121 | t_pppRun::~t_pppRun() {
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | //
|
|---|
| 125 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 126 | void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
|
|---|
| 127 | QMutexLocker locker(&_mutex);
|
|---|
| 128 | t_ephGPS eph;
|
|---|
| 129 | eph.set(&gpseph);
|
|---|
| 130 | _pppClient->putEphemeris(&eph);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | //
|
|---|
| 134 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 135 | void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
|
|---|
| 136 | QMutexLocker locker(&_mutex);
|
|---|
| 137 | t_ephGlo eph;
|
|---|
| 138 | eph.set(&gloeph);
|
|---|
| 139 | _pppClient->putEphemeris(&eph);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | //
|
|---|
| 143 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 144 | void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
|
|---|
| 145 | QMutexLocker locker(&_mutex);
|
|---|
| 146 | t_ephGal eph;
|
|---|
| 147 | eph.set(&galeph);
|
|---|
| 148 | _pppClient->putEphemeris(&eph);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | //
|
|---|
| 152 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 153 | void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
|
|---|
| 154 | QMutexLocker locker(&_mutex);
|
|---|
| 155 |
|
|---|
| 156 | if (string(staID.data()) != _opt->_roverName) {
|
|---|
| 157 | return;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | // Loop over all obsevations (possible different epochs)
|
|---|
| 161 | // -----------------------------------------------------
|
|---|
| 162 | QListIterator<t_obs> it(obsList);
|
|---|
| 163 | while (it.hasNext()) {
|
|---|
| 164 | const t_obs& oldObs = it.next();
|
|---|
| 165 | t_satObs* newObs = new t_satObs;
|
|---|
| 166 |
|
|---|
| 167 | newObs->_prn.set(oldObs.satSys, oldObs.satNum);
|
|---|
| 168 | newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
|
|---|
| 169 |
|
|---|
| 170 | // Find the corresponding data epoch or create a new one
|
|---|
| 171 | // -----------------------------------------------------
|
|---|
| 172 | t_epoData* epoch = 0;
|
|---|
| 173 | deque<t_epoData*>::const_iterator it;
|
|---|
| 174 | for (it = _epoData.begin(); it != _epoData.end(); it++) {
|
|---|
| 175 | if (newObs->_time == (*it)->_time) {
|
|---|
| 176 | epoch = *it;
|
|---|
| 177 | break;
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 | if (epoch == 0) {
|
|---|
| 181 | if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
|
|---|
| 182 | epoch = new t_epoData;
|
|---|
| 183 | epoch->_time = newObs->_time;
|
|---|
| 184 | _epoData.push_back(epoch);
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | // Fill the new observation and add it to the corresponding epoch
|
|---|
| 189 | // --------------------------------------------------------------
|
|---|
| 190 | if (epoch != 0) {
|
|---|
| 191 | epoch->_satObs.push_back(newObs);
|
|---|
| 192 | map<string, t_frqObs*> frqObsMap;
|
|---|
| 193 | for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
|
|---|
| 194 | string hlp(oldObs.rnxStr(iEntry).toAscii().data());
|
|---|
| 195 | if (hlp.length() == 3) {
|
|---|
| 196 | char obsType = hlp[0];
|
|---|
| 197 | string rnxType2ch = hlp.substr(1);
|
|---|
| 198 | if (obsType == 'C' || obsType == 'L') {
|
|---|
| 199 | t_frqObs* frqObs = 0;
|
|---|
| 200 | if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
|
|---|
| 201 | frqObs = new t_frqObs();
|
|---|
| 202 | frqObsMap[rnxType2ch] = frqObs;
|
|---|
| 203 | frqObs->_rnxType2ch = rnxType2ch;
|
|---|
| 204 | newObs->_obs.push_back(frqObs);
|
|---|
| 205 | }
|
|---|
| 206 | else {
|
|---|
| 207 | frqObs = frqObsMap[rnxType2ch];
|
|---|
| 208 | }
|
|---|
| 209 | if (obsType == 'C') {
|
|---|
| 210 | frqObs->_code = oldObs._measdata[iEntry];
|
|---|
| 211 | frqObs->_codeValid = true;
|
|---|
| 212 | }
|
|---|
| 213 | else if (obsType == 'L') {
|
|---|
| 214 | frqObs->_phase = oldObs._measdata[iEntry];
|
|---|
| 215 | frqObs->_phaseValid = true;
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | // Process the oldest epoch
|
|---|
| 224 | // ------------------------
|
|---|
| 225 | if (_epoData.size() > 1) {
|
|---|
| 226 |
|
|---|
| 227 | const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
|
|---|
| 228 |
|
|---|
| 229 | t_output output;
|
|---|
| 230 | _pppClient->processEpoch(satObs, &output);
|
|---|
| 231 |
|
|---|
| 232 | delete _epoData.front(); _epoData.pop_front();
|
|---|
| 233 |
|
|---|
| 234 | emit newMessage(QByteArray(output._log.c_str()), true);
|
|---|
| 235 | }
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | //
|
|---|
| 239 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 240 | void t_pppRun::slotNewCorrections(QStringList corrList) {
|
|---|
| 241 | QMutexLocker locker(&_mutex);
|
|---|
| 242 |
|
|---|
| 243 | if (_opt->_corrMount.empty()) {
|
|---|
| 244 | return;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | // Check the Mountpoint (source of corrections)
|
|---|
| 248 | // --------------------------------------------
|
|---|
| 249 | QMutableListIterator<QString> itm(corrList);
|
|---|
| 250 | while (itm.hasNext()) {
|
|---|
| 251 | QStringList hlp = itm.next().split(" ");
|
|---|
| 252 | if (hlp.size() > 0) {
|
|---|
| 253 | QString mountpoint = hlp[hlp.size()-1];
|
|---|
| 254 | if (mountpoint != QString(_opt->_corrMount.c_str())) {
|
|---|
| 255 | itm.remove();
|
|---|
| 256 | }
|
|---|
| 257 | }
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | if (corrList.size() == 0) {
|
|---|
| 261 | return;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | vector<t_orbCorr*> orbCorr;
|
|---|
| 265 | vector<t_clkCorr*> clkCorr;
|
|---|
| 266 | vector<t_satBias*> satBias;
|
|---|
| 267 |
|
|---|
| 268 | QListIterator<QString> it(corrList);
|
|---|
| 269 | while (it.hasNext()) {
|
|---|
| 270 | QString line = it.next();
|
|---|
| 271 |
|
|---|
| 272 | QTextStream in(&line);
|
|---|
| 273 | int messageType;
|
|---|
| 274 | int updateInterval;
|
|---|
| 275 | int GPSweek;
|
|---|
| 276 | double GPSweeks;
|
|---|
| 277 | QString prn;
|
|---|
| 278 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
|---|
| 279 |
|
|---|
| 280 | if ( t_corr::relevantMessageType(messageType) ) {
|
|---|
| 281 | t_corr corr;
|
|---|
| 282 | corr.readLine(line);
|
|---|
| 283 | if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
|---|
| 284 | messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
|
|---|
| 285 | t_orbCorr* cc = new t_orbCorr();
|
|---|
| 286 | cc->_prn.set(corr.prn.toAscii().data());
|
|---|
| 287 | cc->_iod = corr.iod;
|
|---|
| 288 | cc->_time = corr.tRao;
|
|---|
| 289 | cc->_system = 'R';
|
|---|
| 290 | cc->_xr[0] = corr.rao[0];
|
|---|
| 291 | cc->_xr[1] = corr.rao[1];
|
|---|
| 292 | cc->_xr[2] = corr.rao[2];
|
|---|
| 293 | cc->_dotXr[0] = corr.dotRao[0];
|
|---|
| 294 | cc->_dotXr[0] = corr.dotRao[1];
|
|---|
| 295 | cc->_dotXr[0] = corr.dotRao[2];
|
|---|
| 296 | orbCorr.push_back(cc);
|
|---|
| 297 |
|
|---|
| 298 | _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
|
|---|
| 299 | }
|
|---|
| 300 | else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
|---|
| 301 | messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
|
|---|
| 302 | t_clkCorr* cc = new t_clkCorr();
|
|---|
| 303 | cc->_prn.set(corr.prn.toAscii().data());
|
|---|
| 304 | cc->_iod = corr.iod;
|
|---|
| 305 | cc->_time = corr.tRao;
|
|---|
| 306 | cc->_dClk = corr.dClk;
|
|---|
| 307 | cc->_dotDClk = corr.dotDClk;
|
|---|
| 308 | cc->_dotDotDClk = corr.dotDotDClk;
|
|---|
| 309 | cc->_clkPartial = 0.0;
|
|---|
| 310 | if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
|
|---|
| 311 | int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
|
|---|
| 312 | if (lastIOD != -1) {
|
|---|
| 313 | cc->_iod = lastIOD;
|
|---|
| 314 | }
|
|---|
| 315 | else {
|
|---|
| 316 | delete cc;
|
|---|
| 317 | cc = 0;
|
|---|
| 318 | }
|
|---|
| 319 | }
|
|---|
| 320 | if (cc) {
|
|---|
| 321 | clkCorr.push_back(cc);
|
|---|
| 322 | }
|
|---|
| 323 | }
|
|---|
| 324 | }
|
|---|
| 325 | else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
|
|---|
| 326 | t_bias bias;
|
|---|
| 327 | bias.readLine(line);
|
|---|
| 328 | }
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | _pppClient->putOrbCorrections(orbCorr);
|
|---|
| 332 | _pppClient->putClkCorrections(clkCorr);
|
|---|
| 333 | _pppClient->putBiases(satBias);
|
|---|
| 334 |
|
|---|
| 335 | for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
|
|---|
| 336 | delete orbCorr[ii];
|
|---|
| 337 | }
|
|---|
| 338 | for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
|
|---|
| 339 | delete clkCorr[ii];
|
|---|
| 340 | }
|
|---|
| 341 | for (unsigned ii = 0; ii < satBias.size(); ii++) {
|
|---|
| 342 | delete satBias[ii];
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|