Changeset 6812 in ntrip for trunk/BNC/src/bncutils.cpp


Ignore:
Timestamp:
May 5, 2015, 3:44:39 PM (9 years ago)
Author:
stoecker
Message:

integrate RTCM3 parsing into BNC and directly fill target structures, add doxygen documentation

Location:
trunk/BNC/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src

    • Property svn:ignore
      •  

        old new  
        55debug
        66release
         7html
  • trunk/BNC/src/bncutils.cpp

    r6800 r6812  
    5353
    5454using namespace std;
     55
     56struct leapseconds { /* specify the day of leap second */
     57  int day;        /* this is the day, where 23:59:59 exists 2 times */
     58  int month;      /* not the next day! */
     59  int year;
     60  int taicount;
     61};
     62static const int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
     63static const struct leapseconds leap[] = {
     64/*{31, 12, 1971, 10},*/
     65/*{30, 06, 1972, 11},*/
     66/*{31, 12, 1972, 12},*/
     67/*{31, 12, 1973, 13},*/
     68/*{31, 12, 1974, 14},*/
     69/*{31, 12, 1975, 15},*/
     70/*{31, 12, 1976, 16},*/
     71/*{31, 12, 1977, 17},*/
     72/*{31, 12, 1978, 18},*/
     73/*{31, 12, 1979, 19},*/
     74{30, 06, 1981,20},
     75{30, 06, 1982,21},
     76{30, 06, 1983,22},
     77{30, 06, 1985,23},
     78{31, 12, 1987,24},
     79{31, 12, 1989,25},
     80{31, 12, 1990,26},
     81{30, 06, 1992,27},
     82{30, 06, 1993,28},
     83{30, 06, 1994,29},
     84{31, 12, 1995,30},
     85{30, 06, 1997,31},
     86{31, 12, 1998,32},
     87{31, 12, 2005,33},
     88{31, 12, 2008,34},
     89{30, 06, 2012,35},
     90{30, 06, 2015,36},
     91{0,0,0,0} /* end marker */
     92};
     93
     94#define GPSLEAPSTART    19 /* 19 leap seconds existed at 6.1.1980 */
     95
     96static int longyear(int year, int month)
     97{
     98  if(!(year % 4) && (!(year % 400) || (year % 100)))
     99  {
     100    if(!month || month == 2)
     101      return 1;
     102  }
     103  return 0;
     104}
     105
     106int gnumleap(int year, int month, int day)
     107{
     108  int ls = 0;
     109  const struct leapseconds *l;
     110
     111  for(l = leap; l->taicount && year >= l->year; ++l)
     112  {
     113    if(year > l->year || month > l->month || (month == l->month && day > l->day))
     114       ls = l->taicount - GPSLEAPSTART;
     115  }
     116  return ls;
     117}
     118
     119/* Convert Moscow time into UTC (fixnumleap == 1) or GPS (fixnumleap == 0) */
     120void updatetime(int *week, int *secOfWeek, int mSecOfWeek, bool fixnumleap)
     121{
     122  int y,m,d,k,l, nul;
     123  unsigned int j = *week*(7*24*60*60) + *secOfWeek + 5*24*60*60+3*60*60;
     124  int glo_daynumber = 0, glo_timeofday;
     125  for(y = 1980; j >= (unsigned int)(k = (l = (365+longyear(y,0)))*24*60*60)
     126  + gnumleap(y+1,1,1); ++y)
     127  {
     128    j -= k; glo_daynumber += l;
     129  }
     130  for(m = 1; j >= (unsigned int)(k = (l = months[m]+longyear(y, m))*24*60*60)
     131  + gnumleap(y, m+1, 1); ++m)
     132  {
     133    j -= k; glo_daynumber += l;
     134  }
     135  for(d = 1; j >= 24UL*60UL*60UL + gnumleap(y, m, d+1); ++d)
     136    j -= 24*60*60;
     137  glo_daynumber -= 16*365+4-d;
     138  nul = gnumleap(y, m, d);
     139  glo_timeofday = j-nul;
     140
     141  // original version
     142  // if(mSecOfWeek < 5*60*1000 && glo_timeofday > 23*60*60)
     143  //   *secOfWeek += 24*60*60;
     144  // else if(glo_timeofday < 5*60 && mSecOfWeek > 23*60*60*1000)
     145  //   *secOfWeek -= 24*60*60;
     146
     147  // new version
     148  if(mSecOfWeek < 4*60*60*1000 && glo_timeofday > 20*60*60)
     149    *secOfWeek += 24*60*60;
     150  else if(glo_timeofday < 4*60*60 && mSecOfWeek > 20*60*60*1000)
     151    *secOfWeek -= 24*60*60;
     152
     153  *secOfWeek += mSecOfWeek/1000-glo_timeofday;
     154  if(fixnumleap)
     155    *secOfWeek -= nul;
     156  if(*secOfWeek < 0) {*secOfWeek += 24*60*60*7; --*week; }
     157  if(*secOfWeek >= 24*60*60*7) {*secOfWeek -= 24*60*60*7; ++*week; }
     158}
    55159
    56160//
Note: See TracChangeset for help on using the changeset viewer.