Index: /trunk/BNC/RTCM/GPSDecoder.h
===================================================================
--- /trunk/BNC/RTCM/GPSDecoder.h	(revision 1034)
+++ /trunk/BNC/RTCM/GPSDecoder.h	(revision 1035)
@@ -103,4 +103,5 @@
   QList<p_obs> _obsList;
   QList<int> _typeList; // RTCM message types
+  QList<int> _epochList; // RTCM message types
 };
 
Index: /trunk/BNC/RTCM3/RTCM3Decoder.cpp
===================================================================
--- /trunk/BNC/RTCM3/RTCM3Decoder.cpp	(revision 1034)
+++ /trunk/BNC/RTCM3/RTCM3Decoder.cpp	(revision 1035)
@@ -47,4 +47,5 @@
 #include "bncconst.h"
 #include "bncapp.h"
+#include "bncutils.h" /* Weber, for latencies */
 
 using namespace std;
@@ -67,4 +68,5 @@
   QSettings settings;
   _checkMountPoint = settings.value("messTypes").toString();
+  _corrLate = settings.value("corrLate").toInt();
   _staID = staID;
 
@@ -110,4 +112,33 @@
     if ( _coDecoder->Decode(buffer, bufLen) == success ) {
       decoded = true;
+
+      // Latency, Weber
+      // -------
+      if ( _corrLate == 2 ) {
+        if (0<_coDecoder->_epochList.size()) {
+          for (int ii=0;ii<_coDecoder->_epochList.size();ii++) {
+            int week;
+            double sec;
+            double secGPS = _coDecoder->_epochList[ii];
+            leapsecGPSWeeks(week, sec);
+            double dt = fabs(sec - secGPS);
+            const double secPerWeek = 7.0 * 24.0 * 3600.0;
+            if (dt > 0.5 * secPerWeek) {
+              if (sec > secGPS) {
+                sec  -= secPerWeek;
+              } else {
+                sec  += secPerWeek;
+              }
+            }
+            QString late;
+            late = QString("%1 ").arg(int((sec - secGPS)*100.)/100.);
+            if (late != "") {
+              emit(newMessage(QString(_staID + ": Latency " + late + "sec").toAscii() ) );
+            }
+          }
+        }
+      }
+      _coDecoder->_epochList.clear();
+
       if (_mode == unknown) {
         _mode = corrections;
Index: /trunk/BNC/RTCM3/RTCM3Decoder.h
===================================================================
--- /trunk/BNC/RTCM3/RTCM3Decoder.h	(revision 1034)
+++ /trunk/BNC/RTCM3/RTCM3Decoder.h	(revision 1035)
@@ -50,4 +50,5 @@
   QString                _staID;
   QString                _checkMountPoint;
+  int                    _corrLate;
   struct RTCM3ParserData _Parser;
   RTCM3coDecoder*        _coDecoder; 
@@ -56,2 +57,3 @@
 
 #endif
+
Index: /trunk/BNC/RTCM3/RTCM3coDecoder.cpp
===================================================================
--- /trunk/BNC/RTCM3/RTCM3coDecoder.cpp	(revision 1034)
+++ /trunk/BNC/RTCM3/RTCM3coDecoder.cpp	(revision 1035)
@@ -139,4 +139,8 @@
       double GPSweeks;
       currentGPSWeeks(GPSweek, GPSweeks);
+
+      for (int kk = 0; kk < _co.epochSize; kk++) {
+        _epochList.push_back(_co.epochGPS[kk]);     /* Weber, for latency */
+      }
 
       if (_co.NumberOfGPSSat > 0) {
Index: /trunk/BNC/RTCM3/clock_orbit_rtcm.c
===================================================================
--- /trunk/BNC/RTCM3/clock_orbit_rtcm.c	(revision 1034)
+++ /trunk/BNC/RTCM3/clock_orbit_rtcm.c	(revision 1035)
@@ -3,5 +3,5 @@
         Name:           clock_orbit_rtcm.c
         Project:        RTCM3
-        Version:        $Id$
+        Version:        $Id: clock_orbit_rtcm.c,v 1.2 2008/05/06 15:07:41 mervart Exp $
         Authors:        Dirk Stöcker
         Description:    state space approach for RTCM3
@@ -495,4 +495,6 @@
     if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
     G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
+    co->epochGPS[co->epochSize] = co->GPSEpochTime;   /* Weber, for latency */
+    if(co->epochSize < 100) {co->epochSize += 1;}     /* Weber, for latency */
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
     G_RESERVED6
@@ -521,4 +523,6 @@
     if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
     G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
+    co->epochGPS[co->epochSize] = co->GPSEpochTime;   /* Weber, for latency */
+    if(co->epochSize < 100) {co->epochSize += 1;}     /* Weber, for latency */
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
     G_RESERVED6
@@ -539,4 +543,6 @@
     if(!co) return -5;
     G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
+    co->epochGPS[co->epochSize] = co->GPSEpochTime;   /* Weber, for latency */
+    if(co->epochSize < 100) {co->epochSize += 1;}     /* Weber, for latency */
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
     G_RESERVED6
Index: /trunk/BNC/RTCM3/clock_orbit_rtcm.h
===================================================================
--- /trunk/BNC/RTCM3/clock_orbit_rtcm.h	(revision 1034)
+++ /trunk/BNC/RTCM3/clock_orbit_rtcm.h	(revision 1035)
@@ -6,5 +6,5 @@
         Name:           clock_orbit_rtcm.h
         Project:        RTCM3
-        Version:        $Id$
+        Version:        $Id: clock_orbit_rtcm.h,v 1.2 2008/05/06 15:07:41 mervart Exp $
         Authors:        Dirk Stöcker
         Description:    state space approach for RTCM3
@@ -52,4 +52,6 @@
   int ClockDataSupplied;            /* boolean */
   int OrbitDataSupplied;            /* boolean */
+  int epochGPS[101];                /* Weber, for latency */
+  int epochSize;                    /* Weber, for latency */
   enum SatelliteReferencePoint SatRefPoint;
   enum SatelliteReferenceDatum SatRefDatum;
Index: /trunk/BNC/bncapp.cpp
===================================================================
--- /trunk/BNC/bncapp.cpp	(revision 1034)
+++ /trunk/BNC/bncapp.cpp	(revision 1035)
@@ -631,6 +631,6 @@
   // ---------------------------------
   if (coTime <= _lastDumpCoSec) {
-    QString line = "old correction: " + staID +
-                    QString().sprintf(" age %ld", 
+    QString line = staID + ": Correction overaged by " +
+                    QString().sprintf(" %ld sec",
                     _lastDumpCoSec - coTime + _waitCoTime);
     messagePrivate(line.toAscii());
Index: /trunk/BNC/bncgetthread.cpp
===================================================================
--- /trunk/BNC/bncgetthread.cpp	(revision 1034)
+++ /trunk/BNC/bncgetthread.cpp	(revision 1035)
@@ -418,5 +418,4 @@
   double maxLat = -maxDt;
   double curLat = 0.;
-  double leapsec = 14.;  // Leap second for latency estimation
 
   _decodeTime = QDateTime::currentDateTime();
@@ -570,5 +569,5 @@
           int week;
           double sec;
-          currentGPSWeeks(week, sec);
+          leapsecGPSWeeks(week, sec);
           const double secPerWeek = 7.0 * 24.0 * 3600.0;
 
@@ -635,5 +634,5 @@
                   }
                 }
-                curLat = sec - obs->_o.GPSWeeks + leapsec;
+                curLat = sec - obs->_o.GPSWeeks;
                 sumLat += curLat;
                 if (curLat < minLat) minLat = curLat;
@@ -671,5 +670,6 @@
               type =  QString("%1 ").arg(_decoder->_typeList[ii]);
               if (type != "") {
-                emit(newMessage(_staID + ": Received message type " + type.toAscii() ));              }
+                emit(newMessage(_staID + ": Received message type " + type.toAscii() ));
+              }
             }
           }
