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

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

fix #4 - patch by johansen - allow external specification of data types

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