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


Ignore:
Timestamp:
Nov 9, 2026, 12:15:48 PM (6 hours ago)
Author:
stuerze
Message:

Structured logging improved

File:
1 edited

Legend:

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

    r11179 r11185  
    129129  setTerminationEnabled(true);
    130130
    131   connect(this, SIGNAL(newMessage(QByteArray,bool)),
    132   BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
    133   connect(this, SIGNAL(newLogRecord(t_logRecord,bool)),
    134   BNC_CORE, SLOT(slotLogRecord(t_logRecord,bool)));
    135   t_logRecord::registerStation(_staID);
     131  BNC_CORE->connectMessages(this, "stream");
     132  BNC_CORE->connectLogRecords(this, "stream");
     133  t_logRecord::registerStream(_staID);
    136134
    137135  _isToBeDeleted = false;
    … …  
    162160                      + QByteArray::number(nmeaPort) + ": "
    163161                      + _nmeaServer->errorString();
    164       emit newMessage(message.toLatin1(), true);
     162      emit newLogRecord(t_logRecord::message(t_logRecord::error, message.toLatin1()), true);
    165163    }
    166164    else {
    … …  
    264262    msleep(100); //sleep 0.1 sec
    265263    if (!_serialPort->isOpen()) {
    266       emit(newMessage(_staID + ": Cannot open serial port " + portString.toLatin1()
    267            + ": " + _serialPort->errorString().toLatin1(), true));
     264      emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + ": Cannot open serial port " + portString.toLatin1()
     265           + ": " + _serialPort->errorString().toLatin1()), true);
    268266      delete _serialPort;
    269267      _serialPort = 0;
    270268    }
    271269    else {
    272       emit(newMessage(_staID + ": Serial port " + portString.toLatin1()
    273            + "is connected: " + _serialPort->errorString().toLatin1(), true));
     270      emit newLogRecord(t_logRecord::message(t_logRecord::info, _staID + ": Serial port " + portString.toLatin1()
     271           + "is connected: " + _serialPort->errorString().toLatin1()), true);
    274272      connect(_serialPort, SIGNAL(readyRead()), this, SLOT(slotSerialReadyRead()));
    275273    }
    … …  
    343341    connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)),
    344342        this, SIGNAL(newMessage(QByteArray,bool)));
     343    connect((RTCM3Decoder*) newDecoder, SIGNAL(newLogRecord(t_logRecord,bool)),
     344        this, SIGNAL(newLogRecord(t_logRecord,bool)));
    345345  } else if (_format == "ZERO") {
    346346    emitFormat(": Forward data in original format", "ZERO");
    … …  
    355355    _decoder = new bncRtnetDecoder();
    356356  } else {
    357     emit(newMessage(_staID + ": Unknown data format " + _format + ". Please change the format entry to ZERO or ZERO2FILE to forward unchanged data.", true));
     357    emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + ": Unknown data format " + _format + ". Please change the format entry to ZERO or ZERO2FILE to forward unchanged data."), true);
    358358    _isToBeDeleted = true;
    359359    return failure;
    … …  
    449449    try {
    450450      if (_isToBeDeleted) {
    451         emit(newMessage(_staID + ": is to be deleted", true));
     451        emit newLogRecord(t_logRecord::message(t_logRecord::info, _staID + ": is to be deleted"), true);
    452452        QThread::exit(4);
    453453        this->deleteLater();
    … …  
    484484        _format = _rawFile->format();
    485485        _staID = _rawFile->staID();
    486         t_logRecord::registerStation(_staID);
     486        t_logRecord::registerStream(_staID);
    487487
    488488        QCoreApplication::processEvents();
    489489
    490490        if (data.isEmpty() || BNC_CORE->sigintReceived) {
    491           emit(newMessage("No more data or SIGINT/SIGTERM received", true));
     491          emit newLogRecord(t_logRecord::message(t_logRecord::info, "No more data or SIGINT/SIGTERM received"), true);
    492492          // pass on data the decoders still hold back (last epoch)
    493493          QMapIterator<QString, GPSDecoder*> itFlush(_decodersRaw);
    … …  
    652652            QString prn(obs._prn.toString().c_str());
    653653            QString type = QString("%1").arg(obs._type);
    654             emit(newMessage(_staID + " (" + prn.toLatin1() + ")" + ": Wrong observation epoch(s)" + "( MT: " + type.toLatin1() + ")", false));
     654            emit newLogRecord(t_logRecord::message(t_logRecord::warning, _staID + " (" + prn.toLatin1() + ")" + ": Wrong observation epoch(s)" + "( MT: " + type.toLatin1() + ")"), false);
    655655            continue;
    656656          }
    … …  
    666666            bncTime oldTime = it.value();
    667667            if (obsTime < oldTime) {
    668               emit(newMessage(_staID + ": old observation " + prn.toLatin1(), false));
     668              emit newLogRecord(t_logRecord::message(t_logRecord::warning, _staID + ": old observation " + prn.toLatin1()), false);
    669669              continue;
    670670            } else if (obsTime == oldTime) {
    671               emit(newMessage(_staID + ": observation coming more than once " + prn.toLatin1(), false));
     671              emit newLogRecord(t_logRecord::message(t_logRecord::warning, _staID + ": observation coming more than once " + prn.toLatin1()), false);
    672672              continue;
    673673            }
    … …  
    691691    }
    692692    catch (Exception& exc) {
    693       emit(newMessage(_staID + " " + exc.what(), true));
     693      emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + " " + exc.what()), true);
    694694      _isToBeDeleted = true;
    695695    }
    696696    catch (std::exception& exc) {
    697       emit(newMessage(_staID + " " + exc.what(), true));
     697      emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + " " + exc.what()), true);
    698698      _isToBeDeleted = true;
    699699    }
    700700    catch (const string& error) {
    701       emit(newMessage(_staID + " ERROR: " + error.c_str(), true));
     701      emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + " ERROR: " + error.c_str()), true);
    702702      _isToBeDeleted = true;
    703703    }
    704704    catch (const char* error) {
    705       emit(newMessage(_staID + " ERROR: " + error, true));
     705      emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + " ERROR: " + error), true);
    706706      _isToBeDeleted = true;
    707707    }
    708708    catch (QString error) {
    709       emit(newMessage(_staID + " ERROR: " + error.toStdString().c_str(), true));
     709      emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + " ERROR: " + error.toStdString().c_str()), true);
    710710      _isToBeDeleted = true;
    711711    }
    712712    catch (...) {
    713       emit(newMessage(_staID + " bncGetThread: unknown exception", true));
     713      emit newLogRecord(t_logRecord::message(t_logRecord::error, _staID + " bncGetThread: unknown exception"), true);
    714714      _isToBeDeleted = true;
    715715    }
    … …  
    838838        QString type = QString("%1 ").arg(decoder()->_typeList[ii]._type);
    839839        QString size = (decoder()->_typeList[ii]._size) ? QString("(size %1)").arg(decoder()->_typeList[ii]._size) : "";
    840         emit(newMessage(_staID + ": Received message type " + type.toLatin1() +  size.toLatin1(), true));
     840        t_logRecord rec(t_logRecord::info, "stream", "stream_content", _staID,
     841                        _staID + ": Received message type " + type.toLatin1() +  size.toLatin1());
     842        rec.add("message_type", int(decoder()->_typeList[ii]._type));
     843        if (decoder()->_typeList[ii]._size) {
     844          rec.add("size", int(decoder()->_typeList[ii]._size));
     845        }
     846        emit newLogRecord(rec, true);
    841847      }
    842848
    … …  
    908914            str << " " << rnxTypes[iType];
    909915          }
    910           emit(newMessage(_staID + ": Observation Types: " + msg.toLatin1(),  true));
     916          emitContent(_staID + ": Observation Types: " + msg.toLatin1(),  true);
    911917        }
    912918      }
    … …  
    916922      for (int ii = 0; ii < decoder()->_antType.size(); ii++) {
    917923        QString ant1 = QString(": Antenna Descriptor: %1 ").arg(decoder()->_antType[ii]._descriptor);
    918         emit(newMessage(_staID + ant1.toLatin1(), true));
     924        emitContent(_staID + ant1.toLatin1(), true);
    919925        if (strlen(decoder()->_antType[ii]._serialnumber)) {
    920926          QString ant2 = QString(": Antenna Serial Number: %1 ").arg(decoder()->_antType[ii]._serialnumber);
    921           emit(newMessage(_staID + ant2.toLatin1(), true));
     927          emitContent(_staID + ant2.toLatin1(), true);
    922928        }
    923929      }
    … …  
    936942        ant2 = QString("%1 ").arg(decoder()->_antList[ii]._yy, 0, 'f', 4).toLatin1();
    937943        ant3 = QString("%1 ").arg(decoder()->_antList[ii]._zz, 0, 'f', 4).toLatin1();
    938         emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
    939         emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
    940         emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
     944        emitContent(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true);
     945        emitContent(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true);
     946        emitContent(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true);
    941947        double hh = 0.0;
    942948        if (decoder()->_antList[ii]._height_f) {
    943949          hh = decoder()->_antList[ii]._height;
    944950          QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toLatin1();
    945           emit(newMessage(
    946               _staID + ": Antenna height above marker " + ant4 + "m", true));
     951          emitContent(
     952              _staID + ": Antenna height above marker " + ant4 + "m", true);
    947953        }
    948954        emit(newAntCrd(_staID, decoder()->_antList[ii]._xx,
    … …  
    956962        QString rec2 = QString(": Receiver Firmware Version: %1 ").arg(decoder()->_recType[ii]._firmware);
    957963        QString rec3 = QString(": Receiver Serial Number: %1 ").arg(decoder()->_recType[ii]._serialnumber);
    958         emit(newMessage(_staID + rec1.toLatin1(), true));
    959         emit(newMessage(_staID + rec2.toLatin1(), true));
    960         emit(newMessage(_staID + rec3.toLatin1(), true));
     964        emitContent(_staID + rec1.toLatin1(), true);
     965        emitContent(_staID + rec2.toLatin1(), true);
     966        emitContent(_staID + rec3.toLatin1(), true);
    961967      }
    962968
    … …  
    973979        if (!allFound) {
    974980          _gloSlots.sort();
    975           emit(newMessage(
     981          emitContent(
    976982              _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toLatin1(),
    977               true));
     983              true);
    978984        }
    979985      }
    … …  
    983989      if (decoder()->_gloBiasInfo.changed()) {
    984990        QString gloCodePhaseBiases = decoder()->_gloBiasInfo.toString();
    985         emit(newMessage(_staID + gloCodePhaseBiases.toLatin1(), true));
     991        emitContent(_staID + gloCodePhaseBiases.toLatin1(), true);
    986992        decoder()->_gloBiasInfo.setChanged(false);
    987993      }
    … …  
    9951001          QString coordinateEpoch = QString(": Service CRS Coordinate Epoch: %1 ").arg(decoder()->_serviceCrs[ii]._coordinateEpoch);
    9961002          //QString ce = QString(": CE: %1 ").arg(decoder()->_serviceCrs[ii]._CE);
    997           emit(newMessage(_staID + servicecrsname.toLatin1(), true));
    998           emit(newMessage(_staID + coordinateEpoch.toLatin1(), true));
    999           //emit(newMessage(_staID + ce.toLatin1(), true));
     1003          emitContent(_staID + servicecrsname.toLatin1(), true);
     1004          emitContent(_staID + coordinateEpoch.toLatin1(), true);
     1005          //emitContent(_staID + ce.toLatin1(), true);
    10001006        }
    10011007        // RTCM CRS
    … …  
    10041010          QString anchor      = QString(": RTCM CRS Anchor: %1 ").arg(decoder()->_rtcmCrs[ii]._anchor);
    10051011          QString platenumber = QString(": RTCM CRS Plate Number: %1 ").arg(decoder()->_rtcmCrs[ii]._plateNumber);
    1006           emit(newMessage(_staID + rtcmcrsname.toLatin1(), true));
    1007           emit(newMessage(_staID + anchor.toLatin1(), true));
    1008           emit(newMessage(_staID + platenumber.toLatin1(), true));
     1012          emitContent(_staID + rtcmcrsname.toLatin1(), true);
     1013          emitContent(_staID + anchor.toLatin1(), true);
     1014          emitContent(_staID + platenumber.toLatin1(), true);
    10091015          for (int i = 0; i<decoder()->_rtcmCrs[ii]._databaseLinks.size(); i++) {
    10101016            QString dblink = QString(": Database Link: %1 ").arg(decoder()->_rtcmCrs[ii]._databaseLinks[i]);
    1011             emit(newMessage(_staID + dblink.toLatin1(), true));
     1017            emitContent(_staID + dblink.toLatin1(), true);
    10121018          }
    10131019        }
    … …  
    10301036              .arg(helmertPar._oxr).arg(helmertPar._oyr).arg(helmertPar._ozr);
    10311037          QString parscale = QString(": MT1301 Helmert Par Scale: sc = %1, scr = %2").arg(helmertPar._sc).arg(helmertPar._scr);
    1032           emit(newMessage(_staID + sourcename.toLatin1(), true));
    1033           emit(newMessage(_staID + targetname.toLatin1(), true));
    1034           emit(newMessage(_staID + sysidentnum.toLatin1(), true));
    1035           emit(newMessage(_staID + trafomessageind.toLatin1(), true));
    1036           emit(newMessage(_staID + epoch.toLatin1(), true));
    1037           emit(newMessage(_staID + partrans.toLatin1(), true));
    1038           emit(newMessage(_staID + parrot.toLatin1(), true));
    1039           emit(newMessage(_staID + parscale.toLatin1(), true));
     1038          emitContent(_staID + sourcename.toLatin1(), true);
     1039          emitContent(_staID + targetname.toLatin1(), true);
     1040          emitContent(_staID + sysidentnum.toLatin1(), true);
     1041          emitContent(_staID + trafomessageind.toLatin1(), true);
     1042          emitContent(_staID + epoch.toLatin1(), true);
     1043          emitContent(_staID + partrans.toLatin1(), true);
     1044          emitContent(_staID + parrot.toLatin1(), true);
     1045          emitContent(_staID + parscale.toLatin1(), true);
    10401046        }
    10411047      }
    … …  
    11241130void bncGetThread::slotNewNMEAConnection() {
    11251131  _nmeaSockets->push_back(_nmeaServer->nextPendingConnection());
    1126   emit(newMessage(
    1127       QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toLatin1(),
    1128       true));
     1132  emit newLogRecord(t_logRecord::message(t_logRecord::info, QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toLatin1()), true);
    11291133}
    11301134
    … …  
    11571161  emit newLogRecord(rec, true);
    11581162}
     1163
     1164// Content of the stream found by the RTCM scan (miscScanRTCM)
     1165////////////////////////////////////////////////////////////////////////////
     1166void bncGetThread::emitContent(const QByteArray& msg, bool showOnScreen) {
     1167  emit newLogRecord(t_logRecord(t_logRecord::info, "stream", "stream_content", _staID, msg),
     1168                    showOnScreen);
     1169}
Note: See TracChangeset for help on using the changeset viewer.