Index: /trunk/BNC/bnchelp.html
===================================================================
--- /trunk/BNC/bnchelp.html	(revision 1034)
+++ /trunk/BNC/bnchelp.html	(revision 1035)
@@ -95,4 +95,5 @@
 &nbsp; &nbsp; &nbsp; 3.8.3. <a href=#corrport>Port</a><br>
 &nbsp; &nbsp; &nbsp; 3.8.4. <a href=#corrwait>Wait for Full Epoch</a><br>
+&nbsp; &nbsp; &nbsp; 3.8.5. <a href=#corrlate>Latency Log</a><br>
 3.9. <a href=#advnote>Monitor</a><br>
 &nbsp; &nbsp; &nbsp; 3.9.1. <a href=#obsrate>Observation Rate</a><br>
@@ -476,5 +477,9 @@
 <p><a name="corrwait"><h4>3.8.4 Wait for Full Epoch - mandatory if 'Port' is set</h4></p>
 <p>
-When feeding a real-time GNSS engine waiting for Ephemeris Corrections, BNC drops whatever is received later than 'Wait for full epoch' seconds. A value of 2 to 5 seconds could be an appropriate choice for that, depending on the latency of the incoming Ephemeris Corrections stream and the delay acceptable by your application. Default value for 'Wait for full epoch' is '0' seconds meaning that BNC will output whatever becomes available immediately and not drop any Ephemeris Correction.
+When feeding a real-time GNSS engine waiting for Ephemeris Corrections, BNC drops (only concering IP port output) whatever is received later than 'Wait for full epoch' seconds. A value of 2 to 5 seconds could be an appropriate choice for that, depending on the latency of the incoming Ephemeris Corrections stream and the delay acceptable by your application.
+</p>
+<p><a name="corrlate"><h4>3.8.5 Latency Log - optional</h4></p>
+<p>
+Message latencies are logged for streams carrying orbit and clock corrections to Broadcast Ephemeris if option 'Latency log' is ticked.
 </p>
 
