Index: /trunk/BNS/RTCM/clock_orbit_rtcm.c
===================================================================
--- /trunk/BNS/RTCM/clock_orbit_rtcm.c	(revision 2423)
+++ /trunk/BNS/RTCM/clock_orbit_rtcm.c	(revision 2424)
@@ -3,9 +3,10 @@
         Name:           clock_orbit_rtcm.c
         Project:        RTCM3
-        Version:        $Id: clock_orbit_rtcm.c,v 1.9 2010/02/22 13:42:26 stoecker Exp $
+        Version:        $Id: clock_orbit_rtcm.c,v 1.10 2010/04/14 11:09:18 stoecker Exp $
         Authors:        Dirk Stöcker
         Description:    state space approach for RTCM3
 */
 
+#include <math.h>
 #include <stdio.h>
 #include <string.h>
@@ -93,4 +94,5 @@
 /* standard values */
 #define T_MESSAGE_NUMBER(a)              ADDBITS(12, a) /* DF002 */
+#define T_RESERVED4                      ADDBITS(1, 0)  /* DF001 */
 #define T_RESERVED5                      ADDBITS(5, 0)  /* DF001 */
 #define T_GPS_SATELLITE_ID(a)            ADDBITS(6, a)  /* DF068 */
@@ -105,8 +107,4 @@
 #define T_DELTA_DOT_ALONG_TRACK(a)       SCALEADDBITS(19,   250000.0, a)
 #define T_DELTA_DOT_CROSS_TRACK(a)       SCALEADDBITS(19,   250000.0, a)
-#define T_DELTA_DOT_DOT_RADIAL(a)        SCALEADDBITS(27, 50000000.0, a)
-#define T_DELTA_DOT_DOT_ALONG_TRACK(a)   SCALEADDBITS(25, 12500000.0, a)
-#define T_DELTA_DOT_DOT_CROSS_TRACK(a)   SCALEADDBITS(25, 12500000.0, a)
-#define T_SATELLITE_REFERENCE_POINT(a)   ADDBITS(1, a)
 
 #define T_SATELLITE_REFERENCE_DATUM(a)   ADDBITS(1, a)
@@ -117,5 +115,4 @@
 #define T_GPS_SIGNAL_IDENTIFIER(a)       ADDBITS(5, a)
 #define T_GLONASS_SIGNAL_IDENTIFIER(a)   ADDBITS(5, a)
-#define T_GALILEO_SIGNAL_IDENTIFIER(a)   ADDBITS(5, a)
 #define T_CODE_BIAS(a)                   SCALEADDBITS(14,      100.0, a)
 #define T_GLONASS_SATELLITE_ID(a)        ADDBITS(5, a)
@@ -125,7 +122,31 @@
 #define T_NO_OF_SATELLITES(a)            ADDBITS(6, a)
 #define T_MULTIPLE_MESSAGE_INDICATOR(a)  ADDBITS(1, a)
-#define T_SSR_URA(a)                     ADDBITS(4, a)
+#define T_SSR_URA(a)                     ADDBITS(6, a)
 #define T_HR_CLOCK_CORRECTION(a)         SCALEADDBITS(22,    10000.0, a)
 #define T_SSR_UPDATE_INTERVAL(a)         ADDBITS(4, a)
+
+static double URAToValue(int ura)
+{
+  int urac, urav;
+  urac = ura >> 3;
+  urav = ura & 7;
+  if(!ura)
+    return 0;
+  else if(ura == 63)
+    return SSR_MAXURA;
+  return (pow(3,urac)*(1.0+urav/4.0)-1.0)/1000.0;
+}
+
+static int ValueToURA(double val)
+{
+  int ura;
+  if(!val)
+    return 0;
+  else if(val > 5.4665)
+    return 63;
+  for(ura = 1; ura < 63 && val > URAToValue(ura); ++ura)
+    ;
+  return ura;
+}
 
 size_t MakeClockOrbit(const struct ClockOrbit *co, enum ClockOrbitType type,
@@ -184,5 +205,6 @@
     T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
     --mmi;
-    T_RESERVED5
+    T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+    T_RESERVED4
     T_NO_OF_SATELLITES(co->NumberOfGPSSat)
     for(i = 0; i < co->NumberOfGPSSat; ++i)
@@ -196,9 +218,4 @@
       T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
       T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
-      T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
-      T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
-      T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
-      T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-      T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
     }
     ENDBLOCK
