source: ntrip/trunk/BNC/bncpppthread.cpp@ 2032

Last change on this file since 2032 was 2032, checked in by mervart, 14 years ago

* empty log message *

File size: 6.1 KB
Line 
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
46extern "C" {
47#include "clock_orbit_rtcm.h"
48}
49
50using namespace std;
51
52// Constructor
53////////////////////////////////////////////////////////////////////////////
54bncPPPthread::bncPPPthread(QByteArray staID) {
55 _staID = staID;
56 _isToBeDeleted = false;
57 _data = 0;
58 _dataHlp = 0;
59}
60
61// Destructor
62////////////////////////////////////////////////////////////////////////////
63bncPPPthread::~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////////////////////////////////////////////////////////////////////////////
83void bncPPPthread::terminate() {
84 _isToBeDeleted = true;
85 if (!isRunning()) {
86 delete this;
87 }
88}
89
90// Run
91////////////////////////////////////////////////////////////////////////////
92void 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////////////////////////////////////////////////////////////////////////////
111void 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
146 cout << tt.timestr(1) << " " << obs->satNum << endl;
147 cout.flush();
148
149 } // end of mutex
150
151 processEpoch(); // currently in the same thread of bncgetthread;
152}
153
154//
155////////////////////////////////////////////////////////////////////////////
156void bncPPPthread::slotNewEphGPS(gpsephemeris gpseph) {
157 QMutexLocker locker(&_mutex);
158
159 QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
160
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 }
169}
170
171//
172////////////////////////////////////////////////////////////////////////////
173void bncPPPthread::slotNewCorrections(QList<QString> corrList) {
174 QMutexLocker locker(&_mutex);
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 }
194 cc->tt.set(GPSweek, GPSweeks);
195 in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
196 }
197 }
198}
199
200// Satellite Position
201////////////////////////////////////////////////////////////////////////////
202t_irc bncPPPthread::getSatPos(const t_time& tt, const QString& prn,
203 ColumnVector& xc, ColumnVector& vv) {
204
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;
211}
212
213//
214////////////////////////////////////////////////////////////////////////////
215void bncPPPthread::processEpoch() {
216 QMutexLocker locker(&_mutex);
217
218 if (!_data) {
219 return;
220 }
221
222 for (int is = 1; is <= _data->numSat; is++) {
223 QString prn = _data->prn[is];
224
225 ColumnVector xc(4);
226 ColumnVector vv(3);
227
228 if (getSatPos(_data->tt, prn, xc, vv) == success) {
229 cout << _data->tt.timestr(1) << " " << prn.toAscii().data() << " "
230 << setprecision(3) << xc.t();
231 }
232 }
233
234 cout << endl;
235 cout.flush();
236
237 delete _data;
238 _data = 0;
239}
240
Note: See TracBrowser for help on using the repository browser.