| 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: bncPPPthread
|
|---|
| 30 | *
|
|---|
| 31 | * Purpose: Precise Point Positioning
|
|---|
| 32 | *
|
|---|
| 33 | * Author: L. Mervart
|
|---|
| 34 | *
|
|---|
| 35 | * Created: 21-Nov-2009
|
|---|
| 36 | *
|
|---|
| 37 | * Changes:
|
|---|
| 38 | *
|
|---|
| 39 | * -----------------------------------------------------------------------*/
|
|---|
| 40 |
|
|---|
| 41 | #include <iomanip>
|
|---|
| 42 | #include <newmatio.h>
|
|---|
| 43 |
|
|---|
| 44 | #include "bncpppthread.h"
|
|---|
| 45 |
|
|---|
| 46 | extern "C" {
|
|---|
| 47 | #include "clock_orbit_rtcm.h"
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | using namespace std;
|
|---|
| 51 |
|
|---|
| 52 | // Constructor
|
|---|
| 53 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 54 | bncPPPthread::bncPPPthread(QByteArray staID) {
|
|---|
| 55 | _staID = staID;
|
|---|
| 56 | _isToBeDeleted = false;
|
|---|
| 57 | _data = 0;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | // Destructor
|
|---|
| 61 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 62 | bncPPPthread::~bncPPPthread() {
|
|---|
| 63 | if (isRunning()) {
|
|---|
| 64 | wait();
|
|---|
| 65 | }
|
|---|
| 66 | delete _data;
|
|---|
| 67 | QMapIterator<QString, t_eph*> it(_eph);
|
|---|
| 68 | while (it.hasNext()) {
|
|---|
| 69 | it.next();
|
|---|
| 70 | delete it.value();
|
|---|
| 71 | }
|
|---|
| 72 | QMapIterator<QString, t_corr*> ic(_corr);
|
|---|
| 73 | while (ic.hasNext()) {
|
|---|
| 74 | ic.next();
|
|---|
| 75 | delete ic.value();
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | //
|
|---|
| 80 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 81 | void bncPPPthread::terminate() {
|
|---|
| 82 | _isToBeDeleted = true;
|
|---|
| 83 | if (!isRunning()) {
|
|---|
| 84 | delete this;
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | // Run
|
|---|
| 89 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 90 | void bncPPPthread::run() {
|
|---|
| 91 | while (true) {
|
|---|
| 92 | try {
|
|---|
| 93 | if (_isToBeDeleted) {
|
|---|
| 94 | QThread::exit(0);
|
|---|
| 95 | this->deleteLater();
|
|---|
| 96 | return;
|
|---|
| 97 | }
|
|---|
| 98 | processEpoch();
|
|---|
| 99 | }
|
|---|
| 100 | catch (...) {
|
|---|
| 101 | emit(newMessage(_staID + "bncPPPthread exception", true));
|
|---|
| 102 | _isToBeDeleted = true;
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | //
|
|---|
| 108 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 109 | void bncPPPthread::slotNewEpochData(QList<p_obs> obsList) {
|
|---|
| 110 | QMutexLocker locker(&_mutex);
|
|---|
| 111 | QListIterator<p_obs> it(obsList);
|
|---|
| 112 |
|
|---|
| 113 | delete _data;
|
|---|
| 114 | _data = new t_data();
|
|---|
| 115 |
|
|---|
| 116 | while (it.hasNext()) {
|
|---|
| 117 | p_obs pp = it.next();
|
|---|
| 118 | t_obsInternal* obs = &(pp->_o);
|
|---|
| 119 | QByteArray staID = QByteArray(obs->StatID);
|
|---|
| 120 | if (staID == _staID) {
|
|---|
| 121 | if (_data->tt.undef()) {
|
|---|
| 122 | _data->tt.set(obs->GPSWeek, obs->GPSWeeks);
|
|---|
| 123 | }
|
|---|
| 124 | ++_data->numSat;
|
|---|
| 125 | _data->prn[_data->numSat] =
|
|---|
| 126 | QString("%1%2").arg(obs->satSys).arg(obs->satNum, 2, 10, QChar('0'));
|
|---|
| 127 | _data->C1[_data->numSat] = obs->C1;
|
|---|
| 128 | _data->C2[_data->numSat] = obs->C2;
|
|---|
| 129 | _data->P1[_data->numSat] = obs->P1;
|
|---|
| 130 | _data->P2[_data->numSat] = obs->P2;
|
|---|
| 131 | _data->L1[_data->numSat] = obs->L1;
|
|---|
| 132 | _data->L2[_data->numSat] = obs->L2;
|
|---|
| 133 | }
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | //
|
|---|
| 138 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 139 | void bncPPPthread::slotNewEphGPS(gpsephemeris gpseph) {
|
|---|
| 140 | QMutexLocker locker(&_mutex);
|
|---|
| 141 |
|
|---|
| 142 | QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
|
|---|
| 143 |
|
|---|
| 144 | if (_eph.contains(prn)) {
|
|---|
| 145 | (static_cast<t_ephGPS*>(_eph.value(prn)))->set(&gpseph);
|
|---|
| 146 | }
|
|---|
| 147 | else {
|
|---|
| 148 | t_ephGPS* ee = new t_ephGPS();
|
|---|
| 149 | ee->set(&gpseph);
|
|---|
| 150 | _eph[prn] = ee;
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | //
|
|---|
| 155 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 156 | void bncPPPthread::slotNewCorrections(QList<QString> corrList) {
|
|---|
| 157 | QMutexLocker locker(&_mutex);
|
|---|
| 158 | QListIterator<QString> it(corrList);
|
|---|
| 159 | while (it.hasNext()) {
|
|---|
| 160 | QTextStream in(it.next().toAscii());
|
|---|
| 161 | int messageType;
|
|---|
| 162 | int updateInterval;
|
|---|
| 163 | int GPSweek;
|
|---|
| 164 | double GPSweeks;
|
|---|
| 165 | QString prn;
|
|---|
| 166 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
|---|
| 167 | if ( messageType == COTYPE_GPSCOMBINED ||
|
|---|
| 168 | messageType == COTYPE_GLONASSCOMBINED ) {
|
|---|
| 169 | t_corr* cc = 0;
|
|---|
| 170 | if (_corr.contains(prn)) {
|
|---|
| 171 | cc = _corr.value(prn);
|
|---|
| 172 | }
|
|---|
| 173 | else {
|
|---|
| 174 | cc = new t_corr();
|
|---|
| 175 | _corr[prn] = cc;
|
|---|
| 176 | }
|
|---|
| 177 | cc->tt.set(GPSweek, GPSweeks);
|
|---|
| 178 | in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
|
|---|
| 179 | }
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | // Satellite Position
|
|---|
| 184 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 185 | t_irc bncPPPthread::getSatPos(const t_time& tt, const QString& prn,
|
|---|
| 186 | ColumnVector& xc, ColumnVector& vv) {
|
|---|
| 187 |
|
|---|
| 188 | if (_eph.contains(prn)) {
|
|---|
| 189 | _eph.value(prn)->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
|---|
| 190 | return success;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | return failure;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | //
|
|---|
| 197 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 198 | void bncPPPthread::processEpoch() {
|
|---|
| 199 | QMutexLocker locker(&_mutex);
|
|---|
| 200 |
|
|---|
| 201 | if (!_data) {
|
|---|
| 202 | return;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | for (int is = 1; is <= _data->numSat; is++) {
|
|---|
| 206 | QString prn = _data->prn[is];
|
|---|
| 207 |
|
|---|
| 208 | ColumnVector xc(4);
|
|---|
| 209 | ColumnVector vv(3);
|
|---|
| 210 |
|
|---|
| 211 | if (getSatPos(_data->tt, prn, xc, vv) == success) {
|
|---|
| 212 | cout << _data->tt.timestr(1) << " " << prn.toAscii().data() << " "
|
|---|
| 213 | << setprecision(3) << xc.t();
|
|---|
| 214 | }
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | cout << endl;
|
|---|
| 218 | cout.flush();
|
|---|
| 219 |
|
|---|
| 220 | delete _data;
|
|---|
| 221 | _data = 0;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|