source: ntrip/trunk/rtcm3torinex/rtcm3torinex.h@ 2346

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

updated

File size: 10.4 KB
Line 
1#ifndef RTCM3TORINEX_H
2#define RTCM3TORINEX_H
3
4/*
5 Converter for RTCM3 data to RINEX.
6 $Id: rtcm3torinex.h,v 1.19 2010/01/12 12:13:23 mervart Exp $
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#include <stdio.h>
26
27#define PRN_GPS_START 1
28#define PRN_GPS_END 32
29#define PRN_GLONASS_START 38
30#define PRN_GLONASS_END 61
31#define PRN_WAAS_START 120
32#define PRN_WAAS_END 138
33
34#define GNSSENTRY_C1DATA 0
35#define GNSSENTRY_C2DATA 1
36#define GNSSENTRY_P1DATA 2
37#define GNSSENTRY_P2DATA 3
38#define GNSSENTRY_L1CDATA 4
39#define GNSSENTRY_L1PDATA 5
40#define GNSSENTRY_L2CDATA 6
41#define GNSSENTRY_L2PDATA 7
42#define GNSSENTRY_D1CDATA 8
43#define GNSSENTRY_D1PDATA 9
44#define GNSSENTRY_D2CDATA 10
45#define GNSSENTRY_D2PDATA 11
46#define GNSSENTRY_S1CDATA 12
47#define GNSSENTRY_S1PDATA 13
48#define GNSSENTRY_S2CDATA 14
49#define GNSSENTRY_S2PDATA 15
50#define GNSSENTRY_NUMBER 16 /* number of types!!! */
51
52/* Data flags. These flags are used in the dataflags field of gpsdata structure
53 and are used the determine, which data fields are filled with valid data. */
54#define GNSSDF_C1DATA (1<<GNSSENTRY_C1DATA)
55#define GNSSDF_C2DATA (1<<GNSSENTRY_C2DATA)
56#define GNSSDF_P1DATA (1<<GNSSENTRY_P1DATA)
57#define GNSSDF_P2DATA (1<<GNSSENTRY_P2DATA)
58#define GNSSDF_L1CDATA (1<<GNSSENTRY_L1CDATA)
59#define GNSSDF_L1PDATA (1<<GNSSENTRY_L1PDATA)
60#define GNSSDF_L2CDATA (1<<GNSSENTRY_L2CDATA)
61#define GNSSDF_L2PDATA (1<<GNSSENTRY_L2PDATA)
62#define GNSSDF_D1CDATA (1<<GNSSENTRY_D1CDATA)
63#define GNSSDF_D1PDATA (1<<GNSSENTRY_D1PDATA)
64#define GNSSDF_D2CDATA (1<<GNSSENTRY_D2CDATA)
65#define GNSSDF_D2PDATA (1<<GNSSENTRY_D2PDATA)
66#define GNSSDF_S1CDATA (1<<GNSSENTRY_S1CDATA)
67#define GNSSDF_S1PDATA (1<<GNSSENTRY_S1PDATA)
68#define GNSSDF_S2CDATA (1<<GNSSENTRY_S2CDATA)
69#define GNSSDF_S2PDATA (1<<GNSSENTRY_S2PDATA)
70
71#define RINEXENTRY_C1DATA 0
72#define RINEXENTRY_C2DATA 1
73#define RINEXENTRY_P1DATA 2
74#define RINEXENTRY_P2DATA 3
75#define RINEXENTRY_L1DATA 4
76#define RINEXENTRY_L2DATA 5
77#define RINEXENTRY_D1DATA 6
78#define RINEXENTRY_D2DATA 7
79#define RINEXENTRY_S1DATA 8
80#define RINEXENTRY_S2DATA 9
81#define RINEXENTRY_NUMBER 10
82
83#define LIGHTSPEED 2.99792458e8 /* m/sec */
84#define GPS_FREQU_L1 1575420000.0 /* Hz */
85#define GPS_FREQU_L2 1227600000.0 /* Hz */
86#define GPS_WAVELENGTH_L1 (LIGHTSPEED / GPS_FREQU_L1) /* m */
87#define GPS_WAVELENGTH_L2 (LIGHTSPEED / GPS_FREQU_L2) /* m */
88
89#define GLO_FREQU_L1_BASE 1602000000.0 /* Hz */
90#define GLO_FREQU_L2_BASE 1246000000.0 /* Hz */
91#define GLO_FREQU_L1_STEP 562500.0 /* Hz */
92#define GLO_FREQU_L2_STEP 437500.0 /* Hz */
93#define GLO_FREQU_L1(a) (GLO_FREQU_L1_BASE+(a)*GLO_FREQU_L1_STEP)
94#define GLO_FREQU_L2(a) (GLO_FREQU_L2_BASE+(a)*GLO_FREQU_L2_STEP)
95#define GLO_WAVELENGTH_L1(a) (LIGHTSPEED / GLO_FREQU_L1(a)) /* m */
96#define GLO_WAVELENGTH_L2(a) (LIGHTSPEED / GLO_FREQU_L2(a)) /* m */
97
98/* Additional flags for the data field, which tell us more. */
99#define GNSSDF_LOCKLOSSL1 (1<<29) /* lost lock on L1 */
100#define GNSSDF_LOCKLOSSL2 (1<<30) /* lost lock on L2 */
101
102struct converttimeinfo {
103 int second; /* seconds of GPS time [0..59] */
104 int minute; /* minutes of GPS time [0..59] */
105 int hour; /* hour of GPS time [0..24] */
106 int day; /* day of GPS time [1..28..30(31)*/
107 int month; /* month of GPS time [1..12]*/
108 int year; /* year of GPS time [1980..] */
109};
110
111struct gnssdata {
112 int flags; /* GPSF_xxx */
113 int week; /* week number of GPS date */
114 int numsats;
115 double timeofweek; /* milliseconds in GPS week */
116 double measdata[24][GNSSENTRY_NUMBER]; /* data fields */
117 int dataflags[24]; /* GPSDF_xxx */
118 int satellites[24]; /* SV - IDs */
119 int channels[24]; /* Glonass channels - valid of Glonass SV only */
120 int snrL1[24]; /* Important: all the 5 SV-specific fields must */
121 int snrL2[24]; /* have the same SV-order */
122};
123
124#define GPSEPHF_L2PCODEDATA (1<<0) /* set, if NAV data OFF on L2 P-code, s1w4b01 */
125#define GPSEPHF_L2PCODE (1<<1) /* set, if P-code available, s1w3b12 */
126#define GPSEPHF_L2CACODE (1<<2) /* set, if CA-code available, s1w3b11 */
127#define GPSEPHF_VALIDATED (1<<3) /* data is completely valid */
128
129#define R2R_PI 3.1415926535898
130
131struct gpsephemeris {
132 int flags; /* GPSEPHF_xxx */
133 int satellite; /* SV ID ICD-GPS data position */
134 int IODE; /* [s2w3b01-08] */
135 int URAindex; /* [1..15] [s1w3b13-16] */
136 int SVhealth; /* [s1w3b17-22] */
137 int GPSweek; /* [s1w3b01-10] */
138 int IODC; /* [s1w3b23-32,w8b01-08] */
139 int TOW; /* [s] [s1w2b01-17] */
140 int TOC; /* [s] [s1w8b09-24] */
141 int TOE; /* [s] [s2w10b1-16] */
142 double clock_bias; /* [s] [s1w10b1-22, af0] */
143 double clock_drift; /* [s/s] [s1w9b09-24, af1] */
144 double clock_driftrate; /* [s/s^2] [s1w9b01-08, af2] */
145 double Crs; /* [m] [s2w3b09-24] */
146 double Delta_n; /* [rad/s] [s2w4b01-16 * Pi] */
147 double M0; /* [rad] [s2w4b17-24,w5b01-24 * Pi]*/
148 double Cuc; /* [rad] [s2w6b01-16] */
149 double e; /* [s2w6b17-24,w6b01-24] */
150 double Cus; /* [rad] [s2w8b01-16] */
151 double sqrt_A; /* [m^0.5] [s2w8b16-24,w9b01-24] */
152 double Cic; /* [rad] [s3w3b01-16] */
153 double OMEGA0; /* [rad] [s3w3b17-24,w4b01-24 * Pi]*/
154 double Cis; /* [rad] [s3w5b01-16] */
155 double i0; /* [rad] [s3w5b17-24,w6b01-24 * Pi]*/
156 double Crc; /* [m] [s3w701-16] */
157 double omega; /* [rad] [s3w7b17-24,w8b01-24 * Pi]*/
158 double OMEGADOT; /* [rad/s] [s3w9b01-24 * Pi] */
159 double IDOT; /* [rad/s] [s3w10b9-22 * Pi] */
160 double TGD; /* [s] [s1w7b17-24] */
161};
162
163#define GLOEPHF_UNHEALTHY (1<<0) /* set if unhealty satellite, f2b78 */
164#define GLOEPHF_ALMANACHEALTHOK (1<<1) /* set if ALM health is available */
165#define GLOEPHF_ALMANACHEALTHY (1<<2) /* set if Cn word is true */
166#define GLOEPHF_PAVAILABLE (1<<3) /* set if the 3 P flags are available */
167#define GLOEPHF_P10TRUE (1<<4)
168#define GLOEPHF_P11TRUE (1<<5)
169#define GLOEPHF_P2TRUE (1<<6)
170#define GLOEPHF_P3TRUE (1<<7)
171
172struct glonassephemeris {
173 int GPSWeek;
174 int GPSTOW;
175 int flags; /* GLOEPHF_xxx */
176 int almanac_number;
177 int frequency_number; /* ICD-GLONASS data position */
178 int tb; /* [s] [f2b70-76] */
179 int tk; /* [s] [f1b65-76] */
180 int E; /* [days] [f4b49-53] */
181 double tau; /* [s] [f4b59-80] */
182 double gamma; /* [f3b69-79] */
183 double x_pos; /* [km] [f1b09-35] */
184 double x_velocity; /* [km/s] [f1b41-64] */
185 double x_acceleration; /* [km/s^2][f1b36-40] */
186 double y_pos; /* [km] [f2b09-35] */
187 double y_velocity; /* [km/s] [f2b41-64] */
188 double y_acceleration; /* [km/s^2][f2b36-40] */
189 double z_pos; /* [km] [f3b09-35] */
190 double z_velocity; /* [km/s] [f3b41-64] */
191 double z_acceleration; /* [km/s^2][f3b36-40] */
192};
193
194struct RTCM3ParserData {
195 unsigned char Message[2048]; /* input-buffer */
196 int MessageSize; /* current buffer size */
197 int NeedBytes; /* bytes wanted for next run */
198 int SkipBytes; /* bytes to skip in next round */
199 int GPSWeek;
200 int GPSTOW; /* in seconds */
201 struct gnssdata Data;
202 struct gpsephemeris ephemerisGPS;
203 struct glonassephemeris ephemerisGLONASS;
204 struct gnssdata DataNew;
205 int size;
206 int lastlockl1[64];
207 int lastlockl2[64];
208#ifdef NO_RTCM3_MAIN
209 double antX;
210 double antY;
211 double antZ;
212 double antH;
213 char antenna[256+1];
214 int blocktype;
215#endif /* NO_RTCM3_MAIN */
216 int datapos[RINEXENTRY_NUMBER];
217 int dataflag[RINEXENTRY_NUMBER];
218 /* for RINEX2 GPS and GLO are both handled in GPS */
219 int dataposGPS[RINEXENTRY_NUMBER]; /* SBAS has same entries */
220 int dataflagGPS[RINEXENTRY_NUMBER];
221 int dataposGLO[RINEXENTRY_NUMBER]; /* only used for RINEX3 */
222 int dataflagGLO[RINEXENTRY_NUMBER];
223 int numdatatypesGPS;
224 int numdatatypesGLO; /* only used for RINEX3 */
225 int validwarning;
226 int init;
227 int startflags;
228 int rinex3;
229 const char * headerfile;
230 const char * glonassephemeris;
231 const char * gpsephemeris;
232 FILE *glonassfile;
233 FILE *gpsfile;
234};
235
236#ifndef PRINTFARG
237#ifdef __GNUC__
238#define PRINTFARG(a,b) __attribute__ ((format(printf, a, b)))
239#else /* __GNUC__ */
240#define PRINTFARG(a,b)
241#endif /* __GNUC__ */
242#endif /* PRINTFARG */
243
244int gnumleap(int year, int month, int day);
245void updatetime(int *week, int *tow, int tk, int fixnumleap);
246void converttime(struct converttimeinfo *c, int week, int tow);
247
248void HandleHeader(struct RTCM3ParserData *Parser);
249int RTCM3Parser(struct RTCM3ParserData *handle);
250void HandleByte(struct RTCM3ParserData *Parser, unsigned int byte);
251void PRINTFARG(1,2) RTCM3Error(const char *fmt, ...);
252void PRINTFARG(1,2) RTCM3Text(const char *fmt, ...);
253
254#endif /* RTCM3TORINEX_H */
Note: See TracBrowser for help on using the repository browser.