Changeset 318 in ntrip for trunk/rtcm3torinex


Ignore:
Timestamp:
Nov 15, 2006, 1:31:31 PM (17 years ago)
Author:
stoecker
Message:

some fixed, better error support

Location:
trunk/rtcm3torinex
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/rtcm3torinex/rtcm3torinex.c

    r287 r318  
    11/*
    22  Converter for RTCM3 data to RINEX.
    3   $Id: rtcm3torinex.c,v 1.8 2006/11/03 11:50:11 stoecker Exp $
     3  $Id: rtcm3torinex.c,v 1.9 2006/11/08 17:11:08 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.8 $";
     53static char revisionstr[] = "$Revision: 1.9 $";
    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
     
    638639}
    639640
     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
    640660void HandleHeader(struct RTCM3ParserData *Parser)
    641661{
     
    643663  char thebuffer[MAXHEADERBUFFERSIZE];
    644664  char *buffer = thebuffer;
    645   int buffersize = sizeof(thebuffer);
     665  size_t buffersize = sizeof(thebuffer);
    646666  int i;
    647667
     
    721741    }
    722742
    723     int flags = 0;
     743    int flags = Parser->startflags;
    724744    int data[RINEXENTRY_NUMBER];
    725745    char tbuffer[6*RINEXENTRY_NUMBER+1];
     
    778798    if((fh = fopen(Parser->headerfile, "r")))
    779799    {
    780       int siz;
     800      size_t siz;
    781801      char *lastblockstart;
    782802      if((siz = fread(buffer, 1, buffersize-1, fh)) > 0)
     
    785805        if(siz == buffersize)
    786806        {
    787           fprintf(stderr, "Header file is too large. Only %d bytes read.",
     807          RTCM3Error("Header file is too large. Only %d bytes read.",
    788808          siz);
    789809        }
     
    792812        /* overwrites entries, except for comments */
    793813        lastblockstart = buffer;
    794         for(i = 0; i < siz; ++i)
     814        for(i = 0; i < (int)siz; ++i)
    795815        {
    796816          if(buffer[i] == '\n')
     
    803823              *(end--) = 0;
    804824            if(end-lastblockstart < 60+5) /* short line */
    805               fprintf(stderr, "Short Header line '%s' ignored.\n", lastblockstart);
     825              RTCM3Error("Short Header line '%s' ignored.\n", lastblockstart);
    806826            else
    807827            {
     
    819839                || !strcmp("TIME OF FIRST OBS", lastblockstart+60))
    820840                {
    821                   fprintf(stderr, "Overwriting header '%s' is dangerous.\n",
     841                  RTCM3Error("Overwriting header '%s' is dangerous.\n",
    822842                  lastblockstart+60);
    823843                }
     
    825845              if(pos >= MAXHEADERLINES)
    826846              {
    827                 fprintf(stderr,
    828                 "Maximum number of header lines of %d reached.\n",
     847                RTCM3Error("Maximum number of header lines of %d reached.\n",
    829848                MAXHEADERLINES);
    830849              }
    831850              else if(!strcmp("END OF HEADER", lastblockstart+60))
    832851              {
    833                 fprintf(stderr, "End of header ignored.\n");
     852                RTCM3Error("End of header ignored.\n");
    834853              }
    835854              else
     
    846865      else
    847866      {
    848         fprintf(stderr, "Could not read data from headerfile '%s'.\n",
     867        RTCM3Error("Could not read data from headerfile '%s'.\n",
    849868        Parser->headerfile);
    850869      }
     
    853872    else
    854873    {
    855       fprintf(stderr, "Could not open header datafile '%s'.\n",
     874      RTCM3Error("Could not open header datafile '%s'.\n",
    856875      Parser->headerfile);
    857876    }
     
    860879#ifndef NO_RTCM3_MAIN
    861880  for(i = 0; i < hdata.numheaders; ++i)
    862     printf("%s\n", hdata.data.unnamed[i]);
    863   printf("                                                            "
     881    RTCM3Text("%s\n", hdata.data.unnamed[i]);
     882  RTCM3Text("                                                            "
    864883  "END OF HEADER\n");
    865884#endif
     
    877896      struct converttimeinfo cti;
    878897
    879       if(!Parser->init)
    880       {
    881         HandleHeader(Parser);
    882         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        }
    883910      }
    884911      if(r == 2 && !Parser->validwarning)
    885912      {
    886         printf("No valid RINEX! All values are modulo 299792.458!"
     913        RTCM3Text("No valid RINEX! All values are modulo 299792.458!"
    887914        "           COMMENT\n");
    888915        Parser->validwarning = 1;
     
    891918      converttime(&cti, Parser->Data.week,
    892919      (int)floor(Parser->Data.timeofweek/1000.0));
    893       printf(" %02d %2d %2d %2d %2d %10.7f  0%3d",
     920      RTCM3Text(" %02d %2d %2d %2d %2d %10.7f  0%3d",
    894921      cti.year%100, cti.month, cti.day, cti.hour, cti.minute, cti.second
    895922      + fmod(Parser->Data.timeofweek/1000.0,1.0), Parser->Data.numsats);
     
    897924      {
    898925        if(Parser->Data.satellites[i] <= PRN_GPS_END)
    899           printf("G%02d", Parser->Data.satellites[i]);
     926          RTCM3Text("G%02d", Parser->Data.satellites[i]);
    900927        else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
    901928        && Parser->Data.satellites[i] <= PRN_GLONASS_END)
    902           printf("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
     929          RTCM3Text("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
    903930        else
    904           printf("%3d", Parser->Data.satellites[i]);
    905       }
    906       printf("\n");
     931          RTCM3Text("%3d", Parser->Data.satellites[i]);
     932      }
     933      RTCM3Text("\n");
    907934      o = 12;
    908935      j = Parser->Data.numsats - 12;
    909936      while(j > 0)
    910937      {
    911         printf("                                ");
     938        RTCM3Text("                                ");
    912939        for(i = o; i < o+12 && i < Parser->Data.numsats; ++i)
    913940        {
    914941          if(Parser->Data.satellites[i] <= PRN_GPS_END)
    915             printf("G%02d", Parser->Data.satellites[i]);
     942            RTCM3Text("G%02d", Parser->Data.satellites[i]);
    916943          else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
    917944          && Parser->Data.satellites[i] <= PRN_GLONASS_END)
    918             printf("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
     945            RTCM3Text("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
    919946          else if(Parser->Data.satellites[i] >= PRN_WAAS_START
    920947          && Parser->Data.satellites[i] <= PRN_WAAS_END)
    921             printf("S%02d", Parser->Data.satellites[i] - PRN_WAAS_START);
     948            RTCM3Text("S%02d", Parser->Data.satellites[i] - PRN_WAAS_START);
    922949          else
    923             printf("%3d", Parser->Data.satellites[i]);
    924         }
    925         printf("\n");
     950            RTCM3Text("%3d", Parser->Data.satellites[i]);
     951        }
     952        RTCM3Text("\n");
    926953        j -= 12;
    927954        o += 12;
     
    935962          || isinf(Parser->Data.measdata[i][Parser->datapos[j]]))
    936963          { /* no or illegal data */
    937             printf("                ");
     964            RTCM3Text("                ");
    938965          }
    939966          else
     
    953980              snr = '0'+Parser->Data.snrL2[i];
    954981            }
    955             printf("%14.3f%c%c",
     982            RTCM3Text("%14.3f%c%c",
    956983            Parser->Data.measdata[i][Parser->datapos[j]],lli,snr);
    957984          }
    958985          if(j%5 == 4 || j == Parser->numdatatypes-1)
    959             printf("\n");
     986            RTCM3Text("\n");
    960987        }
    961988      }
     
    965992
    966993#ifndef NO_RTCM3_MAIN
    967 static char datestr[]     = "$Date: 2006/11/03 11:50:11 $";
     994static char datestr[]     = "$Date: 2006/11/08 17:11:08 $";
    968995
    969996/* The string, which is send as agent in HTTP request */
     
    11611188        if((err = geturl(optarg, args)))
    11621189        {
    1163           fprintf(stderr, "%s\n\n", err);
     1190          RTCM3Error("%s\n\n", err);
    11641191          res = 0;
    11651192        }
     
    11831210  if(!res || help)
    11841211  {
    1185     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"
    11861213    " -d " LONG_OPT("--data       ") "the requested data set\n"
    11871214    " -f " LONG_OPT("--headerfile ") "file for RINEX header information\n"
     
    12021229  if(!stop)
    12031230  {
    1204     fprintf(stderr, "Stop signal number %d received. "
     1231    RTCM3Error("Stop signal number %d received. "
    12051232    "Trying to terminate gentle.\n", sig);
    12061233    stop = 1;
     
    12171244#endif /* __GNUC__ */
    12181245{
    1219   fprintf(stderr, "Programm forcefully terminated.\n");
     1246  RTCM3Error("Programm forcefully terminated.\n");
    12201247  exit(1);
    12211248}
     
    13061333      if(i > MAXDATASIZE-40 && i < 0) /* second check for old glibc */
    13071334      {
    1308         fprintf(stderr, "Requested data too long\n");
     1335        RTCM3Error("Requested data too long\n");
    13091336        exit(1);
    13101337      }
     
    13121339      if(i > MAXDATASIZE-5)
    13131340      {
    1314         fprintf(stderr, "Username and/or password too long\n");
     1341        RTCM3Error("Username and/or password too long\n");
    13151342        exit(1);
    13161343      }
     
    13321359          if(numbytes < 12 || strncmp("ICY 200 OK\r\n", buf, 12))
    13331360          {
    1334             fprintf(stderr, "Could not get the requested data: ");
     1361            RTCM3Error("Could not get the requested data: ");
    13351362            for(k = 0; k < numbytes && buf[k] != '\n' && buf[k] != '\r'; ++k)
    13361363            {
    1337               fprintf(stderr, "%c", isprint(buf[k]) ? buf[k] : '.');
    1338             }
    1339             fprintf(stderr, "\n");
     1364              RTCM3Error("%c", isprint(buf[k]) ? buf[k] : '.');
     1365            }
     1366            RTCM3Error("\n");
    13401367            exit(1);
    13411368          }
     
    13461373          int z;
    13471374          for(z = 0; z < numbytes && !stop; ++z)
    1348             HandleByte(&Parser, buf[z]);
     1375            HandleByte(&Parser, (unsigned int) buf[z]);
    13491376        }
    13501377      }
  • trunk/rtcm3torinex/rtcm3torinex.h

    r270 r318  
    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.2 2006/11/03 11:50:11 stoecker Exp $
    77  Copyright (C) 2005-2006 by Dirk Stoecker <stoecker@euronik.eu>
    88
     
    130130  int    validwarning;
    131131  int    init;
     132  int    startflags;
    132133  const char * headerfile;
    133134};
     135
     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 */
    134143
    135144void HandleHeader(struct RTCM3ParserData *Parser);
    136145int RTCM3Parser(struct RTCM3ParserData *handle);
    137146void HandleByte(struct RTCM3ParserData *Parser, unsigned int byte);
     147void PRINTFARG(1,2) RTCM3Error(const char *fmt, ...);
     148void PRINTFARG(1,2) RTCM3Text(const char *fmt, ...);
    138149
    139150#endif /* RTCM3TORINEX_H */
  • trunk/rtcm3torinex/rtcm3torinex.txt

    r29 r318  
    22
    33The program rtcm3torinex is an real-time converter from NTRIP streamed RTCM3
    4 data into the RINEX format. The generated RINEX is somewhat limited due to
    5 the streaming character of the conversion:
     4data into the RINEX format.
     5
     6RTCM3 defines a number of message types. Among them are the following:
     7
     8Message
     9Type  Contains information about
     10--------------------------------------------------------------------------
     111001  GPS L1 code and phase
     121002  GPS L1 code and phase and ambiguities and carrier to noise ratio
     131003  GPS L1 and L1 code and phase
     141004  GPS L1 and L2 code and phase and ambiguities and carrier to noise ratio
     151005  Station coordinates XZY for antenna reference point
     161006  Station coordinates XYZ for antenna reference point and antenna height
     171007  Antenna descriptor and ID
     181008  Antenna serial number
     191009  GLONASS L1 code and phase
     201010  GLONASS L1 code and phase and ambiguities and carrier to noise ratio
     211011  GLONASS L1 and L1 code and phase
     221012  GLONASS L1 and L2 code and phase and ambiguities and carrier to noise ratio
     231013  Modified julian date, leep second, configured message types and intervall
     241014-1017 Network RTK (MAK) messages (under development)
     251019  GPS Ephemeris (under development)
     261020  GLONASS Ephemeris (under development)
     274088-4095 Proprietary messages (under development)
     28
     29Note that this version of rtcm3torinex only handles RTCM3 message types 1001,
     301002, 1003, 1004, 1009, 1010, 1011 and 1012.
     31
     32The generated RINEX is somewhat limited due to the streaming character of the
     33conversion:
     34
    635 - Header records can only represent data, which is known after receiving the
    736   very first epoch. Data rate, position, number of observations and any such
     
    1039   the observables, which exist in the first epoch are outputted. If there
    1140   are new observables later on, these are ignored.
    12  - Only known data types are interpreted. This means only GPS data at the
     41 - Only known message types are interpreted. This means only GPS data at the
    1342   moment. Send me new RTCM3 data files and data support can be improved.
    1443   See contact address at the end of this document.
     
    3261must be used to specify the RTCM3 input data stream. If it is not given, you
    3362will be shown the source table of the selected NTRIP caster.
     63
     64Alternatively a single text of the form
     65"ntrip:mountpoint[/username[:password]][@server[:port]]"
     66can be used. Everything in brackets is optional.
    3467
    3568Additionally the argument --headerfile can be used to provide additional header
     
    5689You will not get corrupted RINEX files.
    5790
    58 Contact me with your comments, suggestions, improvements, patches, ...
     91When compiling the program with older gcc versions running the `make'
     92command, you may receive an informative error message saying
    5993
    60 Dirk Stöcker
    61 EuroNav Service GmbH
    62 http://www.euronav.de/
    63 stoecker@euronav.de
    64 2006-01-12
     94rtcm3torinex.c: In function `signalhandler_alarm':
     95rtcm3torinex.c:1240: warning: `noreturn' function does return
     96
     97This is most likely a compiler problem which only concerns the optimization
     98and is thus not critical. New compilers will not show this problem.
     99
     100Program written by
     101
     102Dirk Stoecker
     103Euronik GmbH
     104http://www.euronik.eu/
     105
     106for
     107
     108Federal Agency for Cartography and Geodesy (BKG)
     109Richard-Strauss-Allee 11
     110D-60598 Frankfurt
     111http://igs.bkg.bund.de/index_ntrip.htm
     112
     113Contact Dirk Stoecker [stoecker@euronik.eu] or [euref-ip@bkg.bund.de]
     114with your comments, suggestions, improvements, patches, ...
Note: See TracChangeset for help on using the changeset viewer.