MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_rtcm.h
Go to the documentation of this file.
1/*------------------------------------------------------------------------------
2 * mrtk_rtcm.h : RTCM type definitions and 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_rtcm.h
18 * @brief MRTKLIB RTCM Module — RTCM message types and functions.
19 *
20 * This header provides the RTCM control struct (rtcm_t) and all public
21 * RTCM function declarations extracted from rtcm.c, rtcm2.c, rtcm3.c,
22 * rtcm3e.c, and rtcm3lcl.c.
23 *
24 * @note All functions in this module are pure cut-and-paste extractions
25 * with zero algorithmic changes.
26 */
27#ifndef MRTK_RTCM_H
28#define MRTK_RTCM_H
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <stdint.h>
35#include <stdio.h>
36
38#include "mrtklib/mrtk_nav.h"
39#include "mrtklib/mrtk_obs.h"
41#include "mrtklib/mrtk_time.h"
42
43/*============================================================================
44 * RTCM Types
45 *===========================================================================*/
46
47/**
48 * @brief RTCM control struct type.
49 */
50typedef struct { /* RTCM control struct type */
51 int staid; /* station id */
52 int stah; /* station health */
53 int seqno; /* sequence number for rtcm 2 or iods msm */
54 int outtype; /* output message type */
55 gtime_t time; /* message time */
56 gtime_t time_s; /* message start time */
57 obs_t obs; /* observation data (uncorrected) */
58 nav_t nav; /* satellite ephemerides */
59 sta_t sta; /* station parameters */
60 dgps_t* dgps; /* output of dgps corrections */
61 ssr_t ssr[MAXSAT]; /* output of ssr corrections */
62 char msg[128]; /* special message */
63 char msgtype[256]; /* last message type */
64 char msmtype[7][128]; /* msm signal types */
65 int obsflag; /* obs data complete flag (1:ok,0:not complete) */
66 int ephsat; /* input ephemeris satellite number */
67 int ephset; /* input ephemeris set (0-1) */
68 double cp[MAXSAT][NFREQ + NEXOBS]; /* carrier-phase measurement */
69 uint16_t lock[MAXSAT][NFREQ + NEXOBS]; /* lock time */
70 uint16_t loss[MAXSAT][NFREQ + NEXOBS]; /* loss of lock count */
71 gtime_t lltime[MAXSAT][NFREQ + NEXOBS]; /* last lock time */
72 int nbyte; /* number of bytes in message buffer */
73 int nbit; /* number of bits in word buffer */
74 int len; /* message length (bytes) */
75 uint8_t buff[1200]; /* message buffer */
76 uint32_t word; /* word buffer for rtcm 2 */
77 uint32_t nmsg2[100]; /* message count of RTCM 2 (1-99:1-99,0:other) */
78 uint32_t nmsg3[400]; /* message count of RTCM 3 (1-299:1001-1299,300-329:4070-4099,0:ohter) */
79 char opt[256]; /* RTCM dependent options */
80 lclblock_t* lclblk; /* iono/trop corrections; lazily allocated (RTCM3 msgs 2001-2016) */
81} rtcm_t;
82
83/*============================================================================
84 * RTCM Functions
85 *===========================================================================*/
86
87/**
88 * @brief Initialize RTCM control struct.
89 * @param[out] rtcm RTCM control struct
90 * @return Status (1:ok, 0:memory allocation error)
91 * @note The struct must be zero-initialized (calloc/memset) before the first
92 * call; an existing lclblk allocation is preserved across re-init.
93 */
95
96/**
97 * @brief Free RTCM control struct.
98 * @param[in,out] rtcm RTCM control struct
99 */
100void free_rtcm(rtcm_t* rtcm);
101
102/**
103 * @brief Get the local correction block, lazily allocating it on first use.
104 * @param[in,out] rtcm RTCM control struct
105 * @return Local correction block (NULL: memory allocation error).
106 */
108
109/**
110 * @brief Input RTCM 2 message from stream (byte-by-byte).
111 * @param[in,out] rtcm RTCM control struct
112 * @param[in] data Stream data (1 byte)
113 * @return Status (-1:error, 0:no message, 1:obs data, 2:ephemeris, ...)
114 */
115int input_rtcm2(rtcm_t* rtcm, uint8_t data);
116
117/**
118 * @brief Input RTCM 3 message from stream (byte-by-byte).
119 * @param[in,out] rtcm RTCM control struct
120 * @param[in] data Stream data (1 byte)
121 * @return Status (-1:error, 0:no message, 1:obs data, 2:ephemeris, ...)
122 */
123int input_rtcm3(rtcm_t* rtcm, uint8_t data);
124
125/**
126 * @brief Input RTCM 2 message from file.
127 * @param[in,out] rtcm RTCM control struct
128 * @param[in] fp File pointer
129 * @return Status (-2:end of file, -1:error, 0:no message, 1:obs, 2:eph, ...)
130 */
131int input_rtcm2f(rtcm_t* rtcm, FILE* fp);
132
133/**
134 * @brief Input RTCM 3 message from file.
135 * @param[in,out] rtcm RTCM control struct
136 * @param[in] fp File pointer
137 * @return Status (-2:end of file, -1:error, 0:no message, 1:obs, 2:eph, ...)
138 */
139int input_rtcm3f(rtcm_t* rtcm, FILE* fp);
140
141/**
142 * @brief Generate RTCM 2 message.
143 * @param[in,out] rtcm RTCM control struct
144 * @param[in] type Message type
145 * @param[in] sync Sync flag (1:another message follows)
146 * @return Status (1:ok, 0:error)
147 */
148int gen_rtcm2(rtcm_t* rtcm, int type, int sync);
149
150/**
151 * @brief Generate RTCM 3 message.
152 * @param[in,out] rtcm RTCM control struct
153 * @param[in] type Message type
154 * @param[in] subtype Message subtype (0:no subtype)
155 * @param[in] sync Sync flag (1:another message follows)
156 * @return Status (1:ok, 0:error)
157 */
158int gen_rtcm3(rtcm_t* rtcm, int type, int subtype, int sync);
159
160/*============================================================================
161 * RTCM Internal Functions (cross-file linkage within the module)
162 *===========================================================================*/
163
164/**
165 * @brief Decode RTCM ver.2 message (called from rtcm.c).
166 * @param[in,out] rtcm RTCM control struct
167 * @return Status (-1:error, 0:no message, 1:obs, 2:eph, ...)
168 */
170
171/**
172 * @brief Decode RTCM ver.3 message (called from rtcm.c).
173 * @param[in,out] rtcm RTCM control struct
174 * @return Status (-1:error, 0:no message, 1:obs, 2:eph, ...)
175 */
177
178/**
179 * @brief Encode RTCM ver.3 message (called from rtcm.c).
180 * @param[in,out] rtcm RTCM control struct
181 * @param[in] type Message type
182 * @param[in] subtype Message subtype
183 * @param[in] sync Sync flag
184 * @return Status (1:ok, 0:error)
185 */
186int encode_rtcm3(rtcm_t* rtcm, int type, int subtype, int sync);
187
188/**
189 * @brief Decode local tropospheric delay correction grid RTCM message.
190 * @param[in,out] rtcm RTCM control struct
191 * @param[in] type Message type
192 * @return Status (1:ok, 0:error)
193 */
194int decode_lcltrop(rtcm_t* rtcm, int type);
195
196/**
197 * @brief Decode local ionospheric delay correction grid RTCM message.
198 * @param[in,out] rtcm RTCM control struct
199 * @param[in] type Message type
200 * @return Status (1:ok, 0:error)
201 */
202int decode_lcliono(rtcm_t* rtcm, int type);
203
204/**
205 * @brief Encode local tropospheric delay correction grid RTCM message.
206 * @param[in,out] rtcm RTCM control struct
207 * @param[in] type Message type
208 * @return Status (1:ok, 0:error)
209 */
210int encode_lcltrop(rtcm_t* rtcm, int type);
211
212/**
213 * @brief Encode local ionospheric delay correction grid RTCM message.
214 * @param[in,out] rtcm RTCM control struct
215 * @param[in] type Message type
216 * @return Status (1:ok, 0:error)
217 */
218int encode_lcliono(rtcm_t* rtcm, int type);
219
220/**
221 * @brief Initialize block information struct.
222 * @param[in,out] b Block information struct
223 */
224void initblkinf(blkinf_t* b);
225
226#ifdef __cplusplus
227}
228#endif
229
230#endif /* MRTK_RTCM_H */
#define MAXSAT
Definition mrtk_coords.c:45
struct nav_s nav_t
Definition mrtk_eph.h:40
MRTKLIB Foundation — Common types, standard includes, and system constants (MAXSAT,...
MRTKLIB Navigation Module — Navigation data types and satellite/nav utility functions.
MRTKLIB Observation Module — Observation data types and utility functions.
static rtcm_t * rtcm
int encode_lcltrop(rtcm_t *rtcm, int type)
Encode local tropospheric delay correction grid RTCM message.
int gen_rtcm2(rtcm_t *rtcm, int type, int sync)
Generate RTCM 2 message.
Definition mrtk_rtcm.c:369
int encode_rtcm3(rtcm_t *rtcm, int type, int subtype, int sync)
Encode RTCM ver.3 message (called from rtcm.c).
lclblock_t * rtcm_lclblk(rtcm_t *rtcm)
Get the local correction block, lazily allocating it on first use.
Definition mrtk_rtcm.c:139
int decode_lcliono(rtcm_t *rtcm, int type)
Decode local ionospheric delay correction grid RTCM message.
void free_rtcm(rtcm_t *rtcm)
Free RTCM control struct.
Definition mrtk_rtcm.c:118
int encode_lcliono(rtcm_t *rtcm, int type)
Encode local ionospheric delay correction grid RTCM message.
int decode_lcltrop(rtcm_t *rtcm, int type)
Decode local tropospheric delay correction grid RTCM message.
int input_rtcm3f(rtcm_t *rtcm, FILE *fp)
Input RTCM 3 message from file.
Definition mrtk_rtcm.c:347
int init_rtcm(rtcm_t *rtcm)
Initialize RTCM control struct.
Definition mrtk_rtcm.c:37
int gen_rtcm3(rtcm_t *rtcm, int type, int subtype, int sync)
Generate RTCM 3 message.
Definition mrtk_rtcm.c:392
int input_rtcm2f(rtcm_t *rtcm, FILE *fp)
Input RTCM 2 message from file.
Definition mrtk_rtcm.c:325
int decode_rtcm2(rtcm_t *rtcm)
Decode RTCM ver.2 message (called from rtcm.c).
Definition mrtk_rtcm2.c:452
void initblkinf(blkinf_t *b)
Initialize block information struct.
int decode_rtcm3(rtcm_t *rtcm)
Decode RTCM ver.3 message (called from rtcm.c).
int input_rtcm2(rtcm_t *rtcm, uint8_t data)
Input RTCM 2 message from stream (byte-by-byte).
Definition mrtk_rtcm.c:159
int input_rtcm3(rtcm_t *rtcm, uint8_t data)
Input RTCM 3 message from stream (byte-by-byte).
Definition mrtk_rtcm.c:289
MRTKLIB Station Module — Site environment parameter I/O.
MRTKLIB Time Module — GNSS time types and conversion functions.
GNSS time representation.
Definition mrtk_time.h:49
Observation data collection.
Definition mrtk_obs.h:59
RTCM control struct type.
Definition mrtk_rtcm.h:50
obs_t obs
Definition mrtk_rtcm.h:57
int nbit
Definition mrtk_rtcm.h:73
dgps_t * dgps
Definition mrtk_rtcm.h:60
gtime_t time
Definition mrtk_rtcm.h:55
nav_t nav
Definition mrtk_rtcm.h:58
uint8_t buff[1200]
Definition mrtk_rtcm.h:75
ssr_t ssr[MAXSAT]
Definition mrtk_rtcm.h:61
int obsflag
Definition mrtk_rtcm.h:65
uint32_t nmsg2[100]
Definition mrtk_rtcm.h:77
gtime_t time_s
Definition mrtk_rtcm.h:56
uint16_t loss[MAXSAT][5+5]
Definition mrtk_rtcm.h:70
int stah
Definition mrtk_rtcm.h:52
char msgtype[256]
Definition mrtk_rtcm.h:63
int staid
Definition mrtk_rtcm.h:51
int ephset
Definition mrtk_rtcm.h:67
char opt[256]
Definition mrtk_rtcm.h:79
int ephsat
Definition mrtk_rtcm.h:66
int seqno
Definition mrtk_rtcm.h:53
int len
Definition mrtk_rtcm.h:74
int outtype
Definition mrtk_rtcm.h:54
sta_t sta
Definition mrtk_rtcm.h:59
char msmtype[7][128]
Definition mrtk_rtcm.h:64
int nbyte
Definition mrtk_rtcm.h:72
double cp[MAXSAT][5+5]
Definition mrtk_rtcm.h:68
uint32_t word
Definition mrtk_rtcm.h:76
uint16_t lock[MAXSAT][5+5]
Definition mrtk_rtcm.h:69
gtime_t lltime[MAXSAT][5+5]
Definition mrtk_rtcm.h:71
lclblock_t * lclblk
Definition mrtk_rtcm.h:80
char msg[128]
Definition mrtk_rtcm.h:62
uint32_t nmsg3[400]
Definition mrtk_rtcm.h:78