@@ -564,5 +569,5 @@
 </pre>
 <p>
- BNC can average the latencies per stream over a certain period of GPS time, the 'Performance log' interval. Mean latencies are calculated from the individual latencies of at most one (first incoming) observation per second. Note that computing correct latencies requires the clock of the host computer to be properly synchronized.
+ BNC can average the latencies of observations per stream over a certain period of GPS time, the 'Performance log' interval. Mean latencies are calculated from the individual latencies of at most one (first incoming) observation per second. Note that computing correct latencies requires the clock of the host computer to be properly synchronized.
 </p>
 <p>
@@ -570,5 +575,5 @@
 </p>
 <p>
-Latencies and statistical information can be recorded in the Log file/section at the end of each 'Performance log' interval. A typical output from a 1 hour 'Performance log' interval would be:
+Latencies of observations and statistical information can be recorded in the Log file/section at the end of each 'Performance log' interval. A typical output from a 1 hour 'Performance log' interval would be:
 </p>
 <pre>
@@ -586,5 +591,5 @@
 <p><a name="messmount"><h4>3.10.1 Mountpoint - optional</h4></p>
 <p>
-Specify the mountpoint of an RTCM Version 3.x stream to log the numbers of incoming message types. Logged time stamps refer to message reception time and allow to understand repetition rates. Enter 'ALL' if you want to log message type numbers of all configured streams. Beware that the size of the logfile can rapidly increase depending on the number of incoming RTCM Version 3.x streams.
+Specify the mountpoint of an RTCM Version 3.x stream to log the numbers of incoming message types. Logged time stamps refer to message reception time and allow to understand repetition rates. Enter 'ALL' if you want to log message type numbers of all configured streams. Beware that the size of the logfile can rapidly increase depending on the number of incoming RTCM Version 3.x streams. 
 </p>
 <p>This option is primarily meant for testing and evaluation. Use it to figure out what exactly is produced by a specific GNSS receiver's configuration. An empty option field (default) means that you don't want BNC to print the message type numbers carried in RTCM Version 3.x streams.
