source: ntrip/trunk/BNC/bncgetthread.cpp@ 723

Last change on this file since 723 was 723, checked in by weber, 16 years ago

* empty log message *

File size: 22.4 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: 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
43#include <QFile>
44#include <QTextStream>
45#include <QtNetwork>
46#include <QTime>
47
48#include "bncgetthread.h"
49#include "bnctabledlg.h"
50#include "bncapp.h"
51#include "bncutils.h"
52#include "bncrinex.h"
53#include "bnczerodecoder.h"
54
55#include "RTCM/RTCM2Decoder.h"
56#include "RTCM3/RTCM3Decoder.h"
57#include "RTIGS/RTIGSDecoder.h"
58
59using namespace std;
60
61// Constructor
62////////////////////////////////////////////////////////////////////////////
63bncGetThread::bncGetThread(const QUrl& mountPoint,
64 const QByteArray& format,
65 const QByteArray& latitude,
66 const QByteArray& longitude,
67 const QByteArray& nmea, int iMount) {
68
69 setTerminationEnabled(true);
70
71 _decoder = 0;
72 _mountPoint = mountPoint;
73 _staID = mountPoint.path().mid(1).toAscii();
74 _staID_orig = _staID;
75 _format = format;
76 _latitude = latitude;
77 _longitude = longitude;
78 _nmea = nmea;
79 _socket = 0;
80 _timeOut = 20*1000; // 20 seconds
81 _nextSleep = 1; // 1 second
82 _iMount = iMount; // index in mountpoints array
83
84 // Check name conflict
85 // -------------------
86 QSettings settings;
87 QListIterator<QString> it(settings.value("mountPoints").toStringList());
88 int num = 0;
89 int ind = -1;
90 while (it.hasNext()) {
91 ++ind;
92 QStringList hlp = it.next().split(" ");
93 if (hlp.size() <= 1) continue;
94 QUrl url(hlp[0]);
95 if (_mountPoint.path() == url.path()) {
96 if (_iMount > ind) {
97 ++num;
98 }
99 }
100 }
101
102 if (num > 0) {
103 _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii();
104 }
105
106 // Notice threshold
107 // ----------------
108 _inspSegm = 50;
109 if ( settings.value("obsRate").toString().isEmpty() ) { _inspSegm = 0; }
110 if ( settings.value("obsRate").toString().indexOf("5 Hz") != -1 ) { _inspSegm = 2; }
111 if ( settings.value("obsRate").toString().indexOf("1 Hz") != -1 ) { _inspSegm = 10; }
112 if ( settings.value("obsRate").toString().indexOf("0.5 Hz") != -1 ) { _inspSegm = 20; }
113 if ( settings.value("obsRate").toString().indexOf("0.2 Hz") != -1 ) { _inspSegm = 40; }
114 if ( settings.value("obsRate").toString().indexOf("0.1 Hz") != -1 ) { _inspSegm = 50; }
115 _adviseFail = settings.value("adviseFail").toInt();
116 _adviseReco = settings.value("adviseReco").toInt();
117 _makePause = false;
118 if ( Qt::CheckState(settings.value("makePause").toInt()) == Qt::Checked) {_makePause = true; }
119 _adviseScript = settings.value("adviseScript").toString();
120 expandEnvVar(_adviseScript);
121
122 // Latency interval/average
123 // ------------------------
124 _latIntr = 86400;
125 if ( settings.value("latIntr").toString().isEmpty() ) { _latIntr = 0; }
126 if ( settings.value("latIntr").toString().indexOf("1 min") != -1 ) { _latIntr = 60; }
127 if ( settings.value("latIntr").toString().indexOf("5 min") != -1 ) { _latIntr = 300; }
128 if ( settings.value("latIntr").toString().indexOf("15 min") != -1 ) { _latIntr = 900; }
129 if ( settings.value("latIntr").toString().indexOf("1 hour") != -1 ) { _latIntr = 3600; }
130 if ( settings.value("latIntr").toString().indexOf("6 hours") != -1 ) { _latIntr = 21600; }
131 if ( settings.value("latIntr").toString().indexOf("1 day") != -1 ) { _latIntr = 86400; }
132
133 // RINEX writer
134 // ------------
135 _samplingRate = settings.value("rnxSampl").toInt();
136 if ( settings.value("rnxPath").toString().isEmpty() ) {
137 _rnx = 0;
138 }
139 else {
140 _rnx = new bncRinex(_staID, mountPoint, format, latitude, longitude, nmea);
141 }
142
143 msleep(100); //sleep 0.1 sec
144}
145
146// Destructor
147////////////////////////////////////////////////////////////////////////////
148bncGetThread::~bncGetThread() {
149 if (_socket) {
150 _socket->close();
151#if QT_VERSION == 0x040203
152 delete _socket;
153#else
154 _socket->deleteLater();
155#endif
156 }
157 delete _decoder;
158 delete _rnx;
159}
160
161#define AGENTVERSION "1.5"
162// Connect to Caster, send the Request (static)
163////////////////////////////////////////////////////////////////////////////
164QTcpSocket* bncGetThread::request(const QUrl& mountPoint,
165 QByteArray& latitude, QByteArray& longitude,
166 QByteArray& nmea, int timeOut,
167 QString& msg) {
168
169 // Connect the Socket
170 // ------------------
171 QSettings settings;
172 QString proxyHost = settings.value("proxyHost").toString();
173 int proxyPort = settings.value("proxyPort").toInt();
174
175 QTcpSocket* socket = new QTcpSocket();
176 if ( proxyHost.isEmpty() ) {
177 socket->connectToHost(mountPoint.host(), mountPoint.port());
178 }
179 else {
180 socket->connectToHost(proxyHost, proxyPort);
181 }
182 if (!socket->waitForConnected(timeOut)) {
183 msg += "Connect timeout\n";
184 delete socket;
185 return 0;
186 }
187
188 // Send Request
189 // ------------
190 QString uName = QUrl::fromPercentEncoding(mountPoint.userName().toAscii());
191 QString passW = QUrl::fromPercentEncoding(mountPoint.password().toAscii());
192 QByteArray userAndPwd;
193
194 if(!uName.isEmpty() || !passW.isEmpty())
195 {
196 userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
197 passW.toAscii()).toBase64() + "\r\n";
198 }
199
200 QUrl hlp;
201 hlp.setScheme("http");
202 hlp.setHost(mountPoint.host());
203 hlp.setPort(mountPoint.port());
204 hlp.setPath(mountPoint.path());
205
206 QByteArray reqStr;
207 if ( proxyHost.isEmpty() ) {
208 if (hlp.path().indexOf("/") != 0) hlp.setPath("/");
209 reqStr = "GET " + hlp.path().toAscii() + " HTTP/1.0\r\n";
210 } else {
211 reqStr = "GET " + hlp.toEncoded() + " HTTP/1.0\r\n";
212 }
213 reqStr += "User-Agent: NTRIP BNC/" AGENTVERSION "\r\n"
214 "Host: " + hlp.host().toAscii() + "\r\n"
215 + userAndPwd + "\r\n";
216
217// NMEA string to handle VRS stream
218// --------------------------------
219
220 double lat, lon;
221
222 lat = strtod(latitude,NULL);
223 lon = strtod(longitude,NULL);
224
225 if ((nmea == "yes") && (hlp.path().length() > 2) && (hlp.path().indexOf(".skl") < 0)) {
226 const char* flagN="N";
227 const char* flagE="E";
228 if (lon >180.) {lon=(lon-360.)*(-1.); flagE="W";}
229 if ((lon < 0.) && (lon >= -180.)) {lon=lon*(-1.); flagE="W";}
230 if (lon < -180.) {lon=(lon+360.); flagE="E";}
231 if (lat < 0.) {lat=lat*(-1.); flagN="S";}
232 QTime ttime(QDateTime::currentDateTime().toUTC().time());
233 int lat_deg = (int)lat;
234 double lat_min=(lat-lat_deg)*60.;
235 int lon_deg = (int)lon;
236 double lon_min=(lon-lon_deg)*60.;
237 int hh = 0 , mm = 0;
238 double ss = 0.0;
239 hh=ttime.hour();
240 mm=ttime.minute();
241 ss=(double)ttime.second()+0.001*ttime.msec();
242 QString gga;
243 gga += "GPGGA,";
244 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'));
245 gga += QString("%1%2,").arg((int)lat_deg,2, 10, QLatin1Char('0')).arg(lat_min, 7, 'f', 4, QLatin1Char('0'));
246 gga += flagN;
247 gga += QString(",%1%2,").arg((int)lon_deg,3, 10, QLatin1Char('0')).arg(lon_min, 7, 'f', 4, QLatin1Char('0'));
248 gga += flagE + QString(",1,05,1.00,+00100,M,10.000,M,,");
249 int xori;
250 char XOR = 0;
251 char *Buff =gga.toAscii().data();
252 int iLen = strlen(Buff);
253 for (xori = 0; xori < iLen; xori++) {
254 XOR ^= (char)Buff[xori];
255 }
256 gga += QString("*%1").arg(XOR, 2, 16, QLatin1Char('0'));
257 reqStr += "$";
258 reqStr += gga;
259 reqStr += "\r\n";
260 }
261
262 msg += reqStr;
263
264 socket->write(reqStr, reqStr.length());
265
266 if (!socket->waitForBytesWritten(timeOut)) {
267 msg += "Write timeout\n";
268 delete socket;
269 return 0;
270 }
271
272 return socket;
273}
274
275// Init Run
276////////////////////////////////////////////////////////////////////////////
277t_irc bncGetThread::initRun() {
278
279 // Initialize Socket
280 // -----------------
281 QString msg;
282 _socket = this->request(_mountPoint, _latitude, _longitude,
283 _nmea, _timeOut, msg);
284 if (!_socket) {
285 return failure;
286 }
287
288 // Read Caster Response
289 // --------------------
290 _socket->waitForReadyRead(_timeOut);
291 if (_socket->canReadLine()) {
292 QString line = _socket->readLine();
293
294 // Skip messages from proxy server
295 // -------------------------------
296 if (line.indexOf("ICY 200 OK") == -1 &&
297 line.indexOf("200 OK") != -1 ) {
298 bool proxyRespond = true;
299 while (true) {
300 if (_socket->canReadLine()) {
301 line = _socket->readLine();
302 if (!proxyRespond) {
303 break;
304 }
305 if (line.trimmed().isEmpty()) {
306 proxyRespond = false;
307 }
308 }
309 else {
310 _socket->waitForReadyRead(_timeOut);
311 if (_socket->bytesAvailable() <= 0) {
312 break;
313 }
314 }
315 }
316 }
317
318 if (line.indexOf("Unauthorized") != -1) {
319 QStringList table;
320 bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table);
321 QString net;
322 QStringListIterator it(table);
323 while (it.hasNext()) {
324 QString line = it.next();
325 if (line.indexOf("STR") == 0) {
326 QStringList tags = line.split(";");
327 if (tags.at(1) == _staID_orig) {
328 net = tags.at(7);
329 break;
330 }
331 }
332 }
333
334 QString reg;
335 it.toFront();
336 while (it.hasNext()) {
337 QString line = it.next();
338 if (line.indexOf("NET") == 0) {
339 QStringList tags = line.split(";");
340 if (tags.at(1) == net) {
341 reg = tags.at(7);
342 break;
343 }
344 }
345 }
346 emit(newMessage((_staID + ": Caster Response: " + line +
347 " Adjust User-ID and Password Register, see"
348 "\n " + reg).toAscii()));
349 return fatal;
350 }
351 if (line.indexOf("ICY 200 OK") != 0) {
352 emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii()));
353 return failure;
354 }
355 }
356 else {
357 emit(newMessage(_staID + ": Response Timeout"));
358 return failure;
359 }
360
361 // Instantiate the filter
362 // ----------------------
363 if (!_decoder) {
364 if (_format.indexOf("RTCM_2") != -1) {
365 emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format"));
366 _decoder = new RTCM2Decoder();
367 }
368 else if (_format.indexOf("RTCM_3") != -1) {
369 emit(newMessage("Get Data: " + _staID + " in RTCM 3.x format"));
370 _decoder = new RTCM3Decoder();
371 }
372 else if (_format.indexOf("RTIGS") != -1) {
373 emit(newMessage("Get Data: " + _staID + " in RTIGS format"));
374 _decoder = new RTIGSDecoder();
375 }
376 else if (_format.indexOf("SP3") != -1 || _format.indexOf("ZERO") != -1) {
377 emit(newMessage("Get Data: " + _staID + " in original format"));
378 _decoder = new bncZeroDecoder(_staID);
379 }
380 else {
381 emit(newMessage(_staID + ": Unknown data format " + _format));
382 return fatal;
383 }
384 }
385 return success;
386}
387
388// Run
389////////////////////////////////////////////////////////////////////////////
390void bncGetThread::run() {
391
392 const double maxDt = 600.0; // Check observation epoch
393 bool wrongEpoch = false;
394 bool decode = true;
395 int numSucc = 0;
396 int secSucc = 0;
397 int secFail = 0;
398 int initPause = 30; // Initial pause for corrupted streams
399 int currPause = 0;
400 bool begCorrupt = false;
401 bool endCorrupt = false;
402 int oldSecGPS= 0;
403 int newSecGPS = 0;
404 int oldSecUTC= 0;
405 int newSecUTC = 0;
406 int numLat = 0;
407 double sumLat = 0.;
408 double minLat = maxDt;
409 double maxLat = -maxDt;
410 double curLat = 0.;
411 double leapsec = 14.; // Leap second for latency estimation
412
413 _decodeTime = QDateTime::currentDateTime();
414 _decodeSucc = QDateTime::currentDateTime();
415 t_irc irc = initRun();
416
417 if (irc == fatal) {
418 QThread::exit(1);
419 return;
420 }
421 else if (irc != success) {
422 emit(newMessage(_staID + ": initRun failed, reconnecting"));
423 tryReconnect();
424 }
425
426 if (initPause < _inspSegm) {
427 initPause = _inspSegm;
428 }
429 currPause = initPause;
430
431 // Read Incoming Data
432 // ------------------
433 while (true) {
434 try {
435 if (_socket->state() != QAbstractSocket::ConnectedState) {
436 emit(newMessage(_staID + ": Socket not connected, reconnecting"));
437 tryReconnect();
438 }
439
440 QListIterator<p_obs> it(_decoder->_obsList);
441 while (it.hasNext()) {
442 delete it.next();
443 }
444 _decoder->_obsList.clear();
445
446 _socket->waitForReadyRead(_timeOut);
447 qint64 nBytes = _socket->bytesAvailable();
448 if (nBytes > 0) {
449 emit newBytes(_staID, nBytes);
450
451 char* data = new char[nBytes];
452 _socket->read(data, nBytes);
453
454 if (_inspSegm<1) {
455 _decoder->Decode(data, nBytes);
456 }
457 else {
458
459 // Decode data
460 // -----------
461 if (!_decodePause.isValid() ||
462 _decodePause.secsTo(QDateTime::currentDateTime()) >= currPause || !_makePause ) {
463
464 if (decode) {
465 if ( _decoder->Decode(data, nBytes) == success ) {
466 numSucc += 1;
467 }
468 if ( _decodeTime.secsTo(QDateTime::currentDateTime()) > _inspSegm ) {
469 decode = false;
470 }
471 }
472
473 // Check - once per inspect segment
474 // --------------------------------
475 if (!decode) {
476 _decodeTime = QDateTime::currentDateTime();
477 if (numSucc>0) {
478 secSucc += _inspSegm;
479 _decodeSucc = QDateTime::currentDateTime();
480 if (secSucc > _adviseReco * 60) {
481 secSucc = _adviseReco * 60 + 1;
482 }
483 numSucc = 0;
484 currPause = initPause;
485 _decodePause.setDate(QDate());
486 _decodePause.setTime(QTime());
487 }
488 else {
489 secFail += _inspSegm;
490 secSucc = 0;
491 if (secFail > _adviseFail * 60) {
492 secFail = _adviseFail * 60 + 1;
493 }
494 if (!_decodePause.isValid()) {
495 _decodePause = QDateTime::currentDateTime();
496 }
497 else {
498 _decodePause.setDate(QDate());
499 _decodePause.setTime(QTime());
500 secFail = secFail + currPause - _inspSegm;
501 currPause = currPause * 2;
502 if (currPause > 960) {
503 currPause = 960;
504 }
505 }
506 }
507
508 // End corrupt threshold
509 // ---------------------
510 if ( begCorrupt && !endCorrupt && secSucc > _adviseReco * 60 ) {
511 _endDateCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
512 _endTimeCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
513 emit(newMessage((_staID + ": Recovery threshold exceeded, corruption ended " + _endDateCor + " " + _endTimeCor).toAscii()));
514 callScript(("End_Corrupted " + _endDateCor + " " + _endTimeCor + " Begin was " + _begDateCor + " " + _begTimeCor).toAscii());
515 endCorrupt = true;
516 begCorrupt = false;
517 secFail = 0;
518 }
519 else {
520
521 // Begin corrupt threshold
522 // -----------------------
523 if ( !begCorrupt && secFail > _adviseFail * 60 ) {
524 _begDateCor = _decodeSucc.toUTC().date().toString("yy-MM-dd");
525 _begTimeCor = _decodeSucc.toUTC().time().toString("hh:mm:ss");
526 emit(newMessage((_staID + ": Failure threshold exceeded, corrupted since " + _begDateCor + " " + _begTimeCor).toAscii()));
527 callScript(("Begin_Corrupted " + _begDateCor + " " + _begTimeCor).toAscii());
528 begCorrupt = true;
529 endCorrupt = false;
530 secSucc = 0;
531 numSucc = 0;
532 }
533 }
534 decode = true;
535 }
536 }
537 }
538
539 // End outage threshold
540 // --------------------
541 if ( _decodeStart.isValid() && _decodeStart.secsTo(QDateTime::currentDateTime()) > _adviseReco * 60 ) {
542 _decodeStart.setDate(QDate());
543 _decodeStart.setTime(QTime());
544 if (_inspSegm>0) {
545 _endDateOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
546 _endTimeOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
547 emit(newMessage((_staID + ": Recovery threshold exceeded, outage ended " + _endDateOut + " " + _endTimeOut).toAscii()));
548 callScript(("End_Outage " + _endDateOut + " " + _endTimeOut + " Begin was " + _begDateOut + " " + _begTimeOut).toAscii());
549 }
550 }
551
552 delete [] data;
553
554 QListIterator<p_obs> it(_decoder->_obsList);
555 while (it.hasNext()) {
556 p_obs obs = it.next();
557
558 // Check observation epoch
559 // -----------------------
560 int week;
561 double sec;
562 currentGPSWeeks(week, sec);
563 const double secPerWeek = 7.0 * 24.0 * 3600.0;
564
565 if (week < obs->_o.GPSWeek) {
566 week += 1;
567 sec -= secPerWeek;
568 }
569 if (week > obs->_o.GPSWeek) {
570 week -= 1;
571 sec += secPerWeek;
572 }
573 double dt = fabs(sec - obs->_o.GPSWeeks);
574 if (week != obs->_o.GPSWeek || dt > maxDt) {
575 if (!wrongEpoch) {
576 emit( newMessage(_staID + ": Wrong observation epoch") );
577 wrongEpoch = true;
578 }
579 delete obs;
580 continue;
581 }
582 else {
583 wrongEpoch = false;
584
585 // Latency
586 // -------
587 if (_latIntr>0) {
588 newSecGPS = static_cast<int>(obs->_o.GPSWeeks);
589 if (newSecGPS != oldSecGPS) {
590 newSecUTC = static_cast<int>(sec);
591 if (newSecUTC % _latIntr < oldSecUTC % _latIntr) {
592 if (numLat>0) {
593 emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4")
594 .arg(_staID.data())
595 .arg(int(sumLat/numLat*100)/100.)
596 .arg(int(minLat*100)/100.)
597 .arg(int(maxLat*100)/100.)
598 .toAscii()) );
599 }
600 sumLat = 0.;
601 numLat = 0;
602 minLat = maxDt;
603 maxLat = -maxDt;
604 }
605 curLat = sec - obs->_o.GPSWeeks + leapsec;
606 sumLat += curLat;
607 if (curLat < minLat) minLat = curLat;
608 if (curLat >= maxLat) maxLat = curLat;
609 numLat += 1;
610 oldSecGPS = newSecGPS;
611 oldSecUTC = newSecUTC;
612 }
613 }
614 }
615
616 // RINEX Output
617 // ------------
618 if (_rnx) {
619 long iSec = long(floor(obs->_o.GPSWeeks+0.5));
620 long newTime = obs->_o.GPSWeek * 7*24*3600 + iSec;
621 if (_samplingRate == 0 || iSec % _samplingRate == 0) {
622 _rnx->deepCopy(obs);
623 }
624 _rnx->dumpEpoch(newTime);
625 }
626
627 bool firstObs = (obs == _decoder->_obsList.first());
628 obs->_status = t_obs::posted;
629 emit newObs(_staID, firstObs, obs);
630 }
631 _decoder->_obsList.clear();
632 }
633 else {
634 emit(newMessage(_staID + ": Data Timeout, reconnecting"));
635 tryReconnect();
636 }
637 }
638 catch (const char* msg) {
639 emit(newMessage(_staID + msg));
640 tryReconnect();
641 }
642 }
643}
644
645// Exit
646////////////////////////////////////////////////////////////////////////////
647void bncGetThread::exit(int exitCode) {
648 if (exitCode!= 0) {
649 emit error(_staID);
650 }
651 QThread::exit(exitCode);
652 terminate();
653}
654
655// Try Re-Connect
656////////////////////////////////////////////////////////////////////////////
657void bncGetThread::tryReconnect() {
658 if (_rnx) {
659 _rnx->setReconnectFlag(true);
660 }
661 if ( !_decodeStart.isValid()) {
662 _decodeStop = QDateTime::currentDateTime();
663 }
664 while (1) {
665 delete _socket; _socket = 0;
666 sleep(_nextSleep);
667 if ( initRun() == success ) {
668 if ( !_decodeStop.isValid()) {
669 _decodeStart = QDateTime::currentDateTime();
670 }
671 break;
672 }
673 else {
674
675 // Begin outage threshold
676 // ----------------------
677 if ( _decodeStop.isValid() && _decodeStop.secsTo(QDateTime::currentDateTime()) > _adviseFail * 60 ) {
678 _decodeStop.setDate(QDate());
679 _decodeStop.setTime(QTime());
680 if (_inspSegm>0) {
681 _begDateOut = _decodeTime.toUTC().date().toString("yy-MM-dd");
682 _begTimeOut = _decodeTime.toUTC().time().toString("hh:mm:ss");
683 emit(newMessage((_staID + ": Failure threshold exceeded, outage since " + _begDateOut + " " + _begTimeOut).toAscii()));
684 callScript(("Begin_Outage " + _begDateOut + " " + _begTimeOut).toAscii());
685 }
686 }
687 _nextSleep *= 2;
688 if (_nextSleep > 256) {
689 _nextSleep = 256;
690 }
691 _nextSleep += rand() % 6;
692 }
693 }
694 _nextSleep = 1;
695}
696
697// Call advisory notice script
698////////////////////////////////////////////////////////////////////////////
699void bncGetThread::callScript(const char* _comment) {
700 QMutexLocker locker(&_mutex);
701 if (!_adviseScript.isEmpty()) {
702 msleep(1);
703#ifdef WIN32
704 QProcess::startDetached(_adviseScript, QStringList() << _staID << _comment) ;
705#else
706 QProcess::startDetached("nohup", QStringList() << _adviseScript << _staID << _comment) ;
707#endif
708 }
709}
Note: See TracBrowser for help on using the repository browser.