Changeset 878 in ntrip


Ignore:
Timestamp:
May 6, 2008, 4:47:42 PM (17 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNS/RTCM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNS/RTCM/clock_orbit_rtcm.c

    r864 r878  
    33        Name:           clock_orbit_rtcm.c
    44        Project:        RTCM3
    5         Version:        $Id: clock_orbit_rtcm.c,v 1.1 2008/05/04 17:38:12 mervart Exp $
     5        Version:        $Id$
    66        Authors:        Dirk Stöcker
    77        Description:    state space approach for RTCM3
     
    397397  while((a) > numbits) \
    398398  { \
    399     if(!size--) return -2; \
     399    if(!size--) return GCOBR_SHORTBUFFER; \
    400400    bitbuffer = (bitbuffer<<8)|((unsigned char)*(buffer++)); \
    401401    numbits += 8; \
     
    424424
    425425/* standard values */
    426 #define G_HEADER                         SKIPBITS(8+6+10)
     426#define G_HEADER(a)                      GETBITS(a,8)
     427#define G_RESERVEDH(a)                   GETBITS(a,6)
     428#define G_SIZE(a)                        GETBITS(a, 10)
    427429#define G_MESSAGE_NUMBER(a)              GETBITS(a, 12) /* DF002 */
    428430#define G_RESERVED6                      SKIPBITS(6)    /* DF001 */
    429 #define G_GPS_SATELLITE_ID(a)            GETBITS(a, 6)  /* DF068 */
     431#define G_GPS_SATELLITE_ID(a)            {int temp; GETBITS(temp, 6) \
     432 if(a && a != temp) return GCOBR_DATAMISMATCH; a = temp;}  /* DF068 */
    430433#define G_GPS_IODE(a)                    GETBITS(a, 8)  /* DF071 */
    431434#define G_GLONASS_IOD(a)                 GETBITS(a, 8)  /* DF237 */
     
    433436/* defined values */
    434437#define G_MULTIPLE_MESSAGE_INDICATOR(a)  GETBITS(a, 1)
    435 #define G_GPS_EPOCH_TIME(a)              GETBITS(a, 20)
    436 #define G_GLONASS_EPOCH_TIME(a)          GETBITS(a, 17)
    437 #define G_GLONASS_SATELLITE_ID(a)        GETBITS(a, 6)
    438 #define G_NO_OF_SATELLITES(a)            GETBITS(a, 5)
     438#define G_GPS_EPOCH_TIME(a, b)           {int temp; GETBITS(temp, 20) \
     439 if(b && a != temp) return GCOBR_TIMEMISMATCH; a = temp;}
     440#define G_GLONASS_EPOCH_TIME(a, b)       {int temp; GETBITS(temp, 17) \
     441 if(b && a != temp) return GCOBR_TIMEMISMATCH; a = temp;}
     442#define G_GLONASS_SATELLITE_ID(a)        {int temp; GETBITS(temp, 6) \
     443 if(a && a != temp) return GCOBR_DATAMISMATCH; a = temp;}
     444#define G_NO_OF_SATELLITES(a)            {int temp; GETBITS(temp, 5) \
     445 if(a && a != temp) return GCOBR_DATAMISMATCH; a = temp;}
    439446#define G_SATELLITE_REFERENCE_POINT(a)   GETBITS(a, 1)
    440447#define G_SATELLITE_REFERENCE_DATUM(a)   GETBITS(a, 1)
     
    458465#define G_CODE_BIAS(a)                   GETFLOATSIGN(a, 20, 1/100.0)
    459466
    460 /* FIXME: Joining data does no care for satellite numbers, dates and so on.
    461 It will only work with data, which is stored and the same order and number as
    462 the previos blocks! */
    463 
    464 int GetClockOrbitBias(struct ClockOrbit *co, struct Bias *b,
    465 const char *buffer, size_t size)
     467enum GCOB_RETURN GetClockOrbitBias(struct ClockOrbit *co, struct Bias *b,
     468const char *buffer, size_t size, int *bytesused)
    466469{
    467   int type, mmi=0, i, j;
     470  int type, mmi=0, i, j, h, rs, sizeofrtcmblock;
     471  const char *blockstart = buffer;
    468472  DECODESTART
    469473
    470   G_HEADER
     474  if(size < 7)
     475    return GCOBR_SHORTBUFFER;
     476
     477  G_HEADER(h)
     478  G_RESERVEDH(rs)
     479  G_SIZE(sizeofrtcmblock);
     480
     481  if((unsigned char)h != 0xD3 || rs)
     482    return GCOBR_UNKNOWNDATA;
     483  if(size < sizeofrtcmblock + 3) /* 3 header bytes already removed */
     484    return GCOBR_MESSAGEEXCEEDSBUFFER;
     485  if(CRC24(sizeofrtcmblock+3, (const unsigned char *) blockstart) !=
     486  ((((unsigned char)buffer[sizeofrtcmblock])<<16)|
     487   (((unsigned char)buffer[sizeofrtcmblock+1])<<8)|
     488   (((unsigned char)buffer[sizeofrtcmblock+2]))))
     489    return GCOBR_CRCMISMATCH;
     490
    471491  G_MESSAGE_NUMBER(type)
    472492  switch(type)
    473493  {
    474494  case COTYPE_GPSORBIT:
    475     if(!co) return -5;
    476     G_GPS_EPOCH_TIME(co->GPSEpochTime)
     495    if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
     496    G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
    477497    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    478498    G_RESERVED6
    479499    G_NO_OF_SATELLITES(co->NumberOfGPSSat)
     500    if(co->OrbitDataSupplied)
     501      return GCOBR_DATAMISMATCH;
    480502    co->OrbitDataSupplied = 1;
    481503    for(i = 0; i < co->NumberOfGPSSat; ++i)
     
    497519    break;
    498520  case COTYPE_GPSCLOCK:
    499     if(!co) return -5;
    500     G_GPS_EPOCH_TIME(co->GPSEpochTime)
     521    if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
     522    G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
    501523    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    502524    G_RESERVED6
    503525    G_NO_OF_SATELLITES(co->NumberOfGPSSat)
     526    if(co->ClockDataSupplied)
     527      return GCOBR_DATAMISMATCH;
    504528    co->ClockDataSupplied = 1;
    505529    for(i = 0; i < co->NumberOfGPSSat; ++i)
     
    514538  case COTYPE_GPSCOMBINED:
    515539    if(!co) return -5;
    516     G_GPS_EPOCH_TIME(co->GPSEpochTime)
     540    G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
    517541    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    518542    G_RESERVED6
    519543    G_NO_OF_SATELLITES(co->NumberOfGPSSat)
     544    if(co->ClockDataSupplied || co->OrbitDataSupplied)
     545      return GCOBR_DATAMISMATCH;
    520546    co->OrbitDataSupplied = 1;
    521547    co->ClockDataSupplied = 1;
     
    541567    break;
    542568  case COTYPE_GLONASSORBIT:
    543     if(!co) return -5;
    544     G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
     569    if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
     570    G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
    545571    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    546572    G_RESERVED6
    547573    G_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
     574    if(co->OrbitDataSupplied)
     575      return GCOBR_DATAMISMATCH;
    548576    co->OrbitDataSupplied = 1;
    549577    for(i = CLOCKORBIT_NUMGPS;
     
    566594    break;
    567595  case COTYPE_GLONASSCLOCK:
    568     if(!co) return -5;
    569     G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
     596    if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
     597    G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
    570598    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    571599    G_RESERVED6
    572600    G_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
     601    if(co->ClockDataSupplied)
     602      return GCOBR_DATAMISMATCH;
    573603    co->ClockDataSupplied = 1;
    574604    for(i = CLOCKORBIT_NUMGPS;
     
    583613    break;
    584614  case COTYPE_GLONASSCOMBINED:
    585     if(!co) return -5;
    586     G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
     615    if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
     616    G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
    587617    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    588618    G_RESERVED6
    589619    G_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
     620    if(co->ClockDataSupplied || co->OrbitDataSupplied)
     621      return GCOBR_DATAMISMATCH;
    590622    co->OrbitDataSupplied = 1;
    591623    co->ClockDataSupplied = 1;
     
    612644    break;
    613645  case BTYPE_GPS:
    614     if(!b) return -4;
    615     G_GPS_EPOCH_TIME(b->GPSEpochTime)
     646    if(!b) return GCOBR_NOBIASPARAMETER;
     647    G_GPS_EPOCH_TIME(b->GPSEpochTime, co->NumberOfGPSSat)
    616648    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    617649    G_RESERVED6
     
    629661    break;
    630662  case BTYPE_GLONASS:
    631     if(!b) return -4;
    632     G_GPS_EPOCH_TIME(b->GLONASSEpochTime)
     663    if(!b) return GCOBR_NOBIASPARAMETER;
     664    G_GPS_EPOCH_TIME(b->GLONASSEpochTime, co->NumberOfGLONASSSat)
    633665    G_MULTIPLE_MESSAGE_INDICATOR(mmi)
    634666    G_RESERVED6
     
    647679    break;
    648680  default:
    649     return -3;
    650   }
    651   return mmi ? 1 : 0;
     681    return GCOBR_UNKNOWNTYPE;
     682  }
     683  if(bytesused)
     684    *bytesused = sizeofrtcmblock+6;
     685  return mmi ? GCOBR_MESSAGEFOLLOWS : GCOBR_OK;
    652686}
    653687#endif /* NODECODE */
  • trunk/BNS/RTCM/clock_orbit_rtcm.h

    r862 r878  
    102102       int moremessagesfollow, char *buffer, size_t size);
    103103
    104 /* returns 0 if all ok and < 0 in case of an error, a value of 1 means
    105    multiple data flags was found and there probably is at least one more block
    106    for same epoch */
    107 /* buffer should point to a RTCM3 block. The functions does not check if the
    108    block is valid, but assumes it has already been checked.
    109    As a result either co or b are filled with data.
    110    NOTE: data is not overwritten, but appended. You get an error if the dataset
    111    do not match (i.e. mismatch in time).
    112 */
    113 int GetClockOrbitBias(struct ClockOrbit *co, struct Bias *b,
    114        const char *buffer, size_t size);
     104enum GCOB_RETURN {
     105  /* all well */
     106  GCOBR_MESSAGEFOLLOWS = 1,
     107  GCOBR_OK = 0,
     108  /* unknown data, a warning */
     109  GCOBR_UNKNOWNTYPE = -1,
     110  GCOBR_UNKNOWNDATA = -2,
     111  GCOBR_CRCMISMATCH = -3,
     112  /* failed to do the work */
     113  GCOBR_NOCLOCKORBITPARAMETER = -10,
     114  GCOBR_NOBIASPARAMETER = -11,
     115  /* data mismatch - data in storage does not match new data */
     116  GCOBR_TIMEMISMATCH = -20,
     117  GCOBR_DATAMISMATCH = -21,
     118  /* not enough data - can decode the block completely */
     119  GCOBR_SHORTBUFFER = -30,
     120  GCOBR_MISSINGBITS = -31,
     121  GCOBR_MESSAGEEXCEEDSBUFFER = -32
     122};
     123
     124/* NOTE: When an error message has been emitted, the output structures may have been modified. Make a copy of the previous variant before calling the
     125function to have a clean state. */
     126
     127/* buffer should point to a RTCM3 block */
     128enum GCOB_RETURN GetClockOrbitBias(struct ClockOrbit *co, struct Bias *b,
     129       const char *buffer, size_t size, int *bytesused);
    115130
    116131#endif /* RTCM3_CLOCK_ORBIT_RTCM_H */
Note: See TracChangeset for help on using the changeset viewer.