Index: /trunk/BNC/bncmain.cpp
===================================================================
--- /trunk/BNC/bncmain.cpp	(revision 1034)
+++ /trunk/BNC/bncmain.cpp	(revision 1035)
@@ -81,5 +81,5 @@
     settings.setValue("corrIntr",   "1 day");
     settings.setValue("rnxSkel",    "SKL");
-    settings.setValue("waitTime",   5);
+    settings.setValue("waitTime",   "5");
     settings.setValue("makePause",  0);
     settings.setValue("obsRate",    "");
@@ -87,6 +87,7 @@
     settings.setValue("adviseReco", "5");
     settings.setValue("perfIntr",   "");
-    settings.setValue("waitCorr",   0);
-    settings.setValue("messTypes",   "");
+    settings.setValue("corrTime",   "5");
+    settings.setValue("messTypes",  "");
+    settings.setValue("corrLate",   0);
   }
 
Index: /trunk/BNC/bncutils.h
===================================================================
--- /trunk/BNC/bncutils.h	(revision 1034)
+++ /trunk/BNC/bncutils.h	(revision 1035)
@@ -34,4 +34,5 @@
 
 void currentGPSWeeks(int& week, double& sec);
+void leapsecGPSWeeks(int& week, double& sec);
 
 #endif
Index: /trunk/BNC/bncwindow.cpp
===================================================================
--- /trunk/BNC/bncwindow.cpp	(revision 1034)
+++ /trunk/BNC/bncwindow.cpp	(revision 1035)
@@ -109,5 +109,5 @@
   _proxyPortLineEdit->setMaximumWidth(9*ww);
   _messTypesLineEdit  = new QLineEdit(settings.value("messTypes").toString());
-  _messTypesLineEdit->setMaximumWidth(9*ww);
+//_messTypesLineEdit->setMaximumWidth(20*ww);
   _waitTimeSpinBox   = new QSpinBox();
   _waitTimeSpinBox->setMinimum(1);
@@ -127,4 +127,7 @@
   _ephPathLineEdit    = new QLineEdit(settings.value("ephPath").toString());
   _corrPathLineEdit    = new QLineEdit(settings.value("corrPath").toString());
+  _corrLateCheckBox  = new QCheckBox();
+  _corrLateCheckBox->setCheckState(Qt::CheckState(
+                                    settings.value("corrLate").toInt()));
 
   _rnxV3CheckBox = new QCheckBox();
@@ -163,5 +166,5 @@
   }
   _corrTimeSpinBox   = new QSpinBox();
-  _corrTimeSpinBox->setMinimum(0);
+  _corrTimeSpinBox->setMinimum(1);
   _corrTimeSpinBox->setMaximum(30);
   _corrTimeSpinBox->setSingleStep(1);
@@ -306,5 +309,5 @@
   _outEphPortLineEdit->setWhatsThis(tr("BNC can produce ephemeris data in RINEX ASCII format on your local host through an IP port. Specify a port number here to activate this function."));
   _corrPortLineEdit->setWhatsThis(tr("BNC can produce Broadcast Ephemeris Corrections on your local host through an IP port. Specify a port number here to activate this function."));
-  _corrTimeSpinBox->setWhatsThis(tr("BNC drops Broadcast Ephemeris Corrections received later than 'Wait for full epoch' seconds. Default value is '0' seconds meaning that BNC will output whatever becomes available immediately and not drop any Ephemeris Correction."));
+  _corrTimeSpinBox->setWhatsThis(tr("Concerning output through IP port, BNC drops Broadcast Ephemeris Corrections received later than 'Wait for full epoch' seconds. A value of 2 to 5 seconds is recommended, depending on the latency of the incoming correction stream(s) and the delay acceptable to your real-time application."));
   _rnxPathLineEdit->setWhatsThis(tr("Here you specify the path to where the RINEX Observation files will be stored. If the specified directory does not exist, BNC will not create RINEX Observation files.")); 
   _ephPathLineEdit->setWhatsThis(tr("Specify the path for saving Broadcast Ephemeris data as RINEX Navigation files. If the specified directory does not exist, BNC will not create RINEX Navigation files."));
