Changeset 11216 in ntrip for trunk/BNC/src/bncephuser.cpp


Ignore:
Timestamp:
Nov 20, 2026, 4:14:37 PM (less than one hour ago)
Author:
stuerze
Message:

Upload Ephemeris: majority vote approach improved

File:
1 edited

Legend:

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

    r11215 r11216  
    144144  }
    145145
     146  if (_voting && realTime) {
     147    releaseHeld();
     148  }
     149
    146150  // satellite outside the range supported by BNC (e.g. G39)
    147151  if (eph->prn().toInt() == 0) {
    … …  
    196200      votes->_eph.append(clone(newEph));
    197201      votes->_station[newEph->receptStaID()] = 0;
     202      votes->_first = currentTime();
     203      if (qq.size() > 1) {
     204        const t_votes* prev = _votes.value(qq[qq.size()-2], 0);
     205        votes->_released = !(prev && prev->_station.size() >= VOTE_AGREE);
     206      }
    198207      _votes[newEph] = votes;
    199208    }
    … …  
    316325}
    317326
     327// Satellite in the vote messages, for Galileo with the navigation message
     328// (I/NAV and F/NAV data sets are buffered and voted separately)
     329////////////////////////////////////////////////////////////////////////////
     330static QString voteSat(const t_eph* eph) {
     331  QString sat(QString(eph->prn().toInternalString().c_str()).left(3));
     332  if      (eph->type() == t_eph::INAV) sat += " INAV";
     333  else if (eph->type() == t_eph::FNAV) sat += " FNAV";
     334  return sat;
     335}
     336
     337const double bncEphUser::VOTE_HOLD  = 40.0;  // SSR providers switch to a new IOD after 60 s
     338const int    bncEphUser::VOTE_AGREE = 3;
     339
     340// Current GPS time (time of the input data when replaying a file)
     341////////////////////////////////////////////////////////////////////////////
     342bncTime bncEphUser::currentTime() {
     343  return bncTime(currentDateAndTimeGPS().toString(Qt::ISODate).toStdString());
     344}
     345
     346// Release the data sets held back longer than VOTE_HOLD seconds
     347////////////////////////////////////////////////////////////////////////////
     348void bncEphUser::releaseHeld() {
     349  bncTime now = currentTime();
     350  bool changed = false;
     351  QStringList msgs;  // sorted: the QHash order differs between runs
     352  QHashIterator<const t_eph*, t_votes*> it(_votes);
     353  while (it.hasNext()) {
     354    it.next();
     355    t_votes* votes = it.value();
     356    if (!votes->_released && now - votes->_first >= VOTE_HOLD) {
     357      votes->_released = true;
     358      changed = true;
     359      const t_eph* eph = it.key();
     360      QVector<int> count(votes->_content.size(), 0);
     361      QMapIterator<QString, int> is(votes->_station);
     362      while (is.hasNext()) {
     363        is.next();
     364        count[is.value()]++;
     365      }
     366      msgs << QString("ephemeris vote %1 %2 %3: copy of %4 uploaded after %5 s without %6 agreeing streams (%7 of %8 streams)")
     367                        .arg(voteSat(eph))
     368                        .arg(eph->TOC().datestr().c_str())
     369                        .arg(eph->TOC().timestr(0).c_str())
     370                        .arg(eph->receptStaID())
     371                        .arg(int(VOTE_HOLD))
     372                        .arg(VOTE_AGREE)
     373                        .arg(count[votes->_current])
     374                        .arg(votes->_station.size());
     375    }
     376  }
     377  msgs.sort();
     378  for (const QString& msg : msgs) {
     379    BNC_CORE->message(msg.toLatin1(), false, "bce", t_logRecord::info);
     380  }
     381  if (changed) {
     382    ephBufferChanged();
     383  }
     384}
     385
     386// Vote over the copies of a data set, check of the hold every second
     387////////////////////////////////////////////////////////////////////////////
     388void bncEphUser::enableVoting() {
     389  _voting = true;
     390  QTimer* timer = new QTimer(this);
     391  connect(timer, SIGNAL(timeout()), this, SLOT(slotVoteTimer()));
     392  timer->start(1000);
     393}
     394
     395// Release of held data sets without new ephemerides; not when replaying a
     396// file, where the time of the input data decides (reproducible results)
     397////////////////////////////////////////////////////////////////////////////
     398void bncEphUser::slotVoteTimer() {
     399  if (BNC_CORE->dateAndTimeGPSSet()) {
     400    return;
     401  }
     402  QMutexLocker locker(&_mutex);
     403  releaseHeld();
     404}
     405
     406// Data set to be uploaded
     407////////////////////////////////////////////////////////////////////////////
     408t_eph* bncEphUser::ephUpload(const QString& prn) {
     409  if (!_eph.contains(prn)) {
     410    return 0;
     411  }
     412  const deque<t_eph*>& qq = _eph[prn];
     413  const t_votes* votes = _votes.value(qq.back(), 0);
     414  if (votes && !votes->_released && qq.size() > 1) {
     415    return qq[qq.size()-2];
     416  }
     417  return qq.back();
     418}
     419
    318420// Further copy of the buffered data set qq[index] received from a stream
    319421////////////////////////////////////////////////////////////////////////////
    … …  
    345447    }
    346448  }
     449  bool released = false;
     450  if (!votes->_released && count[iBest] >= VOTE_AGREE) {
     451    votes->_released = true;
     452    released = true;
     453  }
    347454  if (iBest == votes->_current) {
     455    if (released) {
     456      ephBufferChanged();
     457    }
    348458    return;
    349459  }
    … …  
    353463  if (!radialDistanceOk(newEph)) {
    354464    delete newEph;
     465    if (released) {
     466      ephBufferChanged();
     467    }
    355468    return;
    356469  }
    … …  
    380493  }
    381494  BNC_CORE->message(QString("ephemeris vote %1 %2 %3: copy of %4 replaced by that of %5 (%6 of %7 streams; %8; differing: %9)")
    382                     .arg(prn.left(3))
     495                    .arg(voteSat(oldEph))
    383496                    .arg(oldEph->TOC().datestr().c_str())
    384497                    .arg(oldEph->TOC().timestr(0).c_str())
Note: See TracChangeset for help on using the changeset viewer.