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