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