- Timestamp:
- Oct 2, 2008, 3:23:09 PM (16 years ago)
- Location:
- trunk/BNC
- Files:
-
- 3 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 -
trunk/BNC/bncgetthread.h
r1137 r1138 41 41 42 42 public: 43 bncGetThread(const QByteArray& rawInpFileName, const QByteArray& format); 43 44 bncGetThread(const QUrl& mountPoint, 44 45 const QByteArray& format, … … 46 47 const QByteArray& longitude, 47 48 const QByteArray& nmea, int iMount); 49 48 50 ~bncGetThread(); 49 51 … … 109 111 QDateTime _decodeSucc; 110 112 QMutex _mutex; 111 QFile* _rawFile; 113 QFile* _rawOutFile; 114 QFile* _rawInpFile; 112 115 }; 113 116 -
trunk/BNC/bncmain.cpp
r1095 r1138 115 115 else { 116 116 117 signal(SIGINT, catch_signal); 118 117 119 bncCaster* caster = new bncCaster(settings.value("outFile").toString(), 118 120 settings.value("outPort").toInt()); 119 121 120 122 app.setCaster(caster); 121 122 // Ctrl-C Signal Handling123 // ----------------------124 signal(SIGINT, catch_signal);125 126 //// beg test127 //// QTimer::singleShot(30000, &app, SLOT(slotQuit()));128 //// end test129 130 123 app.setPort(settings.value("outEphPort").toInt()); 131 124 app.setPortCorr(settings.value("corrPort").toInt()); … … 137 130 ((bncApp*)qApp)->slotMessage("============ Start BNC ============"); 138 131 139 int iMount = -1; 140 QListIterator<QString> it(settings.value("mountPoints").toStringList()); 141 while (it.hasNext()) { 142 ++iMount; 143 QStringList hlp = it.next().split(" "); 144 if (hlp.size() <= 1) continue; 145 QUrl url(hlp[0]); 146 QByteArray format = hlp[1].toAscii(); 147 QByteArray latitude = hlp[2].toAscii(); 148 QByteArray longitude = hlp[3].toAscii(); 149 QByteArray nmea = hlp[4].toAscii(); 150 bncGetThread* getThread = new bncGetThread(url, format, latitude, longitude, nmea, iMount); 132 if (false) { 133 bncGetThread* getThread = new bncGetThread("FFMJ2.raw","RTCM_3"); 151 134 app.connect(getThread, SIGNAL(newMessage(QByteArray)), 152 135 &app, SLOT(slotMessage(const QByteArray))); 153 136 154 137 caster->addGetThread(getThread); 155 138 156 139 getThread->start(); 157 140 } 158 if (caster->numStations() == 0) { 159 return 0; 141 else { 142 int iMount = -1; 143 QListIterator<QString> it(settings.value("mountPoints").toStringList()); 144 while (it.hasNext()) { 145 ++iMount; 146 QStringList hlp = it.next().split(" "); 147 if (hlp.size() <= 1) continue; 148 QUrl url(hlp[0]); 149 QByteArray format = hlp[1].toAscii(); 150 QByteArray latitude = hlp[2].toAscii(); 151 QByteArray longitude = hlp[3].toAscii(); 152 QByteArray nmea = hlp[4].toAscii(); 153 154 bncGetThread* getThread = new bncGetThread(url, format, latitude, longitude, nmea, iMount); 155 156 app.connect(getThread, SIGNAL(newMessage(QByteArray)), 157 &app, SLOT(slotMessage(const QByteArray))); 158 159 caster->addGetThread(getThread); 160 161 getThread->start(); 162 } 163 if (caster->numStations() == 0) { 164 return 0; 165 } 160 166 } 161 167 }
Note:
See TracChangeset
for help on using the changeset viewer.