gnss-js 1.1.0 → 1.3.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.
@@ -0,0 +1,206 @@
1
+ import {
2
+ computeDop,
3
+ computeSatPosition,
4
+ ecefToAzEl
5
+ } from "./chunk-ZCNXERQ2.js";
6
+ import "./chunk-HVXYFUCB.js";
7
+ import "./chunk-37QNKGTC.js";
8
+ import "./chunk-6FAL6P4G.js";
9
+ import "./chunk-LEEU5OIO.js";
10
+ import {
11
+ C_LIGHT
12
+ } from "./chunk-W5WKEV7U.js";
13
+
14
+ // src/positioning/index.ts
15
+ var GM_GPS = 3986005e8;
16
+ var F_REL = -4442807633e-19;
17
+ function satClockCorrection(eph, tMs) {
18
+ if (eph.system === "R" || eph.system === "S") {
19
+ const dt2 = (tMs - eph.tocDate.getTime()) / 1e3;
20
+ return eph.tauN + eph.gammaN * dt2;
21
+ }
22
+ const k = eph;
23
+ const dt = (tMs - k.tocDate.getTime()) / 1e3;
24
+ const poly = k.af0 + k.af1 * dt + k.af2 * dt * dt;
25
+ const a = k.sqrtA * k.sqrtA;
26
+ const n = Math.sqrt(GM_GPS / (a * a * a)) + k.deltaN;
27
+ const tk = dt;
28
+ const Mk = k.m0 + n * tk;
29
+ let Ek = Mk;
30
+ for (let i = 0; i < 8; i++) {
31
+ Ek = Mk + k.e * Math.sin(Ek);
32
+ }
33
+ const rel = F_REL * k.e * k.sqrtA * Math.sin(Ek);
34
+ return poly + rel;
35
+ }
36
+ function ionoFree(p1, p2, f1, f2) {
37
+ const g = f1 * f1 / (f1 * f1 - f2 * f2);
38
+ return g * p1 - (g - 1) * p2;
39
+ }
40
+ function tropoDelay(elevationRad) {
41
+ const sinEl = Math.sin(elevationRad);
42
+ return 2.47 / (sinEl + 0.0121);
43
+ }
44
+ function sagnac(pos, travelTimeS) {
45
+ const OMEGA_E = 72921151467e-15;
46
+ const theta = OMEGA_E * travelTimeS;
47
+ const c = Math.cos(theta);
48
+ const s = Math.sin(theta);
49
+ return [pos.x * c + pos.y * s, -pos.x * s + pos.y * c, pos.z];
50
+ }
51
+ function solveLinear(A, b) {
52
+ const n = b.length;
53
+ const M = A.map((row, i) => [...row, b[i]]);
54
+ for (let col = 0; col < n; col++) {
55
+ let pivot = col;
56
+ for (let r = col + 1; r < n; r++) {
57
+ if (Math.abs(M[r][col]) > Math.abs(M[pivot][col])) pivot = r;
58
+ }
59
+ if (Math.abs(M[pivot][col]) < 1e-12) return null;
60
+ [M[col], M[pivot]] = [M[pivot], M[col]];
61
+ for (let r = 0; r < n; r++) {
62
+ if (r === col) continue;
63
+ const f = M[r][col] / M[col][col];
64
+ for (let c = col; c <= n; c++) M[r][c] -= f * M[col][c];
65
+ }
66
+ }
67
+ return M.map((row, i) => row[n] / M[i][i]);
68
+ }
69
+ function solveSpp(pseudoranges, ephemerides, timeMs, opts = {}) {
70
+ const {
71
+ elevationMaskDeg = 10,
72
+ troposphere = true,
73
+ maxIterations = 15,
74
+ convergenceM = 1e-4
75
+ } = opts;
76
+ const all = [...pseudoranges.keys()].filter((p) => ephemerides.has(p));
77
+ const minSats = (list) => 3 + new Set(list.map((p) => p[0])).size;
78
+ if (all.length < minSats(all)) return null;
79
+ const gaussNewton = (prns) => {
80
+ const systems = [...new Set(prns.map((p) => p[0]))].sort();
81
+ const dim = 3 + systems.length;
82
+ const sysIndex = new Map(systems.map((s, i) => [s, 3 + i]));
83
+ let x2 = 0;
84
+ let y2 = 0;
85
+ let z2 = 0;
86
+ const clock2 = new Map(systems.map((s) => [s, 0]));
87
+ const residuals2 = {};
88
+ let iterations2 = 0;
89
+ let converged2 = false;
90
+ for (let iter = 0; iter < maxIterations; iter++) {
91
+ iterations2 = iter + 1;
92
+ const HtH = Array.from(
93
+ { length: dim },
94
+ () => new Array(dim).fill(0)
95
+ );
96
+ const Htv = new Array(dim).fill(0);
97
+ let rows = 0;
98
+ for (const k of Object.keys(residuals2)) delete residuals2[k];
99
+ for (const prn of prns) {
100
+ const psr = pseudoranges.get(prn);
101
+ const eph = ephemerides.get(prn);
102
+ const sys = prn[0];
103
+ const clk = clock2.get(sys);
104
+ const tTx = timeMs - psr / C_LIGHT * 1e3;
105
+ const sat = computeSatPosition(eph, tTx);
106
+ if (!Number.isFinite(sat.x)) continue;
107
+ const dts = satClockCorrection(eph, tTx);
108
+ const travel = Math.hypot(sat.x - x2, sat.y - y2, sat.z - z2) / C_LIGHT;
109
+ const [sx, sy, sz] = sagnac(sat, travel);
110
+ const rho = Math.hypot(sx - x2, sy - y2, sz - z2);
111
+ const ux = (x2 - sx) / rho;
112
+ const uy = (y2 - sy) / rho;
113
+ const uz = (z2 - sz) / rho;
114
+ let elev = Math.PI / 2;
115
+ let weight = 1;
116
+ const positionSane = x2 * x2 + y2 * y2 + z2 * z2 > 1e12;
117
+ if (positionSane) {
118
+ const azel = ecefToAzEl(x2, y2, z2, sx, sy, sz);
119
+ elev = azel.el;
120
+ if (iter >= 2 && elev < elevationMaskDeg * Math.PI / 180) continue;
121
+ const sinEl = Math.max(Math.sin(elev), 0.1);
122
+ weight = sinEl * sinEl;
123
+ }
124
+ const tropo = troposphere && positionSane ? tropoDelay(elev) : 0;
125
+ const predicted = rho + clk - C_LIGHT * dts + tropo;
126
+ const v = psr - predicted;
127
+ const h = new Array(dim).fill(0);
128
+ h[0] = ux;
129
+ h[1] = uy;
130
+ h[2] = uz;
131
+ h[sysIndex.get(sys)] = 1;
132
+ for (let i = 0; i < dim; i++) {
133
+ for (let j = 0; j < dim; j++) HtH[i][j] += weight * h[i] * h[j];
134
+ Htv[i] += weight * h[i] * v;
135
+ }
136
+ residuals2[prn] = v;
137
+ rows++;
138
+ }
139
+ if (rows < dim) return null;
140
+ const dx = solveLinear(HtH, Htv);
141
+ if (!dx) return null;
142
+ x2 += dx[0];
143
+ y2 += dx[1];
144
+ z2 += dx[2];
145
+ for (const s of systems)
146
+ clock2.set(s, clock2.get(s) + dx[sysIndex.get(s)]);
147
+ if (Math.hypot(dx[0], dx[1], dx[2]) < convergenceM) {
148
+ converged2 = true;
149
+ break;
150
+ }
151
+ }
152
+ return { x: x2, y: y2, z: z2, clock: clock2, residuals: residuals2, iterations: iterations2, converged: converged2 };
153
+ };
154
+ const REJECT_THRESHOLD_M = 50;
155
+ let candidates = all;
156
+ const rejected = [];
157
+ let inner = null;
158
+ for (let round = 0; round <= all.length; round++) {
159
+ inner = gaussNewton(candidates);
160
+ if (!inner) return null;
161
+ const vals = Object.entries(inner.residuals);
162
+ let worst = null;
163
+ let worstAbs = REJECT_THRESHOLD_M;
164
+ for (const [prn, v] of vals) {
165
+ if (Math.abs(v) > worstAbs) {
166
+ worstAbs = Math.abs(v);
167
+ worst = prn;
168
+ }
169
+ }
170
+ if (!worst) break;
171
+ const remaining = candidates.filter((p) => p !== worst);
172
+ if (remaining.length < minSats(remaining)) break;
173
+ rejected.push(worst);
174
+ candidates = remaining;
175
+ }
176
+ if (!inner) return null;
177
+ const { x, y, z, clock, residuals, iterations, converged } = inner;
178
+ const used = [];
179
+ const azels = [];
180
+ for (const prn of candidates) {
181
+ if (!(prn in residuals)) continue;
182
+ const eph = ephemerides.get(prn);
183
+ const sat = computeSatPosition(eph, timeMs);
184
+ if (!Number.isFinite(sat.x)) continue;
185
+ const azel = ecefToAzEl(x, y, z, sat.x, sat.y, sat.z);
186
+ if (azel.el >= elevationMaskDeg * Math.PI / 180) {
187
+ used.push(prn);
188
+ azels.push(azel);
189
+ }
190
+ }
191
+ return {
192
+ position: [x, y, z],
193
+ clockBias: Object.fromEntries(clock),
194
+ usedSatellites: used,
195
+ rejectedSatellites: rejected,
196
+ residuals,
197
+ dop: computeDop(azels),
198
+ iterations,
199
+ converged
200
+ };
201
+ }
202
+ export {
203
+ ionoFree,
204
+ satClockCorrection,
205
+ solveSpp
206
+ };
package/dist/rtcm3.js CHANGED
@@ -15,9 +15,9 @@ import {
15
15
  setRtcm3DebugHandler,
16
16
  updateStationMeta,
17
17
  updateStreamStats
18
- } from "./chunk-JDO3LEPC.js";
19
- import "./chunk-W5WKEV7U.js";
18
+ } from "./chunk-7EEWQ5DU.js";
20
19
  import "./chunk-LEEU5OIO.js";
