gnss-js 1.25.0 → 1.27.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/binex.cjs +799 -0
- package/dist/binex.d.cts +189 -0
- package/dist/binex.d.ts +189 -0
- package/dist/binex.js +19 -0
- package/dist/{chunk-VTX3VCL4.js → chunk-5AUK42AL.js} +4 -2
- package/dist/{chunk-WZDFZ76K.js → chunk-726LQBGM.js} +8 -148
- package/dist/{chunk-PZNVFCKJ.js → chunk-AFEDNWXI.js} +5 -3
- package/dist/chunk-CKRNXZHT.js +424 -0
- package/dist/{chunk-7RKLWE6R.js → chunk-F4CM6Q4F.js} +4 -2
- package/dist/{chunk-MCAVU3XL.js → chunk-FEOMYZEU.js} +5 -3
- package/dist/chunk-IQ5OIMQD.js +148 -0
- package/dist/chunk-OK4GGNOO.js +756 -0
- package/dist/{chunk-NOQAAUGY.js → chunk-QVNNHACQ.js} +441 -2
- package/dist/index.cjs +1635 -17
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +43 -16
- package/dist/novatel.js +3 -2
- package/dist/rinex.cjs +438 -0
- package/dist/rinex.d.cts +27 -1
- package/dist/rinex.d.ts +27 -1
- package/dist/rinex.js +5 -2
- package/dist/sbf.js +4 -3
- package/dist/trimble.cjs +452 -0
- package/dist/trimble.d.cts +147 -0
- package/dist/trimble.d.ts +147 -0
- package/dist/trimble.js +10 -0
- package/dist/ubx.js +4 -3
- package/package.json +11 -1
package/dist/binex.cjs
ADDED
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/binex/index.ts
|
|
21
|
+
var binex_exports = {};
|
|
22
|
+
__export(binex_exports, {
|
|
23
|
+
binexCrc16: () => binexCrc16,
|
|
24
|
+
binexCrc32: () => binexCrc32,
|
|
25
|
+
binexCsum8: () => binexCsum8,
|
|
26
|
+
binexRecords: () => binexRecords,
|
|
27
|
+
decodeBinexEph: () => decodeBinexEph,
|
|
28
|
+
getBnxi: () => getBnxi,
|
|
29
|
+
parseBinex: () => parseBinex
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(binex_exports);
|
|
32
|
+
|
|
33
|
+
// src/navbits/index.ts
|
|
34
|
+
var GPS_PI = 3.1415926535898;
|
|
35
|
+
var GPS_EPOCH_MS = Date.UTC(1980, 0, 6);
|
|
36
|
+
var SEC_PER_WEEK = 7 * 86400;
|
|
37
|
+
function getBitU(buff, pos, len) {
|
|
38
|
+
let bits = 0;
|
|
39
|
+
for (let i = pos; i < pos + len; i++) {
|
|
40
|
+
bits = bits * 2 + (buff[i >> 3] >> 7 - (i & 7) & 1);
|
|
41
|
+
}
|
|
42
|
+
return bits;
|
|
43
|
+
}
|
|
44
|
+
function getBitS(buff, pos, len) {
|
|
45
|
+
const bits = getBitU(buff, pos, len);
|
|
46
|
+
if (len <= 0 || bits < 2 ** (len - 1)) return bits;
|
|
47
|
+
return bits - 2 ** len;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/binex/frame.ts
|
|
51
|
+
var CRC16_TABLE = (() => {
|
|
52
|
+
const t = new Uint16Array(256);
|
|
53
|
+
for (let n = 0; n < 256; n++) {
|
|
54
|
+
let c = n << 8;
|
|
55
|
+
for (let k = 0; k < 8; k++)
|
|
56
|
+
c = c & 32768 ? (c << 1 ^ 4129) & 65535 : c << 1 & 65535;
|
|
57
|
+
t[n] = c;
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
})();
|
|
61
|
+
function binexCrc16(data, start, end) {
|
|
62
|
+
let crc = 0;
|
|
63
|
+
for (let i = start; i < end; i++)
|
|
64
|
+
crc = (crc << 8 ^ CRC16_TABLE[(crc >> 8 ^ data[i]) & 255]) & 65535;
|
|
65
|
+
return crc;
|
|
66
|
+
}
|
|
67
|
+
var CRC32_TABLE = (() => {
|
|
68
|
+
const t = new Uint32Array(256);
|
|
69
|
+
for (let n = 0; n < 256; n++) {
|
|
70
|
+
let c = n << 24;
|
|
71
|
+
for (let k = 0; k < 8; k++)
|
|
72
|
+
c = c & 2147483648 ? c << 1 ^ 79764919 : c << 1;
|
|
73
|
+
t[n] = c >>> 0;
|
|
74
|
+
}
|
|
75
|
+
return t;
|
|
76
|
+
})();
|
|
77
|
+
function binexCrc32(data, start, end) {
|
|
78
|
+
let crc = 0;
|
|
79
|
+
for (let i = start; i < end; i++)
|
|
80
|
+
crc = (crc << 8 ^ CRC32_TABLE[(crc >>> 24 ^ data[i]) & 255]) >>> 0;
|
|
81
|
+
return crc >>> 0;
|
|
82
|
+
}
|
|
83
|
+
function binexCsum8(data, start, end) {
|
|
84
|
+
let cs = 0;
|
|
85
|
+
for (let i = start; i < end; i++) cs ^= data[i];
|
|
86
|
+
return cs & 255;
|
|
87
|
+
}
|
|
88
|
+
function getBnxi(data, pos) {
|
|
89
|
+
let value = 0;
|
|
90
|
+
for (let i = 0; i < 3; i++) {
|
|
91
|
+
const b = data[pos + i] ?? 0;
|
|
92
|
+
value = value * 128 + (b & 127);
|
|
93
|
+
if (!(b & 128)) return { value, size: i + 1 };
|
|
94
|
+
}
|
|
95
|
+
value = value * 256 + (data[pos + 3] ?? 0);
|
|
96
|
+
return { value, size: 4 };
|
|
97
|
+
}
|
|
98
|
+
var SYNC = /* @__PURE__ */ new Map([
|
|
99
|
+
[226, { littleEndian: false, enhanced: false }],
|
|
100
|
+
[194, { littleEndian: true, enhanced: false }],
|
|
101
|
+
[232, { littleEndian: false, enhanced: true }],
|
|
102
|
+
[200, { littleEndian: true, enhanced: true }]
|
|
103
|
+
]);
|
|
104
|
+
function csumWidth(covered, enhanced) {
|
|
105
|
+
if (enhanced) {
|
|
106
|
+
if (covered < 128) return 2;
|
|
107
|
+
if (covered < 1048576) return 4;
|
|
108
|
+
return 16;
|
|
109
|
+
}
|
|
110
|
+
if (covered < 128) return 1;
|
|
111
|
+
if (covered < 4096) return 2;
|
|
112
|
+
if (covered < 1048576) return 4;
|
|
113
|
+
return 16;
|
|
114
|
+
}
|
|
115
|
+
function checksumOk(data, view, covStart, covEnd, width) {
|
|
116
|
+
switch (width) {
|
|
117
|
+
case 1:
|
|
118
|
+
return binexCsum8(data, covStart, covEnd) === (data[covEnd] ?? -1);
|
|
119
|
+
case 2:
|
|
120
|
+
return binexCrc16(data, covStart, covEnd) === view.getUint16(covEnd);
|
|
121
|
+
case 4:
|
|
122
|
+
return binexCrc32(data, covStart, covEnd) === view.getUint32(covEnd);
|
|
123
|
+
default:
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function* binexRecords(data, view, stats) {
|
|
128
|
+
let i = 0;
|
|
129
|
+
while (i + 2 <= data.length) {
|
|
130
|
+
const sync = SYNC.get(data[i]);
|
|
131
|
+
if (!sync) {
|
|
132
|
+
i++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const id = data[i + 1];
|
|
136
|
+
const { value: len, size: lenH } = getBnxi(data, i + 2);
|
|
137
|
+
const body = i + 2 + lenH;
|
|
138
|
+
const covStart = i + 1;
|
|
139
|
+
const covEnd = body + len;
|
|
140
|
+
const covered = covEnd - covStart;
|
|
141
|
+
const width = csumWidth(covered, sync.enhanced);
|
|
142
|
+
if (width === 16 || covEnd + width > data.length) {
|
|
143
|
+
i++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (!checksumOk(data, view, covStart, covEnd, width)) {
|
|
147
|
+
stats.badCrc++;
|
|
148
|
+
i++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
yield { id, start: i, body, len, ...sync };
|
|
152
|
+
i = covEnd + width;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/binex/nav.ts
|
|
157
|
+
var GPS_EPOCH_MS2 = Date.UTC(1980, 0, 6);
|
|
158
|
+
var GLO_DAY0_MS = Date.UTC(1980, 0, 1);
|
|
159
|
+
var BDT_EPOCH_MS = Date.UTC(2006, 0, 1);
|
|
160
|
+
var SEC_PER_WEEK2 = 7 * 86400;
|
|
161
|
+
var MS_PER_WEEK = SEC_PER_WEEK2 * 1e3;
|
|
162
|
+
var SC2RAD = GPS_PI;
|
|
163
|
+
var gpsMs = (week, sec) => GPS_EPOCH_MS2 + week * MS_PER_WEEK + sec * 1e3;
|
|
164
|
+
var sowOf = (dateMs) => (dateMs / 1e3 % SEC_PER_WEEK2 + SEC_PER_WEEK2) % SEC_PER_WEEK2;
|
|
165
|
+
var two = (n) => String(n).padStart(2, "0");
|
|
166
|
+
var Reader = class {
|
|
167
|
+
constructor(view, start, le) {
|
|
168
|
+
this.view = view;
|
|
169
|
+
this.le = le;
|
|
170
|
+
this.p = start;
|
|
171
|
+
}
|
|
172
|
+
p;
|
|
173
|
+
u1() {
|
|
174
|
+
return this.view.getUint8(this.p++);
|
|
175
|
+
}
|
|
176
|
+
i1() {
|
|
177
|
+
return this.view.getInt8(this.p++);
|
|
178
|
+
}
|
|
179
|
+
u2() {
|
|
180
|
+
const v = this.view.getUint16(this.p, this.le);
|
|
181
|
+
this.p += 2;
|
|
182
|
+
return v;
|
|
183
|
+
}
|
|
184
|
+
i4() {
|
|
185
|
+
const v = this.view.getInt32(this.p, this.le);
|
|
186
|
+
this.p += 4;
|
|
187
|
+
return v;
|
|
188
|
+
}
|
|
189
|
+
u4() {
|
|
190
|
+
const v = this.view.getUint32(this.p, this.le);
|
|
191
|
+
this.p += 4;
|
|
192
|
+
return v;
|
|
193
|
+
}
|
|
194
|
+
r4() {
|
|
195
|
+
const v = this.view.getFloat32(this.p, this.le);
|
|
196
|
+
this.p += 4;
|
|
197
|
+
return v;
|
|
198
|
+
}
|
|
199
|
+
r8() {
|
|
200
|
+
const v = this.view.getFloat64(this.p, this.le);
|
|
201
|
+
this.p += 8;
|
|
202
|
+
return v;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
function readKeplerCore(r) {
|
|
206
|
+
const deltaN = r.r4() * SC2RAD;
|
|
207
|
+
const m0 = r.r8();
|
|
208
|
+
const e = r.r8();
|
|
209
|
+
const sqrtA = r.r8();
|
|
210
|
+
const cic = r.r4();
|
|
211
|
+
const crc = r.r4();
|
|
212
|
+
const cis = r.r4();
|
|
213
|
+
const crs = r.r4();
|
|
214
|
+
const cuc = r.r4();
|
|
215
|
+
const cus = r.r4();
|
|
216
|
+
const omega0 = r.r8();
|
|
217
|
+
const omega = r.r8();
|
|
218
|
+
const i0 = r.r8();
|
|
219
|
+
const omegaDot = r.r4() * SC2RAD;
|
|
220
|
+
const idot = r.r4() * SC2RAD;
|
|
221
|
+
return {
|
|
222
|
+
deltaN,
|
|
223
|
+
m0,
|
|
224
|
+
e,
|
|
225
|
+
sqrtA,
|
|
226
|
+
cic,
|
|
227
|
+
crc,
|
|
228
|
+
cis,
|
|
229
|
+
crs,
|
|
230
|
+
cuc,
|
|
231
|
+
cus,
|
|
232
|
+
omega0,
|
|
233
|
+
omega,
|
|
234
|
+
i0,
|
|
235
|
+
omegaDot,
|
|
236
|
+
idot
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function decodeGpsQzss(view, p, le, sys) {
|
|
240
|
+
const r = new Reader(view, p, le);
|
|
241
|
+
const prnRaw = r.u1() + (sys === "G" ? 1 : 0);
|
|
242
|
+
const prn = sys === "G" ? prnRaw : prnRaw - 192;
|
|
243
|
+
if (sys === "G" && (prn < 1 || prn > 32)) return null;
|
|
244
|
+
if (sys === "J" && (prn < 1 || prn > 10)) return null;
|
|
245
|
+
const week = r.u2();
|
|
246
|
+
r.i4();
|
|
247
|
+
const toes = r.i4();
|
|
248
|
+
const tgd = r.r4();
|
|
249
|
+
r.i4();
|
|
250
|
+
const af2 = r.r4();
|
|
251
|
+
const af1 = r.r4();
|
|
252
|
+
const af0 = r.r4();
|
|
253
|
+
const iode = r.i4();
|
|
254
|
+
const core = readKeplerCore(r);
|
|
255
|
+
r.r4();
|
|
256
|
+
const svHealth = r.u2();
|
|
257
|
+
const tocDate = new Date(gpsMs(week, toes));
|
|
258
|
+
return {
|
|
259
|
+
system: sys,
|
|
260
|
+
prn: `${sys}${two(prn)}`,
|
|
261
|
+
toc: sowOf(tocDate.getTime()),
|
|
262
|
+
tocDate,
|
|
263
|
+
af0,
|
|
264
|
+
af1,
|
|
265
|
+
af2,
|
|
266
|
+
iode,
|
|
267
|
+
...core,
|
|
268
|
+
toe: toes,
|
|
269
|
+
week,
|
|
270
|
+
svHealth,
|
|
271
|
+
tgd
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function decodeGalileo(view, p, le) {
|
|
275
|
+
const r = new Reader(view, p, le);
|
|
276
|
+
const prn = r.u1() + 1;
|
|
277
|
+
if (prn < 1 || prn > 36) return null;
|
|
278
|
+
const week = r.u2();
|
|
279
|
+
r.i4();
|
|
280
|
+
const toes = r.i4();
|
|
281
|
+
const tgd = r.r4();
|
|
282
|
+
r.r4();
|
|
283
|
+
const iode = r.i4();
|
|
284
|
+
const af2 = r.r4();
|
|
285
|
+
const af1 = r.r4();
|
|
286
|
+
const af0 = r.r4();
|
|
287
|
+
const core = readKeplerCore(r);
|
|
288
|
+
r.r4();
|
|
289
|
+
const svHealth = r.u2();
|
|
290
|
+
const tocDate = new Date(gpsMs(week, toes));
|
|
291
|
+
return {
|
|
292
|
+
system: "E",
|
|
293
|
+
prn: `E${two(prn)}`,
|
|
294
|
+
toc: sowOf(tocDate.getTime()),
|
|
295
|
+
tocDate,
|
|
296
|
+
af0,
|
|
297
|
+
af1,
|
|
298
|
+
af2,
|
|
299
|
+
iode,
|
|
300
|
+
...core,
|
|
301
|
+
toe: toes,
|
|
302
|
+
week,
|
|
303
|
+
svHealth,
|
|
304
|
+
tgd
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function bdsTgd(tgd) {
|
|
308
|
+
tgd &= 1023;
|
|
309
|
+
return tgd & 512 ? -1e-10 * (~tgd & 511) : 1e-10 * (tgd & 511);
|
|
310
|
+
}
|
|
311
|
+
function decodeBeidou(view, p, le) {
|
|
312
|
+
const r = new Reader(view, p, le);
|
|
313
|
+
const prn = r.u1();
|
|
314
|
+
if (prn < 1 || prn > 63) return null;
|
|
315
|
+
const week = r.u2();
|
|
316
|
+
r.i4();
|
|
317
|
+
r.i4();
|
|
318
|
+
const toes = r.i4();
|
|
319
|
+
const af2 = r.r4();
|
|
320
|
+
const af1 = r.r4();
|
|
321
|
+
const af0 = r.r4();
|
|
322
|
+
const core = readKeplerCore(r);
|
|
323
|
+
const flag1 = r.u2();
|
|
324
|
+
const flag2 = r.u4();
|
|
325
|
+
const iode = flag1 >> 6 & 31;
|
|
326
|
+
const svHealth = flag1 & 1;
|
|
327
|
+
const tgd = bdsTgd(flag2 >> 4);
|
|
328
|
+
const tocDate = new Date(BDT_EPOCH_MS + week * MS_PER_WEEK + toes * 1e3);
|
|
329
|
+
return {
|
|
330
|
+
system: "C",
|
|
331
|
+
prn: `C${two(prn)}`,
|
|
332
|
+
toc: sowOf(tocDate.getTime()),
|
|
333
|
+
tocDate,
|
|
334
|
+
af0,
|
|
335
|
+
af1,
|
|
336
|
+
af2,
|
|
337
|
+
iode,
|
|
338
|
+
...core,
|
|
339
|
+
toe: toes,
|
|
340
|
+
week,
|
|
341
|
+
// RINEX BDS week field is the BDT week
|
|
342
|
+
svHealth,
|
|
343
|
+
tgd
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function decodeGlonass(view, p, le) {
|
|
347
|
+
const r = new Reader(view, p, le);
|
|
348
|
+
const slot = r.u1() + 1;
|
|
349
|
+
if (slot < 1 || slot > 27) return null;
|
|
350
|
+
const day = r.u2();
|
|
351
|
+
const tod = r.u4();
|
|
352
|
+
const tauN = r.r8();
|
|
353
|
+
const gammaN = r.r8();
|
|
354
|
+
const tof = r.u4();
|
|
355
|
+
const x = r.r8();
|
|
356
|
+
const xDot = r.r8();
|
|
357
|
+
const xAcc = r.r8();
|
|
358
|
+
const y = r.r8();
|
|
359
|
+
const yDot = r.r8();
|
|
360
|
+
const yAcc = r.r8();
|
|
361
|
+
const z = r.r8();
|
|
362
|
+
const zDot = r.r8();
|
|
363
|
+
const zAcc = r.r8();
|
|
364
|
+
const health = r.u1() & 1;
|
|
365
|
+
const freqNum = r.i1();
|
|
366
|
+
const tocDate = new Date(
|
|
367
|
+
GLO_DAY0_MS + (day - 1) * 864e5 + (tod - 10800) * 1e3
|
|
368
|
+
);
|
|
369
|
+
return {
|
|
370
|
+
system: "R",
|
|
371
|
+
prn: `R${two(slot)}`,
|
|
372
|
+
tocDate,
|
|
373
|
+
tauN,
|
|
374
|
+
gammaN,
|
|
375
|
+
messageFrameTime: tof,
|
|
376
|
+
x,
|
|
377
|
+
y,
|
|
378
|
+
z,
|
|
379
|
+
xDot,
|
|
380
|
+
yDot,
|
|
381
|
+
zDot,
|
|
382
|
+
xAcc,
|
|
383
|
+
yAcc,
|
|
384
|
+
zAcc,
|
|
385
|
+
health,
|
|
386
|
+
freqNum
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function decodeSbas(view, p, le) {
|
|
390
|
+
const r = new Reader(view, p, le);
|
|
391
|
+
const prn = r.u1();
|
|
392
|
+
const week = r.u2();
|
|
393
|
+
const tow = r.u4();
|
|
394
|
+
const af0 = r.r8();
|
|
395
|
+
const af1 = r.r4();
|
|
396
|
+
const toe = r.u4();
|
|
397
|
+
const x = r.r8();
|
|
398
|
+
const xDot = r.r8();
|
|
399
|
+
const xAcc = r.r8();
|
|
400
|
+
const y = r.r8();
|
|
401
|
+
const yDot = r.r8();
|
|
402
|
+
const yAcc = r.r8();
|
|
403
|
+
const z = r.r8();
|
|
404
|
+
const zDot = r.r8();
|
|
405
|
+
const zAcc = r.r8();
|
|
406
|
+
const health = r.u1();
|
|
407
|
+
if (prn < 120 || prn > 158) return null;
|
|
408
|
+
return {
|
|
409
|
+
system: "S",
|
|
410
|
+
prn: `S${two(prn - 100)}`,
|
|
411
|
+
tocDate: new Date(gpsMs(week, toe)),
|
|
412
|
+
tauN: af0,
|
|
413
|
+
gammaN: af1,
|
|
414
|
+
messageFrameTime: tow,
|
|
415
|
+
x,
|
|
416
|
+
y,
|
|
417
|
+
z,
|
|
418
|
+
xDot,
|
|
419
|
+
yDot,
|
|
420
|
+
zDot,
|
|
421
|
+
xAcc,
|
|
422
|
+
yAcc,
|
|
423
|
+
zAcc,
|
|
424
|
+
health,
|
|
425
|
+
freqNum: 0
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function decodeBinexEph(view, body, len, le) {
|
|
429
|
+
const sub = view.getUint8(body);
|
|
430
|
+
const p = body + 1;
|
|
431
|
+
const n = len - 1;
|
|
432
|
+
switch (sub) {
|
|
433
|
+
case 1:
|
|
434
|
+
return n >= 127 ? decodeGpsQzss(view, p, le, "G") : null;
|
|
435
|
+
case 2:
|
|
436
|
+
return n >= 119 ? decodeGlonass(view, p, le) : null;
|
|
437
|
+
case 3:
|
|
438
|
+
return n >= 98 ? decodeSbas(view, p, le) : null;
|
|
439
|
+
case 4:
|
|
440
|
+
return n >= 127 ? decodeGalileo(view, p, le) : null;
|
|
441
|
+
case 5:
|
|
442
|
+
return n >= 117 ? decodeBeidou(view, p, le) : null;
|
|
443
|
+
case 6:
|
|
444
|
+
return n >= 127 ? decodeGpsQzss(view, p, le, "J") : null;
|
|
445
|
+
default:
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/binex/index.ts
|
|
451
|
+
var GPS_EPOCH_MS3 = Date.UTC(1980, 0, 6);
|
|
452
|
+
var CLIGHT = 299792458;
|
|
453
|
+
var OBS_CODES = {
|
|
454
|
+
0: [
|
|
455
|
+
"1C",
|
|
456
|
+
"1C",
|
|
457
|
+
"1P",
|
|
458
|
+
"1W",
|
|
459
|
+
"1Y",
|
|
460
|
+
"1M",
|
|
461
|
+
"1X",
|
|
462
|
+
"1N",
|
|
463
|
+
"",
|
|
464
|
+
"",
|
|
465
|
+
"2W",
|
|
466
|
+
"2C",
|
|
467
|
+
"2D",
|
|
468
|
+
"2S",
|
|
469
|
+
"2L",
|
|
470
|
+
"2X",
|
|
471
|
+
"2P",
|
|
472
|
+
"2W",
|
|
473
|
+
"2Y",
|
|
474
|
+
"2M",
|
|
475
|
+
"2N",
|
|
476
|
+
"",
|
|
477
|
+
"",
|
|
478
|
+
"5X",
|
|
479
|
+
"5I",
|
|
480
|
+
"5Q",
|
|
481
|
+
"5X"
|
|
482
|
+
],
|
|
483
|
+
// GPS
|
|
484
|
+
1: [
|
|
485
|
+
"1C",
|
|
486
|
+
"1C",
|
|
487
|
+
"1P",
|
|
488
|
+
"",
|
|
489
|
+
"",
|
|
490
|
+
"",
|
|
491
|
+
"",
|
|
492
|
+
"",
|
|
493
|
+
"",
|
|
494
|
+
"",
|
|
495
|
+
"2C",
|
|
496
|
+
"2C",
|
|
497
|
+
"2P",
|
|
498
|
+
"3X",
|
|
499
|
+
"3I",
|
|
500
|
+
"3Q",
|
|
501
|
+
"3X"
|
|
502
|
+
],
|
|
503
|
+
// GLONASS
|
|
504
|
+
3: [
|
|
505
|
+
"1C",
|
|
506
|
+
"1A",
|
|
507
|
+
"1B",
|
|
508
|
+
"1C",
|
|
509
|
+
"1X",
|
|
510
|
+
"1Z",
|
|
511
|
+
"5X",
|
|
512
|
+
"5I",
|
|
513
|
+
"5Q",
|
|
514
|
+
"5X",
|
|
515
|
+
"7X",
|
|
516
|
+
"7I",
|
|
517
|
+
"7Q",
|
|
518
|
+
"7X",
|
|
519
|
+
"8X",
|
|
520
|
+
"8I",
|
|
521
|
+
"8Q",
|
|
522
|
+
"8X",
|
|
523
|
+
"6X",
|
|
524
|
+
"6A",
|
|
525
|
+
"6B",
|
|
526
|
+
"6C",
|
|
527
|
+
"6X",
|
|
528
|
+
"6Z"
|
|
529
|
+
],
|
|
530
|
+
// Galileo
|
|
531
|
+
2: ["1C", "1C", "", "", "", "", "5X", "5I", "5Q", "5X"],
|
|
532
|
+
// SBAS
|
|
533
|
+
4: [
|
|
534
|
+
"2X",
|
|
535
|
+
"2I",
|
|
536
|
+
"2Q",
|
|
537
|
+
"2X",
|
|
538
|
+
"7X",
|
|
539
|
+
"7I",
|
|
540
|
+
"7Q",
|
|
541
|
+
"7X",
|
|
542
|
+
"6X",
|
|
543
|
+
"6I",
|
|
544
|
+
"6Q",
|
|
545
|
+
"6X",
|
|
546
|
+
"1X",
|
|
547
|
+
"1S",
|
|
548
|
+
"1L",
|
|
549
|
+
"1X"
|
|
550
|
+
],
|
|
551
|
+
// BeiDou
|
|
552
|
+
5: [
|
|
553
|
+
"1C",
|
|
554
|
+
"1C",
|
|
555
|
+
"1S",
|
|
556
|
+
"1L",
|
|
557
|
+
"1X",
|
|
558
|
+
"",
|
|
559
|
+
"",
|
|
560
|
+
"2X",
|
|
561
|
+
"2S",
|
|
562
|
+
"2L",
|
|
563
|
+
"2X",
|
|
564
|
+
"",
|
|
565
|
+
"",
|
|
566
|
+
"5X",
|
|
567
|
+
"5I",
|
|
568
|
+
"5Q",
|
|
569
|
+
"5X",
|
|
570
|
+
"",
|
|
571
|
+
"",
|
|
572
|
+
"6X",
|
|
573
|
+
"6S",
|
|
574
|
+
"6L",
|
|
575
|
+
"6X",
|
|
576
|
+
"",
|
|
577
|
+
"",
|
|
578
|
+
"",
|
|
579
|
+
"",
|
|
580
|
+
"",
|
|
581
|
+
"",
|
|
582
|
+
"",
|
|
583
|
+
"1Z"
|
|
584
|
+
]
|
|
585
|
+
// QZSS
|
|
586
|
+
};
|
|
587
|
+
var two2 = (n) => String(n).padStart(2, "0");
|
|
588
|
+
function obsPrn(sys, prn) {
|
|
589
|
+
switch (sys) {
|
|
590
|
+
case 0:
|
|
591
|
+
return prn >= 1 && prn <= 32 ? `G${two2(prn)}` : null;
|
|
592
|
+
case 1:
|
|
593
|
+
return prn >= 1 && prn <= 27 ? `R${two2(prn)}` : null;
|
|
594
|
+
case 2:
|
|
595
|
+
return prn >= 120 && prn <= 158 ? `S${two2(prn - 100)}` : null;
|
|
596
|
+
case 3:
|
|
597
|
+
return prn >= 1 && prn <= 36 ? `E${two2(prn)}` : null;
|
|
598
|
+
case 4:
|
|
599
|
+
return prn >= 1 && prn <= 63 ? `C${two2(prn)}` : null;
|
|
600
|
+
case 5:
|
|
601
|
+
if (prn >= 193 && prn <= 202) return `J${two2(prn - 192)}`;
|
|
602
|
+
return prn >= 1 && prn <= 10 ? `J${two2(prn)}` : null;
|
|
603
|
+
default:
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function carrierFreq(sys, code, fcn) {
|
|
608
|
+
const band = code.charCodeAt(0) - 48;
|
|
609
|
+
switch (sys) {
|
|
610
|
+
case "G":
|
|
611
|
+
case "J":
|
|
612
|
+
if (band === 1) return 157542e4;
|
|
613
|
+
if (band === 2) return 12276e5;
|
|
614
|
+
if (band === 5) return 117645e4;
|
|
615
|
+
if (band === 6) return 127875e4;
|
|
616
|
+
return 0;
|
|
617
|
+
case "R":
|
|
618
|
+
if (band === 1) return fcn >= -7 ? 1602e6 + fcn * 562500 : 0;
|
|
619
|
+
if (band === 2) return fcn >= -7 ? 1246e6 + fcn * 437500 : 0;
|
|
620
|
+
if (band === 3) return 1202025e3;
|
|
621
|
+
return 0;
|
|
622
|
+
case "E":
|
|
623
|
+
if (band === 1) return 157542e4;
|
|
624
|
+
if (band === 5) return 117645e4;
|
|
625
|
+
if (band === 6) return 127875e4;
|
|
626
|
+
if (band === 7) return 120714e4;
|
|
627
|
+
if (band === 8) return 1191795e3;
|
|
628
|
+
return 0;
|
|
629
|
+
case "C":
|
|
630
|
+
if (band === 1) return 157542e4;
|
|
631
|
+
if (band === 2) return 1561098e3;
|
|
632
|
+
if (band === 5) return 117645e4;
|
|
633
|
+
if (band === 6) return 126852e4;
|
|
634
|
+
if (band === 7) return 120714e4;
|
|
635
|
+
if (band === 8) return 1191795e3;
|
|
636
|
+
return 0;
|
|
637
|
+
case "S":
|
|
638
|
+
if (band === 1) return 157542e4;
|
|
639
|
+
if (band === 5) return 117645e4;
|
|
640
|
+
return 0;
|
|
641
|
+
default:
|
|
642
|
+
return 0;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
var FCN_UNKNOWN = -100;
|
|
646
|
+
function decodeObsSat(data, start, nobs, sys) {
|
|
647
|
+
let p = start;
|
|
648
|
+
let fcn = FCN_UNKNOWN;
|
|
649
|
+
const obs = [];
|
|
650
|
+
const block0Flags = [0, 0, 0, 0];
|
|
651
|
+
let refRange = 0;
|
|
652
|
+
for (let b = 0; b < nobs; b++) {
|
|
653
|
+
const flags = b === 0 ? block0Flags : block0Flags.slice();
|
|
654
|
+
const b0 = data[p++];
|
|
655
|
+
const code = b0 & 31;
|
|
656
|
+
const slip = (b0 >> 5 & 1) === 1;
|
|
657
|
+
let more = b0 >> 7 & 1;
|
|
658
|
+
while (more) {
|
|
659
|
+
const fb = data[p++];
|
|
660
|
+
flags[fb & 3] = fb & 127;
|
|
661
|
+
more = fb & 128;
|
|
662
|
+
}
|
|
663
|
+
if (sys === 1 && flags[2] > 0 && (code === 1 || code === 2 || code === 11 || code === 12)) {
|
|
664
|
+
fcn = getBitS(Uint8Array.of(flags[2]), 2, 4);
|
|
665
|
+
}
|
|
666
|
+
const acc = flags[0] & 32 ? 1e-4 : 2e-5;
|
|
667
|
+
let cn0 = data[p++] * 0.4;
|
|
668
|
+
let range;
|
|
669
|
+
if (b === 0) {
|
|
670
|
+
cn0 += getBitS(data, p * 8, 2) * 0.1;
|
|
671
|
+
range = getBitU(data, p * 8 + 2, 38) * 1e-3;
|
|
672
|
+
p += 5;
|
|
673
|
+
refRange = range;
|
|
674
|
+
} else if (flags[0] & 64) {
|
|
675
|
+
cn0 += getBitS(data, p * 8, 2) * 0.1;
|
|
676
|
+
range = refRange + getBitS(data, p * 8 + 4, 20) * 1e-3;
|
|
677
|
+
p += 3;
|
|
678
|
+
} else {
|
|
679
|
+
range = refRange + getBitS(data, p * 8, 16) * 1e-3;
|
|
680
|
+
p += 2;
|
|
681
|
+
}
|
|
682
|
+
let phase;
|
|
683
|
+
if (flags[0] & 64) {
|
|
684
|
+
phase = range + getBitS(data, p * 8, 24) * acc;
|
|
685
|
+
p += 3;
|
|
686
|
+
} else {
|
|
687
|
+
cn0 += getBitS(data, p * 8, 2) * 0.1;
|
|
688
|
+
phase = range + getBitS(data, p * 8 + 2, 22) * acc;
|
|
689
|
+
p += 3;
|
|
690
|
+
}
|
|
691
|
+
let doppler = null;
|
|
692
|
+
if (flags[0] & 4) {
|
|
693
|
+
doppler = getBitS(data, p * 8, 24) / 256;
|
|
694
|
+
p += 3;
|
|
695
|
+
}
|
|
696
|
+
if (flags[0] & 8) {
|
|
697
|
+
p += flags[0] & 16 ? 2 : 1;
|
|
698
|
+
}
|
|
699
|
+
obs.push({ code, slip, pr: range, phase, cn0, doppler });
|
|
700
|
+
}
|
|
701
|
+
return { obs, fcn, next: p };
|
|
702
|
+
}
|
|
703
|
+
function decodeObsRecord(data, view, body, len, obsCodes) {
|
|
704
|
+
let p = body + 1;
|
|
705
|
+
const min = view.getUint32(p);
|
|
706
|
+
p += 4;
|
|
707
|
+
const msec = view.getUint16(p);
|
|
708
|
+
p += 2;
|
|
709
|
+
const timeMs = GPS_EPOCH_MS3 + min * 6e4 + msec;
|
|
710
|
+
const flag = data[p++];
|
|
711
|
+
const nsat = (flag & 63) + 1;
|
|
712
|
+
if (flag & 128) p += 3;
|
|
713
|
+
if (flag & 64) {
|
|
714
|
+
const nsys = getBitU(data, p * 8, 4);
|
|
715
|
+
p += 1;
|
|
716
|
+
p += nsys * 4;
|
|
717
|
+
}
|
|
718
|
+
const end = body + len;
|
|
719
|
+
const meas = [];
|
|
720
|
+
for (let i = 0; i < nsat && p < end; i++) {
|
|
721
|
+
const prn = data[p++];
|
|
722
|
+
const b = data[p++];
|
|
723
|
+
const nobs = b >> 4 & 7;
|
|
724
|
+
const sys = b & 15;
|
|
725
|
+
const sat = obsPrn(sys, prn);
|
|
726
|
+
const { obs, fcn, next } = decodeObsSat(data, p, nobs, sys);
|
|
727
|
+
p = next;
|
|
728
|
+
if (p > end) return null;
|
|
729
|
+
if (!sat) continue;
|
|
730
|
+
const table = OBS_CODES[sys];
|
|
731
|
+
const sysL = sat[0];
|
|
732
|
+
for (const o of obs) {
|
|
733
|
+
const code = table?.[o.code & 63] ?? "";
|
|
734
|
+
if (!code) continue;
|
|
735
|
+
const freq = carrierFreq(sysL, code, fcn);
|
|
736
|
+
meas.push({
|
|
737
|
+
prn: sat,
|
|
738
|
+
code,
|
|
739
|
+
pr: o.pr,
|
|
740
|
+
cp: freq > 0 ? o.phase * freq / CLIGHT : null,
|
|
741
|
+
doppler: o.doppler,
|
|
742
|
+
cn0: o.cn0,
|
|
743
|
+
slip: o.slip
|
|
744
|
+
});
|
|
745
|
+
const codes = obsCodes[sysL] ??= [];
|
|
746
|
+
if (!codes.includes(code)) codes.push(code);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return { timeMs, meas };
|
|
750
|
+
}
|
|
751
|
+
function parseBinex(data) {
|
|
752
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
753
|
+
const epochs = [];
|
|
754
|
+
const ephemerides = [];
|
|
755
|
+
const messageCounts = {};
|
|
756
|
+
const obsCodes = {};
|
|
757
|
+
const stats = { badCrc: 0 };
|
|
758
|
+
const lastKep = /* @__PURE__ */ new Map();
|
|
759
|
+
const lastState = /* @__PURE__ */ new Map();
|
|
760
|
+
const hex = (n) => `0x${n.toString(16).padStart(2, "0")}`;
|
|
761
|
+
for (const rec of binexRecords(data, view, stats)) {
|
|
762
|
+
const sub = rec.len > 0 ? data[rec.body] : 0;
|
|
763
|
+
const key = rec.id === 1 || rec.id === 127 ? `${hex(rec.id)}-${sub.toString(16).padStart(2, "0")}` : hex(rec.id);
|
|
764
|
+
messageCounts[key] = (messageCounts[key] ?? 0) + 1;
|
|
765
|
+
if (rec.id === 127 && sub === 5 && rec.len >= 8 && !rec.littleEndian) {
|
|
766
|
+
const epoch = decodeObsRecord(data, view, rec.body, rec.len, obsCodes);
|
|
767
|
+
if (epoch) epochs.push(epoch);
|
|
768
|
+
} else if (rec.id === 1 && rec.len >= 2) {
|
|
769
|
+
const eph = decodeBinexEph(view, rec.body, rec.len, rec.littleEndian);
|
|
770
|
+
if (!eph) continue;
|
|
771
|
+
if ("iode" in eph) {
|
|
772
|
+
const prev = lastKep.get(eph.prn);
|
|
773
|
+
if (prev && prev.iode === eph.iode && prev.toe === eph.toe && prev.tocDate.getTime() === eph.tocDate.getTime()) {
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
lastKep.set(eph.prn, eph);
|
|
777
|
+
ephemerides.push(eph);
|
|
778
|
+
} else {
|
|
779
|
+
const prev = lastState.get(eph.prn);
|
|
780
|
+
if (prev && Math.abs(prev.tocDate.getTime() - eph.tocDate.getTime()) < 1e3 && prev.health === eph.health) {
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
lastState.set(eph.prn, eph);
|
|
784
|
+
ephemerides.push(eph);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return { epochs, ephemerides, messageCounts, obsCodes, badCrc: stats.badCrc };
|
|
789
|
+
}
|
|
790
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
791
|
+
0 && (module.exports = {
|
|
792
|
+
binexCrc16,
|
|
793
|
+
binexCrc32,
|
|
794
|
+
binexCsum8,
|
|
795
|
+
binexRecords,
|
|
796
|
+
decodeBinexEph,
|
|
797
|
+
getBnxi,
|
|
798
|
+
parseBinex
|
|
799
|
+
});
|