gnss-js 2.11.0 → 2.12.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.
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  getUtcDate
3
3
  } from "./chunk-HVXYFUCB.js";
4
- import {
5
- crc24q
6
- } from "./chunk-HUXQABJI.js";
7
4
  import {
8
5
  GPS_PI,
9
6
  getBitS,
@@ -288,317 +285,9 @@ var BdsAssembler = class {
288
285
  }
289
286
  };
290
287
 
291
- // src/navbits/gal.ts
288
+ // src/navbits/glo.ts
292
289
  var GPS_EPOCH_MS = Date.UTC(1980, 0, 6);
293
290
  var SEC_PER_WEEK2 = 7 * 86400;
294
- var HALF_WEEK2 = 302400;
295
- var GST_GPS_WEEK_OFFSET = 1024;
296
- function galInavPageCrcOk(page) {
297
- if (page.length < 28) return false;
298
- return crc24q(page, 196) === getBitU(page, 196, 24);
299
- }
300
- function galFnavPageCrcOk(page) {
301
- if (page.length < 30) return false;
302
- return crc24q(page, 214) === getBitU(page, 214, 24);
303
- }
304
- function gpsDate(week, sec) {
305
- return new Date(GPS_EPOCH_MS + (week * SEC_PER_WEEK2 + sec) * 1e3);
306
- }
307
- function weekOfToe(week, tow, toe) {
308
- if (toe - tow > HALF_WEEK2) return week - 1;
309
- if (toe - tow < -HALF_WEEK2) return week + 1;
310
- return week;
311
- }
312
- var two = (n) => String(n).padStart(2, "0");
313
- function decodeGalInavWords(words) {
314
- if (words.length < 96) return null;
315
- const b = words;
316
- let i = 128;
317
- const type1 = getBitU(b, i, 6);
318
- i += 6;
319
- const iodNav1 = getBitU(b, i, 10);
320
- i += 10;
321
- const toes = getBitU(b, i, 14) * 60;
322
- i += 14;
323
- const m0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
324
- i += 32;
325
- const e = getBitU(b, i, 32) * 2 ** -33;
326
- i += 32;
327
- const sqrtA = getBitU(b, i, 32) * 2 ** -19;
328
- i = 128 * 2;
329
- const type2 = getBitU(b, i, 6);
330
- i += 6;
331
- const iodNav2 = getBitU(b, i, 10);
332
- i += 10;
333
- const omega0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
334
- i += 32;
335
- const i0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
336
- i += 32;
337
- const omega = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
338
- i += 32;
339
- const idot = getBitS(b, i, 14) * 2 ** -43 * GPS_PI;
340
- i = 128 * 3;
341
- const type3 = getBitU(b, i, 6);
342
- i += 6;
343
- const iodNav3 = getBitU(b, i, 10);
344
- i += 10;
345
- const omegaDot = getBitS(b, i, 24) * 2 ** -43 * GPS_PI;
346
- i += 24;
347
- const deltaN = getBitS(b, i, 16) * 2 ** -43 * GPS_PI;
348
- i += 16;
349
- const cuc = getBitS(b, i, 16) * 2 ** -29;
350
- i += 16;
351
- const cus = getBitS(b, i, 16) * 2 ** -29;
352
- i += 16;
353
- const crc = getBitS(b, i, 16) * 2 ** -5;
354
- i += 16;
355
- const crs = getBitS(b, i, 16) * 2 ** -5;
356
- i = 128 * 4;
357
- const type4 = getBitU(b, i, 6);
358
- i += 6;
359
- const iodNav4 = getBitU(b, i, 10);
360
- i += 10;
361
- const svid = getBitU(b, i, 6);
362
- i += 6;
363
- const cic = getBitS(b, i, 16) * 2 ** -29;
364
- i += 16;
365
- const cis = getBitS(b, i, 16) * 2 ** -29;
366
- i += 16;
367
- const tocs = getBitU(b, i, 14) * 60;
368
- i += 14;
369
- const af0 = getBitS(b, i, 31) * 2 ** -34;
370
- i += 31;
371
- const af1 = getBitS(b, i, 21) * 2 ** -46;
372
- i += 21;
373
- const af2 = getBitS(b, i, 6) * 2 ** -59;
374
- i = 128 * 5;
375
- const type5 = getBitU(b, i, 6);
376
- i += 6 + 11 + 11 + 14 + 5;
377
- const bgdE5a = getBitS(b, i, 10) * 2 ** -32;
378
- i += 10;
379
- i += 10;
380
- const e5bHs = getBitU(b, i, 2);
381
- i += 2;
382
- const e1bHs = getBitU(b, i, 2);
383
- i += 2;
384
- const e5bDvs = getBitU(b, i, 1);
385
- i += 1;
386
- const e1bDvs = getBitU(b, i, 1);
387
- i += 1;
388
- const gstWeek = getBitU(b, i, 12);
389
- i += 12;
390
- const tow = getBitU(b, i, 20);
391
- if (type1 !== 1 || type2 !== 2 || type3 !== 3 || type4 !== 4 || type5 !== 5)
392
- return null;
393
- if (iodNav1 !== iodNav2 || iodNav1 !== iodNav3 || iodNav1 !== iodNav4)
394
- return null;
395
- if (svid < 1 || svid > 36) return null;
396
- const week = weekOfToe(gstWeek, tow, toes) + GST_GPS_WEEK_OFFSET;
397
- const tocDate = gpsDate(week, tocs);
398
- return {
399
- system: "E",
400
- prn: `E${two(svid)}`,
401
- toc: tocDate.getTime() / 1e3 % SEC_PER_WEEK2,
402
- tocDate,
403
- af0,
404
- af1,
405
- af2,
406
- iode: iodNav1,
407
- crs,
408
- deltaN,
409
- m0,
410
- cuc,
411
- e,
412
- cus,
413
- sqrtA,
414
- toe: toes,
415
- cic,
416
- omega0,
417
- cis,
418
- i0,
419
- crc,
420
- omega,
421
- omegaDot,
422
- idot,
423
- week,
424
- svHealth: e5bHs << 7 | e5bDvs << 6 | e1bHs << 1 | e1bDvs,
425
- tgd: bgdE5a
426
- };
427
- }
428
- function decodeGalFnavPages(pages) {
429
- if (pages.length < 124) return null;
430
- const b = pages;
431
- let i = 0;
432
- const type1 = getBitU(b, i, 6);
433
- i += 6;
434
- const svid = getBitU(b, i, 6);
435
- i += 6;
436
- const iodNav1 = getBitU(b, i, 10);
437
- i += 10;
438
- const tocs = getBitU(b, i, 14) * 60;
439
- i += 14;
440
- const af0 = getBitS(b, i, 31) * 2 ** -34;
441
- i += 31;
442
- const af1 = getBitS(b, i, 21) * 2 ** -46;
443
- i += 21;
444
- const af2 = getBitS(b, i, 6) * 2 ** -59;
445
- i += 6;
446
- i += 8 + 11 + 11 + 14 + 5;
447
- const bgdE5a = getBitS(b, i, 10) * 2 ** -32;
448
- i += 10;
449
- const e5aHs = getBitU(b, i, 2);
450
- i += 2;
451
- const gstWeek = getBitU(b, i, 12);
452
- i += 12;
453
- const tow = getBitU(b, i, 20);
454
- i += 20;
455
- const e5aDvs = getBitU(b, i, 1);
456
- i = 31 * 8;
457
- const type2 = getBitU(b, i, 6);
458
- i += 6;
459
- const iodNav2 = getBitU(b, i, 10);
460
- i += 10;
461
- const m0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
462
- i += 32;
463
- const omegaDot = getBitS(b, i, 24) * 2 ** -43 * GPS_PI;
464
- i += 24;
465
- const e = getBitU(b, i, 32) * 2 ** -33;
466
- i += 32;
467
- const sqrtA = getBitU(b, i, 32) * 2 ** -19;
468
- i += 32;
469
- const omega0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
470
- i += 32;
471
- const idot = getBitS(b, i, 14) * 2 ** -43 * GPS_PI;
472
- i = 62 * 8;
473
- const type3 = getBitU(b, i, 6);
474
- i += 6;
475
- const iodNav3 = getBitU(b, i, 10);
476
- i += 10;
477
- const i0 = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
478
- i += 32;
479
- const omega = getBitS(b, i, 32) * 2 ** -31 * GPS_PI;
480
- i += 32;
481
- const deltaN = getBitS(b, i, 16) * 2 ** -43 * GPS_PI;
482
- i += 16;
483
- const cuc = getBitS(b, i, 16) * 2 ** -29;
484
- i += 16;
485
- const cus = getBitS(b, i, 16) * 2 ** -29;
486
- i += 16;
487
- const crc = getBitS(b, i, 16) * 2 ** -5;
488
- i += 16;
489
- const crs = getBitS(b, i, 16) * 2 ** -5;
490
- i += 16;
491
- const toes = getBitU(b, i, 14) * 60;
492
- i = 93 * 8;
493
- const type4 = getBitU(b, i, 6);
494
- i += 6;
495
- const iodNav4 = getBitU(b, i, 10);
496
- i += 10;
497
- const cic = getBitS(b, i, 16) * 2 ** -29;
498
- i += 16;
499
- const cis = getBitS(b, i, 16) * 2 ** -29;
500
- if (type1 !== 1 || type2 !== 2 || type3 !== 3 || type4 !== 4) return null;
501
- if (iodNav1 !== iodNav2 || iodNav1 !== iodNav3 || iodNav1 !== iodNav4)
502
- return null;
503
- if (svid < 1 || svid > 36) return null;
504
- const week = weekOfToe(gstWeek, tow, toes) + GST_GPS_WEEK_OFFSET;
505
- const tocDate = gpsDate(week, tocs);
506
- return {
507
- system: "E",
508
- prn: `E${two(svid)}`,
509
- toc: tocDate.getTime() / 1e3 % SEC_PER_WEEK2,
510
- tocDate,
511
- af0,
512
- af1,
513
- af2,
514
- iode: iodNav1,
515
- crs,
516
- deltaN,
517
- m0,
518
- cuc,
519
- e,
520
- cus,
521
- sqrtA,
522
- toe: toes,
523
- cic,
524
- omega0,
525
- cis,
526
- i0,
527
- crc,
528
- omega,
529
- omegaDot,
530
- idot,
531
- week,
532
- svHealth: e5aHs << 4 | e5aDvs << 3,
533
- tgd: bgdE5a
534
- };
535
- }
536
- var dedupKey = (eph) => `${eph.iode}:${eph.toe}:${eph.tocDate.getTime()}`;
537
- var GalInavAssembler = class {
538
- sats = /* @__PURE__ */ new Map();
539
- /**
540
- * Push one I/NAV page pair for satellite `prn` (1-36): the 234-bit
541
- * even+odd concatenation, even part first with its 6 tail bits
542
- * removed, bit 0 = the even part's Even/Odd bit (≥ 17 bytes).
543
- * Returns the newly completed ephemeris, or null. Pages that are
544
- * not an even/odd nominal pair, alert pages and word types outside
545
- * 1-5 are ignored.
546
- */
547
- push(prn, page) {
548
- if (prn < 1 || prn > 36 || page.length < 17) return null;
549
- if (getBitU(page, 0, 1) !== 0 || getBitU(page, 114, 1) !== 1) return null;
550
- if (getBitU(page, 1, 1) === 1 || getBitU(page, 115, 1) === 1) return null;
551
- const type = getBitU(page, 2, 6);
552
- if (type < 1 || type > 5) return null;
553
- let sat = this.sats.get(prn);
554
- if (!sat) {
555
- sat = { words: new Uint8Array(96) };
556
- this.sats.set(prn, sat);
557
- }
558
- for (let k = 0; k < 14; k++)
559
- sat.words[type * 16 + k] = getBitU(page, 2 + 8 * k, 8);
560
- sat.words[type * 16 + 14] = getBitU(page, 116, 8);
561
- sat.words[type * 16 + 15] = getBitU(page, 124, 8);
562
- if (type !== 5) return null;
563
- const eph = decodeGalInavWords(sat.words);
564
- if (!eph || eph.prn !== `E${two(prn)}`) return null;
565
- const key = dedupKey(eph);
566
- if (key === sat.lastKey) return null;
567
- sat.lastKey = key;
568
- return eph;
569
- }
570
- };
571
- var GalFnavAssembler = class {
572
- sats = /* @__PURE__ */ new Map();
573
- /**
574
- * Push one F/NAV page for satellite `prn` (1-36): 244 bits with the
575
- * sync field stripped, bit 0 = first page-type bit (≥ 31 bytes).
576
- * Returns the newly completed ephemeris, or null. Dummy pages
577
- * (type 63) and page types outside 1-4 are ignored.
578
- */
579
- push(prn, page) {
580
- if (prn < 1 || prn > 36 || page.length < 31) return null;
581
- const type = getBitU(page, 0, 6);
582
- if (type < 1 || type > 4) return null;
583
- let sat = this.sats.get(prn);
584
- if (!sat) {
585
- sat = { words: new Uint8Array(124) };
586
- this.sats.set(prn, sat);
587
- }
588
- sat.words.set(page.subarray(0, 31), (type - 1) * 31);
589
- if (type !== 4) return null;
590
- const eph = decodeGalFnavPages(sat.words);
591
- if (!eph || eph.prn !== `E${two(prn)}`) return null;
592
- const key = dedupKey(eph);
593
- if (key === sat.lastKey) return null;
594
- sat.lastKey = key;
595
- return eph;
596
- }
597
- };
598
-
599
- // src/navbits/glo.ts
600
- var GPS_EPOCH_MS2 = Date.UTC(1980, 0, 6);
601
- var SEC_PER_WEEK3 = 7 * 86400;
602
291
  var SEC_PER_DAY = 86400;
