Changeset 1138 in ntrip for trunk/BNC/bncgetthread.cpp
- Timestamp:
- Oct 2, 2008, 3:23:09 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncgetthread.cpp
r1137 r1138 62 62 // Constructor 63 63 //////////////////////////////////////////////////////////////////////////// 64 bncGetThread::bncGetThread(const QByteArray& rawInpFileName, 65 const QByteArray& format) { 66 67 _decoder = 0; 68 _socket = 0; 69 _rawOutFile = 0; 70 _format = format; 71 72 _rawInpFile = new QFile(rawInpFileName); 73 _rawInpFile->open(QIODevice::ReadOnly); 74 } 75 64 76 bncGetThread::bncGetThread(const QUrl& mountPoint, 65 77 const QByteArray& format, … … 82 94 _nextSleep = 1; // 1 second 83 95 _iMount = iMount; // index in mountpoints array 96 _rawInpFile = 0; 84 97 85 98 // Check name conflict … … 151 164 // ---------- 152 165 if (false) { // special option used for testing 153 QByteArray raw FileName = "./" + _staID + ".raw";154 _raw File = new QFile(rawFileName);155 _raw File->open(QIODevice::WriteOnly);166 QByteArray rawOutFileName = "./" + _staID + ".raw"; 167 _rawOutFile = new QFile(rawOutFileName); 168 _rawOutFile->open(QIODevice::WriteOnly); 156 169 } 157 170 else { 158 _raw File = 0;171 _rawOutFile = 0; 159 172 } 160 173 … … 175 188 delete _decoder; 176 189 delete _rnx; 177 delete _rawFile; 190 delete _rawInpFile; 191 delete _rawOutFile; 178 192 } 179 193 … … 297 311 t_irc bncGetThread::initRun() { 298 312 299 // Initialize Socket 300 // ----------------- 301 QString msg; 302 _socket = this->request(_mountPoint, _latitude, _longitude, 303 _nmea, _timeOut, msg); 304 if (!_socket) { 305 return failure; 306 } 307 308 // Read Caster Response 309 // -------------------- 310 _socket->waitForReadyRead(_timeOut); 311 if (_socket->canReadLine()) { 312 QString line = _socket->readLine(); 313 314 // Skip messages from proxy server 315 // ------------------------------- 316 if (line.indexOf("ICY 200 OK") == -1 && 317 line.indexOf("200 OK") != -1 ) { 318 bool proxyRespond = true; 319 while (true) { 320 if (_socket->canReadLine()) { 321 line = _socket->readLine(); 322 if (!proxyRespond) { 323 break; 324 } 325 if (line.trimmed().isEmpty()) { 326 proxyRespond = false; 327 } 328 } 329 else { 330 _socket->waitForReadyRead(_timeOut); 331 if (_socket->bytesAvailable() <= 0) { 332 break; 333 } 334 } 335 } 336 } 337 338 if (line.indexOf("Unauthorized") != -1) { 339 QStringList table; 340 bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table); 341 QString net; 342 QStringListIterator it(table); 343 while (it.hasNext()) { 344 QString line = it.next(); 345 if (line.indexOf("STR") == 0) { 346 QStringList tags = line.split(";"); 347 if (tags.at(1) == _staID_orig) { 348 net = tags.at(7); 349 break; 350 } 351 } 352 } 353 354 QString reg; 355 it.toFront(); 356 while (it.hasNext()) { 357 QString line = it.next(); 358 if (line.indexOf("NET") == 0) { 359 QStringList tags = line.split(";"); 360 if (tags.at(1) == net) { 361 reg = tags.at(7); 362 break; 363 } 364 } 365 } 366 emit(newMessage((_staID + ": Caster Response: " + line + 367 " Adjust User-ID and Password Register, see" 368 "\n " + reg).toAscii())); 369 return fatal; 370 } 371 if (line.indexOf("ICY 200 OK") != 0) { 372 emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii())); 313 if (!_rawInpFile) { 314 315 // Initialize Socket 316 // ----------------- 317 QString msg; 318 _socket = this->request(_mountPoint, _latitude, _longitude, 319 _nmea, _timeOut, msg); 320 if (!_socket) { 373 321 return failure; 374 322 } 375 } 376 else { 377 emit(newMessage(_staID + ": Response Timeout")); 378 return failure; 323 324 // Read Caster Response 325 // -------------------- 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(), table); 357 QString net; 358 QStringListIterator it(table); 359 while (it.hasNext()) { 360 QString line = it.next(); 361 if (line.indexOf("STR") == 0) { 362 QStringList tags = line.split(";"); 363 if (tags.at(1) == _staID_orig) { 364 net = tags.at(7); 365 break; 366 } 367 } 368 } 369 370 QString reg; 371 it.toFront(); 372 while (it.hasNext()) { 373 QString line = it.next(); 374 if (line.indexOf("NET") == 0) { 375 QStringList tags = line.split(";"); 376 if (tags.at(1) == net) { 377 reg = tags.at(7); 378 break; 379 } 380 } 381 } 382 emit(newMessage((_staID + ": Caster Response: " + line + 383 " Adjust User-ID and Password Register, see" 384 "\n " + reg).toAscii())); 385 return fatal; 386 } 387 if (line.indexOf("ICY 200 OK") != 0) { 388 emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii())); 389 return failure; 390 } 391 } 392 else { 393 emit(newMessage(_staID + ": Response Timeout")); 394 return failure; 395 } 379 396 } 380 397 … … 458 475 while (true) { 459 476 try { 460 if (_socket ->state() != QAbstractSocket::ConnectedState) {477 if (_socket && _socket->state() != QAbstractSocket::ConnectedState) { 461 478 emit(newMessage(_staID + ": Socket not connected, reconnecting")); 462 479 tryReconnect(); … … 469 486 _decoder->_obsList.clear(); 470 487 471 _socket->waitForReadyRead(_timeOut); 472 qint64 nBytes = _socket->bytesAvailable(); 488 qint64 nBytes = 0; 489 490 if (_socket) { 491 _socket->waitForReadyRead(_timeOut); 492 nBytes = _socket->bytesAvailable(); 493 } 494 else if (_rawInpFile) { 495 const qint64 maxBytes = 1024; 496 nBytes = maxBytes; 497 } 498 473 499 if (nBytes > 0) { 474 500 emit newBytes(_staID, nBytes); 475 501 476 502 char* data = new char[nBytes]; 477 _socket->read(data, nBytes); 478 479 if (_rawFile) { 480 _rawFile->write(data, nBytes); 481 _rawFile->flush(); 503 504 if (_socket) { 505 _socket->read(data, nBytes); 506 } 507 else if (_rawInpFile) { 508 nBytes = _rawInpFile->read(data, nBytes); 509 cout << "nBytes = " << nBytes << endl; 510 if (nBytes <= 0) { 511 cout << "no more data" << endl; 512 ::exit(0); 513 } 514 } 515 516 if (_rawOutFile) { 517 _rawOutFile->write(data, nBytes); 518 _rawOutFile->flush(); 482 519 } 483 520
Note:
See TracChangeset
for help on using the changeset viewer.