[4757] | 1 |
|
---|
[5719] | 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 | *
|
---|
[5813] | 30 | * Class: t_pppThread, t_pppRun
|
---|
[5719] | 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 |
|
---|
[4757] | 43 | #include <iostream>
|
---|
[4775] | 44 | #include <iomanip>
|
---|
[4757] | 45 | #include <string.h>
|
---|
[5782] | 46 | #include <map>
|
---|
[4757] | 47 |
|
---|
[5813] | 48 | #include "pppThread.h"
|
---|
[5068] | 49 | #include "bnccore.h"
|
---|
[5834] | 50 | #include "bncephuser.h"
|
---|
[4757] | 51 |
|
---|
[5814] | 52 | using namespace BNC_PPP;
|
---|
[4757] | 53 | using namespace std;
|
---|
| 54 |
|
---|
| 55 | // Constructor
|
---|
| 56 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5813] | 57 | t_pppThread::t_pppThread(const t_pppOptions* opt) : QThread(0) {
|
---|
[5774] | 58 | _opt = opt;
|
---|
| 59 | _pppRun = 0;
|
---|
[5775] | 60 | connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
|
---|
| 61 |
|
---|
[5767] | 62 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 63 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
---|
[4763] | 64 | }
|
---|
| 65 |
|
---|
| 66 | // Destructor
|
---|
| 67 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5813] | 68 | t_pppThread::~t_pppThread() {
|
---|
[5731] | 69 | delete _pppRun;
|
---|
[4763] | 70 | }
|
---|
| 71 |
|
---|
| 72 | // Run (virtual)
|
---|
| 73 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5813] | 74 | void t_pppThread::run() {
|
---|
[5742] | 75 | try {
|
---|
| 76 | _pppRun = new t_pppRun(_opt);
|
---|
[5775] | 77 | QThread::exec();
|
---|
[5742] | 78 | }
|
---|
[5825] | 79 | catch (t_except exc) {
|
---|
[5768] | 80 | _pppRun = 0;
|
---|
[5766] | 81 | emit newMessage(QByteArray(exc.what().c_str()), true);
|
---|
[5742] | 82 | }
|
---|
[5731] | 83 | }
|
---|
| 84 |
|
---|
| 85 | // Constructor
|
---|
| 86 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5810] | 87 | t_pppRun::t_pppRun(const t_pppOptions* opt) {
|
---|
[5731] | 88 | _opt = opt;
|
---|
[5767] | 89 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 90 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
---|
[5742] | 91 | if (_opt->_realTime) {
|
---|
[5729] | 92 | connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
|
---|
| 93 | this, SLOT(slotNewObs(QByteArray, QList<t_obs>)));
|
---|
[4757] | 94 |
|
---|
[5722] | 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)));
|
---|
[4757] | 103 |
|
---|
[5732] | 104 | connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
|
---|
| 105 | this, SLOT(slotNewCorrections(QStringList)));
|
---|
[5742] | 106 |
|
---|
[5761] | 107 | _pppClient = new t_pppClient(_opt);
|
---|
[5722] | 108 | }
|
---|
[5742] | 109 | else {
|
---|
[5825] | 110 | throw t_except("t_pppRun: post-processing not yet implemented");
|
---|
[5742] | 111 | }
|
---|
[5731] | 112 | }
|
---|
[5729] | 113 |
|
---|
[5731] | 114 | // Destructor
|
---|
| 115 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 116 | t_pppRun::~t_pppRun() {
|
---|
[4757] | 117 | }
|
---|
| 118 |
|
---|
| 119 | //
|
---|
| 120 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5731] | 121 | void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
[4757] | 122 | QMutexLocker locker(&_mutex);
|
---|
[5742] | 123 | t_ephGPS eph;
|
---|
| 124 | eph.set(&gpseph);
|
---|
[5772] | 125 | _pppClient->putEphemeris(&eph);
|
---|
[4757] | 126 | }
|
---|
| 127 |
|
---|
| 128 | //
|
---|
| 129 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5731] | 130 | void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
[4757] | 131 | QMutexLocker locker(&_mutex);
|
---|
[5769] | 132 | t_ephGlo eph;
|
---|
| 133 | eph.set(&gloeph);
|
---|
[5772] | 134 | _pppClient->putEphemeris(&eph);
|
---|
[4757] | 135 | }
|
---|
| 136 |
|
---|
| 137 | //
|
---|
| 138 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5769] | 139 | void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
|
---|
[5681] | 140 | QMutexLocker locker(&_mutex);
|
---|
[5769] | 141 | t_ephGal eph;
|
---|
| 142 | eph.set(&galeph);
|
---|
[5772] | 143 | _pppClient->putEphemeris(&eph);
|
---|
[4757] | 144 | }
|
---|
| 145 |
|
---|
| 146 | //
|
---|
| 147 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5731] | 148 | void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
|
---|
[4757] | 149 | QMutexLocker locker(&_mutex);
|
---|
[5766] | 150 |
|
---|
[5777] | 151 | if (string(staID.data()) != _opt->_roverName) {
|
---|
| 152 | return;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[5791] | 155 | // Loop over all obsevations (possible different epochs)
|
---|
| 156 | // -----------------------------------------------------
|
---|
[5778] | 157 | QListIterator<t_obs> it(obsList);
|
---|
| 158 | while (it.hasNext()) {
|
---|
[5780] | 159 | const t_obs& oldObs = it.next();
|
---|
[5819] | 160 | t_satObs* newObs = new t_satObs;
|
---|
[5781] | 161 |
|
---|
| 162 | newObs->_prn.set(oldObs.satSys, oldObs.satNum);
|
---|
| 163 | newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
|
---|
[5780] | 164 |
|
---|
[5791] | 165 | // Find the corresponding data epoch or create a new one
|
---|
| 166 | // -----------------------------------------------------
|
---|
[5833] | 167 | t_epoData* epoch = 0;
|
---|
| 168 | deque<t_epoData*>::const_iterator it;
|
---|
| 169 | for (it = _epoData.begin(); it != _epoData.end(); it++) {
|
---|
[5791] | 170 | if (newObs->_time == (*it)->_time) {
|
---|
[5833] | 171 | epoch = *it;
|
---|
[5791] | 172 | break;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
[5833] | 175 | if (epoch == 0) {
|
---|
| 176 | if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
|
---|
| 177 | epoch = new t_epoData;
|
---|
| 178 | epoch->_time = newObs->_time;
|
---|
| 179 | _epoData.push_back(epoch);
|
---|
[5791] | 180 | }
|
---|
| 181 | }
|
---|
[5790] | 182 |
|
---|
[5791] | 183 | // Fill the new observation and add it to the corresponding epoch
|
---|
| 184 | // --------------------------------------------------------------
|
---|
[5833] | 185 | if (epoch != 0) {
|
---|
| 186 | epoch->_satObs.push_back(newObs);
|
---|
[5832] | 187 | map<string, t_frqObs*> frqObsMap;
|
---|
[5791] | 188 | for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
|
---|
| 189 | string hlp(oldObs.rnxStr(iEntry).toAscii().data());
|
---|
| 190 | if (hlp.length() == 3) {
|
---|
| 191 | char obsType = hlp[0];
|
---|
| 192 | string rnxType2ch = hlp.substr(1);
|
---|
| 193 | if (obsType == 'C' || obsType == 'L') {
|
---|
[5832] | 194 | t_frqObs* frqObs = 0;
|
---|
| 195 | if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
|
---|
| 196 | frqObs = new t_frqObs();
|
---|
| 197 | frqObsMap[rnxType2ch] = frqObs;
|
---|
| 198 | frqObs->_rnxType2ch = rnxType2ch;
|
---|
| 199 | newObs->_obs.push_back(frqObs);
|
---|
[5791] | 200 | }
|
---|
| 201 | else {
|
---|
[5832] | 202 | frqObs = frqObsMap[rnxType2ch];
|
---|
[5791] | 203 | }
|
---|
| 204 | if (obsType == 'C') {
|
---|
[5832] | 205 | frqObs->_code = oldObs._measdata[iEntry];
|
---|
| 206 | frqObs->_codeValid = true;
|
---|
[5791] | 207 | }
|
---|
| 208 | else if (obsType == 'L') {
|
---|
[5832] | 209 | frqObs->_phase = oldObs._measdata[iEntry];
|
---|
| 210 | frqObs->_phaseValid = true;
|
---|
[5791] | 211 | }
|
---|
[5783] | 212 | }
|
---|
| 213 | }
|
---|
[5782] | 214 | }
|
---|
| 215 | }
|
---|
[5778] | 216 | }
|
---|
[5772] | 217 |
|
---|
[5791] | 218 | // Process the oldest epoch
|
---|
| 219 | // ------------------------
|
---|
[5833] | 220 | if (_epoData.size() > 1) {
|
---|
[5772] | 221 |
|
---|
[5833] | 222 | const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
|
---|
[5791] | 223 |
|
---|
| 224 | t_output output;
|
---|
[5823] | 225 | _pppClient->processEpoch(satObs, &output);
|
---|
[5791] | 226 |
|
---|
[5833] | 227 | delete _epoData.front(); _epoData.pop_front();
|
---|
[5791] | 228 |
|
---|
| 229 | emit newMessage(QByteArray(output._log.c_str()), true);
|
---|
[5779] | 230 | }
|
---|
[5589] | 231 | }
|
---|
[5525] | 232 |
|
---|
[5833] | 233 | //
|
---|
| 234 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 235 | void t_pppRun::slotNewCorrections(QStringList corrList) {
|
---|
| 236 | QMutexLocker locker(&_mutex);
|
---|
| 237 |
|
---|
[5834] | 238 | if (_opt->_corrMount.empty()) {
|
---|
| 239 | return;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | // Check the Mountpoint (source of corrections)
|
---|
| 243 | // --------------------------------------------
|
---|
| 244 | QMutableListIterator<QString> itm(corrList);
|
---|
| 245 | while (itm.hasNext()) {
|
---|
| 246 | QStringList hlp = itm.next().split(" ");
|
---|
| 247 | if (hlp.size() > 0) {
|
---|
| 248 | QString mountpoint = hlp[hlp.size()-1];
|
---|
| 249 | if (mountpoint != QString(_opt->_corrMount.c_str())) {
|
---|
| 250 | itm.remove();
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | if (corrList.size() == 0) {
|
---|
| 256 | return;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[5835] | 259 | vector<t_orbCorr*> orbCorr;
|
---|
| 260 | vector<t_clkCorr*> clkCorr;
|
---|
| 261 | vector<t_satBias*> satBias;
|
---|
| 262 |
|
---|
[5834] | 263 | QListIterator<QString> it(corrList);
|
---|
[5833] | 264 | while (it.hasNext()) {
|
---|
[5834] | 265 | QString line = it.next();
|
---|
| 266 |
|
---|
| 267 | QTextStream in(&line);
|
---|
| 268 | int messageType;
|
---|
| 269 | int updateInterval;
|
---|
| 270 | int GPSweek;
|
---|
| 271 | double GPSweeks;
|
---|
| 272 | QString prn;
|
---|
| 273 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
| 274 |
|
---|
| 275 | if ( t_corr::relevantMessageType(messageType) ) {
|
---|
| 276 | t_corr corr;
|
---|
| 277 | corr.readLine(line);
|
---|
| 278 | }
|
---|
| 279 | else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
|
---|
| 280 | t_bias bias;
|
---|
| 281 | bias.readLine(line);
|
---|
| 282 | }
|
---|
[5833] | 283 | }
|
---|
| 284 |
|
---|
[5835] | 285 | _pppClient->putOrbCorrections(orbCorr);
|
---|
| 286 | _pppClient->putClkCorrections(clkCorr);
|
---|
| 287 | _pppClient->putBiases(satBias);
|
---|
| 288 |
|
---|
| 289 | for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
|
---|
| 290 | delete orbCorr[ii];
|
---|
| 291 | }
|
---|
| 292 | for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
|
---|
| 293 | delete clkCorr[ii];
|
---|
| 294 | }
|
---|
| 295 | for (unsigned ii = 0; ii < satBias.size(); ii++) {
|
---|
| 296 | delete satBias[ii];
|
---|
| 297 | }
|
---|
[5833] | 298 | }
|
---|