33#ifndef GNSS_SDR_RTKLIB_H
34#define GNSS_SDR_RTKLIB_H
44#include <netinet/in.h>
59#define closesocket close
60#define lock_t pthread_mutex_t
61#define initlock(f) pthread_mutex_init(f, NULL)
62#define rtk_lock(f) pthread_mutex_lock(f)
63#define rtk_unlock(f) pthread_mutex_unlock(f)
65#define VER_RTKLIB "2.4.2"
66#define NTRIP_AGENT "RTKLIB/" VER_RTKLIB
67#define NTRIP_CLI_PORT 2101
68#define NTRIP_SVR_PORT 80
69#define NTRIP_MAXRSP 32768
70#define NTRIP_MAXSTR 256
71#define NTRIP_RSP_OK_CLI "ICY 200 OK\r\n"
72#define NTRIP_RSP_OK_SVR "OK\r\n"
73#define NTRIP_RSP_SRCTBL "SOURCETABLE 200 OK\r\n"
74#define NTRIP_RSP_TBLEND "ENDSOURCETABLE"
75#define NTRIP_RSP_HTTP "HTTP/"
76#define NTRIP_RSP_ERROR "ERROR"
80const int TINTACT = 200;
81const int SERIBUFFSIZE = 4096;
82const int TIMETAGH_LEN = 64;
84const int MAXSTATMSG = 32;
86const int FTP_TIMEOUT = 30;
92const int FILEPATHSEP =
'/';
96const double HION = 350000.0;
156const int NSYSGPS = 1;
175const int NSYSGLO = 1;
180const int NSYSGLO = 0;
187const int NSYSGAL = 1;
196const int NSYSQZS = 1;
200const int NSYSQZS = 0;
208const int NSYSBDS = 1;
213const int NSYSBDS = 0;
220const int NSYSIRN = 1;
222const int NSATIRN = 0;
223const int NSYSIRN = 0;
230const int NSYSLEO = 1;
232const int NSATLEO = 0;
233const int NSYSLEO = 0;
236const int NSYS = (NSYSGPS + NSYSGLO + NSYSGAL + NSYSQZS + NSYSBDS + NSYSIRN + NSYSLEO);
244const int MAXSTA = 255;
313const int ARMODE_WLNL = 6;
314const int ARMODE_TCAR = 7;
324#define STR_MODE_R 0x1
325#define STR_MODE_W 0x2
326#define STR_MODE_RW 0x3
334#define STR_NTRIPSVR 6
335#define STR_NTRIPCLI 7
339#define NP_PPP(opt) ((opt)->dynamics ? 9 : 3)
340#define IC_PPP(s, opt) (NP_PPP(opt) + (s))
341#define IT_PPP(opt) (IC_PPP(0, opt) + NSYS)
342#define NR_PPP(opt) (IT_PPP(opt) + ((opt)->tropopt < TROPOPT_EST ? 0 : ((opt)->tropopt == TROPOPT_EST ? 1 : 3)))
343#define IB_PPP(s, opt) (NR_PPP(opt) + (s)-1)
344#define NX_PPP(opt) (IB_PPP(MAXSAT, opt) + 1)
347#define NF_RTK(opt) ((opt)->ionoopt == IONOOPT_IFLC ? 1 : (opt)->nf)
348#define NP_RTK(opt) ((opt)->dynamics == 0 ? 3 : 9)
349#define NI_RTK(opt) ((opt)->ionoopt != IONOOPT_EST ? 0 : MAXSAT)
350#define NT_RTK(opt) ((opt)->tropopt < TROPOPT_EST ? 0 : ((opt)->tropopt < TROPOPT_ESTG ? 2 : 6))
351#define NL_RTK(opt) ((opt)->glomodear != 2 ? 0 : NFREQGLO)
352#define NB_RTK(opt) ((opt)->mode <= PMODE_DGPS ? 0 : MAXSAT * NF_RTK(opt))
353#define NR_RTK(opt) (NP_RTK(opt) + NI_RTK(opt) + NT_RTK(opt) + NL_RTK(opt))
354#define NX_RTK(opt) (NR_RTK(opt) + NB_RTK(opt))
366 unsigned char sat, rcv;
406 double off[
NFREQ][3];
407 double var[
NFREQ][19];
427 double A, e, i0, OMG0, omg, M0, OMGd;
444 double A, e, i0, OMG0, omg, M0, deln, OMGd, idot;
445 double crc, crs, cuc, cus, cic, cis;
455 float has_clock_correction_m;
456 float has_orbit_radial_correction_m;
457 float has_orbit_in_track_correction_m;
458 float has_orbit_cross_track_correction_m;
459 bool apply_has_corrections;
483 double pos[MAXSAT][4];
484 float std[MAXSAT][4];
485 double vel[MAXSAT][4];
486 float vst[MAXSAT][4];
487 float cov[MAXSAT][3];
488 float vco[MAXSAT][3];
496 double clk[MAXSAT][1];
497 float std[MAXSAT][1];
561 double bias[MAXSAT][3];
562 double std[MAXSAT][3];
570 unsigned char msg[29];
672 double yaw_ang, yaw_rate;
673 unsigned char update;
685 unsigned char msg[212];
701 unsigned char health;
744 char stas[MAXSTA][8];
745 double rr[MAXSTA][3];
746 int ns[MAXSTA], nsmax[MAXSTA];
747 int nt[MAXSTA], ntmax[MAXSTA];
785 double lam[MAXSAT][
NFREQ];
786 double cbias[MAXSAT][3];
787 double rbias[
MAXRCV][2][3];
788 double wlbias[MAXSAT];
789 double glo_cpbias[4];
863 unsigned short slipc;
890 char msmtype[6][128];
900 unsigned char buff[1200];
902 unsigned int nmsg2[100];
903 unsigned int nmsg3[400];
929 double cerr[4][
NFREQ * 2];
930 double perr[4][
NFREQ * 2];
931 double gpsglob[
NFREQ];
932 double gloicb[
NFREQ];
939 double mask[
NFREQ][9];
972 double eratio[
NFREQ];
993 unsigned char exsats[MAXSAT];
1000 double odisp[2][6 * 11];
1038 unsigned char vsat[
NFREQ];
1039 unsigned char snr[
NFREQ];
1040 unsigned char fix[
NFREQ];
1041 unsigned char slip[
NFREQ];
1042 unsigned char half[
NFREQ];
1044 unsigned int outc[
NFREQ];
1045 unsigned int slipc[
NFREQ];
1046 unsigned int rejc[
NFREQ];
1052 double ph[2][
NFREQ];
1088 unsigned char valid;
1100 unsigned int inb, inr;
1101 unsigned int outb, outr;
1102 unsigned int tick, tact;
1103 unsigned int inbt, outbt;
1121 FILE *fp_tag =
nullptr;
1122 FILE *fp_tmp =
nullptr;
1123 FILE *fp_tag_tmp =
nullptr;
1125 std::string openpath;
1132 unsigned int tick = 0;
1133 unsigned int tick_f = 0;
1134 unsigned int fpos = 0;
1137 double swapintv = 0;
1147 struct sockaddr_in addr;
1179 char str[NTRIP_MAXSTR];
1180 unsigned char buff[NTRIP_MAXRSP];
1213 unsigned char subfrm[MAXSAT][380];
1216 double icpp[MAXSAT], off[MAXSAT], icpc;
1217 double prCA[MAXSAT], dpCA[MAXSAT];
1229 double receive_time;
1235 unsigned char pbuff[255 + 4 + 2];
1256 unsigned char *buff[3];
1257 unsigned char *sbuf[2];
1258 unsigned char *pbuf[3];
1260 unsigned int nmsg[3][10];
1280 unsigned char time_s;
1281 unsigned char clk_str;
1282 unsigned char clk_ext;
1283 unsigned char smooth;
1284 unsigned char tint_s;
1285 unsigned char nsat, nsig;
1286 unsigned char sats[64];
1287 unsigned char sigs[32];
1288 unsigned char cellmask[64];
1292const double CHISQR[100] = {
1293 10.8, 13.8, 16.3, 18.5, 20.5, 22.5, 24.3, 26.1, 27.9, 29.6,
1294 31.3, 32.9, 34.5, 36.1, 37.7, 39.3, 40.8, 42.3, 43.8, 45.3,
1295 46.8, 48.3, 49.7, 51.2, 52.6, 54.1, 55.5, 56.9, 58.3, 59.7,
1296 61.1, 62.5, 63.9, 65.2, 66.6, 68.0, 69.3, 70.7, 72.1, 73.4,
1297 74.7, 76.0, 77.3, 78.6, 80.0, 81.3, 82.6, 84.0, 85.4, 86.7,
1298 88.0, 89.3, 90.6, 91.9, 93.3, 94.7, 96.0, 97.4, 98.7, 100,
1299 101, 102, 103, 104, 105, 107, 108, 109, 110, 112,
1300 113, 114, 115, 116, 118, 119, 120, 122, 123, 125,
1301 126, 127, 128, 129, 131, 132, 133, 134, 135, 137,
1302 138, 139, 140, 142, 143, 144, 145, 147, 148, 149};
1305const double LAM_CARR[
MAXFREQ] = {
1309const int STRFMT_RTCM2 = 0;
1310const int STRFMT_RTCM3 = 1;
1311const int STRFMT_SP3 = 16;
1312const int STRFMT_RNXCLK = 17;
1313const int STRFMT_SBAS = 18;
1314const int STRFMT_NMEA = 19;
1317const int MAXSTRRTK = 8;
Defines useful mathematical constants and their scaled versions.
const double EFACT_QZS
error factor: QZSS
const double INT_SWAP_TRAC
swap interval of trace file (s)
const int NSYS
number of systems
const double RE_WGS84
earth semimajor axis (WGS84) (m)
const int TROPOPT_SAAS
troposphere option: Saastamoinen model
const int MAXSTRMSG
max length of stream message
const int MINPRNLEO
min satellite sat number of LEO
const double MAXSBSAGEL
max age of SBAS long term corr (s)
const double ERR_SAAS
saastamoinen model error std (m)
const double EFACT_IRN
error factor: IRNSS
const int NFREQ
number of carrier frequencies
const int TROPOPT_ESTG
troposphere option: ZTD+grad estimation
const int NEXOBS
number of extended obs codes
const int PMODE_MOVEB
positioning mode: moving-base
const int SYS_LEO
navigation system: LEO
const int MAXPRNIRN
max satellite sat number of IRNSS
const int TIMES_UTC
time system: utc
const int EPHOPT_SSRCOM
ephemeris option: broadcast + SSR_COM
const int SYS_NONE
navigation system: none
const int IONOOPT_LEX
ionosphere option: QZSS LEX ionospehre
const int ARMODE_CONT
AR mode: continuous.
const int SOLQ_DGPS
solution status: DGPS/DGNSS
const int MAXPRNBDS
max satellite sat number of BeiDou
const int SOLF_LLH
solution format: lat/lon/height
const int MAXSBSURA
max URA of SBAS satellite
const double MAXDTOE_GLO
max time difference to GLONASS Toe (s)
const int SYS_GLO
navigation system: GLONASS
const int MAXBAND
max SBAS band of IGP
const int MAXOBSTYPE
max number of obs type in RINEX
const int MAXOBSBUF
max number of observation data buffer
const int SOLF_STAT
solution format: solution status
const int TROPOPT_COR
troposphere option: ZTD correction
const int NSATGAL
number of Galileo satellites
const double MAXDTOE_SBS
max time difference to SBAS Toe (s)
const unsigned int POLYCRC32
CRC32 polynomial.
const double EFACT_GLO
error factor: GLONASS
const int PMODE_PPP_STATIC
positioning mode: PPP-static
const int IONOOPT_BRDC
ionosphere option: broadcast model
const int MAXPRNGAL
max satellite PRN number of Galileo
const int MAXPRNGLO
max satellite slot number of GLONASS
const int MAXCLI
max client connection for tcp svr
const int MAXSOLBUF
max number of solution buffer
const int PMODE_KINEMA
positioning mode: kinematic
const double PRN_HWBIAS
process noise of h/w bias (m/MHz/sqrt(s))
const int NSATBDS
number of BeiDou satellites
const int IONOOPT_TEC
ionosphere option: IONEX TEC model
const int SYS_BDS
navigation system: BeiDou
const int MINPRNQZS
min satellite PRN number of QZSS
const int MAXNGEO
max number of GEO satellites
const double INT_SWAP_STAT
swap interval of solution status file (s)
const double EFACT_SBS
error factor: SBAS
const double EFACT_BDS
error factor: BeiDou
const int SOLF_XYZ
solution format: x/y/z-ecef
const int SYS_GPS
navigation system: GPS
const int MAXNIGP
max number of IGP in SBAS band
const double MAXGDOP
max GDOP
const int MAXPRNLEO
max satellite sat number of LEO */
const double MAXDTOE_BDS
max time difference to BeiDou Toe (s)
const int SOLQ_PPP
solution status: PPP
void(const char *) fatalfunc_t
fatal callback function type
const int SOLQ_SINGLE
solution status: single
const int MAXFREQ
max NFREQ
const int ARMODE_INST
AR mode: instantaneous.
const double ERR_BRDCI
broadcast iono model error factor
const int SOLF_GSIF
solution format: GSI F1/F2
const int EPHOPT_BRDC
ephemeris option: broadcast ephemeris
const int NSATGLO
number of GLONASS satellites
const int MAXLEAPS
max number of leap seconds table
const int TIMES_JST
time system: jst
const int POSOPT_RINEX
pos option: rinex header pos
const int MAXPRNSBS
max satellite PRN number of SBAS
const int MINPRNIRN
min satellite sat number of IRNSS
const double MAXDTOE_QZS
max time difference to QZSS Toe (s)
const int MAXERRMSG
max length of error/warning message
const int MAXPRNGPS
max satellite PRN number of GPS
const int SOLQ_NONE
solution status: no solution
const int TROPOPT_OFF
troposphere option: correction off
const int ARMODE_PPPAR
AR mode: PPP-AR.
const int PMODE_SINGLE
positioning mode: single
const int TROPOPT_SBAS
troposphere option: SBAS model
const int IONOOPT_IFLC
ionosphere option: L1/L2 or L1/L5 iono-free LC
const double FE_WGS84
earth flattening (WGS84)
const int SYS_ALL
navigation system: all
const int SOLF_NMEA
solution format: NMEA-183
const int MAXSBSMSG
max number of SBAS msg in RTK server
const int MINPRNGAL
min satellite PRN number of Galileo
const int SYS_QZS
navigation system: QZSS
const int NFREQGLO
number of carrier frequencies of GLONASS
const int ARMODE_FIXHOLD
AR mode: fix and hold.
const int IONOOPT_EST
ionosphere option: estimation
const int EPHOPT_SBAS
ephemeris option: broadcast + SBAS
const int MAXSTRPATH
max length of stream path
const double MAXDTOE_GAL
max time difference to Galileo Toe (s)
const double EFACT_GPS
error factor: GPS
const double REL_HUMI
relative humidity for saastamoinen model
const int SOLQ_DR
solution status: dead reckoning
const int TROPOPT_EST
troposphere option: ZTD estimation
const int PMODE_STATIC
positioning mode: static
const int MINPRNQZS_S
min satellite PRN number of QZSS SAIF
const double EFACT_GAL
error factor: Galileo
const int IONOOPT_STEC
ionosphere option: SLANT TEC model
const int MINPRNSBS
min satellite PRN number of SBAS
const int MAXEXFILE
max number of expanded files
const int PMODE_DGPS
positioning mode: DGPS/DGNSS
const unsigned int POLYCRC24Q
CRC24Q polynomial.
const int SOLQ_FIX
solution status: fix
const double MAXDTOE
max time difference to GPS Toe (s)
const int MINPRNGLO
min satellite slot number of GLONASS
const double HION
ionosphere height (m)
const int MAXSOLMSG
max length of solution message
const int NSATQZS
number of QZSS satellites
const int PMODE_FIXED
positioning mode: fixed
const int IONOOPT_OFF
ionosphere option: correction off
const double DTTOL
tolerance of time difference (s)
const double GAP_RESION
default gap to reset ionos parameters (ep)
const int IONOOPT_QZS
ionosphere option: QZSS broadcast model
const int TIMES_GPST
time system: gps time
const int MINPRNGPS
min satellite PRN number of GPS
const int EPHOPT_SSRAPC
ephemeris option: broadcast + SSR_APC
const int IONOOPT_SBAS
ionosphere option: SBAS model
const int ARMODE_OFF
AR mode: off.
const int SOLQ_SBAS
solution status: SBAS
const int SYS_GAL
navigation system: Galileo
const double MAXDTOE_S
max time difference to ephem toe (s) for other
const int MAXOBS
max number of obs in an epoch
const int EPHOPT_PREC
ephemeris option: precise ephemeris
const int SYS_IRN
navigation system: IRNS
const int ARMODE_PPPAR_ILS
AR mode: AR mode: PPP-AR ILS.
const int NSATGPS
number of GPS satellites
const int MAXANT
max length of station name/antenna type
const int SOLQ_FLOAT
solution status: float
const int NSATSBS
number of SBAS satellites
const int MAXPRNQZS_S
max satellite PRN number of QZSS SAIF
const int PMODE_PPP_FIXED
positioning mode: PPP-fixed
const int SOLF_ENU
solution format: e/n/u-baseline
const int MAXRAWLEN
max length of receiver raw message
const int PMODE_PPP_KINEMA
positioning mode: PPP-kinemaric
const int TROPOPT_CORG
troposphere option: ZTD+grad correction
const int MAXRCV
max receiver number (1 to MAXRCV)
const int SYS_SBS
navigation system: SBAS
const double MAXSBSAGEF
max age of SBAS fast correction (s)
const int MAXSOLQ
max number of solution status
const int MAXPRNQZS
max satellite PRN number of QZSS
const int MINPRNBDS
min satellite sat number of BeiDou
const double ERR_CBIAS
code bias error std (m)
const int EPHOPT_LEX
ephemeris option: QZSS LEX ephemeris
constexpr double SPEED_OF_LIGHT_M_S
Speed of light in vacuum [m/s].
constexpr double FREQ1
L1/E1 frequency (Hz).
constexpr double FREQ5
L5/E5a frequency (Hz).
constexpr double FREQ7
E5b frequency (Hz).
constexpr double FREQ9
S frequency (Hz).
constexpr double FREQ2
L2 frequency (Hz).
constexpr double FREQ8
E5a+b frequency (Hz).
constexpr double FREQ6
E6/LEX frequency (Hz).
constexpr int32_t MAXCODE
max number of obs code