source: ntrip/trunk/rtcm3torinex/lib/rtcm3torinex.h@ 3256

Last change on this file since 3256 was 2849, checked in by stoecker, 14 years ago

fix doppler, switch to larger fields

  • Property svn:keywords set to Id
File size: 15.4 KB
Line 
1#ifndef RTCM3TORINEX_H
2#define RTCM3TORINEX_H
3
4/*
5 Converter for RTCM3 data to RINEX.
6 $Id: rtcm3torinex.h 2849 2011-01-17 13:40:00Z stoecker $
7 Copyright (C) 2005-2006 by Dirk Stöcker <stoecker@alberding.eu>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 or read http://www.gnu.org/licenses/gpl.txt
23*/
24
25#define RTCM3TORINEX_VERSION "1.50"
26
27#include <stdio.h>
28
29#define NUMRTCM3PARSERSATS 144
30#define GNSS_MAXSATS 64
31
32#define PRN_GPS_START 1
33#define PRN_GPS_END 32
34#define PRN_GLONASS_START 38
35#define PRN_GLONASS_END 61
36#define PRN_GALILEO_START 71
37#define PRN_GALILEO_END 100
38#define PRN_WAAS_START 120
39#define PRN_WAAS_END 138
40#define PRN_GIOVE_START 139
41#define PRN_GIOVE_END 140
42
43#define PRN_GLONASS_NUM (PRN_GLONASS_END-PRN_GLONASS_START+1)
44
45#define RTCM3_MSM_NUMSIG 32
46#define RTCM3_MSM_NUMSAT 64
47#define RTCM3_MSM_NUMCELLS 64
48
49/* system identifiers, use start PRN as value */
50#define RTCM3_MSM_GPS PRN_GPS_START
51#define RTCM3_MSM_GLONASS PRN_GLONASS_START
52#define RTCM3_MSM_GALILEO PRN_GALILEO_START
53
54#define GNSSENTRY_C1DATA 0
55#define GNSSENTRY_C2DATA 1
56#define GNSSENTRY_P1DATA 2
57#define GNSSENTRY_P2DATA 3
58#define GNSSENTRY_L1CDATA 4
59#define GNSSENTRY_L1PDATA 5
60#define GNSSENTRY_L2CDATA 6
61#define GNSSENTRY_L2PDATA 7
62#define GNSSENTRY_D1CDATA 8
63#define GNSSENTRY_D1PDATA 9
64#define GNSSENTRY_D2CDATA 10
65#define GNSSENTRY_D2PDATA 11
66#define GNSSENTRY_S1CDATA 12
67#define GNSSENTRY_S1PDATA 13
68#define GNSSENTRY_S2CDATA 14
69#define GNSSENTRY_S2PDATA 15
70
71#define GNSSENTRY_C5DATA 16
72#define GNSSENTRY_L5DATA 17
73#define GNSSENTRY_D5DATA 18
74#define GNSSENTRY_S5DATA 19
75#define GNSSENTRY_C6DATA 20
76#define GNSSENTRY_L6DATA 21
77#define GNSSENTRY_D6DATA 22
78#define GNSSENTRY_S6DATA 23
79#define GNSSENTRY_C5BDATA 24
80#define GNSSENTRY_L5BDATA 25
81#define GNSSENTRY_D5BDATA 26
82#define GNSSENTRY_S5BDATA 27
83#define GNSSENTRY_C5ABDATA 28
84#define GNSSENTRY_L5ABDATA 29
85#define GNSSENTRY_D5ABDATA 30
86#define GNSSENTRY_S5ABDATA 31
87
88#define GNSSENTRY_NUMBER 32 /* number of types!!! */
89
90/* Data flags. These flags are used in the dataflags field of gpsdata structure
91 and are required to determine, which data fields are filled with valid data. */
92#define GNSSDF_C1DATA (1<<GNSSENTRY_C1DATA)
93#define GNSSDF_C2DATA (1<<GNSSENTRY_C2DATA)
94#define GNSSDF_P1DATA (1<<GNSSENTRY_P1DATA)
95#define GNSSDF_P2DATA (1<<GNSSENTRY_P2DATA)
96#define GNSSDF_L1CDATA (1<<GNSSENTRY_L1CDATA)
97#define GNSSDF_L1PDATA (1<<GNSSENTRY_L1PDATA)
98#define GNSSDF_L2CDATA (1<<GNSSENTRY_L2CDATA)
99#define GNSSDF_L2PDATA (1<<GNSSENTRY_L2PDATA)
100#define GNSSDF_D1CDATA (1<<GNSSENTRY_D1CDATA)
101#define GNSSDF_D1PDATA (1<<GNSSENTRY_D1PDATA)
102#define GNSSDF_D2CDATA (1<<GNSSENTRY_D2CDATA)
103#define GNSSDF_D2PDATA (1<<GNSSENTRY_D2PDATA)
104#define GNSSDF_S1CDATA (1<<GNSSENTRY_S1CDATA)
105#define GNSSDF_S1PDATA (1<<GNSSENTRY_S1PDATA)
106#define GNSSDF_S2CDATA (1<<GNSSENTRY_S2CDATA)
107#define GNSSDF_S2PDATA (1<<GNSSENTRY_S2PDATA)
108
109#define GNSSDF_C5DATA (1<<GNSSENTRY_C5DATA)
110#define GNSSDF_L5DATA (1<<GNSSENTRY_L5DATA)
111#define GNSSDF_D5DATA (1<<GNSSENTRY_D5DATA)
112#define GNSSDF_S5DATA (1<<GNSSENTRY_S5DATA)
113#define GNSSDF_C6DATA (1<<GNSSENTRY_C6DATA)
114#define GNSSDF_L6DATA (1<<GNSSENTRY_L6DATA)
115#define GNSSDF_D6DATA (1<<GNSSENTRY_D6DATA)
116#define GNSSDF_S6DATA (1<<GNSSENTRY_S6DATA)
117#define GNSSDF_C5BDATA (1<<GNSSENTRY_C5BDATA)
118#define GNSSDF_L5BDATA (1<<GNSSENTRY_L5BDATA)
119#define GNSSDF_D5BDATA (1<<GNSSENTRY_D5BDATA)
120#define GNSSDF_S5BDATA (1<<GNSSENTRY_S5BDATA)
121#define GNSSDF_C5ABDATA (1<<GNSSENTRY_C5ABDATA)
122#define GNSSDF_L5ABDATA (1<<GNSSENTRY_L5ABDATA)
123#define GNSSDF_D5ABDATA (1<<GNSSENTRY_D5ABDATA)
124#define GNSSDF_S5ABDATA (1<<GNSSENTRY_S5ABDATA)
125
126#define RINEXENTRY_C1DATA 0
127#define RINEXENTRY_C2DATA 1
128#define RINEXENTRY_P1DATA 2
129#define RINEXENTRY_P2DATA 3
130#define RINEXENTRY_L1DATA 4
131#define RINEXENTRY_L2DATA 5
132#define RINEXENTRY_D1DATA 6
133#define RINEXENTRY_D2DATA 7
134#define RINEXENTRY_S1DATA 8
135#define RINEXENTRY_S2DATA 9
136
137#define RINEXENTRY_C5DATA 10
138#define RINEXENTRY_L5DATA 11
139#define RINEXENTRY_D5DATA 12
140#define RINEXENTRY_S5DATA 13
141#define RINEXENTRY_C6DATA 14
142#define RINEXENTRY_L6DATA 15
143#define RINEXENTRY_D6DATA 16
144#define RINEXENTRY_S6DATA 17
145#define RINEXENTRY_C5BDATA 18
146#define RINEXENTRY_L5BDATA 19
147#define RINEXENTRY_D5BDATA 20
148#define RINEXENTRY_S5BDATA 21
149#define RINEXENTRY_C5ABDATA 22
150#define RINEXENTRY_L5ABDATA 23
151#define RINEXENTRY_D5ABDATA 24
152#define RINEXENTRY_S5ABDATA 25
153
154#define RINEXENTRY_NUMBER 26
155
156#define LIGHTSPEED 2.99792458e8 /* m/sec */
157#define GPS_FREQU_L1 1575420000.0 /* Hz */
158#define GPS_FREQU_L2 1227600000.0 /* Hz */
159#define GPS_FREQU_L5 1176450000.0 /* Hz */
160#define GPS_WAVELENGTH_L1 (LIGHTSPEED / GPS_FREQU_L1) /* m */
161#define GPS_WAVELENGTH_L2 (LIGHTSPEED / GPS_FREQU_L2) /* m */
162#define GPS_WAVELENGTH_L5 (LIGHTSPEED / GPS_FREQU_L5) /* m */
163
164#define GLO_FREQU_L1_BASE 1602000000.0 /* Hz */
165#define GLO_FREQU_L2_BASE 1246000000.0 /* Hz */
166#define GLO_FREQU_L1_STEP 562500.0 /* Hz */
167#define GLO_FREQU_L2_STEP 437500.0 /* Hz */
168#define GLO_FREQU_L1(a) (GLO_FREQU_L1_BASE+(a)*GLO_FREQU_L1_STEP)
169#define GLO_FREQU_L2(a) (GLO_FREQU_L2_BASE+(a)*GLO_FREQU_L2_STEP)
170#define GLO_WAVELENGTH_L1(a) (LIGHTSPEED / GLO_FREQU_L1(a)) /* m */
171#define GLO_WAVELENGTH_L2(a) (LIGHTSPEED / GLO_FREQU_L2(a)) /* m */
172
173#define GAL_FREQU_E1 1575420000.0 /* Hz */
174#define GAL_FREQU_E5A 1176450000.0 /* Hz */
175#define GAL_FREQU_E5AB 1197950000.0 /* Hz */
176#define GAL_FREQU_E5B 1207140000.0 /* Hz */
177#define GAL_FREQU_E6 1278750000.0 /* Hz */
178#define GAL_WAVELENGTH_E1 (LIGHTSPEED / GAL_FREQU_E1) /* m */
179#define GAL_WAVELENGTH_E5A (LIGHTSPEED / GAL_FREQU_E5A) /* m */
180#define GAL_WAVELENGTH_E5AB (LIGHTSPEED / GAL_FREQU_E5AB) /* m */
181#define GAL_WAVELENGTH_E5B (LIGHTSPEED / GAL_FREQU_E5B) /* m */
182#define GAL_WAVELENGTH_E6 (LIGHTSPEED / GAL_FREQU_E6) /* m */
183
184#define PRN_GIOVE_OFFSET 51
185
186/* Additional flags for the data field, which tell us more. */
187#define GNSSDF2_XCORRL2 (1<<0) /* cross-correlated L2 */
188#define GNSSDF2_LOCKLOSSL1 (1<<1) /* lost lock on L1 */
189#define GNSSDF2_LOCKLOSSL2 (1<<2) /* lost lock on L2 */
190#define GNSSDF2_LOCKLOSSL5 (1<<3) /* lost lock on L5 */
191#define GNSSDF2_LOCKLOSSE6 (1<<4) /* lost lock on E6 */
192#define GNSSDF2_LOCKLOSSE5B (1<<5) /* lost lock on E5B */
193#define GNSSDF2_LOCKLOSSE5AB (1<<6) /* lost lock on E5AB */
194
195#define UINT64(c) c ## ULL
196
197struct converttimeinfo {
198 int second; /* seconds of GPS time [0..59] */
199 int minute; /* minutes of GPS time [0..59] */
200 int hour; /* hour of GPS time [0..24] */
201 int day; /* day of GPS time [1..28..30(31)*/
202 int month; /* month of GPS time [1..12]*/
203 int year; /* year of GPS time [1980..] */
204};
205
206struct gnssdata {
207 int flags; /* GNSSF_xxx */
208 int week; /* week number of GPS date */
209 int numsats;
210 double timeofweek; /* milliseconds in GPS week */
211 double measdata[GNSS_MAXSATS][GNSSENTRY_NUMBER]; /* data fields */
212 unsigned int dataflags[GNSS_MAXSATS]; /* GNSSDF_xxx */
213 unsigned int dataflags2[GNSS_MAXSATS]; /* GNSSDF2_xxx */
214 int satellites[GNSS_MAXSATS]; /* SV - IDs */
215 int snrL1[GNSS_MAXSATS]; /* Important: all the 5 SV-specific fields must */
216 int snrL2[GNSS_MAXSATS]; /* have the same SV-order */
217};
218
219#define GPSEPHF_L2PCODEDATA (1<<0) /* set, if NAV data OFF on L2 P-code, s1w4b01 */
220#define GPSEPHF_L2PCODE (1<<1) /* set, if P-code available, s1w3b12 */
221#define GPSEPHF_L2CACODE (1<<2) /* set, if CA-code available, s1w3b11 */
222#define GPSEPHF_VALIDATED (1<<3) /* data is completely valid */
223
224#define R2R_PI 3.1415926535898
225
226struct gpsephemeris {
227 int flags; /* GPSEPHF_xxx */
228 int satellite; /* SV ID ICD-GPS data position */
229 int IODE; /* [s2w3b01-08] */
230 int URAindex; /* [1..15] [s1w3b13-16] */
231 int SVhealth; /* [s1w3b17-22] */
232 int GPSweek; /* [s1w3b01-10] */
233 int IODC; /* [s1w3b23-32,w8b01-08] */
234 int TOW; /* [s] [s1w2b01-17] */
235 int TOC; /* [s] [s1w8b09-24] */
236 int TOE; /* [s] [s2w10b1-16] */
237 double clock_bias; /* [s] [s1w10b1-22, af0] */
238 double clock_drift; /* [s/s] [s1w9b09-24, af1] */
239 double clock_driftrate; /* [s/s^2] [s1w9b01-08, af2] */
240 double Crs; /* [m] [s2w3b09-24] */
241 double Delta_n; /* [rad/s] [s2w4b01-16 * Pi] */
242 double M0; /* [rad] [s2w4b17-24,w5b01-24 * Pi]*/
243 double Cuc; /* [rad] [s2w6b01-16] */
244 double e; /* [s2w6b17-24,w6b01-24] */
245 double Cus; /* [rad] [s2w8b01-16] */
246 double sqrt_A; /* [m^0.5] [s2w8b16-24,w9b01-24] */
247 double Cic; /* [rad] [s3w3b01-16] */
248 double OMEGA0; /* [rad] [s3w3b17-24,w4b01-24 * Pi]*/
249 double Cis; /* [rad] [s3w5b01-16] */
250 double i0; /* [rad] [s3w5b17-24,w6b01-24 * Pi]*/
251 double Crc; /* [m] [s3w701-16] */
252 double omega; /* [rad] [s3w7b17-24,w8b01-24 * Pi]*/
253 double OMEGADOT; /* [rad/s] [s3w9b01-24 * Pi] */
254 double IDOT; /* [rad/s] [s3w10b9-22 * Pi] */
255 double TGD; /* [s] [s1w7b17-24] */
256};
257
258#define GALEPHF_E5ADINVALID (1<<0) /* E5aDVS set invalid */
259
260#define GLOEPHF_UNHEALTHY (1<<0) /* set if unhealty satellite, f2b78 */
261#define GLOEPHF_ALMANACHEALTHOK (1<<1) /* set if ALM health is available */
262#define GLOEPHF_ALMANACHEALTHY (1<<2) /* set if Cn word is true */
263#define GLOEPHF_PAVAILABLE (1<<3) /* set if the 3 P flags are available */
264#define GLOEPHF_P10TRUE (1<<4)
265#define GLOEPHF_P11TRUE (1<<5)
266#define GLOEPHF_P2TRUE (1<<6)
267#define GLOEPHF_P3TRUE (1<<7)
268
269struct glonassephemeris {
270 int GPSWeek;
271 int GPSTOW;
272 int flags; /* GLOEPHF_xxx */
273 int almanac_number;
274 int frequency_number; /* ICD-GLONASS data position */
275 int tb; /* [s] [f2b70-76] */
276 int tk; /* [s] [f1b65-76] */
277 int E; /* [days] [f4b49-53] */
278 double tau; /* [s] [f4b59-80] */
279 double gamma; /* [f3b69-79] */
280 double x_pos; /* [km] [f1b09-35] */
281 double x_velocity; /* [km/s] [f1b41-64] */
282 double x_acceleration; /* [km/s^2][f1b36-40] */
283 double y_pos; /* [km] [f2b09-35] */
284 double y_velocity; /* [km/s] [f2b41-64] */
285 double y_acceleration; /* [km/s^2][f2b36-40] */
286 double z_pos; /* [km] [f3b09-35] */
287 double z_velocity; /* [km/s] [f3b41-64] */
288 double z_acceleration; /* [km/s^2][f3b36-40] */
289};
290
291struct galileoephemeris {
292 int flags; /* GALEPHF_xxx */
293 int satellite; /* SV ID */
294 int IODnav;
295 int TOC; /* [s] */
296 int TOE; /* [s] */
297 double clock_bias; /* [s] */
298 double clock_drift; /* [s/s] */
299 double clock_driftrate; /* [s/s^2] */
300 double Crs; /* [m] */
301 double Delta_n; /* [rad/s] */
302 double M0; /* [rad] */
303 double Cuc; /* [rad] */
304 double e;
305 double Cus; /* [rad] */
306 double sqrt_A; /* [m^0.5] */
307 double Cic; /* [rad] */
308 double OMEGA0; /* [rad] */
309 double Cis; /* [rad] */
310 double i0; /* [rad] */
311 double Crc; /* [m] */
312 double omega; /* [rad] */
313 double OMEGADOT; /* [rad/s] */
314 double IDOT; /* [rad/s] */
315 double BGD_1_5A; /* [s] */
316 double BGD_1_5B; /* [s] */
317 int Week;
318 int SISA;
319 int E5aHS;
320};
321
322struct RTCM3ParserData {
323 unsigned char Message[2048]; /* input-buffer */
324 int MessageSize; /* current buffer size */
325 int NeedBytes; /* bytes wanted for next run */
326 int SkipBytes; /* bytes to skip in next round */
327 int GPSWeek;
328 int GPSTOW; /* in seconds */
329 struct gnssdata Data;
330 struct gpsephemeris ephemerisGPS;
331 struct galileoephemeris ephemerisGALILEO;
332 struct glonassephemeris ephemerisGLONASS;
333 struct gnssdata DataNew;
334 int GLOFreq[PRN_GLONASS_NUM]; /* frequency numbers of GLONASS + 100 */
335 int size;
336 int lastlockGPSl1[64];
337 int lastlockGPSl2[64];
338 int lastlockGLOl1[64];
339 int lastlockGLOl2[64];
340 int lastlockmsm[RTCM3_MSM_NUMCELLS][NUMRTCM3PARSERSATS];
341#ifdef NO_RTCM3_MAIN
342 double antX;
343 double antY;
344 double antZ;
345 double antH;
346 char antenna[256+1];
347 int blocktype;
348 int allflags;
349 int modjulday;
350 int secofday;
351 int leapsec;
352#endif /* NO_RTCM3_MAIN */
353 int datapos[RINEXENTRY_NUMBER];
354 int dataflag[RINEXENTRY_NUMBER];
355 /* for RINEX2 GPS and GLO are both handled in GPS */
356 int dataposGPS[RINEXENTRY_NUMBER]; /* SBAS has same entries */
357 int dataflagGPS[RINEXENTRY_NUMBER];
358 int dataposGLO[RINEXENTRY_NUMBER]; /* only used for RINEX3 */
359 int dataflagGLO[RINEXENTRY_NUMBER];
360 int dataposGAL[RINEXENTRY_NUMBER]; /* only used for RINEX3 */
361 int dataflagGAL[RINEXENTRY_NUMBER];
362 int numdatatypesGPS;
363 int numdatatypesGLO; /* only used for RINEX3 */
364 int numdatatypesGAL; /* only used for RINEX3 */
365 int validwarning;
366 int init;
367 int startflags;
368 int rinex3;
369 const char * headerfile;
370 const char * glonassephemeris;
371 const char * gpsephemeris;
372 FILE *glonassfile;
373 FILE *gpsfile;
374};
375
376#ifndef PRINTFARG
377#ifdef __GNUC__
378#define PRINTFARG(a,b) __attribute__ ((format(printf, a, b)))
379#else /* __GNUC__ */
380#define PRINTFARG(a,b)
381#endif /* __GNUC__ */
382#endif /* PRINTFARG */
383
384int gnumleap(int year, int month, int day);
385void updatetime(int *week, int *tow, int tk, int fixnumleap);
386void converttime(struct converttimeinfo *c, int week, int tow);
387
388void HandleHeader(struct RTCM3ParserData *Parser);
389int RTCM3Parser(struct RTCM3ParserData *handle);
390void HandleByte(struct RTCM3ParserData *Parser, unsigned int byte);
391void PRINTFARG(1,2) RTCM3Error(const char *fmt, ...);
392void PRINTFARG(1,2) RTCM3Text(const char *fmt, ...);
393
394#endif /* RTCM3TORINEX_H */
Note: See TracBrowser for help on using the repository browser.