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