@@ -244,5 +261,6 @@
       T_MULTIPLE_MESSAGE_INDICATOR(/*mmi || */ left ? 1 : 0)
       --mmi;
-      T_RESERVED5
+      T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+      T_RESERVED4
       T_NO_OF_SATELLITES(nums)
       for(i = start; i < start+nums; ++i)
@@ -256,9 +274,4 @@
         T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
         T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
-        T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
-        T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
-        T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
-        T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-        T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
         T_DELTA_CLOCK_C0(co->Sat[i].Clock.DeltaA0)
         T_DELTA_CLOCK_C1(co->Sat[i].Clock.DeltaA1)
@@ -300,5 +313,5 @@
     {
       T_GPS_SATELLITE_ID(co->Sat[i].ID)
-      T_SSR_URA(co->Sat[i].URA)
+      T_SSR_URA(ValueToURA(co->Sat[i].UserRangeAccuracy))
     }
     ENDBLOCK
@@ -312,5 +325,6 @@
     T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
     --mmi;
-    T_RESERVED5
+    T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+    T_RESERVED4
     T_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
     for(i = CLOCKORBIT_NUMGPS;
@@ -325,9 +339,4 @@
       T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
       T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
-      T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
-      T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
-      T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
-      T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-      T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
     }
     ENDBLOCK
@@ -362,5 +371,6 @@
     T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
     --mmi;
-    T_RESERVED5
+    T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+    T_RESERVED4
     T_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
     for(i = CLOCKORBIT_NUMGPS;
@@ -375,9 +385,4 @@
       T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
       T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
-      T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
-      T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
-      T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
-      T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-      T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
       T_DELTA_CLOCK_C0(co->Sat[i].Clock.DeltaA0)
       T_DELTA_CLOCK_C1(co->Sat[i].Clock.DeltaA1)
@@ -417,5 +422,5 @@
     {
       T_GPS_SATELLITE_ID(co->Sat[i].ID)
-      T_SSR_URA(co->Sat[i].URA)
+      T_SSR_URA(ValueToURA(co->Sat[i].UserRangeAccuracy))
     }
     ENDBLOCK
@@ -532,4 +537,5 @@
 #define G_SIZE(a)                        GETBITS(a, 10)
 #define G_MESSAGE_NUMBER(a)              GETBITS(a, 12) /* DF002 */
+#define G_RESERVED4                      SKIPBITS(4)    /* DF001 */
 #define G_RESERVED5                      SKIPBITS(5)    /* DF001 */
 #define G_GPS_SATELLITE_ID(a)            GETBITS(a, 6)  /* DF068 */
@@ -544,8 +550,4 @@
 #define G_DELTA_DOT_ALONG_TRACK(a)       GETFLOATSIGN(a, 19, 1/250000.0)
 #define G_DELTA_DOT_CROSS_TRACK(a)       GETFLOATSIGN(a, 19, 1/250000.0)
-#define G_DELTA_DOT_DOT_RADIAL(a)        GETFLOATSIGN(a, 27, 1/50000000.0)
-#define G_DELTA_DOT_DOT_ALONG_TRACK(a)   GETFLOATSIGN(a, 25, 1/12500000.0)
-#define G_DELTA_DOT_DOT_CROSS_TRACK(a)   GETFLOATSIGN(a, 25, 1/12500000.0)
-#define G_SATELLITE_REFERENCE_POINT(a)   GETBITS(a, 1)
 
 #define G_SATELLITE_REFERENCE_DATUM(a)   GETBITS(a, 1)
@@ -556,5 +558,4 @@
 #define G_GPS_SIGNAL_IDENTIFIER(a)       GETBITS(a, 5)
 #define G_GLONASS_SIGNAL_IDENTIFIER(a)   GETBITS(a, 5)
-#define G_GALILEO_SIGNAL_IDENTIFIER(a)   GETBITS(a, 5)
 #define G_CODE_BIAS(a)                   GETFLOATSIGN(a, 14, 1/100.0)
 #define G_GLONASS_SATELLITE_ID(a)        GETBITS(a, 5)
@@ -566,5 +567,6 @@
 #define G_NO_OF_SATELLITES(a)            GETBITS(a, 6)
 #define G_MULTIPLE_MESSAGE_INDICATOR(a)  GETBITS(a, 1)
-#define G_SSR_URA(a)                     GETBITS(a, 4)
+#define G_SSR_URA(a)                     {int temp; GETBITS(temp, 6) \
+ (a) = URAToValue(temp);}
 #define G_HR_CLOCK_CORRECTION(a)         GETFLOATSIGN(a, 22, 1/10000.0)
 #define G_SSR_UPDATE_INTERVAL(a)         GETBITS(a, 4)
