| 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: bncPPPclient
|
|---|
| 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 "bncpppclient.h"
|
|---|
| 45 | #include "bncutils.h"
|
|---|
| 46 |
|
|---|
| 47 | extern "C" {
|
|---|
| 48 | #include "clock_orbit_rtcm.h"
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | using namespace std;
|
|---|
| 52 |
|
|---|
| 53 | // Constructor
|
|---|
| 54 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 55 | bncPPPclient::bncPPPclient(QByteArray staID) {
|
|---|
| 56 | _staID = staID;
|
|---|
| 57 | _epoData = 0;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | // Destructor
|
|---|
| 61 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 62 | bncPPPclient::~bncPPPclient() {
|
|---|
| 63 | delete _epoData;
|
|---|
| 64 | QMapIterator<QString, t_eph*> it(_eph);
|
|---|
| 65 | while (it.hasNext()) {
|
|---|
| 66 | it.next();
|
|---|
| 67 | delete it.value();
|
|---|
| 68 | }
|
|---|
| 69 | QMapIterator<QString, t_corr*> ic(_corr);
|
|---|
| 70 | while (ic.hasNext()) {
|
|---|
| 71 | ic.next();
|
|---|
| 72 | delete ic.value();
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | //
|
|---|
| 77 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 78 | void bncPPPclient::putNewObs(p_obs pp) {
|
|---|
| 79 | QMutexLocker locker(&_mutex);
|
|---|
| 80 |
|
|---|
| 81 | t_obsInternal* obs = &(pp->_o);
|
|---|
| 82 |
|
|---|
| 83 | t_time tt(obs->GPSWeek, obs->GPSWeeks);
|
|---|
| 84 |
|
|---|
| 85 | if (!_epoData) {
|
|---|
| 86 | _epoData = new t_epoData();
|
|---|
| 87 | _epoData->tt = tt;
|
|---|
| 88 | }
|
|---|
| 89 | else if (tt != _epoData->tt) {
|
|---|
| 90 | processEpoch();
|
|---|
| 91 | delete _epoData;
|
|---|
| 92 | _epoData = new t_epoData();
|
|---|
| 93 | _epoData->tt = tt;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | t_satData* satData = new t_satData();
|
|---|
| 97 |
|
|---|
| 98 | satData->C1 = obs->C1;
|
|---|
| 99 | satData->C2 = obs->C2;
|
|---|
| 100 | satData->P1 = obs->P1;
|
|---|
| 101 | satData->P2 = obs->P2;
|
|---|
| 102 | satData->L1 = obs->L1;
|
|---|
| 103 | satData->L2 = obs->L2;
|
|---|
| 104 |
|
|---|
| 105 | QString prn =
|
|---|
| 106 | QString("%1%2").arg(obs->satSys).arg(obs->satNum, 2, 10, QChar('0'));
|
|---|
| 107 |
|
|---|
| 108 | _epoData->satData[prn] = satData;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | //
|
|---|
| 112 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 113 | void bncPPPclient::slotNewEphGPS(gpsephemeris gpseph) {
|
|---|
| 114 | QMutexLocker locker(&_mutex);
|
|---|
| 115 |
|
|---|
| 116 | QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
|
|---|
| 117 |
|
|---|
| 118 | if (_eph.contains(prn)) {
|
|---|
| 119 | t_ephGPS* ee = static_cast<t_ephGPS*>(_eph.value(prn));
|
|---|
| 120 | if ( (ee->GPSweek() < gpseph.GPSweek) ||
|
|---|
| 121 | (ee->GPSweek() == gpseph.GPSweek &&
|
|---|
| 122 | ee->TOC() < gpseph.TOC) ) {
|
|---|
| 123 | ee->set(&gpseph);
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 | else {
|
|---|
| 127 | t_ephGPS* ee = new t_ephGPS();
|
|---|
| 128 | ee->set(&gpseph);
|
|---|
| 129 | _eph[prn] = ee;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | //
|
|---|
| 134 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 135 | void bncPPPclient::slotNewCorrections(QList<QString> corrList) {
|
|---|
| 136 | QMutexLocker locker(&_mutex);
|
|---|
| 137 | QListIterator<QString> it(corrList);
|
|---|
| 138 | while (it.hasNext()) {
|
|---|
| 139 | QTextStream in(it.next().toAscii());
|
|---|
| 140 | int messageType;
|
|---|
| 141 | int updateInterval;
|
|---|
| 142 | int GPSweek;
|
|---|
| 143 | double GPSweeks;
|
|---|
| 144 | QString prn;
|
|---|
| 145 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
|---|
| 146 | if ( messageType == COTYPE_GPSCOMBINED ||
|
|---|
| 147 | messageType == COTYPE_GLONASSCOMBINED ) {
|
|---|
| 148 | t_corr* cc = 0;
|
|---|
| 149 | if (_corr.contains(prn)) {
|
|---|
| 150 | cc = _corr.value(prn);
|
|---|
| 151 | }
|
|---|
| 152 | else {
|
|---|
| 153 | cc = new t_corr();
|
|---|
| 154 | _corr[prn] = cc;
|
|---|
| 155 | }
|
|---|
| 156 | cc->tt.set(GPSweek, GPSweeks);
|
|---|
| 157 | cc->rao.ReSize(3);
|
|---|
| 158 | in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
|
|---|
| 159 | }
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | // Satellite Position
|
|---|
| 164 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 165 | t_irc bncPPPclient::getSatPos(const t_time& tt, const QString& prn,
|
|---|
| 166 | ColumnVector& xc, ColumnVector& vv, bool& corr) {
|
|---|
| 167 |
|
|---|
| 168 | const double MAXAGE = 120.0;
|
|---|
| 169 |
|
|---|
| 170 | corr = false;
|
|---|
| 171 |
|
|---|
| 172 | if (_eph.contains(prn)) {
|
|---|
| 173 | t_eph* ee = _eph.value(prn);
|
|---|
| 174 | ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
|---|
| 175 |
|
|---|
| 176 | if (_corr.contains(prn)) {
|
|---|
| 177 | t_corr* cc = _corr.value(prn);
|
|---|
| 178 | if (ee->IOD() == cc->iod && (tt - cc->tt) < MAXAGE) {
|
|---|
| 179 | corr = true;
|
|---|
| 180 | applyCorr(cc, xc, vv);
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | return success;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | return failure;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | //
|
|---|
| 191 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 192 | void bncPPPclient::applyCorr(const t_corr* cc, ColumnVector& xc,
|
|---|
| 193 | ColumnVector& vv) {
|
|---|
| 194 | ColumnVector dx(3);
|
|---|
| 195 | RSW_to_XYZ(xc.Rows(1,3), vv, cc->rao, dx);
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | //
|
|---|
| 201 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 202 | void bncPPPclient::processEpoch() {
|
|---|
| 203 |
|
|---|
| 204 | cout.setf(ios::fixed);
|
|---|
| 205 |
|
|---|
| 206 | QMapIterator<QString, t_satData*> it(_epoData->satData);
|
|---|
| 207 | while (it.hasNext()) {
|
|---|
| 208 | it.next();
|
|---|
| 209 | QString prn = it.key();
|
|---|
| 210 | t_satData* satData = it.value();
|
|---|
| 211 |
|
|---|
| 212 | ColumnVector xc(4);
|
|---|
| 213 | ColumnVector vv(3);
|
|---|
| 214 |
|
|---|
| 215 | bool corr = false;
|
|---|
| 216 | if (getSatPos(_epoData->tt, prn, xc, vv, corr) == success) {
|
|---|
| 217 | cout << _epoData->tt.timestr(1) << " " << prn.toAscii().data() << " "
|
|---|
| 218 | << setw(14) << setprecision(3) << xc(1) << " "
|
|---|
| 219 | << setw(14) << setprecision(3) << xc(2) << " "
|
|---|
| 220 | << setw(14) << setprecision(3) << xc(3) << " "
|
|---|
| 221 | << setw(12) << setprecision(6) << xc(4)*1.e6;
|
|---|
| 222 | if (corr) {
|
|---|
| 223 | cout << endl;
|
|---|
| 224 | }
|
|---|
| 225 | else {
|
|---|
| 226 | cout << " !\n";
|
|---|
| 227 | }
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | cout << endl;
|
|---|
| 232 | cout.flush();
|
|---|
| 233 | }
|
|---|