[280] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
[464] | 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
[280] | 3 | //
|
---|
[464] | 4 | // Copyright (C) 2007
|
---|
[280] | 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
[464] | 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
[280] | 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.
|
---|
[35] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
[93] | 26 | * BKG NTRIP Client
|
---|
[35] | 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 |
|
---|
[277] | 41 | #include <stdlib.h>
|
---|
| 42 |
|
---|
[35] | 43 | #include <QFile>
|
---|
| 44 | #include <QTextStream>
|
---|
| 45 | #include <QtNetwork>
|
---|
[356] | 46 | #include <QTime>
|
---|
[35] | 47 |
|
---|
| 48 | #include "bncgetthread.h"
|
---|
[192] | 49 | #include "bnctabledlg.h"
|
---|
[243] | 50 | #include "bncapp.h"
|
---|
[352] | 51 | #include "bncutils.h"
|
---|
[408] | 52 | #include "bncrinex.h"
|
---|
[423] | 53 | #include "bnczerodecoder.h"
|
---|
[65] | 54 |
|
---|
[243] | 55 | #include "RTCM/RTCM2Decoder.h"
|
---|
[297] | 56 | #include "RTCM3/RTCM3Decoder.h"
|
---|
[293] | 57 | #include "RTIGS/RTIGSDecoder.h"
|
---|
[35] | 58 |
|
---|
| 59 | using namespace std;
|
---|
| 60 |
|
---|
| 61 | // Constructor
|
---|
| 62 | ////////////////////////////////////////////////////////////////////////////
|
---|
[278] | 63 | bncGetThread::bncGetThread(const QUrl& mountPoint,
|
---|
[366] | 64 | const QByteArray& format,
|
---|
| 65 | const QByteArray& latitude,
|
---|
| 66 | const QByteArray& longitude,
|
---|
| 67 | const QByteArray& nmea, int iMount) {
|
---|
[350] | 68 | _decoder = 0;
|
---|
| 69 | _mountPoint = mountPoint;
|
---|
| 70 | _staID = mountPoint.path().mid(1).toAscii();
|
---|
| 71 | _staID_orig = _staID;
|
---|
| 72 | _format = format;
|
---|
[366] | 73 | _latitude = latitude;
|
---|
| 74 | _longitude = longitude;
|
---|
| 75 | _nmea = nmea;
|
---|
[350] | 76 | _socket = 0;
|
---|
| 77 | _timeOut = 20*1000; // 20 seconds
|
---|
| 78 | _nextSleep = 1; // 1 second
|
---|
| 79 | _iMount = iMount; // index in mountpoints array
|
---|
[255] | 80 |
|
---|
| 81 | // Check name conflict
|
---|
| 82 | // -------------------
|
---|
| 83 | QSettings settings;
|
---|
| 84 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 85 | int num = 0;
|
---|
[278] | 86 | int ind = -1;
|
---|
[255] | 87 | while (it.hasNext()) {
|
---|
[278] | 88 | ++ind;
|
---|
[255] | 89 | QStringList hlp = it.next().split(" ");
|
---|
| 90 | if (hlp.size() <= 1) continue;
|
---|
| 91 | QUrl url(hlp[0]);
|
---|
| 92 | if (_mountPoint.path() == url.path()) {
|
---|
[278] | 93 | if (_iMount > ind) {
|
---|
| 94 | ++num;
|
---|
[255] | 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
[278] | 98 |
|
---|
| 99 | if (num > 0) {
|
---|
| 100 | _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii();
|
---|
[255] | 101 | }
|
---|
[408] | 102 |
|
---|
| 103 | // RINEX writer
|
---|
| 104 | // ------------
|
---|
| 105 | _samplingRate = settings.value("rnxSampl").toInt();
|
---|
| 106 | if ( settings.value("rnxPath").toString().isEmpty() ) {
|
---|
| 107 | _rnx = 0;
|
---|
| 108 | }
|
---|
| 109 | else {
|
---|
| 110 | _rnx = new bncRinex(_staID, mountPoint, format, latitude, longitude, nmea);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[319] | 113 | msleep(100); //sleep 0.1 sec
|
---|
[35] | 114 | }
|
---|
| 115 |
|
---|
| 116 | // Destructor
|
---|
| 117 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 118 | bncGetThread::~bncGetThread() {
|
---|
| 119 | delete _socket;
|
---|
[136] | 120 | delete _decoder;
|
---|
[35] | 121 | }
|
---|
| 122 |
|
---|
| 123 | // Connect to Caster, send the Request (static)
|
---|
| 124 | ////////////////////////////////////////////////////////////////////////////
|
---|
[366] | 125 | QTcpSocket* bncGetThread::request(const QUrl& mountPoint,
|
---|
| 126 | QByteArray& latitude, QByteArray& longitude,
|
---|
| 127 | QByteArray& nmea, int timeOut,
|
---|
[136] | 128 | QString& msg) {
|
---|
[35] | 129 |
|
---|
[88] | 130 | // Connect the Socket
|
---|
| 131 | // ------------------
|
---|
| 132 | QSettings settings;
|
---|
| 133 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
| 134 | int proxyPort = settings.value("proxyPort").toInt();
|
---|
| 135 |
|
---|
[35] | 136 | QTcpSocket* socket = new QTcpSocket();
|
---|
| 137 | if ( proxyHost.isEmpty() ) {
|
---|
[88] | 138 | socket->connectToHost(mountPoint.host(), mountPoint.port());
|
---|
[35] | 139 | }
|
---|
| 140 | else {
|
---|
| 141 | socket->connectToHost(proxyHost, proxyPort);
|
---|
| 142 | }
|
---|
| 143 | if (!socket->waitForConnected(timeOut)) {
|
---|
[82] | 144 | msg += "Connect timeout\n";
|
---|
[35] | 145 | delete socket;
|
---|
| 146 | return 0;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | // Send Request
|
---|
| 150 | // ------------
|
---|
[443] | 151 | QString uName = QUrl::fromPercentEncoding(mountPoint.userName().toAscii());
|
---|
| 152 | QString passW = QUrl::fromPercentEncoding(mountPoint.password().toAscii());
|
---|
[444] | 153 | QByteArray userAndPwd = uName.toAscii() + ":" + passW.toAscii();
|
---|
[92] | 154 |
|
---|
| 155 | QUrl hlp;
|
---|
| 156 | hlp.setScheme("http");
|
---|
| 157 | hlp.setHost(mountPoint.host());
|
---|
| 158 | hlp.setPort(mountPoint.port());
|
---|
| 159 | hlp.setPath(mountPoint.path());
|
---|
| 160 |
|
---|
[214] | 161 | QByteArray reqStr;
|
---|
| 162 | if ( proxyHost.isEmpty() ) {
|
---|
| 163 | if (hlp.path().indexOf("/") != 0) hlp.setPath("/");
|
---|
| 164 | reqStr = "GET " + hlp.path().toAscii() +
|
---|
| 165 | " HTTP/1.0\r\n"
|
---|
[476] | 166 | "User-Agent: NTRIP BNC 1.4\r\n"
|
---|
[214] | 167 | "Authorization: Basic " +
|
---|
[440] | 168 | userAndPwd.toBase64() + "\r\n";
|
---|
[214] | 169 | } else {
|
---|
| 170 | reqStr = "GET " + hlp.toEncoded() +
|
---|
| 171 | " HTTP/1.0\r\n"
|
---|
[476] | 172 | "User-Agent: NTRIP BNC 1.4\r\n"
|
---|
[214] | 173 | "Authorization: Basic " +
|
---|
[440] | 174 | userAndPwd.toBase64() + "\r\n";
|
---|
[205] | 175 | }
|
---|
[440] | 176 | if (hlp.path().indexOf(".skl") > 0) { reqStr += "Host: " + hlp.host().toAscii() + "\r\n"; }
|
---|
| 177 | reqStr += "\r\n";
|
---|
[205] | 178 |
|
---|
[464] | 179 | // NMEA string to handle VRS stream
|
---|
| 180 | // --------------------------------
|
---|
[356] | 181 |
|
---|
| 182 | double lat, lon;
|
---|
[366] | 183 |
|
---|
| 184 | lat = strtod(latitude,NULL);
|
---|
| 185 | lon = strtod(longitude,NULL);
|
---|
| 186 |
|
---|
[410] | 187 | if ((nmea == "yes") && (hlp.path().length() > 2) && (hlp.path().indexOf(".skl") < 0)) {
|
---|
[356] | 188 | const char* flagN="N";
|
---|
| 189 | const char* flagE="E";
|
---|
| 190 | if (lon >180.) {lon=(lon-360.)*(-1.); flagE="W";}
|
---|
| 191 | if ((lon < 0.) && (lon >= -180.)) {lon=lon*(-1.); flagE="W";}
|
---|
| 192 | if (lon < -180.) {lon=(lon+360.); flagE="E";}
|
---|
| 193 | if (lat < 0.) {lat=lat*(-1.); flagN="S";}
|
---|
| 194 | QTime ttime(QTime::currentTime());
|
---|
| 195 | int lat_deg = (int)lat;
|
---|
| 196 | double lat_min=(lat-lat_deg)*60.;
|
---|
| 197 | int lon_deg = (int)lon;
|
---|
| 198 | double lon_min=(lon-lon_deg)*60.;
|
---|
| 199 | int hh = 0 , mm = 0;
|
---|
| 200 | double ss = 0.0;
|
---|
| 201 | hh=ttime.hour();
|
---|
| 202 | mm=ttime.minute();
|
---|
| 203 | ss=(double)ttime.second()+0.001*ttime.msec();
|
---|
| 204 | QString gga;
|
---|
| 205 | gga += "GPGGA,";
|
---|
| 206 | 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'));
|
---|
| 207 | gga += QString("%1%2,").arg((int)lat_deg,2, 10, QLatin1Char('0')).arg(lat_min, 7, 'f', 4, QLatin1Char('0'));
|
---|
| 208 | gga += flagN;
|
---|
| 209 | gga += QString(",%1%2,").arg((int)lon_deg,3, 10, QLatin1Char('0')).arg(lon_min, 7, 'f', 4, QLatin1Char('0'));
|
---|
| 210 | gga += flagE + QString(",1,05,1.00,+00100,M,10.000,M,,");
|
---|
| 211 | int xori;
|
---|
| 212 | char XOR = 0;
|
---|
| 213 | char *Buff =gga.toAscii().data();
|
---|
| 214 | int iLen = strlen(Buff);
|
---|
| 215 | for (xori = 0; xori < iLen; xori++) {
|
---|
| 216 | XOR ^= (char)Buff[xori];
|
---|
| 217 | }
|
---|
| 218 | gga += QString("*%1").arg(XOR, 2, 16, QLatin1Char('0'));
|
---|
| 219 | reqStr += "$";
|
---|
| 220 | reqStr += gga;
|
---|
| 221 | reqStr += "\r\n";
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[82] | 224 | msg += reqStr;
|
---|
[35] | 225 |
|
---|
| 226 | socket->write(reqStr, reqStr.length());
|
---|
| 227 |
|
---|
| 228 | if (!socket->waitForBytesWritten(timeOut)) {
|
---|
[82] | 229 | msg += "Write timeout\n";
|
---|
[35] | 230 | delete socket;
|
---|
| 231 | return 0;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | return socket;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[136] | 237 | // Init Run
|
---|
[35] | 238 | ////////////////////////////////////////////////////////////////////////////
|
---|
[138] | 239 | t_irc bncGetThread::initRun() {
|
---|
[35] | 240 |
|
---|
| 241 | // Send the Request
|
---|
| 242 | // ----------------
|
---|
[82] | 243 | QString msg;
|
---|
[88] | 244 |
|
---|
[366] | 245 | _socket = bncGetThread::request(_mountPoint, _latitude, _longitude, _nmea, _timeOut, msg);
|
---|
[88] | 246 |
|
---|
[193] | 247 | //// emit(newMessage(msg.toAscii()));
|
---|
[82] | 248 |
|
---|
[35] | 249 | if (!_socket) {
|
---|
[138] | 250 | return failure;
|
---|
[35] | 251 | }
|
---|
| 252 |
|
---|
| 253 | // Read Caster Response
|
---|
| 254 | // --------------------
|
---|
[136] | 255 | _socket->waitForReadyRead(_timeOut);
|
---|
[35] | 256 | if (_socket->canReadLine()) {
|
---|
| 257 | QString line = _socket->readLine();
|
---|
[473] | 258 |
|
---|
| 259 | // Skip messages from proxy server
|
---|
| 260 | // -------------------------------
|
---|
| 261 | if (line.indexOf("ICY 200 OK") == -1 &&
|
---|
| 262 | line.indexOf("200 OK") != -1 ) {
|
---|
| 263 | bool proxyRespond = true;
|
---|
| 264 | while (true) {
|
---|
| 265 | if (_socket->canReadLine()) {
|
---|
| 266 | line = _socket->readLine();
|
---|
| 267 | if (!proxyRespond) {
|
---|
| 268 | break;
|
---|
| 269 | }
|
---|
| 270 | if (line.trimmed().isEmpty()) {
|
---|
| 271 | proxyRespond = false;
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 | else {
|
---|
| 275 | _socket->waitForReadyRead(_timeOut);
|
---|
[474] | 276 | if (_socket->bytesAvailable() <= 0) {
|
---|
| 277 | break;
|
---|
| 278 | }
|
---|
[473] | 279 | }
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[146] | 283 | if (line.indexOf("Unauthorized") != -1) {
|
---|
[192] | 284 | QStringList table;
|
---|
| 285 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table);
|
---|
| 286 | QString net;
|
---|
| 287 | QStringListIterator it(table);
|
---|
| 288 | while (it.hasNext()) {
|
---|
| 289 | QString line = it.next();
|
---|
| 290 | if (line.indexOf("STR") == 0) {
|
---|
| 291 | QStringList tags = line.split(";");
|
---|
[255] | 292 | if (tags.at(1) == _staID_orig) {
|
---|
[192] | 293 | net = tags.at(7);
|
---|
| 294 | break;
|
---|
| 295 | }
|
---|
| 296 | }
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | QString reg;
|
---|
| 300 | it.toFront();
|
---|
| 301 | while (it.hasNext()) {
|
---|
| 302 | QString line = it.next();
|
---|
| 303 | if (line.indexOf("NET") == 0) {
|
---|
| 304 | QStringList tags = line.split(";");
|
---|
| 305 | if (tags.at(1) == net) {
|
---|
| 306 | reg = tags.at(7);
|
---|
| 307 | break;
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
[194] | 311 | emit(newMessage((_staID + ": Caster Response: " + line +
|
---|
[200] | 312 | " Adjust User-ID and Password Register, see"
|
---|
[194] | 313 | "\n " + reg).toAscii()));
|
---|
[192] | 314 | return fatal;
|
---|
[146] | 315 | }
|
---|
[35] | 316 | if (line.indexOf("ICY 200 OK") != 0) {
|
---|
[190] | 317 | emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii()));
|
---|
[144] | 318 | return failure;
|
---|
[35] | 319 | }
|
---|
| 320 | }
|
---|
| 321 | else {
|
---|
[190] | 322 | emit(newMessage(_staID + ": Response Timeout"));
|
---|
[138] | 323 | return failure;
|
---|
[35] | 324 | }
|
---|
| 325 |
|
---|
| 326 | // Instantiate the filter
|
---|
| 327 | // ----------------------
|
---|
[423] | 328 | if (!_decoder) {
|
---|
[136] | 329 | if (_format.indexOf("RTCM_2") != -1) {
|
---|
| 330 | emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format"));
|
---|
[243] | 331 | _decoder = new RTCM2Decoder();
|
---|
[136] | 332 | }
|
---|
| 333 | else if (_format.indexOf("RTCM_3") != -1) {
|
---|
| 334 | emit(newMessage("Get Data: " + _staID + " in RTCM 3.0 format"));
|
---|
[297] | 335 | _decoder = new RTCM3Decoder();
|
---|
[136] | 336 | }
|
---|
| 337 | else if (_format.indexOf("RTIGS") != -1) {
|
---|
| 338 | emit(newMessage("Get Data: " + _staID + " in RTIGS format"));
|
---|
[293] | 339 | _decoder = new RTIGSDecoder();
|
---|
[136] | 340 | }
|
---|
[428] | 341 | else if (_format.indexOf("SP3") != -1 || _format.indexOf("ZERO") != -1) {
|
---|
| 342 | emit(newMessage("Get Data: " + _staID + " in original format"));
|
---|
[424] | 343 | _decoder = new bncZeroDecoder(_staID);
|
---|
[406] | 344 | }
|
---|
[136] | 345 | else {
|
---|
[190] | 346 | emit(newMessage(_staID + ": Unknown data format " + _format));
|
---|
[250] | 347 | return fatal;
|
---|
[136] | 348 | }
|
---|
[60] | 349 | }
|
---|
[138] | 350 | return success;
|
---|
[136] | 351 | }
|
---|
[59] | 352 |
|
---|
[136] | 353 | // Run
|
---|
| 354 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 355 | void bncGetThread::run() {
|
---|
| 356 |
|
---|
[229] | 357 | t_irc irc = initRun();
|
---|
| 358 |
|
---|
| 359 | if (irc == fatal) {
|
---|
[192] | 360 | QThread::exit(1);
|
---|
| 361 | return;
|
---|
| 362 | }
|
---|
[229] | 363 | else if (irc != success) {
|
---|
[190] | 364 | emit(newMessage(_staID + ": initRun failed, reconnecting"));
|
---|
[138] | 365 | tryReconnect();
|
---|
| 366 | }
|
---|
[136] | 367 |
|
---|
[35] | 368 | // Read Incoming Data
|
---|
| 369 | // ------------------
|
---|
| 370 | while (true) {
|
---|
[249] | 371 | try {
|
---|
| 372 | if (_socket->state() != QAbstractSocket::ConnectedState) {
|
---|
| 373 | emit(newMessage(_staID + ": Socket not connected, reconnecting"));
|
---|
| 374 | tryReconnect();
|
---|
[35] | 375 | }
|
---|
[249] | 376 |
|
---|
| 377 |
|
---|
| 378 | _socket->waitForReadyRead(_timeOut);
|
---|
| 379 | qint64 nBytes = _socket->bytesAvailable();
|
---|
| 380 | if (nBytes > 0) {
|
---|
| 381 | char* data = new char[nBytes];
|
---|
| 382 | _socket->read(data, nBytes);
|
---|
[406] | 383 |
|
---|
[249] | 384 | _decoder->Decode(data, nBytes);
|
---|
[331] | 385 | delete [] data;
|
---|
[423] | 386 |
|
---|
[249] | 387 | for (list<Observation*>::iterator it = _decoder->_obsList.begin();
|
---|
| 388 | it != _decoder->_obsList.end(); it++) {
|
---|
[351] | 389 |
|
---|
| 390 | // Check observation epoch
|
---|
| 391 | // -----------------------
|
---|
| 392 | int week;
|
---|
| 393 | double sec;
|
---|
| 394 | currentGPSWeeks(week, sec);
|
---|
| 395 |
|
---|
| 396 | const double secPerWeek = 7.0 * 24.0 * 3600.0;
|
---|
| 397 | const double maxDt = 600.0;
|
---|
| 398 |
|
---|
| 399 | if (week < (*it)->GPSWeek) {
|
---|
| 400 | week += 1;
|
---|
| 401 | sec -= secPerWeek;
|
---|
| 402 | }
|
---|
| 403 | if (week > (*it)->GPSWeek) {
|
---|
| 404 | week -= 1;
|
---|
| 405 | sec += secPerWeek;
|
---|
| 406 | }
|
---|
| 407 | double dt = fabs(sec - (*it)->GPSWeeks);
|
---|
| 408 | if (week != (*it)->GPSWeek || dt > maxDt) {
|
---|
| 409 | emit( newMessage("Wrong observation epoch") );
|
---|
| 410 | delete (*it);
|
---|
| 411 | continue;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[408] | 414 | // RINEX Output
|
---|
| 415 | // ------------
|
---|
| 416 | if (_rnx) {
|
---|
| 417 | long iSec = long(floor((*it)->GPSWeeks+0.5));
|
---|
| 418 | long newTime = (*it)->GPSWeek * 7*24*3600 + iSec;
|
---|
| 419 | if (_samplingRate == 0 || iSec % _samplingRate == 0) {
|
---|
| 420 | _rnx->deepCopy(*it);
|
---|
| 421 | }
|
---|
| 422 | _rnx->dumpEpoch(newTime);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[459] | 425 | emit newBytes(_staID, sizeof(**it));
|
---|
[409] | 426 | bool firstObs = (it == _decoder->_obsList.begin());
|
---|
[463] | 427 | emit newObs(_staID, firstObs, *it);
|
---|
[249] | 428 | }
|
---|
| 429 | _decoder->_obsList.clear();
|
---|
| 430 | }
|
---|
| 431 | else {
|
---|
| 432 | emit(newMessage(_staID + ": Data Timeout, reconnecting"));
|
---|
| 433 | tryReconnect();
|
---|
| 434 | }
|
---|
[35] | 435 | }
|
---|
[249] | 436 | catch (const char* msg) {
|
---|
| 437 | emit(newMessage(_staID + msg));
|
---|
[136] | 438 | tryReconnect();
|
---|
[35] | 439 | }
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | // Exit
|
---|
| 444 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 445 | void bncGetThread::exit(int exitCode) {
|
---|
| 446 | if (exitCode!= 0) {
|
---|
[88] | 447 | emit error(_staID);
|
---|
[35] | 448 | }
|
---|
| 449 | QThread::exit(exitCode);
|
---|
[148] | 450 | terminate();
|
---|
[35] | 451 | }
|
---|
[82] | 452 |
|
---|
[136] | 453 | // Try Re-Connect
|
---|
| 454 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 455 | void bncGetThread::tryReconnect() {
|
---|
[408] | 456 | if (_rnx) {
|
---|
| 457 | _rnx->setReconnectFlag(true);
|
---|
| 458 | }
|
---|
[138] | 459 | while (1) {
|
---|
| 460 | delete _socket; _socket = 0;
|
---|
| 461 | sleep(_nextSleep);
|
---|
| 462 | if ( initRun() == success ) {
|
---|
| 463 | break;
|
---|
| 464 | }
|
---|
| 465 | else {
|
---|
| 466 | _nextSleep *= 2;
|
---|
[442] | 467 | if (_nextSleep > 256) {
|
---|
| 468 | _nextSleep = 256;
|
---|
[152] | 469 | }
|
---|
[277] | 470 | _nextSleep += rand() % 6;
|
---|
[138] | 471 | }
|
---|
| 472 | }
|
---|
| 473 | _nextSleep = 1;
|
---|
[136] | 474 | }
|
---|