@@ -614,10 +616,11 @@
     G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
-    G_RESERVED5
+    G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+    G_RESERVED4
     G_NO_OF_SATELLITES(nums)
     co->OrbitDataSupplied |= 1;
 #ifdef DEBUG
-fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GPSEpochTime,
-co->UpdateInterval,mmi,co->NumberOfGPSSat,nums);
+fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d rd %d\n",co->GPSEpochTime,
+co->UpdateInterval,mmi,co->NumberOfGPSSat,nums, co->SatRefDatum);
 #endif
     for(i = 0; i < nums; ++i)
@@ -637,21 +640,11 @@
       G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
       G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
-      G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
-      G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
-      G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
-      G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-      G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
-#ifdef DEBUG
-fprintf(stderr, "id %2d iod %3d dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f rp %d rd %d\n",
+#ifdef DEBUG
+fprintf(stderr, "id %2d iod %3d dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f\n",
 co->Sat[pos].ID,co->Sat[pos].IOD,co->Sat[pos].Orbit.DeltaRadial,
 co->Sat[pos].Orbit.DeltaAlongTrack,co->Sat[pos].Orbit.DeltaCrossTrack,
 co->Sat[pos].Orbit.DotDeltaRadial,
 co->Sat[pos].Orbit.DotDeltaAlongTrack,
-co->Sat[pos].Orbit.DotDeltaCrossTrack,
-co->Sat[pos].Orbit.DotDotDeltaRadial,
-co->Sat[pos].Orbit.DotDotDeltaAlongTrack,
-co->Sat[pos].Orbit.DotDotDeltaCrossTrack,
-co->SatRefPoint,
-co->SatRefDatum);
+co->Sat[pos].Orbit.DotDeltaCrossTrack);
 #endif
     }
@@ -699,5 +692,6 @@
     G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
-    G_RESERVED5
+    G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+    G_RESERVED4
     G_NO_OF_SATELLITES(nums)
     co->OrbitDataSupplied |= 1;
@@ -719,9 +713,4 @@
       G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
       G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
-      G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
-      G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
-      G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
-      G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-      G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
       G_DELTA_CLOCK_C0(co->Sat[pos].Clock.DeltaA0)
       G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
@@ -748,5 +737,5 @@
       co->Sat[pos].ID = id;
 
-      G_SSR_URA(co->Sat[pos].URA)
+      G_SSR_URA(co->Sat[pos].UserRangeAccuracy)
     }
     break;
@@ -780,10 +769,11 @@
     G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
-    G_RESERVED5
+    G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+    G_RESERVED4
     G_NO_OF_SATELLITES(nums)
     co->OrbitDataSupplied |= 2;
 #ifdef DEBUG
-fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GLONASSEpochTime,
-co->UpdateInterval,mmi,co->NumberOfGLONASSSat,nums);
+fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d rd %d\n",co->GLONASSEpochTime,
+co->UpdateInterval,mmi,co->NumberOfGLONASSSat,nums, co->SatRefDatum);
 #endif
     for(i = 0; i < nums; ++i)
@@ -803,21 +793,11 @@
       G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
       G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
