36#define PI 3.1415926535897932
37#define D2R (PI / 180.0)
38#define R2D (180.0 / PI)
39#define CLIGHT 299792458.0
40#define SC2RAD 3.1415926535898
59#define FREQ1 1.57542E9
60#define FREQ2 1.22760E9
61#define FREQ5 1.17645E9
62#define FREQ6 1.27875E9
63#define FREQ7 1.20714E9
64#define FREQ8 1.191795E9
65#define FREQ9 2.492028E9
66#define FREQ1_GLO 1.60200E9
67#define DFRQ1_GLO 0.56250E6
68#define FREQ2_GLO 1.24600E9
69#define DFRQ2_GLO 0.43750E6
70#define FREQ3_GLO 1.202025E9
71#define FREQ1a_GLO 1.600995E9
72#define FREQ2a_GLO 1.248060E9
73#define FREQ1_CMP 1.561098E9
82#define LLI_BOCTRK 0x04
89#define P2_11 4.882812500000000E-04
90#define P2_15 3.051757812500000E-05
91#define P2_17 7.629394531250000E-06
92#define P2_19 1.907348632812500E-06
93#define P2_20 9.536743164062500E-07
94#define P2_21 4.768371582031250E-07
95#define P2_23 1.192092895507810E-07
96#define P2_24 5.960464477539063E-08
97#define P2_27 7.450580596923828E-09
98#define P2_29 1.862645149230957E-09
99#define P2_30 9.313225746154785E-10
100#define P2_31 4.656612873077393E-10
101#define P2_32 2.328306436538696E-10
102#define P2_33 1.164153218269348E-10
103#define P2_34 5.820766091346740E-11
104#define P2_35 2.910383045673370E-11
105#define P2_38 3.637978807091710E-12
106#define P2_40 9.094947017729280E-13
107#define P2_43 1.136868377216160E-13
108#define P2_46 1.421085471520200E-14
109#define P2_50 8.881784197001252E-16
110#define P2_55 2.775557561562891E-17
111#define P2_59 1.734723475976810E-18
119#define PREAMB_CNAV 0x8B
121#define ID_NAVSOL 0x0106
122#define ID_NAVTIME 0x0120
123#define ID_RXMRAW 0x0210
124#define ID_RXMSFRB 0x0211
125#define ID_RXMSFRBX 0x0213
126#define ID_RXMRAWX 0x0215
127#define ID_RXMQZSSL6 0x0273
128#define ID_TRKD5 0x030A
129#define ID_TRKMEAS 0x0310
130#define ID_TRKSFRBX 0x030F
142#define P2_10 0.0009765625
147#define CPSTD_VALID 14
150#define ROUND(x) (int)floor((x) + 0.5)
153#define U1(p) (*((uint8_t*)(p)))
154#define I1(p) (*((int8_t*)(p)))
155static uint16_t
U2(uint8_t* p) {
160static uint32_t
U4(uint8_t* p) {
165static int32_t
I4(uint8_t* p) {
170static float R4(uint8_t* p) {
175static double R8(uint8_t* p) {
180static double I8(uint8_t* p) {
return I4(p + 4) * 4294967296.0 +
U4(p); }
183static void setU1(uint8_t* p, uint8_t u) { *p = u; }
184static void setU2(uint8_t* p, uint16_t u) { memcpy(p, &u, 2); }
185static void setU4(uint8_t* p, uint32_t u) { memcpy(p, &u, 4); }
186static void setI1(uint8_t* p, int8_t i) { *p = (uint8_t)i; }
187static void setI2(uint8_t* p, int16_t i) { memcpy(p, &i, 2); }
188static void setI4(uint8_t* p, int32_t i) { memcpy(p, &i, 4); }
189static void setR4(uint8_t* p,
float r) { memcpy(p, &r, 4); }
190static void setR8(uint8_t* p,
double r) { memcpy(p, &r, 8); }
194 uint8_t cka = 0, ckb = 0;
197 for (i = 2; i < len - 2; i++) {
201 return cka == buff[len - 2] && ckb == buff[len - 1];
203static void setcs(uint8_t* buff,
int len) {
204 uint8_t cka = 0, ckb = 0;
207 for (i = 2; i < len - 2; i++) {
324 return (nex < 1) ? -1 : NFREQ;
328 return (nex < 1) ? -1 : NFREQ;
331 return (nex < 2) ? -1 : NFREQ + 1;
335 return (nex < 1) ? -1 : NFREQ;
338 return (nex < 2) ? -1 : NFREQ + 1;
341 return (idx < NFREQ) ? idx : -1;
345 uint8_t* p = raw->
buff + 6;
347 double tow, tt, tadj = 0.0, toff = 0.0, tn;
348 int i, j, prn, sat, n = 0, nsat, week;
352 sprintf(raw->
msgtype,
"UBX RXM-RAW (%4d): nsat=%d", raw->
len,
U1(p + 6));
355 if ((q = strstr(raw->
opt,
"-TADJ="))) {
356 sscanf(q,
"-TADJ=%lf", &tadj);
359 if (raw->
len < 12 + 24 * nsat) {
360 trace(NULL, 2,
"ubx rxmraw length error: len=%d nsat=%d\n", raw->
len, nsat);
368 trace(NULL, 3,
"ubx rxmraw week=0 error: len=%d nsat=%d\n", raw->
len, nsat);
374 toff = (tn - floor(tn + 0.5)) * tadj;
379 for (i = 0, p += 8; i < nsat && i <
MAXOBS; i++, p += 24) {
390 if (strstr(raw->
opt,
"-INVCP")) {
394 trace(NULL, 2,
"ubx rxmraw sat number error: prn=%d\n", prn);
400 raw->
lockt[sat - 1][0] = 0.0;
401 }
else if (tt < 1.0 || 10.0 < tt) {
402 raw->
lockt[sat - 1][0] = 0.0;
404 raw->
lockt[sat - 1][0] += tt;
407 for (j = 1; j < NFREQ + NEXOBS; j++) {
421 uint8_t* p = raw->
buff + 6;
424 double tow, P, L, D, tn, tadj = 0.0, toff = 0.0;
425 int i, j, k, idx, sys, prn, sat, code, slip, halfv, halfc, LLI, n = 0, std_slip = 0;
426 int week, nmeas, ver, gnss, svid, sigid, frqid, lockt, cn0, cpstd, tstat;
429 trace(NULL, 2,
"ubx rxmrawx length error: len=%d\n", raw->
len);
437 if (raw->
len < 24 + 32 * nmeas) {
438 trace(NULL, 2,
"ubx rxmrawx length error: len=%d nmeas=%d\n", raw->
len, nmeas);
442 trace(NULL, 3,
"ubx rxmrawx week=0 error: len=%d nmeas=%d\n", raw->
len, nmeas);
449 sprintf(raw->
msgtype,
"UBX RXM-RAWX (%4d): time=%s nmeas=%d ver=%d", raw->
len, tstr, nmeas, ver);
452 if ((q = strstr(raw->
opt,
"-TADJ="))) {
453 sscanf(q,
"-TADJ=%lf", &tadj);
456 if ((q = strstr(raw->
opt,
"-STD_SLIP="))) {
457 sscanf(q,
"-STD_SLIP=%d", &std_slip);
462 toff = (tn - floor(tn + 0.5)) * tadj;
465 for (i = 0, p += 16; i < nmeas && n <
MAXOBS; i++, p += 32) {
475 cpstd =
U1(p + 28) & 15;
480 if (!(tstat & 2) || L == -0.5 || cpstd >
CPSTD_VALID) {
485 trace(NULL, 2,
"ubx rxmrawx: system error gnss=%d\n", gnss);
488 prn = svid + (sys ==
SYS_QZS ? 192 : 0);
489 if (!(sat =
satno(sys, prn))) {
490 if (sys ==
SYS_GLO && prn == 255) {
493 trace(NULL, 2,
"ubx rxmrawx sat number error: sys=%2d prn=%2d\n", sys, prn);
505 if ((idx =
sig_idx(sys, code)) < 0) {
506 trace(NULL, 2,
"ubx rxmrawx signal error: sat=%2d sigid=%d\n", sat, sigid);
515 L -= toff *
code2freq(sys, code, frqid - 7);
519 if (sys ==
SYS_CMP && (prn <= 5 || prn >= 59) && L != 0.0) {
522 halfv = (tstat & 4) ? 1 : 0;
523 halfc = (tstat & 8) ? 1 : 0;
524 slip = lockt == 0 || lockt * 1E-3 < raw->
lockt[sat - 1][idx] || halfc != raw->
halfc[sat - 1][idx] ||
525 (std_slip && cpstd >= std_slip);
526 raw->
lockt[sat - 1][idx] = lockt * 1E-3;
527 raw->
halfc[sat - 1][idx] = halfc;
530 for (j = 0; j < n; j++) {
539 for (k = 0; k < NFREQ + NEXOBS; k++) {
560 uint8_t* p = raw->
buff + 6;
561 int itow, ftow, week;
563 trace(NULL, 4,
"decode_navsol: len=%d\n", raw->
len);
566 sprintf(raw->
msgtype,
"UBX NAV-SOL (%4d):", raw->
len);
571 if ((
U1(p + 11) & 0x0C) == 0x0C) {
579 int itow, ftow, week;
581 uint8_t* p = raw->
buff + 6;
583 trace(NULL, 4,
"decode_navtime: len=%d\n", raw->
len);
588 if ((
U1(p + 11) & 0x03) == 0x03) {
593 sprintf(raw->
msgtype,
"UBX NAV-TIME (%4d): time=%s", raw->
len, str);
595 if (strstr(raw->
opt,
"-OUT_QZSSL6")) {
597 trace(NULL, 2,
"$TIME,%.0f,%.0f,%.0f,%.0f,%.0f,%.6f\n", ep[0], ep[1], ep[2], ep[3], ep[4], ep[5]);
603 static double adrs[
MAXSAT] = {0};
604 uint8_t* p = raw->
buff + 6;
606 double ts, tr = -1.0, t, tau, utc_gpst, snr, adr, dop;
607 int i, j, n = 0, nch, sys, prn, sat, qi, frq, flag, lock1, lock2, week;
609 trace(NULL, 4,
"decode_trkmeas: len=%d\n", raw->
len);
612 sprintf(raw->
msgtype,
"UBX TRK-MEAS (%4d):", raw->
len);
621 if (raw->
len < 112 + nch * 56) {
622 trace(NULL, 2,
"decode_trkmeas: length error len=%d nch=%2d\n", raw->
len, nch);
626 for (i = 0, p = raw->
buff + 110; i < nch; i++, p += 56) {
630 if ((t =
I8(p + 24) *
P2_32 / 1000.0) > tr) {
638 tr =
ROUND((tr + 0.08) / 0.1) * 0.1;
642 if (tr < t - 302400.0) {
644 }
else if (tr > t + 302400.0) {
651 for (i = 0, p = raw->
buff + 110; i < nch; i++, p += 56) {
655 if (qi < 4 || 7 < qi) {
661 trace(NULL, 2,
"ubx trkmeas: system error\n");
664 prn =
U1(p + 5) + (sys ==
SYS_QZS ? 192 : 0);
665 if (!(sat =
satno(sys, prn))) {
666 trace(NULL, 2,
"ubx trkmeas sat number error: sys=%2d prn=%2d\n", sys, prn);
670 ts =
I8(p + 24) *
P2_32 / 1000.0;
674 ts -= 10800.0 + utc_gpst;
679 if (tau < -302400.0) {
681 }
else if (tau > 302400.0) {
689 snr =
U2(p + 20) / 256.0;
690 adr =
I8(p + 32) *
P2_32 + (flag & 0x40 ? 0.5 : 0.0);
691 dop =
I4(p + 40) *
P2_10 * 10.0;
694 if (lock2 == 0 || lock2 < raw->lockt[sat - 1][0]) {
695 raw->
lockt[sat - 1][1] = 1.0;
697 raw->
lockt[sat - 1][0] = lock2;
700 trace(NULL,2,
"[%2d] qi=%d sys=%d prn=%3d frq=%2d flag=%02X ?=%02X %02X "
701 "%02X %02X %02X %02X %02X lock=%3d %3d ts=%10.3f snr=%4.1f "
702 "dop=%9.3f adr=%13.3f %6.3f\n",
U1(p),qi,
U1(p+4),prn,frq,flag,
704 lock1,lock2,ts,snr,dop,adr,
705 adrs[sat-1]==0.0||dop==0.0?0.0:(adr-adrs[sat-1])-dop);
710 if (!(flag & 0x20)) {
723 raw->
obs.
data[n].
LLI[0] |= lock2 > 142 ? 0 : 2;
725 raw->
obs.
data[n].
LLI[0] |= flag & 0x80 ? 0 : 2;
727 raw->
lockt[sat - 1][1] = 0.0;
729 for (j = 1; j < NFREQ + NEXOBS; j++) {
746 static double adrs[
MAXSAT] = {0};
748 double ts, tr = -1.0, t, tau, adr, dop, snr, utc_gpst;
749 int i, j, n = 0, type, off, len, sys, prn, sat, qi, frq, flag, week;
750 uint8_t* p = raw->
buff + 6;
752 trace(NULL, 4,
"decode_trkd5: len=%d\n", raw->
len);
755 sprintf(raw->
msgtype,
"UBX TRK-D5 (%4d):", raw->
len);
763 switch ((type =
U1(p))) {
777 for (i = 0, p = raw->
buff + off; p - raw->
buff < raw->
len - 2; i++, p += len) {
779 if (qi < 4 || 7 < qi) {
784 t -= 10800.0 + utc_gpst;
795 tr =
ROUND((tr + 0.08) / 0.1) * 0.1;
799 if (tr < t - 302400.0) {
801 }
else if (tr > t + 302400.0) {
808 for (i = 0, p = raw->
buff + off; p - raw->
buff < raw->
len - 2; i++, p += len) {
811 if (qi < 4 || 7 < qi) {
817 trace(NULL, 2,
"ubx trkd5: system error\n");
820 prn =
U1(p + 57) + (sys ==
SYS_QZS ? 192 : 0);
821 frq =
U1(p + 59) - 7;
826 if (!(sat =
satno(sys, prn))) {
827 trace(NULL, 2,
"ubx trkd5 sat number error: sys=%2d prn=%2d\n", sys, prn);
833 ts -= 10800.0 + utc_gpst;
838 if (tau < -302400.0) {
840 }
else if (tau > 302400.0) {
853 dop =
I4(p + 16) *
P2_10 / 4.0;
854 snr =
U2(p + 32) / 256.0;
857 raw->
lockt[sat - 1][1] = 1.0;
861 trace(NULL,2,
"[%2d] qi=%d sys=%d prn=%3d frq=%2d flag=%02X ts=%1.3f "
862 "snr=%4.1f dop=%9.3f adr=%13.3f %6.3f\n",
U1(p+35),qi,
U1(p+56),
863 prn,frq,flag,ts,snr,dop,adr,
864 adrs[sat-1]==0.0||dop==0.0?0.0:(adr-adrs[sat-1])-dop);
869 if (!(flag & 0x08)) {
881 raw->
lockt[sat - 1][1] = 0.0;
883 for (j = 1; j < NFREQ + NEXOBS; j++) {
903 utc[3] += week / 256 * 256;
904 if (utc[3] < week - 127) {
906 }
else if (utc[3] > week + 127) {
909 utc[5] += utc[3] / 256 * 256;
910 if (utc[5] < utc[3] - 127) {
912 }
else if (utc[5] > utc[3] + 127) {
924 if (!strstr(raw->
opt,
"-EPHALL")) {
932 raw->
nav.
eph[sat - 1] = eph;
939 double ion[8], utc[8];
940 int sys =
satsys(sat, NULL);
958 uint8_t *p = raw->
buff + 6 + off, buff[30];
961 if (raw->
len < 48 + off) {
962 trace(NULL, 2,
"ubx rxmsfrbx nav length error: sat=%d len=%d\n", sat, raw->
len);
966 trace(NULL, 3,
"ubx rxmsfrbx nav unsupported sat=%d len=%d\n", sat, raw->
len);
969 for (i = 0; i < 10; i++, p += 4) {
973 if (id < 1 || id > 5) {
974 trace(NULL, 2,
"ubx rxmsfrbx nav subframe id error: sat=%d id=%d\n", sat,
id);
977 memcpy(raw->
subfrm[sat - 1] + (
id - 1) * 30, buff, 30);
982 if (
id == 4 ||
id == 5) {
984 memset(raw->
subfrm[sat - 1] + (
id - 1) * 30, 0, 30);
992 double ion[4] = {0}, utc[8] = {0};
993 uint8_t *p = raw->
buff + 6 + off, buff[32], crc_buff[26] = {0};
994 int i, j, part1, page1, part2, page2, type;
996 if (raw->
len < 40 + off) {
997 trace(NULL, 2,
"ubx rxmsfrbx enav length error: sat=%d len=%d\n", sat, raw->
len);
1000 for (i = 0; i < 8; i++, p += 4) {
1005 part2 =
getbitu(buff, 128, 1);
1006 page2 =
getbitu(buff, 129, 1);
1008 if (part1 != 0 || part2 != 1) {
1009 trace(NULL, 3,
"ubx rxmsfrbx enav page even/odd error: sat=%d\n", sat);
1012 if (page1 == 1 || page2 == 1) {
1017 for (i = 0, j = 4; i < 15; i++, j += 8) {
1020 for (i = 0, j = 118; i < 11; i++, j += 8) {
1024 trace(NULL, 2,
"ubx rxmsfrbx enav crc error: sat=%d\n", sat);
1034 for (i = 0, j = 2; i < 14; i++, j += 8) {
1037 for (i = 14, j = 130; i < 16; i++, j += 8) {
1047 if (eph.
sat != sat) {
1048 trace(NULL, 2,
"ubx rxmsfrbx enav satellite error: sat=%d %d\n", sat, eph.
sat);
1051 eph.
code |= (1 << 0) | (1 << 2);
1057 if (!strstr(raw->
opt,
"-EPHALL")) {
1063 raw->
nav.
eph[sat - 1] = eph;
1071 double ion[8], utc[8];
1072 uint8_t *p = raw->
buff + 6 + off, buff[38] = {0};
1073 int i, id, pgn, prn;
1075 if (raw->
len < 48 + off) {
1076 trace(NULL, 2,
"ubx rxmsfrbx cnav length error: sat=%d len=%d\n", sat, raw->
len);
1079 for (i = 0; i < 10; i++, p += 4) {
1083 if (
id < 1 || 5 <
id) {
1084 trace(NULL, 2,
"ubx rxmsfrbx cnav subframe id error: sat=%2d\n", sat);
1089 if (prn >= 6 && prn <= 58) {
1090 memcpy(raw->
subfrm[sat - 1] + (
id - 1) * 38, buff, 38);
1096 }
else if (
id == 5) {
1109 if (
id == 1 && pgn >= 1 && pgn <= 10) {
1110 memcpy(raw->
subfrm[sat - 1] + (pgn - 1) * 38, buff, 38);
1117 }
else if (
id == 5 && pgn == 102) {
1118 memcpy(raw->
subfrm[sat - 1] + 10 * 38, buff, 38);
1128 if (!strstr(raw->
opt,
"-EPHALL")) {
1134 raw->
nav.
eph[sat - 1] = eph;
1142 double utc_glo[8] = {0};
1143 int i, j, k, m, prn;
1144 uint8_t *p = raw->
buff + 6 + off, buff[64], *fid;
1148 if (raw->
len < 24 + off) {
1149 trace(NULL, 2,
"ubx rxmsfrbx gnav length error: len=%d\n", raw->
len);
1152 for (i = k = 0; i < 4; i++, p += 4) {
1153 for (j = 0; j < 4; j++) {
1154 buff[k++] = p[3 - j];
1159 trace(NULL, 2,
"ubx rxmsfrbx gnav hamming error: sat=%2d\n", sat);
1163 if (m < 1 || 15 < m) {
1164 trace(NULL, 2,
"ubx rxmsfrbx gnav string no error: sat=%2d\n", sat);
1168 fid = raw->
subfrm[sat - 1] + 150;
1169 if (fid[0] != buff[12] || fid[1] != buff[13]) {
1170 for (i = 0; i < 4; i++) {
1171 memset(raw->
subfrm[sat - 1] + i * 10, 0, 10);
1173 memcpy(fid, buff + 12, 2);
1175 memcpy(raw->
subfrm[sat - 1] + (m - 1) * 10, buff, 10);
1185 if (!strstr(raw->
opt,
"-EPHALL")) {
1190 raw->
nav.
geph[prn - 1] = geph;
1194 }
else if (m == 5) {
1206 uint8_t *p = raw->
buff + 6 + off, buff[32];
1208 if (raw->
len < 40 + off) {
1209 trace(NULL, 2,
"ubx rxmsfrbx snav length error: len=%d\n", raw->
len);
1216 for (i = 0; i < 8; i++, p += 4) {
1225 uint8_t* p = raw->
buff + 6;
1229 sprintf(raw->
msgtype,
"UBX RXM-SFRBX (%4d): sys=%d prn=%3d", raw->
len,
U1(p),
U1(p + 1));
1232 trace(NULL, 2,
"ubx rxmsfrbx sys id error: sys=%d\n",
U1(p));
1235 prn =
U1(p + 1) + ((sys ==
SYS_QZS) ? 192 : 0);
1236 if (!(sat =
satno(sys, prn))) {
1237 if (sys ==
SYS_GLO && prn == 255) {
1240 trace(NULL, 2,
"ubx rxmsfrbx sat number error: sys=%d prn=%d\n", sys, prn);
1265 uint8_t* p = raw->
buff + 6;
1269 sprintf(raw->
msgtype,
"UBX TRK-SFRBX (%4d): sys=%d prn=%3d", raw->
len,
U1(p + 1),
U1(p + 2));
1272 trace(NULL, 2,
"ubx trksfrbx sys id error: sys=%d\n",
U1(p + 1));
1275 prn =
U1(p + 2) + (sys ==
SYS_QZS ? 192 : 0);
1276 if (!(sat =
satno(sys, prn))) {
1277 trace(NULL, 2,
"ubx trksfrbx sat number error: sys=%d prn=%d\n", sys, prn);
1299 uint8_t *p = raw->
buff + 6, buff[30];
1300 int i, sys, prn, sat, id;
1303 sprintf(raw->
msgtype,
"UBX RXM-SFRB (%4d): prn=%2d", raw->
len,
U1(p + 1));
1305 if (raw->
len < 42) {
1306 trace(NULL, 2,
"ubx rxmsfrb length error: len=%d\n", raw->
len);
1312 if (!(sat =
satno(sys, prn))) {
1313 trace(NULL, 2,
"ubx rxmsfrb satellite error: prn=%d\n", prn);
1317 for (i = 0, p += 2; i < 10; i++, p += 4) {
1321 if (
id >= 1 &&
id <= 5) {
1322 memcpy(raw->
subfrm[sat - 1] + (
id - 1) * 30, buff, 30);
1325 }
else if (
id == 4) {
1330 for (i = 0, p += 2; i < 10; i++, p += 4) {
1342 static int count[16][2] = {{0}};
1343 uint8_t* p = raw->
buff + 6;
1345 char buff[1024] =
"", *q = buff;
1346 int i, ver, prn, msg, nerr, stat, ret;
1348 if (raw->
len < 272) {
1349 trace(NULL, 2,
"ubx rxmqzssl6 length error: len=%d\n", raw->
len);
1353 prn =
U1(p + 1) + 192;
1354 msg = (
U2(p + 10) >> 10) & 1;
1355 cn0 =
U2(p + 2) / 256.0;
1356 time =
U4(p + 4) * 1e-3;
1358 stat = (
U2(p + 10) >> 12) & 3;
1361 sprintf(raw->
msgtype,
"UBX RXM-QZSSL6(%4d): ver=%d prn=%2d msg=%s cn0=%.1f nerr=%2d stat=%d", raw->
len, ver,
1362 prn, msg ?
"L6E" :
"L6D", cn0, nerr, stat);
1364 if (strstr(raw->
opt,
"-OUT_QZSSL6") && prn - 192 < 16) {
1366 count[prn - 192][stat == 1 ? 0 : 1]++;
1369 trace(NULL, 2,
"$CH,%.3f,%s,%d,%d,%.1f,%.9f,%.3f,%.3f,%d,%d\n", time, msg ?
"L6E" :
"L6D", prn, 0, cn0, 0.0,
1370 0.0, 0.0, count[prn - 192][0], count[prn - 192][1]);
1371 for (i = 0; i < 250; i++) {
1372 q += sprintf(q,
"%02X",
U1(p + 14 + i));
1374 trace(NULL, 2,
"$L6FRM,%.3f,%s,%d,%d,%s\n", time, msg ?
"L6E" :
"L6D", prn, nerr, buff);
1379 memcpy(
rtcm->buff, p + 14, 250);
1390 int type = (
U1(raw->
buff + 2) << 8) +
U1(raw->
buff + 3);
1392 trace(NULL, 3,
"decode_ubx: type=%04x len=%d\n", type, raw->
len);
1396 trace(NULL, 2,
"ubx checksum error: type=%04x len=%d\n", type, raw->
len);
1422 sprintf(raw->
msgtype,
"UBX 0x%02X 0x%02X (%4d)", type >> 8, type & 0xFF, raw->
len);
1465 trace(NULL, 5,
"input_ubx: data=%02x\n", data);
1468 if (raw->
nbyte == 0) {
1477 if (raw->
nbyte == 6) {
1479 trace(NULL, 2,
"ubx length error: len=%d\n", raw->
len);
1502 trace(NULL, 4,
"input_ubxf:\n");
1505 if (raw->
nbyte == 0) {
1507 if ((data = fgetc(fp)) == EOF) {
1518 if (fread(raw->
buff + 2, 1, 4, fp) < 4) {
1524 trace(NULL, 2,
"ubx length error: len=%d\n", raw->
len);
1528 if (fread(raw->
buff + 6, 1, raw->
len - 6, fp) < (
size_t)(raw->
len - 6)) {
1539 if (sscanf(s,
"0x%X", &n) == 1) {
1590extern int gen_ubx(
const char* msg, uint8_t* buff) {
1591 const char* cmd[] = {
"PRT",
"USB",
"MSG",
"NMEA",
"RATE",
"CFG",
"TP",
"NAV2",
1592 "DAT",
"INF",
"RST",
"RXM",
"ANT",
"FXN",
"SBAS",
"LIC",
1593 "TM",
"TM2",
"TMODE",
"EKF",
"GNSS",
"ITFM",
"LOGFILTER",
"NAV5",
1594 "NAVX5",
"ODO",
"PM2",
"PWR",
"RINV",
"SMGR",
"TMODE2",
"TMODE3",
1595 "TPS",
"TXSLOT",
"VALDEL",
"VALGET",
"VALSET",
""};
1596 const uint8_t
id[] = {0x00, 0x1B, 0x01, 0x17, 0x08, 0x09, 0x07, 0x1A, 0x06, 0x02, 0x04, 0x11, 0x13,
1597 0x0E, 0x16, 0x80, 0x10, 0x19, 0x1D, 0x12, 0x3E, 0x39, 0x47, 0x24, 0x23, 0x1E,
1598 0x3B, 0x57, 0x34, 0x62, 0x3D, 0x71, 0x31, 0x53, 0x8c, 0x8b, 0x8a};
1599 const int prm[][32] = {
1607 {
FU1,
FU1,
FU2,
FU1,
FU1,
FU1,
FU1,
FI4,
FU1,
FU1,
FU1,
FU1,
1608 FU1,
FU1,
FU2,
FU2,
FU2,
FU2,
FU2,
FU1,
FU1,
FU2,
FU4,
FU4},
1610 {
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1},
1620 {
FU1,
FU1,
FU1,
FU1,
FU4,
FU2,
FU2,
FU1,
FU1,
FU2},
1624 {
FU2,
FU1,
FU1,
FI4,
FU4,
FI1,
FU1,
FU2,
FU2,
FU2,
FU2,
FU1,
1625 FU1,
FU1,
FU1,
FU1,
FU1,
FU2,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1},
1626 {
FU2,
FU2,
FU4,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
1627 FU2,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU2},
1629 {
FU1,
FU1,
FU1,
FU1,
FU4,
FU4,
FU4,
FU4,
FU2,
FU2},
1632 {
FU1,
FU1,
FU2,
FU2,
FU1,
FU1,
FU2,
FU2,
FU2,
FU2,
FU4},
1634 {
FU1,
FU1,
FU2,
FI4,
FI4,
FI4,
FI1,
FI1,
FI1,
FU1,
FU4,
1635 FU4,
FU4,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1,
FU1},
1636 {
FU1,
FU1,
FU1,
FU1,
FI2,
FI2,
FU4,
FU4,
FU4,
FU4,
FI4,
FU4},
1643 char mbuff[1024], *args[32], *p;
1644 int i, j, n, narg = 0;
1646 trace(NULL, 4,
"gen_ubxf: msg=%s\n", msg);
1649 for (p = strtok(mbuff,
" "); p && narg < 32; p = strtok(NULL,
" ")) {
1652 if (narg < 1 || strncmp(args[0],
"CFG-", 4)) {
1656 for (i = 0; *cmd[i]; i++) {
1657 if (!strcmp(args[0] + 4, cmd[i])) {
1670 for (j = 1; prm[i][j - 1] || j < narg; j++) {
1671 switch (prm[i][j - 1]) {
1673 setU1(q, j < narg ? (uint8_t)
stoi(args[j]) : 0);
1677 setU2(q, j < narg ? (uint16_t)
stoi(args[j]) : 0);
1681 setU4(q, j < narg ? (uint32_t)
stoi(args[j]) : 0);
1685 setI1(q, j < narg ? (int8_t)
stoi(args[j]) : 0);
1689 setI2(q, j < narg ? (int16_t)
stoi(args[j]) : 0);
1693 setI4(q, j < narg ? (int32_t)
stoi(args[j]) : 0);
1697 setR4(q, j < narg ? (
float)atof(args[j]) : 0);
1701 setR8(q, j < narg ? (
double)atof(args[j]) : 0);
1705 sprintf((
char*)q,
"%-32.32s", j < narg ? args[j] :
"");
1709 setU1(q, j < narg ? (uint8_t)
stoi(args[j]) : 0);
1714 n = (int)(q - buff) + 2;
1715 setU2(buff + 4, (uint16_t)(n - 8));
1718 trace(NULL, 5,
"gen_ubx: buff=\n");
1719 traceb(NULL, 5, buff, n);
uint32_t rtk_crc24q(const uint8_t *buff, int len)
Compute CRC-24Q parity for SBAS and RTCM3.
void setbitu(uint8_t *buff, int pos, int len, uint32_t data)
Set unsigned bits in byte data.
uint32_t getbitu(const uint8_t *buff, int pos, int len)
Extract unsigned bits from byte data.
MRTKLIB Bits Module — Binary bit operations and CRC functions.
int satsys(int sat, int *prn)
MRTKLIB Broadcast Ephemeris Module — Satellite orbit/clock types and Kepler/GLONASS/SBAS orbit comput...
double code2freq(int sys, uint8_t code, int fcn)
MRTKLIB MADOCA-PPP Module — QZSS L6E CSSR message decode functions.
void matcpy(double *A, const double *B, int n, int m)
Copy matrix.
MRTKLIB Matrix Module — Matrix/vector operations and estimation.
int satno(int sys, int prn)
Convert satellite system+prn/slot number to satellite number.
MRTKLIB Navigation Module — Navigation data types and satellite/nav utility functions.
int code2freq_idx(int sys, uint8_t code)
Convert system and obs code to frequency index (obsdef-based).
MRTKLIB Observation Module — Observation data types and utility functions.
static int decode_rxmraw(raw_t *raw)
static void setI2(uint8_t *p, int16_t i)
static int decode_gnav(raw_t *raw, int sat, int off, int frq)
static int decode_nav(raw_t *raw, int sat, int off)
static int stoi(const char *s)
static int decode_trksfrbx(raw_t *raw)
static int sync_ubx(uint8_t *buff, uint8_t data)
int gen_ubx(const char *msg, uint8_t *buff)
int input_ubxf(raw_t *raw, rtcm_t *rtcm, FILE *fp)
static void setI4(uint8_t *p, int32_t i)
static int decode_snav(raw_t *raw, int prn, int off)
static int decode_enav(raw_t *raw, int sat, int off)
static int decode_rxmsfrb(raw_t *raw)
static void adj_utcweek(gtime_t time, double *utc)
static void setU1(uint8_t *p, uint8_t u)
static int decode_rxmqzssl6(raw_t *raw, rtcm_t *rtcm)
static int decode_rxmrawx(raw_t *raw)
static int decode_navtime(raw_t *raw)
static double I8(uint8_t *p)
static void setI1(uint8_t *p, int8_t i)
static int decode_ubx(raw_t *raw, rtcm_t *rtcm)
static int decode_trkmeas(raw_t *raw)
static int sig_idx(int sys, uint8_t code)
static int decode_cnav(raw_t *raw, int sat, int off)
static int decode_ionutc(raw_t *raw, int sat)
static int ubx_sig(int sys, int sigid)
static void setcs(uint8_t *buff, int len)
static int ubx_sys(int gnssid)
static void setR4(uint8_t *p, float r)
static int checksum(uint8_t *buff, int len)
static void setR8(uint8_t *p, double r)
static int decode_rxmsfrbx(raw_t *raw)
static void setU4(uint8_t *p, uint32_t u)
static void setU2(uint8_t *p, uint16_t u)
static int decode_eph(raw_t *raw, int sat)
static int decode_trkd5(raw_t *raw)
static int decode_navsol(raw_t *raw)
int input_ubx(raw_t *raw, rtcm_t *rtcm, uint8_t data)
int decode_qzss_l6frame(rtcm_t *rtcm, int is_l6d)
Route one QZSS L6 frame received in a UBX/SBF container.
int decode_frame(const uint8_t *buff, eph_t *eph, alm_t *alm, double *ion, double *utc)
int test_glostr(const uint8_t *buff)
int decode_glostr(const uint8_t *buff, geph_t *geph, double *utc)
int decode_bds_d2(const uint8_t *buff, eph_t *eph, double *utc)
int decode_gal_inav(const uint8_t *buff, eph_t *eph, double *ion, double *utc)
int decode_bds_d1(const uint8_t *buff, eph_t *eph, double *ion, double *utc)
MRTKLIB Receiver Raw Data Module — Receiver raw data types and decoder functions for various GNSS rec...
MRTKLIB RTCM Module — RTCM message types and functions.
int sbsdecodemsg(gtime_t time, int prn, const uint32_t *words, sbsmsg_t *sbsmsg)
Decode SBAS message frame words.
MRTKLIB SBAS Module — SBAS message decoding and corrections.
MRTKLIB System Module — OS/filesystem utility functions.
gtime_t gpst2time(int week, double sec)
Convert GPS week/tow to gtime_t.
void time2epoch(gtime_t t, double *ep)
Convert gtime_t struct to calendar day/time.
void time2str(gtime_t t, char *s, int n)
Convert gtime_t struct to string.
gtime_t gpst2utc(gtime_t t)
Convert GPS time to UTC considering leap seconds.
double timediff(gtime_t t1, gtime_t t2)
Compute time difference (t1 - t2).
double time2gpst(gtime_t t, int *week)
Convert gtime_t to GPS week/tow.
gtime_t timeadd(gtime_t t, double sec)
Add seconds to gtime_t.
char * time_str(gtime_t t, int n)
Get time string (not reentrant).
MRTKLIB Time Module — GNSS time types and conversion functions.
void traceb(mrtk_ctx_t *ctx, int level, const uint8_t *p, int n)
Output trace binary data.
void trace(mrtk_ctx_t *ctx, int level, const char *format,...)
Output trace message.
MRTKLIB Trace Module — debug trace and logging functions.
GPS/GAL/QZS/BDS/IRN broadcast ephemeris type.
GLONASS broadcast ephemeris type.
GNSS time representation.
Receiver raw data control type.
uint8_t subfrm[MAXSAT][380]
double lockt[MAXSAT][5+5]
uint8_t halfc[MAXSAT][5+5]
RTCM control struct type.