mbgtools-lx  4.2.8
mbggeo.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: mbggeo.h 1.14 2017/05/10 15:21:40 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Definitions and prototypes for mbggeo.c.
10  *
11  * Terms used:
12  *
13  * WGS84 World Geodetic System of 1984
14  *
15  * XYZ WGS84 earth centered, earth fixed (ECEF) kartesian
16  * coordinates
17  *
18  * LLA longitude, latitude, altitude depending on the reference
19  * ellipsoid used.
20  *
21  * DMS degrees, minutes, seconds
22  *
23  * -----------------------------------------------------------------------
24  * $Log: mbggeo.h $
25  * Revision 1.14 2017/05/10 15:21:40 martin
26  * Tiny cleanup.
27  * Revision 1.13 2017/01/27 08:57:58 martin
28  * Fixed macro syntax.
29  * Revision 1.12 2016/10/31 16:50:56 martin
30  * Fixed a typo.
31  * Updated doxygen comments.
32  * Revision 1.11 2011/06/22 10:18:10 martin
33  * Cleaned up handling of pragma pack().
34  * Revision 1.10 2008/09/03 14:54:28 martin
35  * Added macros to swap endianess of structures.
36  * Revision 1.9 2008/01/17 09:31:33 daniel
37  * Made comments compatible for doxygen parser.
38  * No sourcecode changes.
39  * Revision 1.8 2004/11/09 14:16:00Z martin
40  * Redefined interface data types using C99 fixed-size definitions.
41  * Revision 1.7 2003/02/14 13:23:04Z martin
42  * Omit inclusion of mystd.h.
43  * Revision 1.6 2003/01/13 15:17:15 martin
44  * Structures were defined with default alignment which
45  * could result in different data sizes on different platforms.
46  * Revision 1.5 2002/12/18 14:46:41Z martin
47  * Removed variable USER_POS meinberg.
48  * Updated function prototypes.
49  * Revision 1.4 2002/12/12 12:04:25Z martin
50  * Moved some definitions here.
51  * Use standard file format.
52  *
53  **************************************************************************/
54 
55 #ifndef _MBGGEO_H
56 #define _MBGGEO_H
57 
58 
59 /* Other headers to be included */
60 
61 #include <gpsdefs.h>
62 #include <use_pack.h>
63 
64 #ifdef _MBGGEO
65  #define _ext
66  #define _DO_INIT
67 #else
68  #define _ext extern
69 #endif
70 
71 
72 /* Start of header body */
73 
74 #if defined( _USE_PACK )
75  #pragma pack( 1 ) // set byte alignment
76  #define _USING_BYTE_ALIGNMENT
77 #endif
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 
90 typedef struct
91 {
95  double sec;
96 
97 } DMS;
98 
99 #define _mbg_swab_dms( _p ) \
100 do \
101 { \
102  _mbg_swab16( &(_p)->prefix ); \
103  _mbg_swab16( &(_p)->deg ); \
104  _mbg_swab16( &(_p)->min ); \
105  _mbg_swab_double( &(_p)->sec ); \
106 } while ( 0 )
107 
108 
109 
113 typedef struct
114 {
120 
121 } POS;
122 
123 #define _mbg_swab_pos( _p ) \
124 do \
125 { \
126  _mbg_swab_xyz( (_p)->xyz ); \
127  _mbg_swab_lla( (_p)->lla ); \
128  _mbg_swab_dms( &(_p)->longitude ); \
129  _mbg_swab_dms( &(_p)->latitude ); \
130  _mbg_swab16( &(_p)->ellipsoid ); \
131 } while ( 0 )
132 
133 
134 
140 typedef struct
141 {
144 
145  char name[40];
147  double det;
148 
149 
150  // The components below hold the results of intermediate terms
151  // computed in complete_user_pos().
152 
153  // The sin.., cos.., nt.. and ut.. variables are used to compute the
154  // enu_dcos[] parameters of a SV structure in xyz_to_ead().
155 
156  // The e_radius.. variables are used to compute the latitude, longitude
157  // and altitude from ECEF coordinates in lla_to_xyz().
158 
159  double sin_lat;
160  double cos_lat;
161  double sin_lon;
162  double cos_lon;
163 
164  double nt1;
165  double nt2;
166  double utx;
167  double uty;
168 
169  double e_radius;
170  double e_radius_alt;
171 
172 } USER_POS;
173 
174 
175 
179 typedef struct
180 {
183 
184  char name[40];
186  double a;
187  double rcp_f;
188 
189  // The variables below are computed in the init_mbggeo() function:
190 
191  double f;
192  double b;
193  double sqr_e;
194 
195 } ELLIPSOID;
196 
197 
198 
203 {
207 };
208 
209 
211 #ifdef _DO_INIT
212  = { { 0, 0,
213  "WGS 84",
214  { 0.0, 0.0, 0.0 },
215  6378137.0,
216  298.257223563
217  },
218 
219  { 0, 0,
220  "Bessel",
221  { -128.0, 481.0, 664.0 },
222  6377397.0,
223  299.15
224  }
225 
226  }
227 #endif
228 ;
229 
230 
231 // WGS84 constants used
232 
233 _ext double OMEGADOTe // Earth's rotation rate [rad/sec]
234 #ifdef _DO_INIT
235  = 7.2921151467e-5
236 #endif
237 ;
238 
239 _ext double mue // Earth's gravitational constant [m^3/sec^2]
240 #ifdef _DO_INIT
241  = 3.986005e14
242 #endif
243 ;
244 
245 
246 
247 _ext double vr_to_doppler;
248 
249 
250 _ext double gps_pi
251 #ifdef _DO_INIT
252  = 3.1415926535898
253 #endif
254 ;
255 
256 _ext double gps_c0
257 #ifdef _DO_INIT
258  = 2.99792458e8
259 #endif
260 ;
261 
262 
263 #ifndef PI
264  #define PI 3.1415926535897932
265 #endif
266 
267 
268 _ext double pi
269 #ifdef _DO_INIT
270  = PI
271 #endif
272 ;
273 
274 
275 _ext double r2d
276 #ifdef _DO_INIT
277  = 180.0 / PI
278 #endif
279 ;
280 
281 
282 _ext double d2r
283 #ifdef _DO_INIT
284  = PI / 180.0
285 #endif
286 ;
287 
288 
289 // Variables for simplifying computations
290 
291 _ext double gps_two_pi;
292 _ext double sqrt_mue; // sqrt( mue )
293 
294 
295 
296 /* ----- function prototypes begin ----- */
297 
298 /* This section was generated automatically */
299 /* by MAKEHDR, do not remove the comments. */
300 
301  void dms_to_rad( const DMS *dms, double *rad ) ;
302  void rad_to_dms( const double *rad, DMS *dms, const char prefix ) ;
303  void dms_to_lla( POS *pos ) ;
304  void lla_to_dms( POS *pos ) ;
305  void lla_to_xyz( USER_POS *pos ) ;
306  void xyz_to_lla( POS *pos, void (*cyclic_func)( void ) ) ;
307  void dms_to_xyz( USER_POS *pos ) ;
308  void setup_user_pos_from_dms( USER_POS *user ) ;
309  void setup_user_pos_from_lla( USER_POS *user ) ;
310  void setup_user_pos_from_xyz( USER_POS *user, void (*cyclic_func)( void ) ) ;
311  double distance( XYZ xyz_1, XYZ xyz_2 ) ;
312  void init_mbggeo( void ) ;
313 
314 /* ----- function prototypes end ----- */
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 
320 
321 #if defined( _USING_BYTE_ALIGNMENT )
322  #pragma pack() // set default alignment
323  #undef _USING_BYTE_ALIGNMENT
324 #endif
325 
326 /* End of header body */
327 
328 #undef _ext
329 #undef _DO_INIT
330 
331 #endif /* _MBGGEO_H */
332 
DMS longitude
Longitude broken down to degrees, minutes, seconds.
Definition: mbggeo.h:117
void dms_to_xyz(USER_POS *pos)
void lla_to_xyz(USER_POS *pos)
POS pos
The position in WGS84 ECEF coords and LLA.
Definition: mbggeo.h:146
int16_t valid
Indicator if data is valid.
Definition: mbggeo.h:143
Definition: mbggeo.h:204
double e_radius
N.
Definition: mbggeo.h:169
double b
Semi minor axis.
Definition: mbggeo.h:192
short int16_t
Definition: words.h:212
uint16_t CSUM
checksum used by some structures stored in non-volatile memory
Definition: gpsdefs.h:705
unsigned short uint16_t
Definition: words.h:213
double sqr_e
Square of numerical eccentricity.
Definition: mbggeo.h:193
A structure used internally to compute a geographic position.
Definition: mbggeo.h:140
DMS latitude
Latitude broken down to degrees, minutes, seconds.
Definition: mbggeo.h:118
double nt1
-sin_lat * cos_lon
Definition: mbggeo.h:164
CSUM csum
Checksum of the remaining bytes.
Definition: mbggeo.h:181
CSUM csum
Checksum of the remaining bytes.
Definition: mbggeo.h:142
void setup_user_pos_from_xyz(USER_POS *user, void(*cyclic_func)(void))
double gps_two_pi
int16_t ellipsoid
Ellipsoid used for reference, see ELLIPSOIDS.
Definition: mbggeo.h:119
int16_t valid
Indicator if data is valid.
Definition: mbggeo.h:182
double rcp_f
Reciproke of flatness.
Definition: mbggeo.h:187
double a
Semi major axis.
Definition: mbggeo.h:186
double det
Definition: mbggeo.h:147
double gps_pi
double OMEGADOTe
Geographic longitude or latitude in [degrees, minutes, seconds].
Definition: mbggeo.h:90
void rad_to_dms(const double *rad, DMS *dms, const char prefix)
void xyz_to_lla(POS *pos, void(*cyclic_func)(void))
double sin_lat
sin( latitude )
Definition: mbggeo.h:159
void dms_to_rad(const DMS *dms, double *rad)
Characteristics of a geographic reference ellipsoid.
Definition: mbggeo.h:179
uint16_t prefix
&#39;N&#39;, &#39;E&#39;, &#39;S&#39; or &#39;W&#39;
Definition: mbggeo.h:92
double XYZ[N_XYZ]
A position in cartesian coordinates.
Definition: gpsdefs.h:2742
uint16_t deg
[0...90 (lat) or 0...180 (lon)]
Definition: mbggeo.h:93
double r2d
XYZ dxyz
Offset from the WGS84 ECEF coords.
Definition: mbggeo.h:185
ELLIPSOID ellipsoid[N_ELLIPSOIDS]
double utx
cos_lat * cos_lon
Definition: mbggeo.h:166
void lla_to_dms(POS *pos)
double d2r
double gps_c0
double distance(XYZ xyz_1, XYZ xyz_2)
double e_radius_alt
N + h.
Definition: mbggeo.h:170
A geographic position represented in different formats.
Definition: mbggeo.h:113
double pi
double sqrt_mue
XYZ xyz
Always WGS84 ECEF coordinates.
Definition: mbggeo.h:115
void setup_user_pos_from_lla(USER_POS *user)
void dms_to_lla(POS *pos)
double uty
cos_lat * sin_lon
Definition: mbggeo.h:167
ELLIPSOIDS
An enumeration of known ellipsoids.
Definition: mbggeo.h:202
uint16_t min
[0...59]
Definition: mbggeo.h:94
LLA lla
Longitude, latitude and altitude, depending on the ellipsoid used for reference.
Definition: mbggeo.h:116
double f
Flatness.
Definition: mbggeo.h:191
double LLA[N_LLA]
A geographic position based on latitude, longitude, and altitude.
Definition: gpsdefs.h:2764
#define _ext
Definition: mbggeo.h:68
void setup_user_pos_from_dms(USER_POS *user)
void init_mbggeo(void)
double sec
[0...59.99999...]
Definition: mbggeo.h:95
double cos_lon
cos( longitude )
Definition: mbggeo.h:162
double vr_to_doppler
double cos_lat
cos( latitude )
Definition: mbggeo.h:160
double sin_lon
sin( longitude )
Definition: mbggeo.h:161
Definition: mbggeo.h:205
double nt2
-sin_lat * sin_lon
Definition: mbggeo.h:165
double mue
#define PI
Definition: mbggeo.h:264