Changeset 1377 in ntrip for trunk/BNC/bncgetthread.cpp
- Timestamp:
- Dec 28, 2008, 11:36:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncgetthread.cpp
r1376 r1377 54 54 #include "bncrinex.h" 55 55 #include "bnczerodecoder.h" 56 #include "bnc socket.h"56 #include "bncnetquery.h" 57 57 58 58 #include "RTCM/RTCM2Decoder.h" … … 120 120 121 121 _decoder = 0; 122 _ socket= 0;122 _query = 0; 123 123 _timeOut = 20*1000; // 20 seconds 124 124 _nextSleep = 1; // 1 second … … 288 288 //////////////////////////////////////////////////////////////////////////// 289 289 bncGetThread::~bncGetThread() { 290 if (_socket) { 291 _socket->close(); 292 #if QT_VERSION == 0x040203 293 delete _socket; 294 #else 295 _socket->deleteLater(); 296 #endif 290 if (_query) { 291 _query->deleteLater(); 297 292 } 298 293 delete _decoder; … … 308 303 309 304 if (!_rawInpFile) { 310 311 // Initialize Socket 312 // ----------------- 313 QString msg; 314 delete _socket; 315 _socket = new bncSocket; 316 if (_socket->request(_mountPoint, _latitude, _longitude, 317 _nmea, _ntripVersion, _timeOut, msg) != success) { 318 delete _socket; 319 _socket = 0; 320 return failure; 321 } 322 323 // Read Caster Response 324 // -------------------- 325 if (_ntripVersion == "1") { 326 _socket->waitForReadyRead(_timeOut); 327 if (_socket->canReadLine()) { 328 QString line = _socket->readLine(); 329 330 // Skip messages from proxy server 331 // ------------------------------- 332 if (line.indexOf("ICY 200 OK") == -1 && 333 line.indexOf("200 OK") != -1 ) { 334 bool proxyRespond = true; 335 while (true) { 336 if (_socket->canReadLine()) { 337 line = _socket->readLine(); 338 if (!proxyRespond) { 339 break; 340 } 341 if (line.trimmed().isEmpty()) { 342 proxyRespond = false; 343 } 344 } 345 else { 346 _socket->waitForReadyRead(_timeOut); 347 if (_socket->bytesAvailable() <= 0) { 348 break; 349 } 350 } 351 } 352 } 353 354 if (line.indexOf("Unauthorized") != -1) { 355 QStringList table; 356 bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), 357 table); 358 QString net; 359 QStringListIterator it(table); 360 while (it.hasNext()) { 361 QString line = it.next(); 362 if (line.indexOf("STR") == 0) { 363 QStringList tags = line.split(";"); 364 if (tags.at(1) == _staID_orig) { 365 net = tags.at(7); 366 break; 367 } 368 } 369 } 370 371 QString reg; 372 it.toFront(); 373 while (it.hasNext()) { 374 QString line = it.next(); 375 if (line.indexOf("NET") == 0) { 376 QStringList tags = line.split(";"); 377 if (tags.at(1) == net) { 378 reg = tags.at(7); 379 break; 380 } 381 } 382 } 383 emit(newMessage((_staID + ": Caster Response: " + line + 384 " Adjust User-ID and Password Register, see" 385 "\n " + reg).toAscii(), true)); 386 return fatal; 387 } 388 if (line.indexOf("ICY 200 OK") != 0) { 389 emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii(), true)); 390 return failure; 391 } 392 } 393 else { 394 emit(newMessage(_staID + ": Response Timeout", true)); 395 return failure; 396 } 397 } 305 delete _query; 306 _query = new bncNetQuery(); 307 _query->startRequest(_mountPoint); 398 308 } 399 309 … … 487 397 while (true) { 488 398 try { 489 if (_ socket && _socket->state() != QAbstractSocket::ConnectedState) {490 emit(newMessage(_staID + ": Socket not connected, reconnecting", true));399 if (_query && _query->status() != bncNetQuery::running) { 400 emit(newMessage(_staID + ": Internet query not running, reconnecting", true)); 491 401 tryReconnect(); 492 402 } … … 500 410 qint64 nBytes = 0; 501 411 502 if (_socket) { 503 _socket->waitForReadyRead(_timeOut); 504 nBytes = _socket->bytesAvailable(); 412 QByteArray data; 413 414 if (_query) { 415 _query->waitForReadyRead(data); 416 nBytes = data.size(); 505 417 } 506 418 else if (_rawInpFile) { … … 512 424 emit newBytes(_staID, nBytes); 513 425 514 QByteArray data; 515 516 if (_socket) { 517 data = _socket->read(nBytes); 518 } 519 else if (_rawInpFile) { 426 if (_rawInpFile) { 520 427 data = _rawInpFile->read(nBytes); 521 428 if (data.isEmpty()) { … … 532 439 if (_serialPort) { 533 440 _serialPort->write(data); 534 //// _serialPort->flush();535 441 } 536 442
Note:
See TracChangeset
for help on using the changeset viewer.