Changeset 320 in ntrip


Ignore:
Timestamp:
Nov 15, 2006, 7:32:49 PM (17 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC/RTCM3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/RTCM3/RTCM3Decoder.cpp

    r297 r320  
    5151#  define isinf(x) 0
    5252#endif
     53
     54// Error Handling
     55////////////////////////////////////////////////////////////////////////////
     56void RTCM3Error(const char *fmt, ...) {
     57
     58}
    5359
    5460// Constructor
  • trunk/BNC/RTCM3/rtcm3torinex.cpp

    r284 r320  
    11/*
    22  Converter for RTCM3 data to RINEX.
    3   $Id: rtcm3torinex.cpp,v 1.9 2006/11/08 16:08:32 mervart Exp $
     3  $Id: rtcm3torinex.c,v 1.10 2006/11/15 12:31:31 stoecker Exp $
    44  Copyright (C) 2005-2006 by Dirk Stoecker <stoecker@euronik.eu>
    55
     
    2929#include <math.h>
    3030#include <signal.h>
     31#include <stdarg.h>
    3132#include <stdio.h>
    3233#include <stdlib.h>
     
    5051
    5152/* CVS revision and version */
    52 static char revisionstr[] = "$Revision: 1.9 $";
     53static char revisionstr[] = "$Revision: 1.10 $";
    5354
    5455static uint32_t CRC24(long size, const unsigned char *buf)
     
    109110  i = m - handle->Message;
    110111  if(i && m < e)
    111     memmove(handle->Message, m, handle->MessageSize-i);
     112    memmove(handle->Message, m, (size_t)(handle->MessageSize-i));
    112113  handle->MessageSize -= i;
    113114
     
    145146#define SKIPBITS(b) { LOADBITS(b) numbits -= (b); }
    146147
     148struct leapseconds { /* specify the day of leap second */
     149  int day;        /* this is the day, where 23:59:59 exists 2 times */
     150  int month;      /* not the next day! */
     151  int year;
     152  int taicount;
     153};
     154static const int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
     155static const struct leapseconds leap[] = {
     156/*{31, 12, 1971, 11},*/
     157/*{31, 12, 1972, 12},*/
     158/*{31, 12, 1973, 13},*/
     159/*{31, 12, 1974, 14},*/
     160/*{31, 12, 1975, 15},*/
     161/*{31, 12, 1976, 16},*/
     162/*{31, 12, 1977, 17},*/
     163/*{31, 12, 1978, 18},*/
     164/*{31, 12, 1979, 19},*/
     165{30, 06, 1981,20},
     166{30, 06, 1982,21},
     167{30, 06, 1983,22},
     168{30, 06, 1985,23},
     169{31, 12, 1987,24},
     170{31, 12, 1989,25},
     171{31, 12, 1990,26},
     172{30, 06, 1992,27},
     173{30, 06, 1993,28},
     174{30, 06, 1994,29},
     175{31, 12, 1995,30},
     176{30, 06, 1997,31},
     177{31, 12, 1998,32},
     178{31, 12, 2005,33},
     179{0,0,0,0} /* end marker */
     180};
     181#define GPSLEAPSTART    19 /* 19 leap seconds existed at 6.1.1980 */
     182
     183static int longyear(int year, int month)
     184{
     185  if(!(year % 4) && (!(year % 400) || (year % 100)))
     186  {
     187    if(!month || month == 2)
     188      return 1;
     189  }
     190  return 0;
     191}
     192
     193static int gnumleap(int year, int month, int day)
     194{
     195  int ls = 0;
     196  const struct leapseconds *l;
     197
     198  for(l = leap; l->taicount && year >= l->year; ++l)
     199  {
     200    if(year > l->year || month > l->month || day > l->day)
     201       ls = l->taicount - GPSLEAPSTART;
     202  }
     203  return ls;
     204}
     205
     206static void updatetime(int *week, int *tow, int tk)
     207{
     208  int y,m,d,k,l;
     209  unsigned int j = *week*(7*24*60*60) + *tow + 5*24*60*60+3*60*60;
     210  int glo_daynumber = 0, glo_timeofday;
     211  for(y = 1980; j >= (unsigned int)(k = (l = (365+longyear(y,0)))*24*60*60)
     212  + gnumleap(y+1,1,1); ++y)
     213  {
     214    j -= k; glo_daynumber += l;
     215  }
     216  for(m = 1; j >= (unsigned int)(k = (l = months[m]+longyear(y, m))*24*60*60)
     217  + gnumleap(y, m+1, 1); ++m)
     218  {
     219    j -= k; glo_daynumber += l;
     220  }
     221  for(d = 1; j >= 24UL*60UL*60UL + gnumleap(y, m, d+1); ++d)
     222    j -= 24*60*60;
     223  glo_daynumber -= 16*365+4-d;
     224  glo_timeofday = j-gnumleap(y, m, d);
     225
     226  if(tk < 5*60*1000 && glo_timeofday > 23*60*60)
     227    *tow += 24*60*60;
     228  else if(glo_timeofday < 5*60 && tk > 23*60*60*1000)
     229    *tow -= 24*60*60;
     230  *tow += tk/1000-glo_timeofday;
     231  if(*tow < 0) {*tow += 24*60*60*7; --*week; }
     232  if(*tow >= 24*60*60*7) {*tow -= 24*60*60*7; ++*week; }
     233}
     234
    147235int RTCM3Parser(struct RTCM3ParserData *handle)
    148236{
     
    155243    uint64_t numbits = 0, bitfield = 0;
    156244    int size = handle->size, type;
     245    int syncf, old = 0;
    157246    unsigned char *data = handle->Message+3;
    158247
     
    171260          lastlockl1[i] = lastlockl2[i] = 0;
    172261
    173         gnss = &handle->Data;
    174         memset(gnss, 0, sizeof(*gnss));
     262        gnss = &handle->DataNew;
    175263
    176264        SKIPBITS(12) /* id */
     
    179267          ++handle->GPSWeek;
    180268        handle->GPSTOW = i/1000;
     269        if(gnss->week && (gnss->timeofweek != i || gnss->week
     270        != handle->GPSWeek))
     271        {
     272          handle->Data = *gnss;
     273          memset(gnss, 0, sizeof(*gnss));
     274          old = 1;
     275        }
    181276        gnss->timeofweek = i;
    182277        gnss->week = handle->GPSWeek;
    183278
    184         SKIPBITS(1) /* sync */
     279        GETBITS(syncf,1) /* sync */
    185280        GETBITS(i,5)
    186281        gnss->numsats = i;
     
    299394          handle->lastlockl2[i] = lastlockl2[i];
    300395        }
    301         if(wasamb) /* not RINEX compatible without */
    302           ret = 1;
    303         else
    304           ret = 2;
     396        if(!syncf && !old)
     397        {
     398          handle->Data = *gnss;
     399          memset(gnss, 0, sizeof(*gnss));
     400        }
     401        if(!syncf || old)
     402        {
     403          if(wasamb) /* not RINEX compatible without */
     404            ret = 1;
     405          else
     406            ret = 2;
     407        }
    305408      }
    306409      break;
     410    case 1009: case 1010: case 1011: case 1012:
     411      {
     412        int lastlockl1[64];
     413        int lastlockl2[64];
     414        struct gnssdata *gnss;
     415        int i, num;
     416        int wasamb=0;
     417
     418        for(i = 0; i < 64; ++i)
     419          lastlockl1[i] = lastlockl2[i] = 0;
     420
     421        gnss = &handle->DataNew;
     422
     423        SKIPBITS(12) /* id */;
     424        GETBITS(i,27) /* tk */
     425
     426        updatetime(&handle->GPSWeek, &handle->GPSTOW, i);
     427        i = handle->GPSTOW*1000;
     428        if(gnss->week && (gnss->timeofweek != i || gnss->week
     429        != handle->GPSWeek))
     430        {
     431          handle->Data = *gnss;
     432          memset(gnss, 0, sizeof(*gnss));
     433          old = 1;
     434        }
     435
     436        gnss->timeofweek = i;
     437        gnss->week = handle->GPSWeek;
     438
     439        GETBITS(syncf,1) /* sync */
     440        GETBITS(i,5)
     441        gnss->numsats += i;
     442
     443        SKIPBITS(4) /* smind, smint */
     444
     445        for(num = gnss->numsats-i; num < gnss->numsats; ++num)
     446        {
     447          int sv, code, l1range, c,l,s,ce,le,se,amb=0;
     448
     449          GETBITS(sv, 6)
     450          if(!sv || sv > 24)
     451          {
     452            --num; --gnss->numsats;
     453          }
     454          else
     455          {
     456            int freq;
     457            gnss->satellites[num] = sv-1 + PRN_GLONASS_START;
     458            /* L1 */
     459            GETBITS(code, 1)
     460            GETBITS(freq, 5)
     461            if(code)
     462            {
     463              c = GNSSDF_P1DATA;  ce = GNSSENTRY_P1DATA;
     464              l = GNSSDF_L1PDATA; le = GNSSENTRY_L1PDATA;
     465              s = GNSSDF_S1PDATA; se = GNSSENTRY_S1PDATA;
     466            }
     467            else
     468            {
     469              c = GNSSDF_C1DATA;  ce = GNSSENTRY_C1DATA;
     470              l = GNSSDF_L1CDATA; le = GNSSENTRY_L1CDATA;
     471              s = GNSSDF_S1CDATA; se = GNSSENTRY_S1CDATA;
     472            }
     473            GETBITS(l1range, 25)
     474            if(l1range != 0x80000)
     475            {
     476              gnss->dataflags[num] |= c;
     477              gnss->measdata[num][ce] = l1range*0.02;
     478            }
     479            GETBITSSIGN(i, 20)
     480            if(i != 0x80000)
     481            {
     482              gnss->dataflags[num] |= l;
     483              gnss->measdata[num][le] = l1range*0.02+i*0.0005;
     484            }
     485            GETBITS(i, 7)
     486            lastlockl1[sv] = i;
     487            if(handle->lastlockl1[sv] > i)
     488              gnss->dataflags[num] |= GNSSDF_LOCKLOSSL1;
     489            if(type == 1010 || type == 1012)
     490            {
     491              GETBITS(amb,7)
     492              if(amb && (gnss->dataflags[num] & c))
     493              {
     494                gnss->measdata[num][ce] += amb*599584.916;
     495                gnss->measdata[num][le] += amb*599584.916;
     496                ++wasamb;
     497              }
     498              GETBITS(i, 8)
     499              if(i)
     500              {
     501                gnss->dataflags[num] |= s;
     502                gnss->measdata[num][se] = i*0.25;
     503                i /= 4*4;
     504                if(i > 9) i = 9;
     505                else if(i < 1) i = 1;
     506                gnss->snrL1[num] = i;
     507              }
     508            }
     509            gnss->measdata[num][le] /= GLO_WAVELENGTH_L1(freq-7);
     510            if(type == 1011 || type == 1012)
     511            {
     512              /* L2 */
     513              GETBITS(code,2)
     514              if(code)
     515              {
     516                c = GNSSDF_P2DATA;  ce = GNSSENTRY_P2DATA;
     517                l = GNSSDF_L2PDATA; le = GNSSENTRY_L2PDATA;
     518                s = GNSSDF_S2PDATA; se = GNSSENTRY_S2PDATA;
     519              }
     520              else
     521              {
     522                c = GNSSDF_C2DATA;  ce = GNSSENTRY_C2DATA;
     523                l = GNSSDF_L2CDATA; le = GNSSENTRY_L2CDATA;
     524                s = GNSSDF_S2CDATA; se = GNSSENTRY_S2CDATA;
     525              }
     526              GETBITSSIGN(i,14)
     527              if(i != 0x2000)
     528              {
     529                gnss->dataflags[num] |= c;
     530                gnss->measdata[num][ce] = l1range*0.02+i*0.02
     531                +amb*599584.916;
     532              }
     533              GETBITSSIGN(i,20)
     534              if(i != 0x80000)
     535              {
     536                gnss->dataflags[num] |= l;
     537                gnss->measdata[num][le] = l1range*0.02+i*0.0005
     538                +amb*599584.915;
     539              }
     540              GETBITS(i,7)
     541              lastlockl2[sv] = i;
     542              if(handle->lastlockl2[sv] > i)
     543                gnss->dataflags[num] |= GNSSDF_LOCKLOSSL2;
     544              if(type == 1012)
     545              {
     546                GETBITS(i, 8)
     547                if(i)
     548                {
     549                  gnss->dataflags[num] |= s;
     550                  gnss->measdata[num][se] = i*0.25;
     551                  i /= 4*4;
     552                  if(i > 9) i = 9;
     553                  else if(i < 1) i = 1;
     554                  gnss->snrL2[num] = i;
     555                }
     556              }
     557              gnss->measdata[num][le] /= GLO_WAVELENGTH_L2(freq-7);
     558            }
     559          }
     560        }
     561        for(i = 0; i < 64; ++i)
     562        {
     563          handle->lastlockl1[i] = lastlockl1[i];
     564          handle->lastlockl2[i] = lastlockl2[i];
     565        }
     566        if(!syncf && !old)
     567        {
     568          handle->Data = *gnss;
     569          memset(gnss, 0, sizeof(*gnss));
     570        }
     571        if(!syncf || old)
     572        {
     573          if(wasamb) /* not RINEX compatible without */
     574            ret = 1;
     575          else
     576            ret = 2;
     577        }
     578      }
     579      break;
    307580    }
    308581  }
     
    310583}
    311584
    312 static int longyear(int year, int month)
    313 {
    314   if(!(year % 4) && (!(year % 400) || (year % 100)))
    315   {
    316     if(!month || month == 2)
    317       return 1;
    318   }
    319   return 0;
    320 }
    321 
    322 void converttime(struct converttimeinfo *c, int week, int tow)
    323 {
    324   /* static variables */
    325   static const int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    326 
     585struct Header
     586{
     587  const char *version;
     588  const char *pgm;
     589  const char *marker;
     590  const char *observer;
     591  const char *receiver;
     592  const char *antenna;
     593  const char *position;
     594  const char *antennaposition;
     595  const char *wavelength;
     596  const char *typesofobs; /* should not be modified outside */
     597  const char *timeoffirstobs; /* should not be modified outside */
     598};
     599
     600#define MAXHEADERLINES 50
     601#define MAXHEADERBUFFERSIZE 4096
     602struct HeaderData
     603{
     604  union
     605  {
     606    struct Header named;
     607    const char *unnamed[MAXHEADERLINES];
     608  } data;
     609  int  numheaders;
     610};
     611
     612struct converttimeinfo {
     613  int second;    /* seconds of GPS time [0..59] */
     614  int minute;    /* minutes of GPS time [0..59] */
     615  int hour;      /* hour of GPS time [0..24] */
     616  int day;       /* day of GPS time [1..28..30(31)*/
     617  int month;     /* month of GPS time [1..12]*/
     618  int year;      /* year of GPS time [1980..] */
     619};
     620
     621static void converttime(struct converttimeinfo *c, int week, int tow)
     622{
    327623  int i, k, doy, j; /* temporary variables */
    328624  j = week*(7*24*60*60) + tow + 5*24*60*60;
     
    343639}
    344640
    345 struct Header
    346 {
    347   const char *version;
    348   const char *pgm;
    349   const char *marker;
    350   const char *observer;
    351   const char *receiver;
    352   const char *antenna;
    353   const char *position;
    354   const char *antennaposition;
    355   const char *wavelength;
    356   const char *typesofobs; /* should not be modified outside */
    357   const char *timeoffirstobs; /* should not be modified outside */
    358 };
    359 
    360 #define MAXHEADERLINES 50
    361 #define MAXHEADERBUFFERSIZE 4096
    362 struct HeaderData
    363 {
    364   union
    365   {
    366     struct Header named;
    367     const char *unnamed[MAXHEADERLINES];
    368   } data;
    369   int  numheaders;
    370 };
    371 
     641#ifndef NO_RTCM3_MAIN
     642void RTCM3Error(const char *fmt, ...)
     643{
     644  va_list v;
     645  va_start(v, fmt);
     646  vfprintf(stderr, fmt, v);
     647  va_end(v);
     648}
     649#endif
     650
     651void RTCM3Text(const char *fmt, ...)
     652{
     653  va_list v;
     654  va_start(v, fmt);
     655  vprintf(fmt, v);
     656  va_end(v);
     657}
     658
     659#define NUMSTARTSKIP 3
    372660void HandleHeader(struct RTCM3ParserData *Parser)
    373661{
     
    375663  char thebuffer[MAXHEADERBUFFERSIZE];
    376664  char *buffer = thebuffer;
    377   int buffersize = sizeof(thebuffer);
     665  size_t buffersize = sizeof(thebuffer);
    378666  int i;
    379667
     
    453741    }
    454742
    455     int flags = 0;
     743    int flags = Parser->startflags;
    456744    int data[RINEXENTRY_NUMBER];
    457745    char tbuffer[6*RINEXENTRY_NUMBER+1];
     
    510798    if((fh = fopen(Parser->headerfile, "r")))
    511799    {
    512       int siz;
     800      size_t siz;
    513801      char *lastblockstart;
    514802      if((siz = fread(buffer, 1, buffersize-1, fh)) > 0)
     
    517805        if(siz == buffersize)
    518806        {
    519           fprintf(stderr, "Header file is too large. Only %d bytes read.",
     807          RTCM3Error("Header file is too large. Only %d bytes read.",
    520808          siz);
    521809        }
     
    524812        /* overwrites entries, except for comments */
    525813        lastblockstart = buffer;
    526         for(i = 0; i < siz; ++i)
     814        for(i = 0; i < (int)siz; ++i)
    527815        {
    528816          if(buffer[i] == '\n')
     
    535823              *(end--) = 0;
    536824            if(end-lastblockstart < 60+5) /* short line */
    537               fprintf(stderr, "Short Header line '%s' ignored.\n", lastblockstart);
     825              RTCM3Error("Short Header line '%s' ignored.\n", lastblockstart);
    538826            else
    539827            {
     
    551839                || !strcmp("TIME OF FIRST OBS", lastblockstart+60))
    552840                {
    553                   fprintf(stderr, "Overwriting header '%s' is dangerous.\n",
     841                  RTCM3Error("Overwriting header '%s' is dangerous.\n",
    554842                  lastblockstart+60);
    555843                }
     
    557845              if(pos >= MAXHEADERLINES)
    558846              {
    559                 fprintf(stderr,
    560                 "Maximum number of header lines of %d reached.\n",
     847                RTCM3Error("Maximum number of header lines of %d reached.\n",
    561848                MAXHEADERLINES);
    562849              }
    563850              else if(!strcmp("END OF HEADER", lastblockstart+60))
    564851              {
    565                 fprintf(stderr, "End of header ignored.\n");
     852                RTCM3Error("End of header ignored.\n");
    566853              }
    567854              else
     
    578865      else
    579866      {
    580         fprintf(stderr, "Could not read data from headerfile '%s'.\n",
     867        RTCM3Error("Could not read data from headerfile '%s'.\n",
    581868        Parser->headerfile);
    582869      }
     
    585872    else
    586873    {
    587       fprintf(stderr, "Could not open header datafile '%s'.\n",
     874      RTCM3Error("Could not open header datafile '%s'.\n",
    588875      Parser->headerfile);
    589876    }
     
    592879#ifndef NO_RTCM3_MAIN
    593880  for(i = 0; i < hdata.numheaders; ++i)
    594     printf("%s\n", hdata.data.unnamed[i]);
    595   printf("                                                            "
     881    RTCM3Text("%s\n", hdata.data.unnamed[i]);
     882  RTCM3Text("                                                            "
    596883  "END OF HEADER\n");
    597884#endif
     
    609896      struct converttimeinfo cti;
    610897
    611       if(!Parser->init)
    612       {
    613         HandleHeader(Parser);
    614         Parser->init = 1;
     898      if(Parser->init < NUMSTARTSKIP) /* skip first epochs to detect correct data types */
     899      {
     900        ++Parser->init;
     901
     902        if(Parser->init == NUMSTARTSKIP)
     903          HandleHeader(Parser);
     904        else
     905        {
     906          for(i = 0; i < Parser->Data.numsats; ++i)
     907            Parser->startflags |= Parser->Data.dataflags[i];
     908          continue;
     909        }
    615910      }
    616911      if(r == 2 && !Parser->validwarning)
    617912      {
    618         printf("No valid RINEX! All values are modulo 299792.458!"
     913        RTCM3Text("No valid RINEX! All values are modulo 299792.458!"
    619914        "           COMMENT\n");
    620915        Parser->validwarning = 1;
     
    623918      converttime(&cti, Parser->Data.week,
    624919      (int)floor(Parser->Data.timeofweek/1000.0));
    625       printf(" %02d %2d %2d %2d %2d %10.7f  0%3d",
     920      RTCM3Text(" %02d %2d %2d %2d %2d %10.7f  0%3d",
    626921      cti.year%100, cti.month, cti.day, cti.hour, cti.minute, cti.second
    627922      + fmod(Parser->Data.timeofweek/1000.0,1.0), Parser->Data.numsats);
     
    629924      {
    630925        if(Parser->Data.satellites[i] <= PRN_GPS_END)
    631           printf("G%02d", Parser->Data.satellites[i]);
     926          RTCM3Text("G%02d", Parser->Data.satellites[i]);
    632927        else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
    633928        && Parser->Data.satellites[i] <= PRN_GLONASS_END)
    634           printf("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
     929          RTCM3Text("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
    635930        else
    636           printf("%3d", Parser->Data.satellites[i]);
    637       }
    638       printf("\n");
     931          RTCM3Text("%3d", Parser->Data.satellites[i]);
     932      }
     933      RTCM3Text("\n");
    639934      o = 12;
    640935      j = Parser->Data.numsats - 12;
    641936      while(j > 0)
    642937      {
    643         printf("                                ");
     938        RTCM3Text("                                ");
    644939        for(i = o; i < o+12 && i < Parser->Data.numsats; ++i)
    645940        {
    646941          if(Parser->Data.satellites[i] <= PRN_GPS_END)
    647             printf("G%02d", Parser->Data.satellites[i]);
     942            RTCM3Text("G%02d", Parser->Data.satellites[i]);
    648943          else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
    649944          && Parser->Data.satellites[i] <= PRN_GLONASS_END)
    650             printf("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
     945            RTCM3Text("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
     946          else if(Parser->Data.satellites[i] >= PRN_WAAS_START
     947          && Parser->Data.satellites[i] <= PRN_WAAS_END)
     948            RTCM3Text("S%02d", Parser->Data.satellites[i] - PRN_WAAS_START);
    651949          else
    652             printf("%3d", Parser->Data.satellites[i]);
    653         }
    654         printf("\n");
     950            RTCM3Text("%3d", Parser->Data.satellites[i]);
     951        }
     952        RTCM3Text("\n");
    655953        j -= 12;
    656954        o += 12;
     
    664962          || isinf(Parser->Data.measdata[i][Parser->datapos[j]]))
    665963          { /* no or illegal data */
    666             printf("                ");
     964            RTCM3Text("                ");
    667965          }
    668966          else
     
    682980              snr = '0'+Parser->Data.snrL2[i];
    683981            }
    684             printf("%14.3f%c%c",
     982            RTCM3Text("%14.3f%c%c",
    685983            Parser->Data.measdata[i][Parser->datapos[j]],lli,snr);
    686984          }
    687985          if(j%5 == 4 || j == Parser->numdatatypes-1)
    688             printf("\n");
     986            RTCM3Text("\n");
    689987        }
    690988      }
     
    694992
    695993#ifndef NO_RTCM3_MAIN
    696 static char datestr[]     = "$Date: 2006/11/08 16:08:32 $";
     994static char datestr[]     = "$Date: 2006/11/15 12:31:31 $";
    697995
    698996/* The string, which is send as agent in HTTP request */
     
    7771075{0,0,0,0}};
    7781076#endif
    779 #define ARGOPT "d:hp:r:s:u:f:"
     1077#define ARGOPT "-d:hp:r:s:u:f:"
     1078
     1079static const char *geturl(const char *url, struct Args *args)
     1080{
     1081  static char buf[1000];
     1082  static char *Buffer = buf;
     1083  static char *Bufend = buf+sizeof(buf);
     1084
     1085  if(strncmp("ntrip:", url, 6))
     1086    return "URL must start with 'ntrip:'.";
     1087  url += 6; /* skip ntrip: */
     1088
     1089  if(*url != '@' && *url != '/')
     1090  {
     1091    /* scan for mountpoint */
     1092    args->data = Buffer;
     1093    while(*url && *url != '@' && *url != '/' && Buffer != Bufend)
     1094      *(Buffer++) = *(url++);
     1095    if(Buffer == args->data)
     1096      return "Mountpoint required.";
     1097    else if(Buffer >= Bufend-1)
     1098      return "Parsing buffer too short.";
     1099    *(Buffer++) = 0;
     1100  }
     1101
     1102  if(*url == '/') /* username and password */
     1103  {
     1104    ++url;
     1105    args->user = Buffer;
     1106    while(*url && *url != '@' && *url != ':' && Buffer != Bufend)
     1107      *(Buffer++) = *(url++);
     1108    if(Buffer == args->user)
     1109      return "Username cannot be empty.";
     1110    else if(Buffer >= Bufend-1)
     1111      return "Parsing buffer too short.";
     1112    *(Buffer++) = 0;
     1113
     1114    if(*url == ':') ++url;
     1115
     1116    args->password = Buffer;
     1117    while(*url && *url != '@' && Buffer != Bufend)
     1118      *(Buffer++) = *(url++);
     1119    if(Buffer == args->password)
     1120      return "Password cannot be empty.";
     1121    else if(Buffer >= Bufend-1)
     1122      return "Parsing buffer too short.";
     1123    *(Buffer++) = 0;
     1124  }
     1125
     1126  if(*url == '@') /* server */
     1127  {
     1128    ++url;
     1129    args->server = Buffer;
     1130    while(*url && *url != ':' && Buffer != Bufend)
     1131      *(Buffer++) = *(url++);
     1132    if(Buffer == args->server)
     1133      return "Servername cannot be empty.";
     1134    else if(Buffer >= Bufend-1)
     1135      return "Parsing buffer too short.";
     1136    *(Buffer++) = 0;
     1137
     1138    if(*url == ':')
     1139    {
     1140      char *s2 = 0;
     1141      args->port = strtol(++url, &s2, 10);
     1142      if(*s2 || args->port <= 0 || args->port > 0xFFFF)
     1143        return "Illegal port number.";
     1144      url = s2;
     1145    }
     1146  }
     1147
     1148  return *url ? "Garbage at end of server string." : 0;
     1149}
    7801150
    7811151static int getargs(int argc, char **argv, struct Args *args)
     
    8131183        res = 0;
    8141184      break;
     1185    case 1:
     1186      {
     1187        const char *err;
     1188        if((err = geturl(optarg, args)))
     1189        {
     1190          RTCM3Error("%s\n\n", err);
     1191          res = 0;
     1192        }
     1193      }
     1194      break;
    8151195    case -1: break;
    8161196    }
     
    8301210  if(!res || help)
    8311211  {
    832     fprintf(stderr, "Version %s (%s) GPL\nUsage: %s -s server -u user ...\n"
     1212    RTCM3Error("Version %s (%s) GPL\nUsage: %s -s server -u user ...\n"
    8331213    " -d " LONG_OPT("--data       ") "the requested data set\n"
    8341214    " -f " LONG_OPT("--headerfile ") "file for RINEX header information\n"
     
    8371217    " -r " LONG_OPT("--port       ") "the server port number (default 80)\n"
    8381218    " -u " LONG_OPT("--user       ") "the user name\n"
    839     , revisionstr, datestr, argv[0]);
     1219    "or using an URL:\n%s ntrip:mountpoint[/username[:password]][@server[:port]]\n"
     1220    , revisionstr, datestr, argv[0], argv[0]);
    8401221    exit(1);
    8411222  }
     
    8481229  if(!stop)
    8491230  {
    850     fprintf(stderr, "Stop signal number %d received. "
     1231    RTCM3Error("Stop signal number %d received. "
    8511232    "Trying to terminate gentle.\n", sig);
    8521233    stop = 1;
     
    8631244#endif /* __GNUC__ */
    8641245{
    865   fprintf(stderr, "Programm forcefully terminated.\n");
     1246  RTCM3Error("Programm forcefully terminated.\n");
    8661247  exit(1);
    8671248}
     
    9521333      if(i > MAXDATASIZE-40 && i < 0) /* second check for old glibc */
    9531334      {
    954         fprintf(stderr, "Requested data too long\n");
     1335        RTCM3Error("Requested data too long\n");
    9551336        exit(1);
    9561337      }
     
    9581339      if(i > MAXDATASIZE-5)
    9591340      {
    960         fprintf(stderr, "Username and/or password too long\n");
     1341        RTCM3Error("Username and/or password too long\n");
    9611342        exit(1);
    9621343      }
     
    9781359          if(numbytes < 12 || strncmp("ICY 200 OK\r\n", buf, 12))
    9791360          {
    980             fprintf(stderr, "Could not get the requested data: ");
     1361            RTCM3Error("Could not get the requested data: ");
    9811362            for(k = 0; k < numbytes && buf[k] != '\n' && buf[k] != '\r'; ++k)
    9821363            {
    983               fprintf(stderr, "%c", isprint(buf[k]) ? buf[k] : '.');
    984             }
    985             fprintf(stderr, "\n");
     1364              RTCM3Error("%c", isprint(buf[k]) ? buf[k] : '.');
     1365            }
     1366            RTCM3Error("\n");
    9861367            exit(1);
    9871368          }
     
    9921373          int z;
    9931374          for(z = 0; z < numbytes && !stop; ++z)
    994             HandleByte(&Parser, buf[z]);
     1375            HandleByte(&Parser, (unsigned int) buf[z]);
    9951376        }
    9961377      }
  • trunk/BNC/RTCM3/rtcm3torinex.h

    r282 r320  
    44/*
    55  Converter for RTCM3 data to RINEX.
    6   $Id: rtcm3torinex.h,v 1.1 2006/11/02 13:34:00 stoecker Exp $
     6  $Id: rtcm3torinex.h,v 1.3 2006/11/15 12:31:31 stoecker Exp $
    77  Copyright (C) 2005-2006 by Dirk Stoecker <stoecker@euronik.eu>
    88
     
    2727#define PRN_GLONASS_START         38
    2828#define PRN_GLONASS_END           61
     29#define PRN_WAAS_START            120
     30#define PRN_WAAS_END              138
    2931
    3032#define GNSSENTRY_C1DATA     0
     
    7779#define RINEXENTRY_NUMBER     10
    7880
    79 #define LIGHTSPEED         2.99792458e8    /* m/sec                                           */
     81#define LIGHTSPEED         2.99792458e8    /* m/sec */
    8082#define GPS_FREQU_L1       1575420000.0  /* Hz */
    8183#define GPS_FREQU_L2       1227600000.0  /* Hz */
    8284#define GPS_WAVELENGTH_L1  (LIGHTSPEED / GPS_FREQU_L1) /* m */
    8385#define GPS_WAVELENGTH_L2  (LIGHTSPEED / GPS_FREQU_L2) /* m */
     86
     87#define GLO_FREQU_L1_BASE  1602000000.0  /* Hz */
     88#define GLO_FREQU_L2_BASE  1246000000.0  /* Hz */
     89#define GLO_FREQU_L1_STEP      562500.0  /* Hz */
     90#define GLO_FREQU_L2_STEP      437500.0  /* Hz */
     91#define GLO_FREQU_L1(a)      (GLO_FREQU_L1_BASE+(a)*GLO_FREQU_L1_STEP)
     92#define GLO_FREQU_L2(a)      (GLO_FREQU_L2_BASE+(a)*GLO_FREQU_L2_STEP)
     93#define GLO_WAVELENGTH_L1(a) (LIGHTSPEED / GLO_FREQU_L1(a)) /* m */
     94#define GLO_WAVELENGTH_L2(a) (LIGHTSPEED / GLO_FREQU_L2(a)) /* m */
    8495
    8596/* unimportant, only for approx. time needed */
     
    110121  int    GPSTOW;        /* in seconds */
    111122  struct gnssdata Data;
     123  struct gnssdata DataNew;
    112124  int    size;
    113125  int    lastlockl1[64];
     
    118130  int    validwarning;
    119131  int    init;
     132  int    startflags;
    120133  const char * headerfile;
    121134};
    122135
    123 struct converttimeinfo {
    124   int second;    /* seconds of GPS time [0..59] */
    125   int minute;    /* minutes of GPS time [0..59] */
    126   int hour;      /* hour of GPS time [0..24] */
    127   int day;       /* day of GPS time [1..28..30(31)*/
    128   int month;     /* month of GPS time [1..12]*/
    129   int year;      /* year of GPS time [1980..] */
    130 };
     136#ifndef PRINTFARG
     137#ifdef __GNUC__
     138#define PRINTFARG(a,b) __attribute__ ((format(printf, a, b)))
     139#else /* __GNUC__ */
     140#define PRINTFARG(a,b)
     141#endif /* __GNUC__ */
     142#endif /* PRINTFARG */
    131143
    132144void HandleHeader(struct RTCM3ParserData *Parser);
    133145int RTCM3Parser(struct RTCM3ParserData *handle);
    134146void HandleByte(struct RTCM3ParserData *Parser, unsigned int byte);
    135 void converttime(struct converttimeinfo *c, int week, int tow);
     147void PRINTFARG(1,2) RTCM3Error(const char *fmt, ...);
     148void PRINTFARG(1,2) RTCM3Text(const char *fmt, ...);
    136149
    137150#endif /* RTCM3TORINEX_H */
Note: See TracChangeset for help on using the changeset viewer.