MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_sol.h
Go to the documentation of this file.
1/*------------------------------------------------------------------------------
2 * mrtk_sol.h : solution type definitions and I/O functions
3 *
4 * Copyright (C) 2026 H.SHIONO (MRTKLIB Project)
5 * Copyright (C) 2023-2025 Cabinet Office, Japan
6 * Copyright (C) 2024-2025 Lighthouse Technology & Consulting Co. Ltd.
7 * Copyright (C) 2023-2025 Japan Aerospace Exploration Agency
8 * Copyright (C) 2023-2025 TOSHIBA ELECTRONIC TECHNOLOGIES CORPORATION
9 * Copyright (C) 2015- Mitsubishi Electric Corp.
10 * Copyright (C) 2014 Geospatial Information Authority of Japan
11 * Copyright (C) 2014 T.SUZUKI
12 * Copyright (C) 2007-2023 T.TAKASU
13 *
14 * SPDX-License-Identifier: BSD-2-Clause
15 *----------------------------------------------------------------------------*/
16/**
17 * @file mrtk_sol.h
18 * @brief MRTKLIB Solution Module — Solution data types and I/O functions.
19 *
20 * This header provides the solution data structures (sol_t, solbuf_t,
21 * solstat_t, solstatbuf_t, ssat_t) and solution I/O functions extracted
22 * from rtklib.h/solution.c with zero algorithmic changes.
23 *
24 * @note Functions declared here are implemented in mrtk_sol.c.
25 */
26#ifndef MRTK_SOL_H
27#define MRTK_SOL_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <stdint.h>
34#include <stdio.h>
35
37#include "mrtklib/mrtk_opt.h"
38#include "mrtklib/mrtk_time.h"
39
40/*============================================================================
41 * Solution Data Types
42 *===========================================================================*/
43
44typedef struct { /* solution type */
45 gtime_t time; /* time (GPST) */
46 double rr[6]; /* position/velocity (m|m/s) */
47 /* {x,y,z,vx,vy,vz} or {e,n,u,ve,vn,vu} */
48 float qr[6]; /* position variance/covariance (m^2) */
49 /* {c_xx,c_yy,c_zz,c_xy,c_yz,c_zx} or */
50 /* {c_ee,c_nn,c_uu,c_en,c_nu,c_ue} */
51 float qv[6]; /* velocity variance/covariance (m^2/s^2) */
52 double dtr[NSYS + 1]; /* receiver clock bias to time systems (s) */
53 uint8_t type; /* type (0:xyz-ecef,1:enu-baseline) */
54 uint8_t stat; /* solution status (SOLQ_???) */
55 uint8_t ns; /* number of valid satellites */
56 float age; /* age of differential (s) */
57 float ratio; /* AR ratio factor for valiation */
58 float thres; /* AR ratio threshold for valiation */
59 float prev_ratio1; /* previous initial AR ratio factor for validation */
60 float prev_ratio2; /* previous final AR ratio factor for validation */
61} sol_t;
62
63typedef struct { /* solution buffer type */
64 int n, nmax; /* number of solution/max number of buffer */
65 int cyclic; /* cyclic buffer flag */
66 int start, end; /* start/end index */
67 gtime_t time; /* current solution time */
68 sol_t* data; /* solution data */
69 double rb[3]; /* reference position {x,y,z} (ecef) (m) */
70 uint8_t buff[MAXSOLMSG + 1]; /* message buffer */
71 int nb; /* number of byte in message buffer */
72} solbuf_t;
73
74typedef struct { /* solution status type */
75 gtime_t time; /* time (GPST) */
76 uint8_t sat; /* satellite number */
77 uint8_t frq; /* frequency (1:L1,2:L2,...) */
78 float az, el; /* azimuth/elevation angle (rad) */
79 float resp; /* pseudorange residual (m) */
80 float resc; /* carrier-phase residual (m) */
81 uint8_t flag; /* flags: (vsat<<5)+(slip<<3)+fix */
82 uint16_t snr; /* signal strength (*SNR_UNIT dBHz) */
83 uint16_t lock; /* lock counter */
84 uint16_t outc; /* outage counter */
85 uint16_t slipc; /* slip counter */
86 uint16_t rejc; /* reject counter */
87} solstat_t;
88
89typedef struct { /* solution status buffer type */
90 int n, nmax; /* number of solution/max number of buffer */
91 solstat_t* data; /* solution status data */
93
94/*============================================================================
95 * Satellite Status Type
96 *===========================================================================*/
97
98typedef struct { /* satellite status type */
99 uint8_t sys; /* navigation system */
100 uint8_t vs; /* valid satellite flag single */
101 double azel[2]; /* azimuth/elevation angles {az,el} (rad) */
102 double resp[NFREQ]; /* residuals of pseudorange (m) */
103 double resc[NFREQ]; /* residuals of carrier-phase (m) */
104 uint8_t vsat[NFREQ]; /* valid satellite flag */
105 uint16_t snr[NFREQ]; /* signal strength (*SNR_UNIT dBHz) */
106 uint8_t fix[NFREQ]; /* ambiguity fix flag (1:fix,2:float,3:hold) */
107 uint8_t slip[NFREQ]; /* cycle-slip flag */
108 uint8_t half[NFREQ]; /* half-cycle valid flag */
109 int lock[NFREQ]; /* lock counter of phase */
110 uint32_t outc[NFREQ]; /* obs outage counter of phase */
111 uint32_t slipc[NFREQ]; /* cycle-slip counter */
112 uint32_t rejc[NFREQ]; /* reject counter */
113 double gf[NFREQ]; /* geometry-free phase (m) */
114 double mw[NFREQ]; /* MW-LC (m) */
115 double phw; /* phase windup (cycle) */
116 gtime_t pt[2][NFREQ]; /* previous carrier-phase time */
117 double ph[2][NFREQ]; /* previous carrier-phase observable (cycle) */
118 gtime_t spt[NFREQ]; /* SPP TDCP: previous carrier-phase time (pntpos-private;
119 * pt[0] belongs to the engines' slip detectors and must
120 * not be written by pntpos — see issue #318) */
121 double sph[NFREQ]; /* SPP TDCP: previous carrier-phase observable (cycle) */
122 int discont[NFREQ]; /* SSR phase bias discontinuity counter */
123 double ionc; /* ionospheric delay by carrier phase (m) */
124 uint8_t code[NFREQ]; /* observation code indicator (CODE_???) */
125 int pbreset[NFREQ]; /* phase bias reset flag */
126 uint8_t codeprev[NFREQ][2]; /* previous obs code per freq/receiver (0:rover,1:base) */
127} ssat_t;
128
129/*============================================================================
130 * Solution Buffer Functions
131 *===========================================================================*/
132
133/**
134 * @brief Initialize solution buffer.
135 * @param[out] solbuf Solution buffer
136 * @param[in] cyclic Cyclic buffer flag (0:off, 1:on)
137 * @param[in] nmax Max number of solutions (0:default)
138 */
139void initsolbuf(solbuf_t* solbuf, int cyclic, int nmax);
140
141/**
142 * @brief Free solution buffer memory.
143 * @param[in,out] solbuf Solution buffer
144 */
145void freesolbuf(solbuf_t* solbuf);
146
147/**
148 * @brief Free solution status buffer memory.
149 * @param[in,out] solstatbuf Solution status buffer
150 */
151void freesolstatbuf(solstatbuf_t* solstatbuf);
152
153/**
154 * @brief Get solution from buffer.
155 * @param[in,out] solbuf Solution buffer
156 * @param[in] index Solution index (0 to n-1)
157 * @return Solution data pointer (NULL: out of range)
158 */
159sol_t* getsol(solbuf_t* solbuf, int index);
160
161/**
162 * @brief Add solution to buffer.
163 * @param[in,out] solbuf Solution buffer
164 * @param[in] sol Solution data
165 * @return Status (1:ok, 0:error)
166 */
167int addsol(solbuf_t* solbuf, const sol_t* sol);
168
169/*============================================================================
170 * Solution I/O Functions
171 *===========================================================================*/
172
173/**
174 * @brief Read solutions from files.
175 * @param[in] files Solution file paths
176 * @param[in] nfile Number of files
177 * @param[out] sol Solution buffer
178 * @return Status (1:ok, 0:error)
179 */
180int readsol(char* files[], int nfile, solbuf_t* sol);
181
182/**
183 * @brief Read solutions from files with time filter.
184 * @param[in] files Solution file paths
185 * @param[in] nfile Number of files
186 * @param[in] ts Start time (GPST) (ts.time==0: no limit)
187 * @param[in] te End time (GPST) (te.time==0: no limit)
188 * @param[in] tint Time interval (s) (0.0: no limit)
189 * @param[in] qflag Quality flag (0:all)
190 * @param[out] sol Solution buffer
191 * @return Status (1:ok, 0:error)
192 */
193int readsolt(char* files[], int nfile, gtime_t ts, gtime_t te, double tint, int qflag, solbuf_t* sol);
194
195/**
196 * @brief Read solution status from files.
197 * @param[in] files Solution status file paths
198 * @param[in] nfile Number of files
199 * @param[out] statbuf Solution status buffer
200 * @return Status (1:ok, 0:error)
201 */
202int readsolstat(char* files[], int nfile, solstatbuf_t* statbuf);
203
204/**
205 * @brief Read solution status from files with time filter.
206 * @param[in] files Solution status file paths
207 * @param[in] nfile Number of files
208 * @param[in] ts Start time (GPST)
209 * @param[in] te End time (GPST)
210 * @param[in] tint Time interval (s)
211 * @param[out] statbuf Solution status buffer
212 * @return Status (1:ok, 0:error)
213 */
214int readsolstatt(char* files[], int nfile, gtime_t ts, gtime_t te, double tint, solstatbuf_t* statbuf);
215
216/**
217 * @brief Input solution data from stream.
218 * @param[in] data Stream data byte
219 * @param[in] ts Start time (GPST)
220 * @param[in] te End time (GPST)
221 * @param[in] tint Time interval (s)
222 * @param[in] qflag Quality flag (0:all)
223 * @param[in] opt Solution options
224 * @param[in,out] solbuf Solution buffer
225 * @return Status (0:no data, 1:new solution)
226 */
227int inputsol(uint8_t data, gtime_t ts, gtime_t te, double tint, int qflag, const solopt_t* opt, solbuf_t* solbuf);
228
229/*============================================================================
230 * Solution Output Functions
231 *===========================================================================*/
232
233/**
234 * @brief Output processing options to buffer.
235 * @param[out] buff Output buffer
236 * @param[in] opt Processing options
237 * @return Number of output bytes
238 */
239int outprcopts(uint8_t* buff, const prcopt_t* opt);
240
241/**
242 * @brief Output solution header to buffer.
243 * @param[out] buff Output buffer
244 * @param[in] opt Solution options
245 * @return Number of output bytes
246 */
247int outsolheads(uint8_t* buff, const solopt_t* opt);
248
249/**
250 * @brief Output solution to buffer.
251 * @param[out] buff Output buffer
252 * @param[in] sol Solution data
253 * @param[in] rb Reference position (ecef) (m)
254 * @param[in] opt Solution options
255 * @return Number of output bytes
256 */
257int outsols(uint8_t* buff, const sol_t* sol, const double* rb, const solopt_t* opt);
258
259/**
260 * @brief Output solution extended data to buffer.
261 * @param[out] buff Output buffer
262 * @param[in] sol Solution data
263 * @param[in] ssat Satellite status
264 * @param[in] opt Solution options
265 * @return Number of output bytes
266 */
267int outsolexs(uint8_t* buff, const sol_t* sol, const ssat_t* ssat, const solopt_t* opt);
268
269/**
270 * @brief Output processing options to file.
271 * @param[in] fp Output file pointer
272 * @param[in] opt Processing options
273 */
274void outprcopt(FILE* fp, const prcopt_t* opt);
275
276/**
277 * @brief Output solution header to file.
278 * @param[in] fp Output file pointer
279 * @param[in] opt Solution options
280 */
281void outsolhead(FILE* fp, const solopt_t* opt);
282
283/**
284 * @brief Output solution to file.
285 * @param[in] fp Output file pointer
286 * @param[in] sol Solution data
287 * @param[in] rb Reference position (ecef) (m)
288 * @param[in] opt Solution options
289 */
290void outsol(FILE* fp, const sol_t* sol, const double* rb, const solopt_t* opt);
291
292/**
293 * @brief Output solution extended data to file.
294 * @param[in] fp Output file pointer
295 * @param[in] sol Solution data
296 * @param[in] ssat Satellite status
297 * @param[in] opt Solution options
298 */
299void outsolex(FILE* fp, const sol_t* sol, const ssat_t* ssat, const solopt_t* opt);
300
301/*============================================================================
302 * NMEA Output Functions
303 *===========================================================================*/
304
305/**
306 * @brief Output NMEA RMC sentence.
307 * @param[out] buff Output buffer
308 * @param[in] sol Solution data
309 * @return Number of output bytes
310 */
311int outnmea_rmc(uint8_t* buff, const sol_t* sol);
312
313/**
314 * @brief Output NMEA GGA sentence.
315 * @param[out] buff Output buffer
316 * @param[in] sol Solution data
317 * @return Number of output bytes
318 */
319int outnmea_gga(uint8_t* buff, const sol_t* sol);
320
321/**
322 * @brief Output NMEA GSA sentence.
323 * @param[out] buff Output buffer
324 * @param[in] sol Solution data
325 * @param[in] ssat Satellite status
326 * @return Number of output bytes
327 */
328int outnmea_gsa(uint8_t* buff, const sol_t* sol, const ssat_t* ssat);
329
330/**
331 * @brief Output NMEA GSV sentence.
332 * @param[out] buff Output buffer
333 * @param[in] sol Solution data
334 * @param[in] ssat Satellite status
335 * @return Number of output bytes
336 */
337int outnmea_gsv(uint8_t* buff, const sol_t* sol, const ssat_t* ssat);
338
339#ifdef __cplusplus
340}
341#endif
342
343#endif /* MRTK_SOL_H */
MRTKLIB Foundation — Common types, standard includes, and system constants (MAXSAT,...
#define NSYS
#define MAXSOLMSG
MRTKLIB Options Module — Processing and solution option types.
void freesolstatbuf(solstatbuf_t *solstatbuf)
Free solution status buffer memory.
Definition mrtk_sol.c:1123
int outprcopts(uint8_t *buff, const prcopt_t *opt)
Output processing options to buffer.
Definition mrtk_sol.c:1609
int readsolstat(char *files[], int nfile, solstatbuf_t *statbuf)
Read solution status from files.
Definition mrtk_sol.c:1293
void freesolbuf(solbuf_t *solbuf)
Free solution buffer memory.
Definition mrtk_sol.c:1111
int inputsol(uint8_t data, gtime_t ts, gtime_t te, double tint, int qflag, const solopt_t *opt, solbuf_t *solbuf)
Input solution data from stream.
Definition mrtk_sol.c:874
int outsols(uint8_t *buff, const sol_t *sol, const double *rb, const solopt_t *opt)
Output solution to buffer.
Definition mrtk_sol.c:1770
int addsol(solbuf_t *solbuf, const sol_t *sol)
Add solution to buffer.
Definition mrtk_sol.c:1017
int readsolstatt(char *files[], int nfile, gtime_t ts, gtime_t te, double tint, solstatbuf_t *statbuf)
Read solution status from files with time filter.
Definition mrtk_sol.c:1261
int readsolt(char *files[], int nfile, gtime_t ts, gtime_t te, double tint, int qflag, solbuf_t *sol)
Read solutions from files with time filter.
Definition mrtk_sol.c:978
void outprcopt(FILE *fp, const prcopt_t *opt)
Output processing options to file.
Definition mrtk_sol.c:1871
int outnmea_gsv(uint8_t *buff, const sol_t *sol, const ssat_t *ssat)
Output NMEA GSV sentence.
Definition mrtk_sol.c:1552
void outsolex(FILE *fp, const sol_t *sol, const ssat_t *ssat, const solopt_t *opt)
Output solution extended data to file.
Definition mrtk_sol.c:1924
void initsolbuf(solbuf_t *solbuf, int cyclic, int nmax)
Initialize solution buffer.
Definition mrtk_sol.c:1078
int outsolexs(uint8_t *buff, const sol_t *sol, const ssat_t *ssat, const solopt_t *opt)
Output solution extended data to buffer.
Definition mrtk_sol.c:1841
int outnmea_rmc(uint8_t *buff, const sol_t *sol)
Output NMEA RMC sentence.
Definition mrtk_sol.c:1390
void outsolhead(FILE *fp, const solopt_t *opt)
Output solution header to file.
Definition mrtk_sol.c:1887
int outnmea_gga(uint8_t *buff, const sol_t *sol)
Output NMEA GGA sentence.
Definition mrtk_sol.c:1447
int outnmea_gsa(uint8_t *buff, const sol_t *sol, const ssat_t *ssat)
Output NMEA GSA sentence.
Definition mrtk_sol.c:1493
void outsol(FILE *fp, const sol_t *sol, const double *rb, const solopt_t *opt)
Output solution to file.
Definition mrtk_sol.c:1905
int outsolheads(uint8_t *buff, const solopt_t *opt)
Output solution header to buffer.
Definition mrtk_sol.c:1683
sol_t * getsol(solbuf_t *solbuf, int index)
Get solution from buffer.
Definition mrtk_sol.c:1060
int readsol(char *files[], int nfile, solbuf_t *sol)
Read solutions from files.
Definition mrtk_sol.c:1004
MRTKLIB Time Module — GNSS time types and conversion functions.
GNSS time representation.
Definition mrtk_time.h:49
float ratio
Definition mrtk_sol.h:57
float qr[6]
Definition mrtk_sol.h:48
double rr[6]
Definition mrtk_sol.h:46
float thres
Definition mrtk_sol.h:58
uint8_t type
Definition mrtk_sol.h:53
float prev_ratio2
Definition mrtk_sol.h:60
uint8_t stat
Definition mrtk_sol.h:54
double dtr[NSYS+1]
Definition mrtk_sol.h:52
float prev_ratio1
Definition mrtk_sol.h:59
float age
Definition mrtk_sol.h:56
uint8_t ns
Definition mrtk_sol.h:55
float qv[6]
Definition mrtk_sol.h:51
gtime_t time
Definition mrtk_sol.h:45
int nmax
Definition mrtk_sol.h:64
int n
Definition mrtk_sol.h:64
gtime_t time
Definition mrtk_sol.h:67
int nb
Definition mrtk_sol.h:71
uint8_t buff[MAXSOLMSG+1]
Definition mrtk_sol.h:70
double rb[3]
Definition mrtk_sol.h:69
int end
Definition mrtk_sol.h:66
int cyclic
Definition mrtk_sol.h:65
sol_t * data
Definition mrtk_sol.h:68
int start
Definition mrtk_sol.h:66
float az
Definition mrtk_sol.h:78
uint8_t flag
Definition mrtk_sol.h:81
uint8_t sat
Definition mrtk_sol.h:76
gtime_t time
Definition mrtk_sol.h:75
uint16_t slipc
Definition mrtk_sol.h:85
float resp
Definition mrtk_sol.h:79
uint16_t lock
Definition mrtk_sol.h:83
uint16_t outc
Definition mrtk_sol.h:84
float el
Definition mrtk_sol.h:78
uint16_t rejc
Definition mrtk_sol.h:86
uint16_t snr
Definition mrtk_sol.h:82
uint8_t frq
Definition mrtk_sol.h:77
float resc
Definition mrtk_sol.h:80
solstat_t * data
Definition mrtk_sol.h:91
gtime_t pt[2][5]
Definition mrtk_sol.h:116
double mw[5]
Definition mrtk_sol.h:114
uint8_t vsat[5]
Definition mrtk_sol.h:104
gtime_t spt[5]
Definition mrtk_sol.h:118
uint32_t slipc[5]
Definition mrtk_sol.h:111
int discont[5]
Definition mrtk_sol.h:122
uint8_t vs
Definition mrtk_sol.h:100
double ph[2][5]
Definition mrtk_sol.h:117
uint32_t outc[5]
Definition mrtk_sol.h:110
uint32_t rejc[5]
Definition mrtk_sol.h:112
uint8_t codeprev[5][2]
Definition mrtk_sol.h:126
double azel[2]
Definition mrtk_sol.h:101
double phw
Definition mrtk_sol.h:115
double resp[5]
Definition mrtk_sol.h:102
int lock[5]
Definition mrtk_sol.h:109
uint8_t slip[5]
Definition mrtk_sol.h:107
double gf[5]
Definition mrtk_sol.h:113
double sph[5]
Definition mrtk_sol.h:121
uint16_t snr[5]
Definition mrtk_sol.h:105
uint8_t half[5]
Definition mrtk_sol.h:108
uint8_t sys
Definition mrtk_sol.h:99
double ionc
Definition mrtk_sol.h:123
int pbreset[5]
Definition mrtk_sol.h:125
uint8_t fix[5]
Definition mrtk_sol.h:106
uint8_t code[5]
Definition mrtk_sol.h:124
double resc[5]
Definition mrtk_sol.h:103