GNSS-SDR  0.0.14
An Open Source GNSS Software Defined Receiver
rtklib_rtkcmn.h
Go to the documentation of this file.
1 /*!
2  * \file rtklib_rtkcmn.h
3  * \brief rtklib common functions
4  * \authors <ul>
5  * <li> 2007-2013, T. Takasu
6  * <li> 2017, Javier Arribas
7  * <li> 2017, Carles Fernandez
8  * </ul>
9  *
10  * This is a derived work from RTKLIB http://www.rtklib.com/
11  * The original source code at https://github.com/tomojitakasu/RTKLIB is
12  * released under the BSD 2-clause license with an additional exclusive clause
13  * that does not apply here. This additional clause is reproduced below:
14  *
15  * " The software package includes some companion executive binaries or shared
16  * libraries necessary to execute APs on Windows. These licenses succeed to the
17  * original ones of these software. "
18  *
19  * Neither the executive binaries nor the shared libraries are required by, used
20  * or included in GNSS-SDR.
21  *
22  * -----------------------------------------------------------------------------
23  * Copyright (C) 2007-2013, T. Takasu
24  * Copyright (C) 2017, Javier Arribas
25  * Copyright (C) 2017, Carles Fernandez
26  * All rights reserved.
27  *
28  * SPDX-License-Identifier: BSD-2-Clause
29  *
30  *
31  * References :
32  * [1] IS-GPS-200K, Navstar GPS Space Segment/Navigation User Interfaces,
33  * 7 March, 2006
34  * [2] RTCA/DO-229C, Minimum operational performanc standards for global
35  * positioning system/wide area augmentation system airborne equipment,
36  * RTCA inc, November 28, 2001
37  * [3] M.Rothacher, R.Schmid, ANTEX: The Antenna Exchange Format Version 1.4,
38  * 15 September, 2010
39  * [4] A.Gelb ed., Applied Optimal Estimation, The M.I.T Press, 1974
40  * [5] A.E.Niell, Global mapping functions for the atmosphere delay at radio
41  * wavelengths, Jounal of geophysical research, 1996
42  * [6] W.Gurtner and L.Estey, RINEX The Receiver Independent Exchange Format
43  * Version 3.00, November 28, 2007
44  * [7] J.Kouba, A Guide to using International GNSS Service (IGS) products,
45  * May 2009
46  * [8] China Satellite Navigation Office, BeiDou navigation satellite system
47  * signal in space interface control document, open service signal B1I
48  * (version 1.0), Dec 2012
49  * [9] J.Boehm, A.Niell, P.Tregoning and H.Shuh, Global Mapping Function
50  * (GMF): A new empirical mapping function base on numerical weather
51  * model data, Geophysical Research Letters, 33, L07304, 2006
52  * [10] GLONASS/GPS/Galileo/Compass/SBAS NV08C receiver series BINR interface
53  * protocol specification ver.1.3, August, 2012
54  *
55  * -----------------------------------------------------------------------------
56  */
57 
58 #ifndef GNSS_SDR_RTKLIB_RTKCMN_H
59 #define GNSS_SDR_RTKLIB_RTKCMN_H
60 
61 #include "rtklib.h"
62 #include <string>
63 
64 
65 /* coordinate rotation matrix ------------------------------------------------*/
66 #define Rx(t, X) \
67  do \
68  { \
69  (X)[0] = 1.0; \
70  (X)[1] = (X)[2] = (X)[3] = (X)[6] = 0.0; \
71  (X)[4] = (X)[8] = cos(t); \
72  (X)[7] = sin(t); \
73  (X)[5] = -(X)[7]; \
74  } \
75  while (0)
76 
77 #define Ry(t, X) \
78  do \
79  { \
80  (X)[4] = 1.0; \
81  (X)[1] = (X)[3] = (X)[5] = (X)[7] = 0.0; \
82  (X)[0] = (X)[8] = cos(t); \
83  (X)[2] = sin(t); \
84  (X)[6] = -(X)[2]; \
85  } \
86  while (0)
87 
88 #define Rz(t, X) \
89  do \
90  { \
91  (X)[8] = 1.0; \
92  (X)[2] = (X)[5] = (X)[6] = (X)[7] = 0.0; \
93  (X)[0] = (X)[4] = cos(t); \
94  (X)[3] = sin(t); \
95  (X)[1] = -(X)[3]; \
96  } \
97  while (0)
98 
99 
100 void fatalerr(const char *format, ...);
101 int satno(int sys, int prn);
102 int satsys(int sat, int *prn);
103 int satid2no(const char *id);
104 void satno2id(int sat, char *id);
105 int satexclude(int sat, int svh, const prcopt_t *opt);
106 int testsnr(int base, int freq, double el, double snr, const snrmask_t *mask);
107 unsigned char obs2code(const char *obs, int *freq);
108 char *code2obs(unsigned char code, int *freq);
109 void setcodepri(int sys, int freq, const char *pri);
110 int getcodepri(int sys, unsigned char code, const char *opt);
111 unsigned int getbitu(const unsigned char *buff, int pos, int len);
112 int getbits(const unsigned char *buff, int pos, int len);
113 void setbitu(unsigned char *buff, int pos, int len, unsigned int data);
114 void setbits(unsigned char *buff, int pos, int len, int data);
115 unsigned int rtk_crc32(const unsigned char *buff, int len);
116 unsigned int rtk_crc24q(const unsigned char *buff, int len);
117 unsigned short rtk_crc16(const unsigned char *buff, int len);
118 int decode_word(unsigned int word, unsigned char *data);
119 double *mat(int n, int m);
120 int *imat(int n, int m);
121 double *zeros(int n, int m);
122 double *eye(int n);
123 double dot(const double *a, const double *b, int n);
124 double norm_rtk(const double *a, int n);
125 void cross3(const double *a, const double *b, double *c);
126 int normv3(const double *a, double *b);
127 void matcpy(double *A, const double *B, int n, int m);
128 void matmul(const char *tr, int n, int k, int m, double alpha,
129  const double *A, const double *B, double beta, double *C);
130 int matinv(double *A, int n);
131 int solve(const char *tr, const double *A, const double *Y, int n,
132  int m, double *X);
133 int lsq(const double *A, const double *y, int n, int m, double *x,
134  double *Q);
135 int filter_(const double *x, const double *P, const double *H,
136  const double *v, const double *R, int n, int m,
137  double *xp, double *Pp);
138 int filter(double *x, double *P, const double *H, const double *v,
139  const double *R, int n, int m);
140 int smoother(const double *xf, const double *Qf, const double *xb,
141  const double *Qb, int n, double *xs, double *Qs);
142 void matfprint(const double A[], int n, int m, int p, int q, FILE *fp);
143 void matsprint(const double A[], int n, int m, int p, int q, std::string &buffer);
144 void matprint(const double A[], int n, int m, int p, int q);
145 double str2num(const char *s, int i, int n);
146 int str2time(const char *s, int i, int n, gtime_t *t);
147 gtime_t epoch2time(const double *ep);
148 void time2epoch(gtime_t t, double *ep);
149 gtime_t gpst2time(int week, double sec);
150 double time2gpst(gtime_t t, int *week);
151 gtime_t gst2time(int week, double sec);
152 double time2gst(gtime_t t, int *week);
153 gtime_t bdt2time(int week, double sec);
154 double time2bdt(gtime_t t, int *week);
155 gtime_t timeadd(gtime_t t, double sec);
156 double timediff(gtime_t t1, gtime_t t2);
157 double timediffweekcrossover(gtime_t t1, gtime_t t2);
158 gtime_t timeget();
159 void timeset(gtime_t t);
160 int read_leaps_text(FILE *fp);
161 int read_leaps_usno(FILE *fp);
162 int read_leaps(const char *file);
163 gtime_t gpst2utc(gtime_t t);
164 gtime_t utc2gpst(gtime_t t);
165 gtime_t gpst2bdt(gtime_t t);
166 gtime_t bdt2gpst(gtime_t t);
167 double time2sec(gtime_t time, gtime_t *day);
168 double utc2gmst(gtime_t t, double ut1_utc);
169 void time2str(gtime_t t, char *s, int n);
170 char *time_str(gtime_t t, int n);
171 double time2doy(gtime_t t);
172 int adjgpsweek(int week, bool pre_2009_file = false);
173 unsigned int tickget();
174 void sleepms(int ms);
175 void deg2dms(double deg, double *dms, int ndec);
176 void deg2dms(double deg, double *dms);
177 double dms2deg(const double *dms);
178 void ecef2pos(const double *r, double *pos);
179 void pos2ecef(const double *pos, double *r);
180 void xyz2enu(const double *pos, double *E);
181 void ecef2enu(const double *pos, const double *r, double *e);
182 void enu2ecef(const double *pos, const double *e, double *r);
183 void covenu(const double *pos, const double *P, double *Q);
184 void covecef(const double *pos, const double *Q, double *P);
185 void ast_args(double t, double *f);
186 void nut_iau1980(double t, const double *f, double *dpsi, double *deps);
187 void eci2ecef(gtime_t tutc, const double *erpv, double *U, double *gmst);
188 int decodef(char *p, int n, double *v);
189 void addpcv(const pcv_t *pcv, pcvs_t *pcvs);
190 int readngspcv(const char *file, pcvs_t *pcvs);
191 int readantex(const char *file, pcvs_t *pcvs);
192 int readpcv(const char *file, pcvs_t *pcvs);
193 pcv_t *searchpcv(int sat, const char *type, gtime_t time,
194  const pcvs_t *pcvs);
195 void readpos(const char *file, const char *rcv, double *pos);
196 int readblqrecord(FILE *fp, double *odisp);
197 int readblq(const char *file, const char *sta, double *odisp);
198 int readerp(const char *file, erp_t *erp);
199 int geterp(const erp_t *erp, gtime_t time, double *erpv);
200 int cmpeph(const void *p1, const void *p2);
201 void uniqeph(nav_t *nav);
202 int cmpgeph(const void *p1, const void *p2);
203 void uniqgeph(nav_t *nav);
204 int cmpseph(const void *p1, const void *p2);
205 void uniqseph(nav_t *nav);
206 void uniqnav(nav_t *nav);
207 int cmpobs(const void *p1, const void *p2);
208 int sortobs(obs_t *obs);
209 int screent(gtime_t time, gtime_t ts, gtime_t te, double tint);
210 int readnav(const char *file, nav_t *nav);
211 int savenav(const char *file, const nav_t *nav);
212 void freeobs(obs_t *obs);
213 void freenav(nav_t *nav, int opt);
214 
215 void traceopen(const char *file);
216 void traceclose();
217 void tracelevel(int level);
218 void traceswap();
219 void trace(int level, const char *format, ...);
220 void tracet(int level, const char *format, ...);
221 void tracemat(int level, const double *A, int n, int m, int p, int q);
222 void traceobs(int level, const obsd_t *obs, int n);
223 // void tracenav(int level, const nav_t *nav);
224 // void tracegnav(int level, const nav_t *nav);
225 // void tracehnav(int level, const nav_t *nav);
226 // void tracepeph(int level, const nav_t *nav);
227 // void tracepclk(int level, const nav_t *nav);
228 // void traceb (int level, const unsigned char *p, int n);
229 
230 int execcmd(const char *cmd);
231 void createdir(const char *path);
232 int repstr(char *str, const char *pat, const char *rep);
233 int reppath(const char *path, char *rpath, gtime_t time, const char *rov,
234  const char *base);
235 int reppaths(const char *path, char *rpath[], int nmax, gtime_t ts,
236  gtime_t te, const char *rov, const char *base);
237 double satwavelen(int sat, int frq, const nav_t *nav);
238 double geodist(const double *rs, const double *rr, double *e);
239 double satazel(const double *pos, const double *e, double *azel);
240 
241 void dops(int ns, const double *azel, double elmin, double *dop);
242 double ionmodel(gtime_t t, const double *ion, const double *pos,
243  const double *azel);
244 double ionmapf(const double *pos, const double *azel);
245 double ionppp(const double *pos, const double *azel, double re,
246  double hion, double *posp);
247 double tropmodel(gtime_t time, const double *pos, const double *azel,
248  double humi);
249 double interpc(const double coef[], double lat);
250 double mapf(double el, double a, double b, double c);
251 double nmf(gtime_t time, const double pos[], const double azel[],
252  double *mapfw);
253 double tropmapf(gtime_t time, const double pos[], const double azel[],
254  double *mapfw);
255 double interpvar(double ang, const double *var);
256 
257 void antmodel(const pcv_t *pcv, const double *del, const double *azel,
258  int opt, double *dant);
259 
260 void antmodel_s(const pcv_t *pcv, double nadir, double *dant);
261 void sunmoonpos_eci(gtime_t tut, double *rsun, double *rmoon);
262 void sunmoonpos(gtime_t tutc, const double *erpv, double *rsun,
263  double *rmoon, double *gmst);
264 void csmooth(obs_t *obs, int ns);
265 int rtk_uncompress(const char *file, char *uncfile);
266 int expath(const char *path, char *paths[], int nmax);
267 void windupcorr(gtime_t time, const double *rs, const double *rr, double *phw);
268 
269 #endif // GNSS_SDR_RTKLIB_RTKCMN_H
Definition: rtklib.h:369
Definition: rtklib.h:754
Definition: rtklib.h:418
Definition: rtklib.h:406
main header file for the rtklib library
Definition: rtklib.h:399
Definition: rtklib.h:382