@@ -312,4 +315,5 @@
   _rnxScrpLineEdit->setWhatsThis(tr("<p>Whenever a RINEX Observation file is saved, you might want to compress, copy or upload it immediately via FTP. BNC allows you to execute a script/batch file to carry out these operations. To do that specify the full path of the script/batch file here. BNC will pass the full RINEX Observation file path to the script as a command line parameter (%1 on Windows systems, $1 onUnix/Linux systems).</p><p>The triggering event for calling the script or batch file is the end of a RINEX Observation file 'Interval'. If that is overridden by a stream outage, the triggering event is the stream reconnection.</p>"));
   _rnxSkelLineEdit->setWhatsThis(tr("<p>Whenever BNC starts generating RINEX Observation files (and then once every day at midnight), it first tries to retrieve information needed for RINEX headers from so-called public RINEX header skeleton files which are derived from sitelogs. However, sometimes public RINEX header skeleton files are not available, its contents is not up to date, or you need to put additional/optional records in the RINEX header.</p><p>For that BNC allows using personal skeleton files that contain the header records you would like to include. You can derive a personal RINEX header skeleton file from the information given in an up to date sitelog. A file in the RINEX 'Directory' with the RINEX 'Skeleton extension' is interpreted by BNC as a personal RINEX header skeleton file for the corresponding stream.</p>"));
+  _corrLateCheckBox->setWhatsThis(tr("<p>Log latency of Broadcast Ephemeris Corrections.</p>"));
   _rnxAppendCheckBox->setWhatsThis(tr("<p>When BNC is started, new files are created by default and any existing files with the same name will be overwritten. However, users might want to append already existing files following a restart of BNC, a system crash or when BNC crashed. Tick 'Append files' to continue with existing files and keep what has been recorded so far.</p>"));
   _rnxIntrComboBox->setWhatsThis(tr("<p>Select the length of the RINEX Observation file.</p>"));
@@ -324,5 +328,5 @@
   _logFileLineEdit->setWhatsThis(tr("Records of BNC's activities are shown in the Log section on the bottom of this window. They can be saved into a file when a valid path is specified in the 'Logfile (full path)' field."));
   _adviseScriptLineEdit->setWhatsThis(tr("<p>Specify the full path to a script or batch file to handle advisory notes generated in the event of corrupted streams or stream outages. The affected mountpoint and one of the comments 'Begin_Outage', 'End_Outage', 'Begin_Corrupted', or 'End_Corrupted' are passed on to the script as command line parameters.</p><p>The script can be configured to send an email to BNC's operator and/or to the affected stream provider. An empty option field (default) or invalid path means that you don't want to use this option.</p><p> Note that for using this function you need to specify the 'Observation rate'.</p>"));
