[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: bncCaster
|
---|
| 30 | *
|
---|
| 31 | * Purpose: buffers and disseminates the data
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 24-Dec-2005
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[222] | 41 | #include <math.h>
|
---|
[636] | 42 | #include <unistd.h>
|
---|
[222] | 43 |
|
---|
[35] | 44 | #include "bnccaster.h"
|
---|
[2697] | 45 | #include "bncrinex.h"
|
---|
[1170] | 46 | #include "bncapp.h"
|
---|
[35] | 47 | #include "bncgetthread.h"
|
---|
[134] | 48 | #include "bncutils.h"
|
---|
[1535] | 49 | #include "bncsettings.h"
|
---|
[207] | 50 | #include "RTCM/GPSDecoder.h"
|
---|
[35] | 51 |
|
---|
| 52 | // Constructor
|
---|
| 53 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 54 | bncCaster::bncCaster(const QString& outFileName, int port) {
|
---|
| 55 |
|
---|
[1535] | 56 | bncSettings settings;
|
---|
[275] | 57 |
|
---|
[1299] | 58 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 59 | (bncApp*) qApp, SLOT(slotMessage(const QByteArray,bool)));
|
---|
[1228] | 60 |
|
---|
[35] | 61 | if ( !outFileName.isEmpty() ) {
|
---|
[134] | 62 | QString lName = outFileName;
|
---|
| 63 | expandEnvVar(lName);
|
---|
| 64 | _outFile = new QFile(lName);
|
---|
[275] | 65 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 66 | _outFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 67 | }
|
---|
| 68 | else {
|
---|
| 69 | _outFile->open(QIODevice::WriteOnly);
|
---|
| 70 | }
|
---|
[35] | 71 | _out = new QTextStream(_outFile);
|
---|
| 72 | _out->setRealNumberNotation(QTextStream::FixedNotation);
|
---|
| 73 | }
|
---|
| 74 | else {
|
---|
| 75 | _outFile = 0;
|
---|
| 76 | _out = 0;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | _port = port;
|
---|
| 80 |
|
---|
| 81 | if (_port != 0) {
|
---|
| 82 | _server = new QTcpServer;
|
---|
[1228] | 83 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
---|
[1450] | 84 | emit newMessage("bncCaster: Cannot listen on sync port", true);
|
---|
[1228] | 85 | }
|
---|
[35] | 86 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
---|
| 87 | _sockets = new QList<QTcpSocket*>;
|
---|
| 88 | }
|
---|
| 89 | else {
|
---|
| 90 | _server = 0;
|
---|
| 91 | _sockets = 0;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[1222] | 94 | int uPort = settings.value("outUPort").toInt();
|
---|
| 95 | if (uPort != 0) {
|
---|
| 96 | _uServer = new QTcpServer;
|
---|
[1228] | 97 | if ( !_uServer->listen(QHostAddress::Any, uPort) ) {
|
---|
[1450] | 98 | emit newMessage("bncCaster: Cannot listen on usync port", true);
|
---|
[1228] | 99 | }
|
---|
[1222] | 100 | connect(_uServer, SIGNAL(newConnection()), this, SLOT(slotNewUConnection()));
|
---|
| 101 | _uSockets = new QList<QTcpSocket*>;
|
---|
| 102 | }
|
---|
| 103 | else {
|
---|
| 104 | _uServer = 0;
|
---|
| 105 | _uSockets = 0;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[2183] | 108 | int nmeaPort = settings.value("nmeaPort").toInt();
|
---|
| 109 | if (nmeaPort != 0) {
|
---|
| 110 | _nmeaServer = new QTcpServer;
|
---|
| 111 | if ( !_nmeaServer->listen(QHostAddress::Any, nmeaPort) ) {
|
---|
| 112 | emit newMessage("bncCaster: Cannot listen on port", true);
|
---|
| 113 | }
|
---|
| 114 | connect(_nmeaServer, SIGNAL(newConnection()), this, SLOT(slotNewNMEAConnection()));
|
---|
| 115 | _nmeaSockets = new QList<QTcpSocket*>;
|
---|
| 116 | }
|
---|
| 117 | else {
|
---|
| 118 | _nmeaServer = 0;
|
---|
| 119 | _nmeaSockets = 0;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[2711] | 122 | _epochs = new QMultiMap<long, t_obs>;
|
---|
[35] | 123 |
|
---|
[2316] | 124 | _lastDumpSec = 0;
|
---|
[133] | 125 |
|
---|
[1705] | 126 | _confInterval = -1;
|
---|
[35] | 127 | }
|
---|
| 128 |
|
---|
| 129 | // Destructor
|
---|
| 130 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 131 | bncCaster::~bncCaster() {
|
---|
[2647] | 132 |
|
---|
| 133 | QMutexLocker locker(&_mutex);
|
---|
| 134 |
|
---|
[186] | 135 | QListIterator<bncGetThread*> it(_threads);
|
---|
| 136 | while(it.hasNext()){
|
---|
| 137 | bncGetThread* thread = it.next();
|
---|
[1525] | 138 | thread->terminate();
|
---|
[186] | 139 | }
|
---|
[35] | 140 | delete _out;
|
---|
| 141 | delete _outFile;
|
---|
[187] | 142 | delete _server;
|
---|
[631] | 143 | delete _sockets;
|
---|
[1222] | 144 | delete _uServer;
|
---|
| 145 | delete _uSockets;
|
---|
[2186] | 146 | delete _nmeaServer;
|
---|
| 147 | delete _nmeaSockets;
|
---|
[2711] | 148 | delete _epochs;
|
---|
[35] | 149 | }
|
---|
| 150 |
|
---|
| 151 | // New Observations
|
---|
| 152 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2711] | 153 | void bncCaster::newObs(const QByteArray staID, bool firstObs, t_obs obs) {
|
---|
[35] | 154 |
|
---|
[243] | 155 | QMutexLocker locker(&_mutex);
|
---|
| 156 |
|
---|
[2711] | 157 | long iSec = long(floor(obs.GPSWeeks+0.5));
|
---|
| 158 | long newTime = obs.GPSWeek * 7*24*3600 + iSec;
|
---|
[624] | 159 |
|
---|
[160] | 160 | // Rename the Station
|
---|
| 161 | // ------------------
|
---|
[2711] | 162 | strncpy(obs.StatID, staID.constData(),sizeof(obs.StatID));
|
---|
| 163 | obs.StatID[sizeof(obs.StatID)-1] = '\0';
|
---|
| 164 |
|
---|
[1222] | 165 | const char begObs[] = "BEGOBS";
|
---|
| 166 | const int begObsNBytes = sizeof(begObs) - 1;
|
---|
| 167 |
|
---|
| 168 | // Output into the socket
|
---|
| 169 | // ----------------------
|
---|
| 170 | if (_uSockets) {
|
---|
| 171 | QMutableListIterator<QTcpSocket*> is(*_uSockets);
|
---|
| 172 | while (is.hasNext()) {
|
---|
| 173 | QTcpSocket* sock = is.next();
|
---|
| 174 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 175 | bool ok = true;
|
---|
| 176 | if (myWrite(sock, begObs, begObsNBytes) != begObsNBytes) {
|
---|
| 177 | ok = false;
|
---|
| 178 | }
|
---|
[2829] | 179 | int numBytes = sizeof(obs);
|
---|
| 180 | if (myWrite(sock, (const char*)(&obs), numBytes) != numBytes) {
|
---|
| 181 | ok = false;
|
---|
[1222] | 182 | }
|
---|
| 183 | if (!ok) {
|
---|
| 184 | delete sock;
|
---|
| 185 | is.remove();
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 189 | delete sock;
|
---|
| 190 | is.remove();
|
---|
| 191 | }
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[35] | 195 | // First time, set the _lastDumpSec immediately
|
---|
| 196 | // --------------------------------------------
|
---|
[2316] | 197 | if (_lastDumpSec == 0) {
|
---|
| 198 | _lastDumpSec = newTime - 1;
|
---|
[35] | 199 | }
|
---|
| 200 |
|
---|
| 201 | // An old observation - throw it away
|
---|
| 202 | // ----------------------------------
|
---|
[2316] | 203 | if (newTime <= _lastDumpSec) {
|
---|
[257] | 204 | if (firstObs) {
|
---|
[1535] | 205 | bncSettings settings;
|
---|
[257] | 206 | if ( !settings.value("outFile").toString().isEmpty() ||
|
---|
| 207 | !settings.value("outPort").toString().isEmpty() ) {
|
---|
[1810] | 208 |
|
---|
[2316] | 209 | QTime enomtime = QTime(0,0,0).addSecs(iSec);
|
---|
[1810] | 210 |
|
---|
| 211 | emit( newMessage(QString("%1: Old epoch %2 (%3) thrown away")
|
---|
[2316] | 212 | .arg(staID.data()).arg(iSec)
|
---|
[1810] | 213 | .arg(enomtime.toString("HH:mm:ss"))
|
---|
| 214 | .toAscii(), true) );
|
---|
[257] | 215 | }
|
---|
[181] | 216 | }
|
---|
[350] | 217 | return;
|
---|
[35] | 218 | }
|
---|
| 219 |
|
---|
[160] | 220 | // Save the observation
|
---|
| 221 | // --------------------
|
---|
[2316] | 222 | _epochs->insert(newTime, obs);
|
---|
[393] | 223 |
|
---|
[462] | 224 | // Dump Epochs
|
---|
| 225 | // -----------
|
---|
[2316] | 226 | if (newTime - _waitTime > _lastDumpSec) {
|
---|
| 227 | dumpEpochs(_lastDumpSec + 1, newTime - _waitTime);
|
---|
| 228 | _lastDumpSec = newTime - _waitTime;
|
---|
[252] | 229 | }
|
---|
[35] | 230 | }
|
---|
| 231 |
|
---|
| 232 | // New Connection
|
---|
| 233 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 234 | void bncCaster::slotNewConnection() {
|
---|
| 235 | _sockets->push_back( _server->nextPendingConnection() );
|
---|
[1450] | 236 | emit( newMessage(QString("New client connection on sync port: # %1")
|
---|
[1299] | 237 | .arg(_sockets->size()).toAscii(), true) );
|
---|
[35] | 238 | }
|
---|
| 239 |
|
---|
[1222] | 240 | void bncCaster::slotNewUConnection() {
|
---|
| 241 | _uSockets->push_back( _uServer->nextPendingConnection() );
|
---|
[1450] | 242 | emit( newMessage(QString("New client connection on usync port: # %1")
|
---|
[1299] | 243 | .arg(_uSockets->size()).toAscii(), true) );
|
---|
[1222] | 244 | }
|
---|
| 245 |
|
---|
[2183] | 246 | void bncCaster::slotNewNMEAConnection() {
|
---|
| 247 | _nmeaSockets->push_back( _nmeaServer->nextPendingConnection() );
|
---|
| 248 | emit( newMessage(QString("New PPP client on port: # %1")
|
---|
| 249 | .arg(_nmeaSockets->size()).toAscii(), true) );
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[35] | 252 | // Add New Thread
|
---|
| 253 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2528] | 254 | void bncCaster::addGetThread(bncGetThread* getThread, bool noNewThread) {
|
---|
[624] | 255 |
|
---|
[2711] | 256 | qRegisterMetaType<t_obs>("t_obs");
|
---|
[2585] | 257 | qRegisterMetaType<gpsephemeris>("gpsephemeris");
|
---|
| 258 | qRegisterMetaType<glonassephemeris>("glonassephemeris");
|
---|
[624] | 259 |
|
---|
[2711] | 260 | connect(getThread, SIGNAL(newObs(QByteArray, bool, t_obs)),
|
---|
| 261 | this, SLOT(newObs(QByteArray, bool, t_obs)));
|
---|
[463] | 262 |
|
---|
[1556] | 263 | connect(getThread, SIGNAL(getThreadFinished(QByteArray)),
|
---|
| 264 | this, SLOT(slotGetThreadFinished(QByteArray)));
|
---|
[35] | 265 |
|
---|
[2182] | 266 | connect(getThread, SIGNAL(newNMEAstr(QByteArray)),
|
---|
| 267 | this, SLOT(slotNewNMEAstr(QByteArray)));
|
---|
| 268 |
|
---|
[1807] | 269 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
[2585] | 270 | getThread, SLOT(slotNewEphGPS(gpsephemeris)));
|
---|
[1807] | 271 |
|
---|
[88] | 272 | _staIDs.push_back(getThread->staID());
|
---|
[186] | 273 | _threads.push_back(getThread);
|
---|
[1170] | 274 |
|
---|
[2528] | 275 | if (noNewThread) {
|
---|
| 276 | getThread->run();
|
---|
| 277 | }
|
---|
| 278 | else {
|
---|
| 279 | getThread->start();
|
---|
| 280 | }
|
---|
[35] | 281 | }
|
---|
| 282 |
|
---|
[1556] | 283 | // Get Thread destroyed
|
---|
[35] | 284 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1556] | 285 | void bncCaster::slotGetThreadFinished(QByteArray staID) {
|
---|
[243] | 286 | QMutexLocker locker(&_mutex);
|
---|
[1560] | 287 |
|
---|
| 288 | QListIterator<bncGetThread*> it(_threads);
|
---|
| 289 | while (it.hasNext()) {
|
---|
| 290 | bncGetThread* thread = it.next();
|
---|
| 291 | if (thread->staID() == staID) {
|
---|
| 292 | _threads.removeOne(thread);
|
---|
| 293 | }
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[88] | 296 | _staIDs.removeAll(staID);
|
---|
[82] | 297 | emit( newMessage(
|
---|
[1986] | 298 | QString("Decoding %1 stream(s)").arg(_staIDs.size()).toAscii(), true) );
|
---|
[88] | 299 | if (_staIDs.size() == 0) {
|
---|
[1450] | 300 | emit(newMessage("bncCaster: Last get thread terminated", true));
|
---|
[1556] | 301 | emit getThreadsFinished();
|
---|
[35] | 302 | }
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | // Dump Complete Epochs
|
---|
| 306 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2316] | 307 | void bncCaster::dumpEpochs(long minTime, long maxTime) {
|
---|
[35] | 308 |
|
---|
[1182] | 309 | const char begEpoch[] = "BEGEPOCH";
|
---|
| 310 | const char endEpoch[] = "ENDEPOCH";
|
---|
[35] | 311 |
|
---|
[1182] | 312 | const int begEpochNBytes = sizeof(begEpoch) - 1;
|
---|
| 313 | const int endEpochNBytes = sizeof(endEpoch) - 1;
|
---|
| 314 |
|
---|
[2316] | 315 | for (long sec = minTime; sec <= maxTime; sec++) {
|
---|
[140] | 316 |
|
---|
[35] | 317 | bool first = true;
|
---|
[2711] | 318 | QList<t_obs> allObs = _epochs->values(sec);
|
---|
[1999] | 319 |
|
---|
[2711] | 320 | QListIterator<t_obs> it(allObs);
|
---|
[35] | 321 | while (it.hasNext()) {
|
---|
[2711] | 322 | const t_obs& obs = it.next();
|
---|
[35] | 323 |
|
---|
[2316] | 324 | if (_samplingRate == 0 || sec % _samplingRate == 0) {
|
---|
[1810] | 325 |
|
---|
| 326 | if (first) {
|
---|
[2711] | 327 | QTime enomtime = QTime(0,0,0).addSecs(static_cast<int>(floor(obs.GPSWeeks+0.5)));
|
---|
[1821] | 328 | // emit( newMessage( QString("Epoch %1 dumped").arg(enomtime.toString("HH:mm:ss")).toAscii(), true) ); // weber
|
---|
[1810] | 329 | }
|
---|
[140] | 330 | // Output into the file
|
---|
| 331 | // --------------------
|
---|
| 332 | if (_out) {
|
---|
[35] | 333 | if (first) {
|
---|
[1810] | 334 | _out->setFieldWidth(1); *_out << begEpoch << endl;
|
---|
[35] | 335 | }
|
---|
[2697] | 336 |
|
---|
[2711] | 337 | *_out << obs.StatID << " " << obs.GPSWeek << " ";
|
---|
[2697] | 338 | _out->setRealNumberPrecision(7);
|
---|
[2711] | 339 | *_out << obs.GPSWeeks << " ";
|
---|
[2697] | 340 |
|
---|
[2709] | 341 | *_out << bncRinex::rinexSatLine(obs, ' ', ' ', ' ').c_str()
|
---|
[2697] | 342 | << endl;
|
---|
| 343 |
|
---|
[35] | 344 | if (!it.hasNext()) {
|
---|
[341] | 345 | _out->setFieldWidth(1); *_out << endEpoch << endl;
|
---|
[35] | 346 | }
|
---|
[347] | 347 | _out->flush();
|
---|
[35] | 348 | }
|
---|
[140] | 349 |
|
---|
| 350 | // Output into the socket
|
---|
| 351 | // ----------------------
|
---|
| 352 | if (_sockets) {
|
---|
[637] | 353 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
---|
[140] | 354 | while (is.hasNext()) {
|
---|
| 355 | QTcpSocket* sock = is.next();
|
---|
[397] | 356 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
[637] | 357 | bool ok = true;
|
---|
[397] | 358 | if (first) {
|
---|
[1182] | 359 | if (myWrite(sock, begEpoch, begEpochNBytes) != begEpochNBytes) {
|
---|
[637] | 360 | ok = false;
|
---|
| 361 | }
|
---|
[397] | 362 | }
|
---|
[2829] | 363 | int numBytes = sizeof(obs);
|
---|
| 364 | if (myWrite(sock, (const char*)(&obs), numBytes) != numBytes) {
|
---|
| 365 | ok = false;
|
---|
[637] | 366 | }
|
---|
[397] | 367 | if (!it.hasNext()) {
|
---|
[1182] | 368 | if (myWrite(sock, endEpoch, endEpochNBytes) != endEpochNBytes) {
|
---|
[637] | 369 | ok = false;
|
---|
| 370 | }
|
---|
[397] | 371 | }
|
---|
[637] | 372 | if (!ok) {
|
---|
| 373 | delete sock;
|
---|
| 374 | is.remove();
|
---|
| 375 | }
|
---|
[140] | 376 | }
|
---|
[637] | 377 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 378 | delete sock;
|
---|
| 379 | is.remove();
|
---|
| 380 | }
|
---|
[140] | 381 | }
|
---|
| 382 | }
|
---|
[73] | 383 | }
|
---|
| 384 |
|
---|
[2316] | 385 | _epochs->remove(sec);
|
---|
[35] | 386 | first = false;
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
[1170] | 390 |
|
---|
| 391 | // Reread configuration
|
---|
| 392 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1179] | 393 | void bncCaster::slotReadMountPoints() {
|
---|
[1170] | 394 |
|
---|
[1535] | 395 | bncSettings settings;
|
---|
[1170] | 396 |
|
---|
| 397 | // Reread several options
|
---|
| 398 | // ----------------------
|
---|
[2316] | 399 | _samplingRate = settings.value("binSampl").toInt();
|
---|
| 400 | _waitTime = settings.value("waitTime").toInt();
|
---|
| 401 | if (_waitTime < 1) {
|
---|
| 402 | _waitTime = 1;
|
---|
[1170] | 403 | }
|
---|
| 404 |
|
---|
| 405 | // Add new mountpoints
|
---|
| 406 | // -------------------
|
---|
| 407 | int iMount = -1;
|
---|
| 408 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 409 | while (it.hasNext()) {
|
---|
| 410 | ++iMount;
|
---|
| 411 | QStringList hlp = it.next().split(" ");
|
---|
| 412 | if (hlp.size() <= 1) continue;
|
---|
| 413 | QUrl url(hlp[0]);
|
---|
| 414 |
|
---|
| 415 | // Does it already exist?
|
---|
| 416 | // ----------------------
|
---|
| 417 | bool existFlg = false;
|
---|
| 418 | QListIterator<bncGetThread*> iTh(_threads);
|
---|
| 419 | while (iTh.hasNext()) {
|
---|
| 420 | bncGetThread* thread = iTh.next();
|
---|
| 421 | if (thread->mountPoint() == url) {
|
---|
| 422 | existFlg = true;
|
---|
| 423 | break;
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | // New bncGetThread
|
---|
| 428 | // ----------------
|
---|
| 429 | if (!existFlg) {
|
---|
| 430 | QByteArray format = hlp[1].toAscii();
|
---|
| 431 | QByteArray latitude = hlp[2].toAscii();
|
---|
| 432 | QByteArray longitude = hlp[3].toAscii();
|
---|
| 433 | QByteArray nmea = hlp[4].toAscii();
|
---|
[1353] | 434 | QByteArray ntripVersion = hlp[5].toAscii();
|
---|
[1170] | 435 |
|
---|
| 436 | bncGetThread* getThread = new bncGetThread(url, format, latitude,
|
---|
[1770] | 437 | longitude, nmea, ntripVersion, "");
|
---|
[1170] | 438 | addGetThread(getThread);
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | // Remove mountpoints
|
---|
| 443 | // ------------------
|
---|
| 444 | QListIterator<bncGetThread*> iTh(_threads);
|
---|
| 445 | while (iTh.hasNext()) {
|
---|
| 446 | bncGetThread* thread = iTh.next();
|
---|
| 447 |
|
---|
| 448 | bool existFlg = false;
|
---|
| 449 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 450 | while (it.hasNext()) {
|
---|
| 451 | QStringList hlp = it.next().split(" ");
|
---|
| 452 | if (hlp.size() <= 1) continue;
|
---|
| 453 | QUrl url(hlp[0]);
|
---|
| 454 |
|
---|
| 455 | if (thread->mountPoint() == url) {
|
---|
| 456 | existFlg = true;
|
---|
| 457 | break;
|
---|
| 458 | }
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | if (!existFlg) {
|
---|
| 462 | disconnect(thread, 0, 0, 0);
|
---|
| 463 | _staIDs.removeAll(thread->staID());
|
---|
| 464 | _threads.removeAll(thread);
|
---|
| 465 | thread->terminate();
|
---|
| 466 | }
|
---|
| 467 | }
|
---|
| 468 |
|
---|
[1179] | 469 | emit mountPointsRead(_threads);
|
---|
[1529] | 470 | emit( newMessage(QString("Configuration read: "
|
---|
[1542] | 471 | + ((bncApp*) qApp)->confFileName()
|
---|
[1529] | 472 | + ", %1 stream(s)")
|
---|
[1299] | 473 | .arg(_threads.count()).toAscii(), true) );
|
---|
[1176] | 474 |
|
---|
[1170] | 475 | // (Re-) Start the configuration timer
|
---|
| 476 | // -----------------------------------
|
---|
| 477 | int ms = 0;
|
---|
| 478 |
|
---|
[1705] | 479 | if (_confInterval != -1) {
|
---|
[1170] | 480 | ms = 1000 * _confInterval;
|
---|
| 481 | }
|
---|
| 482 | else {
|
---|
| 483 | QTime currTime = currentDateAndTimeGPS().time();
|
---|
| 484 | QTime nextShotTime;
|
---|
| 485 |
|
---|
| 486 | if (settings.value("onTheFlyInterval").toString() == "1 min") {
|
---|
| 487 | _confInterval = 60;
|
---|
| 488 | nextShotTime = QTime(currTime.hour(), currTime.minute()+1, 0);
|
---|
| 489 | }
|
---|
| 490 | else if (settings.value("onTheFlyInterval").toString() == "1 hour") {
|
---|
| 491 | _confInterval = 3600;
|
---|
| 492 | nextShotTime = QTime(currTime.hour()+1, 0, 0);
|
---|
| 493 | }
|
---|
| 494 | else {
|
---|
| 495 | _confInterval = 86400;
|
---|
| 496 | nextShotTime = QTime(23, 59, 59, 999);
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | ms = currTime.msecsTo(nextShotTime);
|
---|
[1176] | 500 | if (ms < 30000) {
|
---|
| 501 | ms = 30000;
|
---|
| 502 | }
|
---|
[1170] | 503 | }
|
---|
| 504 |
|
---|
[1705] | 505 | QTimer::singleShot(ms, this, SLOT(slotReadMountPoints()));
|
---|
[1170] | 506 | }
|
---|
[1182] | 507 |
|
---|
| 508 | //
|
---|
| 509 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 510 | int bncCaster::myWrite(QTcpSocket* sock, const char* buf, int bufLen) {
|
---|
[1229] | 511 | sock->write(buf, bufLen);
|
---|
| 512 | for (int ii = 1; ii <= 10; ii++) {
|
---|
| 513 | if (sock->waitForBytesWritten(10)) { // wait 10 ms
|
---|
| 514 | return bufLen;
|
---|
[1182] | 515 | }
|
---|
| 516 | }
|
---|
[1229] | 517 | return -1;
|
---|
[1182] | 518 | }
|
---|
[2182] | 519 |
|
---|
| 520 | //
|
---|
| 521 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 522 | void bncCaster::slotNewNMEAstr(QByteArray str) {
|
---|
[2184] | 523 | if (_nmeaSockets) {
|
---|
| 524 | QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
|
---|
| 525 | while (is.hasNext()) {
|
---|
| 526 | QTcpSocket* sock = is.next();
|
---|
| 527 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 528 | sock->write(str);
|
---|
| 529 | }
|
---|
| 530 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 531 | delete sock;
|
---|
| 532 | is.remove();
|
---|
| 533 | }
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
[2182] | 536 | }
|
---|