blob: f6f7cc07bd145b3e072217e7c63a821d963ceeb5 [file] [log] [blame]
Sylvain Munaut341542b2009-12-22 21:53:22 +01001/*
2 * gps.h
3 *
4 * Header to deal with low level GPS data
5 *
6 *
7 * Copyright (C) 2009 Sylvain Munaut <tnt@246tNt.com>
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, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __GPS_H__
24#define __GPS_H__
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <stdint.h>
31
32
33#define MAX_SV 64
34
35
36/* Ionosperic model data */
37struct gps_ionosphere_model {
38 /* #bits Scale factor Effective Units */
39 /* (LSB) range */
40
41 int alpha_0; /* s 8 2^-30 seconds */
42 int alpha_1; /* s 8 2^-27 s / semi-circles */
43 int alpha_2; /* s 8 2^-24 s / (semi-circles)^2 */
44 int alpha_3; /* s 8 2^-24 s / (semi-circles)^3 */
45 int beta_0; /* s 8 2^11 seconds */
46 int beta_1; /* s 8 2^14 s / semi-circles */
47 int beta_2; /* s 8 2^16 s / (semi-circles)^2 */
48 int beta_3; /* s 8 2^16 s / (semi-circles)^3 */
49};
50
51
52/* UTC model data */
53struct gps_utc_model {
54 /* #bits Scale factor Effective Units */
55 /* (LSB) range */
56
57 int a0; /* s 32 2^-30 seconds */
58 int a1; /* s 24 2^-50 seconds / seconds */
59 int delta_t_ls; /* s 8 1 seconds */
60 int t_ot; /* u 8 2^12 602,112 seconds */
61 int wn_t; /* u 8 1 weeks */
62 int wn_lsf; /* u 8 1 weeks */
63 int dn; /* u 8 1 7 days */
64 int delta_t_lsf;/* s 8 1 seconds */
65};
66
67
68/* Almanach data */
69struct gps_almanac_sv {
70 int sv_id;
71 int sv_health;
72
73 /* #bits Scale factor Effective Units */
74 /* (LSB) range */
75
76 int e; /* u 16 2^-21 */
77 int t_oa; /* u 8 2^12 602,112 seconds */
78 int ksii; /* s 16 2^-19 semi-circles */
79 int omega_dot; /* s 16 2^-38 semi-circles / s */
80 int a_powhalf; /* u 24 2^-11 meters */
81 int omega_0; /* s 24 2^-23 semi-circles */
82 int w; /* s 24 2^-23 semi-circles */
83 int m_0; /* s 24 2^-23 semi-circles */
84 int a_f0; /* s 11 2^-20 seconds */
85 int a_f1; /* s 11 2^-38 seconds / seconds */
86};
87
88struct gps_almanac {
89 int wna;
90 int n_sv;
91 struct gps_almanac_sv svs[MAX_SV];
92};
93
94
95/* Ephemeris data */
96struct gps_ephemeris_sv {
97 int sv_id;
98
99 /* #bits Scale factor Effective Units */
100 /* (LSB) range */
101
102 int code_on_l2; /* u 2 1 / */
103 int week_no; /* u 10 1 week */
104 int l2_p_flag; /* u 1 1 / */
105 int sv_ura; /* u 4 / / */
106 int sv_health; /* u 6 / / */
107 int t_gd; /* s 8 2^-31 seconds */
108 int iodc; /* u 10 / / */
109 int t_oc; /* u 16 2^4 604,784 seconds */
110 int a_f2; /* s 8 2^-55 sec / sec^2 */
111 int a_f1; /* s 16 2^-43 sec / sec */
112 int a_f0; /* s 22 2^-31 seconds */
113
114 int c_rs; /* s 16 2^-5 meters */
115 int delta_n; /* s 16 2^-43 semi-circles / s */
116 int m_0; /* s 32 2^-31 semi-circles */
117 int c_uc; /* s 16 2^-29 radians */
118 unsigned int e; /* u 32 2^-33 0.03 / */
119 int c_us; /* s 16 2^-29 radians */
120 unsigned int a_powhalf; /* u 32 2^-19 meters^(1/2) */
121 int t_oe; /* u 16 2^4 604,784 seconds */
122 int fit_flag; /* u 1 / / */
123
124 int c_ic; /* s 16 2^-29 radians */
125 int omega_0; /* s 32 2^-31 semi-circles */
126 int c_is; /* s 16 2^-29 radians */
127 int i_0; /* s 32 2^-31 semi-circles */
128 int c_rc; /* s 16 2^-5 meters */
129 int w; /* s 32 2^-31 semi-circles */
130 int omega_dot; /* s 24 2^-43 semi-circles / s */
131 int idot; /* s 14 2^-43 semi-circles / s */
132
133 int _rsvd1; /* 23 bits */
134 int _rsvd2; /* 24 bits */
135 int _rsvd3; /* 24 bits */
136 int _rsvd4; /* 16 bits */
137 int aodo; /* 8 bits Not sure it needs to be here ... */
138};
139
140struct gps_ephemeris {
141 int n_sv;
142 struct gps_ephemeris_sv svs[MAX_SV];
143};
144
145
146/* All assist data */
147#define GPS_FIELD_IONOSPHERE (1<<0)
148#define GPS_FIELD_UTC (1<<1)
149#define GPS_FIELD_ALMANAC (1<<2)
150#define GPS_FIELD_EPHEMERIS (1<<3)
151
152struct gps_assist_data {
153 int fields;
154 struct gps_ionosphere_model ionosphere;
155 struct gps_utc_model utc;
156 struct gps_almanac almanac;
157 struct gps_ephemeris ephemeris;
158};
159
160
161/* GPS Subframe utility methods (see gps.c for details) */
162int gps_unpack_sf123(uint32_t *sf, struct gps_ephemeris_sv *eph);
163int gps_unpack_sf45_almanac(uint32_t *sf, struct gps_almanac_sv *alm);
164
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* __GPS_H__ */
171