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: bncGetThread
|
---|
30 | *
|
---|
31 | * Purpose: Thread that retrieves data from NTRIP caster
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 24-Dec-2005
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <stdlib.h>
|
---|
42 | #include <iomanip>
|
---|
43 | #include <sstream>
|
---|
44 |
|
---|
45 | #include <QFile>
|
---|
46 | #include <QTextStream>
|
---|
47 | #include <QtNetwork>
|
---|
48 | #include <QTime>
|
---|
49 |
|
---|
50 | #include "bncgetthread.h"
|
---|
51 | #include "bnctabledlg.h"
|
---|
52 | #include "bncapp.h"
|
---|
53 | #include "bncutils.h"
|
---|
54 | #include "bncrinex.h"
|
---|
55 | #include "bnczerodecoder.h"
|
---|
56 |
|
---|
57 | #include "RTCM/RTCM2Decoder.h"
|
---|
58 | #include "RTCM3/RTCM3Decoder.h"
|
---|
59 | #include "RTIGS/RTIGSDecoder.h"
|
---|
60 | #include "GPSS/gpssDecoder.h"
|
---|
61 | #include "serial/qextserialport.h"
|
---|
62 |
|
---|
63 | using namespace std;
|
---|
64 |
|
---|
65 | // Constructor 1
|
---|
66 | ////////////////////////////////////////////////////////////////////////////
|
---|
67 | bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
|
---|
68 | const QByteArray& format) {
|
---|
69 |
|
---|
70 | _format = format;
|
---|
71 |
|
---|
72 | int iSep = rawInpFileName.lastIndexOf(QDir::separator());
|
---|
73 | _staID = rawInpFileName.mid(iSep+1,4);
|
---|
74 |
|
---|
75 | initialize();
|
---|
76 |
|
---|
77 | _inspSegm = 0;
|
---|
78 |
|
---|
79 | _rawInpFile = new QFile(rawInpFileName);
|
---|
80 | _rawInpFile->open(QIODevice::ReadOnly);
|
---|
81 |
|
---|
82 | if (!_rnx) {
|
---|
83 | cerr << "no RINEX path specified" << endl;
|
---|
84 | ::exit(0);
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Constructor 2
|
---|
89 | ////////////////////////////////////////////////////////////////////////////
|
---|
90 | bncGetThread::bncGetThread(const QUrl& mountPoint,
|
---|
91 | const QByteArray& format,
|
---|
92 | const QByteArray& latitude,
|
---|
93 | const QByteArray& longitude,
|
---|
94 | const QByteArray& nmea, int iMount) {
|
---|
95 |
|
---|
96 | setTerminationEnabled(true);
|
---|
97 |
|
---|
98 | _mountPoint = mountPoint;
|
---|
99 | _staID = mountPoint.path().mid(1).toAscii();
|
---|
100 | _format = format;
|
---|
101 | _latitude = latitude;
|
---|
102 | _longitude = longitude;
|
---|
103 | _nmea = nmea;
|
---|
104 | _iMount = iMount; // index in mountpoints array
|
---|
105 |
|
---|
106 | initialize();
|
---|
107 | }
|
---|
108 |
|
---|
109 | // Initialization
|
---|
110 | ////////////////////////////////////////////////////////////////////////////
|
---|
111 | void bncGetThread::initialize() {
|
---|
112 |
|
---|
113 |
|
---|
114 | bncApp* app = (bncApp*) qApp;
|
---|
115 | app->connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
116 | app, SLOT(slotMessage(const QByteArray,bool)));
|
---|
117 |
|
---|
118 | _decoder = 0;
|
---|
119 | _socket = 0;
|
---|
120 | _timeOut = 20*1000; // 20 seconds
|
---|
121 | _nextSleep = 1; // 1 second
|
---|
122 | _rawInpFile = 0;
|
---|
123 | _rawOutFile = 0;
|
---|
124 | _staID_orig = _staID;
|
---|
125 |
|
---|
126 | // Check name conflict
|
---|
127 | // -------------------
|
---|
128 | QSettings settings;
|
---|
129 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
130 | int num = 0;
|
---|
131 | int ind = -1;
|
---|
132 | while (it.hasNext()) {
|
---|
133 | ++ind;
|
---|
134 | QStringList hlp = it.next().split(" ");
|
---|
135 | if (hlp.size() <= 1) continue;
|
---|
136 | QUrl url(hlp[0]);
|
---|
137 | if (_mountPoint.path() == url.path()) {
|
---|
138 | if (_iMount > ind || _iMount < 0) {
|
---|
139 | ++num;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (num > 0) {
|
---|
145 | _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii();
|
---|
146 | }
|
---|
147 |
|
---|
148 | // Notice threshold
|
---|
149 | // ----------------
|
---|
150 | _inspSegm = 50;
|
---|
151 | if ( settings.value("obsRate").toString().isEmpty() ) { _inspSegm = 0; }
|
---|
152 | if ( settings.value("obsRate").toString().indexOf("5 Hz") != -1 ) { _inspSegm = 2; }
|
---|
153 | if ( settings.value("obsRate").toString().indexOf("1 Hz") != -1 ) { _inspSegm = 10; }
|
---|
154 | if ( settings.value("obsRate").toString().indexOf("0.5 Hz") != -1 ) { _inspSegm = 20; }
|
---|
155 | if ( settings.value("obsRate").toString().indexOf("0.2 Hz") != -1 ) { _inspSegm = 40; }
|
---|
156 | if ( settings.value("obsRate").toString().indexOf("0.1 Hz") != -1 ) { _inspSegm = 50; }
|
---|
157 | _adviseFail = settings.value("adviseFail").toInt();
|
---|
158 | _adviseReco = settings.value("adviseReco").toInt();
|
---|
159 | _makePause = false;
|
---|
160 | if ( Qt::CheckState(settings.value("makePause").toInt()) == Qt::Checked) {_makePause = true; }
|
---|
161 | _adviseScript = settings.value("adviseScript").toString();
|
---|
162 | expandEnvVar(_adviseScript);
|
---|
163 |
|
---|
164 | // Latency interval/average
|
---|
165 | // ------------------------
|
---|
166 | _perfIntr = 86400;
|
---|
167 | if ( settings.value("perfIntr").toString().isEmpty() ) { _perfIntr = 0; }
|
---|
168 | if ( settings.value("perfIntr").toString().indexOf("1 min") != -1 ) { _perfIntr = 60; }
|
---|
169 | if ( settings.value("perfIntr").toString().indexOf("5 min") != -1 ) { _perfIntr = 300; }
|
---|
170 | if ( settings.value("perfIntr").toString().indexOf("15 min") != -1 ) { _perfIntr = 900; }
|
---|
171 | if ( settings.value("perfIntr").toString().indexOf("1 hour") != -1 ) { _perfIntr = 3600; }
|
---|
172 | if ( settings.value("perfIntr").toString().indexOf("6 hours") != -1 ) { _perfIntr = 21600; }
|
---|
173 | if ( settings.value("perfIntr").toString().indexOf("1 day") != -1 ) { _perfIntr = 86400; }
|
---|
174 |
|
---|
175 | // RTCM message types
|
---|
176 | // ------------------
|
---|
177 | _checkMountPoint = settings.value("miscMount").toString();
|
---|
178 |
|
---|
179 | // RINEX writer
|
---|
180 | // ------------
|
---|
181 | _samplingRate = settings.value("rnxSampl").toInt();
|
---|
182 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
---|
183 | _rnx = 0;
|
---|
184 | }
|
---|
185 | else {
|
---|
186 | _rnx = new bncRinex(_staID, _mountPoint,
|
---|
187 | _format, _latitude, _longitude, _nmea);
|
---|
188 | }
|
---|
189 | _rnx_set_position = false;
|
---|
190 |
|
---|
191 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
192 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
---|
193 |
|
---|
194 | if (settings.value("serial_staID").toString() == _staID) {
|
---|
195 | _serialPort = new QextSerialPort();
|
---|
196 | _serialPort->open();
|
---|
197 | }
|
---|
198 | else {
|
---|
199 | _serialPort = 0;
|
---|
200 | }
|
---|
201 |
|
---|
202 | // Raw Output
|
---|
203 | // ----------
|
---|
204 | // QByteArray rawOutFileName = "./" + _staID + ".raw";
|
---|
205 | // _rawOutFile = new QFile(rawOutFileName);
|
---|
206 | // _rawOutFile->open(QIODevice::WriteOnly);
|
---|
207 |
|
---|
208 | msleep(100); //sleep 0.1 sec
|
---|
209 | }
|
---|
210 |
|
---|
211 | // Destructor
|
---|
212 | ////////////////////////////////////////////////////////////////////////////
|
---|
213 | bncGetThread::~bncGetThread() {
|
---|
214 | if (_socket) {
|
---|
215 | _socket->close();
|
---|
216 | #if QT_VERSION == 0x040203
|
---|
217 | delete _socket;
|
---|
218 | #else
|
---|
219 | _socket->deleteLater();
|
---|
220 | #endif
|
---|
221 | }
|
---|
222 | delete _decoder;
|
---|
223 | delete _rnx;
|
---|
224 | delete _rawInpFile;
|
---|
225 | delete _rawOutFile;
|
---|
226 | }
|
---|
227 |
|
---|
228 | #define AGENTVERSION "1.7"
|
---|
229 | // Connect to Caster, send the Request (static)
|
---|
230 | ////////////////////////////////////////////////////////////////////////////
|
---|
231 | QTcpSocket* bncGetThread::request(const QUrl& mountPoint,
|
---|
232 | QByteArray& latitude, QByteArray& longitude,
|
---|
233 | QByteArray& nmea, int timeOut,
|
---|
234 | QString& msg) {
|
---|
235 |
|
---|
236 | // Connect the Socket
|
---|
237 | // ------------------
|
---|
238 | QSettings settings;
|
---|
239 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
240 | int proxyPort = settings.value("proxyPort").toInt();
|
---|
241 |
|
---|
242 | QTcpSocket* socket = new QTcpSocket();
|
---|
243 | if ( proxyHost.isEmpty() ) {
|
---|
244 | socket->connectToHost(mountPoint.host(), mountPoint.port());
|
---|
245 | }
|
---|
246 | else {
|
---|
247 | socket->connectToHost(proxyHost, proxyPort);
|
---|
248 | }
|
---|
249 | if (!socket->waitForConnected(timeOut)) {
|
---|
250 | msg += "Connect timeout\n";
|
---|
251 | delete socket;
|
---|
252 | return 0;
|
---|
253 | }
|
---|
254 |
|
---|
255 | // Send Request
|
---|
256 | // ------------
|
---|
257 | QString uName = QUrl::fromPercentEncoding(mountPoint.userName().toAscii());
|
---|
258 | QString passW = QUrl::fromPercentEncoding(mountPoint.password().toAscii());
|
---|
259 | QByteArray userAndPwd;
|
---|
260 |
|
---|
261 | if(!uName.isEmpty() || !passW.isEmpty())
|
---|
262 | {
|
---|
263 | userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
|
---|
264 | passW.toAscii()).toBase64() + "\r\n";
|
---|
265 | }
|
---|
266 |
|
---|
267 | QUrl hlp;
|
---|
268 | hlp.setScheme("http");
|
---|
269 | hlp.setHost(mountPoint.host());
|
---|
270 | hlp.setPort(mountPoint.port());
|
---|
271 | hlp.setPath(mountPoint.path());
|
---|
272 |
|
---|
273 | QByteArray reqStr;
|
---|
274 | if ( proxyHost.isEmpty() ) {
|
---|
275 | if (hlp.path().indexOf("/") != 0) hlp.setPath("/");
|
---|
276 | reqStr = "GET " + hlp.path().toAscii() + " HTTP/1.0\r\n"
|
---|
277 | + "User-Agent: NTRIP BNC/" AGENTVERSION "\r\n"
|
---|
278 | + userAndPwd + "\r\n";
|
---|
279 | } else {
|
---|
280 | reqStr = "GET " + hlp.toEncoded() + " HTTP/1.0\r\n"
|
---|
281 | + "User-Agent: NTRIP BNC/" AGENTVERSION "\r\n"
|
---|
282 | + "Host: " + hlp.host().toAscii() + "\r\n"
|
---|
283 | + userAndPwd + "\r\n";
|
---|
284 | }
|
---|
285 |
|
---|
286 | // NMEA string to handle VRS stream
|
---|
287 | // --------------------------------
|
---|
288 | double lat, lon;
|
---|
289 |
|
---|
290 | lat = strtod(latitude,NULL);
|
---|
291 | lon = strtod(longitude,NULL);
|
---|
292 |
|
---|
293 | if ((nmea == "yes") && (hlp.path().length() > 2) && (hlp.path().indexOf(".skl") < 0)) {
|
---|
294 | const char* flagN="N";
|
---|
295 | const char* flagE="E";
|
---|
296 | if (lon >180.) {lon=(lon-360.)*(-1.); flagE="W";}
|
---|
297 | if ((lon < 0.) && (lon >= -180.)) {lon=lon*(-1.); flagE="W";}
|
---|
298 | if (lon < -180.) {lon=(lon+360.); flagE="E";}
|
---|
299 | if (lat < 0.) {lat=lat*(-1.); flagN="S";}
|
---|
300 | QTime ttime(QDateTime::currentDateTime().toUTC().time());
|
---|
301 | int lat_deg = (int)lat;
|
---|
302 | double lat_min=(lat-lat_deg)*60.;
|
---|
303 | int lon_deg = (int)lon;
|
---|
304 | double lon_min=(lon-lon_deg)*60.;
|
---|
305 | int hh = 0 , mm = 0;
|
---|
306 | double ss = 0.0;
|
---|
307 | hh=ttime.hour();
|
---|
308 | mm=ttime.minute();
|
---|
309 | ss=(double)ttime.second()+0.001*ttime.msec();
|
---|
310 | QString gga;
|
---|
311 | gga += "GPGGA,";
|
---|
312 | gga += QString("%1%2%3,").arg((int)hh, 2, 10, QLatin1Char('0')).arg((int)mm, 2, 10, QLatin1Char('0')).arg((int)ss, 2, 10, QLatin1Char('0'));
|
---|
313 | gga += QString("%1%2,").arg((int)lat_deg,2, 10, QLatin1Char('0')).arg(lat_min, 7, 'f', 4, QLatin1Char('0'));
|
---|
314 | gga += flagN;
|
---|
315 | gga += QString(",%1%2,").arg((int)lon_deg,3, 10, QLatin1Char('0')).arg(lon_min, 7, 'f', 4, QLatin1Char('0'));
|
---|
316 | gga += flagE + QString(",1,05,1.00,+00100,M,10.000,M,,");
|
---|
317 | int xori;
|
---|
318 | char XOR = 0;
|
---|
319 | char *Buff =gga.toAscii().data();
|
---|
320 | int iLen = strlen(Buff);
|
---|
321 | for (xori = 0; xori < iLen; xori++) {
|
---|
322 | XOR ^= (char)Buff[xori];
|
---|
323 | }
|
---|
324 | gga += QString("*%1").arg(XOR, 2, 16, QLatin1Char('0'));
|
---|
325 | reqStr += "$";
|
---|
326 | reqStr += gga;
|
---|
327 | reqStr += "\r\n";
|
---|
328 | }
|
---|
329 |
|
---|
330 | msg += reqStr;
|
---|
331 |
|
---|
332 | socket->write(reqStr, reqStr.length());
|
---|
333 |
|
---|
334 | if (!socket->waitForBytesWritten(timeOut)) {
|
---|
335 | msg += "Write timeout\n";
|
---|
336 | delete socket;
|
---|
337 | return 0;
|
---|
338 | }
|
---|
339 |
|
---|
340 | return socket;
|
---|
341 | }
|
---|
342 |
|
---|
343 | // Init Run
|
---|
344 | ////////////////////////////////////////////////////////////////////////////
|
---|
345 | t_irc bncGetThread::initRun() {
|
---|
346 |
|
---|
347 | if (!_rawInpFile) {
|
---|
348 |
|
---|
349 | // Initialize Socket
|
---|
350 | // -----------------
|
---|
351 | QString msg;
|
---|
352 | _socket = this->request(_mountPoint, _latitude, _longitude,
|
---|
353 | _nmea, _timeOut, msg);
|
---|
354 | if (!_socket) {
|
---|
355 | return failure;
|
---|
356 | }
|
---|
357 |
|
---|
358 | // Read Caster Response
|
---|
359 | // --------------------
|
---|
360 | _socket->waitForReadyRead(_timeOut);
|
---|
361 | if (_socket->canReadLine()) {
|
---|
362 | QString line = _socket->readLine();
|
---|
363 |
|
---|
364 | // Skip messages from proxy server
|
---|
365 | // -------------------------------
|
---|
366 | if (line.indexOf("ICY 200 OK") == -1 &&
|
---|
367 | line.indexOf("200 OK") != -1 ) {
|
---|
368 | bool proxyRespond = true;
|
---|
369 | while (true) {
|
---|
370 | if (_socket->canReadLine()) {
|
---|
371 | line = _socket->readLine();
|
---|
372 | if (!proxyRespond) {
|
---|
373 | break;
|
---|
374 | }
|
---|
375 | if (line.trimmed().isEmpty()) {
|
---|
376 | proxyRespond = false;
|
---|
377 | }
|
---|
378 | }
|
---|
379 | else {
|
---|
380 | _socket->waitForReadyRead(_timeOut);
|
---|
381 | if (_socket->bytesAvailable() <= 0) {
|
---|
382 | break;
|
---|
383 | }
|
---|
384 | }
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | if (line.indexOf("Unauthorized") != -1) {
|
---|
389 | QStringList table;
|
---|
390 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table);
|
---|
391 | QString net;
|
---|
392 | QStringListIterator it(table);
|
---|
393 | while (it.hasNext()) {
|
---|
394 | QString line = it.next();
|
---|
395 | if (line.indexOf("STR") == 0) {
|
---|
396 | QStringList tags = line.split(";");
|
---|
397 | if (tags.at(1) == _staID_orig) {
|
---|
398 | net = tags.at(7);
|
---|
399 | break;
|
---|
400 | }
|
---|
401 | }
|
---|
402 | }
|
---|
403 |
|
---|
404 | QString reg;
|
---|
405 | it.toFront();
|
---|
406 | while (it.hasNext()) {
|
---|
407 | QString line = it.next();
|
---|
408 | if (line.indexOf("NET") == 0) {
|
---|
409 | QStringList tags = line.split(";");
|
---|
410 | if (tags.at(1) == net) {
|
---|
411 | reg = tags.at(7);
|
---|
412 | break;
|
---|
413 | }
|
---|
414 | }
|
---|
415 | }
|
---|
416 | emit(newMessage((_staID + ": Caster Response: " + line +
|
---|
417 | " Adjust User-ID and Password Register, see"
|
---|
418 | "\n " + reg).toAscii(), true));
|
---|
419 | return fatal;
|
---|
420 | }
|
---|
421 | if (line.indexOf("ICY 200 OK") != 0) {
|
---|
422 | emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii(), true));
|
---|
423 | return failure;
|
---|
424 | }
|
---|
425 | }
|
---|
426 | else {
|
---|
427 | emit(newMessage(_staID + ": Response Timeout", true));
|
---|
428 | return failure;
|
---|
429 | }
|
---|
430 | }
|
---|
431 |
|
---|
432 | // Instantiate the filter
|
---|
433 | // ----------------------
|
---|
434 | if (!_decoder) {
|
---|
435 | if (_format.indexOf("RTCM_2") != -1) {
|
---|
436 | emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format", true));
|
---|
437 | _decoder = new RTCM2Decoder(_staID.data());
|
---|
438 | }
|
---|
439 | else if (_format.indexOf("RTCM_3") != -1) {
|
---|
440 | emit(newMessage("Get Data: " + _staID + " in RTCM 3.x format", true));
|
---|
441 | _decoder = new RTCM3Decoder(_staID);
|
---|
442 | connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
|
---|
443 | this, SIGNAL(newMessage(QByteArray,bool)));
|
---|
444 | }
|
---|
445 | else if (_format.indexOf("RTIGS") != -1) {
|
---|
446 | emit(newMessage("Get Data: " + _staID + " in RTIGS format", true));
|
---|
447 | _decoder = new RTIGSDecoder();
|
---|
448 | }
|
---|
449 | else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
|
---|
450 | emit(newMessage("Get Data: " + _staID + " in GPSS format", true));
|
---|
451 | _decoder = new gpssDecoder();
|
---|
452 | }
|
---|
453 | else if (_format.indexOf("ZERO") != -1) {
|
---|
454 | emit(newMessage("Get Data: " + _staID + " in original format", true));
|
---|
455 | _decoder = new bncZeroDecoder(_staID);
|
---|
456 | }
|
---|
457 | else {
|
---|
458 | emit(newMessage(_staID + ": Unknown data format " + _format, true));
|
---|
459 | if (_rawInpFile) {
|
---|
460 | cerr << "Uknown data format" << endl;
|
---|
461 | ::exit(0);
|
---|
462 | }
|
---|
463 | else {
|
---|
464 | return fatal;
|
---|
465 | }
|
---|
466 | }
|
---|
467 | }
|
---|
468 | return success;
|
---|
469 | }
|
---|
470 |
|
---|
471 | // Run
|
---|
472 | ////////////////////////////////////////////////////////////////////////////
|
---|
473 | void bncGetThread::run() {
|
---|
474 |
|
---|
475 | const double maxDt = 600.0; // Check observation epoch
|
---|
476 | bool wrongEpoch = false;
|
---|
477 | bool decode = true;
|
---|
478 | int numSucc = 0;
|
---|
479 | int secSucc = 0;
|
---|
480 | int secFail = 0;
|
---|
481 | int initPause = 30; // Initial pause for corrupted streams
|
---|
482 | int currPause = 0;
|
---|
483 | bool begCorrupt = false;
|
---|
484 | bool endCorrupt = false;
|
---|
485 | bool followSec = false;
|
---|
486 | int oldSecGPS= 0;
|
---|
487 | int newSecGPS = 0;
|
---|
488 | int numGaps = 0;
|
---|
489 | int diffSecGPS = 0;
|
---|
490 | int numLat = 0;
|
---|
491 | double sumLat = 0.;
|
---|
492 | double sumLatQ = 0.;
|
---|
493 | double meanDiff = 0.;
|
---|
494 | double minLat = maxDt;
|
---|
495 | double maxLat = -maxDt;
|
---|
496 | double curLat = 0.;
|
---|
497 |
|
---|
498 | _decodeTime = QDateTime::currentDateTime();
|
---|
499 | _decodeSucc = QDateTime::currentDateTime();
|
---|
500 | t_irc irc = initRun();
|
---|
501 |
|
---|
502 | if (irc == fatal) {
|
---|
503 | QThread::exit(1);
|
---|
504 | return;
|
---|
505 | }
|
---|
506 | else if (irc != success) {
|
---|
507 | emit(newMessage(_staID + ": initRun failed, reconnecting", true));
|
---|
508 | tryReconnect();
|
---|
509 | }
|
---|
510 |
|
---|
511 | if (initPause < _inspSegm) {
|
---|
512 | initPause = _inspSegm;
|
---|
513 | }
|
---|
514 | if(!_makePause) {initPause = 0;}
|
---|
515 | currPause = initPause;
|
---|
516 |
|
---|
517 | // Read Incoming Data
|
---|
518 | // ------------------
|
---|
519 | while (true) {
|
---|
520 | try {
|
---|
521 | if (_socket && _socket->state() != QAbstractSocket::ConnectedState) {
|
---|
522 | emit(newMessage(_staID + ": Socket not connected, reconnecting", true));
|
---|
523 | tryReconnect();
|
---|
524 | }
|
---|
525 |
|
---|
526 | QListIterator<p_obs> it(_decoder->_obsList);
|
---|
527 | while (it.hasNext()) {
|
---|
528 | delete it.next();
|
---|
529 | }
|
---|
530 | _decoder->_obsList.clear();
|
---|
531 |
|
---|
532 | qint64 nBytes = 0;
|
---|
533 |
|
---|
534 | if (_socket) {
|
---|
535 | _socket->waitForReadyRead(_timeOut);
|
---|
536 | nBytes = _socket->bytesAvailable();
|
---|
537 | }
|
---|
538 | else if (_rawInpFile) {
|
---|
539 | const qint64 maxBytes = 1024;
|
---|
540 | nBytes = maxBytes;
|
---|
541 | }
|
---|
542 |
|
---|
543 | if (nBytes > 0) {
|
---|
544 | emit newBytes(_staID, nBytes);
|
---|
545 |
|
---|
546 | char* data = new char[nBytes];
|
---|
547 |
|
---|
548 | if (_socket) {
|
---|
549 | _socket->read(data, nBytes);
|
---|
550 | }
|
---|
551 | else if (_rawInpFile) {
|
---|
552 | nBytes = _rawInpFile->read(data, nBytes);
|
---|
553 | if (nBytes <= 0) {
|
---|
554 | cout << "no more data" << endl;
|
---|
555 | ::exit(0);
|
---|
556 | }
|
---|
557 | }
|
---|
558 |
|
---|
559 | if (_rawOutFile) {
|
---|
560 | _rawOutFile->write(data, nBytes);
|
---|
561 | _rawOutFile->flush();
|
---|
562 | }
|
---|
563 |
|
---|
564 | if (_serialPort) {
|
---|
565 | _serialPort->write(data, nBytes);
|
---|
566 | _serialPort->flush();
|
---|
567 | }
|
---|
568 |
|
---|
569 | if (_inspSegm<1) {
|
---|
570 | vector<string> errmsg;
|
---|
571 | _decoder->Decode(data, nBytes, errmsg);
|
---|
572 | #ifdef DEBUG_RTCM2_2021
|
---|
573 | for (unsigned ii = 0; ii < errmsg.size(); ii++) {
|
---|
574 | emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
|
---|
575 | }
|
---|
576 | #endif
|
---|
577 | }
|
---|
578 | else {
|
---|
579 |
|
---|
580 | // Decode data
|
---|
581 | // -----------
|
---|
582 | if (!_decodePause.isValid() ||
|
---|
583 | _decodePause.secsTo(QDateTime::currentDateTime()) >= currPause ) {
|
---|
584 |
|
---|
585 | if (decode) {
|
---|
586 | vector<string> errmsg;
|
---|
587 | if ( _decoder->Decode(data, nBytes, errmsg) == success ) {
|
---|
588 | numSucc += 1;
|
---|
589 | }
|
---|
590 | if ( _decodeTime.secsTo(QDateTime::currentDateTime()) > _inspSegm ) {
|
---|
591 | decode = false;
|
---|
592 | }
|
---|
593 | #ifdef DEBUG_RTCM2_2021
|
---|
594 | for (unsigned ii = 0; ii < errmsg.size(); ii++) {
|
---|
595 | emit newMessage(_staID + ": " + errmsg[ii].c_str(), false);
|
---|
596 | }
|
---|
597 | #endif
|
---|
598 | }
|
---|
599 |
|
---|
600 | // Check - once per inspect segment
|
---|
601 | // --------------------------------
|
---|
602 | if (!decode) {
|
---|
603 | _decodeTime = QDateTime::currentDateTime();
|
---|
604 | if (numSucc>0) {
|
---|
605 | secSucc += _inspSegm;
|
---|
606 | _decodeSucc = QDateTime::currentDateTime();
|
---|
607 | if (secSucc > _adviseReco * 60) {
|
---|
608 | secSucc = _adviseReco * 60 + 1;
|
---|
609 | }
|
---|
610 | numSucc = 0;
|
---|
611 | currPause = initPause;
|
---|
612 | _decodePause.setDate(QDate());
|
---|
613 | _decodePause.setTime(QTime());
|
---|
614 | }
|
---|
615 | else {
|
---|
616 | secFail += _inspSegm;
|
---|
617 | secSucc = 0;
|
---|
618 | if (secFail > _adviseFail * 60) {
|
---|
619 | secFail = _adviseFail * 60 + 1;
|
---|
620 | }
|
---|
621 | if (!_decodePause.isValid() || !_makePause) {
|
---|
622 | _decodePause = QDateTime::currentDateTime();
|
---|
623 | }
|
---|
624 | else {
|
---|
625 | _decodePause.setDate(QDate());
|
---|
626 | _decodePause.setTime(QTime());
|
---|
627 | secFail = secFail + currPause - _inspSegm;
|
---|
628 | currPause = currPause * 2;
|
---|
629 | if (currPause > 960) {
|
---|
630 | currPause = 960;
|
---|
631 | }
|
---|
632 | }
|
---|
633 | }
|
---|
634 |
|
---|
635 | // End corrupt threshold
|
---|
636 | // ---------------------
|
---|
637 | if ( begCorrupt && !endCorrupt && secSucc > _adviseReco * 60 ) {
|
---|
638 | _endDateCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
|
---|
639 | _endTimeCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
|
---|
640 | emit(newMessage((_staID + ": Recovery threshold exceeded, corruption ended "
|
---|
641 | + _endDateCor + " " + _endTimeCor).toAscii(), true));
|
---|
642 | callScript(("End_Corrupted " + _endDateCor + " " + _endTimeCor + " Begin was " + _begDateCor + " " + _begTimeCor).toAscii());
|
---|
643 | endCorrupt = true;
|
---|
644 | begCorrupt = false;
|
---|
645 | secFail = 0;
|
---|
646 | }
|
---|
647 | else {
|
---|
648 |
|
---|
649 | // Begin corrupt threshold
|
---|
650 | // -----------------------
|
---|
651 | if ( !begCorrupt && secFail > _adviseFail * 60 ) {
|
---|
652 | _begDateCor = _decodeSucc.toUTC().date().toString("yy-MM-dd");
|
---|
653 | _begTimeCor = _decodeSucc.toUTC().time().toString("hh:mm:ss");
|
---|
654 | emit(newMessage((_staID + ": Failure threshold exceeded, corrupted since "
|
---|
655 | + _begDateCor + " " + _begTimeCor).toAscii(), true));
|
---|
656 | callScript(("Begin_Corrupted " + _begDateCor + " " + _begTimeCor).toAscii());
|
---|
657 | begCorrupt = true;
|
---|
658 | endCorrupt = false;
|
---|
659 | secSucc = 0;
|
---|
660 | numSucc = 0;
|
---|
661 | }
|
---|
662 | }
|
---|
663 | decode = true;
|
---|
664 | }
|
---|
665 | }
|
---|
666 | }
|
---|
667 |
|
---|
668 | // End outage threshold
|
---|
669 | // --------------------
|
---|
670 | if ( _decodeStart.isValid() && _decodeStart.secsTo(QDateTime::currentDateTime()) > _adviseReco * 60 ) {
|
---|
671 | _decodeStart.setDate(QDate());
|
---|
672 | _decodeStart.setTime(QTime());
|
---|
673 | if (_inspSegm>0) {
|
---|
674 | _endDateOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
|
---|
675 | _endTimeOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
|
---|
676 | emit(newMessage((_staID + ": Recovery threshold exceeded, outage ended "
|
---|
677 | + _endDateOut + " " + _endTimeOut).toAscii(), true));
|
---|
678 | callScript(("End_Outage " + _endDateOut + " " + _endTimeOut + " Begin was " + _begDateOut + " " + _begTimeOut).toAscii());
|
---|
679 | }
|
---|
680 | }
|
---|
681 |
|
---|
682 | delete [] data;
|
---|
683 |
|
---|
684 |
|
---|
685 | // RTCM scan output
|
---|
686 | // ----------------
|
---|
687 | if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
|
---|
688 | QSettings settings;
|
---|
689 | if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked) {
|
---|
690 |
|
---|
691 | // RTCMv3 message types
|
---|
692 | // --------------------
|
---|
693 | if (0<_decoder->_typeList.size()) {
|
---|
694 | QString type;
|
---|
695 | for (int ii=0;ii<_decoder->_typeList.size();ii++) {
|
---|
696 | type = QString("%1 ").arg(_decoder->_typeList[ii]);
|
---|
697 | emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
|
---|
698 | }
|
---|
699 | }
|
---|
700 |
|
---|
701 | // RTCMv3 antenna descriptor
|
---|
702 | // -------------------------
|
---|
703 | if (0<_decoder->_antType.size()) {
|
---|
704 | QString ant1;
|
---|
705 | for (int ii=0;ii<_decoder->_antType.size();ii++) {
|
---|
706 | ant1 = QString("%1 ").arg(_decoder->_antType[ii]);
|
---|
707 | emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
|
---|
708 | }
|
---|
709 | }
|
---|
710 |
|
---|
711 | // Antenna XYZ
|
---|
712 | // ------------------
|
---|
713 | if (0<_decoder->_antList.size()) {
|
---|
714 | for (int ii=0;ii<_decoder->_antList.size();++ii) {
|
---|
715 | QByteArray ant1,ant2,ant3, antT;
|
---|
716 | ant1 = QString("%1 ").arg(_decoder->_antList[ii].xx,0,'f',4).toAscii();
|
---|
717 | ant2 = QString("%1 ").arg(_decoder->_antList[ii].yy,0,'f',4).toAscii();
|
---|
718 | ant3 = QString("%1 ").arg(_decoder->_antList[ii].zz,0,'f',4).toAscii();
|
---|
719 | switch (_decoder->_antList[ii].type) {
|
---|
720 | case GPSDecoder::t_antInfo::ARP: antT = "ARP"; break;
|
---|
721 | case GPSDecoder::t_antInfo::APC: antT = "APC"; break;
|
---|
722 | }
|
---|
723 | emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
|
---|
724 | emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
|
---|
725 | emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
|
---|
726 | if (_decoder->_antList[ii].height_f) {
|
---|
727 | QByteArray ant4 = QString("%1 ").arg(_decoder->_antList[ii].height,0,'f',4).toAscii();
|
---|
728 | emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true));
|
---|
729 | }
|
---|
730 | emit(newAntCrd(_staID,
|
---|
731 | _decoder->_antList[ii].xx, _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
|
---|
732 | antT));
|
---|
733 | }
|
---|
734 | }
|
---|
735 | }
|
---|
736 | if ( _checkMountPoint == "ANTCRD_ONLY" && _decoder->_antList.size() ) {
|
---|
737 | for (int ii=0;ii<_decoder->_antList.size();++ii) {
|
---|
738 | QByteArray antT;
|
---|
739 | switch (_decoder->_antList[ii].type) {
|
---|
740 | case GPSDecoder::t_antInfo::ARP: antT = "ARP"; break;
|
---|
741 | case GPSDecoder::t_antInfo::APC: antT = "APC"; break;
|
---|
742 | }
|
---|
743 | emit(newAntCrd(_staID,
|
---|
744 | _decoder->_antList[ii].xx, _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,
|
---|
745 | antT));
|
---|
746 | }
|
---|
747 | }
|
---|
748 | }
|
---|
749 |
|
---|
750 | _decoder->_typeList.clear();
|
---|
751 | _decoder->_antType.clear();
|
---|
752 | _decoder->_antList.clear();
|
---|
753 |
|
---|
754 | // Loop over all observations (observations output)
|
---|
755 | // ------------------------------------------------
|
---|
756 | QListIterator<p_obs> it(_decoder->_obsList);
|
---|
757 | while (it.hasNext()) {
|
---|
758 | p_obs obs = it.next();
|
---|
759 |
|
---|
760 | // Check observation epoch
|
---|
761 | // -----------------------
|
---|
762 | if (!_rawInpFile && !dynamic_cast<gpssDecoder*>(_decoder)) {
|
---|
763 | int week;
|
---|
764 | double sec;
|
---|
765 | currentGPSWeeks(week, sec);
|
---|
766 | const double secPerWeek = 7.0 * 24.0 * 3600.0;
|
---|
767 |
|
---|
768 | if (week < obs->_o.GPSWeek) {
|
---|
769 | week += 1;
|
---|
770 | sec -= secPerWeek;
|
---|
771 | }
|
---|
772 | if (week > obs->_o.GPSWeek) {
|
---|
773 | week -= 1;
|
---|
774 | sec += secPerWeek;
|
---|
775 | }
|
---|
776 | double dt = fabs(sec - obs->_o.GPSWeeks);
|
---|
777 | if (week != obs->_o.GPSWeek || dt > maxDt) {
|
---|
778 | if (!wrongEpoch) {
|
---|
779 | emit( newMessage(_staID + ": Wrong observation epoch(s)", true) );
|
---|
780 | wrongEpoch = true;
|
---|
781 | }
|
---|
782 | delete obs;
|
---|
783 | continue;
|
---|
784 | }
|
---|
785 | else {
|
---|
786 | wrongEpoch = false;
|
---|
787 |
|
---|
788 | // Latency and completeness
|
---|
789 | // ------------------------
|
---|
790 | if (_perfIntr>0) {
|
---|
791 | if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
|
---|
792 | newSecGPS = static_cast<int>(obs->_o.GPSWeeks);
|
---|
793 | if (newSecGPS != oldSecGPS) {
|
---|
794 | if (newSecGPS % _perfIntr < oldSecGPS % _perfIntr) {
|
---|
795 | if (numLat>0) {
|
---|
796 | if (meanDiff>0.) {
|
---|
797 | emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs, %7 gaps")
|
---|
798 | .arg(_staID.data())
|
---|
799 | .arg(int(sumLat/numLat*100)/100.)
|
---|
800 | .arg(int(minLat*100)/100.)
|
---|
801 | .arg(int(maxLat*100)/100.)
|
---|
802 | .arg(int((sqrt((sumLatQ - sumLat * sumLat / numLat)/numLat))*100)/100.)
|
---|
803 | .arg(numLat)
|
---|
804 | .arg(numGaps)
|
---|
805 | .toAscii(), true) );
|
---|
806 | } else {
|
---|
807 | emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs")
|
---|
808 | .arg(_staID.data())
|
---|
809 | .arg(int(sumLat/numLat*100)/100.)
|
---|
810 | .arg(int(minLat*100)/100.)
|
---|
811 | .arg(int(maxLat*100)/100.)
|
---|
812 | .arg(int((sqrt((sumLatQ - sumLat * sumLat / numLat)/numLat))*100)/100.)
|
---|
813 | .arg(numLat)
|
---|
814 | .toAscii(), true) );
|
---|
815 | }
|
---|
816 | }
|
---|
817 | meanDiff = diffSecGPS/numLat;
|
---|
818 | diffSecGPS = 0;
|
---|
819 | numGaps = 0;
|
---|
820 | sumLat = 0.;
|
---|
821 | sumLatQ = 0.;
|
---|
822 | numLat = 0;
|
---|
823 | minLat = maxDt;
|
---|
824 | maxLat = -maxDt;
|
---|
825 | }
|
---|
826 | if (followSec) {
|
---|
827 | diffSecGPS += newSecGPS - oldSecGPS;
|
---|
828 | if (meanDiff>0.) {
|
---|
829 | if (newSecGPS - oldSecGPS > 1.5 * meanDiff) {
|
---|
830 | numGaps += 1;
|
---|
831 | }
|
---|
832 | }
|
---|
833 | }
|
---|
834 | curLat = sec - obs->_o.GPSWeeks;
|
---|
835 | sumLat += curLat;
|
---|
836 | sumLatQ += curLat * curLat;
|
---|
837 | if (curLat < minLat) minLat = curLat;
|
---|
838 | if (curLat >= maxLat) maxLat = curLat;
|
---|
839 | numLat += 1;
|
---|
840 | oldSecGPS = newSecGPS;
|
---|
841 | followSec = true;
|
---|
842 | }
|
---|
843 | }
|
---|
844 | }
|
---|
845 | }
|
---|
846 | }
|
---|
847 |
|
---|
848 | // RINEX Output
|
---|
849 | // ------------
|
---|
850 | if (_rnx) {
|
---|
851 | bool dump = true;
|
---|
852 |
|
---|
853 | //// // RTCMv2 XYZ
|
---|
854 | //// // ----------
|
---|
855 | //// RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
|
---|
856 | //// if ( decoder2 && !_rnx_set_position ) {
|
---|
857 | //// double stax, stay, staz;
|
---|
858 | //// double dL1[3], dL2[3];
|
---|
859 | //// if ( decoder2->getStaCrd(stax, stay, staz,
|
---|
860 | //// dL1[0], dL1[1], dL1[2],
|
---|
861 | //// dL2[0], dL2[1], dL2[2]) == success ) {
|
---|
862 | ////
|
---|
863 | //// if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
|
---|
864 | //// QString ant1;
|
---|
865 | //// ant1 = QString("%1 ").arg(stax,0,'f',4);
|
---|
866 | //// emit(newMessage(_staID + ": ARP X " + ant1.toAscii() + "m" ));
|
---|
867 | //// ant1 = QString("%1 ").arg(stay,0,'f',4);
|
---|
868 | //// emit(newMessage(_staID + ": ARP Y " + ant1.toAscii() + "m" ));
|
---|
869 | //// ant1 = QString("%1 ").arg(staz,0,'f',4);
|
---|
870 | //// emit(newMessage(_staID + ": ARP Z " + ant1.toAscii() + "m" ));
|
---|
871 | //// ant1 = QString("%1 ").arg(dL1[0],0,'f',4);
|
---|
872 | //// emit(newMessage(_staID + ": L1 APC DX " + ant1.toAscii() + "m" ));
|
---|
873 | //// ant1 = QString("%1 ").arg(dL1[1],0,'f',4);
|
---|
874 | //// emit(newMessage(_staID + ": L1 APC DY " + ant1.toAscii() + "m" ));
|
---|
875 | //// ant1 = QString("%1 ").arg(dL1[2],0,'f',4);
|
---|
876 | //// emit(newMessage(_staID + ": L1 APC DZ " + ant1.toAscii() + "m" ));
|
---|
877 | //// ant1 = QString("%1 ").arg(dL2[0],0,'f',4);
|
---|
878 | //// emit(newMessage(_staID + ": L2 APC DX " + ant1.toAscii() + "m" ));
|
---|
879 | //// ant1 = QString("%1 ").arg(dL2[1],0,'f',4);
|
---|
880 | //// emit(newMessage(_staID + ": L2 APC DY " + ant1.toAscii() + "m" ));
|
---|
881 | //// ant1 = QString("%1 ").arg(dL2[2],0,'f',4);
|
---|
882 | //// emit(newMessage(_staID + ": L2 APC DZ " + ant1.toAscii() + "m" ));
|
---|
883 | //// }
|
---|
884 | //// _rnx_set_position = true;
|
---|
885 | //// }
|
---|
886 | //// }
|
---|
887 |
|
---|
888 | if ( dump ) {
|
---|
889 | long iSec = long(floor(obs->_o.GPSWeeks+0.5));
|
---|
890 | long newTime = obs->_o.GPSWeek * 7*24*3600 + iSec;
|
---|
891 | if (_samplingRate == 0 || iSec % _samplingRate == 0) {
|
---|
892 | _rnx->deepCopy(obs);
|
---|
893 | }
|
---|
894 | _rnx->dumpEpoch(newTime);
|
---|
895 | }
|
---|
896 | }
|
---|
897 |
|
---|
898 | // Emit new observation signal
|
---|
899 | // ---------------------------
|
---|
900 | bool firstObs = (obs == _decoder->_obsList.first());
|
---|
901 | obs->_status = t_obs::posted;
|
---|
902 | emit newObs(_staID, firstObs, obs);
|
---|
903 | }
|
---|
904 | _decoder->_obsList.clear();
|
---|
905 |
|
---|
906 | }
|
---|
907 |
|
---|
908 | // Timeout, reconnect
|
---|
909 | // ------------------
|
---|
910 | else {
|
---|
911 | emit(newMessage(_staID + ": Data Timeout, reconnecting", true));
|
---|
912 | tryReconnect();
|
---|
913 | }
|
---|
914 | }
|
---|
915 | catch (const char* msg) {
|
---|
916 | emit(newMessage(_staID + msg, true));
|
---|
917 | tryReconnect();
|
---|
918 | }
|
---|
919 | }
|
---|
920 | }
|
---|
921 |
|
---|
922 | // Exit
|
---|
923 | ////////////////////////////////////////////////////////////////////////////
|
---|
924 | void bncGetThread::exit(int exitCode) {
|
---|
925 | if (exitCode!= 0) {
|
---|
926 | emit error(_staID);
|
---|
927 | }
|
---|
928 | QThread::exit(exitCode);
|
---|
929 | terminate();
|
---|
930 | }
|
---|
931 |
|
---|
932 | // Try Re-Connect
|
---|
933 | ////////////////////////////////////////////////////////////////////////////
|
---|
934 | void bncGetThread::tryReconnect() {
|
---|
935 | if (_rnx) {
|
---|
936 | _rnx->setReconnectFlag(true);
|
---|
937 | }
|
---|
938 | if ( !_decodeStart.isValid()) {
|
---|
939 | _decodeStop = QDateTime::currentDateTime();
|
---|
940 | }
|
---|
941 | while (1) {
|
---|
942 | delete _socket; _socket = 0;
|
---|
943 | sleep(_nextSleep);
|
---|
944 | if ( initRun() == success ) {
|
---|
945 | if ( !_decodeStop.isValid()) {
|
---|
946 | _decodeStart = QDateTime::currentDateTime();
|
---|
947 | }
|
---|
948 | break;
|
---|
949 | }
|
---|
950 | else {
|
---|
951 |
|
---|
952 | // Begin outage threshold
|
---|
953 | // ----------------------
|
---|
954 | if ( _decodeStop.isValid() && _decodeStop.secsTo(QDateTime::currentDateTime()) > _adviseFail * 60 ) {
|
---|
955 | _decodeStop.setDate(QDate());
|
---|
956 | _decodeStop.setTime(QTime());
|
---|
957 | if (_inspSegm>0) {
|
---|
958 | _begDateOut = _decodeTime.toUTC().date().toString("yy-MM-dd");
|
---|
959 | _begTimeOut = _decodeTime.toUTC().time().toString("hh:mm:ss");
|
---|
960 | emit(newMessage((_staID + ": Failure threshold exceeded, outage since "
|
---|
961 | + _begDateOut + " " + _begTimeOut).toAscii(), true));
|
---|
962 | callScript(("Begin_Outage " + _begDateOut + " " + _begTimeOut).toAscii());
|
---|
963 | }
|
---|
964 | }
|
---|
965 | _nextSleep *= 2;
|
---|
966 | if (_nextSleep > 256) {
|
---|
967 | _nextSleep = 256;
|
---|
968 | }
|
---|
969 | _nextSleep += rand() % 6;
|
---|
970 | }
|
---|
971 | }
|
---|
972 | _nextSleep = 1;
|
---|
973 | }
|
---|
974 |
|
---|
975 | // Call advisory notice script
|
---|
976 | ////////////////////////////////////////////////////////////////////////////
|
---|
977 | void bncGetThread::callScript(const char* _comment) {
|
---|
978 | QMutexLocker locker(&_mutex);
|
---|
979 | if (!_adviseScript.isEmpty()) {
|
---|
980 | msleep(1);
|
---|
981 | #ifdef WIN32
|
---|
982 | QProcess::startDetached(_adviseScript, QStringList() << _staID << _comment) ;
|
---|
983 | #else
|
---|
984 | QProcess::startDetached("nohup", QStringList() << _adviseScript << _staID << _comment) ;
|
---|
985 | #endif
|
---|
986 | }
|
---|
987 | }
|
---|
988 |
|
---|
989 | //
|
---|
990 | //////////////////////////////////////////////////////////////////////////////
|
---|
991 | void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
992 | RTCM2Decoder* decoder = dynamic_cast<RTCM2Decoder*>(_decoder);
|
---|
993 |
|
---|
994 | if ( decoder ) {
|
---|
995 | QMutexLocker locker(&_mutex);
|
---|
996 |
|
---|
997 | string storedPRN;
|
---|
998 | vector<int> IODs;
|
---|
999 |
|
---|
1000 | if ( decoder->storeEph(gpseph, storedPRN, IODs) ) {
|
---|
1001 | #ifdef DEBUG_RTCM2_2021
|
---|
1002 | QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
|
---|
1003 |
|
---|
1004 | for (unsigned ii = 0; ii < IODs.size(); ii++) {
|
---|
1005 | msg += QString(" %1").arg(IODs[ii],4);
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | emit(newMessage(msg.toAscii(), false));
|
---|
1009 | #endif
|
---|
1010 | }
|
---|
1011 | }
|
---|
1012 | }
|
---|
1013 |
|
---|