[27] | 1 | /*
|
---|
| 2 | Converter for RTCM3 data to RINEX.
|
---|
[2487] | 3 | $Id: rtcm3torinex.c 5553 2013-11-19 14:41:34Z stoecker $
|
---|
[4417] | 4 | Copyright (C) 2005-2012 by Dirk Stöcker <stoecker@alberding.eu>
|
---|
[27] | 5 |
|
---|
[268] | 6 | This software is a complete NTRIP-RTCM3 to RINEX converter as well as
|
---|
| 7 | a module of the BNC tool for multiformat conversion. Contact Dirk
|
---|
[744] | 8 | Stöcker for suggestions and bug reports related to the RTCM3 to RINEX
|
---|
[268] | 9 | conversion problems and the author of BNC for all the other problems.
|
---|
| 10 |
|
---|
[27] | 11 | This program is free software; you can redistribute it and/or modify
|
---|
| 12 | it under the terms of the GNU General Public License as published by
|
---|
| 13 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | (at your option) any later version.
|
---|
| 15 |
|
---|
| 16 | This program is distributed in the hope that it will be useful,
|
---|
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | GNU General Public License for more details.
|
---|
| 20 |
|
---|
| 21 | You should have received a copy of the GNU General Public License
|
---|
| 22 | along with this program; if not, write to the Free Software
|
---|
| 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 24 | or read http://www.gnu.org/licenses/gpl.txt
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | #include <ctype.h>
|
---|
| 28 | #include <errno.h>
|
---|
| 29 | #include <math.h>
|
---|
| 30 | #include <signal.h>
|
---|
[318] | 31 | #include <stdarg.h>
|
---|
[27] | 32 | #include <stdio.h>
|
---|
| 33 | #include <stdlib.h>
|
---|
| 34 | #include <string.h>
|
---|
| 35 | #include <sys/types.h>
|
---|
| 36 | #include <time.h>
|
---|
| 37 | #include <unistd.h>
|
---|
| 38 |
|
---|
[268] | 39 | #ifndef NO_RTCM3_MAIN
|
---|
| 40 | #include <getopt.h>
|
---|
| 41 | #include <netdb.h>
|
---|
| 42 | #include <netinet/in.h>
|
---|
| 43 | #include <sys/socket.h>
|
---|
| 44 | #endif
|
---|
[27] | 45 |
|
---|
[269] | 46 | #ifndef sparc
|
---|
| 47 | #include <stdint.h>
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
[2346] | 50 | #ifndef isinf
|
---|
| 51 | #define isinf(x) 0
|
---|
| 52 | #endif
|
---|
| 53 |
|
---|
[268] | 54 | #include "rtcm3torinex.h"
|
---|
[27] | 55 |
|
---|
| 56 | /* CVS revision and version */
|
---|
[2487] | 57 | static char revisionstr[] = "$Revision: 5553 $";
|
---|
[27] | 58 |
|
---|
[439] | 59 | #ifndef COMPILEDATE
|
---|
| 60 | #define COMPILEDATE " built " __DATE__
|
---|
| 61 | #endif
|
---|
| 62 |
|
---|
[27] | 63 | static uint32_t CRC24(long size, const unsigned char *buf)
|
---|
| 64 | {
|
---|
| 65 | uint32_t crc = 0;
|
---|
| 66 | int i;
|
---|
| 67 |
|
---|
| 68 | while(size--)
|
---|
| 69 | {
|
---|
| 70 | crc ^= (*buf++) << (16);
|
---|
| 71 | for(i = 0; i < 8; i++)
|
---|
| 72 | {
|
---|
| 73 | crc <<= 1;
|
---|
| 74 | if(crc & 0x1000000)
|
---|
| 75 | crc ^= 0x01864cfb;
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | return crc;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | static int GetMessage(struct RTCM3ParserData *handle)
|
---|
| 82 | {
|
---|
| 83 | unsigned char *m, *e;
|
---|
| 84 | int i;
|
---|
| 85 |
|
---|
| 86 | m = handle->Message+handle->SkipBytes;
|
---|
| 87 | e = handle->Message+handle->MessageSize;
|
---|
| 88 | handle->NeedBytes = handle->SkipBytes = 0;
|
---|
| 89 | while(e-m >= 3)
|
---|
| 90 | {
|
---|
| 91 | if(m[0] == 0xD3)
|
---|
| 92 | {
|
---|
| 93 | handle->size = ((m[1]&3)<<8)|m[2];
|
---|
| 94 | if(e-m >= handle->size+6)
|
---|
| 95 | {
|
---|
| 96 | if((uint32_t)((m[3+handle->size]<<16)|(m[3+handle->size+1]<<8)
|
---|
| 97 | |(m[3+handle->size+2])) == CRC24(handle->size+3, m))
|
---|
| 98 | {
|
---|
| 99 | handle->SkipBytes = handle->size;
|
---|
| 100 | break;
|
---|
| 101 | }
|
---|
| 102 | else
|
---|
| 103 | ++m;
|
---|
| 104 | }
|
---|
| 105 | else
|
---|
| 106 | {
|
---|
| 107 | handle->NeedBytes = handle->size+6;
|
---|
| 108 | break;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | else
|
---|
| 112 | ++m;
|
---|
| 113 | }
|
---|
| 114 | if(e-m < 3)
|
---|
| 115 | handle->NeedBytes = 3;
|
---|
[744] | 116 |
|
---|
[27] | 117 | /* copy buffer to front */
|
---|
| 118 | i = m - handle->Message;
|
---|
| 119 | if(i && m < e)
|
---|
[318] | 120 | memmove(handle->Message, m, (size_t)(handle->MessageSize-i));
|
---|
[27] | 121 | handle->MessageSize -= i;
|
---|
| 122 |
|
---|
| 123 | return !handle->NeedBytes;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | #define LOADBITS(a) \
|
---|
| 127 | { \
|
---|
| 128 | while((a) > numbits) \
|
---|
| 129 | { \
|
---|
| 130 | if(!size--) break; \
|
---|
| 131 | bitfield = (bitfield<<8)|*(data++); \
|
---|
| 132 | numbits += 8; \
|
---|
| 133 | } \
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | /* extract bits from data stream
|
---|
| 137 | b = variable to store result, a = number of bits */
|
---|
[2860] | 138 | #define GETBITS64(b, a) \
|
---|
| 139 | { \
|
---|
| 140 | if(((a) > 56) && ((a)-56) > numbits) \
|
---|
| 141 | { \
|
---|
| 142 | uint64_t x; \
|
---|
| 143 | GETBITS(x, 56) \
|
---|
| 144 | LOADBITS((a)-56) \
|
---|
| 145 | b = ((x<<((a)-56)) | (bitfield<<(sizeof(bitfield)*8-numbits)) \
|
---|
| 146 | >>(sizeof(bitfield)*8-((a)-56))); \
|
---|
| 147 | numbits -= ((a)-56); \
|
---|
| 148 | } \
|
---|
| 149 | else \
|
---|
| 150 | { \
|
---|
| 151 | GETBITS(b, a) \
|
---|
| 152 | } \
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | /* extract bits from data stream
|
---|
| 156 | b = variable to store result, a = number of bits */
|
---|
[27] | 157 | #define GETBITS(b, a) \
|
---|
| 158 | { \
|
---|
| 159 | LOADBITS(a) \
|
---|
| 160 | b = (bitfield<<(64-numbits))>>(64-(a)); \
|
---|
| 161 | numbits -= (a); \
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[2756] | 164 | /* extract bits from data stream
|
---|
| 165 | b = variable to store result, a = number of bits */
|
---|
| 166 | #define GETBITSFACTOR(b, a, c) \
|
---|
| 167 | { \
|
---|
| 168 | LOADBITS(a) \
|
---|
| 169 | b = ((bitfield<<(sizeof(bitfield)*8-numbits))>>(sizeof(bitfield)*8-(a)))*(c); \
|
---|
| 170 | numbits -= (a); \
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[502] | 173 | /* extract floating value from data stream
|
---|
| 174 | b = variable to store result, a = number of bits */
|
---|
| 175 | #define GETFLOAT(b, a, c) \
|
---|
| 176 | { \
|
---|
| 177 | LOADBITS(a) \
|
---|
| 178 | b = ((double)((bitfield<<(64-numbits))>>(64-(a))))*(c); \
|
---|
| 179 | numbits -= (a); \
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | /* extract signed floating value from data stream
|
---|
| 183 | b = variable to store result, a = number of bits */
|
---|
| 184 | #define GETFLOATSIGN(b, a, c) \
|
---|
| 185 | { \
|
---|
| 186 | LOADBITS(a) \
|
---|
| 187 | b = ((double)(((int64_t)(bitfield<<(64-numbits)))>>(64-(a))))*(c); \
|
---|
| 188 | numbits -= (a); \
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[27] | 191 | /* extract bits from data stream
|
---|
| 192 | b = variable to store result, a = number of bits */
|
---|
| 193 | #define GETBITSSIGN(b, a) \
|
---|
| 194 | { \
|
---|
| 195 | LOADBITS(a) \
|
---|
| 196 | b = ((int64_t)(bitfield<<(64-numbits)))>>(64-(a)); \
|
---|
| 197 | numbits -= (a); \
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[502] | 200 | #define GETFLOATSIGNM(b, a, c) \
|
---|
| 201 | { int l; \
|
---|
| 202 | LOADBITS(a) \
|
---|
| 203 | l = (bitfield<<(64-numbits))>>(64-1); \
|
---|
| 204 | b = ((double)(((bitfield<<(64-(numbits-1))))>>(64-(a-1))))*(c); \
|
---|
| 205 | numbits -= (a); \
|
---|
| 206 | if(l) b *= -1.0; \
|
---|
| 207 | }
|
---|
| 208 |
|
---|
[27] | 209 | #define SKIPBITS(b) { LOADBITS(b) numbits -= (b); }
|
---|
| 210 |
|
---|
[1237] | 211 | /* extract byte-aligned byte from data stream,
|
---|
| 212 | b = variable to store size, s = variable to store string pointer */
|
---|
| 213 | #define GETSTRING(b, s) \
|
---|
| 214 | { \
|
---|
| 215 | b = *(data++); \
|
---|
| 216 | s = (char *) data; \
|
---|
| 217 | data += b; \
|
---|
| 218 | size -= b+1; \
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[270] | 221 | struct leapseconds { /* specify the day of leap second */
|
---|
| 222 | int day; /* this is the day, where 23:59:59 exists 2 times */
|
---|
| 223 | int month; /* not the next day! */
|
---|
| 224 | int year;
|
---|
| 225 | int taicount;
|
---|
[744] | 226 | };
|
---|
[270] | 227 | static const int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
|
---|
| 228 | static const struct leapseconds leap[] = {
|
---|
[4367] | 229 | /*{31, 12, 1971, 10},*/
|
---|
| 230 | /*{30, 06, 1972, 11},*/
|
---|
[270] | 231 | /*{31, 12, 1972, 12},*/
|
---|
| 232 | /*{31, 12, 1973, 13},*/
|
---|
| 233 | /*{31, 12, 1974, 14},*/
|
---|
| 234 | /*{31, 12, 1975, 15},*/
|
---|
| 235 | /*{31, 12, 1976, 16},*/
|
---|
| 236 | /*{31, 12, 1977, 17},*/
|
---|
| 237 | /*{31, 12, 1978, 18},*/
|
---|
| 238 | /*{31, 12, 1979, 19},*/
|
---|
| 239 | {30, 06, 1981,20},
|
---|
| 240 | {30, 06, 1982,21},
|
---|
| 241 | {30, 06, 1983,22},
|
---|
| 242 | {30, 06, 1985,23},
|
---|
| 243 | {31, 12, 1987,24},
|
---|
| 244 | {31, 12, 1989,25},
|
---|
| 245 | {31, 12, 1990,26},
|
---|
| 246 | {30, 06, 1992,27},
|
---|
| 247 | {30, 06, 1993,28},
|
---|
| 248 | {30, 06, 1994,29},
|
---|
| 249 | {31, 12, 1995,30},
|
---|
| 250 | {30, 06, 1997,31},
|
---|
| 251 | {31, 12, 1998,32},
|
---|
| 252 | {31, 12, 2005,33},
|
---|
[959] | 253 | {31, 12, 2008,34},
|
---|
[4365] | 254 | {30, 06, 2012,35},
|
---|
[270] | 255 | {0,0,0,0} /* end marker */
|
---|
| 256 | };
|
---|
[4370] | 257 | #define LEAPSECONDS 16 /* only needed for approx. time */
|
---|
[270] | 258 | #define GPSLEAPSTART 19 /* 19 leap seconds existed at 6.1.1980 */
|
---|
| 259 |
|
---|
| 260 | static int longyear(int year, int month)
|
---|
| 261 | {
|
---|
| 262 | if(!(year % 4) && (!(year % 400) || (year % 100)))
|
---|
| 263 | {
|
---|
| 264 | if(!month || month == 2)
|
---|
| 265 | return 1;
|
---|
| 266 | }
|
---|
| 267 | return 0;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
[2346] | 270 | int gnumleap(int year, int month, int day)
|
---|
[270] | 271 | {
|
---|
| 272 | int ls = 0;
|
---|
| 273 | const struct leapseconds *l;
|
---|
| 274 |
|
---|
| 275 | for(l = leap; l->taicount && year >= l->year; ++l)
|
---|
| 276 | {
|
---|
[1824] | 277 | if(year > l->year || month > l->month || (month == l->month && day > l->day))
|
---|
[270] | 278 | ls = l->taicount - GPSLEAPSTART;
|
---|
| 279 | }
|
---|
| 280 | return ls;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[2346] | 283 | /* Convert Moscow time into UTC (fixnumleap == 1) or GPS (fixnumleap == 0) */
|
---|
| 284 | void updatetime(int *week, int *secOfWeek, int mSecOfWeek, int fixnumleap)
|
---|
[270] | 285 | {
|
---|
[502] | 286 | int y,m,d,k,l, nul;
|
---|
[2346] | 287 | unsigned int j = *week*(7*24*60*60) + *secOfWeek + 5*24*60*60+3*60*60;
|
---|
[270] | 288 | int glo_daynumber = 0, glo_timeofday;
|
---|
| 289 | for(y = 1980; j >= (unsigned int)(k = (l = (365+longyear(y,0)))*24*60*60)
|
---|
| 290 | + gnumleap(y+1,1,1); ++y)
|
---|
| 291 | {
|
---|
| 292 | j -= k; glo_daynumber += l;
|
---|
| 293 | }
|
---|
| 294 | for(m = 1; j >= (unsigned int)(k = (l = months[m]+longyear(y, m))*24*60*60)
|
---|
| 295 | + gnumleap(y, m+1, 1); ++m)
|
---|
| 296 | {
|
---|
| 297 | j -= k; glo_daynumber += l;
|
---|
| 298 | }
|
---|
| 299 | for(d = 1; j >= 24UL*60UL*60UL + gnumleap(y, m, d+1); ++d)
|
---|
| 300 | j -= 24*60*60;
|
---|
| 301 | glo_daynumber -= 16*365+4-d;
|
---|
[502] | 302 | nul = gnumleap(y, m, d);
|
---|
| 303 | glo_timeofday = j-nul;
|
---|
[270] | 304 |
|
---|
[3270] | 305 | // original version
|
---|
| 306 | // if(mSecOfWeek < 5*60*1000 && glo_timeofday > 23*60*60)
|
---|
| 307 | // *secOfWeek += 24*60*60;
|
---|
| 308 | // else if(glo_timeofday < 5*60 && mSecOfWeek > 23*60*60*1000)
|
---|
| 309 | // *secOfWeek -= 24*60*60;
|
---|
| 310 |
|
---|
| 311 | // new version
|
---|
| 312 | if(mSecOfWeek < 4*60*60*1000 && glo_timeofday > 20*60*60)
|
---|
[2346] | 313 | *secOfWeek += 24*60*60;
|
---|
[3270] | 314 | else if(glo_timeofday < 4*60*60 && mSecOfWeek > 20*60*60*1000)
|
---|
[2346] | 315 | *secOfWeek -= 24*60*60;
|
---|
[3270] | 316 |
|
---|
[2346] | 317 | *secOfWeek += mSecOfWeek/1000-glo_timeofday;
|
---|
[502] | 318 | if(fixnumleap)
|
---|
[2346] | 319 | *secOfWeek -= nul;
|
---|
| 320 | if(*secOfWeek < 0) {*secOfWeek += 24*60*60*7; --*week; }
|
---|
| 321 | if(*secOfWeek >= 24*60*60*7) {*secOfWeek -= 24*60*60*7; ++*week; }
|
---|
[270] | 322 | }
|
---|
| 323 |
|
---|
[268] | 324 | int RTCM3Parser(struct RTCM3ParserData *handle)
|
---|
[27] | 325 | {
|
---|
| 326 | int ret=0;
|
---|
| 327 |
|
---|
[1237] | 328 | #ifdef NO_RTCM3_MAIN
|
---|
| 329 | if(GetMessage(handle)) /* don't repeat */
|
---|
| 330 | #else
|
---|
[27] | 331 | while(!ret && GetMessage(handle))
|
---|
[1237] | 332 | #endif /* NO_RTCM3_MAIN */
|
---|
[27] | 333 | {
|
---|
| 334 | /* using 64 bit integer types, as it is much easier than handling
|
---|
| 335 | the long datatypes in 32 bit */
|
---|
| 336 | uint64_t numbits = 0, bitfield = 0;
|
---|
| 337 | int size = handle->size, type;
|
---|
[270] | 338 | int syncf, old = 0;
|
---|
[27] | 339 | unsigned char *data = handle->Message+3;
|
---|
| 340 |
|
---|
| 341 | GETBITS(type,12)
|
---|
[1097] | 342 | #ifdef NO_RTCM3_MAIN
|
---|
[1237] | 343 | handle->blocktype = type;
|
---|
[1092] | 344 | #endif /* NO_RTCM3_MAIN */
|
---|
[27] | 345 | switch(type)
|
---|
| 346 | {
|
---|
[1237] | 347 | #ifdef NO_RTCM3_MAIN
|
---|
| 348 | default:
|
---|
| 349 | ret = type;
|
---|
| 350 | break;
|
---|
| 351 | case 1005: case 1006:
|
---|
| 352 | {
|
---|
| 353 | SKIPBITS(22)
|
---|
| 354 | GETBITSSIGN(handle->antX, 38)
|
---|
| 355 | SKIPBITS(2)
|
---|
| 356 | GETBITSSIGN(handle->antY, 38)
|
---|
| 357 | SKIPBITS(2)
|
---|
| 358 | GETBITSSIGN(handle->antZ, 38)
|
---|
| 359 | if(type == 1006)
|
---|
| 360 | GETBITS(handle->antH, 16)
|
---|
| 361 | ret = type;
|
---|
| 362 | }
|
---|
| 363 | break;
|
---|
| 364 | case 1007: case 1008: case 1033:
|
---|
| 365 | {
|
---|
| 366 | char *antenna;
|
---|
| 367 | int antnum;
|
---|
| 368 |
|
---|
| 369 | SKIPBITS(12)
|
---|
| 370 | GETSTRING(antnum,antenna)
|
---|
| 371 | memcpy(handle->antenna, antenna, antnum);
|
---|
| 372 | handle->antenna[antnum] = 0;
|
---|
| 373 | ret = type;
|
---|
| 374 | }
|
---|
| 375 | break;
|
---|
[2501] | 376 | case 1013:
|
---|
| 377 | {
|
---|
| 378 | SKIPBITS(12);
|
---|
| 379 | GETBITS(handle->modjulday, 16);
|
---|
| 380 | GETBITS(handle->secofday, 17);
|
---|
| 381 | SKIPBITS(5);
|
---|
| 382 | GETBITS(handle->leapsec, 8);
|
---|
| 383 | ret = 1013;
|
---|
| 384 | }
|
---|
| 385 | break;
|
---|
[1237] | 386 | #endif /* NO_RTCM3_MAIN */
|
---|
[502] | 387 | case 1019:
|
---|
| 388 | {
|
---|
| 389 | struct gpsephemeris *ge;
|
---|
[2764] | 390 | int sv, i;
|
---|
[502] | 391 |
|
---|
| 392 | ge = &handle->ephemerisGPS;
|
---|
| 393 | memset(ge, 0, sizeof(*ge));
|
---|
| 394 |
|
---|
| 395 | GETBITS(sv, 6)
|
---|
| 396 | ge->satellite = (sv < 40 ? sv : sv+80);
|
---|
| 397 | GETBITS(ge->GPSweek, 10)
|
---|
| 398 | ge->GPSweek += 1024;
|
---|
| 399 | GETBITS(ge->URAindex, 4)
|
---|
| 400 | GETBITS(sv, 2)
|
---|
| 401 | if(sv & 1)
|
---|
| 402 | ge->flags |= GPSEPHF_L2PCODE;
|
---|
| 403 | if(sv & 2)
|
---|
| 404 | ge->flags |= GPSEPHF_L2CACODE;
|
---|
[1092] | 405 | GETFLOATSIGN(ge->IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
|
---|
[502] | 406 | GETBITS(ge->IODE, 8)
|
---|
| 407 | GETBITS(ge->TOC, 16)
|
---|
| 408 | ge->TOC <<= 4;
|
---|
| 409 | GETFLOATSIGN(ge->clock_driftrate, 8, 1.0/(double)(1<<30)/(double)(1<<25))
|
---|
| 410 | GETFLOATSIGN(ge->clock_drift, 16, 1.0/(double)(1<<30)/(double)(1<<13))
|
---|
| 411 | GETFLOATSIGN(ge->clock_bias, 22, 1.0/(double)(1<<30)/(double)(1<<1))
|
---|
| 412 | GETBITS(ge->IODC, 10)
|
---|
| 413 | GETFLOATSIGN(ge->Crs, 16, 1.0/(double)(1<<5))
|
---|
[1092] | 414 | GETFLOATSIGN(ge->Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
|
---|
| 415 | GETFLOATSIGN(ge->M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
[502] | 416 | GETFLOATSIGN(ge->Cuc, 16, 1.0/(double)(1<<29))
|
---|
| 417 | GETFLOAT(ge->e, 32, 1.0/(double)(1<<30)/(double)(1<<3))
|
---|
| 418 | GETFLOATSIGN(ge->Cus, 16, 1.0/(double)(1<<29))
|
---|
| 419 | GETFLOAT(ge->sqrt_A, 32, 1.0/(double)(1<<19))
|
---|
| 420 | GETBITS(ge->TOE, 16)
|
---|
| 421 | ge->TOE <<= 4;
|
---|
| 422 |
|
---|
| 423 | GETFLOATSIGN(ge->Cic, 16, 1.0/(double)(1<<29))
|
---|
[1092] | 424 | GETFLOATSIGN(ge->OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
[502] | 425 | GETFLOATSIGN(ge->Cis, 16, 1.0/(double)(1<<29))
|
---|
[1092] | 426 | GETFLOATSIGN(ge->i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
[502] | 427 | GETFLOATSIGN(ge->Crc, 16, 1.0/(double)(1<<5))
|
---|
[1092] | 428 | GETFLOATSIGN(ge->omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
| 429 | GETFLOATSIGN(ge->OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
|
---|
[502] | 430 | GETFLOATSIGN(ge->TGD, 8, 1.0/(double)(1<<30)/(double)(1<<1))
|
---|
| 431 | GETBITS(ge->SVhealth, 6)
|
---|
| 432 | GETBITS(sv, 1)
|
---|
| 433 | if(sv)
|
---|
| 434 | ge->flags |= GPSEPHF_L2PCODEDATA;
|
---|
[5332] | 435 | GETBITS(sv, 1)
|
---|
| 436 | if(sv)
|
---|
| 437 | ge->flags |= GPSEPHF_6HOURSFIT;
|
---|
[502] | 438 |
|
---|
[2764] | 439 | i = ((int)ge->GPSweek - (int)handle->GPSWeek)*7*24*60*60
|
---|
| 440 | + ((int)ge->TOE - (int)handle->GPSTOW) - 2*60*60;
|
---|
| 441 | if(i > 5*60*60 && i < 8*60*60)
|
---|
| 442 | {
|
---|
| 443 | handle->GPSTOW = ge->TOE;
|
---|
| 444 | handle->GPSWeek = ge->GPSweek;
|
---|
| 445 | }
|
---|
[2994] | 446 | ge->TOW = 0.9999E9;
|
---|
[502] | 447 | ret = 1019;
|
---|
| 448 | }
|
---|
| 449 | break;
|
---|
[5318] | 450 | case 1045: case 1046:
|
---|
[2756] | 451 | {
|
---|
| 452 | struct galileoephemeris *ge;
|
---|
| 453 | int sv;
|
---|
| 454 |
|
---|
| 455 | ge = &handle->ephemerisGALILEO;
|
---|
| 456 | memset(ge, 0, sizeof(*ge));
|
---|
| 457 |
|
---|
| 458 | GETBITS(sv, 6)
|
---|
| 459 | ge->satellite = sv;
|
---|
| 460 | GETBITS(ge->Week, 12)
|
---|
| 461 | GETBITS(ge->IODnav, 10)
|
---|
| 462 | GETBITS(ge->SISA, 8)
|
---|
| 463 | GETFLOATSIGN(ge->IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
|
---|
| 464 | GETBITSFACTOR(ge->TOC, 14, 60)
|
---|
| 465 | GETFLOATSIGN(ge->clock_driftrate, 6, 1.0/(double)(1<<30)/(double)(1<<29))
|
---|
| 466 | GETFLOATSIGN(ge->clock_drift, 21, 1.0/(double)(1<<30)/(double)(1<<16))
|
---|
| 467 | GETFLOATSIGN(ge->clock_bias, 31, 1.0/(double)(1<<30)/(double)(1<<4))
|
---|
| 468 | GETFLOATSIGN(ge->Crs, 16, 1.0/(double)(1<<5))
|
---|
| 469 | GETFLOATSIGN(ge->Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
|
---|
| 470 | GETFLOATSIGN(ge->M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
| 471 | GETFLOATSIGN(ge->Cuc, 16, 1.0/(double)(1<<29))
|
---|
| 472 | GETFLOAT(ge->e, 32, 1.0/(double)(1<<30)/(double)(1<<3))
|
---|
| 473 | GETFLOATSIGN(ge->Cus, 16, 1.0/(double)(1<<29))
|
---|
| 474 | GETFLOAT(ge->sqrt_A, 32, 1.0/(double)(1<<19))
|
---|
| 475 | GETBITSFACTOR(ge->TOE, 14, 60)
|
---|
| 476 | GETFLOATSIGN(ge->Cic, 16, 1.0/(double)(1<<29))
|
---|
| 477 | GETFLOATSIGN(ge->OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
| 478 | GETFLOATSIGN(ge->Cis, 16, 1.0/(double)(1<<29))
|
---|
| 479 | GETFLOATSIGN(ge->i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
| 480 | GETFLOATSIGN(ge->Crc, 16, 1.0/(double)(1<<5))
|
---|
| 481 | GETFLOATSIGN(ge->omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
|
---|
| 482 | GETFLOATSIGN(ge->OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
|
---|
| 483 | GETFLOATSIGN(ge->BGD_1_5A, 10, 1.0/(double)(1<<30)/(double)(1<<2))
|
---|
[5318] | 484 | if(type == 1046)
|
---|
| 485 | {
|
---|
| 486 | GETFLOATSIGN(ge->BGD_1_5B, 10, 1.0/(double)(1<<30)/(double)(1<<2))
|
---|
| 487 | GETBITS(ge->E5aHS, 2)
|
---|
| 488 | GETBITS(sv, 1)
|
---|
[5533] | 489 | ge->flags |= GALEPHF_INAV;
|
---|
[5318] | 490 | if(sv)
|
---|
| 491 | ge->flags |= GALEPHF_E5ADINVALID;
|
---|
| 492 | GETFLOATSIGN(ge->BGD_1_5B, 10, 1.0/(double)(1<<30)/(double)(1<<2))
|
---|
| 493 | }
|
---|
| 494 | else
|
---|
| 495 | {
|
---|
[5533] | 496 | ge->flags |= GALEPHF_FNAV;
|
---|
[5318] | 497 | GETBITS(ge->E5bHS, 2)
|
---|
| 498 | GETBITS(sv, 1)
|
---|
| 499 | if(sv)
|
---|
| 500 | ge->flags |= GALEPHF_E5BDINVALID;
|
---|
| 501 | }
|
---|
| 502 | ret = type;
|
---|
[2756] | 503 | }
|
---|
| 504 | break;
|
---|
[502] | 505 | case 1020:
|
---|
| 506 | {
|
---|
| 507 | struct glonassephemeris *ge;
|
---|
| 508 | int i;
|
---|
| 509 |
|
---|
| 510 | ge = &handle->ephemerisGLONASS;
|
---|
| 511 | memset(ge, 0, sizeof(*ge));
|
---|
| 512 |
|
---|
| 513 | ge->flags |= GLOEPHF_PAVAILABLE;
|
---|
| 514 | GETBITS(ge->almanac_number, 6)
|
---|
| 515 | GETBITS(i, 5)
|
---|
| 516 | ge->frequency_number = i-7;
|
---|
[2659] | 517 | if(ge->almanac_number >= 1 && ge->almanac_number <= PRN_GLONASS_NUM)
|
---|
| 518 | handle->GLOFreq[ge->almanac_number-1] = 100+ge->frequency_number;
|
---|
[502] | 519 | GETBITS(i, 1)
|
---|
| 520 | if(i)
|
---|
| 521 | ge->flags |= GLOEPHF_ALMANACHEALTHY;
|
---|
| 522 | GETBITS(i, 1)
|
---|
| 523 | if(i)
|
---|
| 524 | ge->flags |= GLOEPHF_ALMANACHEALTHOK;
|
---|
| 525 | GETBITS(i, 2)
|
---|
| 526 | if(i & 1)
|
---|
| 527 | ge->flags |= GLOEPHF_P10TRUE;
|
---|
| 528 | if(i & 2)
|
---|
| 529 | ge->flags |= GLOEPHF_P11TRUE;
|
---|
| 530 | GETBITS(i, 5)
|
---|
| 531 | ge->tk = i*60*60;
|
---|
| 532 | GETBITS(i, 6)
|
---|
| 533 | ge->tk += i*60;
|
---|
| 534 | GETBITS(i, 1)
|
---|
| 535 | ge->tk += i*30;
|
---|
| 536 | GETBITS(i, 1)
|
---|
| 537 | if(i)
|
---|
| 538 | ge->flags |= GLOEPHF_UNHEALTHY;
|
---|
| 539 | GETBITS(i, 1)
|
---|
| 540 | if(i)
|
---|
| 541 | ge->flags |= GLOEPHF_P2TRUE;
|
---|
| 542 | GETBITS(i, 7)
|
---|
| 543 | ge->tb = i*15*60;
|
---|
| 544 | GETFLOATSIGNM(ge->x_velocity, 24, 1.0/(double)(1<<20))
|
---|
| 545 | GETFLOATSIGNM(ge->x_pos, 27, 1.0/(double)(1<<11))
|
---|
| 546 | GETFLOATSIGNM(ge->x_acceleration, 5, 1.0/(double)(1<<30))
|
---|
| 547 | GETFLOATSIGNM(ge->y_velocity, 24, 1.0/(double)(1<<20))
|
---|
| 548 | GETFLOATSIGNM(ge->y_pos, 27, 1.0/(double)(1<<11))
|
---|
| 549 | GETFLOATSIGNM(ge->y_acceleration, 5, 1.0/(double)(1<<30))
|
---|
| 550 | GETFLOATSIGNM(ge->z_velocity, 24, 1.0/(double)(1<<20))
|
---|
| 551 | GETFLOATSIGNM(ge->z_pos, 27, 1.0/(double)(1<<11))
|
---|
| 552 | GETFLOATSIGNM(ge->z_acceleration, 5, 1.0/(double)(1<<30))
|
---|
| 553 | GETBITS(i, 1)
|
---|
| 554 | if(i)
|
---|
| 555 | ge->flags |= GLOEPHF_P3TRUE;
|
---|
| 556 | GETFLOATSIGNM(ge->gamma, 11, 1.0/(double)(1<<30)/(double)(1<<10))
|
---|
| 557 | SKIPBITS(3) /* GLONASS-M P, GLONASS-M ln (third string) */
|
---|
| 558 | GETFLOATSIGNM(ge->tau, 22, 1.0/(double)(1<<30)) /* GLONASS tau n(tb) */
|
---|
| 559 | SKIPBITS(5) /* GLONASS-M delta tau n(tb) */
|
---|
| 560 | GETBITS(ge->E, 5)
|
---|
| 561 | /* GETBITS(b, 1) / * GLONASS-M P4 */
|
---|
| 562 | /* GETBITS(b, 4) / * GLONASS-M Ft */
|
---|
| 563 | /* GETBITS(b, 11) / * GLONASS-M Nt */
|
---|
| 564 | /* GETBITS(b, 2) / * GLONASS-M M */
|
---|
| 565 | /* GETBITS(b, 1) / * GLONASS-M The Availability of Additional Data */
|
---|
| 566 | /* GETBITS(b, 11) / * GLONASS-M Na */
|
---|
| 567 | /* GETFLOATSIGNM(b, 32, 1.0/(double)(1<<30)/(double)(1<<1)) / * GLONASS tau c */
|
---|
| 568 | /* GETBITS(b, 5) / * GLONASS-M N4 */
|
---|
| 569 | /* GETFLOATSIGNM(b, 22, 1.0/(double)(1<<30)/(double)(1<<1)) / * GLONASS-M tau GPS */
|
---|
| 570 | /* GETBITS(b, 1) / * GLONASS-M ln (fifth string) */
|
---|
| 571 | ge->GPSWeek = handle->GPSWeek;
|
---|
| 572 | ge->GPSTOW = handle->GPSTOW;
|
---|
| 573 | ret = 1020;
|
---|
| 574 | }
|
---|
| 575 | break;
|
---|
[33] | 576 | case 1001: case 1002: case 1003: case 1004:
|
---|
[27] | 577 | if(handle->GPSWeek)
|
---|
| 578 | {
|
---|
| 579 | int lastlockl1[64];
|
---|
| 580 | int lastlockl2[64];
|
---|
| 581 | struct gnssdata *gnss;
|
---|
[1270] | 582 | int i, numsats, wasamb=0;
|
---|
[27] | 583 |
|
---|
| 584 | for(i = 0; i < 64; ++i)
|
---|
| 585 | lastlockl1[i] = lastlockl2[i] = 0;
|
---|
| 586 |
|
---|
[270] | 587 | gnss = &handle->DataNew;
|
---|
[27] | 588 |
|
---|
| 589 | SKIPBITS(12) /* id */
|
---|
| 590 | GETBITS(i,30)
|
---|
| 591 | if(i/1000 < (int)handle->GPSTOW - 86400)
|
---|
| 592 | ++handle->GPSWeek;
|
---|
| 593 | handle->GPSTOW = i/1000;
|
---|
[270] | 594 | if(gnss->week && (gnss->timeofweek != i || gnss->week
|
---|
| 595 | != handle->GPSWeek))
|
---|
| 596 | {
|
---|
| 597 | handle->Data = *gnss;
|
---|
| 598 | memset(gnss, 0, sizeof(*gnss));
|
---|
| 599 | old = 1;
|
---|
| 600 | }
|
---|
[27] | 601 | gnss->timeofweek = i;
|
---|
| 602 | gnss->week = handle->GPSWeek;
|
---|
| 603 |
|
---|
[270] | 604 | GETBITS(syncf,1) /* sync */
|
---|
[1270] | 605 | GETBITS(numsats,5)
|
---|
[27] | 606 | SKIPBITS(4) /* smind, smint */
|
---|
| 607 |
|
---|
[2352] | 608 | while(numsats-- && gnss->numsats < GNSS_MAXSATS)
|
---|
[27] | 609 | {
|
---|
[33] | 610 | int sv, code, l1range, c,l,s,ce,le,se,amb=0;
|
---|
[1270] | 611 | int fullsat, num;
|
---|
[27] | 612 |
|
---|
[1270] | 613 | GETBITS(sv, 6)
|
---|
| 614 | fullsat = sv < 40 ? sv : sv+80;
|
---|
| 615 | for(num = 0; num < gnss->numsats
|
---|
| 616 | && fullsat != gnss->satellites[num]; ++num)
|
---|
| 617 | ;
|
---|
| 618 |
|
---|
| 619 | if(num == gnss->numsats)
|
---|
| 620 | gnss->satellites[gnss->numsats++] = fullsat;
|
---|
| 621 |
|
---|
[27] | 622 | /* L1 */
|
---|
| 623 | GETBITS(code, 1);
|
---|
| 624 | if(code)
|
---|
| 625 | {
|
---|
| 626 | c = GNSSDF_P1DATA; ce = GNSSENTRY_P1DATA;
|
---|
| 627 | l = GNSSDF_L1PDATA; le = GNSSENTRY_L1PDATA;
|
---|
| 628 | s = GNSSDF_S1PDATA; se = GNSSENTRY_S1PDATA;
|
---|
[4796] | 629 | gnss->codetype[num][se] =
|
---|
[5156] | 630 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "1W";
|
---|
[27] | 631 | }
|
---|
| 632 | else
|
---|
| 633 | {
|
---|
| 634 | c = GNSSDF_C1DATA; ce = GNSSENTRY_C1DATA;
|
---|
| 635 | l = GNSSDF_L1CDATA; le = GNSSENTRY_L1CDATA;
|
---|
| 636 | s = GNSSDF_S1CDATA; se = GNSSENTRY_S1CDATA;
|
---|
[4796] | 637 | gnss->codetype[num][se] =
|
---|
[4430] | 638 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "1C";
|
---|
[27] | 639 | }
|
---|
[4959] | 640 | if(!handle->info[RTCM3_MSM_GPS].type[ce])
|
---|
| 641 | {
|
---|
| 642 | handle->info[RTCM3_MSM_GPS].type[ce] =
|
---|
| 643 | handle->info[RTCM3_MSM_GPS].type[le] =
|
---|
| 644 | handle->info[RTCM3_MSM_GPS].type[se] = gnss->codetype[num][ce][1];
|
---|
| 645 | }
|
---|
[27] | 646 | GETBITS(l1range, 24);
|
---|
| 647 | GETBITSSIGN(i, 20);
|
---|
[325] | 648 | if((i&((1<<20)-1)) != 0x80000)
|
---|
[27] | 649 | {
|
---|
[744] | 650 | gnss->dataflags[num] |= (c|l);
|
---|
| 651 | gnss->measdata[num][ce] = l1range*0.02;
|
---|
[27] | 652 | gnss->measdata[num][le] = l1range*0.02+i*0.0005;
|
---|
| 653 | }
|
---|
| 654 | GETBITS(i, 7);
|
---|
| 655 | lastlockl1[sv] = i;
|
---|
[2500] | 656 | if(handle->lastlockGPSl1[sv] > i || i == 0)
|
---|
[2659] | 657 | gnss->dataflags2[num] |= GNSSDF2_LOCKLOSSL1;
|
---|
[33] | 658 | if(type == 1002 || type == 1004)
|
---|
[27] | 659 | {
|
---|
[33] | 660 | GETBITS(amb,8);
|
---|
| 661 | if(amb && (gnss->dataflags[num] & c))
|
---|
| 662 | {
|
---|
| 663 | gnss->measdata[num][ce] += amb*299792.458;
|
---|
| 664 | gnss->measdata[num][le] += amb*299792.458;
|
---|
| 665 | ++wasamb;
|
---|
| 666 | }
|
---|
| 667 | GETBITS(i, 8);
|
---|
| 668 | if(i)
|
---|
| 669 | {
|
---|
| 670 | gnss->dataflags[num] |= s;
|
---|
| 671 | gnss->measdata[num][se] = i*0.25;
|
---|
| 672 | i /= 4*4;
|
---|
| 673 | if(i > 9) i = 9;
|
---|
| 674 | else if(i < 1) i = 1;
|
---|
| 675 | gnss->snrL1[num] = i;
|
---|
| 676 | }
|
---|
[27] | 677 | }
|
---|
[81] | 678 | gnss->measdata[num][le] /= GPS_WAVELENGTH_L1;
|
---|
[33] | 679 | if(type == 1003 || type == 1004)
|
---|
[27] | 680 | {
|
---|
[33] | 681 | /* L2 */
|
---|
| 682 | GETBITS(code,2);
|
---|
| 683 | if(code)
|
---|
| 684 | {
|
---|
| 685 | c = GNSSDF_P2DATA; ce = GNSSENTRY_P2DATA;
|
---|
| 686 | l = GNSSDF_L2PDATA; le = GNSSENTRY_L2PDATA;
|
---|
| 687 | s = GNSSDF_S2PDATA; se = GNSSENTRY_S2PDATA;
|
---|
[2422] | 688 | if(code >= 2)
|
---|
[4430] | 689 | {
|
---|
[4796] | 690 | gnss->codetype[num][se] =
|
---|
[4430] | 691 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "2W";
|
---|
[2659] | 692 | gnss->dataflags2[num] |= GNSSDF2_XCORRL2;
|
---|
[4430] | 693 | }
|
---|
| 694 | else
|
---|
| 695 | {
|
---|
[4796] | 696 | gnss->codetype[num][se] =
|
---|
[4430] | 697 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "2P";
|
---|
| 698 | }
|
---|
[33] | 699 | }
|
---|
| 700 | else
|
---|
| 701 | {
|
---|
| 702 | c = GNSSDF_C2DATA; ce = GNSSENTRY_C2DATA;
|
---|
| 703 | l = GNSSDF_L2CDATA; le = GNSSENTRY_L2CDATA;
|
---|
| 704 | s = GNSSDF_S2CDATA; se = GNSSENTRY_S2CDATA;
|
---|
[4796] | 705 | gnss->codetype[num][se] =
|
---|
[5521] | 706 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "2 ";
|
---|
[33] | 707 | }
|
---|
[4959] | 708 | if(!handle->info[RTCM3_MSM_GPS].type[ce])
|
---|
| 709 | {
|
---|
| 710 | handle->info[RTCM3_MSM_GPS].type[ce] =
|
---|
| 711 | handle->info[RTCM3_MSM_GPS].type[le] =
|
---|
| 712 | handle->info[RTCM3_MSM_GPS].type[se] = gnss->codetype[num][ce][1];
|
---|
| 713 | }
|
---|
[33] | 714 | GETBITSSIGN(i,14);
|
---|
[325] | 715 | if((i&((1<<14)-1)) != 0x2000)
|
---|
[33] | 716 | {
|
---|
| 717 | gnss->dataflags[num] |= c;
|
---|
| 718 | gnss->measdata[num][ce] = l1range*0.02+i*0.02
|
---|
| 719 | +amb*299792.458;
|
---|
| 720 | }
|
---|
| 721 | GETBITSSIGN(i,20);
|
---|
[325] | 722 | if((i&((1<<20)-1)) != 0x80000)
|
---|
[33] | 723 | {
|
---|
| 724 | gnss->dataflags[num] |= l;
|
---|
| 725 | gnss->measdata[num][le] = l1range*0.02+i*0.0005
|
---|
| 726 | +amb*299792.458;
|
---|
| 727 | }
|
---|
| 728 | GETBITS(i,7);
|
---|
| 729 | lastlockl2[sv] = i;
|
---|
[2500] | 730 | if(handle->lastlockGPSl2[sv] > i || i == 0)
|
---|
[2659] | 731 | gnss->dataflags2[num] |= GNSSDF2_LOCKLOSSL2;
|
---|
[33] | 732 | if(type == 1004)
|
---|
| 733 | {
|
---|
| 734 | GETBITS(i, 8);
|
---|
| 735 | if(i)
|
---|
| 736 | {
|
---|
| 737 | gnss->dataflags[num] |= s;
|
---|
| 738 | gnss->measdata[num][se] = i*0.25;
|
---|
| 739 | i /= 4*4;
|
---|
| 740 | if(i > 9) i = 9;
|
---|
| 741 | else if(i < 1) i = 1;
|
---|
| 742 | gnss->snrL2[num] = i;
|
---|
| 743 | }
|
---|
| 744 | }
|
---|
[81] | 745 | gnss->measdata[num][le] /= GPS_WAVELENGTH_L2;
|
---|
[27] | 746 | }
|
---|
| 747 | }
|
---|
| 748 | for(i = 0; i < 64; ++i)
|
---|
| 749 | {
|
---|
[2490] | 750 | handle->lastlockGPSl1[i] = lastlockl1[i];
|
---|
| 751 | handle->lastlockGPSl2[i] = lastlockl2[i];
|
---|
[27] | 752 | }
|
---|
[270] | 753 | if(!syncf && !old)
|
---|
| 754 | {
|
---|
| 755 | handle->Data = *gnss;
|
---|
| 756 | memset(gnss, 0, sizeof(*gnss));
|
---|
| 757 | }
|
---|
| 758 | if(!syncf || old)
|
---|
| 759 | {
|
---|
| 760 | if(wasamb) /* not RINEX compatible without */
|
---|
| 761 | ret = 1;
|
---|
| 762 | else
|
---|
| 763 | ret = 2;
|
---|
| 764 | }
|
---|
[1265] | 765 | #ifdef NO_RTCM3_MAIN
|
---|
| 766 | else
|
---|
| 767 | ret = type;
|
---|
| 768 | #endif /* NO_RTCM3_MAIN */
|
---|
[27] | 769 | }
|
---|
| 770 | break;
|
---|
[270] | 771 | case 1009: case 1010: case 1011: case 1012:
|
---|
| 772 | {
|
---|
| 773 | int lastlockl1[64];
|
---|
| 774 | int lastlockl2[64];
|
---|
| 775 | struct gnssdata *gnss;
|
---|
[1270] | 776 | int i, numsats;
|
---|
[270] | 777 | int wasamb=0;
|
---|
| 778 |
|
---|
| 779 | for(i = 0; i < 64; ++i)
|
---|
| 780 | lastlockl1[i] = lastlockl2[i] = 0;
|
---|
| 781 |
|
---|
| 782 | gnss = &handle->DataNew;
|
---|
| 783 |
|
---|
| 784 | SKIPBITS(12) /* id */;
|
---|
| 785 | GETBITS(i,27) /* tk */
|
---|
| 786 |
|
---|
[2346] | 787 | updatetime(&handle->GPSWeek, &handle->GPSTOW, i, 0); /* Moscow -> GPS */
|
---|
[270] | 788 | i = handle->GPSTOW*1000;
|
---|
| 789 | if(gnss->week && (gnss->timeofweek != i || gnss->week
|
---|
| 790 | != handle->GPSWeek))
|
---|
| 791 | {
|
---|
| 792 | handle->Data = *gnss;
|
---|
| 793 | memset(gnss, 0, sizeof(*gnss));
|
---|
| 794 | old = 1;
|
---|
| 795 | }
|
---|
| 796 |
|
---|
| 797 | gnss->timeofweek = i;
|
---|
| 798 | gnss->week = handle->GPSWeek;
|
---|
| 799 |
|
---|
| 800 | GETBITS(syncf,1) /* sync */
|
---|
[1270] | 801 | GETBITS(numsats,5)
|
---|
[270] | 802 |
|
---|
| 803 | SKIPBITS(4) /* smind, smint */
|
---|
| 804 |
|
---|
[2352] | 805 | while(numsats-- && gnss->numsats < GNSS_MAXSATS)
|
---|
[270] | 806 | {
|
---|
| 807 | int sv, code, l1range, c,l,s,ce,le,se,amb=0;
|
---|
[325] | 808 | int freq;
|
---|
[1270] | 809 | int fullsat, num;
|
---|
[270] | 810 |
|
---|
| 811 | GETBITS(sv, 6)
|
---|
[1270] | 812 | fullsat = sv-1 + PRN_GLONASS_START;
|
---|
| 813 | for(num = 0; num < gnss->numsats
|
---|
| 814 | && fullsat != gnss->satellites[num]; ++num)
|
---|
| 815 | ;
|
---|
| 816 |
|
---|
| 817 | if(num == gnss->numsats)
|
---|
| 818 | gnss->satellites[gnss->numsats++] = fullsat;
|
---|
| 819 |
|
---|
[325] | 820 | /* L1 */
|
---|
| 821 | GETBITS(code, 1)
|
---|
| 822 | GETBITS(freq, 5)
|
---|
[2346] | 823 |
|
---|
[2660] | 824 | if(sv >= 1 && sv <= PRN_GLONASS_NUM)
|
---|
| 825 | handle->GLOFreq[sv-1] = 100+freq-7;
|
---|
[2346] | 826 |
|
---|
[325] | 827 | if(code)
|
---|
[270] | 828 | {
|
---|
[325] | 829 | c = GNSSDF_P1DATA; ce = GNSSENTRY_P1DATA;
|
---|
| 830 | l = GNSSDF_L1PDATA; le = GNSSENTRY_L1PDATA;
|
---|
| 831 | s = GNSSDF_S1PDATA; se = GNSSENTRY_S1PDATA;
|
---|
[4796] | 832 | gnss->codetype[num][se] =
|
---|
[4430] | 833 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "1P";
|
---|
[270] | 834 | }
|
---|
| 835 | else
|
---|
| 836 | {
|
---|
[325] | 837 | c = GNSSDF_C1DATA; ce = GNSSENTRY_C1DATA;
|
---|
| 838 | l = GNSSDF_L1CDATA; le = GNSSENTRY_L1CDATA;
|
---|
| 839 | s = GNSSDF_S1CDATA; se = GNSSENTRY_S1CDATA;
|
---|
[4796] | 840 | gnss->codetype[num][se] =
|
---|
[4430] | 841 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "1C";
|
---|
[325] | 842 | }
|
---|
[4959] | 843 | if(!handle->info[RTCM3_MSM_GLONASS].type[ce])
|
---|
| 844 | {
|
---|
| 845 | handle->info[RTCM3_MSM_GLONASS].type[ce] =
|
---|
| 846 | handle->info[RTCM3_MSM_GLONASS].type[le] =
|
---|
| 847 | handle->info[RTCM3_MSM_GLONASS].type[se] = gnss->codetype[num][ce][1];
|
---|
| 848 | }
|
---|
[325] | 849 | GETBITS(l1range, 25)
|
---|
| 850 | GETBITSSIGN(i, 20)
|
---|
| 851 | if((i&((1<<20)-1)) != 0x80000)
|
---|
| 852 | {
|
---|
[744] | 853 | /* Handle this like GPS. Actually for GLONASS L1 range is always
|
---|
| 854 | valid. To be on the save side, we handle it as invalid like we
|
---|
| 855 | do for GPS and also remove range in case of 0x80000. */
|
---|
| 856 | gnss->dataflags[num] |= (c|l);
|
---|
| 857 | gnss->measdata[num][ce] = l1range*0.02;
|
---|
[325] | 858 | gnss->measdata[num][le] = l1range*0.02+i*0.0005;
|
---|
| 859 | }
|
---|
| 860 | GETBITS(i, 7)
|
---|
| 861 | lastlockl1[sv] = i;
|
---|
[2500] | 862 | if(handle->lastlockGLOl1[sv] > i || i == 0)
|
---|
[2659] | 863 | gnss->dataflags2[num] |= GNSSDF2_LOCKLOSSL1;
|
---|
[325] | 864 | if(type == 1010 || type == 1012)
|
---|
| 865 | {
|
---|
| 866 | GETBITS(amb,7)
|
---|
| 867 | if(amb && (gnss->dataflags[num] & c))
|
---|
| 868 | {
|
---|
| 869 | gnss->measdata[num][ce] += amb*599584.916;
|
---|
| 870 | gnss->measdata[num][le] += amb*599584.916;
|
---|
| 871 | ++wasamb;
|
---|
| 872 | }
|
---|
| 873 | GETBITS(i, 8)
|
---|
| 874 | if(i)
|
---|
| 875 | {
|
---|
| 876 | gnss->dataflags[num] |= s;
|
---|
| 877 | gnss->measdata[num][se] = i*0.25;
|
---|
| 878 | i /= 4*4;
|
---|
| 879 | if(i > 9) i = 9;
|
---|
| 880 | else if(i < 1) i = 1;
|
---|
| 881 | gnss->snrL1[num] = i;
|
---|
| 882 | }
|
---|
| 883 | }
|
---|
| 884 | gnss->measdata[num][le] /= GLO_WAVELENGTH_L1(freq-7);
|
---|
| 885 | if(type == 1011 || type == 1012)
|
---|
| 886 | {
|
---|
| 887 | /* L2 */
|
---|
| 888 | GETBITS(code,2)
|
---|
[270] | 889 | if(code)
|
---|
| 890 | {
|
---|
[325] | 891 | c = GNSSDF_P2DATA; ce = GNSSENTRY_P2DATA;
|
---|
| 892 | l = GNSSDF_L2PDATA; le = GNSSENTRY_L2PDATA;
|
---|
| 893 | s = GNSSDF_S2PDATA; se = GNSSENTRY_S2PDATA;
|
---|
[4796] | 894 | gnss->codetype[num][se] =
|
---|
[4430] | 895 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "2P";
|
---|
[270] | 896 | }
|
---|
| 897 | else
|
---|
| 898 | {
|
---|
[325] | 899 | c = GNSSDF_C2DATA; ce = GNSSENTRY_C2DATA;
|
---|
| 900 | l = GNSSDF_L2CDATA; le = GNSSENTRY_L2CDATA;
|
---|
| 901 | s = GNSSDF_S2CDATA; se = GNSSENTRY_S2CDATA;
|
---|
[4796] | 902 | gnss->codetype[num][se] =
|
---|
[4430] | 903 | gnss->codetype[num][ce] = gnss->codetype[num][le] = "2C";
|
---|
[270] | 904 | }
|
---|
[4959] | 905 | if(!handle->info[RTCM3_MSM_GLONASS].type[ce])
|
---|
| 906 | {
|
---|
| 907 | handle->info[RTCM3_MSM_GLONASS].type[ce] =
|
---|
| 908 | handle->info[RTCM3_MSM_GLONASS].type[le] =
|
---|
| 909 | handle->info[RTCM3_MSM_GLONASS].type[se] = gnss->codetype[num][ce][1];
|
---|
| 910 | }
|
---|
[325] | 911 | GETBITSSIGN(i,14)
|
---|
| 912 | if((i&((1<<14)-1)) != 0x2000)
|
---|
[270] | 913 | {
|
---|
| 914 | gnss->dataflags[num] |= c;
|
---|
[325] | 915 | gnss->measdata[num][ce] = l1range*0.02+i*0.02
|
---|
| 916 | +amb*599584.916;
|
---|
[270] | 917 | }
|
---|
[325] | 918 | GETBITSSIGN(i,20)
|
---|
| 919 | if((i&((1<<20)-1)) != 0x80000)
|
---|
[270] | 920 | {
|
---|
| 921 | gnss->dataflags[num] |= l;
|
---|
[325] | 922 | gnss->measdata[num][le] = l1range*0.02+i*0.0005
|
---|
[949] | 923 | +amb*599584.916;
|
---|
[270] | 924 | }
|
---|
[325] | 925 | GETBITS(i,7)
|
---|
| 926 | lastlockl2[sv] = i;
|
---|
[2500] | 927 | if(handle->lastlockGLOl2[sv] > i || i == 0)
|
---|
[2659] | 928 | gnss->dataflags2[num] |= GNSSDF2_LOCKLOSSL2;
|
---|
[325] | 929 | if(type == 1012)
|
---|
[270] | 930 | {
|
---|
| 931 | GETBITS(i, 8)
|
---|
| 932 | if(i)
|
---|
| 933 | {
|
---|
| 934 | gnss->dataflags[num] |= s;
|
---|
| 935 | gnss->measdata[num][se] = i*0.25;
|
---|
| 936 | i /= 4*4;
|
---|
| 937 | if(i > 9) i = 9;
|
---|
| 938 | else if(i < 1) i = 1;
|
---|
[325] | 939 | gnss->snrL2[num] = i;
|
---|
[270] | 940 | }
|
---|
| 941 | }
|
---|
[325] | 942 | gnss->measdata[num][le] /= GLO_WAVELENGTH_L2(freq-7);
|
---|
[270] | 943 | }
|
---|
[1270] | 944 | if(!sv || sv > 24) /* illegal, remove it again */
|
---|
| 945 | --gnss->numsats;
|
---|
[270] | 946 | }
|
---|
| 947 | for(i = 0; i < 64; ++i)
|
---|
| 948 | {
|
---|
[2490] | 949 | handle->lastlockGLOl1[i] = lastlockl1[i];
|
---|
| 950 | handle->lastlockGLOl2[i] = lastlockl2[i];
|
---|
[270] | 951 | }
|
---|
| 952 | if(!syncf && !old)
|
---|
| 953 | {
|
---|
| 954 | handle->Data = *gnss;
|
---|
| 955 | memset(gnss, 0, sizeof(*gnss));
|
---|
| 956 | }
|
---|
| 957 | if(!syncf || old)
|
---|
| 958 | {
|
---|
| 959 | if(wasamb) /* not RINEX compatible without */
|
---|
| 960 | ret = 1;
|
---|
| 961 | else
|
---|
| 962 | ret = 2;
|
---|
| 963 | }
|
---|
[1265] | 964 | #ifdef NO_RTCM3_MAIN
|
---|
| 965 | else
|
---|
| 966 | ret = type;
|
---|
| 967 | #endif /* NO_RTCM3_MAIN */
|
---|
[270] | 968 | }
|
---|
| 969 | break;
|
---|
[4367] | 970 | case 1071: case 1081: case 1091: case 1101: case 1111: case 1121:
|
---|
| 971 | case 1072: case 1082: case 1092: case 1102: case 1112: case 1122:
|
---|
| 972 | case 1073: case 1083: case 1093: case 1103: case 1113: case 1123:
|
---|
| 973 | case 1074: case 1084: case 1094: case 1104: case 1114: case 1124:
|
---|
| 974 | case 1075: case 1085: case 1095: case 1105: case 1115: case 1125:
|
---|
| 975 | case 1076: case 1086: case 1096: case 1106: case 1116: case 1126:
|
---|
| 976 | case 1077: case 1087: case 1097: case 1107: case 1117: case 1127:
|
---|
[2659] | 977 | if(handle->GPSWeek)
|
---|
| 978 | {
|
---|
| 979 | struct CodeData {
|
---|
| 980 | int typeR;
|
---|
| 981 | int typeP;
|
---|
| 982 | int typeD;
|
---|
| 983 | int typeS;
|
---|
| 984 | int lock;
|
---|
| 985 | double wl;
|
---|
| 986 | const char *code; /* currently unused */
|
---|
| 987 | };
|
---|
| 988 | struct CodeData gps[RTCM3_MSM_NUMSIG] =
|
---|
| 989 | {
|
---|
| 990 | {0,0,0,0,0,0,0},
|
---|
| 991 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
| 992 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1C"},
|
---|
| 993 | {GNSSENTRY_P1DATA,GNSSENTRY_L1PDATA,GNSSENTRY_D1PDATA,
|
---|
| 994 | GNSSENTRY_S1PDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1P"},
|
---|
| 995 | {GNSSENTRY_P1DATA,GNSSENTRY_L1PDATA,GNSSENTRY_D1PDATA,
|
---|
| 996 | GNSSENTRY_S1PDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1W"},
|
---|
[3581] | 997 | {0,0,0,0,0,0,0}/*{GNSSENTRY_P1DATA,GNSSENTRY_L1PDATA,GNSSENTRY_D1PDATA,
|
---|
| 998 | GNSSENTRY_S1PDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1Y"}*/,
|
---|
[2659] | 999 | {0,0,0,0,0,0,0},
|
---|
| 1000 | {0,0,0,0,0,0,0},
|
---|
| 1001 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1002 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2C"},
|
---|
| 1003 | {GNSSENTRY_P2DATA,GNSSENTRY_L2PDATA,GNSSENTRY_D2PDATA,
|
---|
| 1004 | GNSSENTRY_S2PDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2P"},
|
---|
| 1005 | {GNSSENTRY_P2DATA,GNSSENTRY_L2PDATA,GNSSENTRY_D2PDATA,
|
---|
| 1006 | GNSSENTRY_S2PDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2W"},
|
---|
[3581] | 1007 | {0,0,0,0,0,0,0}/*{GNSSENTRY_P2DATA,GNSSENTRY_L2PDATA,GNSSENTRY_D2PDATA,
|
---|
| 1008 | GNSSENTRY_S2PDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2Y"}*/,
|
---|
[2659] | 1009 | {0,0,0,0,0,0,0},
|
---|
| 1010 | {0,0,0,0,0,0,0},
|
---|
| 1011 | {0,0,0,0,0,0,0},
|
---|
| 1012 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1013 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2S"},
|
---|
| 1014 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1015 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2L"},
|
---|
| 1016 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1017 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2X"},
|
---|
| 1018 | {0,0,0,0,0,0,0},
|
---|
| 1019 | {0,0,0,0,0,0,0},
|
---|
| 1020 | {0,0,0,0,0,0,0},
|
---|
| 1021 | {0,0,0,0,0,0,0},
|
---|
| 1022 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
| 1023 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GPS_WAVELENGTH_L5,"5I"},
|
---|
| 1024 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
| 1025 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GPS_WAVELENGTH_L5,"5Q"},
|
---|
| 1026 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
[3581] | 1027 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GPS_WAVELENGTH_L5,"5X"},
|
---|
| 1028 | {0,0,0,0,0,0,0},
|
---|
| 1029 | {0,0,0,0,0,0,0},
|
---|
| 1030 | {0,0,0,0,0,0,0},
|
---|
| 1031 | {0,0,0,0,0,0,0},
|
---|
| 1032 | {0,0,0,0,0,0,0},
|
---|
[4367] | 1033 | {GNSSENTRY_C1NDATA,GNSSENTRY_L1NDATA,GNSSENTRY_D1NDATA,
|
---|
| 1034 | GNSSENTRY_S1NDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1S"},
|
---|
| 1035 | {GNSSENTRY_C1NDATA,GNSSENTRY_L1NDATA,GNSSENTRY_D1NDATA,
|
---|
| 1036 | GNSSENTRY_S1NDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1L"},
|
---|
| 1037 | {GNSSENTRY_C1NDATA,GNSSENTRY_L1NDATA,GNSSENTRY_D1NDATA,
|
---|
| 1038 | GNSSENTRY_S1NDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1X"}
|
---|
[2659] | 1039 | };
|
---|
| 1040 | /* NOTE: Uses 0.0, 1.0 for wavelength as sat index dependence is done later! */
|
---|
| 1041 | struct CodeData glo[RTCM3_MSM_NUMSIG] =
|
---|
| 1042 | {
|
---|
| 1043 | {0,0,0,0,0,0,0},
|
---|
| 1044 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
| 1045 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,0.0,"1C"},
|
---|
| 1046 | {GNSSENTRY_P1DATA,GNSSENTRY_L1PDATA,GNSSENTRY_D1PDATA,
|
---|
| 1047 | GNSSENTRY_S1PDATA,GNSSDF2_LOCKLOSSL1,0.0,"1P"},
|
---|
| 1048 | {0,0,0,0,0,0,0},
|
---|
| 1049 | {0,0,0,0,0,0,0},
|
---|
| 1050 | {0,0,0,0,0,0,0},
|
---|
| 1051 | {0,0,0,0,0,0,0},
|
---|
| 1052 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1053 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,1.0,"2C"},
|
---|
| 1054 | {GNSSENTRY_P2DATA,GNSSENTRY_L2PDATA,GNSSENTRY_D2PDATA,
|
---|
| 1055 | GNSSENTRY_S2PDATA,GNSSDF2_LOCKLOSSL2,1.0,"2P"},
|
---|
| 1056 | {0,0,0,0,0,0,0},
|
---|
| 1057 | {0,0,0,0,0,0,0},
|
---|
| 1058 | {0,0,0,0,0,0,0},
|
---|
| 1059 | {0,0,0,0,0,0,0},
|
---|
| 1060 | {0,0,0,0,0,0,0},
|
---|
| 1061 | {0,0,0,0,0,0,0},
|
---|
| 1062 | {0,0,0,0,0,0,0},
|
---|
| 1063 | {0,0,0,0,0,0,0},
|
---|
| 1064 | {0,0,0,0,0,0,0},
|
---|
| 1065 | {0,0,0,0,0,0,0},
|
---|
| 1066 | {0,0,0,0,0,0,0},
|
---|
| 1067 | {0,0,0,0,0,0,0},
|
---|
| 1068 | {0,0,0,0,0,0,0},
|
---|
| 1069 | {0,0,0,0,0,0,0},
|
---|
[3581] | 1070 | {0,0,0,0,0,0,0},
|
---|
| 1071 | {0,0,0,0,0,0,0},
|
---|
| 1072 | {0,0,0,0,0,0,0},
|
---|
| 1073 | {0,0,0,0,0,0,0},
|
---|
| 1074 | {0,0,0,0,0,0,0},
|
---|
| 1075 | {0,0,0,0,0,0,0},
|
---|
| 1076 | {0,0,0,0,0,0,0},
|
---|
| 1077 | {0,0,0,0,0,0,0},
|
---|
[2659] | 1078 | {0,0,0,0,0,0,0}
|
---|
| 1079 | };
|
---|
| 1080 | struct CodeData gal[RTCM3_MSM_NUMSIG] =
|
---|
| 1081 | {
|
---|
| 1082 | {0,0,0,0,0,0,0},
|
---|
| 1083 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
| 1084 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,GAL_WAVELENGTH_E1,"1C"},
|
---|
[4958] | 1085 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
[4955] | 1086 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,GAL_WAVELENGTH_E1,"1A"},
|
---|
[2659] | 1087 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
| 1088 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,GAL_WAVELENGTH_E1,"1B"},
|
---|
[4228] | 1089 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
[4955] | 1090 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,GAL_WAVELENGTH_E1,"1X"},
|
---|
[4958] | 1091 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
[4955] | 1092 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,GAL_WAVELENGTH_E1,"1Z"},
|
---|
[2659] | 1093 | {0,0,0,0,0,0,0},
|
---|
| 1094 | {GNSSENTRY_C6DATA,GNSSENTRY_L6DATA,GNSSENTRY_D6DATA,
|
---|
[3581] | 1095 | GNSSENTRY_S6DATA,GNSSDF2_LOCKLOSSE6,GAL_WAVELENGTH_E6,"6C"},
|
---|
[4958] | 1096 | {GNSSENTRY_C6DATA,GNSSENTRY_L6DATA,GNSSENTRY_D6DATA,
|
---|
[4955] | 1097 | GNSSENTRY_S6DATA,GNSSDF2_LOCKLOSSE6,GAL_WAVELENGTH_E6,"6A"},
|
---|
[2659] | 1098 | {GNSSENTRY_C6DATA,GNSSENTRY_L6DATA,GNSSENTRY_D6DATA,
|
---|
[3581] | 1099 | GNSSENTRY_S6DATA,GNSSDF2_LOCKLOSSE6,GAL_WAVELENGTH_E6,"6B"},
|
---|
[4958] | 1100 | {GNSSENTRY_C6DATA,GNSSENTRY_L6DATA,GNSSENTRY_D6DATA,
|
---|
[4955] | 1101 | GNSSENTRY_S6DATA,GNSSDF2_LOCKLOSSE6,GAL_WAVELENGTH_E6,"6X"},
|
---|
[4958] | 1102 | {GNSSENTRY_C6DATA,GNSSENTRY_L6DATA,GNSSENTRY_D6DATA,
|
---|
[4955] | 1103 | GNSSENTRY_S6DATA,GNSSDF2_LOCKLOSSE6,GAL_WAVELENGTH_E6,"6Z"},
|
---|
[2659] | 1104 | {0,0,0,0,0,0,0},
|
---|
| 1105 | {GNSSENTRY_C5BDATA,GNSSENTRY_L5BDATA,GNSSENTRY_D5BDATA,
|
---|
| 1106 | GNSSENTRY_S5BDATA,GNSSDF2_LOCKLOSSE5B,GAL_WAVELENGTH_E5B,"7I"},
|
---|
| 1107 | {GNSSENTRY_C5BDATA,GNSSENTRY_L5BDATA,GNSSENTRY_D5BDATA,
|
---|
| 1108 | GNSSENTRY_S5BDATA,GNSSDF2_LOCKLOSSE5B,GAL_WAVELENGTH_E5B,"7Q"},
|
---|
[4228] | 1109 | {GNSSENTRY_C5BDATA,GNSSENTRY_L5BDATA,GNSSENTRY_D5BDATA,
|
---|
[4955] | 1110 | GNSSENTRY_S5BDATA,GNSSDF2_LOCKLOSSE5B,GAL_WAVELENGTH_E5B,"7X"},
|
---|
[2659] | 1111 | {0,0,0,0,0,0,0},
|
---|
| 1112 | {GNSSENTRY_C5ABDATA,GNSSENTRY_L5ABDATA,GNSSENTRY_D5ABDATA,
|
---|
| 1113 | GNSSENTRY_S5ABDATA,GNSSDF2_LOCKLOSSE5AB,GAL_WAVELENGTH_E5AB,"8I"},
|
---|
| 1114 | {GNSSENTRY_C5ABDATA,GNSSENTRY_L5ABDATA,GNSSENTRY_D5ABDATA,
|
---|
| 1115 | GNSSENTRY_S5ABDATA,GNSSDF2_LOCKLOSSE5AB,GAL_WAVELENGTH_E5AB,"8Q"},
|
---|
[4228] | 1116 | {GNSSENTRY_C5ABDATA,GNSSENTRY_L5ABDATA,GNSSENTRY_D5ABDATA,
|
---|
[4955] | 1117 | GNSSENTRY_S5ABDATA,GNSSDF2_LOCKLOSSE5AB,GAL_WAVELENGTH_E5AB,"8X"},
|
---|
[2659] | 1118 | {0,0,0,0,0,0,0},
|
---|
| 1119 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
| 1120 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GAL_WAVELENGTH_E5A,"5I"},
|
---|
| 1121 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
| 1122 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GAL_WAVELENGTH_E5A,"5Q"},
|
---|
[4228] | 1123 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
[4955] | 1124 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GAL_WAVELENGTH_E5A,"5X"},
|
---|
[3581] | 1125 | {0,0,0,0,0,0,0},
|
---|
| 1126 | {0,0,0,0,0,0,0},
|
---|
| 1127 | {0,0,0,0,0,0,0},
|
---|
| 1128 | {0,0,0,0,0,0,0},
|
---|
| 1129 | {0,0,0,0,0,0,0},
|
---|
| 1130 | {0,0,0,0,0,0,0},
|
---|
| 1131 | {0,0,0,0,0,0,0},
|
---|
| 1132 | {0,0,0,0,0,0,0},
|
---|
[2659] | 1133 | };
|
---|
[4367] | 1134 | struct CodeData qzss[RTCM3_MSM_NUMSIG] =
|
---|
| 1135 | {
|
---|
| 1136 | {0,0,0,0,0,0,0},
|
---|
| 1137 | {GNSSENTRY_C1DATA,GNSSENTRY_L1CDATA,GNSSENTRY_D1CDATA,
|
---|
| 1138 | GNSSENTRY_S1CDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1C"},
|
---|
| 1139 | {0,0,0,0,0,0,0},
|
---|
| 1140 | {0,0,0,0,0,0,0},
|
---|
| 1141 | {0,0,0,0,0,0,0},
|
---|
| 1142 | {GNSSENTRY_CSAIFDATA,GNSSENTRY_LSAIFDATA,GNSSENTRY_DSAIFDATA,
|
---|
| 1143 | GNSSENTRY_SSAIFDATA,GNSSDF2_LOCKLOSSSAIF,GPS_WAVELENGTH_L1,"1Z"},
|
---|
| 1144 | {0,0,0,0,0,0,0},
|
---|
| 1145 | {0,0,0,0,0,0,0},
|
---|
| 1146 | {GNSSENTRY_CLEXDATA,GNSSENTRY_LLEXDATA,GNSSENTRY_DLEXDATA,
|
---|
| 1147 | GNSSENTRY_SLEXDATA,GNSSDF2_LOCKLOSSLEX,QZSS_WAVELENGTH_LEX,"6S"},
|
---|
| 1148 | {GNSSENTRY_CLEXDATA,GNSSENTRY_LLEXDATA,GNSSENTRY_DLEXDATA,
|
---|
| 1149 | GNSSENTRY_SLEXDATA,GNSSDF2_LOCKLOSSLEX,QZSS_WAVELENGTH_LEX,"6L"},
|
---|
| 1150 | {GNSSENTRY_CLEXDATA,GNSSENTRY_LLEXDATA,GNSSENTRY_DLEXDATA,
|
---|
| 1151 | GNSSENTRY_SLEXDATA,GNSSDF2_LOCKLOSSLEX,QZSS_WAVELENGTH_LEX,"6X"},
|
---|
[4498] | 1152 | {0,0,0,0,0,0,0},
|
---|
| 1153 | {0,0,0,0,0,0,0},
|
---|
| 1154 | {0,0,0,0,0,0,0},
|
---|
[4367] | 1155 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1156 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2S"},
|
---|
| 1157 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1158 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2L"},
|
---|
| 1159 | {GNSSENTRY_C2DATA,GNSSENTRY_L2CDATA,GNSSENTRY_D2CDATA,
|
---|
| 1160 | GNSSENTRY_S2CDATA,GNSSDF2_LOCKLOSSL2,GPS_WAVELENGTH_L2,"2X"},
|
---|
| 1161 | {0,0,0,0,0,0,0},
|
---|
| 1162 | {0,0,0,0,0,0,0},
|
---|
| 1163 | {0,0,0,0,0,0,0},
|
---|
| 1164 | {0,0,0,0,0,0,0},
|
---|
| 1165 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
| 1166 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GPS_WAVELENGTH_L5,"5I"},
|
---|
| 1167 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
| 1168 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GPS_WAVELENGTH_L5,"5Q"},
|
---|
| 1169 | {GNSSENTRY_C5DATA,GNSSENTRY_L5DATA,GNSSENTRY_D5DATA,
|
---|
| 1170 | GNSSENTRY_S5DATA,GNSSDF2_LOCKLOSSL5,GPS_WAVELENGTH_L5,"5X"},
|
---|
| 1171 | {0,0,0,0,0,0,0},
|
---|
| 1172 | {0,0,0,0,0,0,0},
|
---|
| 1173 | {0,0,0,0,0,0,0},
|
---|
| 1174 | {0,0,0,0,0,0,0},
|
---|
[4535] | 1175 | {0,0,0,0,0,0,0},
|
---|
[4498] | 1176 | {GNSSENTRY_C1NDATA,GNSSENTRY_L1NDATA,GNSSENTRY_D1NDATA,
|
---|
| 1177 | GNSSENTRY_S1NDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1D"},
|
---|
| 1178 | {GNSSENTRY_C1NDATA,GNSSENTRY_L1NDATA,GNSSENTRY_D1NDATA,
|
---|
| 1179 | GNSSENTRY_S1NDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1P"},
|
---|
| 1180 | {GNSSENTRY_C1NDATA,GNSSENTRY_L1NDATA,GNSSENTRY_D1NDATA,
|
---|
| 1181 | GNSSENTRY_S1NDATA,GNSSDF2_LOCKLOSSL1,GPS_WAVELENGTH_L1,"1X"}
|
---|
[4367] | 1182 | };
|
---|
| 1183 | struct CodeData compass[RTCM3_MSM_NUMSIG] =
|
---|
| 1184 | {
|
---|
| 1185 | {0,0,0,0,0,0,0},
|
---|
| 1186 | {GNSSENTRY_CB1DATA,GNSSENTRY_LB1DATA,GNSSENTRY_DB1DATA,
|
---|
[5372] | 1187 | GNSSENTRY_SB1DATA,GNSSDF2_LOCKLOSSB1,COMPASS_WAVELENGTH_B1,"1I"},
|
---|
[4367] | 1188 | {0,0,0,0,0,0,0},
|
---|
| 1189 | {0,0,0,0,0,0,0},
|
---|
| 1190 | {0,0,0,0,0,0,0},
|
---|
| 1191 | {0,0,0,0,0,0,0},
|
---|
| 1192 | {0,0,0,0,0,0,0},
|
---|
| 1193 | {GNSSENTRY_CB3DATA,GNSSENTRY_LB3DATA,GNSSENTRY_DB3DATA,
|
---|
| 1194 | GNSSENTRY_SB3DATA,GNSSDF2_LOCKLOSSB3,COMPASS_WAVELENGTH_B3,"6I"},
|
---|
| 1195 | {0,0,0,0,0,0,0},
|
---|
| 1196 | {0,0,0,0,0,0,0},
|
---|
| 1197 | {0,0,0,0,0,0,0},
|
---|
| 1198 | {0,0,0,0,0,0,0},
|
---|
| 1199 | {0,0,0,0,0,0,0},
|
---|
| 1200 | {GNSSENTRY_CB2DATA,GNSSENTRY_LB2DATA,GNSSENTRY_DB2DATA,
|
---|
| 1201 | GNSSENTRY_SB2DATA,GNSSDF2_LOCKLOSSB2,COMPASS_WAVELENGTH_B2,"7I"},
|
---|
| 1202 | {0,0,0,0,0,0,0},
|
---|
| 1203 | {0,0,0,0,0,0,0},
|
---|
| 1204 | {0,0,0,0,0,0,0},
|
---|
| 1205 | {0,0,0,0,0,0,0},
|
---|
| 1206 | {0,0,0,0,0,0,0},
|
---|
| 1207 | {0,0,0,0,0,0,0},
|
---|
| 1208 | {0,0,0,0,0,0,0},
|
---|
| 1209 | {0,0,0,0,0,0,0},
|
---|
| 1210 | {0,0,0,0,0,0,0},
|
---|
| 1211 | {0,0,0,0,0,0,0},
|
---|
| 1212 | {0,0,0,0,0,0,0},
|
---|
| 1213 | {0,0,0,0,0,0,0},
|
---|
| 1214 | {0,0,0,0,0,0,0},
|
---|
| 1215 | {0,0,0,0,0,0,0},
|
---|
| 1216 | {0,0,0,0,0,0,0},
|
---|
| 1217 | {0,0,0,0,0,0,0},
|
---|
| 1218 | {0,0,0,0,0,0,0},
|
---|
| 1219 | {0,0,0,0,0,0,0},
|
---|
| 1220 | };
|
---|
[2659] | 1221 |
|
---|
[4371] | 1222 | int sys = RTCM3_MSM_GPS, i=0, count, j, old = 0, wasnoamb = 0,
|
---|
| 1223 | start=PRN_GPS_START;
|
---|
[2659] | 1224 | int syncf, sigmask, numsat = 0, numsig = 0, numcells;
|
---|
| 1225 | uint64_t satmask, cellmask, ui;
|
---|
| 1226 | double rrmod[RTCM3_MSM_NUMSAT];
|
---|
[3581] | 1227 | int rrint[RTCM3_MSM_NUMSAT], rdop[RTCM3_MSM_NUMSAT],
|
---|
| 1228 | extsat[RTCM3_MSM_NUMSAT];
|
---|
[5358] | 1229 | int ll[RTCM3_MSM_NUMCELLS]/*, hc[RTCM3_MSM_NUMCELLS]*/;
|
---|
[2659] | 1230 | double cnr[RTCM3_MSM_NUMCELLS];
|
---|
| 1231 | double cp[RTCM3_MSM_NUMCELLS], psr[RTCM3_MSM_NUMCELLS],
|
---|
| 1232 | dop[RTCM3_MSM_NUMCELLS];
|
---|
| 1233 | struct gnssdata *gnss = &handle->DataNew;
|
---|
| 1234 |
|
---|
| 1235 | SKIPBITS(12)
|
---|
[4367] | 1236 | if(type >= 1121)
|
---|
[4371] | 1237 | {
|
---|
[4367] | 1238 | sys = RTCM3_MSM_COMPASS;
|
---|
[4371] | 1239 | start = PRN_COMPASS_START;
|
---|
| 1240 | }
|
---|
[4367] | 1241 | else if(type >= 1111)
|
---|
[4371] | 1242 | {
|
---|
[4367] | 1243 | sys = RTCM3_MSM_QZSS;
|
---|
[4371] | 1244 | start = PRN_QZSS_START;
|
---|
| 1245 | }
|
---|
[4367] | 1246 | else if(type >= 1101)
|
---|
[4371] | 1247 | {
|
---|
[4367] | 1248 | sys = RTCM3_MSM_SBAS;
|
---|
[4371] | 1249 | start = PRN_SBAS_START;
|
---|
| 1250 | }
|
---|
[4367] | 1251 | else if(type >= 1091)
|
---|
[4371] | 1252 | {
|
---|
[2659] | 1253 | sys = RTCM3_MSM_GALILEO;
|
---|
[4371] | 1254 | start = PRN_GALILEO_START;
|
---|
| 1255 | }
|
---|
[2659] | 1256 | else if(type >= 1081)
|
---|
[4371] | 1257 | {
|
---|
[2659] | 1258 | sys = RTCM3_MSM_GLONASS;
|
---|
[4371] | 1259 | start = PRN_GLONASS_START;
|
---|
| 1260 | }
|
---|
[2659] | 1261 |
|
---|
[4383] | 1262 | for(i = 0; i < RTCM3_MSM_NUMSAT; ++i)
|
---|
| 1263 | extsat[i] = 15;
|
---|
| 1264 |
|
---|
[2659] | 1265 | switch(sys)
|
---|
| 1266 | {
|
---|
[4367] | 1267 | case RTCM3_MSM_COMPASS:
|
---|
[5152] | 1268 | GETBITS(i,30)
|
---|
| 1269 | i += 14000;
|
---|
| 1270 | if(i >= 7*24*60*60*1000)
|
---|
| 1271 | i -= 7*24*60*60*1000;
|
---|
| 1272 | if(i/1000 < (int)handle->GPSTOW - 86400)
|
---|
| 1273 | ++handle->GPSWeek;
|
---|
| 1274 | handle->GPSTOW = i/1000;
|
---|
| 1275 | break;
|
---|
[2659] | 1276 | case RTCM3_MSM_GALILEO: /* use DF004 instead of DF248 */
|
---|
[4367] | 1277 | case RTCM3_MSM_QZSS:
|
---|
| 1278 | case RTCM3_MSM_SBAS:
|
---|
[2659] | 1279 | case RTCM3_MSM_GPS:
|
---|
| 1280 | GETBITS(i,30)
|
---|
| 1281 | if(i/1000 < (int)handle->GPSTOW - 86400)
|
---|
| 1282 | ++handle->GPSWeek;
|
---|
| 1283 | handle->GPSTOW = i/1000;
|
---|
| 1284 | break;
|
---|
| 1285 | case RTCM3_MSM_GLONASS:
|
---|
| 1286 | SKIPBITS(3)
|
---|
| 1287 | GETBITS(i,27) /* tk */
|
---|
| 1288 |
|
---|
| 1289 | updatetime(&handle->GPSWeek, &handle->GPSTOW, i, 0); /* Moscow -> GPS */
|
---|
| 1290 | i = handle->GPSTOW*1000;
|
---|
| 1291 | break;
|
---|
| 1292 | }
|
---|
| 1293 |
|
---|
| 1294 | if(gnss->week && (gnss->timeofweek != i || gnss->week
|
---|
| 1295 | != handle->GPSWeek))
|
---|
| 1296 | {
|
---|
| 1297 | handle->Data = *gnss;
|
---|
| 1298 | memset(gnss, 0, sizeof(*gnss));
|
---|
| 1299 | old = 1;
|
---|
| 1300 | }
|
---|
| 1301 | gnss->timeofweek = i;
|
---|
| 1302 | gnss->week = handle->GPSWeek;
|
---|
| 1303 |
|
---|
| 1304 | GETBITS(syncf, 1)
|
---|
[3581] | 1305 | SKIPBITS(3+7+2+2+1+3)
|
---|
[2860] | 1306 | GETBITS64(satmask, RTCM3_MSM_NUMSAT)
|
---|
[2659] | 1307 |
|
---|
| 1308 | /* http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/ */
|
---|
| 1309 | for(ui = satmask; ui; ui &= (ui - 1) /* remove rightmost bit */)
|
---|
| 1310 | ++numsat;
|
---|
| 1311 | GETBITS(sigmask, RTCM3_MSM_NUMSIG)
|
---|
| 1312 | for(i = sigmask; i; i &= (i - 1) /* remove rightmost bit */)
|
---|
| 1313 | ++numsig;
|
---|
| 1314 | i = numsat*numsig;
|
---|
[2860] | 1315 | GETBITS64(cellmask, (unsigned)i)
|
---|
[2659] | 1316 |
|
---|
| 1317 | switch(type % 10)
|
---|
| 1318 | {
|
---|
| 1319 | case 1: case 2: case 3:
|
---|
[2668] | 1320 | ++wasnoamb;
|
---|
[2659] | 1321 | for(j = numsat; j--;)
|
---|
[3581] | 1322 | GETFLOAT(rrmod[j], 10, 1.0/1024.0)
|
---|
[2659] | 1323 | break;
|
---|
| 1324 | case 4: case 6:
|
---|
| 1325 | for(j = numsat; j--;)
|
---|
| 1326 | GETBITS(rrint[j], 8)
|
---|
| 1327 | for(j = numsat; j--;)
|
---|
[3581] | 1328 | GETFLOAT(rrmod[j], 10, 1.0/1024.0)
|
---|
[2659] | 1329 | break;
|
---|
| 1330 | case 5: case 7:
|
---|
| 1331 | for(j = numsat; j--;)
|
---|
| 1332 | GETBITS(rrint[j], 8)
|
---|
| 1333 | for(j = numsat; j--;)
|
---|
[3581] | 1334 | GETBITS(extsat[j], 4)
|
---|
[2659] | 1335 | for(j = numsat; j--;)
|
---|
[3581] | 1336 | GETFLOAT(rrmod[j], 10, 1.0/1024.0)
|
---|
| 1337 | for(j = numsat; j--;)
|
---|
[2659] | 1338 | GETBITSSIGN(rdop[j], 14)
|
---|
| 1339 | break;
|
---|
| 1340 | }
|
---|
| 1341 |
|
---|
| 1342 | numcells = numsat*numsig;
|
---|
| 1343 | if(numcells <= RTCM3_MSM_NUMCELLS)
|
---|
| 1344 | {
|
---|
| 1345 | switch(type % 10)
|
---|
| 1346 | {
|
---|
| 1347 | case 1:
|
---|
| 1348 | for(count = numcells; count--;)
|
---|
| 1349 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1350 | GETFLOATSIGN(psr[count], 15, 1.0/(1<<24))
|
---|
[2659] | 1351 | break;
|
---|
| 1352 | case 2:
|
---|
| 1353 | for(count = numcells; count--;)
|
---|
| 1354 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1355 | GETFLOATSIGN(cp[count], 22, 1.0/(1<<29))
|
---|
[2659] | 1356 | for(count = numcells; count--;)
|
---|
| 1357 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1358 | GETBITS(ll[count], 4)
|
---|
[3712] | 1359 | for(count = numcells; count--;)
|
---|
| 1360 | if(cellmask & (UINT64(1)<<count))
|
---|
[5358] | 1361 | SKIPBITS(1)/*GETBITS(hc[count], 1)*/
|
---|
[2659] | 1362 | break;
|
---|
| 1363 | case 3:
|
---|
| 1364 | for(count = numcells; count--;)
|
---|
| 1365 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1366 | GETFLOATSIGN(psr[count], 15, 1.0/(1<<24))
|
---|
[2659] | 1367 | for(count = numcells; count--;)
|
---|
| 1368 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1369 | GETFLOATSIGN(cp[count], 22, 1.0/(1<<29))
|
---|
[2659] | 1370 | for(count = numcells; count--;)
|
---|
| 1371 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1372 | GETBITS(ll[count], 4)
|
---|
[3712] | 1373 | for(count = numcells; count--;)
|
---|
| 1374 | if(cellmask & (UINT64(1)<<count))
|
---|
[5358] | 1375 | SKIPBITS(1)/*GETBITS(hc[count], 1)*/
|
---|
[2659] | 1376 | break;
|
---|
| 1377 | case 4:
|
---|
| 1378 | for(count = numcells; count--;)
|
---|
| 1379 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1380 | GETFLOATSIGN(psr[count], 15, 1.0/(1<<24))
|
---|
[2659] | 1381 | for(count = numcells; count--;)
|
---|
| 1382 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1383 | GETFLOATSIGN(cp[count], 22, 1.0/(1<<29))
|
---|
[2659] | 1384 | for(count = numcells; count--;)
|
---|
| 1385 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1386 | GETBITS(ll[count], 4)
|
---|
| 1387 | for(count = numcells; count--;)
|
---|
| 1388 | if(cellmask & (UINT64(1)<<count))
|
---|
[5358] | 1389 | SKIPBITS(1)/*GETBITS(hc[count], 1)*/
|
---|
[3712] | 1390 | for(count = numcells; count--;)
|
---|
| 1391 | if(cellmask & (UINT64(1)<<count))
|
---|
[2659] | 1392 | GETBITS(cnr[count], 6)
|
---|
| 1393 | break;
|
---|
| 1394 | case 5:
|
---|
| 1395 | for(count = numcells; count--;)
|
---|
| 1396 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1397 | GETFLOATSIGN(psr[count], 15, 1.0/(1<<24))
|
---|
[2659] | 1398 | for(count = numcells; count--;)
|
---|
| 1399 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1400 | GETFLOATSIGN(cp[count], 22, 1.0/(1<<29))
|
---|
[2659] | 1401 | for(count = numcells; count--;)
|
---|
| 1402 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1403 | GETBITS(ll[count], 4)
|
---|
| 1404 | for(count = numcells; count--;)
|
---|
| 1405 | if(cellmask & (UINT64(1)<<count))
|
---|
[5358] | 1406 | SKIPBITS(1)/*GETBITS(hc[count], 1)*/
|
---|
[3712] | 1407 | for(count = numcells; count--;)
|
---|
| 1408 | if(cellmask & (UINT64(1)<<count))
|
---|
[2659] | 1409 | GETFLOAT(cnr[count], 6, 1.0)
|
---|
| 1410 | for(count = numcells; count--;)
|
---|
| 1411 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1412 | GETFLOATSIGN(dop[count], 15, 0.0001)
|
---|
| 1413 | break;
|
---|
| 1414 | case 6:
|
---|
| 1415 | for(count = numcells; count--;)
|
---|
| 1416 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1417 | GETFLOATSIGN(psr[count], 20, 1.0/(1<<29))
|
---|
[2659] | 1418 | for(count = numcells; count--;)
|
---|
| 1419 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1420 | GETFLOATSIGN(cp[count], 24, 1.0/(1U<<31))
|
---|
[2659] | 1421 | for(count = numcells; count--;)
|
---|
| 1422 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1423 | GETBITS(ll[count], 10)
|
---|
| 1424 | for(count = numcells; count--;)
|
---|
| 1425 | if(cellmask & (UINT64(1)<<count))
|
---|
[5358] | 1426 | SKIPBITS(1)/*GETBITS(hc[count], 1)*/
|
---|
[3712] | 1427 | for(count = numcells; count--;)
|
---|
| 1428 | if(cellmask & (UINT64(1)<<count))
|
---|
[3724] | 1429 | GETFLOAT(cnr[count], 10, 1.0/(1<<4))
|
---|
[3581] | 1430 | break;
|
---|
[2659] | 1431 | case 7:
|
---|
| 1432 | for(count = numcells; count--;)
|
---|
| 1433 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1434 | GETFLOATSIGN(psr[count], 20, 1.0/(1<<29))
|
---|
[2659] | 1435 | for(count = numcells; count--;)
|
---|
| 1436 | if(cellmask & (UINT64(1)<<count))
|
---|
[3581] | 1437 | GETFLOATSIGN(cp[count], 24, 1.0/(1U<<31))
|
---|
[2659] | 1438 | for(count = numcells; count--;)
|
---|
| 1439 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1440 | GETBITS(ll[count], 10)
|
---|
| 1441 | for(count = numcells; count--;)
|
---|
| 1442 | if(cellmask & (UINT64(1)<<count))
|
---|
[5358] | 1443 | SKIPBITS(1)/*GETBITS(hc[count], 1)*/
|
---|
[3712] | 1444 | for(count = numcells; count--;)
|
---|
| 1445 | if(cellmask & (UINT64(1)<<count))
|
---|
[3724] | 1446 | GETFLOAT(cnr[count], 10, 1.0/(1<<4))
|
---|
[2659] | 1447 | for(count = numcells; count--;)
|
---|
| 1448 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1449 | GETFLOATSIGN(dop[count], 15, 0.0001)
|
---|
| 1450 | break;
|
---|
| 1451 | }
|
---|
| 1452 | i = RTCM3_MSM_NUMSAT;
|
---|
| 1453 | j = -1;
|
---|
| 1454 | for(count = numcells; count--;)
|
---|
| 1455 | {
|
---|
| 1456 | while(j >= 0 && !(sigmask&(1<<--j)))
|
---|
| 1457 | ;
|
---|
| 1458 | if(j < 0)
|
---|
| 1459 | {
|
---|
| 1460 | while(!(satmask&(UINT64(1)<<(--i)))) /* next satellite */
|
---|
| 1461 | ;
|
---|
| 1462 | j = RTCM3_MSM_NUMSIG;
|
---|
| 1463 | while(!(sigmask&(1<<--j)))
|
---|
| 1464 | ;
|
---|
| 1465 | --numsat;
|
---|
| 1466 | }
|
---|
| 1467 | if(cellmask & (UINT64(1)<<count))
|
---|
| 1468 | {
|
---|
| 1469 | struct CodeData cd = {0,0,0,0,0,0,0};
|
---|
| 1470 | double wl = 0.0;
|
---|
| 1471 | switch(sys)
|
---|
| 1472 | {
|
---|
[4367] | 1473 | case RTCM3_MSM_QZSS:
|
---|
| 1474 | cd = qzss[RTCM3_MSM_NUMSIG-j-1];
|
---|
[2659] | 1475 | wl = cd.wl;
|
---|
| 1476 | break;
|
---|
[4367] | 1477 | case RTCM3_MSM_COMPASS:
|
---|
| 1478 | cd = compass[RTCM3_MSM_NUMSIG-j-1];
|
---|
| 1479 | wl = cd.wl;
|
---|
| 1480 | break;
|
---|
| 1481 | case RTCM3_MSM_GPS: case RTCM3_MSM_SBAS:
|
---|
| 1482 | cd = gps[RTCM3_MSM_NUMSIG-j-1];
|
---|
| 1483 | wl = cd.wl;
|
---|
| 1484 | break;
|
---|
[2659] | 1485 | case RTCM3_MSM_GLONASS: cd = glo[RTCM3_MSM_NUMSIG-j-1];
|
---|
| 1486 | {
|
---|
| 1487 | int k = handle->GLOFreq[RTCM3_MSM_NUMSAT-i-1];
|
---|
[5535] | 1488 | if(!k && extsat[numsat] < 14)
|
---|
[3653] | 1489 | {
|
---|
[3654] | 1490 | k = handle->GLOFreq[RTCM3_MSM_NUMSAT-i-1]
|
---|
[5535] | 1491 | = 100+extsat[numsat]-7;
|
---|
[3653] | 1492 | }
|
---|
[2659] | 1493 | if(k)
|
---|
| 1494 | {
|
---|
| 1495 | if(cd.wl == 0.0)
|
---|
| 1496 | wl = GLO_WAVELENGTH_L1(k-100);
|
---|
| 1497 | else if(cd.wl == 1.0)
|
---|
| 1498 | wl = GLO_WAVELENGTH_L2(k-100);
|
---|
| 1499 | }
|
---|
| 1500 | }
|
---|
| 1501 | break;
|
---|
| 1502 | case RTCM3_MSM_GALILEO: cd = gal[RTCM3_MSM_NUMSIG-j-1];
|
---|
| 1503 | wl = cd.wl;
|
---|
| 1504 | break;
|
---|
| 1505 | }
|
---|
| 1506 | if(cd.lock && wl) /* lock cannot have a valid zero value */
|
---|
| 1507 | {
|
---|
[2996] | 1508 | int fullsat = RTCM3_MSM_NUMSAT-i-1, num;
|
---|
| 1509 |
|
---|
| 1510 | if(sys == RTCM3_MSM_GALILEO && fullsat >= 50 && fullsat <= 51)
|
---|
| 1511 | fullsat += PRN_GIOVE_START-50;
|
---|
| 1512 | else
|
---|
[4371] | 1513 | fullsat += start;
|
---|
[2996] | 1514 |
|
---|
[2659] | 1515 | for(num = 0; num < gnss->numsats
|
---|
| 1516 | && fullsat != gnss->satellites[num]; ++num)
|
---|
| 1517 | ;
|
---|
| 1518 |
|
---|
| 1519 | if(num == gnss->numsats)
|
---|
| 1520 | gnss->satellites[gnss->numsats++] = fullsat;
|
---|
| 1521 |
|
---|
[4374] | 1522 | gnss->codetype[num][cd.typeR] =
|
---|
| 1523 | gnss->codetype[num][cd.typeP] =
|
---|
| 1524 | gnss->codetype[num][cd.typeD] =
|
---|
| 1525 | gnss->codetype[num][cd.typeS] = cd.code;
|
---|
[4371] | 1526 | if(!handle->info[sys].type[cd.typeR])
|
---|
| 1527 | {
|
---|
| 1528 | handle->info[sys].type[cd.typeR] =
|
---|
| 1529 | handle->info[sys].type[cd.typeP] =
|
---|
| 1530 | handle->info[sys].type[cd.typeD] =
|
---|
| 1531 | handle->info[sys].type[cd.typeS] = cd.code[1];
|
---|
| 1532 | }
|
---|
[4367] | 1533 |
|
---|
[2659] | 1534 | switch(type % 10)
|
---|
| 1535 | {
|
---|
| 1536 | case 1:
|
---|
[3581] | 1537 | if(psr[count] > -1.0/(1<<10))
|
---|
[2659] | 1538 | {
|
---|
[3581] | 1539 | gnss->measdata[num][cd.typeR] = psr[count]*LIGHTSPEED/1000.0
|
---|
[2668] | 1540 | +(rrmod[numsat])*LIGHTSPEED/1000.0;
|
---|
[4383] | 1541 | gnss->dataflags[num] |= (1LL<<cd.typeR);
|
---|
[2659] | 1542 | }
|
---|
| 1543 | break;
|
---|
| 1544 | case 2:
|
---|
[3581] | 1545 | if(wl && cp[count] > -1.0/(1<<8))
|
---|
[2659] | 1546 | {
|
---|
[3725] | 1547 | gnss->measdata[num][cd.typeP] = cp[count]*LIGHTSPEED/1000.0/wl
|
---|
[2668] | 1548 | +(rrmod[numsat])*LIGHTSPEED/1000.0/wl;
|
---|
[2659] | 1549 | if(handle->lastlockmsm[j][i] != ll[count])
|
---|
| 1550 | {
|
---|
| 1551 | gnss->dataflags2[num] |= cd.lock;
|
---|
| 1552 | handle->lastlockmsm[j][i] = ll[count];
|
---|
| 1553 | }
|
---|
[4383] | 1554 | gnss->dataflags[num] |= (1LL<<cd.typeP);
|
---|
[2659] | 1555 | }
|
---|
| 1556 | break;
|
---|
| 1557 | case 3:
|
---|
[3581] | 1558 | if(psr[count] > -1.0/(1<<10))
|
---|
[2659] | 1559 | {
|
---|
[3581] | 1560 | gnss->measdata[num][cd.typeR] = psr[count]*LIGHTSPEED/1000.0
|
---|
[2668] | 1561 | +(rrmod[numsat])*LIGHTSPEED/1000.0;
|
---|
[4383] | 1562 | gnss->dataflags[num] |= (1LL<<cd.typeR);
|
---|
[2659] | 1563 | }
|
---|
| 1564 |
|
---|
[3581] | 1565 | if(wl && cp[count] > -1.0/(1<<8))
|
---|
[2659] | 1566 | {
|
---|
[3725] | 1567 | gnss->measdata[num][cd.typeP] = cp[count]*LIGHTSPEED/1000.0/wl
|
---|
[2659] | 1568 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0/wl;
|
---|
| 1569 | if(handle->lastlockmsm[j][i] != ll[count])
|
---|
| 1570 | {
|
---|
| 1571 | gnss->dataflags2[num] |= cd.lock;
|
---|
| 1572 | handle->lastlockmsm[j][i] = ll[count];
|
---|
| 1573 | }
|
---|
[4383] | 1574 | gnss->dataflags[num] |= (1LL<<cd.typeP);
|
---|
[2659] | 1575 | }
|
---|
| 1576 | break;
|
---|
| 1577 | case 4:
|
---|
[3581] | 1578 | if(psr[count] > -1.0/(1<<10))
|
---|
[2659] | 1579 | {
|
---|
[3581] | 1580 | gnss->measdata[num][cd.typeR] = psr[count]*LIGHTSPEED/1000.0
|
---|
[2659] | 1581 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0;
|
---|
[4383] | 1582 | gnss->dataflags[num] |= (1LL<<cd.typeR);
|
---|
[2659] | 1583 | }
|
---|
| 1584 |
|
---|
[3581] | 1585 | if(wl && cp[count] > -1.0/(1<<8))
|
---|
[2659] | 1586 | {
|
---|
[3725] | 1587 | gnss->measdata[num][cd.typeP] = cp[count]*LIGHTSPEED/1000.0/wl
|
---|
[2659] | 1588 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0/wl;
|
---|
| 1589 | if(handle->lastlockmsm[j][i] != ll[count])
|
---|
| 1590 | {
|
---|
| 1591 | gnss->dataflags2[num] |= cd.lock;
|
---|
| 1592 | handle->lastlockmsm[j][i] = ll[count];
|
---|
| 1593 | }
|
---|
[4383] | 1594 | gnss->dataflags[num] |= (1LL<<cd.typeP);
|
---|
[2659] | 1595 | }
|
---|
| 1596 |
|
---|
| 1597 | gnss->measdata[num][cd.typeS] = cnr[count];
|
---|
[4383] | 1598 | gnss->dataflags[num] |= (1LL<<cd.typeS);
|
---|
[2659] | 1599 | break;
|
---|
| 1600 | case 5:
|
---|
[3581] | 1601 | if(psr[count] > -1.0/(1<<10))
|
---|
[2659] | 1602 | {
|
---|
[3581] | 1603 | gnss->measdata[num][cd.typeR] = psr[count]*LIGHTSPEED/1000.0
|
---|
[2659] | 1604 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0;
|
---|
[4383] | 1605 | gnss->dataflags[num] |= (1LL<<cd.typeR);
|
---|
[2659] | 1606 | }
|
---|
| 1607 |
|
---|
[3581] | 1608 | if(wl && cp[count] > -1.0/(1<<8))
|
---|
[2659] | 1609 | {
|
---|
[3725] | 1610 | gnss->measdata[num][cd.typeP] = cp[count]*LIGHTSPEED/1000.0/wl
|
---|
[2659] | 1611 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0/wl;
|
---|
| 1612 | if(handle->lastlockmsm[j][i] != ll[count])
|
---|
| 1613 | {
|
---|
| 1614 | gnss->dataflags2[num] |= cd.lock;
|
---|
| 1615 | handle->lastlockmsm[j][i] = ll[count];
|
---|
| 1616 | }
|
---|
[4383] | 1617 | gnss->dataflags[num] |= (1LL<<cd.typeP);
|
---|
[2659] | 1618 | }
|
---|
| 1619 |
|
---|
| 1620 | gnss->measdata[num][cd.typeS] = cnr[count];
|
---|
| 1621 | gnss->dataflags[num] |= (1<<cd.typeS);
|
---|
| 1622 |
|
---|
| 1623 | if(dop[count] > -1.6384)
|
---|
| 1624 | {
|
---|
[2873] | 1625 | gnss->measdata[num][cd.typeD] = -(dop[count]
|
---|
[2849] | 1626 | +rdop[numsat])/wl;
|
---|
[4383] | 1627 | gnss->dataflags[num] |= (1LL<<cd.typeD);
|
---|
[2659] | 1628 | }
|
---|
| 1629 | break;
|
---|
| 1630 | case 6:
|
---|
[3581] | 1631 | if(psr[count] > -1.0/(1<<10))
|
---|
[2659] | 1632 | {
|
---|
[3581] | 1633 | gnss->measdata[num][cd.typeR] = psr[count]*LIGHTSPEED/1000.0
|
---|
[2659] | 1634 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0;
|
---|
[4383] | 1635 | gnss->dataflags[num] |= (1LL<<cd.typeR);
|
---|
[2659] | 1636 | }
|
---|
| 1637 |
|
---|
[3581] | 1638 | if(wl && cp[count] > -1.0/(1<<8))
|
---|
[2659] | 1639 | {
|
---|
[3725] | 1640 | gnss->measdata[num][cd.typeP] = cp[count]*LIGHTSPEED/1000.0/wl
|
---|
[2659] | 1641 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0/wl;
|
---|
| 1642 | if(handle->lastlockmsm[j][i] != ll[count])
|
---|
| 1643 | {
|
---|
| 1644 | gnss->dataflags2[num] |= cd.lock;
|
---|
| 1645 | handle->lastlockmsm[j][i] = ll[count];
|
---|
| 1646 | }
|
---|
[4383] | 1647 | gnss->dataflags[num] |= (1LL<<cd.typeP);
|
---|
[2659] | 1648 | }
|
---|
| 1649 |
|
---|
| 1650 | gnss->measdata[num][cd.typeS] = cnr[count];
|
---|
[4383] | 1651 | gnss->dataflags[num] |= (1LL<<cd.typeS);
|
---|
[2659] | 1652 | break;
|
---|
| 1653 | case 7:
|
---|
[3581] | 1654 | if(psr[count] > -1.0/(1<<10))
|
---|
[2659] | 1655 | {
|
---|
[3581] | 1656 | gnss->measdata[num][cd.typeR] = psr[count]*LIGHTSPEED/1000.0
|
---|
[2659] | 1657 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0;
|
---|
[4383] | 1658 | gnss->dataflags[num] |= (1LL<<cd.typeR);
|
---|
[2659] | 1659 | }
|
---|
| 1660 |
|
---|
[3581] | 1661 | if(wl && cp[count] > -1.0/(1<<8))
|
---|
[2659] | 1662 | {
|
---|
[3725] | 1663 | gnss->measdata[num][cd.typeP] = cp[count]*LIGHTSPEED/1000.0/wl
|
---|
[2659] | 1664 | +(rrmod[numsat]+rrint[numsat])*LIGHTSPEED/1000.0/wl;
|
---|
| 1665 | if(handle->lastlockmsm[j][i] != ll[count])
|
---|
| 1666 | {
|
---|
| 1667 | gnss->dataflags2[num] |= cd.lock;
|
---|
| 1668 | handle->lastlockmsm[j][i] = ll[count];
|
---|
| 1669 | }
|
---|
[4383] | 1670 | gnss->dataflags[num] |= (1LL<<cd.typeP);
|
---|
[2659] | 1671 | }
|
---|
| 1672 |
|
---|
| 1673 | gnss->measdata[num][cd.typeS] = cnr[count];
|
---|
[4383] | 1674 | gnss->dataflags[num] |= (1LL<<cd.typeS);
|
---|
[2659] | 1675 |
|
---|
| 1676 | if(dop[count] > -1.6384)
|
---|
| 1677 | {
|
---|
[2873] | 1678 | gnss->measdata[num][cd.typeD] = -(dop[count]
|
---|
[2849] | 1679 | +rdop[numsat])/wl;
|
---|
[4383] | 1680 | gnss->dataflags[num] |= (1LL<<cd.typeD);
|
---|
[2659] | 1681 | }
|
---|
| 1682 | break;
|
---|
| 1683 | }
|
---|
| 1684 | }
|
---|
| 1685 | }
|
---|
| 1686 | }
|
---|
| 1687 | }
|
---|
| 1688 | if(!syncf && !old)
|
---|
| 1689 | {
|
---|
| 1690 | handle->Data = *gnss;
|
---|
| 1691 | memset(gnss, 0, sizeof(*gnss));
|
---|
| 1692 | }
|
---|
| 1693 | if(!syncf || old)
|
---|
| 1694 | {
|
---|
[2668] | 1695 | if(!wasnoamb) /* not RINEX compatible without */
|
---|
[2659] | 1696 | ret = 1;
|
---|
| 1697 | else
|
---|
| 1698 | ret = 2;
|
---|
| 1699 | }
|
---|
| 1700 | #ifdef NO_RTCM3_MAIN
|
---|
| 1701 | else
|
---|
| 1702 | ret = type;
|
---|
| 1703 | #endif /* NO_RTCM3_MAIN */
|
---|
| 1704 | }
|
---|
| 1705 | break;
|
---|
[27] | 1706 | }
|
---|
| 1707 | }
|
---|
| 1708 | return ret;
|
---|
| 1709 | }
|
---|
| 1710 |
|
---|
| 1711 | struct Header
|
---|
| 1712 | {
|
---|
| 1713 | const char *version;
|
---|
| 1714 | const char *pgm;
|
---|
| 1715 | const char *marker;
|
---|
[503] | 1716 | const char *markertype;
|
---|
[27] | 1717 | const char *observer;
|
---|
| 1718 | const char *receiver;
|
---|
| 1719 | const char *antenna;
|
---|
| 1720 | const char *position;
|
---|
| 1721 | const char *antennaposition;
|
---|
| 1722 | const char *wavelength;
|
---|
| 1723 | const char *typesofobs; /* should not be modified outside */
|
---|
[502] | 1724 | const char *typesofobsG; /* should not be modified outside */
|
---|
| 1725 | const char *typesofobsR; /* should not be modified outside */
|
---|
| 1726 | const char *typesofobsS; /* should not be modified outside */
|
---|
[2699] | 1727 | const char *typesofobsE; /* should not be modified outside */
|
---|
[4367] | 1728 | const char *typesofobsC; /* should not be modified outside */
|
---|
| 1729 | const char *typesofobsJ; /* should not be modified outside */
|
---|
[27] | 1730 | const char *timeoffirstobs; /* should not be modified outside */
|
---|
| 1731 | };
|
---|
| 1732 |
|
---|
| 1733 | #define MAXHEADERLINES 50
|
---|
| 1734 | #define MAXHEADERBUFFERSIZE 4096
|
---|
| 1735 | struct HeaderData
|
---|
| 1736 | {
|
---|
| 1737 | union
|
---|
| 1738 | {
|
---|
| 1739 | struct Header named;
|
---|
| 1740 | const char *unnamed[MAXHEADERLINES];
|
---|
| 1741 | } data;
|
---|
| 1742 | int numheaders;
|
---|
| 1743 | };
|
---|
| 1744 |
|
---|
[1092] | 1745 | void converttime(struct converttimeinfo *c, int week, int tow)
|
---|
[270] | 1746 | {
|
---|
| 1747 | int i, k, doy, j; /* temporary variables */
|
---|
| 1748 | j = week*(7*24*60*60) + tow + 5*24*60*60;
|
---|
| 1749 | for(i = 1980; j >= (k = (365+longyear(i,0))*24*60*60); ++i)
|
---|
| 1750 | j -= k;
|
---|
| 1751 | c->year = i;
|
---|
| 1752 | doy = 1+ (j / (24*60*60));
|
---|
| 1753 | j %= (24*60*60);
|
---|
| 1754 | c->hour = j / (60*60);
|
---|
| 1755 | j %= (60*60);
|
---|
| 1756 | c->minute = j / 60;
|
---|
| 1757 | c->second = j % 60;
|
---|
| 1758 | j = 0;
|
---|
| 1759 | for(i = 1; j + (k = months[i] + longyear(c->year,i)) < doy; ++i)
|
---|
| 1760 | j += k;
|
---|
| 1761 | c->month = i;
|
---|
| 1762 | c->day = doy - j;
|
---|
| 1763 | }
|
---|
| 1764 |
|
---|
[318] | 1765 | #ifndef NO_RTCM3_MAIN
|
---|
| 1766 | void RTCM3Error(const char *fmt, ...)
|
---|
| 1767 | {
|
---|
| 1768 | va_list v;
|
---|
| 1769 | va_start(v, fmt);
|
---|
| 1770 | vfprintf(stderr, fmt, v);
|
---|
| 1771 | va_end(v);
|
---|
| 1772 | }
|
---|
| 1773 | #endif
|
---|
| 1774 |
|
---|
| 1775 | void RTCM3Text(const char *fmt, ...)
|
---|
| 1776 | {
|
---|
| 1777 | va_list v;
|
---|
| 1778 | va_start(v, fmt);
|
---|
| 1779 | vprintf(fmt, v);
|
---|
| 1780 | va_end(v);
|
---|
| 1781 | }
|
---|
| 1782 |
|
---|
[2487] | 1783 | static void fixrevision(void)
|
---|
| 1784 | {
|
---|
| 1785 | if(revisionstr[0] == '$')
|
---|
| 1786 | {
|
---|
| 1787 | char *a;
|
---|
| 1788 | int i=sizeof(RTCM3TORINEX_VERSION); /* set version to 1.<revision> */
|
---|
| 1789 | strcpy(revisionstr, RTCM3TORINEX_VERSION ".");
|
---|
| 1790 | for(a = revisionstr+11; *a && *a != ' '; ++a)
|
---|
| 1791 | revisionstr[i++] = *a;
|
---|
| 1792 | revisionstr[i] = 0;
|
---|
| 1793 | }
|
---|
| 1794 | }
|
---|
| 1795 |
|
---|
[503] | 1796 | static int HandleRunBy(char *buffer, int buffersize, const char **u,
|
---|
| 1797 | int rinex3)
|
---|
[502] | 1798 | {
|
---|
| 1799 | const char *user;
|
---|
| 1800 | time_t t;
|
---|
| 1801 | struct tm * t2;
|
---|
| 1802 |
|
---|
| 1803 | #ifdef NO_RTCM3_MAIN
|
---|
[2487] | 1804 | fixrevision();
|
---|
[502] | 1805 | #endif
|
---|
| 1806 |
|
---|
| 1807 | user= getenv("USER");
|
---|
| 1808 | if(!user) user = "";
|
---|
| 1809 | t = time(&t);
|
---|
| 1810 | t2 = gmtime(&t);
|
---|
| 1811 | if(u) *u = user;
|
---|
| 1812 | return 1+snprintf(buffer, buffersize,
|
---|
[1088] | 1813 | rinex3 ?
|
---|
[4371] | 1814 | "RTCM3TORINEX %-7.7s%-20.20s%04d%02d%02d %02d%02d%02d UTC "
|
---|
[503] | 1815 | "PGM / RUN BY / DATE" :
|
---|
[4371] | 1816 | "RTCM3TORINEX %-7.7s%-20.20s%04d-%02d-%02d %02d:%02d "
|
---|
[502] | 1817 | "PGM / RUN BY / DATE", revisionstr, user, 1900+t2->tm_year,
|
---|
[503] | 1818 | t2->tm_mon+1, t2->tm_mday, t2->tm_hour, t2->tm_min, t2->tm_sec);
|
---|
[502] | 1819 | }
|
---|
| 1820 |
|
---|
[1092] | 1821 | #ifdef NO_RTCM3_MAIN
|
---|
| 1822 | #define NUMSTARTSKIP 1
|
---|
| 1823 | #else
|
---|
[318] | 1824 | #define NUMSTARTSKIP 3
|
---|
[1092] | 1825 | #endif
|
---|
| 1826 |
|
---|
[5358] | 1827 | int HandleObsHeader(struct RTCM3ParserData *Parser, char *buffer,
|
---|
| 1828 | size_t buffersize, struct HeaderData *hdata)
|
---|
[27] | 1829 | {
|
---|
[5358] | 1830 | int buffersizeold = buffersize;
|
---|
| 1831 | int i, modified = 0;
|
---|
| 1832 |
|
---|
[1092] | 1833 | if(Parser->rinex3)
|
---|
| 1834 | {
|
---|
[5358] | 1835 | int flags;
|
---|
[1092] | 1836 | #define CHECKFLAGSNEW(a, b, c) \
|
---|
[5358] | 1837 | if(flags & GNSSDF_##b##DATA) \
|
---|
[1092] | 1838 | { \
|
---|
[5358] | 1839 | int new = hdata ? 1 : 0; \
|
---|
| 1840 | if(!hdata) /* check if already known */ \
|
---|
[1092] | 1841 | { \
|
---|
[5358] | 1842 | int ic; \
|
---|
| 1843 | for(ic = 0; ic < Parser->info[RTCM3_MSM_##a].numtypes \
|
---|
| 1844 | && Parser->info[RTCM3_MSM_##a].flags[ic] != GNSSDF_##b##DATA; ++ic) \
|
---|
| 1845 | ; \
|
---|
| 1846 | if(ic == Parser->info[RTCM3_MSM_##a].numtypes) \
|
---|
| 1847 | new = 1; \
|
---|
[1092] | 1848 | } \
|
---|
[5358] | 1849 | if(new) \
|
---|
[1092] | 1850 | { \
|
---|
[5358] | 1851 | Parser->info[RTCM3_MSM_##a].flags[Parser->info[RTCM3_MSM_##a].numtypes] \
|
---|
| 1852 | = GNSSDF_##b##DATA; \
|
---|
| 1853 | Parser->info[RTCM3_MSM_##a].pos[Parser->info[RTCM3_MSM_##a].numtypes] \
|
---|
| 1854 | = GNSSENTRY_##b##DATA; \
|
---|
| 1855 | if(Parser->info[RTCM3_MSM_##a].type[GNSSENTRY_##b##DATA]) \
|
---|
| 1856 | { \
|
---|
| 1857 | snprintf(Parser->fieldbuffer##a+4*Parser->info[RTCM3_MSM_##a].numtypes, \
|
---|
| 1858 | sizeof(Parser->fieldbuffer##a)-4*Parser->info[RTCM3_MSM_##a].numtypes, \
|
---|
| 1859 | " %-2.2s%c", #c, Parser->info[RTCM3_MSM_##a].type[GNSSENTRY_##b##DATA]); \
|
---|
| 1860 | } \
|
---|
| 1861 | else \
|
---|
| 1862 | { \
|
---|
| 1863 | snprintf(Parser->fieldbuffer##a+4*Parser->info[RTCM3_MSM_##a].numtypes, \
|
---|
| 1864 | sizeof(Parser->fieldbuffer##a)-4*Parser->info[RTCM3_MSM_##a].numtypes, \
|
---|
| 1865 | " %-3s", #c); \
|
---|
| 1866 | } \
|
---|
| 1867 | ++Parser->info[RTCM3_MSM_##a].numtypes; \
|
---|
| 1868 | ++modified; \
|
---|
[1092] | 1869 | } \
|
---|
| 1870 | }
|
---|
| 1871 |
|
---|
[5358] | 1872 | #define INITFLAGS(a) \
|
---|
| 1873 | flags = Parser->startflags; \
|
---|
| 1874 | modified = 0; \
|
---|
| 1875 | for(i = 0; i < Parser->Data.numsats; ++i) \
|
---|
[502] | 1876 | { \
|
---|
[5358] | 1877 | if(Parser->Data.satellites[i] >= PRN_##a##_START \
|
---|
| 1878 | && Parser->Data.satellites[i] <= PRN_##a##_END) \
|
---|
| 1879 | flags |= Parser->Data.dataflags[i]; \
|
---|
[502] | 1880 | }
|
---|
| 1881 |
|
---|
[5358] | 1882 | INITFLAGS(SBAS)
|
---|
[4371] | 1883 | CHECKFLAGSNEW(SBAS, C1, C1C)
|
---|
| 1884 | CHECKFLAGSNEW(SBAS, L1C, L1C)
|
---|
| 1885 | CHECKFLAGSNEW(SBAS, D1C, D1C)
|
---|
| 1886 | CHECKFLAGSNEW(SBAS, S1C, S1C)
|
---|
| 1887 | CHECKFLAGSNEW(SBAS, C5, C5)
|
---|
| 1888 | CHECKFLAGSNEW(SBAS, L5, L5)
|
---|
| 1889 | CHECKFLAGSNEW(SBAS, D5, D5)
|
---|
| 1890 | CHECKFLAGSNEW(SBAS, S5, S5)
|
---|
| 1891 |
|
---|
[5358] | 1892 | if(modified)
|
---|
| 1893 | {
|
---|
| 1894 | if(hdata)
|
---|
| 1895 | hdata->data.named.typesofobsS = buffer;
|
---|
| 1896 | i = 1+snprintf(buffer, buffersize,
|
---|
| 1897 | "S %3d%-52.52s SYS / # / OBS TYPES",
|
---|
| 1898 | Parser->info[RTCM3_MSM_SBAS].numtypes, Parser->fieldbufferSBAS);
|
---|
| 1899 | buffer += i; buffersize -= i;
|
---|
| 1900 | }
|
---|
[4371] | 1901 |
|
---|
[5358] | 1902 | INITFLAGS(GPS)
|
---|
[502] | 1903 | CHECKFLAGSNEW(GPS, C1, C1C)
|
---|
| 1904 | CHECKFLAGSNEW(GPS, L1C, L1C)
|
---|
| 1905 | CHECKFLAGSNEW(GPS, D1C, D1C)
|
---|
| 1906 | CHECKFLAGSNEW(GPS, S1C, S1C)
|
---|
[2699] | 1907 | CHECKFLAGSNEW(GPS, P1, C1W)
|
---|
| 1908 | CHECKFLAGSNEW(GPS, L1P, L1W)
|
---|
| 1909 | CHECKFLAGSNEW(GPS, D1P, D1W)
|
---|
| 1910 | CHECKFLAGSNEW(GPS, S1P, S1W)
|
---|
[4367] | 1911 | CHECKFLAGSNEW(GPS, C5, C5)
|
---|
| 1912 | CHECKFLAGSNEW(GPS, L5, L5)
|
---|
| 1913 | CHECKFLAGSNEW(GPS, D5, D5)
|
---|
| 1914 | CHECKFLAGSNEW(GPS, S5, S5)
|
---|
[4383] | 1915 | CHECKFLAGSNEW(GPS, P2, C2W)
|
---|
| 1916 | CHECKFLAGSNEW(GPS, L2P, L2W)
|
---|
| 1917 | CHECKFLAGSNEW(GPS, D2P, D2W)
|
---|
| 1918 | CHECKFLAGSNEW(GPS, S2P, S2W)
|
---|
| 1919 | CHECKFLAGSNEW(GPS, C2, C2)
|
---|
| 1920 | CHECKFLAGSNEW(GPS, L2C, L2)
|
---|
| 1921 | CHECKFLAGSNEW(GPS, D2C, D2)
|
---|
| 1922 | CHECKFLAGSNEW(GPS, S2C, S2)
|
---|
[4371] | 1923 | CHECKFLAGSNEW(GPS, C1N, C1)
|
---|
| 1924 | CHECKFLAGSNEW(GPS, L1N, L1)
|
---|
| 1925 | CHECKFLAGSNEW(GPS, D1N, D1)
|
---|
| 1926 | CHECKFLAGSNEW(GPS, S1N, S1)
|
---|
[502] | 1927 |
|
---|
[5358] | 1928 | if(modified)
|
---|
[502] | 1929 | {
|
---|
[5358] | 1930 | if(hdata)
|
---|
| 1931 | hdata->data.named.typesofobsG = buffer;
|
---|
| 1932 | i = 1+snprintf(buffer, buffersize,
|
---|
| 1933 | "G %3d%-52.52s SYS / # / OBS TYPES",
|
---|
| 1934 | Parser->info[RTCM3_MSM_GPS].numtypes, Parser->fieldbufferGPS);
|
---|
| 1935 | if(Parser->info[RTCM3_MSM_GPS].numtypes>13)
|
---|
| 1936 | {
|
---|
| 1937 | i += snprintf(buffer+i-1, buffersize,
|
---|
| 1938 | "\n %-52.52s SYS / # / OBS TYPES", Parser->fieldbufferGPS+13*4);
|
---|
| 1939 | }
|
---|
| 1940 | buffer += i; buffersize -= i;
|
---|
[502] | 1941 | }
|
---|
| 1942 |
|
---|
[5358] | 1943 | INITFLAGS(GLONASS)
|
---|
[4371] | 1944 | CHECKFLAGSNEW(GLONASS, C1, C1C)
|
---|
| 1945 | CHECKFLAGSNEW(GLONASS, L1C, L1C)
|
---|
| 1946 | CHECKFLAGSNEW(GLONASS, D1C, D1C)
|
---|
| 1947 | CHECKFLAGSNEW(GLONASS, S1C, S1C)
|
---|
| 1948 | CHECKFLAGSNEW(GLONASS, P1, C1P)
|
---|
| 1949 | CHECKFLAGSNEW(GLONASS, L1P, L1P)
|
---|
| 1950 | CHECKFLAGSNEW(GLONASS, D1P, D1P)
|
---|
| 1951 | CHECKFLAGSNEW(GLONASS, S1P, S1P)
|
---|
| 1952 | CHECKFLAGSNEW(GLONASS, P2, C2P)
|
---|
| 1953 | CHECKFLAGSNEW(GLONASS, L2P, L2P)
|
---|
| 1954 | CHECKFLAGSNEW(GLONASS, D2P, D2P)
|
---|
| 1955 | CHECKFLAGSNEW(GLONASS, S2P, S2P)
|
---|
| 1956 | CHECKFLAGSNEW(GLONASS, C2, C2C)
|
---|
| 1957 | CHECKFLAGSNEW(GLONASS, L2C, L2C)
|
---|
| 1958 | CHECKFLAGSNEW(GLONASS, D2C, D2C)
|
---|
| 1959 | CHECKFLAGSNEW(GLONASS, S2C, S2C)
|
---|
[502] | 1960 |
|
---|
[5358] | 1961 | if(modified)
|
---|
[502] | 1962 | {
|
---|
[5358] | 1963 | if(hdata)
|
---|
| 1964 | hdata->data.named.typesofobsR = buffer;
|
---|
| 1965 | i = 1+snprintf(buffer, buffersize,
|
---|
| 1966 | "R %3d%-52.52s SYS / # / OBS TYPES",
|
---|
| 1967 | Parser->info[RTCM3_MSM_GLONASS].numtypes, Parser->fieldbufferGLONASS);
|
---|
| 1968 | if(Parser->info[RTCM3_MSM_GLONASS].numtypes>13)
|
---|
| 1969 | {
|
---|
| 1970 | i += snprintf(buffer+i-1, buffersize,
|
---|
| 1971 | "\n %-52.52s SYS / # / OBS TYPES", Parser->fieldbufferGLONASS+13*4);
|
---|
| 1972 | }
|
---|
| 1973 | buffer += i; buffersize -= i;
|
---|
[502] | 1974 | }
|
---|
[2699] | 1975 |
|
---|
[5358] | 1976 | INITFLAGS(GALGIO)
|
---|
[4371] | 1977 | CHECKFLAGSNEW(GALILEO, C1, C1)
|
---|
| 1978 | CHECKFLAGSNEW(GALILEO, L1C, L1)
|
---|
| 1979 | CHECKFLAGSNEW(GALILEO, D1C, D1)
|
---|
| 1980 | CHECKFLAGSNEW(GALILEO, S1C, S1)
|
---|
| 1981 | CHECKFLAGSNEW(GALILEO, C6, C6)
|
---|
| 1982 | CHECKFLAGSNEW(GALILEO, L6, L6)
|
---|
| 1983 | CHECKFLAGSNEW(GALILEO, D6, D6)
|
---|
| 1984 | CHECKFLAGSNEW(GALILEO, S6, S6)
|
---|
| 1985 | CHECKFLAGSNEW(GALILEO, C5, C5)
|
---|
| 1986 | CHECKFLAGSNEW(GALILEO, L5, L5)
|
---|
| 1987 | CHECKFLAGSNEW(GALILEO, D5, D5)
|
---|
| 1988 | CHECKFLAGSNEW(GALILEO, S5, S5)
|
---|
| 1989 | CHECKFLAGSNEW(GALILEO, C5B, C7)
|
---|
| 1990 | CHECKFLAGSNEW(GALILEO, L5B, L7)
|
---|
| 1991 | CHECKFLAGSNEW(GALILEO, D5B, D7)
|
---|
| 1992 | CHECKFLAGSNEW(GALILEO, S5B, S7)
|
---|
| 1993 | CHECKFLAGSNEW(GALILEO, C5AB, C8)
|
---|
| 1994 | CHECKFLAGSNEW(GALILEO, L5AB, L8)
|
---|
| 1995 | CHECKFLAGSNEW(GALILEO, D5AB, D8)
|
---|
| 1996 | CHECKFLAGSNEW(GALILEO, S5AB, S8)
|
---|
[2699] | 1997 |
|
---|
[5358] | 1998 | if(modified)
|
---|
[2699] | 1999 | {
|
---|
[5358] | 2000 | if(hdata)
|
---|
| 2001 | hdata->data.named.typesofobsE = buffer;
|
---|
| 2002 | i = 1+snprintf(buffer, buffersize,
|
---|
| 2003 | "E %3d%-52.52s SYS / # / OBS TYPES",
|
---|
| 2004 | Parser->info[RTCM3_MSM_GALILEO].numtypes, Parser->fieldbufferGALILEO);
|
---|
| 2005 | if(Parser->info[RTCM3_MSM_GALILEO].numtypes>13)
|
---|
| 2006 | {
|
---|
| 2007 | i += snprintf(buffer+i-1, buffersize,
|
---|
| 2008 | "\n %-52.52s SYS / # / OBS TYPES", Parser->fieldbufferGALILEO+13*4);
|
---|
| 2009 | }
|
---|
| 2010 | buffer += i; buffersize -= i;
|
---|
[2699] | 2011 | }
|
---|
[4367] | 2012 |
|
---|
[5358] | 2013 | INITFLAGS(COMPASS)
|
---|
[4371] | 2014 | CHECKFLAGSNEW(COMPASS, CB1, C2I)
|
---|
| 2015 | CHECKFLAGSNEW(COMPASS, LB1, L2I)
|
---|
| 2016 | CHECKFLAGSNEW(COMPASS, DB1, D2I)
|
---|
| 2017 | CHECKFLAGSNEW(COMPASS, SB1, S2I)
|
---|
| 2018 | CHECKFLAGSNEW(COMPASS, CB2, C7I)
|
---|
| 2019 | CHECKFLAGSNEW(COMPASS, LB2, L7I)
|
---|
| 2020 | CHECKFLAGSNEW(COMPASS, DB2, D7I)
|
---|
| 2021 | CHECKFLAGSNEW(COMPASS, SB2, S7I)
|
---|
| 2022 | CHECKFLAGSNEW(COMPASS, CB3, C6I)
|
---|
| 2023 | CHECKFLAGSNEW(COMPASS, LB3, L6I)
|
---|
| 2024 | CHECKFLAGSNEW(COMPASS, DB3, D6I)
|
---|
| 2025 | CHECKFLAGSNEW(COMPASS, SB3, S6I)
|
---|
[4367] | 2026 |
|
---|
[5358] | 2027 | if(modified)
|
---|
[4367] | 2028 | {
|
---|
[5358] | 2029 | if(hdata)
|
---|
| 2030 | hdata->data.named.typesofobsC = buffer;
|
---|
| 2031 | i = 1+snprintf(buffer, buffersize,
|
---|
| 2032 | "C %3d%-52.52s SYS / # / OBS TYPES",
|
---|
| 2033 | Parser->info[RTCM3_MSM_COMPASS].numtypes, Parser->fieldbufferCOMPASS);
|
---|
| 2034 | if(Parser->info[RTCM3_MSM_COMPASS].numtypes>13)
|
---|
| 2035 | {
|
---|
| 2036 | i += snprintf(buffer+i-1, buffersize,
|
---|
| 2037 | "\n %-52.52s SYS / # / OBS TYPES", Parser->fieldbufferCOMPASS+13*4);
|
---|
| 2038 | }
|
---|
| 2039 | buffer += i; buffersize -= i;
|
---|
[4367] | 2040 | }
|
---|
| 2041 |
|
---|
[5358] | 2042 | INITFLAGS(QZSS)
|
---|
[4367] | 2043 |
|
---|
[4371] | 2044 | CHECKFLAGSNEW(QZSS, C1, C1C)
|
---|
| 2045 | CHECKFLAGSNEW(QZSS, L1C, L1C)
|
---|
| 2046 | CHECKFLAGSNEW(QZSS, D1C, D1C)
|
---|
| 2047 | CHECKFLAGSNEW(QZSS, S1C, S1C)
|
---|
[4367] | 2048 |
|
---|
[4371] | 2049 | CHECKFLAGSNEW(QZSS, CSAIF, C1Z)
|
---|
| 2050 | CHECKFLAGSNEW(QZSS, LSAIF, L1Z)
|
---|
| 2051 | CHECKFLAGSNEW(QZSS, DSAIF, D1Z)
|
---|
| 2052 | CHECKFLAGSNEW(QZSS, SSAIF, S1Z)
|
---|
[4367] | 2053 |
|
---|
[4371] | 2054 | CHECKFLAGSNEW(QZSS, C1N, C1)
|
---|
| 2055 | CHECKFLAGSNEW(QZSS, L1N, L1)
|
---|
| 2056 | CHECKFLAGSNEW(QZSS, D1N, D1)
|
---|
| 2057 | CHECKFLAGSNEW(QZSS, S1N, S1)
|
---|
[4367] | 2058 |
|
---|
[4371] | 2059 | CHECKFLAGSNEW(QZSS, C6, C6)
|
---|
| 2060 | CHECKFLAGSNEW(QZSS, L6, L6)
|
---|
| 2061 | CHECKFLAGSNEW(QZSS, D6, D6)
|
---|
| 2062 | CHECKFLAGSNEW(QZSS, S6, S6)
|
---|
[4367] | 2063 |
|
---|
[4371] | 2064 | CHECKFLAGSNEW(QZSS, C2, C2)
|
---|
| 2065 | CHECKFLAGSNEW(QZSS, L2C, L2)
|
---|
| 2066 | CHECKFLAGSNEW(QZSS, D2C, D2)
|
---|
| 2067 | CHECKFLAGSNEW(QZSS, S2C, S2)
|
---|
[4367] | 2068 |
|
---|
[4371] | 2069 | CHECKFLAGSNEW(QZSS, C5, C5)
|
---|
| 2070 | CHECKFLAGSNEW(QZSS, L5, L5)
|
---|
| 2071 | CHECKFLAGSNEW(QZSS, D5, D5)
|
---|
| 2072 | CHECKFLAGSNEW(QZSS, S5, S5)
|
---|
[4367] | 2073 |
|
---|
[5358] | 2074 | if(modified)
|
---|
[4367] | 2075 | {
|
---|
[5358] | 2076 | if(hdata)
|
---|
| 2077 | hdata->data.named.typesofobsJ = buffer;
|
---|
| 2078 | i = 1+snprintf(buffer, buffersize,
|
---|
| 2079 | "J %3d%-52.52s SYS / # / OBS TYPES",
|
---|
| 2080 | Parser->info[RTCM3_MSM_QZSS].numtypes, Parser->fieldbufferQZSS);
|
---|
| 2081 | if(Parser->info[RTCM3_MSM_QZSS].numtypes>13)
|
---|
| 2082 | {
|
---|
| 2083 | i += snprintf(buffer+i-1, buffersize,
|
---|
| 2084 | "\n %-52.52s SYS / # / OBS TYPES", Parser->fieldbufferQZSS+13*4);
|
---|
| 2085 | }
|
---|
| 2086 | buffer += i; buffersize -= i;
|
---|
[4367] | 2087 | }
|
---|
[502] | 2088 | }
|
---|
| 2089 | else
|
---|
| 2090 | {
|
---|
[27] | 2091 | #define CHECKFLAGS(a, b) \
|
---|
[363] | 2092 | if(flags & GNSSDF_##a##DATA) \
|
---|
[27] | 2093 | { \
|
---|
[5358] | 2094 | if(Parser->datafields[RINEXENTRY_##b##DATA]) \
|
---|
[363] | 2095 | { \
|
---|
[5358] | 2096 | Parser->info[RTCM3_MSM_GPS].flags[Parser->datafields[\
|
---|
| 2097 | RINEXENTRY_##b##DATA]-1] = GNSSDF_##a##DATA; \
|
---|
| 2098 | Parser->info[RTCM3_MSM_GPS].pos[Parser->datafields[\
|
---|
| 2099 | RINEXENTRY_##b##DATA]-1] = GNSSENTRY_##a##DATA; \
|
---|
[363] | 2100 | } \
|
---|
| 2101 | else \
|
---|
| 2102 | { \
|
---|
[4371] | 2103 | Parser->flags[Parser->info[RTCM3_MSM_GPS].numtypes] = GNSSDF_##a##DATA; \
|
---|
| 2104 | Parser->pos[Parser->info[RTCM3_MSM_GPS].numtypes] = GNSSENTRY_##a##DATA; \
|
---|
[5358] | 2105 | Parser->datafields[RINEXENTRY_##b##DATA] = \
|
---|
| 2106 | ++Parser->info[RTCM3_MSM_GPS].numtypes; \
|
---|
| 2107 | snprintf(Parser->fieldbuffer+6*Parser->numdatafields, \
|
---|
| 2108 | sizeof(Parser->fieldbuffer)-6*Parser->numdatafields, " "#b); \
|
---|
| 2109 | ++Parser->numdatafields; \
|
---|
| 2110 | ++modified; \
|
---|
[363] | 2111 | } \
|
---|
[27] | 2112 | }
|
---|
| 2113 |
|
---|
[318] | 2114 | int flags = Parser->startflags;
|
---|
[27] | 2115 | for(i = 0; i < Parser->Data.numsats; ++i)
|
---|
| 2116 | flags |= Parser->Data.dataflags[i];
|
---|
| 2117 |
|
---|
| 2118 | CHECKFLAGS(C1,C1)
|
---|
| 2119 | CHECKFLAGS(C2,C2)
|
---|
| 2120 | CHECKFLAGS(P1,P1)
|
---|
| 2121 | CHECKFLAGS(P2,P2)
|
---|
| 2122 | CHECKFLAGS(L1C,L1)
|
---|
| 2123 | CHECKFLAGS(L1P,L1)
|
---|
| 2124 | CHECKFLAGS(L2C,L2)
|
---|
| 2125 | CHECKFLAGS(L2P,L2)
|
---|
| 2126 | CHECKFLAGS(D1C,D1)
|
---|
| 2127 | CHECKFLAGS(D1P,D1)
|
---|
| 2128 | CHECKFLAGS(D2C,D2)
|
---|
| 2129 | CHECKFLAGS(D2P,D2)
|
---|
| 2130 | CHECKFLAGS(S1C,S1)
|
---|
| 2131 | CHECKFLAGS(S1P,S1)
|
---|
| 2132 | CHECKFLAGS(S2C,S2)
|
---|
| 2133 | CHECKFLAGS(S2P,S2)
|
---|
[2659] | 2134 | CHECKFLAGS(C5,C5)
|
---|
| 2135 | CHECKFLAGS(L5,L5)
|
---|
| 2136 | CHECKFLAGS(D5,D5)
|
---|
| 2137 | CHECKFLAGS(S5,S5)
|
---|
[4367] | 2138 | CHECKFLAGS(C5AB,C8)
|
---|
| 2139 | CHECKFLAGS(L5AB,L8)
|
---|
| 2140 | CHECKFLAGS(D5AB,D8)
|
---|
| 2141 | CHECKFLAGS(S5AB,S8)
|
---|
| 2142 | CHECKFLAGS(C5B,C7)
|
---|
| 2143 | CHECKFLAGS(L5B,L7)
|
---|
| 2144 | CHECKFLAGS(D5B,D7)
|
---|
| 2145 | CHECKFLAGS(S5B,S7)
|
---|
[2659] | 2146 | CHECKFLAGS(C6,C6)
|
---|
| 2147 | CHECKFLAGS(L6,L6)
|
---|
| 2148 | CHECKFLAGS(D6,D6)
|
---|
| 2149 | CHECKFLAGS(S6,S6)
|
---|
[4369] | 2150 | /* Skip C1N and SAIF for RINEX2! */
|
---|
[27] | 2151 |
|
---|
[5358] | 2152 | if(hdata)
|
---|
| 2153 | hdata->data.named.typesofobs = buffer;
|
---|
| 2154 | if(modified)
|
---|
[27] | 2155 | {
|
---|
[5358] | 2156 | i = 1+snprintf(buffer, buffersize,
|
---|
| 2157 | "%6d%-54.54s# / TYPES OF OBSERV", Parser->info[RTCM3_MSM_GPS].numtypes,
|
---|
| 2158 | Parser->fieldbuffer);
|
---|
| 2159 | if(Parser->info[RTCM3_MSM_GPS].numtypes>9)
|
---|
| 2160 | {
|
---|
| 2161 | i += snprintf(buffer+i-1, buffersize,
|
---|
| 2162 | "\n %-54.54s# / TYPES OF OBSERV", Parser->fieldbuffer+9*6);
|
---|
| 2163 | }
|
---|
| 2164 | if(Parser->info[RTCM3_MSM_GPS].numtypes>18)
|
---|
| 2165 | {
|
---|
| 2166 | i += snprintf(buffer+i-1, buffersize,
|
---|
| 2167 | "\n %-54.54s# / TYPES OF OBSERV", Parser->fieldbuffer+18*6);
|
---|
| 2168 | }
|
---|
| 2169 | buffer += i; buffersize -= i;
|
---|
[27] | 2170 | }
|
---|
[5358] | 2171 | }
|
---|
| 2172 | return buffersizeold - buffersize;
|
---|
| 2173 | }
|
---|
| 2174 |
|
---|
| 2175 | void HandleHeader(struct RTCM3ParserData *Parser)
|
---|
| 2176 | {
|
---|
| 2177 | #ifdef NO_RTCM3_MAIN
|
---|
[5363] | 2178 | int flags, modified = 0;
|
---|
[5358] | 2179 | if(Parser->allflags == 0)
|
---|
| 2180 | Parser->allflags = ~0;
|
---|
[5363] | 2181 | flags = Parser->allflags;
|
---|
[5358] | 2182 | if(Parser->rinex3)
|
---|
| 2183 | {
|
---|
[5360] | 2184 | struct HeaderData *hdata = 0;
|
---|
[5358] | 2185 | CHECKFLAGSNEW(GPS, C1, C1C)
|
---|
| 2186 | CHECKFLAGSNEW(GPS, L1C, L1C)
|
---|
| 2187 | CHECKFLAGSNEW(GPS, D1C, D1C)
|
---|
| 2188 | CHECKFLAGSNEW(GPS, S1C, S1C)
|
---|
| 2189 | CHECKFLAGSNEW(GPS, P1, C1P)
|
---|
| 2190 | CHECKFLAGSNEW(GPS, L1P, L1P)
|
---|
| 2191 | CHECKFLAGSNEW(GPS, D1P, D1P)
|
---|
| 2192 | CHECKFLAGSNEW(GPS, S1P, S1P)
|
---|
| 2193 | CHECKFLAGSNEW(GPS, P2, C2P)
|
---|
| 2194 | CHECKFLAGSNEW(GPS, L2P, L2P)
|
---|
| 2195 | CHECKFLAGSNEW(GPS, D2P, D2P)
|
---|
| 2196 | CHECKFLAGSNEW(GPS, S2P, S2P)
|
---|
| 2197 | CHECKFLAGSNEW(GPS, C2, C2X)
|
---|
| 2198 | CHECKFLAGSNEW(GPS, L2C, L2X)
|
---|
| 2199 | CHECKFLAGSNEW(GPS, D2C, D2X)
|
---|
| 2200 | CHECKFLAGSNEW(GPS, S2C, S2X)
|
---|
| 2201 | CHECKFLAGSNEW(GLONASS, C1, C1C)
|
---|
| 2202 | CHECKFLAGSNEW(GLONASS, L1C, L1C)
|
---|
| 2203 | CHECKFLAGSNEW(GLONASS, D1C, D1C)
|
---|
| 2204 | CHECKFLAGSNEW(GLONASS, S1C, S1C)
|
---|
| 2205 | CHECKFLAGSNEW(GLONASS, P1, C1P)
|
---|
| 2206 | CHECKFLAGSNEW(GLONASS, L1P, L1P)
|
---|
| 2207 | CHECKFLAGSNEW(GLONASS, D1P, D1P)
|
---|
| 2208 | CHECKFLAGSNEW(GLONASS, S1P, S1P)
|
---|
| 2209 | CHECKFLAGSNEW(GLONASS, P2, C2P)
|
---|
| 2210 | CHECKFLAGSNEW(GLONASS, L2P, L2P)
|
---|
| 2211 | CHECKFLAGSNEW(GLONASS, D2P, D2P)
|
---|
| 2212 | CHECKFLAGSNEW(GLONASS, S2P, S2P)
|
---|
| 2213 | CHECKFLAGSNEW(GLONASS, C2, C2C)
|
---|
| 2214 | CHECKFLAGSNEW(GLONASS, L2C, L2C)
|
---|
| 2215 | CHECKFLAGSNEW(GLONASS, D2C, D2C)
|
---|
| 2216 | CHECKFLAGSNEW(GLONASS, S2C, S2C)
|
---|
| 2217 | }
|
---|
| 2218 | else
|
---|
| 2219 | {
|
---|
| 2220 | CHECKFLAGS(C1,C1)
|
---|
| 2221 | CHECKFLAGS(C2,C2)
|
---|
| 2222 | CHECKFLAGS(P1,P1)
|
---|
| 2223 | CHECKFLAGS(P2,P2)
|
---|
| 2224 | CHECKFLAGS(L1C,L1)
|
---|
| 2225 | CHECKFLAGS(L1P,L1)
|
---|
| 2226 | CHECKFLAGS(L2C,L2)
|
---|
| 2227 | CHECKFLAGS(L2P,L2)
|
---|
| 2228 | CHECKFLAGS(D1C,D1)
|
---|
| 2229 | CHECKFLAGS(D1P,D1)
|
---|
| 2230 | CHECKFLAGS(D2C,D2)
|
---|
| 2231 | CHECKFLAGS(D2P,D2)
|
---|
| 2232 | CHECKFLAGS(S1C,S1)
|
---|
| 2233 | CHECKFLAGS(S1P,S1)
|
---|
| 2234 | CHECKFLAGS(S2C,S2)
|
---|
| 2235 | CHECKFLAGS(S2P,S2)
|
---|
| 2236 | CHECKFLAGS(C5,C5)
|
---|
| 2237 | CHECKFLAGS(L5,L5)
|
---|
| 2238 | CHECKFLAGS(D5,D5)
|
---|
| 2239 | CHECKFLAGS(S5,S5)
|
---|
| 2240 | CHECKFLAGS(C5AB,C8)
|
---|
| 2241 | CHECKFLAGS(L5AB,L8)
|
---|
| 2242 | CHECKFLAGS(D5AB,D8)
|
---|
| 2243 | CHECKFLAGS(S5AB,S8)
|
---|
| 2244 | CHECKFLAGS(C5B,C7)
|
---|
| 2245 | CHECKFLAGS(L5B,L7)
|
---|
| 2246 | CHECKFLAGS(D5B,D7)
|
---|
| 2247 | CHECKFLAGS(S5B,S7)
|
---|
| 2248 | CHECKFLAGS(C6,C6)
|
---|
| 2249 | CHECKFLAGS(L6,L6)
|
---|
| 2250 | CHECKFLAGS(D6,D6)
|
---|
| 2251 | CHECKFLAGS(S6,S6)
|
---|
| 2252 | }
|
---|
| 2253 | #else /* NO_RTCM3_MAIN */
|
---|
| 2254 | struct HeaderData hdata;
|
---|
| 2255 | char thebuffer[MAXHEADERBUFFERSIZE];
|
---|
| 2256 | char *buffer = thebuffer;
|
---|
| 2257 | size_t buffersize = sizeof(thebuffer);
|
---|
| 2258 | int i;
|
---|
| 2259 |
|
---|
| 2260 | memset(&hdata, 0, sizeof(hdata));
|
---|
| 2261 |
|
---|
| 2262 | hdata.data.named.version = buffer;
|
---|
| 2263 | i = 1+snprintf(buffer, buffersize,
|
---|
| 2264 | "%9.2f OBSERVATION DATA M (Mixed)"
|
---|
| 2265 | " RINEX VERSION / TYPE", Parser->rinex3 ? 3.0 : 2.11);
|
---|
| 2266 | buffer += i; buffersize -= i;
|
---|
| 2267 |
|
---|
| 2268 | {
|
---|
| 2269 | const char *str;
|
---|
| 2270 | hdata.data.named.pgm = buffer;
|
---|
| 2271 | i = HandleRunBy(buffer, buffersize, &str, Parser->rinex3);
|
---|
[27] | 2272 | buffer += i; buffersize -= i;
|
---|
[5358] | 2273 | hdata.data.named.observer = buffer;
|
---|
| 2274 | i = 1+snprintf(buffer, buffersize,
|
---|
| 2275 | "%-20.20s "
|
---|
| 2276 | "OBSERVER / AGENCY", str);
|
---|
| 2277 | buffer += i; buffersize -= i;
|
---|
[27] | 2278 | }
|
---|
| 2279 |
|
---|
[5358] | 2280 | hdata.data.named.marker =
|
---|
| 2281 | "RTCM3TORINEX "
|
---|
| 2282 | "MARKER NAME";
|
---|
| 2283 |
|
---|
| 2284 | hdata.data.named.markertype = !Parser->rinex3 ? 0 :
|
---|
| 2285 | "GEODETIC "
|
---|
| 2286 | "MARKER TYPE";
|
---|
| 2287 |
|
---|
| 2288 | hdata.data.named.receiver =
|
---|
| 2289 | " "
|
---|
| 2290 | "REC # / TYPE / VERS";
|
---|
| 2291 |
|
---|
| 2292 | hdata.data.named.antenna =
|
---|
| 2293 | " "
|
---|
| 2294 | "ANT # / TYPE";
|
---|
| 2295 |
|
---|
| 2296 | hdata.data.named.position =
|
---|
| 2297 | " .0000 .0000 .0000 "
|
---|
| 2298 | "APPROX POSITION XYZ";
|
---|
| 2299 |
|
---|
| 2300 | hdata.data.named.antennaposition =
|
---|
| 2301 | " .0000 .0000 .0000 "
|
---|
| 2302 | "ANTENNA: DELTA H/E/N";
|
---|
| 2303 |
|
---|
| 2304 | hdata.data.named.wavelength = Parser->rinex3 ? 0 :
|
---|
| 2305 | " 1 1 "
|
---|
| 2306 | "WAVELENGTH FACT L1/2";
|
---|
| 2307 |
|
---|
| 2308 | hdata.numheaders = 18;
|
---|
| 2309 |
|
---|
| 2310 | i = HandleObsHeader(Parser, buffer, buffersize, &hdata);
|
---|
| 2311 | buffer += i; buffersize -= i;
|
---|
| 2312 |
|
---|
[27] | 2313 | {
|
---|
| 2314 | struct converttimeinfo cti;
|
---|
| 2315 | converttime(&cti, Parser->Data.week,
|
---|
[268] | 2316 | (int)floor(Parser->Data.timeofweek/1000.0));
|
---|
[27] | 2317 | hdata.data.named.timeoffirstobs = buffer;
|
---|
[502] | 2318 | i = 1+snprintf(buffer, buffersize,
|
---|
[27] | 2319 | " %4d %2d %2d %2d %2d %10.7f GPS "
|
---|
[378] | 2320 | "TIME OF FIRST OBS", cti.year, cti.month, cti.day, cti.hour,
|
---|
[27] | 2321 | cti.minute, cti.second + fmod(Parser->Data.timeofweek/1000.0,1.0));
|
---|
| 2322 |
|
---|
| 2323 | buffer += i; buffersize -= i;
|
---|
| 2324 | }
|
---|
| 2325 |
|
---|
| 2326 | if(Parser->headerfile)
|
---|
| 2327 | {
|
---|
| 2328 | FILE *fh;
|
---|
| 2329 | if((fh = fopen(Parser->headerfile, "r")))
|
---|
| 2330 | {
|
---|
[318] | 2331 | size_t siz;
|
---|
[27] | 2332 | char *lastblockstart;
|
---|
| 2333 | if((siz = fread(buffer, 1, buffersize-1, fh)) > 0)
|
---|
| 2334 | {
|
---|
| 2335 | buffer[siz] = '\n';
|
---|
| 2336 | if(siz == buffersize)
|
---|
| 2337 | {
|
---|
[318] | 2338 | RTCM3Error("Header file is too large. Only %d bytes read.",
|
---|
[364] | 2339 | (int)siz);
|
---|
[27] | 2340 | }
|
---|
| 2341 | /* scan the file line by line and enter the entries in the list */
|
---|
| 2342 | /* warn for "# / TYPES OF OBSERV" and "TIME OF FIRST OBS" */
|
---|
| 2343 | /* overwrites entries, except for comments */
|
---|
| 2344 | lastblockstart = buffer;
|
---|
[318] | 2345 | for(i = 0; i < (int)siz; ++i)
|
---|
[27] | 2346 | {
|
---|
| 2347 | if(buffer[i] == '\n')
|
---|
| 2348 | { /* we found a line */
|
---|
| 2349 | char *end;
|
---|
| 2350 | while(buffer[i+1] == '\r')
|
---|
| 2351 | ++i; /* skip \r in case there are any */
|
---|
| 2352 | end = buffer+i;
|
---|
| 2353 | while(*end == '\t' || *end == ' ' || *end == '\r' || *end == '\n')
|
---|
| 2354 | *(end--) = 0;
|
---|
| 2355 | if(end-lastblockstart < 60+5) /* short line */
|
---|
[318] | 2356 | RTCM3Error("Short Header line '%s' ignored.\n", lastblockstart);
|
---|
[27] | 2357 | else
|
---|
| 2358 | {
|
---|
| 2359 | int pos;
|
---|
| 2360 | if(!strcmp("COMMENT", lastblockstart+60))
|
---|
| 2361 | pos = hdata.numheaders;
|
---|
| 2362 | else
|
---|
| 2363 | {
|
---|
| 2364 | for(pos = 0; pos < hdata.numheaders; ++pos)
|
---|
| 2365 | {
|
---|
| 2366 | if(!strcmp(hdata.data.unnamed[pos]+60, lastblockstart+60))
|
---|
| 2367 | break;
|
---|
| 2368 | }
|
---|
| 2369 | if(!strcmp("# / TYPES OF OBSERV", lastblockstart+60)
|
---|
| 2370 | || !strcmp("TIME OF FIRST OBS", lastblockstart+60))
|
---|
| 2371 | {
|
---|
[318] | 2372 | RTCM3Error("Overwriting header '%s' is dangerous.\n",
|
---|
[27] | 2373 | lastblockstart+60);
|
---|
| 2374 | }
|
---|
| 2375 | }
|
---|
| 2376 | if(pos >= MAXHEADERLINES)
|
---|
| 2377 | {
|
---|
[318] | 2378 | RTCM3Error("Maximum number of header lines of %d reached.\n",
|
---|
[27] | 2379 | MAXHEADERLINES);
|
---|
| 2380 | }
|
---|
| 2381 | else if(!strcmp("END OF HEADER", lastblockstart+60))
|
---|
| 2382 | {
|
---|
[318] | 2383 | RTCM3Error("End of header ignored.\n");
|
---|
[27] | 2384 | }
|
---|
| 2385 | else
|
---|
| 2386 | {
|
---|
| 2387 | hdata.data.unnamed[pos] = lastblockstart;
|
---|
| 2388 | if(pos == hdata.numheaders)
|
---|
| 2389 | ++hdata.numheaders;
|
---|
| 2390 | }
|
---|
| 2391 | }
|
---|
| 2392 | lastblockstart = buffer+i+1;
|
---|
| 2393 | }
|
---|
| 2394 | }
|
---|
| 2395 | }
|
---|
| 2396 | else
|
---|
| 2397 | {
|
---|
[318] | 2398 | RTCM3Error("Could not read data from headerfile '%s'.\n",
|
---|
[27] | 2399 | Parser->headerfile);
|
---|
| 2400 | }
|
---|
| 2401 | fclose(fh);
|
---|
| 2402 | }
|
---|
| 2403 | else
|
---|
| 2404 | {
|
---|
[318] | 2405 | RTCM3Error("Could not open header datafile '%s'.\n",
|
---|
[27] | 2406 | Parser->headerfile);
|
---|
| 2407 | }
|
---|
| 2408 | }
|
---|
| 2409 |
|
---|
| 2410 | for(i = 0; i < hdata.numheaders; ++i)
|
---|
[502] | 2411 | {
|
---|
| 2412 | if(hdata.data.unnamed[i] && hdata.data.unnamed[i][0])
|
---|
| 2413 | RTCM3Text("%s\n", hdata.data.unnamed[i]);
|
---|
| 2414 | }
|
---|
[318] | 2415 | RTCM3Text(" "
|
---|
[27] | 2416 | "END OF HEADER\n");
|
---|
[287] | 2417 | #endif
|
---|
[27] | 2418 | }
|
---|
| 2419 |
|
---|
[502] | 2420 | static void ConvLine(FILE *file, const char *fmt, ...)
|
---|
| 2421 | {
|
---|
| 2422 | char buffer[100], *b;
|
---|
| 2423 | va_list v;
|
---|
| 2424 | va_start(v, fmt);
|
---|
| 2425 | vsnprintf(buffer, sizeof(buffer), fmt, v);
|
---|
| 2426 | for(b = buffer; *b; ++b)
|
---|
| 2427 | {
|
---|
| 2428 | if(*b == 'e') *b = 'D';
|
---|
| 2429 | }
|
---|
| 2430 | fprintf(file, "%s", buffer);
|
---|
| 2431 | va_end(v);
|
---|
| 2432 | }
|
---|
| 2433 |
|
---|
[268] | 2434 | void HandleByte(struct RTCM3ParserData *Parser, unsigned int byte)
|
---|
[27] | 2435 | {
|
---|
| 2436 | Parser->Message[Parser->MessageSize++] = byte;
|
---|
| 2437 | if(Parser->MessageSize >= Parser->NeedBytes)
|
---|
| 2438 | {
|
---|
| 2439 | int r;
|
---|
| 2440 | while((r = RTCM3Parser(Parser)))
|
---|
| 2441 | {
|
---|
[502] | 2442 | if(r == 1020 || r == 1019)
|
---|
[27] | 2443 | {
|
---|
[502] | 2444 | FILE *file = 0;
|
---|
[318] | 2445 |
|
---|
[502] | 2446 | if(Parser->rinex3 && !(file = Parser->gpsfile))
|
---|
| 2447 | {
|
---|
| 2448 | const char *n = Parser->gpsephemeris ? Parser->gpsephemeris : Parser->glonassephemeris;
|
---|
| 2449 | if(n)
|
---|
| 2450 | {
|
---|
| 2451 | if(!(Parser->gpsfile = fopen(n, "w")))
|
---|
| 2452 | {
|
---|
| 2453 | RTCM3Error("Could not open ephemeris output file.\n");
|
---|
| 2454 | }
|
---|
| 2455 | else
|
---|
| 2456 | {
|
---|
| 2457 | char buffer[100];
|
---|
| 2458 | fprintf(Parser->gpsfile,
|
---|
| 2459 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n", 3.0, "", "");
|
---|
[503] | 2460 | HandleRunBy(buffer, sizeof(buffer), 0, Parser->rinex3);
|
---|
[502] | 2461 | fprintf(Parser->gpsfile, "%s\n%60sEND OF HEADER\n", buffer, "");
|
---|
| 2462 | }
|
---|
| 2463 | Parser->gpsephemeris = 0;
|
---|
| 2464 | Parser->glonassephemeris = 0;
|
---|
| 2465 | file = Parser->gpsfile;
|
---|
| 2466 | }
|
---|
| 2467 | }
|
---|
[318] | 2468 | else
|
---|
| 2469 | {
|
---|
[502] | 2470 | if(r == 1020)
|
---|
| 2471 | {
|
---|
| 2472 | if(Parser->glonassephemeris)
|
---|
| 2473 | {
|
---|
| 2474 | if(!(Parser->glonassfile = fopen(Parser->glonassephemeris, "w")))
|
---|
| 2475 | {
|
---|
| 2476 | RTCM3Error("Could not open GLONASS ephemeris output file.\n");
|
---|
| 2477 | }
|
---|
| 2478 | else
|
---|
| 2479 | {
|
---|
| 2480 | char buffer[100];
|
---|
| 2481 | fprintf(Parser->glonassfile,
|
---|
| 2482 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n", 2.1, "", "");
|
---|
[503] | 2483 | HandleRunBy(buffer, sizeof(buffer), 0, Parser->rinex3);
|
---|
[502] | 2484 | fprintf(Parser->glonassfile, "%s\n%60sEND OF HEADER\n", buffer, "");
|
---|
| 2485 | }
|
---|
| 2486 | Parser->glonassephemeris = 0;
|
---|
| 2487 | }
|
---|
| 2488 | file = Parser->glonassfile;
|
---|
| 2489 | }
|
---|
| 2490 | else if(r == 1019)
|
---|
| 2491 | {
|
---|
| 2492 | if(Parser->gpsephemeris)
|
---|
| 2493 | {
|
---|
| 2494 | if(!(Parser->gpsfile = fopen(Parser->gpsephemeris, "w")))
|
---|
| 2495 | {
|
---|
| 2496 | RTCM3Error("Could not open GPS ephemeris output file.\n");
|
---|
| 2497 | }
|
---|
| 2498 | else
|
---|
| 2499 | {
|
---|
| 2500 | char buffer[100];
|
---|
| 2501 | fprintf(Parser->gpsfile,
|
---|
| 2502 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.1, "", "");
|
---|
[503] | 2503 | HandleRunBy(buffer, sizeof(buffer), 0, Parser->rinex3);
|
---|
[502] | 2504 | fprintf(Parser->gpsfile, "%s\n%60sEND OF HEADER\n", buffer, "");
|
---|
| 2505 | }
|
---|
| 2506 | Parser->gpsephemeris = 0;
|
---|
| 2507 | }
|
---|
| 2508 | file = Parser->gpsfile;
|
---|
| 2509 | }
|
---|
[318] | 2510 | }
|
---|
[502] | 2511 | if(file)
|
---|
| 2512 | {
|
---|
| 2513 | if(r == 1020)
|
---|
| 2514 | {
|
---|
| 2515 | struct glonassephemeris *e = &Parser->ephemerisGLONASS;
|
---|
| 2516 | int w = e->GPSWeek, tow = e->GPSTOW, i;
|
---|
| 2517 | struct converttimeinfo cti;
|
---|
| 2518 |
|
---|
[2346] | 2519 | updatetime(&w, &tow, e->tb*1000, 1); /* Moscow - > UTC */
|
---|
[502] | 2520 | converttime(&cti, w, tow);
|
---|
| 2521 |
|
---|
| 2522 | i = e->tk-3*60*60; if(i < 0) i += 86400;
|
---|
| 2523 |
|
---|
| 2524 | if(Parser->rinex3)
|
---|
| 2525 | ConvLine(file, "R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e\n",
|
---|
| 2526 | e->almanac_number, cti.year, cti.month, cti.day, cti.hour, cti.minute,
|
---|
| 2527 | cti.second, -e->tau, e->gamma, (double) i);
|
---|
| 2528 | else
|
---|
| 2529 | ConvLine(file, "%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e\n",
|
---|
| 2530 | e->almanac_number, cti.year%100, cti.month, cti.day, cti.hour, cti.minute,
|
---|
| 2531 | (double) cti.second, -e->tau, e->gamma, (double) i);
|
---|
| 2532 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", e->x_pos,
|
---|
| 2533 | e->x_velocity, e->x_acceleration, (e->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
|
---|
| 2534 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", e->y_pos,
|
---|
| 2535 | e->y_velocity, e->y_acceleration, (double) e->frequency_number);
|
---|
| 2536 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", e->z_pos,
|
---|
| 2537 | e->z_velocity, e->z_acceleration, (double) e->E);
|
---|
| 2538 | }
|
---|
| 2539 | else /* if(r == 1019) */
|
---|
| 2540 | {
|
---|
| 2541 | struct gpsephemeris *e = &Parser->ephemerisGPS;
|
---|
| 2542 | double d; /* temporary variable */
|
---|
| 2543 | unsigned long int i; /* temporary variable */
|
---|
| 2544 | struct converttimeinfo cti;
|
---|
| 2545 | converttime(&cti, e->GPSweek, e->TOC);
|
---|
| 2546 |
|
---|
| 2547 | if(Parser->rinex3)
|
---|
| 2548 | ConvLine(file, "G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e\n",
|
---|
| 2549 | e->satellite, cti.year, cti.month, cti.day, cti.hour,
|
---|
| 2550 | cti.minute, cti.second, e->clock_bias, e->clock_drift,
|
---|
| 2551 | e->clock_driftrate);
|
---|
| 2552 | else
|
---|
| 2553 | ConvLine(file, "%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e\n",
|
---|
| 2554 | e->satellite, cti.year%100, cti.month, cti.day, cti.hour,
|
---|
| 2555 | cti.minute, (double) cti.second, e->clock_bias, e->clock_drift,
|
---|
| 2556 | e->clock_driftrate);
|
---|
| 2557 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", (double)e->IODE,
|
---|
| 2558 | e->Crs, e->Delta_n, e->M0);
|
---|
| 2559 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", e->Cuc,
|
---|
| 2560 | e->e, e->Cus, e->sqrt_A);
|
---|
| 2561 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n",
|
---|
| 2562 | (double) e->TOE, e->Cic, e->OMEGA0, e->Cis);
|
---|
| 2563 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", e->i0,
|
---|
| 2564 | e->Crc, e->omega, e->OMEGADOT);
|
---|
| 2565 | d = 0;
|
---|
| 2566 | i = e->flags;
|
---|
| 2567 | if(i & GPSEPHF_L2CACODE)
|
---|
| 2568 | d += 2.0;
|
---|
| 2569 | if(i & GPSEPHF_L2PCODE)
|
---|
| 2570 | d += 1.0;
|
---|
| 2571 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", e->IDOT, d,
|
---|
| 2572 | (double) e->GPSweek, i & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
|
---|
| 2573 | if(e->URAindex <= 6) /* URA index */
|
---|
| 2574 | d = ceil(10.0*pow(2.0, 1.0+((double)e->URAindex)/2.0))/10.0;
|
---|
| 2575 | else
|
---|
| 2576 | d = ceil(10.0*pow(2.0, ((double)e->URAindex)/2.0))/10.0;
|
---|
| 2577 | /* 15 indicates not to use satellite. We can't handle this special
|
---|
| 2578 | case, so we create a high "non"-accuracy value. */
|
---|
| 2579 | ConvLine(file, " %19.12e%19.12e%19.12e%19.12e\n", d,
|
---|
| 2580 | ((double) e->SVhealth), e->TGD, ((double) e->IODC));
|
---|
| 2581 |
|
---|
[5332] | 2582 | ConvLine(file, " %19.12e%19.12e\n", ((double)e->TOW),
|
---|
[5333] | 2583 | i & GPSEPHF_6HOURSFIT ? 6.0 : 4.0);
|
---|
[502] | 2584 | /* TOW */
|
---|
| 2585 | }
|
---|
| 2586 | }
|
---|
[27] | 2587 | }
|
---|
[2507] | 2588 | else if (r == 1 || r == 2)
|
---|
[27] | 2589 | {
|
---|
[5553] | 2590 | int i, j, o, nh=0, hl=2;
|
---|
[5358] | 2591 | char newheader[512];
|
---|
[502] | 2592 | struct converttimeinfo cti;
|
---|
[27] | 2593 |
|
---|
[5358] | 2594 | /* skip first epochs to detect correct data types */
|
---|
| 2595 | if(Parser->init < (Parser->changeobs ? 1 : NUMSTARTSKIP))
|
---|
[27] | 2596 | {
|
---|
[502] | 2597 | ++Parser->init;
|
---|
| 2598 |
|
---|
[5358] | 2599 | if(Parser->init == (Parser->changeobs ? 1 : NUMSTARTSKIP))
|
---|
[502] | 2600 | HandleHeader(Parser);
|
---|
[27] | 2601 | else
|
---|
[502] | 2602 | {
|
---|
| 2603 | for(i = 0; i < Parser->Data.numsats; ++i)
|
---|
| 2604 | Parser->startflags |= Parser->Data.dataflags[i];
|
---|
| 2605 | continue;
|
---|
| 2606 | }
|
---|
[27] | 2607 | }
|
---|
[502] | 2608 | if(r == 2 && !Parser->validwarning)
|
---|
[27] | 2609 | {
|
---|
[502] | 2610 | RTCM3Text("No valid RINEX! All values are modulo 299792.458!"
|
---|
| 2611 | " COMMENT\n");
|
---|
| 2612 | Parser->validwarning = 1;
|
---|
| 2613 | }
|
---|
| 2614 |
|
---|
| 2615 | converttime(&cti, Parser->Data.week,
|
---|
| 2616 | (int)floor(Parser->Data.timeofweek/1000.0));
|
---|
[5358] | 2617 | newheader[0] = 0;
|
---|
| 2618 | if(Parser->changeobs)
|
---|
| 2619 | {
|
---|
| 2620 | nh = HandleObsHeader(Parser, newheader, sizeof(newheader), 0);
|
---|
[5553] | 2621 | for(i = 0; i < nh; ++i)
|
---|
| 2622 | {
|
---|
| 2623 | if(newheader[i] == '\n')
|
---|
| 2624 | ++hl;
|
---|
| 2625 | }
|
---|
[5358] | 2626 | }
|
---|
[502] | 2627 | if(Parser->rinex3)
|
---|
| 2628 | {
|
---|
[5358] | 2629 | if(nh)
|
---|
| 2630 | {
|
---|
[5553] | 2631 | RTCM3Text("> %04d %02d %02d %02d %02d%11.7f 4%3d\n",
|
---|
| 2632 | cti.year, cti.month, cti.day, cti.hour, cti.minute, cti.second
|
---|
| 2633 | + fmod(Parser->Data.timeofweek/1000.0,1.0), hl);
|
---|
[5358] | 2634 | RTCM3Text("%s\n "
|
---|
| 2635 | " END OF HEADER\n", newheader);
|
---|
| 2636 | }
|
---|
[5553] | 2637 | RTCM3Text("> %04d %02d %02d %02d %02d%11.7f %d%3d\n",
|
---|
| 2638 | cti.year, cti.month, cti.day, cti.hour, cti.minute, cti.second
|
---|
| 2639 | + fmod(Parser->Data.timeofweek/1000.0,1.0), 0,
|
---|
| 2640 | Parser->Data.numsats);
|
---|
[502] | 2641 | for(i = 0; i < Parser->Data.numsats; ++i)
|
---|
[363] | 2642 | {
|
---|
[4371] | 2643 | int sys[RTCM3_MSM_NUMSYS] = {0,0,0,0,0,0};
|
---|
[502] | 2644 | if(Parser->Data.satellites[i] <= PRN_GPS_END)
|
---|
[4371] | 2645 | {
|
---|
[502] | 2646 | RTCM3Text("G%02d", Parser->Data.satellites[i]);
|
---|
[4371] | 2647 | sys[RTCM3_MSM_GPS] = 1;
|
---|
| 2648 | }
|
---|
[502] | 2649 | else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
|
---|
| 2650 | && Parser->Data.satellites[i] <= PRN_GLONASS_END)
|
---|
| 2651 | {
|
---|
| 2652 | RTCM3Text("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
|
---|
[4371] | 2653 | sys[RTCM3_MSM_GLONASS] = 1;
|
---|
[502] | 2654 | }
|
---|
[2699] | 2655 | else if(Parser->Data.satellites[i] >= PRN_GALILEO_START
|
---|
| 2656 | && Parser->Data.satellites[i] <= PRN_GALILEO_END)
|
---|
| 2657 | {
|
---|
| 2658 | RTCM3Text("E%02d", Parser->Data.satellites[i] - (PRN_GALILEO_START-1));
|
---|
[4371] | 2659 | sys[RTCM3_MSM_GALILEO] = 1;
|
---|
[2699] | 2660 | }
|
---|
| 2661 | else if(Parser->Data.satellites[i] >= PRN_GIOVE_START
|
---|
| 2662 | && Parser->Data.satellites[i] <= PRN_GIOVE_END)
|
---|
| 2663 | {
|
---|
| 2664 | RTCM3Text("E%02d", Parser->Data.satellites[i] - (PRN_GIOVE_START-PRN_GIOVE_OFFSET));
|
---|
[4371] | 2665 | sys[RTCM3_MSM_GALILEO] = 1;
|
---|
[2699] | 2666 | }
|
---|
[4367] | 2667 | else if(Parser->Data.satellites[i] >= PRN_QZSS_START
|
---|
| 2668 | && Parser->Data.satellites[i] <= PRN_QZSS_END)
|
---|
| 2669 | {
|
---|
| 2670 | RTCM3Text("J%02d", Parser->Data.satellites[i] - (PRN_QZSS_START-1));
|
---|
[4371] | 2671 | sys[RTCM3_MSM_QZSS] = 1;
|
---|
[4367] | 2672 | }
|
---|
| 2673 | else if(Parser->Data.satellites[i] >= PRN_COMPASS_START
|
---|
| 2674 | && Parser->Data.satellites[i] <= PRN_COMPASS_END)
|
---|
| 2675 | {
|
---|
| 2676 | RTCM3Text("C%02d", Parser->Data.satellites[i] - (PRN_COMPASS_START-1));
|
---|
[4371] | 2677 | sys[RTCM3_MSM_COMPASS] = 1;
|
---|
[4367] | 2678 | }
|
---|
| 2679 | else if(Parser->Data.satellites[i] >= PRN_SBAS_START
|
---|
| 2680 | && Parser->Data.satellites[i] <= PRN_SBAS_END)
|
---|
[4371] | 2681 | {
|
---|
[4367] | 2682 | RTCM3Text("S%02d", Parser->Data.satellites[i] - PRN_SBAS_START+20);
|
---|
[4371] | 2683 | sys[RTCM3_MSM_SBAS] = 1;
|
---|
| 2684 | }
|
---|
[502] | 2685 | else
|
---|
[4371] | 2686 | {
|
---|
[502] | 2687 | RTCM3Text("%3d", Parser->Data.satellites[i]);
|
---|
[4371] | 2688 | }
|
---|
[363] | 2689 |
|
---|
[4371] | 2690 | if(sys[RTCM3_MSM_GLONASS])
|
---|
[363] | 2691 | {
|
---|
[4371] | 2692 | for(j = 0; j < Parser->info[RTCM3_MSM_GLONASS].numtypes; ++j)
|
---|
[502] | 2693 | {
|
---|
[4383] | 2694 | long long df = Parser->info[RTCM3_MSM_GLONASS].flags[j];
|
---|
[4371] | 2695 | int pos = Parser->info[RTCM3_MSM_GLONASS].pos[j];
|
---|
[502] | 2696 | if((Parser->Data.dataflags[i] & df)
|
---|
| 2697 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
[4374] | 2698 | && !isinf(Parser->Data.measdata[i][pos])
|
---|
| 2699 | && (Parser->Data.codetype[i][pos]
|
---|
| 2700 | && Parser->info[RTCM3_MSM_GLONASS].type[pos]
|
---|
| 2701 | && Parser->info[RTCM3_MSM_GLONASS].type[pos]
|
---|
| 2702 | == Parser->Data.codetype[i][pos][1]))
|
---|
[502] | 2703 | {
|
---|
| 2704 | char lli = ' ';
|
---|
| 2705 | char snr = ' ';
|
---|
| 2706 | if(df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA))
|
---|
| 2707 | {
|
---|
[2659] | 2708 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL1)
|
---|
[502] | 2709 | lli = '1';
|
---|
| 2710 | snr = '0'+Parser->Data.snrL1[i];
|
---|
| 2711 | }
|
---|
| 2712 | if(df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA))
|
---|
| 2713 | {
|
---|
[2659] | 2714 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL2)
|
---|
[502] | 2715 | lli = '1';
|
---|
| 2716 | snr = '0'+Parser->Data.snrL2[i];
|
---|
| 2717 | }
|
---|
| 2718 | RTCM3Text("%14.3f%c%c",
|
---|
| 2719 | Parser->Data.measdata[i][pos],lli,snr);
|
---|
| 2720 | }
|
---|
| 2721 | else
|
---|
| 2722 | { /* no or illegal data */
|
---|
| 2723 | RTCM3Text(" ");
|
---|
| 2724 | }
|
---|
| 2725 | }
|
---|
[363] | 2726 | }
|
---|
[4371] | 2727 | else if(sys[RTCM3_MSM_GALILEO])
|
---|
[2699] | 2728 | {
|
---|
[4371] | 2729 | for(j = 0; j < Parser->info[RTCM3_MSM_GALILEO].numtypes; ++j)
|
---|
[2699] | 2730 | {
|
---|
[4383] | 2731 | long long df = Parser->info[RTCM3_MSM_GALILEO].flags[j];
|
---|
[4371] | 2732 | int pos = Parser->info[RTCM3_MSM_GALILEO].pos[j];
|
---|
[2699] | 2733 | if((Parser->Data.dataflags[i] & df)
|
---|
| 2734 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
[4374] | 2735 | && !isinf(Parser->Data.measdata[i][pos])
|
---|
| 2736 | && (Parser->Data.codetype[i][pos]
|
---|
| 2737 | && Parser->info[RTCM3_MSM_GALILEO].type[pos]
|
---|
| 2738 | && Parser->info[RTCM3_MSM_GALILEO].type[pos]
|
---|
| 2739 | == Parser->Data.codetype[i][pos][1]))
|
---|
[2699] | 2740 | {
|
---|
| 2741 | char lli = ' ';
|
---|
| 2742 | char snr = ' ';
|
---|
| 2743 | if(df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA))
|
---|
| 2744 | {
|
---|
| 2745 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL1)
|
---|
| 2746 | lli = '1';
|
---|
| 2747 | snr = '0'+Parser->Data.snrL1[i];
|
---|
| 2748 | }
|
---|
| 2749 | if(df & GNSSDF_L6DATA)
|
---|
| 2750 | {
|
---|
| 2751 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSE6)
|
---|
| 2752 | lli = '1';
|
---|
| 2753 | snr = ' ';
|
---|
| 2754 | }
|
---|
| 2755 | if(df & GNSSDF_L5DATA)
|
---|
| 2756 | {
|
---|
| 2757 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL5)
|
---|
| 2758 | lli = '1';
|
---|
| 2759 | snr = ' ';
|
---|
| 2760 | }
|
---|
| 2761 | if(df & GNSSDF_L5BDATA)
|
---|
| 2762 | {
|
---|
| 2763 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSE5B)
|
---|
| 2764 | lli = '1';
|
---|
| 2765 | snr = ' ';
|
---|
| 2766 | }
|
---|
| 2767 | if(df & GNSSDF_L5ABDATA)
|
---|
| 2768 | {
|
---|
| 2769 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSE5AB)
|
---|
| 2770 | lli = '1';
|
---|
| 2771 | snr = ' ';
|
---|
| 2772 | }
|
---|
| 2773 | RTCM3Text("%14.3f%c%c",
|
---|
| 2774 | Parser->Data.measdata[i][pos],lli,snr);
|
---|
| 2775 | }
|
---|
| 2776 | else
|
---|
| 2777 | { /* no or illegal data */
|
---|
| 2778 | RTCM3Text(" ");
|
---|
| 2779 | }
|
---|
| 2780 | }
|
---|
| 2781 | }
|
---|
[4371] | 2782 | else if(sys[RTCM3_MSM_COMPASS])
|
---|
[4367] | 2783 | {
|
---|
[4371] | 2784 | for(j = 0; j < Parser->info[RTCM3_MSM_COMPASS].numtypes; ++j)
|
---|
[4367] | 2785 | {
|
---|
[4383] | 2786 | long long df = Parser->info[RTCM3_MSM_COMPASS].flags[j];
|
---|
[4371] | 2787 | int pos = Parser->info[RTCM3_MSM_COMPASS].pos[j];
|
---|
[4367] | 2788 | if((Parser->Data.dataflags[i] & df)
|
---|
| 2789 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
[4374] | 2790 | && !isinf(Parser->Data.measdata[i][pos])
|
---|
| 2791 | && (Parser->Data.codetype[i][pos]
|
---|
| 2792 | && Parser->info[RTCM3_MSM_COMPASS].type[pos]
|
---|
| 2793 | && Parser->info[RTCM3_MSM_COMPASS].type[pos]
|
---|
| 2794 | == Parser->Data.codetype[i][pos][1]))
|
---|
[4367] | 2795 | {
|
---|
| 2796 | char lli = ' ';
|
---|
| 2797 | char snr = ' ';
|
---|
| 2798 | if(df & GNSSDF_LB1DATA)
|
---|
| 2799 | {
|
---|
| 2800 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSB1)
|
---|
| 2801 | lli = '1';
|
---|
| 2802 | }
|
---|
| 2803 | if(df & GNSSDF_LB2DATA)
|
---|
| 2804 | {
|
---|
| 2805 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSB2)
|
---|
| 2806 | lli = '1';
|
---|
| 2807 | }
|
---|
| 2808 | if(df & GNSSDF_LB3DATA)
|
---|
| 2809 | {
|
---|
| 2810 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSB3)
|
---|
| 2811 | lli = '1';
|
---|
| 2812 | }
|
---|
| 2813 | RTCM3Text("%14.3f%c%c",
|
---|
| 2814 | Parser->Data.measdata[i][pos],lli,snr);
|
---|
| 2815 | }
|
---|
| 2816 | else
|
---|
| 2817 | { /* no or illegal data */
|
---|
| 2818 | RTCM3Text(" ");
|
---|
| 2819 | }
|
---|
| 2820 | }
|
---|
| 2821 | }
|
---|
[4371] | 2822 | else if(sys[RTCM3_MSM_QZSS])
|
---|
[4367] | 2823 | {
|
---|
[4371] | 2824 | for(j = 0; j < Parser->info[RTCM3_MSM_QZSS].numtypes; ++j)
|
---|
[4367] | 2825 | {
|
---|
[4383] | 2826 | long long df = Parser->info[RTCM3_MSM_QZSS].flags[j];
|
---|
[4371] | 2827 | int pos = Parser->info[RTCM3_MSM_QZSS].pos[j];
|
---|
[4367] | 2828 | if((Parser->Data.dataflags[i] & df)
|
---|
| 2829 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
[4371] | 2830 | && !isinf(Parser->Data.measdata[i][pos])
|
---|
[4374] | 2831 | && (Parser->Data.codetype[i][pos]
|
---|
[4371] | 2832 | && Parser->info[RTCM3_MSM_QZSS].type[pos]
|
---|
| 2833 | && Parser->info[RTCM3_MSM_QZSS].type[pos]
|
---|
[4374] | 2834 | == Parser->Data.codetype[i][pos][1]))
|
---|
[4367] | 2835 | {
|
---|
| 2836 | char lli = ' ';
|
---|
| 2837 | char snr = ' ';
|
---|
| 2838 | if(df & GNSSDF_L1CDATA)
|
---|
| 2839 | {
|
---|
| 2840 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL1)
|
---|
| 2841 | lli = '1';
|
---|
| 2842 | snr = '0'+Parser->Data.snrL1[i];
|
---|
| 2843 | }
|
---|
| 2844 | if(df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA))
|
---|
| 2845 | {
|
---|
| 2846 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL2)
|
---|
| 2847 | lli = '1';
|
---|
| 2848 | snr = '0'+Parser->Data.snrL2[i];
|
---|
| 2849 | }
|
---|
| 2850 | if(df & GNSSDF_L5DATA)
|
---|
| 2851 | {
|
---|
| 2852 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL5)
|
---|
| 2853 | lli = '1';
|
---|
| 2854 | snr = ' ';
|
---|
| 2855 | }
|
---|
| 2856 | RTCM3Text("%14.3f%c%c",
|
---|
| 2857 | Parser->Data.measdata[i][pos],lli,snr);
|
---|
| 2858 | }
|
---|
| 2859 | else
|
---|
| 2860 | { /* no or illegal data */
|
---|
| 2861 | RTCM3Text(" ");
|
---|
| 2862 | }
|
---|
| 2863 | }
|
---|
| 2864 | }
|
---|
[4371] | 2865 | else if(sys[RTCM3_MSM_SBAS])
|
---|
| 2866 | {
|
---|
| 2867 | for(j = 0; j < Parser->info[RTCM3_MSM_SBAS].numtypes; ++j)
|
---|
| 2868 | {
|
---|
[4383] | 2869 | long long df = Parser->info[RTCM3_MSM_SBAS].flags[j];
|
---|
[4371] | 2870 | int pos = Parser->info[RTCM3_MSM_SBAS].pos[j];
|
---|
| 2871 | if((Parser->Data.dataflags[i] & df)
|
---|
| 2872 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
[4374] | 2873 | && !isinf(Parser->Data.measdata[i][pos])
|
---|
| 2874 | && (Parser->Data.codetype[i][pos]
|
---|
| 2875 | && Parser->info[RTCM3_MSM_SBAS].type[pos]
|
---|
| 2876 | && Parser->info[RTCM3_MSM_SBAS].type[pos]
|
---|
| 2877 | == Parser->Data.codetype[i][pos][1]))
|
---|
[4371] | 2878 | {
|
---|
| 2879 | char lli = ' ';
|
---|
| 2880 | char snr = ' ';
|
---|
| 2881 | if(df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA))
|
---|
| 2882 | {
|
---|
| 2883 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL1)
|
---|
| 2884 | lli = '1';
|
---|
| 2885 | snr = '0'+Parser->Data.snrL1[i];
|
---|
| 2886 | }
|
---|
| 2887 | if(df & GNSSDF_L5DATA)
|
---|
| 2888 | {
|
---|
| 2889 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL5)
|
---|
| 2890 | lli = '1';
|
---|
| 2891 | snr = ' ';
|
---|
| 2892 | }
|
---|
| 2893 | RTCM3Text("%14.3f%c%c",
|
---|
| 2894 | Parser->Data.measdata[i][pos],lli,snr);
|
---|
| 2895 | }
|
---|
| 2896 | else
|
---|
| 2897 | { /* no or illegal data */
|
---|
| 2898 | RTCM3Text(" ");
|
---|
| 2899 | }
|
---|
| 2900 | }
|
---|
| 2901 | }
|
---|
[502] | 2902 | else
|
---|
| 2903 | {
|
---|
[4371] | 2904 | for(j = 0; j < Parser->info[RTCM3_MSM_GPS].numtypes; ++j)
|
---|
[502] | 2905 | {
|
---|
[4383] | 2906 | long long df = Parser->info[RTCM3_MSM_GPS].flags[j];
|
---|
[4371] | 2907 | int pos = Parser->info[RTCM3_MSM_GPS].pos[j];
|
---|
[4383] | 2908 | if((Parser->Data.dataflags[i] & df)
|
---|
[502] | 2909 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
[4374] | 2910 | && !isinf(Parser->Data.measdata[i][pos])
|
---|
| 2911 | && (Parser->Data.codetype[i][pos]
|
---|
| 2912 | && Parser->info[RTCM3_MSM_GPS].type[pos]
|
---|
| 2913 | && Parser->info[RTCM3_MSM_GPS].type[pos]
|
---|
| 2914 | == Parser->Data.codetype[i][pos][1]))
|
---|
[502] | 2915 | {
|
---|
| 2916 | char lli = ' ';
|
---|
| 2917 | char snr = ' ';
|
---|
| 2918 | if(df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA))
|
---|
| 2919 | {
|
---|
[2659] | 2920 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL1)
|
---|
[502] | 2921 | lli = '1';
|
---|
| 2922 | snr = '0'+Parser->Data.snrL1[i];
|
---|
| 2923 | }
|
---|
| 2924 | if(df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA))
|
---|
| 2925 | {
|
---|
[2659] | 2926 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL2)
|
---|
[502] | 2927 | lli = '1';
|
---|
| 2928 | snr = '0'+Parser->Data.snrL2[i];
|
---|
| 2929 | }
|
---|
[2699] | 2930 | if(df & GNSSDF_L5DATA)
|
---|
| 2931 | {
|
---|
| 2932 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL5)
|
---|
| 2933 | lli = '1';
|
---|
| 2934 | snr = ' ';
|
---|
| 2935 | }
|
---|
[502] | 2936 | RTCM3Text("%14.3f%c%c",
|
---|
| 2937 | Parser->Data.measdata[i][pos],lli,snr);
|
---|
| 2938 | }
|
---|
| 2939 | else
|
---|
| 2940 | { /* no or illegal data */
|
---|
| 2941 | RTCM3Text(" ");
|
---|
| 2942 | }
|
---|
| 2943 | }
|
---|
| 2944 | }
|
---|
| 2945 | RTCM3Text("\n");
|
---|
[363] | 2946 | }
|
---|
[502] | 2947 | }
|
---|
| 2948 | else
|
---|
| 2949 | {
|
---|
[5358] | 2950 | RTCM3Text(" %02d %2d %2d %2d %2d %10.7f %d%3d",
|
---|
[502] | 2951 | cti.year%100, cti.month, cti.day, cti.hour, cti.minute, cti.second
|
---|
[5358] | 2952 | + fmod(Parser->Data.timeofweek/1000.0,1.0), nh ? 4 : 0,
|
---|
| 2953 | Parser->Data.numsats);
|
---|
[502] | 2954 | for(i = 0; i < 12 && i < Parser->Data.numsats; ++i)
|
---|
| 2955 | {
|
---|
| 2956 | if(Parser->Data.satellites[i] <= PRN_GPS_END)
|
---|
| 2957 | RTCM3Text("G%02d", Parser->Data.satellites[i]);
|
---|
| 2958 | else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
|
---|
| 2959 | && Parser->Data.satellites[i] <= PRN_GLONASS_END)
|
---|
[2659] | 2960 | RTCM3Text("R%02d", Parser->Data.satellites[i]
|
---|
| 2961 | - (PRN_GLONASS_START-1));
|
---|
[4367] | 2962 | else if(Parser->Data.satellites[i] >= PRN_SBAS_START
|
---|
| 2963 | && Parser->Data.satellites[i] <= PRN_SBAS_END)
|
---|
[2659] | 2964 | RTCM3Text("S%02d", Parser->Data.satellites[i]
|
---|
[4367] | 2965 | - PRN_SBAS_START+20);
|
---|
[2659] | 2966 | else if(Parser->Data.satellites[i] >= PRN_GALILEO_START
|
---|
| 2967 | && Parser->Data.satellites[i] <= PRN_GALILEO_END)
|
---|
| 2968 | RTCM3Text("E%02d", Parser->Data.satellites[i]
|
---|
| 2969 | - (PRN_GALILEO_START-1));
|
---|
| 2970 | else if(Parser->Data.satellites[i] >= PRN_GIOVE_START
|
---|
| 2971 | && Parser->Data.satellites[i] <= PRN_GIOVE_END)
|
---|
| 2972 | RTCM3Text("E%02d", Parser->Data.satellites[i]
|
---|
| 2973 | - (PRN_GIOVE_START-PRN_GIOVE_OFFSET));
|
---|
[4367] | 2974 | else if(Parser->Data.satellites[i] >= PRN_QZSS_START
|
---|
| 2975 | && Parser->Data.satellites[i] <= PRN_QZSS_END)
|
---|
| 2976 | RTCM3Text("J%02d", Parser->Data.satellites[i]
|
---|
| 2977 | - (PRN_QZSS_START-1));
|
---|
| 2978 | else if(Parser->Data.satellites[i] >= PRN_COMPASS_START
|
---|
| 2979 | && Parser->Data.satellites[i] <= PRN_COMPASS_END)
|
---|
| 2980 | RTCM3Text("C%02d", Parser->Data.satellites[i]
|
---|
| 2981 | - (PRN_COMPASS_START-1));
|
---|
[502] | 2982 | else
|
---|
| 2983 | RTCM3Text("%3d", Parser->Data.satellites[i]);
|
---|
[27] | 2984 | }
|
---|
[502] | 2985 | RTCM3Text("\n");
|
---|
| 2986 | o = 12;
|
---|
| 2987 | j = Parser->Data.numsats - 12;
|
---|
| 2988 | while(j > 0)
|
---|
[27] | 2989 | {
|
---|
[502] | 2990 | RTCM3Text(" ");
|
---|
| 2991 | for(i = o; i < o+12 && i < Parser->Data.numsats; ++i)
|
---|
[27] | 2992 | {
|
---|
[502] | 2993 | if(Parser->Data.satellites[i] <= PRN_GPS_END)
|
---|
| 2994 | RTCM3Text("G%02d", Parser->Data.satellites[i]);
|
---|
| 2995 | else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
|
---|
| 2996 | && Parser->Data.satellites[i] <= PRN_GLONASS_END)
|
---|
[2659] | 2997 | RTCM3Text("R%02d", Parser->Data.satellites[i]
|
---|
| 2998 | - (PRN_GLONASS_START-1));
|
---|
[4367] | 2999 | else if(Parser->Data.satellites[i] >= PRN_SBAS_START
|
---|
| 3000 | && Parser->Data.satellites[i] <= PRN_SBAS_END)
|
---|
[2659] | 3001 | RTCM3Text("S%02d", Parser->Data.satellites[i]
|
---|
[4367] | 3002 | - PRN_SBAS_START+20);
|
---|
[2659] | 3003 | else if(Parser->Data.satellites[i] >= PRN_GALILEO_START
|
---|
| 3004 | && Parser->Data.satellites[i] <= PRN_GALILEO_END)
|
---|
| 3005 | RTCM3Text("E%02d", Parser->Data.satellites[i]
|
---|
| 3006 | - (PRN_GALILEO_START-1));
|
---|
| 3007 | else if(Parser->Data.satellites[i] >= PRN_GIOVE_START
|
---|
| 3008 | && Parser->Data.satellites[i] <= PRN_GIOVE_END)
|
---|
| 3009 | RTCM3Text("E%02d", Parser->Data.satellites[i]
|
---|
| 3010 | - (PRN_GIOVE_START-PRN_GIOVE_OFFSET));
|
---|
[4367] | 3011 | else if(Parser->Data.satellites[i] >= PRN_QZSS_START
|
---|
| 3012 | && Parser->Data.satellites[i] <= PRN_QZSS_END)
|
---|
| 3013 | RTCM3Text("J%02d", Parser->Data.satellites[i]
|
---|
| 3014 | - (PRN_QZSS_START-1));
|
---|
| 3015 | else if(Parser->Data.satellites[i] >= PRN_COMPASS_START
|
---|
| 3016 | && Parser->Data.satellites[i] <= PRN_COMPASS_END)
|
---|
| 3017 | RTCM3Text("C%02d", Parser->Data.satellites[i]
|
---|
| 3018 | - (PRN_COMPASS_START-1));
|
---|
[502] | 3019 | else
|
---|
| 3020 | RTCM3Text("%3d", Parser->Data.satellites[i]);
|
---|
[27] | 3021 | }
|
---|
[502] | 3022 | RTCM3Text("\n");
|
---|
| 3023 | j -= 12;
|
---|
| 3024 | o += 12;
|
---|
| 3025 | }
|
---|
[5358] | 3026 | if(nh)
|
---|
| 3027 | {
|
---|
| 3028 | RTCM3Text("%s\n "
|
---|
| 3029 | " END OF HEADER\n", newheader);
|
---|
| 3030 | }
|
---|
[502] | 3031 | for(i = 0; i < Parser->Data.numsats; ++i)
|
---|
| 3032 | {
|
---|
[4371] | 3033 | for(j = 0; j < Parser->info[RTCM3_MSM_GPS].numtypes; ++j)
|
---|
[27] | 3034 | {
|
---|
[502] | 3035 | int v = 0;
|
---|
[4383] | 3036 | long long df = Parser->flags[j];
|
---|
[4371] | 3037 | int pos = Parser->pos[j];
|
---|
[502] | 3038 | if((Parser->Data.dataflags[i] & df)
|
---|
| 3039 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
| 3040 | && !isinf(Parser->Data.measdata[i][pos]))
|
---|
| 3041 | {
|
---|
| 3042 | v = 1;
|
---|
| 3043 | }
|
---|
| 3044 | else
|
---|
| 3045 | {
|
---|
[4371] | 3046 | df = Parser->info[RTCM3_MSM_GPS].flags[j];
|
---|
| 3047 | pos = Parser->info[RTCM3_MSM_GPS].pos[j];
|
---|
[502] | 3048 |
|
---|
| 3049 | if((Parser->Data.dataflags[i] & df)
|
---|
| 3050 | && !isnan(Parser->Data.measdata[i][pos])
|
---|
| 3051 | && !isinf(Parser->Data.measdata[i][pos]))
|
---|
| 3052 | {
|
---|
| 3053 | v = 1;
|
---|
| 3054 | }
|
---|
| 3055 | }
|
---|
| 3056 |
|
---|
| 3057 | if(!v)
|
---|
| 3058 | { /* no or illegal data */
|
---|
| 3059 | RTCM3Text(" ");
|
---|
| 3060 | }
|
---|
| 3061 | else
|
---|
| 3062 | {
|
---|
| 3063 | char lli = ' ';
|
---|
| 3064 | char snr = ' ';
|
---|
| 3065 | if(df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA))
|
---|
| 3066 | {
|
---|
[2659] | 3067 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL1)
|
---|
[502] | 3068 | lli = '1';
|
---|
| 3069 | snr = '0'+Parser->Data.snrL1[i];
|
---|
| 3070 | }
|
---|
| 3071 | if(df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA))
|
---|
| 3072 | {
|
---|
[2659] | 3073 | if(Parser->Data.dataflags2[i]
|
---|
| 3074 | & (GNSSDF2_LOCKLOSSL2|GNSSDF2_XCORRL2))
|
---|
[2422] | 3075 | {
|
---|
| 3076 | lli = '0';
|
---|
[2659] | 3077 | if(Parser->Data.dataflags2[i] & GNSSDF2_LOCKLOSSL2)
|
---|
[2422] | 3078 | lli += 1;
|
---|
[2659] | 3079 | if(Parser->Data.dataflags2[i] & GNSSDF2_XCORRL2)
|
---|
[2422] | 3080 | lli += 4;
|
---|
| 3081 | }
|
---|
[502] | 3082 | snr = '0'+Parser->Data.snrL2[i];
|
---|
| 3083 | }
|
---|
[2659] | 3084 | if((df & GNSSDF_P2DATA) && (Parser->Data.dataflags2[i]
|
---|
| 3085 | & GNSSDF2_XCORRL2))
|
---|
[2422] | 3086 | lli = '4';
|
---|
[502] | 3087 | RTCM3Text("%14.3f%c%c",
|
---|
| 3088 | Parser->Data.measdata[i][pos],lli,snr);
|
---|
| 3089 | }
|
---|
[4371] | 3090 | if(j%5 == 4 || j == Parser->info[RTCM3_MSM_GPS].numtypes-1)
|
---|
[502] | 3091 | RTCM3Text("\n");
|
---|
[27] | 3092 | }
|
---|
| 3093 | }
|
---|
| 3094 | }
|
---|
| 3095 | }
|
---|
| 3096 | }
|
---|
| 3097 | }
|
---|
| 3098 | }
|
---|
| 3099 |
|
---|
[268] | 3100 | #ifndef NO_RTCM3_MAIN
|
---|
[2487] | 3101 | static char datestr[] = "$Date: 2013-11-19 14:41:34 +0000 (Tue, 19 Nov 2013) $";
|
---|
[269] | 3102 |
|
---|
[268] | 3103 | /* The string, which is send as agent in HTTP request */
|
---|
| 3104 | #define AGENTSTRING "NTRIP NtripRTCM3ToRINEX"
|
---|
| 3105 |
|
---|
| 3106 | #define MAXDATASIZE 1000 /* max number of bytes we can get at once */
|
---|
| 3107 |
|
---|
[269] | 3108 | static const char encodingTable [64] = {
|
---|
| 3109 | 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
|
---|
| 3110 | 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
|
---|
| 3111 | 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
|
---|
| 3112 | 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
|
---|
| 3113 | };
|
---|
| 3114 |
|
---|
| 3115 | /* does not buffer overrun, but breaks directly after an error */
|
---|
| 3116 | /* returns the number of required bytes */
|
---|
| 3117 | static int encode(char *buf, int size, const char *user, const char *pwd)
|
---|
| 3118 | {
|
---|
| 3119 | unsigned char inbuf[3];
|
---|
| 3120 | char *out = buf;
|
---|
| 3121 | int i, sep = 0, fill = 0, bytes = 0;
|
---|
| 3122 |
|
---|
| 3123 | while(*user || *pwd)
|
---|
| 3124 | {
|
---|
| 3125 | i = 0;
|
---|
| 3126 | while(i < 3 && *user) inbuf[i++] = *(user++);
|
---|
| 3127 | if(i < 3 && !sep) {inbuf[i++] = ':'; ++sep; }
|
---|
| 3128 | while(i < 3 && *pwd) inbuf[i++] = *(pwd++);
|
---|
| 3129 | while(i < 3) {inbuf[i++] = 0; ++fill; }
|
---|
| 3130 | if(out-buf < size-1)
|
---|
| 3131 | *(out++) = encodingTable[(inbuf [0] & 0xFC) >> 2];
|
---|
| 3132 | if(out-buf < size-1)
|
---|
| 3133 | *(out++) = encodingTable[((inbuf [0] & 0x03) << 4)
|
---|
| 3134 | | ((inbuf [1] & 0xF0) >> 4)];
|
---|
| 3135 | if(out-buf < size-1)
|
---|
| 3136 | {
|
---|
| 3137 | if(fill == 2)
|
---|
| 3138 | *(out++) = '=';
|
---|
| 3139 | else
|
---|
| 3140 | *(out++) = encodingTable[((inbuf [1] & 0x0F) << 2)
|
---|
| 3141 | | ((inbuf [2] & 0xC0) >> 6)];
|
---|
| 3142 | }
|
---|
| 3143 | if(out-buf < size-1)
|
---|
| 3144 | {
|
---|
| 3145 | if(fill >= 1)
|
---|
| 3146 | *(out++) = '=';
|
---|
| 3147 | else
|
---|
| 3148 | *(out++) = encodingTable[inbuf [2] & 0x3F];
|
---|
| 3149 | }
|
---|
| 3150 | bytes += 4;
|
---|
| 3151 | }
|
---|
| 3152 | if(out-buf < size)
|
---|
| 3153 | *out = 0;
|
---|
| 3154 | return bytes;
|
---|
| 3155 | }
|
---|
| 3156 |
|
---|
[268] | 3157 | static int stop = 0;
|
---|
| 3158 |
|
---|
| 3159 | struct Args
|
---|
| 3160 | {
|
---|
| 3161 | const char *server;
|
---|
[502] | 3162 | const char *port;
|
---|
| 3163 | int mode;
|
---|
[477] | 3164 | int timeout;
|
---|
[502] | 3165 | int rinex3;
|
---|
[5358] | 3166 | int changeobs;
|
---|
[268] | 3167 | const char *user;
|
---|
| 3168 | const char *password;
|
---|
[502] | 3169 | const char *proxyhost;
|
---|
| 3170 | const char *proxyport;
|
---|
| 3171 | const char *nmea;
|
---|
[268] | 3172 | const char *data;
|
---|
| 3173 | const char *headerfile;
|
---|
[502] | 3174 | const char *gpsephemeris;
|
---|
| 3175 | const char *glonassephemeris;
|
---|
[268] | 3176 | };
|
---|
| 3177 |
|
---|
| 3178 | /* option parsing */
|
---|
| 3179 | #ifdef NO_LONG_OPTS
|
---|
| 3180 | #define LONG_OPT(a)
|
---|
| 3181 | #else
|
---|
| 3182 | #define LONG_OPT(a) a
|
---|
| 3183 | static struct option opts[] = {
|
---|
[502] | 3184 | { "data", required_argument, 0, 'd'},
|
---|
| 3185 | { "server", required_argument, 0, 's'},
|
---|
| 3186 | { "password", required_argument, 0, 'p'},
|
---|
| 3187 | { "port", required_argument, 0, 'r'},
|
---|
| 3188 | { "timeout", required_argument, 0, 't'},
|
---|
| 3189 | { "header", required_argument, 0, 'f'},
|
---|
| 3190 | { "user", required_argument, 0, 'u'},
|
---|
| 3191 | { "gpsephemeris", required_argument, 0, 'E'},
|
---|
| 3192 | { "glonassephemeris", required_argument, 0, 'G'},
|
---|
| 3193 | { "rinex3", no_argument, 0, '3'},
|
---|
[5358] | 3194 | { "changeobs", no_argument, 0, 'O'},
|
---|
[502] | 3195 | { "proxyport", required_argument, 0, 'R'},
|
---|
| 3196 | { "proxyhost", required_argument, 0, 'S'},
|
---|
| 3197 | { "nmea", required_argument, 0, 'n'},
|
---|
| 3198 | { "mode", required_argument, 0, 'M'},
|
---|
| 3199 | { "help", no_argument, 0, 'h'},
|
---|
[268] | 3200 | {0,0,0,0}};
|
---|
| 3201 | #endif
|
---|
[5358] | 3202 | #define ARGOPT "-d:s:p:r:t:f:u:E:G:M:S:R:n:h3O"
|
---|
[268] | 3203 |
|
---|
[502] | 3204 | enum MODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, AUTO = 4, END };
|
---|
| 3205 |
|
---|
[270] | 3206 | static const char *geturl(const char *url, struct Args *args)
|
---|
| 3207 | {
|
---|
| 3208 | static char buf[1000];
|
---|
| 3209 | static char *Buffer = buf;
|
---|
| 3210 | static char *Bufend = buf+sizeof(buf);
|
---|
| 3211 |
|
---|
| 3212 | if(strncmp("ntrip:", url, 6))
|
---|
| 3213 | return "URL must start with 'ntrip:'.";
|
---|
| 3214 | url += 6; /* skip ntrip: */
|
---|
| 3215 |
|
---|
| 3216 | if(*url != '@' && *url != '/')
|
---|
| 3217 | {
|
---|
| 3218 | /* scan for mountpoint */
|
---|
| 3219 | args->data = Buffer;
|
---|
[502] | 3220 | while(*url && *url != '@' && *url != ';' &&*url != '/' && Buffer != Bufend)
|
---|
[270] | 3221 | *(Buffer++) = *(url++);
|
---|
| 3222 | if(Buffer == args->data)
|
---|
| 3223 | return "Mountpoint required.";
|
---|
| 3224 | else if(Buffer >= Bufend-1)
|
---|
| 3225 | return "Parsing buffer too short.";
|
---|
| 3226 | *(Buffer++) = 0;
|
---|
| 3227 | }
|
---|
| 3228 |
|
---|
| 3229 | if(*url == '/') /* username and password */
|
---|
| 3230 | {
|
---|
| 3231 | ++url;
|
---|
| 3232 | args->user = Buffer;
|
---|
[502] | 3233 | while(*url && *url != '@' && *url != ';' && *url != ':' && Buffer != Bufend)
|
---|
[270] | 3234 | *(Buffer++) = *(url++);
|
---|
| 3235 | if(Buffer == args->user)
|
---|
| 3236 | return "Username cannot be empty.";
|
---|
| 3237 | else if(Buffer >= Bufend-1)
|
---|
| 3238 | return "Parsing buffer too short.";
|
---|
| 3239 | *(Buffer++) = 0;
|
---|
| 3240 |
|
---|
| 3241 | if(*url == ':') ++url;
|
---|
| 3242 |
|
---|
| 3243 | args->password = Buffer;
|
---|
[502] | 3244 | while(*url && *url != '@' && *url != ';' && Buffer != Bufend)
|
---|
[270] | 3245 | *(Buffer++) = *(url++);
|
---|
| 3246 | if(Buffer == args->password)
|
---|
| 3247 | return "Password cannot be empty.";
|
---|
| 3248 | else if(Buffer >= Bufend-1)
|
---|
| 3249 | return "Parsing buffer too short.";
|
---|
| 3250 | *(Buffer++) = 0;
|
---|
| 3251 | }
|
---|
| 3252 |
|
---|
| 3253 | if(*url == '@') /* server */
|
---|
| 3254 | {
|
---|
| 3255 | ++url;
|
---|
[502] | 3256 | if(*url != '@' && *url != ':')
|
---|
| 3257 | {
|
---|
| 3258 | args->server = Buffer;
|
---|
| 3259 | while(*url && *url != '@' && *url != ':' && *url != ';' && Buffer != Bufend)
|
---|
| 3260 | *(Buffer++) = *(url++);
|
---|
| 3261 | if(Buffer == args->server)
|
---|
| 3262 | return "Servername cannot be empty.";
|
---|
| 3263 | else if(Buffer >= Bufend-1)
|
---|
| 3264 | return "Parsing buffer too short.";
|
---|
| 3265 | *(Buffer++) = 0;
|
---|
| 3266 | }
|
---|
[270] | 3267 |
|
---|
| 3268 | if(*url == ':')
|
---|
| 3269 | {
|
---|
[502] | 3270 | ++url;
|
---|
| 3271 | args->port = Buffer;
|
---|
| 3272 | while(*url && *url != '@' && *url != ';' && Buffer != Bufend)
|
---|
| 3273 | *(Buffer++) = *(url++);
|
---|
| 3274 | if(Buffer == args->port)
|
---|
| 3275 | return "Port cannot be empty.";
|
---|
| 3276 | else if(Buffer >= Bufend-1)
|
---|
| 3277 | return "Parsing buffer too short.";
|
---|
| 3278 | *(Buffer++) = 0;
|
---|
[270] | 3279 | }
|
---|
[502] | 3280 |
|
---|
| 3281 | if(*url == '@') /* proxy */
|
---|
| 3282 | {
|
---|
| 3283 | ++url;
|
---|
| 3284 | args->proxyhost = Buffer;
|
---|
| 3285 | while(*url && *url != ':' && *url != ';' && Buffer != Bufend)
|
---|
| 3286 | *(Buffer++) = *(url++);
|
---|
| 3287 | if(Buffer == args->proxyhost)
|
---|
| 3288 | return "Proxy servername cannot be empty.";
|
---|
| 3289 | else if(Buffer >= Bufend-1)
|
---|
| 3290 | return "Parsing buffer too short.";
|
---|
| 3291 | *(Buffer++) = 0;
|
---|
| 3292 |
|
---|
| 3293 | if(*url == ':')
|
---|
| 3294 | {
|
---|
| 3295 | ++url;
|
---|
| 3296 | args->proxyport = Buffer;
|
---|
| 3297 | while(*url && *url != ';' && Buffer != Bufend)
|
---|
| 3298 | *(Buffer++) = *(url++);
|
---|
| 3299 | if(Buffer == args->proxyport)
|
---|
| 3300 | return "Proxy port cannot be empty.";
|
---|
| 3301 | else if(Buffer >= Bufend-1)
|
---|
| 3302 | return "Parsing buffer too short.";
|
---|
| 3303 | *(Buffer++) = 0;
|
---|
| 3304 | }
|
---|
| 3305 | }
|
---|
[270] | 3306 | }
|
---|
[502] | 3307 | if(*url == ';') /* NMEA */
|
---|
| 3308 | {
|
---|
| 3309 | args->nmea = ++url;
|
---|
| 3310 | while(*url)
|
---|
| 3311 | ++url;
|
---|
| 3312 | }
|
---|
[270] | 3313 |
|
---|
| 3314 | return *url ? "Garbage at end of server string." : 0;
|
---|
| 3315 | }
|
---|
| 3316 |
|
---|
[268] | 3317 | static int getargs(int argc, char **argv, struct Args *args)
|
---|
| 3318 | {
|
---|
| 3319 | int res = 1;
|
---|
| 3320 | int getoptr;
|
---|
| 3321 | int help = 0;
|
---|
| 3322 | char *t;
|
---|
| 3323 |
|
---|
| 3324 | args->server = "www.euref-ip.net";
|
---|
[502] | 3325 | args->port = "2101";
|
---|
[477] | 3326 | args->timeout = 60;
|
---|
[268] | 3327 | args->user = "";
|
---|
| 3328 | args->password = "";
|
---|
| 3329 | args->data = 0;
|
---|
| 3330 | args->headerfile = 0;
|
---|
[502] | 3331 | args->gpsephemeris = 0;
|
---|
| 3332 | args->glonassephemeris = 0;
|
---|
| 3333 | args->rinex3 = 0;
|
---|
| 3334 | args->nmea = 0;
|
---|
[5358] | 3335 | args->changeobs = 0;
|
---|
[502] | 3336 | args->proxyhost = 0;
|
---|
| 3337 | args->proxyport = "2101";
|
---|
| 3338 | args->mode = AUTO;
|
---|
[268] | 3339 | help = 0;
|
---|
| 3340 |
|
---|
| 3341 | do
|
---|
| 3342 | {
|
---|
[477] | 3343 |
|
---|
[268] | 3344 | #ifdef NO_LONG_OPTS
|
---|
| 3345 | switch((getoptr = getopt(argc, argv, ARGOPT)))
|
---|
| 3346 | #else
|
---|
| 3347 | switch((getoptr = getopt_long(argc, argv, ARGOPT, opts, 0)))
|
---|
| 3348 | #endif
|
---|
| 3349 | {
|
---|
| 3350 | case 's': args->server = optarg; break;
|
---|
| 3351 | case 'u': args->user = optarg; break;
|
---|
| 3352 | case 'p': args->password = optarg; break;
|
---|
| 3353 | case 'd': args->data = optarg; break;
|
---|
| 3354 | case 'f': args->headerfile = optarg; break;
|
---|
[502] | 3355 | case 'E': args->gpsephemeris = optarg; break;
|
---|
| 3356 | case 'G': args->glonassephemeris = optarg; break;
|
---|
| 3357 | case 'r': args->port = optarg; break;
|
---|
| 3358 | case '3': args->rinex3 = 1; break;
|
---|
| 3359 | case 'S': args->proxyhost = optarg; break;
|
---|
| 3360 | case 'n': args->nmea = optarg; break;
|
---|
| 3361 | case 'R': args->proxyport = optarg; break;
|
---|
[5358] | 3362 | case 'O': args->changeobs = 1; break;
|
---|
[268] | 3363 | case 'h': help=1; break;
|
---|
[502] | 3364 | case 'M':
|
---|
| 3365 | args->mode = 0;
|
---|
| 3366 | if (!strcmp(optarg,"n") || !strcmp(optarg,"ntrip1"))
|
---|
| 3367 | args->mode = NTRIP1;
|
---|
| 3368 | else if(!strcmp(optarg,"h") || !strcmp(optarg,"http"))
|
---|
| 3369 | args->mode = HTTP;
|
---|
| 3370 | else if(!strcmp(optarg,"r") || !strcmp(optarg,"rtsp"))
|
---|
| 3371 | args->mode = RTSP;
|
---|
| 3372 | else if(!strcmp(optarg,"a") || !strcmp(optarg,"auto"))
|
---|
| 3373 | args->mode = AUTO;
|
---|
| 3374 | else args->mode = atoi(optarg);
|
---|
| 3375 | if((args->mode == 0) || (args->mode >= END))
|
---|
| 3376 | {
|
---|
| 3377 | fprintf(stderr, "Mode %s unknown\n", optarg);
|
---|
[268] | 3378 | res = 0;
|
---|
[502] | 3379 | }
|
---|
[268] | 3380 | break;
|
---|
[502] | 3381 | case 't':
|
---|
[477] | 3382 | args->timeout = strtoul(optarg, &t, 10);
|
---|
| 3383 | if((t && *t) || args->timeout < 0)
|
---|
| 3384 | res = 0;
|
---|
| 3385 | break;
|
---|
| 3386 |
|
---|
[270] | 3387 | case 1:
|
---|
| 3388 | {
|
---|
| 3389 | const char *err;
|
---|
| 3390 | if((err = geturl(optarg, args)))
|
---|
| 3391 | {
|
---|
[318] | 3392 | RTCM3Error("%s\n\n", err);
|
---|
[270] | 3393 | res = 0;
|
---|
| 3394 | }
|
---|
| 3395 | }
|
---|
| 3396 | break;
|
---|
[268] | 3397 | case -1: break;
|
---|
| 3398 | }
|
---|
| 3399 | } while(getoptr != -1 || !res);
|
---|
| 3400 |
|
---|
| 3401 | datestr[0] = datestr[7];
|
---|
| 3402 | datestr[1] = datestr[8];
|
---|
| 3403 | datestr[2] = datestr[9];
|
---|
| 3404 | datestr[3] = datestr[10];
|
---|
| 3405 | datestr[5] = datestr[12];
|
---|
| 3406 | datestr[6] = datestr[13];
|
---|
| 3407 | datestr[8] = datestr[15];
|
---|
| 3408 | datestr[9] = datestr[16];
|
---|
| 3409 | datestr[4] = datestr[7] = '-';
|
---|
| 3410 | datestr[10] = 0;
|
---|
| 3411 |
|
---|
[502] | 3412 | if(args->gpsephemeris && args->glonassephemeris && args->rinex3)
|
---|
[268] | 3413 | {
|
---|
[503] | 3414 | RTCM3Error("RINEX3 produces a combined ephemeris file, but 2 files were specified.\n"
|
---|
| 3415 | "Please specify only one navigation file.\n");
|
---|
[502] | 3416 | res = 0;
|
---|
| 3417 | }
|
---|
| 3418 | else if(!res || help)
|
---|
| 3419 | {
|
---|
[439] | 3420 | RTCM3Error("Version %s (%s) GPL" COMPILEDATE
|
---|
| 3421 | "\nUsage: %s -s server -u user ...\n"
|
---|
[502] | 3422 | " -d " LONG_OPT("--data ") "the requested data set\n"
|
---|
| 3423 | " -f " LONG_OPT("--headerfile ") "file for RINEX header information\n"
|
---|
| 3424 | " -s " LONG_OPT("--server ") "the server name or address\n"
|
---|
| 3425 | " -p " LONG_OPT("--password ") "the login password\n"
|
---|
| 3426 | " -r " LONG_OPT("--port ") "the server port number (default 2101)\n"
|
---|
| 3427 | " -t " LONG_OPT("--timeout ") "timeout in seconds (default 60)\n"
|
---|
| 3428 | " -u " LONG_OPT("--user ") "the user name\n"
|
---|
| 3429 | " -E " LONG_OPT("--gpsephemeris ") "output file for GPS ephemeris data\n"
|
---|
| 3430 | " -G " LONG_OPT("--glonassephemeris ") "output file for GLONASS ephemeris data\n"
|
---|
| 3431 | " -3 " LONG_OPT("--rinex3 ") "output RINEX type 3 data\n"
|
---|
| 3432 | " -S " LONG_OPT("--proxyhost ") "proxy name or address\n"
|
---|
| 3433 | " -R " LONG_OPT("--proxyport ") "proxy port, optional (default 2101)\n"
|
---|
| 3434 | " -n " LONG_OPT("--nmea ") "NMEA string for sending to server\n"
|
---|
[5358] | 3435 | " -O " LONG_OPT("--changeobs ") "Add observation type change header lines\n"
|
---|
[502] | 3436 | " -M " LONG_OPT("--mode ") "mode for data request\n"
|
---|
| 3437 | " Valid modes are:\n"
|
---|
| 3438 | " 1, h, http NTRIP Version 2.0 Caster in TCP/IP mode\n"
|
---|
| 3439 | " 2, r, rtsp NTRIP Version 2.0 Caster in RTSP/RTP mode\n"
|
---|
| 3440 | " 3, n, ntrip1 NTRIP Version 1.0 Caster\n"
|
---|
| 3441 | " 4, a, auto automatic detection (default)\n"
|
---|
| 3442 | "or using an URL:\n%s ntrip:data[/user[:password]][@[server][:port][@proxyhost[:proxyport]]][;nmea]\n"
|
---|
[270] | 3443 | , revisionstr, datestr, argv[0], argv[0]);
|
---|
[268] | 3444 | exit(1);
|
---|
| 3445 | }
|
---|
| 3446 | return res;
|
---|
| 3447 | }
|
---|
| 3448 |
|
---|
| 3449 | /* let the output complete a block if necessary */
|
---|
| 3450 | static void signalhandler(int sig)
|
---|
| 3451 | {
|
---|
| 3452 | if(!stop)
|
---|
| 3453 | {
|
---|
[318] | 3454 | RTCM3Error("Stop signal number %d received. "
|
---|
[268] | 3455 | "Trying to terminate gentle.\n", sig);
|
---|
| 3456 | stop = 1;
|
---|
| 3457 | alarm(1);
|
---|
| 3458 | }
|
---|
| 3459 | }
|
---|
| 3460 |
|
---|
[1091] | 3461 | #ifndef WINDOWSVERSION
|
---|
| 3462 | static void WaitMicro(int mic)
|
---|
| 3463 | {
|
---|
| 3464 | struct timeval tv;
|
---|
| 3465 | tv.tv_sec = mic/1000000;
|
---|
| 3466 | tv.tv_usec = mic%1000000;
|
---|
| 3467 | #ifdef DEBUG
|
---|
| 3468 | fprintf(stderr, "Waiting %d micro seconds\n", mic);
|
---|
| 3469 | #endif
|
---|
| 3470 | select(0, 0, 0, 0, &tv);
|
---|
| 3471 | }
|
---|
| 3472 | #else /* WINDOWSVERSION */
|
---|
| 3473 | void WaitMicro(int mic)
|
---|
| 3474 | {
|
---|
| 3475 | Sleep(mic/1000);
|
---|
| 3476 | }
|
---|
| 3477 | #endif /* WINDOWSVERSION */
|
---|
| 3478 |
|
---|
[502] | 3479 | #define ALARMTIME (2*60)
|
---|
| 3480 |
|
---|
[268] | 3481 | /* for some reason we had to abort hard (maybe waiting for data */
|
---|
| 3482 | #ifdef __GNUC__
|
---|
| 3483 | static __attribute__ ((noreturn)) void signalhandler_alarm(
|
---|
| 3484 | int sig __attribute__((__unused__)))
|
---|
| 3485 | #else /* __GNUC__ */
|
---|
| 3486 | static void signalhandler_alarm(int sig)
|
---|
| 3487 | #endif /* __GNUC__ */
|
---|
| 3488 | {
|
---|
[318] | 3489 | RTCM3Error("Programm forcefully terminated.\n");
|
---|
[268] | 3490 | exit(1);
|
---|
| 3491 | }
|
---|
| 3492 |
|
---|
[27] | 3493 | int main(int argc, char **argv)
|
---|
| 3494 | {
|
---|
| 3495 | struct Args args;
|
---|
| 3496 | struct RTCM3ParserData Parser;
|
---|
| 3497 |
|
---|
| 3498 | setbuf(stdout, 0);
|
---|
| 3499 | setbuf(stdin, 0);
|
---|
| 3500 | setbuf(stderr, 0);
|
---|
| 3501 |
|
---|
[2487] | 3502 | fixrevision();
|
---|
[27] | 3503 |
|
---|
| 3504 | signal(SIGINT, signalhandler);
|
---|
| 3505 | signal(SIGALRM,signalhandler_alarm);
|
---|
| 3506 | signal(SIGQUIT,signalhandler);
|
---|
| 3507 | signal(SIGTERM,signalhandler);
|
---|
| 3508 | signal(SIGPIPE,signalhandler);
|
---|
| 3509 | memset(&Parser, 0, sizeof(Parser));
|
---|
| 3510 | {
|
---|
| 3511 | time_t tim;
|
---|
| 3512 | tim = time(0) - ((10*365+2+5)*24*60*60+LEAPSECONDS);
|
---|
| 3513 | Parser.GPSWeek = tim/(7*24*60*60);
|
---|
| 3514 | Parser.GPSTOW = tim%(7*24*60*60);
|
---|
| 3515 | }
|
---|
| 3516 |
|
---|
| 3517 | if(getargs(argc, argv, &args))
|
---|
| 3518 | {
|
---|
[1088] | 3519 | int sockfd, numbytes;
|
---|
[27] | 3520 | char buf[MAXDATASIZE];
|
---|
[502] | 3521 | struct sockaddr_in their_addr; /* connector's address information */
|
---|
[27] | 3522 | struct hostent *he;
|
---|
[502] | 3523 | struct servent *se;
|
---|
| 3524 | const char *server, *port, *proxyserver = 0;
|
---|
| 3525 | char proxyport[6];
|
---|
| 3526 | char *b;
|
---|
| 3527 | long i;
|
---|
| 3528 | struct timeval tv;
|
---|
[27] | 3529 |
|
---|
[502] | 3530 | alarm(ALARMTIME);
|
---|
| 3531 |
|
---|
[27] | 3532 | Parser.headerfile = args.headerfile;
|
---|
[502] | 3533 | Parser.glonassephemeris = args.glonassephemeris;
|
---|
| 3534 | Parser.gpsephemeris = args.gpsephemeris;
|
---|
| 3535 | Parser.rinex3 = args.rinex3;
|
---|
[5358] | 3536 | Parser.changeobs = args.changeobs;
|
---|
[27] | 3537 |
|
---|
[502] | 3538 | if(args.proxyhost)
|
---|
[27] | 3539 | {
|
---|
[502] | 3540 | int p;
|
---|
| 3541 | if((i = strtol(args.port, &b, 10)) && (!b || !*b))
|
---|
| 3542 | p = i;
|
---|
| 3543 | else if(!(se = getservbyname(args.port, 0)))
|
---|
| 3544 | {
|
---|
| 3545 | RTCM3Error("Can't resolve port %s.", args.port);
|
---|
| 3546 | exit(1);
|
---|
| 3547 | }
|
---|
| 3548 | else
|
---|
| 3549 | {
|
---|
| 3550 | p = ntohs(se->s_port);
|
---|
| 3551 | }
|
---|
| 3552 | snprintf(proxyport, sizeof(proxyport), "%d", p);
|
---|
| 3553 | port = args.proxyport;
|
---|
| 3554 | proxyserver = args.server;
|
---|
| 3555 | server = args.proxyhost;
|
---|
| 3556 | }
|
---|
| 3557 | else
|
---|
| 3558 | {
|
---|
| 3559 | server = args.server;
|
---|
| 3560 | port = args.port;
|
---|
| 3561 | }
|
---|
| 3562 |
|
---|
| 3563 | memset(&their_addr, 0, sizeof(struct sockaddr_in));
|
---|
| 3564 | if((i = strtol(port, &b, 10)) && (!b || !*b))
|
---|
| 3565 | their_addr.sin_port = htons(i);
|
---|
| 3566 | else if(!(se = getservbyname(port, 0)))
|
---|
| 3567 | {
|
---|
| 3568 | RTCM3Error("Can't resolve port %s.", port);
|
---|
[27] | 3569 | exit(1);
|
---|
| 3570 | }
|
---|
[502] | 3571 | else
|
---|
| 3572 | {
|
---|
| 3573 | their_addr.sin_port = se->s_port;
|
---|
| 3574 | }
|
---|
| 3575 | if(!(he=gethostbyname(server)))
|
---|
| 3576 | {
|
---|
| 3577 | RTCM3Error("Server name lookup failed for '%s'.\n", server);
|
---|
| 3578 | exit(1);
|
---|
| 3579 | }
|
---|
[27] | 3580 | if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
---|
| 3581 | {
|
---|
[502] | 3582 | perror("socket");
|
---|
[27] | 3583 | exit(1);
|
---|
| 3584 | }
|
---|
[477] | 3585 |
|
---|
| 3586 | tv.tv_sec = args.timeout;
|
---|
| 3587 | tv.tv_usec = 0;
|
---|
| 3588 | if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv, sizeof(struct timeval) ) == -1)
|
---|
| 3589 | {
|
---|
| 3590 | RTCM3Error("Function setsockopt: %s\n", strerror(errno));
|
---|
| 3591 | exit(1);
|
---|
| 3592 | }
|
---|
| 3593 |
|
---|
[502] | 3594 | their_addr.sin_family = AF_INET;
|
---|
[27] | 3595 | their_addr.sin_addr = *((struct in_addr *)he->h_addr);
|
---|
[502] | 3596 |
|
---|
| 3597 | if(args.data && args.mode == RTSP)
|
---|
[27] | 3598 | {
|
---|
[502] | 3599 | struct sockaddr_in local;
|
---|
| 3600 | int sockudp, localport;
|
---|
| 3601 | int cseq = 1;
|
---|
| 3602 | socklen_t len;
|
---|
[27] | 3603 |
|
---|
[502] | 3604 | if((sockudp = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
|
---|
| 3605 | {
|
---|
| 3606 | perror("socket");
|
---|
| 3607 | exit(1);
|
---|
| 3608 | }
|
---|
| 3609 | /* fill structure with local address information for UDP */
|
---|
| 3610 | memset(&local, 0, sizeof(local));
|
---|
[1088] | 3611 | local.sin_family = AF_INET;
|
---|
[502] | 3612 | local.sin_port = htons(0);
|
---|
[1088] | 3613 | local.sin_addr.s_addr = htonl(INADDR_ANY);
|
---|
[502] | 3614 | len = sizeof(local);
|
---|
[1088] | 3615 | /* bind() in order to get a random RTP client_port */
|
---|
[502] | 3616 | if((bind(sockudp, (struct sockaddr *)&local, len)) < 0)
|
---|
| 3617 | {
|
---|
| 3618 | perror("bind");
|
---|
| 3619 | exit(1);
|
---|
| 3620 | }
|
---|
[1088] | 3621 | if((getsockname(sockudp, (struct sockaddr*)&local, &len)) != -1)
|
---|
[502] | 3622 | {
|
---|
[1088] | 3623 | localport = ntohs(local.sin_port);
|
---|
[502] | 3624 | }
|
---|
| 3625 | else
|
---|
| 3626 | {
|
---|
[1088] | 3627 | perror("local access failed");
|
---|
[502] | 3628 | exit(1);
|
---|
| 3629 | }
|
---|
| 3630 | if(connect(sockfd, (struct sockaddr *)&their_addr,
|
---|
| 3631 | sizeof(struct sockaddr)) == -1)
|
---|
| 3632 | {
|
---|
| 3633 | perror("connect");
|
---|
| 3634 | exit(1);
|
---|
| 3635 | }
|
---|
[27] | 3636 | i=snprintf(buf, MAXDATASIZE-40, /* leave some space for login */
|
---|
[1088] | 3637 | "SETUP rtsp://%s%s%s/%s RTSP/1.0\r\n"
|
---|
| 3638 | "CSeq: %d\r\n"
|
---|
[502] | 3639 | "Ntrip-Version: Ntrip/2.0\r\n"
|
---|
| 3640 | "Ntrip-Component: Ntripclient\r\n"
|
---|
[27] | 3641 | "User-Agent: %s/%s\r\n"
|
---|
[502] | 3642 | "Transport: RTP/GNSS;unicast;client_port=%u\r\n"
|
---|
| 3643 | "Authorization: Basic ",
|
---|
| 3644 | args.server, proxyserver ? ":" : "", proxyserver ? args.port : "",
|
---|
| 3645 | args.data, cseq++, AGENTSTRING, revisionstr, localport);
|
---|
[479] | 3646 | if(i > MAXDATASIZE-40 || i < 0) /* second check for old glibc */
|
---|
[27] | 3647 | {
|
---|
[318] | 3648 | RTCM3Error("Requested data too long\n");
|
---|
[27] | 3649 | exit(1);
|
---|
| 3650 | }
|
---|
[339] | 3651 | i += encode(buf+i, MAXDATASIZE-i-4, args.user, args.password);
|
---|
| 3652 | if(i > MAXDATASIZE-4)
|
---|
[27] | 3653 | {
|
---|
[318] | 3654 | RTCM3Error("Username and/or password too long\n");
|
---|
[27] | 3655 | exit(1);
|
---|
| 3656 | }
|
---|
[339] | 3657 | buf[i++] = '\r';
|
---|
| 3658 | buf[i++] = '\n';
|
---|
| 3659 | buf[i++] = '\r';
|
---|
| 3660 | buf[i++] = '\n';
|
---|
[502] | 3661 | if(args.nmea)
|
---|
[27] | 3662 | {
|
---|
[502] | 3663 | int j = snprintf(buf+i, MAXDATASIZE-i, "%s\r\n", args.nmea);
|
---|
| 3664 | if(j >= 0 && j < MAXDATASIZE-i)
|
---|
| 3665 | i += j;
|
---|
| 3666 | else
|
---|
[27] | 3667 | {
|
---|
[502] | 3668 | RTCM3Error("NMEA string too long\n");
|
---|
| 3669 | exit(1);
|
---|
| 3670 | }
|
---|
| 3671 | }
|
---|
| 3672 | if(send(sockfd, buf, (size_t)i, 0) != i)
|
---|
| 3673 | {
|
---|
| 3674 | perror("send");
|
---|
| 3675 | exit(1);
|
---|
| 3676 | }
|
---|
| 3677 | if((numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) != -1)
|
---|
| 3678 | {
|
---|
| 3679 | if(numbytes >= 17 && !strncmp(buf, "RTSP/1.0 200 OK\r\n", 17))
|
---|
[744] | 3680 | {
|
---|
[502] | 3681 | int serverport = 0, session = 0;
|
---|
| 3682 | const char *portcheck = "server_port=";
|
---|
| 3683 | const char *sessioncheck = "session: ";
|
---|
| 3684 | int l = strlen(portcheck)-1;
|
---|
| 3685 | int j=0;
|
---|
| 3686 | for(i = 0; j != l && i < numbytes-l; ++i)
|
---|
[27] | 3687 | {
|
---|
[502] | 3688 | for(j = 0; j < l && tolower(buf[i+j]) == portcheck[j]; ++j)
|
---|
| 3689 | ;
|
---|
| 3690 | }
|
---|
| 3691 | if(i == numbytes-l)
|
---|
| 3692 | {
|
---|
| 3693 | RTCM3Error("No server port number found\n");
|
---|
| 3694 | exit(1);
|
---|
| 3695 | }
|
---|
| 3696 | else
|
---|
| 3697 | {
|
---|
| 3698 | i+=l;
|
---|
| 3699 | while(i < numbytes && buf[i] >= '0' && buf[i] <= '9')
|
---|
| 3700 | serverport = serverport * 10 + buf[i++]-'0';
|
---|
| 3701 | if(buf[i] != '\r' && buf[i] != ';')
|
---|
[27] | 3702 | {
|
---|
[502] | 3703 | RTCM3Error("Could not extract server port\n");
|
---|
| 3704 | exit(1);
|
---|
[27] | 3705 | }
|
---|
[502] | 3706 | }
|
---|
| 3707 | l = strlen(sessioncheck)-1;
|
---|
| 3708 | j=0;
|
---|
| 3709 | for(i = 0; j != l && i < numbytes-l; ++i)
|
---|
| 3710 | {
|
---|
| 3711 | for(j = 0; j < l && tolower(buf[i+j]) == sessioncheck[j]; ++j)
|
---|
| 3712 | ;
|
---|
| 3713 | }
|
---|
| 3714 | if(i == numbytes-l)
|
---|
| 3715 | {
|
---|
| 3716 | RTCM3Error("No session number found\n");
|
---|
[27] | 3717 | exit(1);
|
---|
| 3718 | }
|
---|
[502] | 3719 | else
|
---|
| 3720 | {
|
---|
| 3721 | i+=l;
|
---|
| 3722 | while(i < numbytes && buf[i] >= '0' && buf[i] <= '9')
|
---|
| 3723 | session = session * 10 + buf[i++]-'0';
|
---|
| 3724 | if(buf[i] != '\r')
|
---|
| 3725 | {
|
---|
| 3726 | RTCM3Error("Could not extract session number\n");
|
---|
| 3727 | exit(1);
|
---|
| 3728 | }
|
---|
| 3729 | }
|
---|
| 3730 |
|
---|
| 3731 | i = snprintf(buf, MAXDATASIZE,
|
---|
[1088] | 3732 | "PLAY rtsp://%s%s%s/%s RTSP/1.0\r\n"
|
---|
[502] | 3733 | "CSeq: %d\r\n"
|
---|
| 3734 | "Session: %d\r\n"
|
---|
[1088] | 3735 | "\r\n",
|
---|
[502] | 3736 | args.server, proxyserver ? ":" : "", proxyserver ? args.port : "",
|
---|
| 3737 | args.data, cseq++, session);
|
---|
| 3738 |
|
---|
| 3739 | if(i > MAXDATASIZE || i < 0) /* second check for old glibc */
|
---|
| 3740 | {
|
---|
| 3741 | RTCM3Error("Requested data too long\n");
|
---|
| 3742 | exit(1);
|
---|
| 3743 | }
|
---|
| 3744 | if(send(sockfd, buf, (size_t)i, 0) != i)
|
---|
| 3745 | {
|
---|
| 3746 | perror("send");
|
---|
| 3747 | exit(1);
|
---|
| 3748 | }
|
---|
| 3749 | if((numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) != -1)
|
---|
| 3750 | {
|
---|
| 3751 | if(numbytes >= 17 && !strncmp(buf, "RTSP/1.0 200 OK\r\n", 17))
|
---|
| 3752 | {
|
---|
| 3753 | struct sockaddr_in addrRTP;
|
---|
| 3754 | /* fill structure with caster address information for UDP */
|
---|
| 3755 | memset(&addrRTP, 0, sizeof(addrRTP));
|
---|
[1088] | 3756 | addrRTP.sin_family = AF_INET;
|
---|
[502] | 3757 | addrRTP.sin_port = htons(serverport);
|
---|
| 3758 | their_addr.sin_addr = *((struct in_addr *)he->h_addr);
|
---|
| 3759 | len = sizeof(addrRTP);
|
---|
| 3760 | int ts = 0;
|
---|
| 3761 | int sn = 0;
|
---|
| 3762 | int ssrc = 0;
|
---|
| 3763 | int init = 0;
|
---|
| 3764 | int u, v, w;
|
---|
| 3765 | while(!stop && (i = recvfrom(sockudp, buf, 1526, 0,
|
---|
| 3766 | (struct sockaddr*) &addrRTP, &len)) > 0)
|
---|
| 3767 | {
|
---|
| 3768 | alarm(ALARMTIME);
|
---|
| 3769 | if(i >= 12+1 && (unsigned char)buf[0] == (2 << 6) && buf[1] == 0x60)
|
---|
| 3770 | {
|
---|
| 3771 | u= ((unsigned char)buf[2]<<8)+(unsigned char)buf[3];
|
---|
| 3772 | v = ((unsigned char)buf[4]<<24)+((unsigned char)buf[5]<<16)
|
---|
| 3773 | +((unsigned char)buf[6]<<8)+(unsigned char)buf[7];
|
---|
| 3774 | w = ((unsigned char)buf[8]<<24)+((unsigned char)buf[9]<<16)
|
---|
| 3775 | +((unsigned char)buf[10]<<8)+(unsigned char)buf[11];
|
---|
| 3776 |
|
---|
| 3777 | if(init)
|
---|
| 3778 | {
|
---|
[1091] | 3779 | int z;
|
---|
[502] | 3780 | if(u < -30000 && sn > 30000) sn -= 0xFFFF;
|
---|
| 3781 | if(ssrc != w || ts > v)
|
---|
| 3782 | {
|
---|
| 3783 | RTCM3Error("Illegal UDP data received.\n");
|
---|
| 3784 | exit(1);
|
---|
| 3785 | }
|
---|
| 3786 | if(u > sn) /* don't show out-of-order packets */
|
---|
[1091] | 3787 | for(z = 12; z < i && !stop; ++z)
|
---|
| 3788 | HandleByte(&Parser, (unsigned int) buf[z]);
|
---|
[502] | 3789 | }
|
---|
| 3790 | sn = u; ts = v; ssrc = w; init = 1;
|
---|
| 3791 | }
|
---|
| 3792 | else
|
---|
| 3793 | {
|
---|
| 3794 | RTCM3Error("Illegal UDP header.\n");
|
---|
| 3795 | exit(1);
|
---|
| 3796 | }
|
---|
| 3797 | }
|
---|
| 3798 | }
|
---|
| 3799 | i = snprintf(buf, MAXDATASIZE,
|
---|
[1088] | 3800 | "TEARDOWN rtsp://%s%s%s/%s RTSP/1.0\r\n"
|
---|
[502] | 3801 | "CSeq: %d\r\n"
|
---|
| 3802 | "Session: %d\r\n"
|
---|
[1088] | 3803 | "\r\n",
|
---|
[502] | 3804 | args.server, proxyserver ? ":" : "", proxyserver ? args.port : "",
|
---|
| 3805 | args.data, cseq++, session);
|
---|
| 3806 |
|
---|
| 3807 | if(i > MAXDATASIZE || i < 0) /* second check for old glibc */
|
---|
| 3808 | {
|
---|
| 3809 | RTCM3Error("Requested data too long\n");
|
---|
| 3810 | exit(1);
|
---|
| 3811 | }
|
---|
| 3812 | if(send(sockfd, buf, (size_t)i, 0) != i)
|
---|
| 3813 | {
|
---|
| 3814 | perror("send");
|
---|
| 3815 | exit(1);
|
---|
| 3816 | }
|
---|
| 3817 | }
|
---|
| 3818 | else
|
---|
| 3819 | {
|
---|
| 3820 | RTCM3Error("Could not start data stream.\n");
|
---|
| 3821 | exit(1);
|
---|
| 3822 | }
|
---|
[27] | 3823 | }
|
---|
| 3824 | else
|
---|
| 3825 | {
|
---|
[502] | 3826 | RTCM3Error("Could not setup initial control connection.\n");
|
---|
| 3827 | exit(1);
|
---|
[27] | 3828 | }
|
---|
| 3829 | }
|
---|
[502] | 3830 | else
|
---|
| 3831 | {
|
---|
| 3832 | perror("recv");
|
---|
| 3833 | exit(1);
|
---|
| 3834 | }
|
---|
[27] | 3835 | }
|
---|
| 3836 | else
|
---|
| 3837 | {
|
---|
[502] | 3838 | if(connect(sockfd, (struct sockaddr *)&their_addr,
|
---|
| 3839 | sizeof(struct sockaddr)) == -1)
|
---|
[27] | 3840 | {
|
---|
[502] | 3841 | perror("connect");
|
---|
| 3842 | exit(1);
|
---|
[27] | 3843 | }
|
---|
[502] | 3844 | if(!args.data)
|
---|
| 3845 | {
|
---|
| 3846 | i = snprintf(buf, MAXDATASIZE,
|
---|
| 3847 | "GET %s%s%s%s/ HTTP/1.0\r\n"
|
---|
| 3848 | "Host: %s\r\n%s"
|
---|
| 3849 | "User-Agent: %s/%s\r\n"
|
---|
[646] | 3850 | "Connection: close\r\n"
|
---|
[502] | 3851 | "\r\n"
|
---|
| 3852 | , proxyserver ? "http://" : "", proxyserver ? proxyserver : "",
|
---|
| 3853 | proxyserver ? ":" : "", proxyserver ? proxyport : "",
|
---|
| 3854 | args.server, args.mode == NTRIP1 ? "" : "Ntrip-Version: Ntrip/2.0\r\n",
|
---|
| 3855 | AGENTSTRING, revisionstr);
|
---|
| 3856 | }
|
---|
| 3857 | else
|
---|
| 3858 | {
|
---|
| 3859 | i=snprintf(buf, MAXDATASIZE-40, /* leave some space for login */
|
---|
| 3860 | "GET %s%s%s%s/%s HTTP/1.0\r\n"
|
---|
| 3861 | "Host: %s\r\n%s"
|
---|
| 3862 | "User-Agent: %s/%s\r\n"
|
---|
[646] | 3863 | "Connection: close\r\n"
|
---|
[502] | 3864 | "Authorization: Basic "
|
---|
| 3865 | , proxyserver ? "http://" : "", proxyserver ? proxyserver : "",
|
---|
| 3866 | proxyserver ? ":" : "", proxyserver ? proxyport : "",
|
---|
| 3867 | args.data, args.server,
|
---|
| 3868 | args.mode == NTRIP1 ? "" : "Ntrip-Version: Ntrip/2.0\r\n",
|
---|
| 3869 | AGENTSTRING, revisionstr);
|
---|
| 3870 | if(i > MAXDATASIZE-40 || i < 0) /* second check for old glibc */
|
---|
| 3871 | {
|
---|
| 3872 | RTCM3Error("Requested data too long\n");
|
---|
| 3873 | exit(1);
|
---|
| 3874 | }
|
---|
| 3875 | i += encode(buf+i, MAXDATASIZE-i-4, args.user, args.password);
|
---|
| 3876 | if(i > MAXDATASIZE-4)
|
---|
| 3877 | {
|
---|
| 3878 | RTCM3Error("Username and/or password too long\n");
|
---|
| 3879 | exit(1);
|
---|
| 3880 | }
|
---|
| 3881 | buf[i++] = '\r';
|
---|
| 3882 | buf[i++] = '\n';
|
---|
| 3883 | buf[i++] = '\r';
|
---|
| 3884 | buf[i++] = '\n';
|
---|
| 3885 | if(args.nmea)
|
---|
| 3886 | {
|
---|
| 3887 | int j = snprintf(buf+i, MAXDATASIZE-i, "%s\r\n", args.nmea);
|
---|
| 3888 | if(j >= 0 && j < MAXDATASIZE-i)
|
---|
| 3889 | i += j;
|
---|
| 3890 | else
|
---|
| 3891 | {
|
---|
| 3892 | RTCM3Error("NMEA string too long\n");
|
---|
| 3893 | exit(1);
|
---|
| 3894 | }
|
---|
| 3895 | }
|
---|
| 3896 | }
|
---|
| 3897 | if(send(sockfd, buf, (size_t)i, 0) != i)
|
---|
| 3898 | {
|
---|
| 3899 | perror("send");
|
---|
| 3900 | exit(1);
|
---|
| 3901 | }
|
---|
| 3902 | if(args.data)
|
---|
| 3903 | {
|
---|
| 3904 | int k = 0;
|
---|
| 3905 | int chunkymode = 0;
|
---|
| 3906 | int totalbytes = 0;
|
---|
| 3907 | int chunksize = 0;
|
---|
| 3908 |
|
---|
| 3909 | while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) != -1)
|
---|
| 3910 | {
|
---|
[1091] | 3911 | if(numbytes > 0)
|
---|
| 3912 | alarm(ALARMTIME);
|
---|
| 3913 | else
|
---|
| 3914 | {
|
---|
| 3915 | WaitMicro(100);
|
---|
| 3916 | continue;
|
---|
| 3917 | }
|
---|
[502] | 3918 | if(!k)
|
---|
| 3919 | {
|
---|
| 3920 | if(numbytes > 17 && (!strncmp(buf, "HTTP/1.1 200 OK\r\n", 17)
|
---|
| 3921 | || !strncmp(buf, "HTTP/1.0 200 OK\r\n", 17)))
|
---|
[744] | 3922 | {
|
---|
[502] | 3923 | const char *datacheck = "Content-Type: gnss/data\r\n";
|
---|
| 3924 | const char *chunkycheck = "Transfer-Encoding: chunked\r\n";
|
---|
| 3925 | int l = strlen(datacheck)-1;
|
---|
| 3926 | int j=0;
|
---|
| 3927 | for(i = 0; j != l && i < numbytes-l; ++i)
|
---|
| 3928 | {
|
---|
| 3929 | for(j = 0; j < l && buf[i+j] == datacheck[j]; ++j)
|
---|
| 3930 | ;
|
---|
| 3931 | }
|
---|
| 3932 | if(i == numbytes-l)
|
---|
| 3933 | {
|
---|
| 3934 | RTCM3Error("No 'Content-Type: gnss/data' found\n");
|
---|
| 3935 | exit(1);
|
---|
| 3936 | }
|
---|
| 3937 | l = strlen(chunkycheck)-1;
|
---|
| 3938 | j=0;
|
---|
| 3939 | for(i = 0; j != l && i < numbytes-l; ++i)
|
---|
| 3940 | {
|
---|
| 3941 | for(j = 0; j < l && buf[i+j] == chunkycheck[j]; ++j)
|
---|
| 3942 | ;
|
---|
| 3943 | }
|
---|
| 3944 | if(i < numbytes-l)
|
---|
| 3945 | chunkymode = 1;
|
---|
[1091] | 3946 | }
|
---|
[502] | 3947 | else if(numbytes < 12 || strncmp("ICY 200 OK\r\n", buf, 12))
|
---|
| 3948 | {
|
---|
| 3949 | RTCM3Error("Could not get the requested data: ");
|
---|
| 3950 | for(k = 0; k < numbytes && buf[k] != '\n' && buf[k] != '\r'; ++k)
|
---|
| 3951 | {
|
---|
| 3952 | RTCM3Error("%c", isprint(buf[k]) ? buf[k] : '.');
|
---|
| 3953 | }
|
---|
| 3954 | RTCM3Error("\n");
|
---|
| 3955 | exit(1);
|
---|
| 3956 | }
|
---|
| 3957 | else if(args.mode != NTRIP1)
|
---|
| 3958 | {
|
---|
| 3959 | if(args.mode != AUTO)
|
---|
| 3960 | {
|
---|
| 3961 | RTCM3Error("NTRIP version 2 HTTP connection failed%s.\n",
|
---|
| 3962 | args.mode == AUTO ? ", falling back to NTRIP1" : "");
|
---|
| 3963 | }
|
---|
| 3964 | if(args.mode == HTTP)
|
---|
| 3965 | exit(1);
|
---|
| 3966 | }
|
---|
| 3967 | ++k;
|
---|
| 3968 | }
|
---|
| 3969 | else
|
---|
| 3970 | {
|
---|
| 3971 | if(chunkymode)
|
---|
| 3972 | {
|
---|
| 3973 | int stop = 0;
|
---|
| 3974 | int pos = 0;
|
---|
| 3975 | while(!stop && pos < numbytes)
|
---|
| 3976 | {
|
---|
| 3977 | switch(chunkymode)
|
---|
| 3978 | {
|
---|
| 3979 | case 1: /* reading number starts */
|
---|
| 3980 | chunksize = 0;
|
---|
| 3981 | ++chunkymode; /* no break */
|
---|
| 3982 | case 2: /* during reading number */
|
---|
| 3983 | i = buf[pos++];
|
---|
| 3984 | if(i >= '0' && i <= '9') chunksize = chunksize*16+i-'0';
|
---|
| 3985 | else if(i >= 'a' && i <= 'f') chunksize = chunksize*16+i-'a'+10;
|
---|
| 3986 | else if(i >= 'A' && i <= 'F') chunksize = chunksize*16+i-'A'+10;
|
---|
| 3987 | else if(i == '\r') ++chunkymode;
|
---|
[646] | 3988 | else if(i == ';') chunkymode = 5;
|
---|
[502] | 3989 | else stop = 1;
|
---|
| 3990 | break;
|
---|
| 3991 | case 3: /* scanning for return */
|
---|
| 3992 | if(buf[pos++] == '\n') chunkymode = chunksize ? 4 : 1;
|
---|
| 3993 | else stop = 1;
|
---|
| 3994 | break;
|
---|
| 3995 | case 4: /* output data */
|
---|
| 3996 | i = numbytes-pos;
|
---|
| 3997 | if(i > chunksize) i = chunksize;
|
---|
| 3998 | {
|
---|
| 3999 | int z;
|
---|
| 4000 | for(z = 0; z < i && !stop; ++z)
|
---|
| 4001 | HandleByte(&Parser, (unsigned int) buf[pos+z]);
|
---|
| 4002 | }
|
---|
| 4003 | totalbytes += i;
|
---|
| 4004 | chunksize -= i;
|
---|
| 4005 | pos += i;
|
---|
| 4006 | if(!chunksize)
|
---|
| 4007 | chunkymode = 1;
|
---|
| 4008 | break;
|
---|
[646] | 4009 | case 5:
|
---|
| 4010 | if(i == '\r') chunkymode = 3;
|
---|
| 4011 | break;
|
---|
[502] | 4012 | }
|
---|
| 4013 | }
|
---|
| 4014 | if(stop)
|
---|
| 4015 | {
|
---|
| 4016 | RTCM3Error("Error in chunky transfer encoding\n");
|
---|
| 4017 | break;
|
---|
| 4018 | }
|
---|
| 4019 | }
|
---|
| 4020 | else
|
---|
| 4021 | {
|
---|
| 4022 | totalbytes += numbytes;
|
---|
| 4023 | {
|
---|
| 4024 | int z;
|
---|
| 4025 | for(z = 0; z < numbytes && !stop; ++z)
|
---|
| 4026 | HandleByte(&Parser, (unsigned int) buf[z]);
|
---|
| 4027 | }
|
---|
| 4028 | }
|
---|
| 4029 | if(totalbytes < 0) /* overflow */
|
---|
| 4030 | {
|
---|
| 4031 | totalbytes = 0;
|
---|
| 4032 | }
|
---|
| 4033 | }
|
---|
| 4034 | }
|
---|
| 4035 | }
|
---|
| 4036 | else
|
---|
| 4037 | {
|
---|
| 4038 | while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) > 0)
|
---|
| 4039 | {
|
---|
| 4040 | alarm(ALARMTIME);
|
---|
| 4041 | fwrite(buf, (size_t)numbytes, 1, stdout);
|
---|
| 4042 | }
|
---|
| 4043 | }
|
---|
| 4044 | close(sockfd);
|
---|
[27] | 4045 | }
|
---|
| 4046 | }
|
---|
| 4047 | return 0;
|
---|
| 4048 | }
|
---|
[268] | 4049 | #endif /* NO_RTCM3_MAIN */
|
---|