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

Last change on this file since 2659 was 2659, checked in by stoecker, 13 years ago

first test of MSM messages

  • Property svn:keywords set to Id
File size: 14.2 KB
Line 
1#ifndef RTCM3TORINEX_H
2#define RTCM3TORINEX_H
3
4/*
5 Converter for RTCM3 data to RINEX.
6 $Id: rtcm3torinex.h 2659 2010-11-09 13:50:16Z 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 24
46#define RTCM3_MSM_NUMSAT 40
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 channels[GNSS_MAXSATS]; /* Glonass channels - valid of Glonass SV only */
216 int snrL1[GNSS_MAXSATS]; /* Important: all the 5 SV-specific fields must */
217 int snrL2[GNSS_MAXSATS]; /* have the same SV-order */
218};
219
220#define GPSEPHF_L2PCODEDATA (1<<0) /* set, if NAV data OFF on L2 P-code, s1w4b01 */
221#define GPSEPHF_L2PCODE (1<<1) /* set, if P-code available, s1w3b12 */
222#define GPSEPHF_L2CACODE (1<<2) /* set, if CA-code available, s1w3b11 */
223#define GPSEPHF_VALIDATED (1<<3) /* data is completely valid */
224
225#define R2R_PI 3.1415926535898
226
227struct gpsephemeris {
228 int flags; /* GPSEPHF_xxx */
229 int satellite; /* SV ID ICD-GPS data position */
230 int IODE; /* [s2w3b01-08] */
231 int URAindex; /* [1..15] [s1w3b13-16] */
232 int SVhealth; /* [s1w3b17-22] */
233 int GPSweek; /* [s1w3b01-10] */
234 int IODC; /* [s1w3b23-32,w8b01-08] */
235 int TOW; /* [s] [s1w2b01-17] */
236 int TOC; /* [s] [s1w8b09-24] */
237 int TOE; /* [s] [s2w10b1-16] */
238 double clock_bias; /* [s] [s1w10b1-22, af0] */
239 double clock_drift; /* [s/s] [s1w9b09-24, af1] */
240 double clock_driftrate; /* [s/s^2] [s1w9b01-08, af2] */
241 double Crs; /* [m] [s2w3b09-24] */
242 double Delta_n; /* [rad/s] [s2w4b01-16 * Pi] */
243 double M0; /* [rad] [s2w4b17-24,w5b01-24 * Pi]*/
244 double Cuc; /* [rad] [s2w6b01-16] */
245 double e; /* [s2w6b17-24,w6b01-24] */
246 double Cus; /* [rad] [s2w8b01-16] */
247 double sqrt_A; /* [m^0.5] [s2w8b16-24,w9b01-24] */
248 double Cic; /* [rad] [s3w3b01-16] */
249 double OMEGA0; /* [rad] [s3w3b17-24,w4b01-24 * Pi]*/
250 double Cis; /* [rad] [s3w5b01-16] */
251 double i0; /* [rad] [s3w5b17-24,w6b01-24 * Pi]*/
252 double Crc; /* [m] [s3w701-16] */
253 double omega; /* [rad] [s3w7b17-24,w8b01-24 * Pi]*/
254 double OMEGADOT; /* [rad/s] [s3w9b01-24 * Pi] */
255 double IDOT; /* [rad/s] [s3w10b9-22 * Pi] */
256 double TGD; /* [s] [s1w7b17-24] */
257};
258
259#define GLOEPHF_UNHEALTHY (1<<0) /* set if unhealty satellite, f2b78 */
260#define GLOEPHF_ALMANACHEALTHOK (1<<1) /* set if ALM health is available */
261#define GLOEPHF_ALMANACHEALTHY (1<<2) /* set if Cn word is true */
262#define GLOEPHF_PAVAILABLE (1<<3) /* set if the 3 P flags are available */
263#define GLOEPHF_P10TRUE (1<<4)
264#define GLOEPHF_P11TRUE (1<<5)
265#define GLOEPHF_P2TRUE (1<<6)
266#define GLOEPHF_P3TRUE (1<<7)
267
268struct glonassephemeris {
269 int GPSWeek;
270 int GPSTOW;
271 int flags; /* GLOEPHF_xxx */
272 int almanac_number;
273 int frequency_number; /* ICD-GLONASS data position */
274 int tb; /* [s] [f2b70-76] */
275 int tk; /* [s] [f1b65-76] */
276 int E; /* [days] [f4b49-53] */
277 double tau; /* [s] [f4b59-80] */
278 double gamma; /* [f3b69-79] */
279 double x_pos; /* [km] [f1b09-35] */
280 double x_velocity; /* [km/s] [f1b41-64] */
281 double x_acceleration; /* [km/s^2][f1b36-40] */
282 double y_pos; /* [km] [f2b09-35] */
283 double y_velocity; /* [km/s] [f2b41-64] */
284 double y_acceleration; /* [km/s^2][f2b36-40] */
285 double z_pos; /* [km] [f3b09-35] */
286 double z_velocity; /* [km/s] [f3b41-64] */
287 double z_acceleration; /* [km/s^2][f3b36-40] */
288};
289
290struct RTCM3ParserData {
291 unsigned char Message[2048]; /* input-buffer */
292 int MessageSize; /* current buffer size */
293 int NeedBytes; /* bytes wanted for next run */
294 int SkipBytes; /* bytes to skip in next round */
295 int GPSWeek;
296 int GPSTOW; /* in seconds */
297 struct gnssdata Data;
298 struct gpsephemeris ephemerisGPS;
299 struct glonassephemeris ephemerisGLONASS;
300 struct gnssdata DataNew;
301 int GLOFreq[PRN_GLONASS_NUM]; /* frequency numbers of GLONASS + 100 */
302 int size;
303 int lastlockGPSl1[64];
304 int lastlockGPSl2[64];
305 int lastlockGLOl1[64];
306 int lastlockGLOl2[64];
307 int lastlockmsm[RTCM3_MSM_NUMCELLS][NUMRTCM3PARSERSATS];
308#ifdef NO_RTCM3_MAIN
309 double antX;
310 double antY;
311 double antZ;
312 double antH;
313 char antenna[256+1];
314 int blocktype;
315 int allflags;
316 int modjulday;
317 int secofday;
318 int leapsec;
319#endif /* NO_RTCM3_MAIN */
320 int datapos[RINEXENTRY_NUMBER];
321 int dataflag[RINEXENTRY_NUMBER];
322 /* for RINEX2 GPS and GLO are both handled in GPS */
323 int dataposGPS[RINEXENTRY_NUMBER]; /* SBAS has same entries */
324 int dataflagGPS[RINEXENTRY_NUMBER];
325 int dataposGLO[RINEXENTRY_NUMBER]; /* only used for RINEX3 */
326 int dataflagGLO[RINEXENTRY_NUMBER];
327 int numdatatypesGPS;
328 int numdatatypesGLO; /* only used for RINEX3 */
329 int validwarning;
330 int init;
331 int startflags;
332 int rinex3;
333 const char * headerfile;
334 const char * glonassephemeris;
335 const char * gpsephemeris;
336 FILE *glonassfile;
337 FILE *gpsfile;
338};
339
340#ifndef PRINTFARG
341#ifdef __GNUC__
342#define PRINTFARG(a,b) __attribute__ ((format(printf, a, b)))
343#else /* __GNUC__ */
344#define PRINTFARG(a,b)
345#endif /* __GNUC__ */
346#endif /* PRINTFARG */
347
348int gnumleap(int year, int month, int day);
349void updatetime(int *week, int *tow, int tk, int fixnumleap);
350void converttime(struct converttimeinfo *c, int week, int tow);
351
352void HandleHeader(struct RTCM3ParserData *Parser);
353int RTCM3Parser(struct RTCM3ParserData *handle);
354void HandleByte(struct RTCM3ParserData *Parser, unsigned int byte);
355void PRINTFARG(1,2) RTCM3Error(const char *fmt, ...);
356void PRINTFARG(1,2) RTCM3Text(const char *fmt, ...);
357
358#endif /* RTCM3TORINEX_H */
Note: See TracBrowser for help on using the repository browser.