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