-      G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
-      G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
-      G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
-      G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-      G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
-#ifdef DEBUG
-fprintf(stderr, "id %2d iod %3d dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f rp %d rd %d\n",
+#ifdef DEBUG
+fprintf(stderr, "id %2d iod %3d dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f\n",
 co->Sat[pos].ID,co->Sat[pos].IOD,co->Sat[pos].Orbit.DeltaRadial,
 co->Sat[pos].Orbit.DeltaAlongTrack,co->Sat[pos].Orbit.DeltaCrossTrack,
 co->Sat[pos].Orbit.DotDeltaRadial,
 co->Sat[pos].Orbit.DotDeltaAlongTrack,
-co->Sat[pos].Orbit.DotDeltaCrossTrack,
-co->Sat[pos].Orbit.DotDotDeltaRadial,
-co->Sat[pos].Orbit.DotDotDeltaAlongTrack,
-co->Sat[pos].Orbit.DotDotDeltaCrossTrack,
-co->SatRefPoint,
-co->SatRefDatum);
+co->Sat[pos].Orbit.DotDeltaCrossTrack);
 #endif
     }
@@ -861,5 +841,6 @@
     G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
-    G_RESERVED5
+    G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+    G_RESERVED4
     G_NO_OF_SATELLITES(nums)
     co->OrbitDataSupplied |= 2;
@@ -881,9 +862,4 @@
       G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
       G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
-      G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
-      G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
-      G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
-      G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
-      G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
       G_DELTA_CLOCK_C0(co->Sat[pos].Clock.DeltaA0)
       G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
@@ -908,5 +884,5 @@
       co->Sat[pos].ID = id;
 
-      G_SSR_URA(co->Sat[pos].URA)
+      G_SSR_URA(co->Sat[pos].UserRangeAccuracy)
     }
     break;
Index: /trunk/BNS/RTCM/clock_orbit_rtcm.h
===================================================================
--- /trunk/BNS/RTCM/clock_orbit_rtcm.h	(revision 2423)
+++ /trunk/BNS/RTCM/clock_orbit_rtcm.h	(revision 2424)
@@ -6,5 +6,5 @@
         Name:           clock_orbit_rtcm.h
         Project:        RTCM3
-        Version:        $Id: clock_orbit_rtcm.h,v 1.12 2010/02/17 10:49:27 mervart Exp $
+        Version:        $Id: clock_orbit_rtcm.h,v 1.8 2010/04/14 11:09:18 stoecker Exp $
         Authors:        Dirk Stöcker
         Description:    state space approach for RTCM3
@@ -14,5 +14,4 @@
 
 enum SatelliteReferenceDatum { DATUM_ITRF=0, DATUM_LOCAL=1 };
-enum SatelliteReferencePoint { POINT_IONOFREE=0, POINT_CENTER=1 };
 enum ClockOrbitType {
      COTYPE_GPSORBIT=1057, COTYPE_GPSCLOCK=1058,
@@ -46,4 +45,6 @@
 };
 
+#define SSR_MAXURA 5.5 /* > 5466.5mm in meter */
+
 /* GLONASS data is stored with offset CLOCKORBIT_NUMGPS in the data structures.
 So first GLONASS satellite is at xxx->Sat[CLOCKORBIT_NUMGPS], first
@@ -64,10 +65,9 @@
   int epochSize;                    /* Weber, for latency */
   int UpdateInterval;
-  enum SatelliteReferencePoint SatRefPoint;
   enum SatelliteReferenceDatum SatRefDatum;
   struct SatData {
     int ID; /* GPS or GLONASS */
     int IOD; /* GPS or GLONASS */
-    int URA;
+    double UserRangeAccuracy; /* accuracy values in [m] */
     double hrclock;
     struct OrbitPart
@@ -79,7 +79,4 @@
       double DotDeltaAlongTrack;    /* m/s */
       double DotDeltaCrossTrack;    /* m/s */
-      double DotDotDeltaRadial;     /* m/ss */
-      double DotDotDeltaAlongTrack; /* m/ss */
-      double DotDotDeltaCrossTrack; /* m/ss */
     } Orbit;
     struct ClockPart
Index: /trunk/BNS/bns.cpp
===================================================================
--- /trunk/BNS/bns.cpp	(revision 2423)
+++ /trunk/BNS/bns.cpp	(revision 2424)
@@ -515,11 +515,4 @@
           char obuffer[CLOCKORBIT_BUFFERSIZE];
 
-          if (_caster.at(ic)->CoM()) {
-            co.SatRefPoint = POINT_CENTER;
-          }
-          else {
-            co.SatRefPoint = POINT_IONOFREE;
-          }
-
           int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
           if (len > 0) {
