Changeset 7180 in ntrip for trunk/BNC/src/bncgetthread.cpp


Ignore:
Timestamp:
Aug 14, 2015, 10:57:56 AM (9 years ago)
Author:
stuerze
Message:

NMEA TCP port functionlity removed into bncgetthread class in order to have it available for each PPP station

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/bncgetthread.cpp

    r7153 r7180  
    128128  _decoder   = 0;
    129129
     130  // NMEA Port
     131  // -----------
     132  QListIterator<QString> iSta(settings.value("PPP/staTable").toStringList());
     133  int nmeaPort = 0;
     134  while (iSta.hasNext()) {
     135    QStringList hlp = iSta.next().split(",");
     136    if (hlp.size() < 10) {continue;}
     137    QByteArray mp = hlp[0].toAscii();
     138    if (_staID == mp) {
     139      nmeaPort = hlp[9].toInt();
     140    }
     141  }
     142  if (nmeaPort != 0) {
     143    _nmeaServer = new QTcpServer;
     144    if ( !_nmeaServer->listen(QHostAddress::Any, nmeaPort) ) {
     145      emit newMessage("bncCaster: Cannot listen on port", true);
     146    }
     147    else {
     148      connect(_nmeaServer, SIGNAL(newConnection()), this, SLOT(slotNewNMEAConnection()));
     149      connect(BNC_CORE, SIGNAL(newNMEAstr(QByteArray, QByteArray)),
     150              this, SLOT(slotNewNMEAstr(QByteArray, QByteArray)));
     151      _nmeaSockets = new QList<QTcpSocket*>;
     152      _nmeaPortsMap[_staID] = nmeaPort;
     153    }
     154  } else {
     155    _nmeaServer = 0;
     156    _nmeaSockets = 0;
     157  }
     158
    130159  // Serial Port
    131160  // -----------
     
    371400    delete this;
    372401  }
     402  _nmeaPortsMap.remove(_staID);
     403  delete _nmeaServer;
     404  delete _nmeaSockets;
    373405}
    374406
     
    879911  }
    880912}
     913
     914void bncGetThread::slotNewNMEAConnection() {
     915  _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
     916  emit( newMessage(QString("New PPP client on port: # %1")
     917                   .arg(_nmeaSockets->size()).toAscii(), true) );
     918}
     919
     920//
     921////////////////////////////////////////////////////////////////////////////
     922void bncGetThread::slotNewNMEAstr(QByteArray staID, QByteArray str) {
     923  if (_nmeaPortsMap.contains(staID)) {
     924    int nmeaPort = _nmeaPortsMap.value(staID);
     925    QMutableListIterator<QTcpSocket*> is(*_nmeaSockets);
     926    while (is.hasNext()) {
     927      QTcpSocket* sock = is.next();
     928      if (sock->localPort() == nmeaPort) {
     929        if (sock->state() == QAbstractSocket::ConnectedState) {
     930          sock->write(str);
     931        }
     932        else if (sock->state() != QAbstractSocket::ConnectingState) {
     933          delete sock;
     934          is.remove();
     935        }
     936      }
     937    }
     938  }
     939}
Note: See TracChangeset for help on using the changeset viewer.