34#define PI 3.1415926535897932
35#define D2R (PI / 180.0)
36#define R2D (180.0 / PI)
37#define CLIGHT 299792458.0
38#define SC2RAD 3.1415926535898
57#define FREQ1 1.57542E9
58#define FREQ2 1.22760E9
59#define FREQ5 1.17645E9
60#define FREQ6 1.27875E9
61#define FREQ7 1.20714E9
62#define FREQ8 1.191795E9
63#define FREQ9 2.492028E9
64#define FREQ1_GLO 1.60200E9
65#define DFRQ1_GLO 0.56250E6
66#define FREQ2_GLO 1.24600E9
67#define DFRQ2_GLO 0.43750E6
68#define FREQ3_GLO 1.202025E9
69#define FREQ1a_GLO 1.600995E9
70#define FREQ2a_GLO 1.248060E9
71#define FREQ1_CMP 1.561098E9
81#define P2_11 4.882812500000000E-04
82#define P2_15 3.051757812500000E-05
83#define P2_17 7.629394531250000E-06
84#define P2_19 1.907348632812500E-06
85#define P2_20 9.536743164062500E-07
86#define P2_21 4.768371582031250E-07
87#define P2_23 1.192092895507810E-07
88#define P2_24 5.960464477539063E-08
89#define P2_27 7.450580596923828E-09
90#define P2_29 1.862645149230957E-09
91#define P2_30 9.313225746154785E-10
92#define P2_31 4.656612873077393E-10
93#define P2_32 2.328306436538696E-10
94#define P2_33 1.164153218269348E-10
95#define P2_34 5.820766091346740E-11
96#define P2_35 2.910383045673370E-11
97#define P2_38 3.637978807091710E-12
98#define P2_40 9.094947017729280E-13
99#define P2_43 1.136868377216160E-13
100#define P2_46 1.421085471520200E-14
101#define P2_50 8.881784197001252E-16
102#define P2_55 2.775557561562891E-17
103#define P2_59 1.734723475976810E-18
107#define CRESSYNC "$BIN"
110#define ID_CRESGLOEPH 65
111#define ID_CRESGLORAW 66
112#define ID_CRESRAW2 76
113#define ID_CRESWAAS 80
114#define ID_CRESIONUTC 94
118#define SNR2CN0_L1 30.0
119#define SNR2CN0_L2 30.0
122#define U1(p) (*((uint8_t*)(p)))
123#define I1(p) (*((int8_t*)(p)))
124static uint16_t
U2(uint8_t* p) {
129static uint32_t
U4(uint8_t* p) {
134static int16_t
I2(uint8_t* p) {
139static int32_t
I4(uint8_t* p) {
144static float R4(uint8_t* p) {
149static double R8(uint8_t* p) {
156static int chksum(
const uint8_t* buff,
int len) {
160 for (i = 8; i < len - 4; i++) {
163 trace(NULL, 4,
"checksum=%02X%02X %02X%02X:%02X%02X\n", sum >> 8, sum & 0xFF, buff[len - 3], buff[len - 4],
164 buff[len - 2], buff[len - 1]);
165 return (sum >> 8) == buff[len - 3] && (sum & 0xFF) == buff[len - 4] && buff[len - 2] == 0x0D &&
166 buff[len - 1] == 0x0A;
171 double tow, pos[3], vel[3], std;
173 uint8_t* p = raw->
buff + 8;
175 trace(NULL, 4,
"decode_crespos: len=%d\n", raw->
len);
177 if (raw->
len != 64) {
178 trace(NULL, 2,
"crescent bin 1 message length error: len=%d\n", raw->
len);
196 }
else if (mode > 4) {
198 }
else if (mode > 1) {
203 trace(NULL, 3,
"$BIN1 %s %13.9f %14.9f %10.4f %4d %3d %.3f\n", tstr, pos[0], pos[1], pos[2], mode_val, ns, std);
209 double tow, tows, toff = 0.0, cp, pr, dop, snr, freq =
FREQ1;
210 int i, j, n, prn, sat, week, word2, lli = 0;
211 uint32_t word1, sn, sc;
212 uint8_t* p = raw->
buff + 8;
214 trace(NULL, 4,
"decode_cresraw: len=%d\n", raw->
len);
216 if (raw->
len != 312) {
217 trace(NULL, 2,
"crescent bin 96 message length error: len=%d\n", raw->
len);
222 tows = floor(tow * 1000.0 + 0.5) / 1000.0;
226 if (strstr(raw->
opt,
"-TTCORR")) {
227 toff =
CLIGHT * (tows - tow);
229 for (i = n = 0, p += 12; i < 12 && n <
MAXOBS; i++, p += 24) {
232 if ((prn = word1 & 0xFF) == 0) {
236 trace(NULL, 2,
"creasent bin 96 satellite number error: prn=%d\n", prn);
239 pr =
R8(p + 8) - toff;
240 cp =
R8(p + 16) - toff;
244 sn = (word1 >> 8) & 0xFF;
245 snr = sn == 0 ? 0.0 : 10.0 * log10(0.8192 * sn) +
SNR2CN0_L1;
246 sc = (uint32_t)(word1 >> 24);
248 lli = (int)((uint8_t)sc - (uint8_t)raw->
lockt[sat - 1][0]) > 0;
250 raw->
lockt[sat - 1][0] = (uint8_t)sc;
251 dop = word2 / 16 / 4096.0;
262 for (j = 1; j < NFREQ; j++) {
277 double tow, tows, toff = 0.0, cp[2] = {0}, pr1, pr[2] = {0}, dop[2] = {0}, snr[2] = {0};
279 int i, j, n = 0, prn, sat, week, lli[2] = {0};
280 uint32_t word1, word2, word3, sc, sn;
281 uint8_t* p = raw->
buff + 8;
283 trace(NULL, 4,
"decode_cresraw2: len=%d\n", raw->
len);
285 if (raw->
len != 460) {
286 trace(NULL, 2,
"crescent bin 76 message length error: len=%d\n", raw->
len);
291 tows = floor(tow * 1000.0 + 0.5) / 1000.0;
295 if (strstr(raw->
opt,
"-TTCORR")) {
296 toff =
CLIGHT * (tows - tow);
301 for (i = 0, p += 16; i < 15 && n <
MAXOBS; i++) {
302 word1 =
U4(p + 324 + 4 * i);
303 if ((prn = word1 & 0xFF) == 0) {
307 trace(NULL, 2,
"creasent bin 76 satellite number error: prn=%d\n", prn);
310 pr1 = (word1 >> 13) * 256.0;
312 word1 =
U4(p + 144 + 12 * i);
313 word2 =
U4(p + 148 + 12 * i);
314 word3 =
U4(p + 152 + 12 * i);
316 snr[0] = sn == 0 ? 0.0 : 10.0 * log10(0.1024 * sn) +
SNR2CN0_L1;
317 sc = (uint32_t)(word1 >> 24);
319 lli[0] = (int)((uint8_t)sc - (uint8_t)raw->
lockt[sat - 1][0]) > 0;
323 lli[0] |= ((word1 >> 12) & 7) ? 2 : 0;
324 raw->
lockt[sat - 1][0] = (uint8_t)sc;
325 dop[0] = ((word2 >> 1) & 0x7FFFFF) / 512.0;
326 if ((word2 >> 24) & 1) {
329 pr[0] = pr1 + (word3 & 0xFFFF) / 256.0;
330 cp[0] = floor(pr[0] * freq[0] /
CLIGHT / 8192.0) * 8192.0;
331 cp[0] += ((word2 & 0xFE000000) + ((word3 & 0xFFFF0000) >> 7)) / 524288.0;
332 if (cp[0] - pr[0] * freq[0] /
CLIGHT < -4096.0) {
334 }
else if (cp[0] - pr[0] * freq[0] /
CLIGHT > 4096.0) {
339 word1 =
U4(p + 12 * i);
340 word2 =
U4(p + 4 + 12 * i);
341 word3 =
U4(p + 8 + 12 * i);
343 snr[1] = sn == 0 ? 0.0 : 10.0 * log10(0.1164 * sn) +
SNR2CN0_L2;
344 sc = (uint32_t)(word1 >> 24);
346 lli[1] = (int)((uint8_t)sc - (uint8_t)raw->
lockt[sat - 1][1]) > 0;
350 lli[1] |= ((word1 >> 12) & 7) ? 2 : 0;
351 raw->
lockt[sat - 1][1] = (uint8_t)sc;
352 dop[1] = ((word2 >> 1) & 0x7FFFFF) / 512.0;
353 if ((word2 >> 24) & 1) {
356 pr[1] = (word3 & 0xFFFF) / 256.0;
359 if (pr[1] - pr[0] < -128.0) {
361 }
else if (pr[1] - pr[0] > 128.0) {
364 cp[1] = floor(pr[1] * freq[1] /
CLIGHT / 8192.0) * 8192.0;
365 cp[1] += ((word2 & 0xFE000000) + ((word3 & 0xFFFF0000) >> 7)) / 524288.0;
366 if (cp[1] - pr[1] * freq[1] /
CLIGHT < -4096.0) {
368 }
else if (cp[1] - pr[1] * freq[1] /
CLIGHT > 4096.0) {
377 for (j = 0; j < NFREQ; j++) {
378 if (j == 0 || (j == 1 && i < 12)) {
379 raw->
obs.
data[n].
P[j] = pr[j] == 0.0 ? 0.0 : pr[j] - toff;
380 raw->
obs.
data[n].
L[j] = cp[j] == 0.0 ? 0.0 : cp[j] - toff * freq[j] /
CLIGHT;
381 raw->
obs.
data[n].
D[j] = -(float)dop[j];
396 if (strstr(raw->
opt,
"-ENAGLO")) {
405 int i, j, k, prn, sat;
406 uint8_t *p = raw->
buff + 8, buff[90];
408 trace(NULL, 4,
"decode_creseph: len=%d\n", raw->
len);
410 if (raw->
len != 140) {
411 trace(NULL, 2,
"crescent bin 95 message length error: len=%d\n", raw->
len);
416 trace(NULL, 2,
"crescent bin 95 satellite number error: prn=%d\n", prn);
419 for (i = 0; i < 3; i++) {
420 for (j = 0; j < 10; j++) {
421 word =
U4(p + 8 + i * 40 + j * 4) >> 6;
422 for (k = 0; k < 3; k++) {
423 buff[i * 30 + j * 3 + k] = (uint8_t)((word >> (8 * (2 - k))) & 0xFF);
428 trace(NULL, 2,
"crescent bin 95 navigation frame error: prn=%d\n", prn);
431 if (!strstr(raw->
opt,
"-EPHALL")) {
437 raw->
nav.
eph[sat - 1] = eph;
445 uint8_t* p = raw->
buff + 8;
447 trace(NULL, 4,
"decode_cresionutc: len=%d\n", raw->
len);
449 if (raw->
len != 108) {
450 trace(NULL, 2,
"crescent bin 94 message length error: len=%d\n", raw->
len);
453 for (i = 0; i < 8; i++) {
468 uint8_t* p = raw->
buff + 8;
470 trace(NULL, 4,
"decode_creswaas: len=%d\n", raw->
len);
472 if (raw->
len != 52) {
473 trace(NULL, 2,
"creasent bin 80 message length error: len=%d\n", raw->
len);
478 trace(NULL, 2,
"creasent bin 80 satellite number error: prn=%d\n", prn);
486 }
else if (raw->
sbsmsg.
tow > tow + 302400.0) {
490 for (i = k = 0; i < 8 && k < 29; i++) {
491 word =
U4(p + 8 + i * 4);
492 for (j = 0; j < 4 && k < 29; j++) {
493 raw->
sbsmsg.
msg[k++] = (uint8_t)(word >> (3 - j) * 8);
502 double tow, tows, toff = 0.0, cp[2] = {0}, pr1, pr[2] = {0}, dop[2] = {0}, snr[2] = {0};
504 int i, j, n = 0, prn, sat, week, lli[2] = {0};
505 uint32_t word1, word2, word3, sc, sn;
506 uint8_t* p = raw->
buff + 8;
508 trace(NULL, 4,
"decode_cregloraw: len=%d\n", raw->
len);
510 if (!strstr(raw->
opt,
"-ENAGLO")) {
514 if (raw->
len != 364) {
515 trace(NULL, 2,
"crescent bin 66 message length error: len=%d\n", raw->
len);
520 tows = floor(tow * 1000.0 + 0.5) / 1000.0;
524 if (strstr(raw->
opt,
"-TTCORR")) {
525 toff =
CLIGHT * (tows - tow);
530 for (i = 0, p += 16; i < 12 && n <
MAXOBS; i++) {
531 word1 =
U4(p + 288 + 4 * i);
532 if ((prn = word1 & 0xFF) == 0) {
536 trace(NULL, 2,
"creasent bin 66 satellite number error: prn=%d\n", prn);
539 pr1 = (word1 >> 13) * 256.0;
545 word1 =
U4(p + 12 * i);
546 word2 =
U4(p + 4 + 12 * i);
547 word3 =
U4(p + 8 + 12 * i);
549 snr[0] = sn == 0 ? 0.0 : 10.0 * log10(0.1024 * sn) +
SNR2CN0_L1;
550 sc = (uint32_t)(word1 >> 24);
552 lli[0] = (int)((uint8_t)sc - (uint8_t)raw->
lockt[sat - 1][0]) > 0;
556 lli[0] |= ((word1 >> 12) & 7) ? 2 : 0;
557 raw->
lockt[sat - 1][0] = (uint8_t)sc;
558 dop[0] = ((word2 >> 1) & 0x7FFFFF) / 512.0;
559 if ((word2 >> 24) & 1) {
562 pr[0] = pr1 + (word3 & 0xFFFF) / 256.0;
563 cp[0] = floor(pr[0] * freq[0] /
CLIGHT / 8192.0) * 8192.0;
564 cp[0] += ((word2 & 0xFE000000) + ((word3 & 0xFFFF0000) >> 7)) / 524288.0;
565 if (cp[0] - pr[0] * freq[0] /
CLIGHT < -4096.0) {
567 }
else if (cp[0] - pr[0] * freq[0] /
CLIGHT > 4096.0) {
572 word1 =
U4(p + 144 + 12 * i);
573 word2 =
U4(p + 148 + 12 * i);
574 word3 =
U4(p + 152 + 12 * i);
576 snr[1] = sn == 0 ? 0.0 : 10.0 * log10(0.1164 * sn) +
SNR2CN0_L2;
577 sc = (uint32_t)(word1 >> 24);
579 lli[1] = (int)((uint8_t)sc - (uint8_t)raw->
lockt[sat - 1][1]) > 0;
583 lli[1] |= ((word1 >> 12) & 7) ? 2 : 0;
584 raw->
lockt[sat - 1][1] = (uint8_t)sc;
585 dop[1] = ((word2 >> 1) & 0x7FFFFF) / 512.0;
586 if ((word2 >> 24) & 1) {
589 pr[1] = (word3 & 0xFFFF) / 256.0;
592 if (pr[1] - pr[0] < -128.0) {
594 }
else if (pr[1] - pr[0] > 128.0) {
597 cp[1] = floor(pr[1] * freq[1] /
CLIGHT / 8192.0) * 8192.0;
598 cp[1] += ((word2 & 0xFE000000) + ((word3 & 0xFFFF0000) >> 7)) / 524288.0;
599 if (cp[1] - pr[1] * freq[1] /
CLIGHT < -4096.0) {
601 }
else if (cp[1] - pr[1] * freq[1] /
CLIGHT > 4096.0) {
607 for (j = 0; j < NFREQ; j++) {
608 if (j == 0 || (j == 1 && i < 12)) {
609 raw->
obs.
data[n].
P[j] = pr[j] == 0.0 ? 0.0 : pr[j] - toff;
610 raw->
obs.
data[n].
L[j] = cp[j] == 0.0 ? 0.0 : cp[j] - toff * freq[j] /
CLIGHT;
611 raw->
obs.
data[n].
D[j] = -(float)dop[j];
631 uint8_t *p = raw->
buff + 8, str[12];
632 int i, j, k, sat, prn, frq, time, no;
634 trace(NULL, 4,
"decode_cregloeph: len=%d\n", raw->
len);
636 if (!strstr(raw->
opt,
"-ENAGLO")) {
648 trace(NULL, 2,
"creasent bin 65 satellite number error: prn=%d\n", prn);
651 for (i = 0; i < 5; i++) {
652 for (j = 0; j < 3; j++) {
653 for (k = 3; k >= 0; k--) {
654 str[k + j * 4] =
U1(p++);
657 if ((no =
getbitu(str, 1, 4)) != i + 1) {
658 trace(NULL, 2,
"creasent bin 65 string no error: sat=%2d no=%d %d\n", sat, i + 1, no);
661 memcpy(raw->
subfrm[sat - 1] + 10 * i, str, 10);
670 if (!strstr(raw->
opt,
"-EPHALL")) {
682 int type =
U2(raw->
buff + 4);
684 trace(NULL, 3,
"decode_cres: type=%2d len=%d\n", type, raw->
len);
687 trace(NULL, 2,
"crescent checksum error: type=%2d len=%d\n", type, raw->
len);
691 sprintf(raw->
msgtype,
"HEMIS %2d (%4d):", type, raw->
len);
738 trace(NULL, 5,
"input_cres: data=%02x\n", data);
741 if (raw->
nbyte == 0) {
750 if (raw->
nbyte == 8) {
752 trace(NULL, 2,
"cresent length error: len=%d\n", raw->
len);
774 trace(NULL, 4,
"input_cresf:\n");
777 if (raw->
nbyte == 0) {
779 if ((data = fgetc(fp)) == EOF) {
790 if (fread(raw->
buff + 4, 1, 4, fp) < 4) {
796 trace(NULL, 2,
"crescent length error: len=%d\n", raw->
len);
800 if (fread(raw->
buff + 8, 1, raw->
len - 8, fp) < (
size_t)(raw->
len - 8)) {
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.
double sat2freq(int sat, uint8_t code, const nav_t *nav)
MRTKLIB Broadcast Ephemeris Module — Satellite orbit/clock types and Kepler/GLONASS/SBAS orbit comput...
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.
MRTKLIB Observation Module — Observation data types and utility functions.
static int decode_cres(raw_t *raw)
static int decode_creswaas(raw_t *raw)
static int sync_cres(uint8_t *buff, uint8_t data)
static int decode_crespos(raw_t *raw)
static int decode_cresraw(raw_t *raw)
static int decode_cresgloraw(raw_t *raw)
static int chksum(const uint8_t *buff, int len)
static int decode_cresraw2(raw_t *raw)
static int decode_cresgloeph(raw_t *raw)
static int decode_creseph(raw_t *raw)
int input_cres(raw_t *raw, uint8_t data)
static int decode_cresionutc(raw_t *raw)
int input_cresf(raw_t *raw, FILE *fp)
int decode_frame(const uint8_t *buff, eph_t *eph, alm_t *alm, double *ion, double *utc)
int decode_glostr(const uint8_t *buff, geph_t *geph, 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.
MRTKLIB System Module — OS/filesystem utility functions.
gtime_t gpst2time(int week, double sec)
Convert GPS week/tow to gtime_t.
void time2str(gtime_t t, char *s, int n)
Convert gtime_t struct to string.
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.
MRTKLIB Time Module — GNSS time types and conversion functions.
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]