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

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

* empty log message *

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