603
292
  var GLO_STRING_BYTES = 10;
604
293
  function getBitG(b, pos, len) {
@@ -691,9 +380,9 @@ function decodeGloStrings(strings, refDate, opts = {}) {
691
380
  const slot = getBitU(b, i, 5);
692
381
  if (frn1 !== 1 || frn2 !== 2 || frn3 !== 3 || frn4 !== 4) return null;
693
382
  if (slot < 1 || slot > 27) return null;
694
- const utcSec = (getUtcDate(refDate).getTime() - GPS_EPOCH_MS2) / 1e3;
695
- const week = Math.floor(utcSec / SEC_PER_WEEK3);
696
- let tow = utcSec - week * SEC_PER_WEEK3;
383
+ const utcSec = (getUtcDate(refDate).getTime() - GPS_EPOCH_MS) / 1e3;
384
+ const week = Math.floor(utcSec / SEC_PER_WEEK2);
385
+ let tow = utcSec - week * SEC_PER_WEEK2;
697
386
  const tod = tow % SEC_PER_DAY;
698
387
  tow -= tod;
699
388
  let tof = tkH * 3600 + tkM * 60 + tkS - 10800;
@@ -706,12 +395,12 @@ function decodeGloStrings(strings, refDate, opts = {}) {
706
395
  system: "R",
707
396
  prn: `R${String(slot).padStart(2, "0")}`,
708
397
  // RINEX GLONASS epochs are UTC: build the UTC toe Date directly.
709
- tocDate: new Date(GPS_EPOCH_MS2 + (week * SEC_PER_WEEK3 + tow + toe) * 1e3),
398
+ tocDate: new Date(GPS_EPOCH_MS + (week * SEC_PER_WEEK2 + tow + toe) * 1e3),
710
399
  tauN: -tauN,
711
400
  // RINEX stores −τn; the SIS carries τn (ICD sign)
712
401
  gammaN,
713
402
  // v3 message frame time: seconds of the UTC week (RTKLIB tof).
714
- messageFrameTime: ((tow + tof) % SEC_PER_WEEK3 + SEC_PER_WEEK3) % SEC_PER_WEEK3,
403
+ messageFrameTime: ((tow + tof) % SEC_PER_WEEK2 + SEC_PER_WEEK2) % SEC_PER_WEEK2,
715
404
  x,
716
405
  xDot,
717
406
  xAcc,
@@ -762,10 +451,6 @@ var GloStringAssembler = class {
762
451
  export {
763
452
  bdsSubframeParityOk,
764
453
  BdsAssembler,
765
- galInavPageCrcOk,
766
- galFnavPageCrcOk,
767
- GalInavAssembler,
768
- GalFnavAssembler,
769
454
  testGloString,
770
455
  GloStringAssembler
771
456
  };