Changeset 11216 in ntrip for trunk/BNC/src


Ignore:
Timestamp:
Nov 20, 2026, 4:14:37 PM (10 days ago)
Author:
stuerze
Message:

Upload Ephemeris: majority vote approach improved

Location:
trunk/BNC/src
Files:
4 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())
  • trunk/BNC/src/bncephuser.h

    r11215 r11216  
    4545  void slotNewBDSEph(t_ephBDS);
    4646
     47 private slots:
     48  void slotVoteTimer();
     49
    4750 public:
    4851  bncEphUser(bool connectSlots, unsigned maxQueueSize = 6);
    … …  
    5356  // Majority vote over the copies of a data set received from different streams
    5457  // (real-time input only, used for the ephemeris upload): the first copy is
    55   // accepted immediately; a copy with different content (RTCM3 encoding without
     58  // buffered immediately; a copy with different content (RTCM3 encoding without
    5659  // the GLONASS frame time tk and the system time offsets tau_c, tau_GPS) replaces it as soon as more streams deliver it
    5760  // than the current one, i.e. with at least three streams.
    58   void enableVoting() {_voting = true;}
     61  // A new data set is held back from the upload (ephUpload() returns the
     62  // previous one) until three streams deliver the same content or VOTE_HOLD
     63  // seconds (GPS time) have passed since its first copy; no hold if fewer than
     64  // three streams delivered the previous data set or there is none. The hold
     65  // is checked with each ephemeris received and in real time every second, so
     66  // that a held data set is also uploaded when no further ephemeris arrives.
     67  void enableVoting();
     68
     69  // data set to be uploaded: the latest one, or the previous one while the
     70  // latest is held back by the vote
     71  t_eph* ephUpload(const QString& prn);
    5972
    6073  // Real-time input restricted to the ephemerides of the streams given in the
    … …  
    110123    QMap<QString, int>   _station;  // stream -> variant of its latest copy
    111124    int                  _current = 0;  // variant in the buffer
     125    bncTime              _first;        // first copy received (GPS time)
     126    bool                 _released = true;  // may be uploaded
    112127  };
     128  static const double VOTE_HOLD;    // maximum hold of a new data set [s]
     129  static const int    VOTE_AGREE;   // streams releasing a new data set
     130  static bncTime currentTime();
     131  void   releaseHeld();
    113132  static t_eph*     clone(const t_eph* eph);
    114133  static QByteArray votingContent(const t_eph* eph);
  • trunk/BNC/src/bnchelp.html

    r11215 r11216  
    1007010070  <p>
    1007110071    If the same data set (same TOC and IOD) is received from several streams, BNC votes on its content: the
    10072     first copy received is uploaded immediately; every further stream counts as a vote for the copy it delivers, and
    10073     a copy with different content replaces the uploaded one as soon as more streams deliver it than the current one,
    10074     i.e. with at least three streams. The content compared is the RTCM Version 3 message as uploaded, for GLONASS
     10072    first copy received is buffered; every further stream counts as a vote for the copy it delivers, and
     10073    a copy with different content replaces the buffered one as soon as more streams deliver it than the current one,
     10074    i.e. with at least three streams. A new data set is uploaded as soon as three streams deliver the same content as
     10075    the buffered copy, at the latest 40 seconds after its first copy; until then the previous data set of the
     10076    satellite stays in the upload; the hold is checked with each ephemeris received and every second. Data sets of satellites whose previous data set came from less than three streams
     10077    (and the first data set of a satellite) are uploaded immediately, as the vote cannot decide there. Receivers and
     10078    applications usually keep the first copy of a data set they received, also BNC itself, so a later replacement
     10079    with the same TOC and IOD would not reach them. The maximum of 40 seconds leaves time for the upload interval and
     10080    the latency before SSR providers may use the new IOD, 60 seconds after its broadcast; three streams agreed in the
     10081    median after 14 seconds and in 87 percent of the data sets within 40 seconds with 89 input streams
     10082    (18 Nov 2026). A replacement after the upload is still possible. The content compared is the RTCM Version 3 message as uploaded, for GLONASS
    1007510083    without the frame time tk and the system time offsets tau_c and tau_GPS, which differ legitimately between
    1007610084    receivers. This protects the uploaded stream against single receivers sending e.g. wrong health flags. Each
    … …  
    1008110089ephemeris vote R19 2026-11-18 17:45:18: copy of RIO200ARG0 replaced by that of BRAZ00BRA0 (2 of 3 streams;
    1008210090  - RIO200ARG0, + BRAZ00BRA0 RGDG00ARG0; differing: Cn A Bn P3 NA N4)
     10091</pre>
     10092  <p>
     10093    A data set uploaded after 40 seconds without three agreeing streams is logged as well, e.g.
     10094  </p>
     10095  <pre>
     10096ephemeris vote G14 2026-11-18 20:00:00: copy of OWMG00NZL0 uploaded after 40 s without 3 agreeing streams
     10097  (2 of 4 streams)
    1008310098</pre>
    1008410099  <p>
  • trunk/BNC/src/upload/bncephuploadcaster.cpp

    r11215 r11216  
    2626////////////////////////////////////////////////////////////////////////////
    2727bncEphUploadCaster::bncEphUploadCaster() : bncEphUser(true) {
    28   enableVoting();
    2928  bncSettings settings;
    3029  int sampl = settings.value("uploadSamplRtcmEph").toInt();
    … …  
    4948      _casters.push_back(newCaster);
    5049    }
     50  }
     51
     52  // vote (and hold back new data sets) only for an actual upload
     53  if (!_casters.isEmpty()) {
     54    enableVoting();
    5155  }
    5256}
    … …  
    7882      QListIterator<QString> it(prnList());
    7983      while (it.hasNext()) {
    80         const t_eph* eph = ephLast(it.next());
     84        const t_eph* eph = ephUpload(it.next());
    8185
    8286        bncTime toc = eph->TOC();
Note: See TracChangeset for help on using the changeset viewer.