GNSS-SDR  0.0.17
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-200M, Navstar GPS Space Segment/Navigation User Interfaces,
33  * May, 2021
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 <cstddef>
63 #include <string>
64 
65 
66 /* coordinate rotation matrix ------------------------------------------------*/
67 #define Rx(t, X) \
68  do \
69  { \
70  (X)[0] = 1.0; \
71  (X)[1] = (X)[2] = (X)[3] = (X)[6] = 0.0; \
72  (X)[4] = (X)[8] = cos(t); \
73  (X)[7] = sin(t); \
74  (X)[5] = -(X)[7]; \
75  } \
76  while (0)
77 
78 #define Ry(t, X) \
79  do \
80  { \
81  (X)[4] = 1.0; \
82  (X)[1] = (X)[3] = (X)[5] = (X)[7] = 0.0; \
83  (X)[0] = (X)[8] = cos(t); \
84  (X)[2] = sin(t); \
85  (X)[6] = -(X)[2]; \
86  } \
87  while (0)
88 
89 #define Rz(t, X) \
90  do \
91  { \
92  (X)[8] = 1.0; \
93  (X)[2] = (X)[5] = (X)[6] = (X)[7] = 0.0; \
94  (X)[0] = (X)[4] = cos(t); \
95  (X)[3] = sin(t); \
96  (X)[1] = -(X)[3]; \
97  } \
98  while (0)
99 
100 char *strncpy_no_trunc(char *out, size_t outsz, const char *in, size_t insz);
101 void fatalerr(const char *format, ...);
102 int satno(int sys, int prn);
103 int satsys(int sat, int *prn);
104 int satid2no(const char *id);
105 void satno2id(int sat, char *id);
106 int satexclude(int sat, int svh, const prcopt_t *opt);
107 int testsnr(int base, int freq, double el, double snr, const snrmask_t *mask);
108 unsigned char obs2code(const char *obs, int *freq);
109 char *code2obs(unsigned char code, int *freq);
110 void setcodepri(int sys, int freq, const char *pri);
111 int getcodepri(int sys, unsigned char code, const char *opt);
112 unsigned int getbitu(const unsigned char *buff, int pos, int len);
113 int getbits(const unsigned char *buff, int pos, int len);
114 void setbitu(unsigned char *buff, int pos, int len, unsigned int data);
115 void setbits(unsigned char *buff, int pos, int len, int data);
116 unsigned int rtk_crc32(const unsigned char *buff, int len);
117 unsigned int rtk_crc24q(const unsigned char *buff, int len);
118 unsigned short rtk_crc16(const unsigned char *buff, int len);
119 int decode_word(unsigned int word, unsigned char *data);
120 double *mat(int n, int m);
121 int *imat(int n, int m);
122 double *zeros(int n, int m);
123 double *eye(int n);
124 double dot(const double *a, const double *b, int n);
125 double norm_rtk(const double *a, int n);
126 void cross3(const double *a, const double *b, double *c);
127 int normv3(const double *a, double *b);
128 void matcpy(double *A, const double *B, int n, int m);
129 void matmul(const char *tr, int n, int k, int m, double alpha,
130  const double *A, const double *B, double beta, double *C);
131 int matinv(double *A, int n);
132 int solve(const char *tr, const double *A, const double *Y, int n,
133  int m, double *X);
134 int lsq(const double *A, const double *y, int n, int m, double *x,
135  double *Q);
136 int filter_(const double *x, const double *P, const double *H,
137  const double *v, const double *R, int n, int m,
138  double *xp, double *Pp);
139 int filter(double *x, double *P, const double *H, const double *v,
140  const double *R, int n, int m);
141 int smoother(const double *xf, const double *Qf, const double *xb,
142  const double *Qb, int n, double *xs, double *Qs);
143 void matfprint(const double A[], int n, int m, int p, int q, FILE *fp);
144 void matsprint(const double A[], int n, int m, int p, int q, std::string &buffer);
145 void matprint(const double A[], int n, int m, int p, int q);
146 double str2num(const char *s, int i, int n);
147 int str2time(const char *s, int i, int n, gtime_t *t);
148 gtime_t epoch2time(const double *ep);
149 void time2epoch(gtime_t t, double *ep);
150 gtime_t gpst2time(int week, double sec);
151 double time2gpst(gtime_t t, int *week);
152 gtime_t gst2time(int week, double sec);
153 double time2gst(gtime_t t, int *week);
154 gtime_t bdt2time(int week, double sec);
155 double time2bdt(gtime_t t, int *week);
156 gtime_t timeadd(gtime_t t, double sec);
157 double timediff(gtime_t t1, gtime_t t2);
158 double timediffweekcrossover(gtime_t t1, gtime_t t2);
159 gtime_t timeget();
160 void timeset(gtime_t t);
161 int read_leaps_text(FILE *fp);
162 int read_leaps_usno(FILE *fp);
163 int read_leaps(const char *file);
164 gtime_t gpst2utc(gtime_t t);
165 gtime_t utc2gpst(gtime_t t);
166 gtime_t gpst2bdt(gtime_t t);
167 gtime_t bdt2gpst(gtime_t t);
168 double time2sec(gtime_t time, gtime_t *day);
169 double utc2gmst(gtime_t t, double ut1_utc);
170 void time2str(gtime_t t, char *s, int n);
171 char *time_str(gtime_t t, int n);
172 double time2doy(gtime_t t);
173 int adjgpsweek(int week, bool pre_2009_file = false);
174 unsigned int tickget();
175 void sleepms(int ms);
176 void deg2dms(double deg, double *dms, int ndec);
177 void deg2dms(double deg, double *dms);
178 double dms2deg(const double *dms);
179 void ecef2pos(const double *r, double *pos);
180 void pos2ecef(const double *pos, double *r);
181 void xyz2enu(const double *pos, double *E);
182 void ecef2enu(const double *pos, const double *r, double *e);
183 void enu2ecef(const double *pos, const double *e, double *r);
184 void covenu(const double *pos, const double *P, double *Q);
185 void covecef(const double *pos, const double *Q, double *P);
186 void ast_args(double t, double *f);
187 void nut_iau1980(double t, const double *f, double *dpsi, double *deps);
188 void eci2ecef(gtime_t tutc, const double *erpv, double *U, double *gmst);
189 int decodef(char *p, int n, double *v);
190 void addpcv(const pcv_t *pcv, pcvs_t *pcvs);
191 int readngspcv(const char *file, pcvs_t *pcvs);
192 int readantex(const char *file, pcvs_t *pcvs);
193 int readpcv(const char *file, pcvs_t *pcvs);
194 pcv_t *searchpcv(int sat, const char *type, gtime_t time,
195  const pcvs_t *pcvs);
196 void readpos(const char *file, const char *rcv, double *pos);
197 int readblqrecord(FILE *fp, double *odisp);
198 int readblq(const char *file, const char *sta, double *odisp);
199 int readerp(const char *file, erp_t *erp);
200 int geterp(const erp_t *erp, gtime_t time, double *erpv);
201 int cmpeph(const void *p1, const void *p2);
202 void uniqeph(nav_t *nav);
203 int cmpgeph(const void *p1, const void *p2);
204 void uniqgeph(nav_t *nav);
205 int cmpseph(const void *p1, const void *p2);
206 void uniqseph(nav_t *nav);
207 void uniqnav(nav_t *nav);
208 int cmpobs(const void *p1, const void *p2);
209 int sortobs(obs_t *obs);
210 int screent(gtime_t time, gtime_t ts, gtime_t te, double tint);
211 int readnav(const char *file, nav_t *nav);
212 int savenav(const char *file, const nav_t *nav);
213 void freeobs(obs_t *obs);
214 void freenav(nav_t *nav, int opt);
215 
216 void traceopen(const char *file);
217 void traceclose();
218 void tracelevel(int level);
219 void traceswap();
220 void trace(int level, const char *format, ...);
221 void tracet(int level, const char *format, ...);
222 void tracemat(int level, const double *A, int n, int m, int p, int q);
223 void traceobs(int level, const obsd_t *obs, int n);
224 // void tracenav(int level, const nav_t *nav);
225 // void tracegnav(int level, const nav_t *nav);
226 // void tracehnav(int level, const nav_t *nav);
227 // void tracepeph(int level, const nav_t *nav);
228 // void tracepclk(int level, const nav_t *nav);
229 // void traceb (int level, const unsigned char *p, int n);
230 
231 int execcmd(const char *cmd);
232 void createdir(const char *path);
233 int repstr(char *str, const char *pat, const char *rep);
234 int reppath(const char *path, char *rpath, gtime_t time, const char *rov,
235  const char *base);
236 int reppaths(const char *path, char *rpath[], int nmax, gtime_t ts,
237  gtime_t te, const char *rov, const char *base);
238 double satwavelen(int sat, int frq, const nav_t *nav);
239 double geodist(const double *rs, const double *rr, double *e);
240 double satazel(const double *pos, const double *e, double *azel);
241 
242 void dops(int ns, const double *azel, double elmin, double *dop);
243 double ionmodel(gtime_t t, const double *ion, const double *pos,
244  const double *azel);
245 double ionmapf(const double *pos, const double *azel);
246 double ionppp(const double *pos, const double *azel, double re,
247  double hion, double *posp);
248 double tropmodel(gtime_t time, const double *pos, const double *azel,
249  double humi);
250 double interpc(const double coef[], double lat);
251 double mapf(double el, double a, double b, double c);
252 double nmf(gtime_t time, const double pos[], const double azel[],
253  double *mapfw);
254 double tropmapf(gtime_t time, const double pos[], const double azel[],
255  double *mapfw);
256 double interpvar(double ang, const double *var);
257 
258 void antmodel(const pcv_t *pcv, const double *del, const double *azel,
259  int opt, double *dant);
260 
261 void antmodel_s(const pcv_t *pcv, double nadir, double *dant);
262 void sunmoonpos_eci(gtime_t tut, double *rsun, double *rmoon);
263 void sunmoonpos(gtime_t tutc, const double *erpv, double *rsun,
264  double *rmoon, double *gmst);
265 void csmooth(obs_t *obs, int ns);
266 int rtk_uncompress(const char *file, char *uncfile);
267 int expath(const char *path, char *paths[], int nmax);
268 void windupcorr(gtime_t time, const double *rs, const double *rr, double *phw);
269 
270 #endif // GNSS_SDR_RTKLIB_RTKCMN_H
Definition: rtklib.h:362
Definition: rtklib.h:747
Definition: rtklib.h:411
Definition: rtklib.h:399
main header file for the rtklib library
Definition: rtklib.h:392
Definition: rtklib.h:375