gnss-js 1.18.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-2IM5VXNI.js → chunk-7RKLWE6R.js} +23 -2
- package/dist/{chunk-QXZZNXE3.js → chunk-B5LU4746.js} +1 -1
- package/dist/{chunk-FEGLXNWA.js → chunk-DLXTTHRK.js} +2 -4
- package/dist/{chunk-OMVL3X7V.js → chunk-JNFV5BYB.js} +186 -8
- package/dist/{chunk-HXF7XVW7.js → chunk-NOQAAUGY.js} +297 -11
- package/dist/{chunk-CG7SF45F.js → chunk-VJEPOC76.js} +908 -14
- package/dist/{chunk-Y5IWUPJQ.js → chunk-WZDFZ76K.js} +151 -8
- package/dist/index.cjs +3283 -1908
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +25 -8
- package/dist/nav-BYmYoh9A.d.cts +137 -0
- package/dist/nav-CN8rxL4h.d.ts +137 -0
- package/dist/nav-DImXUdbp.d.cts +223 -0
- package/dist/nav-DImXUdbp.d.ts +223 -0
- package/dist/novatel.cjs +230 -15
- package/dist/novatel.d.cts +8 -1
- package/dist/novatel.d.ts +8 -1
- package/dist/novatel.js +2 -2
- package/dist/orbit.cjs +190 -8
- package/dist/orbit.d.cts +91 -2
- package/dist/orbit.d.ts +91 -2
- package/dist/orbit.js +9 -1
- package/dist/positioning.d.cts +2 -1
- package/dist/positioning.d.ts +2 -1
- package/dist/positioning.js +2 -2
- package/dist/rinex.cjs +304 -11
- package/dist/rinex.d.cts +45 -3
- package/dist/rinex.d.ts +45 -3
- package/dist/rinex.js +6 -1
- package/dist/sbf.cjs +908 -11
- package/dist/sbf.d.cts +114 -137
- package/dist/sbf.d.ts +114 -137
- package/dist/sbf.js +8 -3
- package/dist/ubx.d.cts +1 -2
- package/dist/ubx.d.ts +1 -2
- package/dist/ubx.js +2 -3
- package/package.json +1 -1
- package/dist/chunk-IQ5OIMQD.js +0 -148
- package/dist/cnav-CRns0ECn.d.cts +0 -96
- package/dist/cnav-CRns0ECn.d.ts +0 -96
- package/dist/nav-BAI1a9vK.d.cts +0 -108
- package/dist/nav-BAI1a9vK.d.ts +0 -108
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CnavAssembler,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
GPS_PI,
|
|
4
|
+
cnavCrcOk,
|
|
5
|
+
crc24q,
|
|
6
|
+
getBitS,
|
|
7
|
+
getBitU
|
|
8
|
+
} from "./chunk-WZDFZ76K.js";
|
|
5
9
|
import {
|
|
6
|
-
getGpsLeap
|
|
10
|
+
getGpsLeap,
|
|
11
|
+
getUtcDate
|
|
7
12
|
} from "./chunk-HVXYFUCB.js";
|
|
8
13
|
|
|
9
14
|
// src/sbf/frame.ts
|
|
@@ -444,10 +449,896 @@ function parseSbfCnav(data) {
|
|
|
444
449
|
return { ephemerides, badCrc, messages };
|
|
445
450
|
}
|
|
446
451
|
|
|
452
|
+
// src/navbits/gal.ts
|
|
453
|
+
var GPS_EPOCH_MS2 = Date.UTC(1980, 0, 6);
|
|
454
|
+
var SEC_PER_WEEK2 = 7 * 86400;
|
|
455
|
+
var HALF_WEEK = 302400;
|
|
456
|
+
var GST_GPS_WEEK_OFFSET = 1024;
|
|
457
|
+
function galInavPageCrcOk(page) {
|
|
458
|
+
if (page.length < 28) return false;
|
|
459
|
+
return crc24q(page, 196) === getBitU(page, 196, 24);
|
|
460
|
+
}
|
|
461
|
+
function galFnavPageCrcOk(page) {
|
|
462
|
+
if (page.length < 30) return false;
|
|
463
|
+
return crc24q(page, 214) === getBitU(page, 214, 24);
|
|
464
|
+
}
|
|
465
|
+
function gpsDate(week, sec) {
|
|
466
|
+
return new Date(GPS_EPOCH_MS2 + (week * SEC_PER_WEEK2 + sec) * 1e3);
|
|
467
|
+
}
|
|
468
|
+
function weekOfToe(week, tow, toe) {
|
|
469
|
+
if (toe - tow > HALF_WEEK) return week - 1;
|
|
470
|
+
if (toe - tow < -HALF_WEEK) return week + 1;
|
|
471
|
+
return week;
|
|
472
|
+
}
|
|
473
|
+
var two2 = (n) => String(n).padStart(2, "0");
|
|
474
|
+
function decodeGalInavWords(words) {
|
|
475
|
+
if (words.length < 96) return null;
|
|
476
|
+
const b = words;
|
|
477
|
+
let i = 128;
|
|
478
|
+
const type1 = getBitU(b, i, 6);
|
|
479
|
+
i += 6;
|
|
480
|
+
const iodNav1 = getBitU(b, i, 10);
|
|
481
|
+
i += 10;
|
|
482
|
+
const toes = getBitU(b, i, 14) * 60;
|
|
483
|
+
i += 14;
|
|
484
|
+
const m0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
485
|
+
i += 32;
|
|
486
|
+
const e = getBitU(b, i, 32) * 2 ** -33;
|
|
487
|
+
i += 32;
|
|
488
|
+
const sqrtA = getBitU(b, i, 32) * 2 ** -19;
|
|
489
|
+
i = 128 * 2;
|
|
490
|
+
const type2 = getBitU(b, i, 6);
|
|
491
|
+
i += 6;
|
|
492
|
+
const iodNav2 = getBitU(b, i, 10);
|
|
493
|
+
i += 10;
|
|
494
|
+
const omega0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
495
|
+
i += 32;
|
|
496
|
+
const i0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
497
|
+
i += 32;
|
|
498
|
+
const omega = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
499
|
+
i += 32;
|
|
500
|
+
const idot = getBitS(b, i, 14) * 2 ** -43 * GPS_PI;
|
|
501
|
+
i = 128 * 3;
|
|
502
|
+
const type3 = getBitU(b, i, 6);
|
|
503
|
+
i += 6;
|
|
504
|
+
const iodNav3 = getBitU(b, i, 10);
|
|
505
|
+
i += 10;
|
|
506
|
+
const omegaDot = getBitS(b, i, 24) * 2 ** -43 * GPS_PI;
|
|
507
|
+
i += 24;
|
|
508
|
+
const deltaN = getBitS(b, i, 16) * 2 ** -43 * GPS_PI;
|
|
509
|
+
i += 16;
|
|
510
|
+
const cuc = getBitS(b, i, 16) * 2 ** -29;
|
|
511
|
+
i += 16;
|
|
512
|
+
const cus = getBitS(b, i, 16) * 2 ** -29;
|
|
513
|
+
i += 16;
|
|
514
|
+
const crc = getBitS(b, i, 16) * 2 ** -5;
|
|
515
|
+
i += 16;
|
|
516
|
+
const crs = getBitS(b, i, 16) * 2 ** -5;
|
|
517
|
+
i = 128 * 4;
|
|
518
|
+
const type4 = getBitU(b, i, 6);
|
|
519
|
+
i += 6;
|
|
520
|
+
const iodNav4 = getBitU(b, i, 10);
|
|
521
|
+
i += 10;
|
|
522
|
+
const svid = getBitU(b, i, 6);
|
|
523
|
+
i += 6;
|
|
524
|
+
const cic = getBitS(b, i, 16) * 2 ** -29;
|
|
525
|
+
i += 16;
|
|
526
|
+
const cis = getBitS(b, i, 16) * 2 ** -29;
|
|
527
|
+
i += 16;
|
|
528
|
+
const tocs = getBitU(b, i, 14) * 60;
|
|
529
|
+
i += 14;
|
|
530
|
+
const af0 = getBitS(b, i, 31) * 2 ** -34;
|
|
531
|
+
i += 31;
|
|
532
|
+
const af1 = getBitS(b, i, 21) * 2 ** -46;
|
|
533
|
+
i += 21;
|
|
534
|
+
const af2 = getBitS(b, i, 6) * 2 ** -59;
|
|
535
|
+
i = 128 * 5;
|
|
536
|
+
const type5 = getBitU(b, i, 6);
|
|
537
|
+
i += 6 + 11 + 11 + 14 + 5;
|
|
538
|
+
const bgdE5a = getBitS(b, i, 10) * 2 ** -32;
|
|
539
|
+
i += 10;
|
|
540
|
+
i += 10;
|
|
541
|
+
const e5bHs = getBitU(b, i, 2);
|
|
542
|
+
i += 2;
|
|
543
|
+
const e1bHs = getBitU(b, i, 2);
|
|
544
|
+
i += 2;
|
|
545
|
+
const e5bDvs = getBitU(b, i, 1);
|
|
546
|
+
i += 1;
|
|
547
|
+
const e1bDvs = getBitU(b, i, 1);
|
|
548
|
+
i += 1;
|
|
549
|
+
const gstWeek = getBitU(b, i, 12);
|
|
550
|
+
i += 12;
|
|
551
|
+
const tow = getBitU(b, i, 20);
|
|
552
|
+
if (type1 !== 1 || type2 !== 2 || type3 !== 3 || type4 !== 4 || type5 !== 5)
|
|
553
|
+
return null;
|
|
554
|
+
if (iodNav1 !== iodNav2 || iodNav1 !== iodNav3 || iodNav1 !== iodNav4)
|
|
555
|
+
return null;
|
|
556
|
+
if (svid < 1 || svid > 36) return null;
|
|
557
|
+
const week = weekOfToe(gstWeek, tow, toes) + GST_GPS_WEEK_OFFSET;
|
|
558
|
+
const tocDate = gpsDate(week, tocs);
|
|
559
|
+
return {
|
|
560
|
+
system: "E",
|
|
561
|
+
prn: `E${two2(svid)}`,
|
|
562
|
+
toc: tocDate.getTime() / 1e3 % SEC_PER_WEEK2,
|
|
563
|
+
tocDate,
|
|
564
|
+
af0,
|
|
565
|
+
af1,
|
|
566
|
+
af2,
|
|
567
|
+
iode: iodNav1,
|
|
568
|
+
crs,
|
|
569
|
+
deltaN,
|
|
570
|
+
m0,
|
|
571
|
+
cuc,
|
|
572
|
+
e,
|
|
573
|
+
cus,
|
|
574
|
+
sqrtA,
|
|
575
|
+
toe: toes,
|
|
576
|
+
cic,
|
|
577
|
+
omega0,
|
|
578
|
+
cis,
|
|
579
|
+
i0,
|
|
580
|
+
crc,
|
|
581
|
+
omega,
|
|
582
|
+
omegaDot,
|
|
583
|
+
idot,
|
|
584
|
+
week,
|
|
585
|
+
svHealth: e5bHs << 7 | e5bDvs << 6 | e1bHs << 1 | e1bDvs,
|
|
586
|
+
tgd: bgdE5a
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function decodeGalFnavPages(pages) {
|
|
590
|
+
if (pages.length < 124) return null;
|
|
591
|
+
const b = pages;
|
|
592
|
+
let i = 0;
|
|
593
|
+
const type1 = getBitU(b, i, 6);
|
|
594
|
+
i += 6;
|
|
595
|
+
const svid = getBitU(b, i, 6);
|
|
596
|
+
i += 6;
|
|
597
|
+
const iodNav1 = getBitU(b, i, 10);
|
|
598
|
+
i += 10;
|
|
599
|
+
const tocs = getBitU(b, i, 14) * 60;
|
|
600
|
+
i += 14;
|
|
601
|
+
const af0 = getBitS(b, i, 31) * 2 ** -34;
|
|
602
|
+
i += 31;
|
|
603
|
+
const af1 = getBitS(b, i, 21) * 2 ** -46;
|
|
604
|
+
i += 21;
|
|
605
|
+
const af2 = getBitS(b, i, 6) * 2 ** -59;
|
|
606
|
+
i += 6;
|
|
607
|
+
i += 8 + 11 + 11 + 14 + 5;
|
|
608
|
+
const bgdE5a = getBitS(b, i, 10) * 2 ** -32;
|
|
609
|
+
i += 10;
|
|
610
|
+
const e5aHs = getBitU(b, i, 2);
|
|
611
|
+
i += 2;
|
|
612
|
+
const gstWeek = getBitU(b, i, 12);
|
|
613
|
+
i += 12;
|
|
614
|
+
const tow = getBitU(b, i, 20);
|
|
615
|
+
i += 20;
|
|
616
|
+
const e5aDvs = getBitU(b, i, 1);
|
|
617
|
+
i = 31 * 8;
|
|
618
|
+
const type2 = getBitU(b, i, 6);
|
|
619
|
+
i += 6;
|
|
620
|
+
const iodNav2 = getBitU(b, i, 10);
|
|
621
|
+
i += 10;
|
|
622
|
+
const m0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
623
|
+
i += 32;
|
|
624
|
+
const omegaDot = getBitS(b, i, 24) * 2 ** -43 * GPS_PI;
|
|
625
|
+
i += 24;
|
|
626
|
+
const e = getBitU(b, i, 32) * 2 ** -33;
|
|
627
|
+
i += 32;
|
|
628
|
+
const sqrtA = getBitU(b, i, 32) * 2 ** -19;
|
|
629
|
+
i += 32;
|
|
630
|
+
const omega0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
631
|
+
i += 32;
|
|
632
|
+
const idot = getBitS(b, i, 14) * 2 ** -43 * GPS_PI;
|
|
633
|
+
i = 62 * 8;
|
|
634
|
+
const type3 = getBitU(b, i, 6);
|
|
635
|
+
i += 6;
|
|
636
|
+
const iodNav3 = getBitU(b, i, 10);
|
|
637
|
+
i += 10;
|
|
638
|
+
const i0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
639
|
+
i += 32;
|
|
640
|
+
const omega = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
|
|
641
|
+
i += 32;
|
|
642
|
+
const deltaN = getBitS(b, i, 16) * 2 ** -43 * GPS_PI;
|
|
643
|
+
i += 16;
|
|
644
|
+
const cuc = getBitS(b, i, 16) * 2 ** -29;
|
|
645
|
+
i += 16;
|
|
646
|
+
const cus = getBitS(b, i, 16) * 2 ** -29;
|
|
647
|
+
i += 16;
|
|
648
|
+
const crc = getBitS(b, i, 16) * 2 ** -5;
|
|
649
|
+
i += 16;
|
|
650
|
+
const crs = getBitS(b, i, 16) * 2 ** -5;
|
|
651
|
+
i += 16;
|
|
652
|
+
const toes = getBitU(b, i, 14) * 60;
|
|
653
|
+
i = 93 * 8;
|
|
654
|
+
const type4 = getBitU(b, i, 6);
|
|
655
|
+
i += 6;
|
|
656
|
+
const iodNav4 = getBitU(b, i, 10);
|
|
657
|
+
i += 10;
|
|
658
|
+
const cic = getBitS(b, i, 16) * 2 ** -29;
|
|
659
|
+
i += 16;
|
|
660
|
+
const cis = getBitS(b, i, 16) * 2 ** -29;
|
|
661
|
+
if (type1 !== 1 || type2 !== 2 || type3 !== 3 || type4 !== 4) return null;
|
|
662
|
+
if (iodNav1 !== iodNav2 || iodNav1 !== iodNav3 || iodNav1 !== iodNav4)
|
|
663
|
+
return null;
|
|
664
|
+
if (svid < 1 || svid > 36) return null;
|
|
665
|
+
const week = weekOfToe(gstWeek, tow, toes) + GST_GPS_WEEK_OFFSET;
|
|
666
|
+
const tocDate = gpsDate(week, tocs);
|
|
667
|
+
return {
|
|
668
|
+
system: "E",
|
|
669
|
+
prn: `E${two2(svid)}`,
|
|
670
|
+
toc: tocDate.getTime() / 1e3 % SEC_PER_WEEK2,
|
|
671
|
+
tocDate,
|
|
672
|
+
af0,
|
|
673
|
+
af1,
|
|
674
|
+
af2,
|
|
675
|
+
iode: iodNav1,
|
|
676
|
+
crs,
|
|
677
|
+
deltaN,
|
|
678
|
+
m0,
|
|
679
|
+
cuc,
|
|
680
|
+
e,
|
|
681
|
+
cus,
|
|
682
|
+
sqrtA,
|
|
683
|
+
toe: toes,
|
|
684
|
+
cic,
|
|
685
|
+
omega0,
|
|
686
|
+
cis,
|
|
687
|
+
i0,
|
|
688
|
+
crc,
|
|
689
|
+
omega,
|
|
690
|
+
omegaDot,
|
|
691
|
+
idot,
|
|
692
|
+
week,
|
|
693
|
+
svHealth: e5aHs << 4 | e5aDvs << 3,
|
|
694
|
+
tgd: bgdE5a
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
var dedupKey = (eph) => `${eph.iode}:${eph.toe}:${eph.tocDate.getTime()}`;
|
|
698
|
+
var GalInavAssembler = class {
|
|
699
|
+
sats = /* @__PURE__ */ new Map();
|
|
700
|
+
/**
|
|
701
|
+
* Push one I/NAV page pair for satellite `prn` (1-36): the 234-bit
|
|
702
|
+
* even+odd concatenation, even part first with its 6 tail bits
|
|
703
|
+
* removed, bit 0 = the even part's Even/Odd bit (≥ 17 bytes).
|
|
704
|
+
* Returns the newly completed ephemeris, or null. Pages that are
|
|
705
|
+
* not an even/odd nominal pair, alert pages and word types outside
|
|
706
|
+
* 1-5 are ignored.
|
|
707
|
+
*/
|
|
708
|
+
push(prn, page) {
|
|
709
|
+
if (prn < 1 || prn > 36 || page.length < 17) return null;
|
|
710
|
+
if (getBitU(page, 0, 1) !== 0 || getBitU(page, 114, 1) !== 1) return null;
|
|
711
|
+
if (getBitU(page, 1, 1) === 1 || getBitU(page, 115, 1) === 1) return null;
|
|
712
|
+
const type = getBitU(page, 2, 6);
|
|
713
|
+
if (type < 1 || type > 5) return null;
|
|
714
|
+
let sat = this.sats.get(prn);
|
|
715
|
+
if (!sat) {
|
|
716
|
+
sat = { words: new Uint8Array(96) };
|
|
717
|
+
this.sats.set(prn, sat);
|
|
718
|
+
}
|
|
719
|
+
for (let k = 0; k < 14; k++)
|
|
720
|
+
sat.words[type * 16 + k] = getBitU(page, 2 + 8 * k, 8);
|
|
721
|
+
sat.words[type * 16 + 14] = getBitU(page, 116, 8);
|
|
722
|
+
sat.words[type * 16 + 15] = getBitU(page, 124, 8);
|
|
723
|
+
if (type !== 5) return null;
|
|
724
|
+
const eph = decodeGalInavWords(sat.words);
|
|
725
|
+
if (!eph || eph.prn !== `E${two2(prn)}`) return null;
|
|
726
|
+
const key = dedupKey(eph);
|
|
727
|
+
if (key === sat.lastKey) return null;
|
|
728
|
+
sat.lastKey = key;
|
|
729
|
+
return eph;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
var GalFnavAssembler = class {
|
|
733
|
+
sats = /* @__PURE__ */ new Map();
|
|
734
|
+
/**
|
|
735
|
+
* Push one F/NAV page for satellite `prn` (1-36): 244 bits with the
|
|
736
|
+
* sync field stripped, bit 0 = first page-type bit (≥ 31 bytes).
|
|
737
|
+
* Returns the newly completed ephemeris, or null. Dummy pages
|
|
738
|
+
* (type 63) and page types outside 1-4 are ignored.
|
|
739
|
+
*/
|
|
740
|
+
push(prn, page) {
|
|
741
|
+
if (prn < 1 || prn > 36 || page.length < 31) return null;
|
|
742
|
+
const type = getBitU(page, 0, 6);
|
|
743
|
+
if (type < 1 || type > 4) return null;
|
|
744
|
+
let sat = this.sats.get(prn);
|
|
745
|
+
if (!sat) {
|
|
746
|
+
sat = { words: new Uint8Array(124) };
|
|
747
|
+
this.sats.set(prn, sat);
|
|
748
|
+
}
|
|
749
|
+
sat.words.set(page.subarray(0, 31), (type - 1) * 31);
|
|
750
|
+
if (type !== 4) return null;
|
|
751
|
+
const eph = decodeGalFnavPages(sat.words);
|
|
752
|
+
if (!eph || eph.prn !== `E${two2(prn)}`) return null;
|
|
753
|
+
const key = dedupKey(eph);
|
|
754
|
+
if (key === sat.lastKey) return null;
|
|
755
|
+
sat.lastKey = key;
|
|
756
|
+
return eph;
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// src/sbf/rawnav-gal.ts
|
|
761
|
+
var INAV_SOURCES = [17, 21, 22];
|
|
762
|
+
var FNAV_SOURCES = [20, 22];
|
|
763
|
+
function parseSbfGalNav(data) {
|
|
764
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
765
|
+
const ephemerides = [];
|
|
766
|
+
const inav = new GalInavAssembler();
|
|
767
|
+
const fnav = new GalFnavAssembler();
|
|
768
|
+
let badCrc = 0;
|
|
769
|
+
let messages = 0;
|
|
770
|
+
scanSbfFrames(data, view, (id, b, len) => {
|
|
771
|
+
if (id !== 4022 && id !== 4023 || len < 52) return;
|
|
772
|
+
messages++;
|
|
773
|
+
const prnStr = svidToPrn(data[b + 14]);
|
|
774
|
+
if (!prnStr || prnStr[0] !== "E") return;
|
|
775
|
+
const prn = parseInt(prnStr.slice(1), 10);
|
|
776
|
+
const source = data[b + 17] & 31;
|
|
777
|
+
const page = new Uint8Array(32);
|
|
778
|
+
for (let k = 0; k < 8; k++) {
|
|
779
|
+
const w = view.getUint32(b + 20 + 4 * k, true);
|
|
780
|
+
page[4 * k] = w >>> 24;
|
|
781
|
+
page[4 * k + 1] = w >>> 16 & 255;
|
|
782
|
+
page[4 * k + 2] = w >>> 8 & 255;
|
|
783
|
+
page[4 * k + 3] = w & 255;
|
|
784
|
+
}
|
|
785
|
+
let eph;
|
|
786
|
+
let src;
|
|
787
|
+
if (id === 4023) {
|
|
788
|
+
src = "inav";
|
|
789
|
+
if (!INAV_SOURCES.includes(source)) return;
|
|
790
|
+
if (getBitU2(page, 0) !== 0 || getBitU2(page, 114) !== 1) return;
|
|
791
|
+
if (!galInavPageCrcOk(page)) {
|
|
792
|
+
badCrc++;
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
eph = inav.push(prn, page);
|
|
796
|
+
} else {
|
|
797
|
+
src = "fnav";
|
|
798
|
+
if (!FNAV_SOURCES.includes(source)) return;
|
|
799
|
+
if (isFnavDummy(page)) return;
|
|
800
|
+
if (!galFnavPageCrcOk(page)) {
|
|
801
|
+
badCrc++;
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
eph = fnav.push(prn, page);
|
|
805
|
+
}
|
|
806
|
+
if (eph) ephemerides.push({ ...eph, source: src });
|
|
807
|
+
});
|
|
808
|
+
return { ephemerides, badCrc, messages };
|
|
809
|
+
}
|
|
810
|
+
function getBitU2(buff, pos) {
|
|
811
|
+
return buff[pos >> 3] >> 7 - (pos & 7) & 1;
|
|
812
|
+
}
|
|
813
|
+
function isFnavDummy(page) {
|
|
814
|
+
return page[0] >> 2 === 63;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// src/navbits/bds.ts
|
|
818
|
+
var BDT_EPOCH_MS2 = Date.UTC(2006, 0, 1);
|
|
819
|
+
var SEC_PER_WEEK3 = 7 * 86400;
|
|
820
|
+
var MS_PER_WEEK2 = SEC_PER_WEEK3 * 1e3;
|
|
821
|
+
var HALF_WEEK2 = 302400;
|
|
822
|
+
var sowOf2 = (dateMs) => dateMs / 1e3 % SEC_PER_WEEK3;
|
|
823
|
+
var BDS_SUBFRAME_BYTES = 38;
|
|
824
|
+
function getBitU22(b, p1, l1, p2, l2) {
|
|
825
|
+
return getBitU(b, p1, l1) * 2 ** l2 + getBitU(b, p2, l2);
|
|
826
|
+
}
|
|
827
|
+
function getBitS2(b, p1, l1, p2, l2) {
|
|
828
|
+
return getBitS(b, p1, l1) * 2 ** l2 + getBitU(b, p2, l2);
|
|
829
|
+
}
|
|
830
|
+
function getBitU3(b, p1, l1, p2, l2, p3, l3) {
|
|
831
|
+
return getBitU(b, p1, l1) * 2 ** (l2 + l3) + getBitU(b, p2, l2) * 2 ** l3 + getBitU(b, p3, l3);
|
|
832
|
+
}
|
|
833
|
+
function getBitS3(b, p1, l1, p2, l2, p3, l3) {
|
|
834
|
+
return getBitS(b, p1, l1) * 2 ** (l2 + l3) + getBitU(b, p2, l2) * 2 ** l3 + getBitU(b, p3, l3);
|
|
835
|
+
}
|
|
836
|
+
var mergeS = (hi, lo, n) => hi * 2 ** n + lo;
|
|
837
|
+
function bchOk(cw) {
|
|
838
|
+
for (let i = 14; i >= 4; i--) {
|
|
839
|
+
if (cw & 1 << i) cw ^= 19 << i - 4;
|
|
840
|
+
}
|
|
841
|
+
return cw === 0;
|
|
842
|
+
}
|
|
843
|
+
function bdsSubframeParityOk(subframe) {
|
|
844
|
+
if (subframe.length < BDS_SUBFRAME_BYTES) return false;
|
|
845
|
+
if (!bchOk(getBitU(subframe, 15, 15))) return false;
|
|
846
|
+
for (let w = 1; w < 10; w++) {
|
|
847
|
+
const base = 30 * w;
|
|
848
|
+
const cw1 = getBitU(subframe, base, 11) * 16 + getBitU(subframe, base + 22, 4);
|
|
849
|
+
const cw2 = getBitU(subframe, base + 11, 11) * 16 + getBitU(subframe, base + 26, 4);
|
|
850
|
+
if (!bchOk(cw1) || !bchOk(cw2)) return false;
|
|
851
|
+
}
|
|
852
|
+
return true;
|
|
853
|
+
}
|
|
854
|
+
function buildBdsEphemeris(prn, f) {
|
|
855
|
+
let week = f.week;
|
|
856
|
+
if (f.toes < f.sow - HALF_WEEK2) week++;
|
|
857
|
+
else if (f.toes > f.sow + HALF_WEEK2) week--;
|
|
858
|
+
const tocDate = new Date(BDT_EPOCH_MS2 + week * MS_PER_WEEK2 + f.tocSec * 1e3);
|
|
859
|
+
return {
|
|
860
|
+
system: "C",
|
|
861
|
+
prn,
|
|
862
|
+
toc: sowOf2(tocDate.getTime()),
|
|
863
|
+
tocDate,
|
|
864
|
+
af0: f.af0,
|
|
865
|
+
af1: f.af1,
|
|
866
|
+
af2: f.af2,
|
|
867
|
+
// AODE is not in the ephemeris subframes; RTKLIB derives the RINEX
|
|
868
|
+
// IODE/AODE slot from toc per the BDS ICD update schedule.
|
|
869
|
+
iode: Math.floor(f.tocSec / 720) % 240,
|
|
870
|
+
crs: f.crs,
|
|
871
|
+
deltaN: f.deltaN,
|
|
872
|
+
m0: f.m0,
|
|
873
|
+
cuc: f.cuc,
|
|
874
|
+
e: f.e,
|
|
875
|
+
cus: f.cus,
|
|
876
|
+
sqrtA: f.sqrtA,
|
|
877
|
+
toe: f.toes,
|
|
878
|
+
cic: f.cic,
|
|
879
|
+
omega0: f.omega0,
|
|
880
|
+
cis: f.cis,
|
|
881
|
+
i0: f.i0,
|
|
882
|
+
crc: f.crc,
|
|
883
|
+
omega: f.omega,
|
|
884
|
+
omegaDot: f.omegaDot,
|
|
885
|
+
idot: f.idot,
|
|
886
|
+
week,
|
|
887
|
+
// RINEX BDS week field is the BDT week of toe
|
|
888
|
+
svHealth: f.svh,
|
|
889
|
+
// SatH1
|
|
890
|
+
tgd: f.tgd1
|
|
891
|
+
// TGD1 (B1) — RINEX slot
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
function decodeBdsD1Frame(subframes, opts = {}) {
|
|
895
|
+
if (subframes.length < 3 * BDS_SUBFRAME_BYTES) return null;
|
|
896
|
+
const b = subframes;
|
|
897
|
+
let i = 8 * 38 * 0;
|
|
898
|
+
const frn1 = getBitU(b, i + 15, 3);
|
|
899
|
+
const sow1 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
900
|
+
const svh = getBitU(b, i + 42, 1);
|
|
901
|
+
const week = getBitU(b, i + 60, 13);
|
|
902
|
+
const tocSec = getBitU22(b, i + 73, 9, i + 90, 8) * 8;
|
|
903
|
+
const tgd1 = getBitS(b, i + 98, 10) * 0.1 * 1e-9;
|
|
904
|
+
const af2 = getBitS(b, i + 214, 11) * 2 ** -66;
|
|
905
|
+
const af0 = getBitS2(b, i + 225, 7, i + 240, 17) * 2 ** -33;
|
|
906
|
+
const af1 = getBitS2(b, i + 257, 5, i + 270, 17) * 2 ** -50;
|
|
907
|
+
i = 8 * 38 * 1;
|
|
908
|
+
const frn2 = getBitU(b, i + 15, 3);
|
|
909
|
+
const sow2 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
910
|
+
const deltaN = getBitS2(b, i + 42, 10, i + 60, 6) * 2 ** -43 * GPS_PI;
|
|
911
|
+
const cuc = getBitS2(b, i + 66, 16, i + 90, 2) * 2 ** -31;
|
|
912
|
+
const m0 = getBitS2(b, i + 92, 20, i + 120, 12) * 2 ** -31 * GPS_PI;
|
|
913
|
+
const e = getBitU22(b, i + 132, 10, i + 150, 22) * 2 ** -33;
|
|
914
|
+
const cus = getBitS(b, i + 180, 18) * 2 ** -31;
|
|
915
|
+
const crc = getBitS2(b, i + 198, 4, i + 210, 14) * 2 ** -6;
|
|
916
|
+
const crs = getBitS2(b, i + 224, 8, i + 240, 10) * 2 ** -6;
|
|
917
|
+
const sqrtA = getBitU22(b, i + 250, 12, i + 270, 20) * 2 ** -19;
|
|
918
|
+
const toe1 = getBitU(b, i + 290, 2);
|
|
919
|
+
i = 8 * 38 * 2;
|
|
920
|
+
const frn3 = getBitU(b, i + 15, 3);
|
|
921
|
+
const sow3 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
922
|
+
const toe2 = getBitU22(b, i + 42, 10, i + 60, 5);
|
|
923
|
+
const i0 = getBitS2(b, i + 65, 17, i + 90, 15) * 2 ** -31 * GPS_PI;
|
|
924
|
+
const cic = getBitS2(b, i + 105, 7, i + 120, 11) * 2 ** -31;
|
|
925
|
+
const omegaDot = getBitS2(b, i + 131, 11, i + 150, 13) * 2 ** -43 * GPS_PI;
|
|
926
|
+
const cis = getBitS2(b, i + 163, 9, i + 180, 9) * 2 ** -31;
|
|
927
|
+
const idot = getBitS2(b, i + 189, 13, i + 210, 1) * 2 ** -43 * GPS_PI;
|
|
928
|
+
const omega0 = getBitS2(b, i + 211, 21, i + 240, 11) * 2 ** -31 * GPS_PI;
|
|
929
|
+
const omega = getBitS2(b, i + 251, 11, i + 270, 21) * 2 ** -31 * GPS_PI;
|
|
930
|
+
const toes = (toe1 * 2 ** 15 + toe2) * 8;
|
|
931
|
+
if (frn1 !== 1 || frn2 !== 2 || frn3 !== 3) return null;
|
|
932
|
+
if (sow2 !== sow1 + 6 || sow3 !== sow2 + 6) return null;
|
|
933
|
+
if (tocSec !== toes) return null;
|
|
934
|
+
return buildBdsEphemeris(opts.prn ?? "C00", {
|
|
935
|
+
week,
|
|
936
|
+
sow: sow1,
|
|
937
|
+
toes,
|
|
938
|
+
tocSec,
|
|
939
|
+
svh,
|
|
940
|
+
tgd1,
|
|
941
|
+
af0,
|
|
942
|
+
af1,
|
|
943
|
+
af2,
|
|
944
|
+
crs,
|
|
945
|
+
deltaN,
|
|
946
|
+
m0,
|
|
947
|
+
cuc,
|
|
948
|
+
e,
|
|
949
|
+
cus,
|
|
950
|
+
sqrtA,
|
|
951
|
+
cic,
|
|
952
|
+
omega0,
|
|
953
|
+
cis,
|
|
954
|
+
i0,
|
|
955
|
+
crc,
|
|
956
|
+
omega,
|
|
957
|
+
omegaDot,
|
|
958
|
+
idot
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
function decodeBdsD2Frame(pages, opts = {}) {
|
|
962
|
+
if (pages.length < 10 * BDS_SUBFRAME_BYTES) return null;
|
|
963
|
+
const b = pages;
|
|
964
|
+
let i = 8 * 38 * 0;
|
|
965
|
+
const pgn1 = getBitU(b, i + 42, 4);
|
|
966
|
+
const sow1 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
967
|
+
const svh = getBitU(b, i + 46, 1);
|
|
968
|
+
const week = getBitU(b, i + 64, 13);
|
|
969
|
+
const tocSec = getBitU22(b, i + 77, 5, i + 90, 12) * 8;
|
|
970
|
+
const tgd1 = getBitS(b, i + 102, 10) * 0.1 * 1e-9;
|
|
971
|
+
i = 8 * 38 * 2;
|
|
972
|
+
const pgn3 = getBitU(b, i + 42, 4);
|
|
973
|
+
const sow3 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
974
|
+
const af0 = getBitS2(b, i + 100, 12, i + 120, 12) * 2 ** -33;
|
|
975
|
+
const af1p3 = getBitS(b, i + 132, 4);
|
|
976
|
+
i = 8 * 38 * 3;
|
|
977
|
+
const pgn4 = getBitU(b, i + 42, 4);
|
|
978
|
+
const sow4 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
979
|
+
const af1p4 = getBitU22(b, i + 46, 6, i + 60, 12);
|
|
980
|
+
const af2 = getBitS2(b, i + 72, 10, i + 90, 1) * 2 ** -66;
|
|
981
|
+
const deltaN = getBitS(b, i + 96, 16) * 2 ** -43 * GPS_PI;
|
|
982
|
+
const cucp4 = getBitS(b, i + 120, 14);
|
|
983
|
+
i = 8 * 38 * 4;
|
|
984
|
+
const pgn5 = getBitU(b, i + 42, 4);
|
|
985
|
+
const sow5 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
986
|
+
const cucp5 = getBitU(b, i + 46, 4);
|
|
987
|
+
const m0 = getBitS3(b, i + 50, 2, i + 60, 22, i + 90, 8) * 2 ** -31 * GPS_PI;
|
|
988
|
+
const cus = getBitS2(b, i + 98, 14, i + 120, 4) * 2 ** -31;
|
|
989
|
+
const ep5 = getBitS(b, i + 124, 10);
|
|
990
|
+
i = 8 * 38 * 5;
|
|
991
|
+
const pgn6 = getBitU(b, i + 42, 4);
|
|
992
|
+
const sow6 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
993
|
+
const ep6 = getBitU22(b, i + 46, 6, i + 60, 16);
|
|
994
|
+
const sqrtA = getBitU3(b, i + 76, 6, i + 90, 22, i + 120, 4) * 2 ** -19;
|
|
995
|
+
const cicp6 = getBitS(b, i + 124, 10);
|
|
996
|
+
i = 8 * 38 * 6;
|
|
997
|
+
const pgn7 = getBitU(b, i + 42, 4);
|
|
998
|
+
const sow7 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
999
|
+
const cicp7 = getBitU22(b, i + 46, 6, i + 60, 2);
|
|
1000
|
+
const cis = getBitS(b, i + 62, 18) * 2 ** -31;
|
|
1001
|
+
const toes = getBitU22(b, i + 80, 2, i + 90, 15) * 8;
|
|
1002
|
+
const i0p7 = getBitS2(b, i + 105, 7, i + 120, 14);
|
|
1003
|
+
i = 8 * 38 * 7;
|
|
1004
|
+
const pgn8 = getBitU(b, i + 42, 4);
|
|
1005
|
+
const sow8 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
1006
|
+
const i0p8 = getBitU22(b, i + 46, 6, i + 60, 5);
|
|
1007
|
+
const crc = getBitS2(b, i + 65, 17, i + 90, 1) * 2 ** -6;
|
|
1008
|
+
const crs = getBitS(b, i + 91, 18) * 2 ** -6;
|
|
1009
|
+
const omegaDotP8 = getBitS2(b, i + 109, 3, i + 120, 16);
|
|
1010
|
+
i = 8 * 38 * 8;
|
|
1011
|
+
const pgn9 = getBitU(b, i + 42, 4);
|
|
1012
|
+
const sow9 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
1013
|
+
const omegaDotP9 = getBitU(b, i + 46, 5);
|
|
1014
|
+
const omega0 = getBitS3(b, i + 51, 1, i + 60, 22, i + 90, 9) * 2 ** -31 * GPS_PI;
|
|
1015
|
+
const omegaP9 = getBitS2(b, i + 99, 13, i + 120, 14);
|
|
1016
|
+
i = 8 * 38 * 9;
|
|
1017
|
+
const pgn10 = getBitU(b, i + 42, 4);
|
|
1018
|
+
const sow10 = getBitU22(b, i + 18, 8, i + 30, 12);
|
|
1019
|
+
const omegaP10 = getBitU(b, i + 46, 5);
|
|
1020
|
+
const idot = getBitS2(b, i + 51, 1, i + 60, 13) * 2 ** -43 * GPS_PI;
|
|
1021
|
+
if (pgn1 !== 1 || pgn3 !== 3 || pgn4 !== 4 || pgn5 !== 5 || pgn6 !== 6 || pgn7 !== 7 || pgn8 !== 8 || pgn9 !== 9 || pgn10 !== 10) {
|
|
1022
|
+
return null;
|
|
1023
|
+
}
|
|
1024
|
+
if (sow3 !== sow1 + 6 || sow4 !== sow3 + 3 || sow5 !== sow4 + 3 || sow6 !== sow5 + 3 || sow7 !== sow6 + 3 || sow8 !== sow7 + 3 || sow9 !== sow8 + 3 || sow10 !== sow9 + 3) {
|
|
1025
|
+
return null;
|
|
1026
|
+
}
|
|
1027
|
+
if (tocSec !== toes) return null;
|
|
1028
|
+
return buildBdsEphemeris(opts.prn ?? "C00", {
|
|
1029
|
+
week,
|
|
1030
|
+
sow: sow1,
|
|
1031
|
+
toes,
|
|
1032
|
+
tocSec,
|
|
1033
|
+
svh,
|
|
1034
|
+
tgd1,
|
|
1035
|
+
af0,
|
|
1036
|
+
af1: mergeS(af1p3, af1p4, 18) * 2 ** -50,
|
|
1037
|
+
af2,
|
|
1038
|
+
crs,
|
|
1039
|
+
deltaN,
|
|
1040
|
+
m0,
|
|
1041
|
+
cuc: mergeS(cucp4, cucp5, 4) * 2 ** -31,
|
|
1042
|
+
e: mergeS(ep5, ep6, 22) * 2 ** -33,
|
|
1043
|
+
cus,
|
|
1044
|
+
sqrtA,
|
|
1045
|
+
cic: mergeS(cicp6, cicp7, 8) * 2 ** -31,
|
|
1046
|
+
omega0,
|
|
1047
|
+
cis,
|
|
1048
|
+
i0: mergeS(i0p7, i0p8, 11) * 2 ** -31 * GPS_PI,
|
|
1049
|
+
crc,
|
|
1050
|
+
omega: mergeS(omegaP9, omegaP10, 5) * 2 ** -31 * GPS_PI,
|
|
1051
|
+
omegaDot: mergeS(omegaDotP8, omegaDotP9, 5) * 2 ** -43 * GPS_PI,
|
|
1052
|
+
idot
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
function isBdsGeoPrn(prn) {
|
|
1056
|
+
return prn < 6 || prn > 58;
|
|
1057
|
+
}
|
|
1058
|
+
var BdsAssembler = class {
|
|
1059
|
+
sats = /* @__PURE__ */ new Map();
|
|
1060
|
+
/**
|
|
1061
|
+
* Push one 300-bit subframe (38+ bytes, bit 0 = first bit of the
|
|
1062
|
+
* preamble) for the satellite `prn` ("C06"). Returns the newly
|
|
1063
|
+
* completed ephemeris, or null.
|
|
1064
|
+
*/
|
|
1065
|
+
push(prn, subframe) {
|
|
1066
|
+
if (subframe.length < BDS_SUBFRAME_BYTES) return null;
|
|
1067
|
+
const num = parseInt(prn.slice(1), 10);
|
|
1068
|
+
if (!Number.isFinite(num) || num < 1 || num > 63) return null;
|
|
1069
|
+
const id = getBitU(subframe, 15, 3);
|
|
1070
|
+
if (id < 1 || id > 5) return null;
|
|
1071
|
+
let sat = this.sats.get(prn);
|
|
1072
|
+
if (!sat) {
|
|
1073
|
+
sat = { buf: new Uint8Array(10 * BDS_SUBFRAME_BYTES) };
|
|
1074
|
+
this.sats.set(prn, sat);
|
|
1075
|
+
}
|
|
1076
|
+
let eph = null;
|
|
1077
|
+
if (!isBdsGeoPrn(num)) {
|
|
1078
|
+
sat.buf.set(subframe.subarray(0, BDS_SUBFRAME_BYTES), (id - 1) * 38);
|
|
1079
|
+
if (id === 3) eph = decodeBdsD1Frame(sat.buf, { prn });
|
|
1080
|
+
} else {
|
|
1081
|
+
if (id !== 1) return null;
|
|
1082
|
+
const pgn = getBitU(subframe, 42, 4);
|
|
1083
|
+
if (pgn < 1 || pgn > 10) return null;
|
|
1084
|
+
sat.buf.set(subframe.subarray(0, BDS_SUBFRAME_BYTES), (pgn - 1) * 38);
|
|
1085
|
+
if (pgn === 10) eph = decodeBdsD2Frame(sat.buf, { prn });
|
|
1086
|
+
}
|
|
1087
|
+
if (!eph) return null;
|
|
1088
|
+
const key = `${eph.week}:${eph.toe}`;
|
|
1089
|
+
if (key === sat.lastKey) return null;
|
|
1090
|
+
sat.lastKey = key;
|
|
1091
|
+
return eph;
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
// src/navbits/glo.ts
|
|
1096
|
+
var GPS_EPOCH_MS3 = Date.UTC(1980, 0, 6);
|
|
1097
|
+
var SEC_PER_WEEK4 = 7 * 86400;
|
|
1098
|
+
var SEC_PER_DAY = 86400;
|
|
1099
|
+
var GLO_STRING_BYTES = 10;
|
|
1100
|
+
function getBitG(b, pos, len) {
|
|
1101
|
+
const value = getBitU(b, pos + 1, len - 1);
|
|
1102
|
+
return getBitU(b, pos, 1) && value !== 0 ? -value : value;
|
|
1103
|
+
}
|
|
1104
|
+
var HAMMING_MASKS = [
|
|
1105
|
+
[85, 85, 90, 170, 170, 170, 181, 85, 106, 216, 8],
|
|
1106
|
+
[102, 102, 108, 204, 204, 204, 217, 153, 179, 104, 16],
|
|
1107
|
+
[135, 135, 143, 15, 15, 15, 30, 30, 60, 112, 32],
|
|
1108
|
+
[7, 248, 15, 240, 15, 240, 31, 224, 63, 128, 64],
|
|
1109
|
+
[248, 0, 15, 255, 240, 0, 31, 255, 192, 0, 128],
|
|
1110
|
+
[0, 0, 15, 255, 255, 255, 224, 0, 0, 1, 0],
|
|
1111
|
+
[255, 255, 240, 0, 0, 0, 0, 0, 0, 2, 0],
|
|
1112
|
+
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 248]
|
|
1113
|
+
];
|
|
1114
|
+
function testGloString(buff) {
|
|
1115
|
+
if (buff.length < 11) return false;
|
|
1116
|
+
let n = 0;
|
|
1117
|
+
let cs = 0;
|
|
1118
|
+
for (const mask of HAMMING_MASKS) {
|
|
1119
|
+
cs = 0;
|
|
1120
|
+
for (let j = 0; j < 11; j++) {
|
|
1121
|
+
let x = buff[j] & mask[j];
|
|
1122
|
+
x ^= x >> 4;
|
|
1123
|
+
x ^= x >> 2;
|
|
1124
|
+
x ^= x >> 1;
|
|
1125
|
+
cs ^= x & 1;
|
|
1126
|
+
}
|
|
1127
|
+
if (cs) n++;
|
|
1128
|
+
}
|
|
1129
|
+
return n === 0 || n === 2 && cs === 1;
|
|
1130
|
+
}
|
|
1131
|
+
function decodeGloStrings(strings, refDate, opts = {}) {
|
|
1132
|
+
if (strings.length < 4 * GLO_STRING_BYTES) return null;
|
|
1133
|
+
const b = strings;
|
|
1134
|
+
let i = 1;
|
|
1135
|
+
const frn1 = getBitU(b, i, 4);
|
|
1136
|
+
i += 4 + 2;
|
|
1137
|
+
i += 2;
|
|
1138
|
+
const tkH = getBitU(b, i, 5);
|
|
1139
|
+
i += 5;
|
|
1140
|
+
const tkM = getBitU(b, i, 6);
|
|
1141
|
+
i += 6;
|
|
1142
|
+
const tkS = getBitU(b, i, 1) * 30;
|
|
1143
|
+
i += 1;
|
|
1144
|
+
const xDot = getBitG(b, i, 24) * 2 ** -20;
|
|
1145
|
+
i += 24;
|
|
1146
|
+
const xAcc = getBitG(b, i, 5) * 2 ** -30;
|
|
1147
|
+
i += 5;
|
|
1148
|
+
const x = getBitG(b, i, 27) * 2 ** -11;
|
|
1149
|
+
i = 80 + 1;
|
|
1150
|
+
const frn2 = getBitU(b, i, 4);
|
|
1151
|
+
i += 4;
|
|
1152
|
+
const bn = getBitU(b, i, 1);
|
|
1153
|
+
i += 1 + 2;
|
|
1154
|
+
i += 1;
|
|
1155
|
+
const tb = getBitU(b, i, 7);
|
|
1156
|
+
i += 7 + 5;
|
|
1157
|
+
const yDot = getBitG(b, i, 24) * 2 ** -20;
|
|
1158
|
+
i += 24;
|
|
1159
|
+
const yAcc = getBitG(b, i, 5) * 2 ** -30;
|
|
1160
|
+
i += 5;
|
|
1161
|
+
const y = getBitG(b, i, 27) * 2 ** -11;
|
|
1162
|
+
i = 160 + 1;
|
|
1163
|
+
const frn3 = getBitU(b, i, 4);
|
|
1164
|
+
i += 4;
|
|
1165
|
+
i += 1;
|
|
1166
|
+
const gammaN = getBitG(b, i, 11) * 2 ** -40;
|
|
1167
|
+
i += 11 + 1;
|
|
1168
|
+
i += 2;
|
|
1169
|
+
i += 1;
|
|
1170
|
+
const zDot = getBitG(b, i, 24) * 2 ** -20;
|
|
1171
|
+
i += 24;
|
|
1172
|
+
const zAcc = getBitG(b, i, 5) * 2 ** -30;
|
|
1173
|
+
i += 5;
|
|
1174
|
+
const z = getBitG(b, i, 27) * 2 ** -11;
|
|
1175
|
+
i = 240 + 1;
|
|
1176
|
+
const frn4 = getBitU(b, i, 4);
|
|
1177
|
+
i += 4;
|
|
1178
|
+
const tauN = getBitG(b, i, 22) * 2 ** -30;
|
|
1179
|
+
i += 22;
|
|
1180
|
+
i += 5;
|
|
1181
|
+
i += 5;
|
|
1182
|
+
i += 14;
|
|
1183
|
+
i += 1;
|
|
1184
|
+
i += 4;
|
|
1185
|
+
i += 3;
|
|
1186
|
+
i += 11;
|
|
1187
|
+
const slot = getBitU(b, i, 5);
|
|
1188
|
+
if (frn1 !== 1 || frn2 !== 2 || frn3 !== 3 || frn4 !== 4) return null;
|
|
1189
|
+
if (slot < 1 || slot > 27) return null;
|
|
1190
|
+
const utcSec = (getUtcDate(refDate).getTime() - GPS_EPOCH_MS3) / 1e3;
|
|
1191
|
+
const week = Math.floor(utcSec / SEC_PER_WEEK4);
|
|
1192
|
+
let tow = utcSec - week * SEC_PER_WEEK4;
|
|
1193
|
+
const tod = tow % SEC_PER_DAY;
|
|
1194
|
+
tow -= tod;
|
|
1195
|
+
let tof = tkH * 3600 + tkM * 60 + tkS - 10800;
|
|
1196
|
+
if (tof < tod - 43200) tof += SEC_PER_DAY;
|
|
1197
|
+
else if (tof > tod + 43200) tof -= SEC_PER_DAY;
|
|
1198
|
+
let toe = tb * 900 - 10800;
|
|
1199
|
+
if (toe < tod - 43200) toe += SEC_PER_DAY;
|
|
1200
|
+
else if (toe > tod + 43200) toe -= SEC_PER_DAY;
|
|
1201
|
+
return {
|
|
1202
|
+
system: "R",
|
|
1203
|
+
prn: `R${String(slot).padStart(2, "0")}`,
|
|
1204
|
+
// RINEX GLONASS epochs are UTC: build the UTC toe Date directly.
|
|
1205
|
+
tocDate: new Date(GPS_EPOCH_MS3 + (week * SEC_PER_WEEK4 + tow + toe) * 1e3),
|
|
1206
|
+
tauN: -tauN,
|
|
1207
|
+
// RINEX stores −τn; the SIS carries τn (ICD sign)
|
|
1208
|
+
gammaN,
|
|
1209
|
+
// v3 message frame time: seconds of the UTC week (RTKLIB tof).
|
|
1210
|
+
messageFrameTime: ((tow + tof) % SEC_PER_WEEK4 + SEC_PER_WEEK4) % SEC_PER_WEEK4,
|
|
1211
|
+
x,
|
|
1212
|
+
xDot,
|
|
1213
|
+
xAcc,
|
|
1214
|
+
y,
|
|
1215
|
+
yDot,
|
|
1216
|
+
yAcc,
|
|
1217
|
+
z,
|
|
1218
|
+
zDot,
|
|
1219
|
+
zAcc,
|
|
1220
|
+
// MSB of the 3-bit Bn word — the unhealthy flag RINEX carries
|
|
1221
|
+
health: bn,
|
|
1222
|
+
freqNum: opts.freqNum ?? 0
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
var GloStringAssembler = class {
|
|
1226
|
+
sats = /* @__PURE__ */ new Map();
|
|
1227
|
+
/**
|
|
1228
|
+
* Push one navigation string (10+ bytes, bit 0 = string bit 85) for
|
|
1229
|
+
* the satellite `prn` ("R09"), received at the GPS-scale `time`.
|
|
1230
|
+
* Returns the newly completed ephemeris, or null. The decoded
|
|
1231
|
+
* string-4 slot number must match `prn`, or nothing is emitted.
|
|
1232
|
+
*/
|
|
1233
|
+
push(prn, str, time, freqNum = 0) {
|
|
1234
|
+
if (str.length < GLO_STRING_BYTES) return null;
|
|
1235
|
+
const m = getBitU(str, 1, 4);
|
|
1236
|
+
if (m < 1) return null;
|
|
1237
|
+
const sec = Math.floor(time.getTime() / 1e3);
|
|
1238
|
+
let sat = this.sats.get(prn);
|
|
1239
|
+
if (!sat) {
|
|
1240
|
+
sat = { buf: new Uint8Array(4 * GLO_STRING_BYTES), batchSec: sec };
|
|
1241
|
+
this.sats.set(prn, sat);
|
|
1242
|
+
} else if (Math.abs(sec - sat.batchSec) > 30) {
|
|
1243
|
+
sat.buf.fill(0);
|
|
1244
|
+
sat.batchSec = sec;
|
|
1245
|
+
}
|
|
1246
|
+
if (m > 4) return null;
|
|
1247
|
+
sat.buf.set(str.subarray(0, GLO_STRING_BYTES), (m - 1) * 10);
|
|
1248
|
+
if (m !== 4) return null;
|
|
1249
|
+
const eph = decodeGloStrings(sat.buf, time, { freqNum });
|
|
1250
|
+
if (!eph || eph.prn !== prn) return null;
|
|
1251
|
+
const key = `${eph.tocDate.getTime()}:${eph.health}`;
|
|
1252
|
+
if (key === sat.lastKey) return null;
|
|
1253
|
+
sat.lastKey = key;
|
|
1254
|
+
return eph;
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
// src/sbf/rawnav-bds.ts
|
|
1259
|
+
var GPS_EPOCH_MS4 = Date.UTC(1980, 0, 6);
|
|
1260
|
+
var MS_PER_WEEK3 = 7 * 86400 * 1e3;
|
|
1261
|
+
var TOW_DNU = 4294967295;
|
|
1262
|
+
var WNC_DNU = 65535;
|
|
1263
|
+
function parseSbfBdsNav(data) {
|
|
1264
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1265
|
+
const ephemerides = [];
|
|
1266
|
+
const assembler = new BdsAssembler();
|
|
1267
|
+
let badCrc = 0;
|
|
1268
|
+
let messages = 0;
|
|
1269
|
+
scanSbfFrames(data, view, (id, b, len) => {
|
|
1270
|
+
if (id !== 4047 || len < 60) return;
|
|
1271
|
+
messages++;
|
|
1272
|
+
const prn = svidToPrn(view.getUint8(b + 14));
|
|
1273
|
+
if (!prn || prn[0] !== "C") return;
|
|
1274
|
+
const sf = new Uint8Array(38);
|
|
1275
|
+
for (let k = 0; k < 10; k++) {
|
|
1276
|
+
const w = view.getUint32(b + 20 + 4 * k, true);
|
|
1277
|
+
sf[4 * k] = w >>> 24;
|
|
1278
|
+
if (k < 9) {
|
|
1279
|
+
sf[4 * k + 1] = w >>> 16 & 255;
|
|
1280
|
+
sf[4 * k + 2] = w >>> 8 & 255;
|
|
1281
|
+
sf[4 * k + 3] = w & 255;
|
|
1282
|
+
} else {
|
|
1283
|
+
sf[37] = w >>> 16 & 240;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
if (!bdsSubframeParityOk(sf)) {
|
|
1287
|
+
badCrc++;
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
const eph = assembler.push(prn, sf);
|
|
1291
|
+
if (eph) ephemerides.push(eph);
|
|
1292
|
+
});
|
|
1293
|
+
return { ephemerides, badCrc, messages };
|
|
1294
|
+
}
|
|
1295
|
+
function parseSbfGloNav(data) {
|
|
1296
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1297
|
+
const ephemerides = [];
|
|
1298
|
+
const assembler = new GloStringAssembler();
|
|
1299
|
+
let badCrc = 0;
|
|
1300
|
+
let messages = 0;
|
|
1301
|
+
scanSbfFrames(data, view, (id, b, len) => {
|
|
1302
|
+
if (id !== 4026 || len < 32) return;
|
|
1303
|
+
messages++;
|
|
1304
|
+
const prn = svidToPrn(view.getUint8(b + 14));
|
|
1305
|
+
if (!prn || prn[0] !== "R") return;
|
|
1306
|
+
const towMs = view.getUint32(b + 8, true);
|
|
1307
|
+
const wnc = view.getUint16(b + 12, true);
|
|
1308
|
+
if (towMs === TOW_DNU || wnc === WNC_DNU) return;
|
|
1309
|
+
const str = new Uint8Array(11);
|
|
1310
|
+
for (let k = 0; k < 3; k++) {
|
|
1311
|
+
const w = view.getUint32(b + 20 + 4 * k, true);
|
|
1312
|
+
str[4 * k] = w >>> 24;
|
|
1313
|
+
if (k < 2) {
|
|
1314
|
+
str[4 * k + 1] = w >>> 16 & 255;
|
|
1315
|
+
str[4 * k + 2] = w >>> 8 & 255;
|
|
1316
|
+
str[4 * k + 3] = w & 255;
|
|
1317
|
+
} else {
|
|
1318
|
+
str[9] = w >>> 16 & 255;
|
|
1319
|
+
str[10] = w >>> 8 & 248;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
if (!testGloString(str)) {
|
|
1323
|
+
badCrc++;
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const eph = assembler.push(
|
|
1327
|
+
prn,
|
|
1328
|
+
str,
|
|
1329
|
+
new Date(GPS_EPOCH_MS4 + wnc * MS_PER_WEEK3 + towMs),
|
|
1330
|
+
view.getUint8(b + 18) - 8
|
|
1331
|
+
// FreqNr, offset by 8
|
|
1332
|
+
);
|
|
1333
|
+
if (eph) ephemerides.push(eph);
|
|
1334
|
+
});
|
|
1335
|
+
return { ephemerides, badCrc, messages };
|
|
1336
|
+
}
|
|
1337
|
+
|
|
447
1338
|
// src/sbf/index.ts
|
|
448
1339
|
var CLIGHT = 299792458;
|
|
449
|
-
var
|
|
450
|
-
var
|
|
1340
|
+
var GPS_EPOCH_MS5 = Date.UTC(1980, 0, 6);
|
|
1341
|
+
var MS_PER_WEEK4 = 7 * 864e5;
|
|
451
1342
|
var M3_SYS = ["G", "R", "E", "C", "S", "J", "I"];
|
|
452
1343
|
var M3_PR_BASE = [19e6, 19e6, 22e6, 2e7, 34e6, 34e6, 34e6];
|
|
453
1344
|
var M3_INTERVALS = [
|
|
@@ -546,23 +1437,23 @@ var MEAS2_SIG = [
|
|
|
546
1437
|
["J", "1E"],
|
|
547
1438
|
["J", "5P"]
|
|
548
1439
|
];
|
|
549
|
-
var
|
|
1440
|
+
var two3 = (n) => String(n).padStart(2, "0");
|
|
550
1441
|
function m3Prn(navsys, svid) {
|
|
551
1442
|
switch (navsys) {
|
|
552
1443
|
case 0:
|
|
553
|
-
return svid < 32 ? `G${
|
|
1444
|
+
return svid < 32 ? `G${two3(svid + 1)}` : null;
|
|
554
1445
|
case 1:
|
|
555
|
-
return svid < 27 ? `R${
|
|
1446
|
+
return svid < 27 ? `R${two3(svid + 1)}` : null;
|
|
556
1447
|
case 2:
|
|
557
|
-
return svid < 36 ? `E${
|
|
1448
|
+
return svid < 36 ? `E${two3(svid + 1)}` : null;
|
|
558
1449
|
case 3:
|
|
559
|
-
return svid < 50 ? `C${
|
|
1450
|
+
return svid < 50 ? `C${two3(svid + 1)}` : null;
|
|
560
1451
|
case 4:
|
|
561
|
-
return svid <= 38 ? `S${
|
|
1452
|
+
return svid <= 38 ? `S${two3(svid + 20)}` : null;
|
|
562
1453
|
case 5:
|
|
563
|
-
return svid < 10 ? `J${
|
|
1454
|
+
return svid < 10 ? `J${two3(svid + 1)}` : null;
|
|
564
1455
|
case 6:
|
|
565
|
-
return svid < 14 ? `I${
|
|
1456
|
+
return svid < 14 ? `I${two3(svid + 1)}` : null;
|
|
566
1457
|
default:
|
|
567
1458
|
return null;
|
|
568
1459
|
}
|
|
@@ -1100,7 +1991,7 @@ function parseSbfMeas(data) {
|
|
|
1100
1991
|
const tow = view.getUint32(i + 8, true);
|
|
1101
1992
|
const wnc = view.getUint16(i + 12, true);
|
|
1102
1993
|
if (tow !== 4294967295 && wnc !== 65535) {
|
|
1103
|
-
ensureEpoch(
|
|
1994
|
+
ensureEpoch(GPS_EPOCH_MS5 + wnc * MS_PER_WEEK4 + tow);
|
|
1104
1995
|
if (id === 4109) decodeMeas3Ranges(i, tow);
|
|
1105
1996
|
else if (id === 4110) decodeMeas3CN0(i, len);
|
|
1106
1997
|
else if (id === 4111) decodeMeas3Doppler(i, len);
|
|
@@ -1119,5 +2010,8 @@ export {
|
|
|
1119
2010
|
parseSbfAlmanac,
|
|
1120
2011
|
parseSbfIonoUtc,
|
|
1121
2012
|
parseSbfCnav,
|
|
2013
|
+
parseSbfGalNav,
|
|
2014
|
+
parseSbfBdsNav,
|
|
2015
|
+
parseSbfGloNav,
|
|
1122
2016
|
parseSbfMeas
|
|
1123
2017
|
};
|