20
+ import "./chunk-W5WKEV7U.js";
21
21
  export {
22
22
  BitReader,
23
23
  RTCM3_MESSAGE_NAMES,
package/dist/time.js CHANGED
@@ -1,39 +1,43 @@
1
1
  import {
2
2
  Scale,
3
- getBdsTime,
4
- getDateFromBdsTime,
5
3
  getDateFromDayOfWeek,
6
4
  getDateFromDayOfYear,
7
- getDateFromGalTime,
8
- getDateFromGloN,
9
- getDateFromGpsData,
10
- getDateFromGpsTime,
11
5
  getDateFromHourCode,
12
6
  getDateFromJulianDate,
13
7
  getDateFromMJD,
14
8
  getDateFromMJD2000,
15
9
  getDateFromRINEX,
16
- getDateFromTai,
17
10
  getDateFromTimeOfDay,
11
+ getDayOfWeek,
12
+ getDayOfYear,
13
+ getHourCode,
14
+ getJulianDate,
15
+ getMJD,
16
+ getMJD2000,
17
+ getRINEX,
18
+ getTimeOfDay,
19
+ getWeekOfYear
20
+ } from "./chunk-L5OUUNLT.js";
21
+ import {
22
+ getBdsTime,
23
+ getDateFromBdsTime,
24
+ getDateFromGalTime,
25
+ getDateFromGloN,
26
+ getDateFromGpsData,
27
+ getDateFromGpsTime,
28
+ getDateFromTai,
18
29
  getDateFromTt,
19
30
  getDateFromUnixTime,
20
31
  getDateFromUtc,
21
- getDayOfWeek,
22
- getDayOfYear,
23
32
  getGalTime,
24
33
  getGloN4,
25
34
  getGloNA,
26
35
  getGpsLeap,
27
36
  getGpsTime,
28
- getHourCode,
29
37
  getHoursFromTimeDifference,
30
- getJulianDate,
31
38
  getLeap,
32
- getMJD,
33
- getMJD2000,
34
39
  getMinutesFromTimeDifference,
35
40
  getNtpTime,
36
- getRINEX,
37
41
  getSecondsFromTimeDifference,
38
42
  getTaiDate,
39
43
  getTimeDifference,
@@ -42,15 +46,13 @@ import {
42
46
  getTimeDifferenceFromMinutes,
43
47
  getTimeDifferenceFromObject,
44
48
  getTimeDifferenceFromSeconds,
45
- getTimeOfDay,
46
49
  getTimeOfWeek,
47
50
  getTotalDaysFromTimeDifference,
48
51
  getTtDate,
49
52
  getUnixTime,
50
53
  getUtcDate,
51
- getWeekNumber,
52
- getWeekOfYear
53
- } from "./chunk-7NOFXKET.js";
54
+ getWeekNumber
55
+ } from "./chunk-HVXYFUCB.js";
54
56
  import {
55
57
  DAYS_MJD2000_MJD,
56
58
  DAYS_MJD_JULIAN,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gnss-js",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Comprehensive GNSS library for JavaScript — time scales, coordinates, RINEX parsing, RTCM3 decoding, orbit computation, and signal analysis",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -64,6 +64,16 @@
64
64
  "types": "./dist/signals.d.ts",
65
65
  "import": "./dist/signals.js",
66
66
  "require": "./dist/signals.cjs"
67
+ },
68
+ "./frames": {
69
+ "types": "./dist/frames.d.ts",
70
+ "import": "./dist/frames.js",
71
+ "require": "./dist/frames.cjs"
72
+ },
73
+ "./positioning": {
74
+ "types": "./dist/positioning.d.ts",
75
+ "import": "./dist/positioning.js",
76
+ "require": "./dist/positioning.cjs"
67
77
  }
68
78
  },
69
79
  "main": "./dist/index.cjs",
@@ -1,3 +1,8 @@
1
+ import {
2
+ MILLISECONDS_IN_WEEK,
3
+ START_BDS_TIME,
4
+ START_GPS_TIME
5
+ } from "./chunk-LEEU5OIO.js";
1
6
  import {
2
7
  C_LIGHT,
3
8
  FREQ,
@@ -6,11 +11,6 @@ import {
6
11
  GLO_F2_BASE,
7
12
  GLO_F2_STEP
8
13
  } from "./chunk-W5WKEV7U.js";
9
- import {
10
- MILLISECONDS_IN_WEEK,
11
- START_BDS_TIME,
12
- START_GPS_TIME
13
- } from "./chunk-LEEU5OIO.js";
14
14
 
15
15
  // src/rtcm3/decoder.ts
16
16
  var debugHandler = null;