-  _perfIntrComboBox->setWhatsThis(tr("<p>BNC can average all latencies per stream over a certain period of GPS time. The resulting mean latencies are recorded in the Log file/section at the end of each 'Performance log' interval together with results of a statistical evaluation (approximate number of covered epochs, data gaps).</p><p>Select a 'Performance log' interval or select the empty option field if you do not want BNC to log latencies and statistical information.</p>"));
+  _perfIntrComboBox->setWhatsThis(tr("<p>BNC can average all observation latencies per stream over a certain period of GPS time. The resulting mean latencies of observations are recorded in the Log file/section at the end of each 'Performance log' interval together with results of a statistical evaluation (approximate number of covered epochs, data gaps).</p><p>Select a 'Performance log' interval or select the empty option field if you do not want BNC to log latencies and statistical information.</p>"));
   _mountPointsTable->setWhatsThis(tr("<p>Streams selected for retrieval are listed in the 'Mountpoints' section. Clicking on 'Add Mountpoints' button will open a window that allows the user to select data streams from an NTRIP broadcaster according to their mountpoints. To remove a stream from the 'Mountpoints' list, highlight it by clicking on it and hit the 'Delete Mountpoints' button. You can also remove multiple mountpoints by highlighting them using +Shift and +Ctrl.</p><p>BNC automatically allocates one of its internal decoders to a stream based on the stream's 'format' and 'format-details' as given in the sourcetable. However, there might be cases where you need to override the automatic selection due to incorrect sourcetable for example. BNC allows users to manually select the required decoder by editing the decoder string. Double click on the 'decoder' field, enter your preferred decoder and then hit Enter. The accepted decoder strings are 'RTCM_2.x', 'RTCM_3.x', and 'RTIGS'.</p><p>In case you need to log the raw data as is, BNC allows users to by-pass its decoders and and directly save the input in daily log files. To do this specify the decoder string as 'ZERO'.</p><p>BNC can also retrieve streams from virtual reference stations (VRS). To initiate these streams, an approximate rover position needs to be sent in NMEA GGA message to the NTRIP broadcaster. In return, a user-specific data stream is generated, typically by a Network-RTK software. This stream is customized to the exact latitude and longitude as shown in the 'lat' and 'long' columns under 'Mountpoints'. These VRS streams are indicated by a 'yes' in the 'nmea' column under 'Mountpoints' as well as in the sourcetable. The default 'lat' and 'long' values are taken from the sourcetable. However, in most cases you would probably want to change this according to your requirement. Double click on 'lat' and 'long' fields, enter the values you wish to send and then hit Enter. The format is in positive north latitude degrees (e.g. for northern hemisphere: 52.436, for southern hemisphere: -24.567) and eastern longitude degrees (e.g.: 358.872 or -1.128). Only mountpoints with a 'yes' in its 'nmea' column can be edited. The position should preferably be a point within the coverage of the network.</p>"));
   _log->setWhatsThis(tr("Records of BNC's activities are shown in the Log section. The message log covers the communication status between BNC and the NTRIP broadcaster as well as any problems that occur in the communication link, stream availability, stream delay, stream conversion etc."));
@@ -470,6 +474,7 @@
   cLayout->addWidget(new QLabel("Wait for full epoch"),           3, 0);
   cLayout->addWidget(_corrTimeSpinBox,                            3, 1);
-  cLayout->addWidget(new QLabel("Saving Broadcast Ephemeris correction files and correction output through IP port."),4,0,1,2,Qt::AlignLeft);
-  cLayout->addWidget(new QLabel("    "),5,0);
+  cLayout->addWidget(new QLabel("Latency log"),                   4, 0);
+  cLayout->addWidget(_corrLateCheckBox,                           4, 1);
+  cLayout->addWidget(new QLabel("Saving Broadcast Ephemeris correction files and correction output through IP port."),5,0,1,2,Qt::AlignLeft);
   cgroup->setLayout(cLayout);
 
@@ -627,4 +632,5 @@
   settings.setValue("rnxSkel",     _rnxSkelLineEdit->text());
   settings.setValue("rnxAppend",   _rnxAppendCheckBox->checkState());
+  settings.setValue("corrLate",    _corrLateCheckBox->checkState());
   settings.setValue("rnxV3",       _rnxV3CheckBox->checkState());
   settings.setValue("ephV3",       _ephV3CheckBox->checkState());
Index: /trunk/BNC/bncwindow.h
===================================================================
--- /trunk/BNC/bncwindow.h	(revision 1034)
+++ /trunk/BNC/bncwindow.h	(revision 1035)
@@ -116,4 +116,5 @@
     QSpinBox*  _binSamplSpinBox;
     QCheckBox* _rnxAppendCheckBox;
+    QCheckBox* _corrLateCheckBox;
     QCheckBox* _makePauseCheckBox;
     QSpinBox*  _waitTimeSpinBox;
