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 | _dataHlp = 0;
|
---|
59 | }
|
---|
60 |
|
---|
61 | // Destructor
|
---|
62 | ////////////////////////////////////////////////////////////////////////////
|
---|
63 | bncPPPthread::~bncPPPthread() {
|
---|
64 | if (isRunning()) {
|
---|
65 | wait();
|
---|
66 | }
|
---|
67 | delete _data;
|
---|
68 | delete _dataHlp;
|
---|
69 | QMapIterator<QString, t_eph*> it(_eph);
|
---|
70 | while (it.hasNext()) {
|
---|
71 | it.next();
|
---|
72 | delete it.value();
|
---|
73 | }
|
---|
74 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
75 | while (ic.hasNext()) {
|
---|
76 | ic.next();
|
---|
77 | delete ic.value();
|
---|
78 | }
|
---|
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 | }
|
---|
100 | processEpoch();
|
---|
101 | }
|
---|
102 | catch (...) {
|
---|
103 | emit(newMessage(_staID + "bncPPPthread exception", true));
|
---|
104 | _isToBeDeleted = true;
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | //
|
---|
110 | ////////////////////////////////////////////////////////////////////////////
|
---|
111 | void bncPPPthread::putNewObs(p_obs pp) {
|
---|
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 | } // end of mutex
|
---|
146 |
|
---|
147 | processEpoch(); // currently in the same thread as bncgetthread
|
---|
148 | }
|
---|
149 |
|
---|
150 | //
|
---|
151 | ////////////////////////////////////////////////////////////////////////////
|
---|
152 | void bncPPPthread::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
153 | QMutexLocker locker(&_mutex);
|
---|
154 |
|
---|
155 | QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
|
---|
156 |
|
---|
157 | if (_eph.contains(prn)) {
|
---|
158 | (static_cast<t_ephGPS*>(_eph.value(prn)))->set(&gpseph);
|
---|
159 | }
|
---|
160 | else {
|
---|
161 | t_ephGPS* ee = new t_ephGPS();
|
---|
162 | ee->set(&gpseph);
|
---|
163 | _eph[prn] = ee;
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | //
|
---|
168 | ////////////////////////////////////////////////////////////////////////////
|
---|
169 | void bncPPPthread::slotNewCorrections(QList<QString> corrList) {
|
---|
170 | QMutexLocker locker(&_mutex);
|
---|
171 | QListIterator<QString> it(corrList);
|
---|
172 | while (it.hasNext()) {
|
---|
173 | QTextStream in(it.next().toAscii());
|
---|
174 | int messageType;
|
---|
175 | int updateInterval;
|
---|
176 | int GPSweek;
|
---|
177 | double GPSweeks;
|
---|
178 | QString prn;
|
---|
179 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
180 | if ( messageType == COTYPE_GPSCOMBINED ||
|
---|
181 | messageType == COTYPE_GLONASSCOMBINED ) {
|
---|
182 | t_corr* cc = 0;
|
---|
183 | if (_corr.contains(prn)) {
|
---|
184 | cc = _corr.value(prn);
|
---|
185 | }
|
---|
186 | else {
|
---|
187 | cc = new t_corr();
|
---|
188 | _corr[prn] = cc;
|
---|
189 | }
|
---|
190 | cc->tt.set(GPSweek, GPSweeks);
|
---|
191 | in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
|
---|
192 | }
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | // Satellite Position
|
---|
197 | ////////////////////////////////////////////////////////////////////////////
|
---|
198 | t_irc bncPPPthread::getSatPos(const t_time& tt, const QString& prn,
|
---|
199 | ColumnVector& xc, ColumnVector& vv) {
|
---|
200 |
|
---|
201 | if (_eph.contains(prn)) {
|
---|
202 | _eph.value(prn)->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
203 | return success;
|
---|
204 | }
|
---|
205 |
|
---|
206 | return failure;
|
---|
207 | }
|
---|
208 |
|
---|
209 | //
|
---|
210 | ////////////////////////////////////////////////////////////////////////////
|
---|
211 | void bncPPPthread::processEpoch() {
|
---|
212 | QMutexLocker locker(&_mutex);
|
---|
213 |
|
---|
214 | if (!_data) {
|
---|
215 | return;
|
---|
216 | }
|
---|
217 |
|
---|
218 | for (int is = 1; is <= _data->numSat; is++) {
|
---|
219 | QString prn = _data->prn[is];
|
---|
220 |
|
---|
221 | ColumnVector xc(4);
|
---|
222 | ColumnVector vv(3);
|
---|
223 |
|
---|
224 | cout.setf(ios::fixed);
|
---|
225 |
|
---|
226 | if (getSatPos(_data->tt, prn, xc, vv) == success) {
|
---|
227 | cout << _data->tt.timestr(1) << " " << prn.toAscii().data() << " "
|
---|
228 | << setw(14) << setprecision(3) << xc(1) << " "
|
---|
229 | << setw(14) << setprecision(3) << xc(2) << " "
|
---|
230 | << setw(14) << setprecision(3) << xc(3) << " "
|
---|
231 | << setw(14) << setprecision(6) << xc(4)*1.e6 << endl;
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | cout << endl;
|
---|
236 | cout.flush();
|
---|
237 |
|
---|
238 | delete _data;
|
---|
239 | _data = 0;
|
---|
240 | }
|
---|
241 |
|
---|