mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-17 13:23:43 +00:00
Compare commits
193 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b107d21373 | |||
| 4f222d107c | |||
| fce5019225 | |||
| 7e670872c1 | |||
| 6f66ce0ca9 | |||
| b5cb118c01 | |||
| 23e0553963 | |||
| 0382d7be8b | |||
| e0a9fb97fd | |||
| 2344389364 | |||
| dffee7781e | |||
| 1d5ea2f15c | |||
| 5e8b9fc305 | |||
| 54a8da8565 | |||
| 7a3c727b0f | |||
| b817a14320 | |||
| ee2a6086b9 | |||
| cd9032fb44 | |||
| cb61fe340e | |||
| cd125da49b | |||
| 9cfd033380 | |||
| 3403dee7d5 | |||
| 09c8f301c3 | |||
| 9880a6e27c | |||
| 4033ba6f83 | |||
| 469dd941d8 | |||
| acee908444 | |||
| c3a73e386e | |||
| 8d8073b267 | |||
| 92d5983e3f | |||
| 69875ded6c | |||
| 5f8db9d26e | |||
| 4f53374834 | |||
| 8bc5213b44 | |||
| 34de2a06db | |||
| cd24aa75fc | |||
| d5a7fac9b5 | |||
| 25f1330e3f | |||
| 2dacf7f5af | |||
| 2831ab55d0 | |||
| f03dcf4314 | |||
| a4a49a072c | |||
| 75b32055f3 | |||
| 4a96c64a8d | |||
| 96e1b69326 | |||
| 32a3bfb4e4 | |||
| 9c87505c53 | |||
| ec51f81597 | |||
| 0f1d42e557 | |||
| 6d7c62f8ee | |||
| 5634d5ed7d | |||
| c5d47e3e86 | |||
| fedd14840c | |||
| b946235af1 | |||
| 02ad9725d9 | |||
| 8bc7947754 | |||
| 668a0195c9 | |||
| 804ab32113 | |||
| 365701f0e9 | |||
| b673604842 | |||
| 55b57bed36 | |||
| b18b309ab9 | |||
| e778525cab | |||
| ddb46086a6 | |||
| e974f710fd | |||
| 736dc45e59 | |||
| cd4bf19297 | |||
| 7289336be9 | |||
| 298cf4c25d | |||
| 3f8c719e5e | |||
| 550e7444ed | |||
| 4b0641aaef | |||
| 447367e605 | |||
| 0be865b2e2 | |||
| 363cb52daf | |||
| b7826af09e | |||
| c9a485271f | |||
| f773ea1873 | |||
| 820b226e3a | |||
| 2ee8f5fc8b | |||
| 6a39d95746 | |||
| 36ffc5896f | |||
| d2deda6f07 | |||
| b4994f9542 | |||
| 57f7305f9d | |||
| 30295e7359 | |||
| 9fa5dd3787 | |||
| 6ac10ab576 | |||
| 46af9ea98e | |||
| 151c96c640 | |||
| 4cefd6401d | |||
| 5458ceaa6c | |||
| 784ae84161 | |||
| 9f3c447f4b | |||
| 79b9a051ba | |||
| fc2d7e23e4 | |||
| 7392b4cb65 | |||
| 7e2a1135c5 | |||
| ca6e7ee3e9 | |||
| de95036afa | |||
| dd58b99193 | |||
| 7c31d92ad1 | |||
| cfe8ab4aa0 | |||
| ef8483941a | |||
| 7e3a28ebc2 | |||
| f34cdd025b | |||
| 071af0bf4c | |||
| 6bd486392f | |||
| 8188d2db20 | |||
| c9182ec1b0 | |||
| eafff30244 | |||
| 2a7e0c6f02 | |||
| a0b62378f5 | |||
| d6e12c9b30 | |||
| 7aa348e7da | |||
| 1334149112 | |||
| a4964dd3df | |||
| 9b7efedd0c | |||
| 06fd468e76 | |||
| cd215dad3e | |||
| 2351d97426 | |||
| 12eadee805 | |||
| 95b798cfc8 | |||
| cdb76ec89d | |||
| b51e4c603f | |||
| 84cbc1d6d6 | |||
| d7d552efb1 | |||
| 89c9a7a579 | |||
| 6081cd3700 | |||
| 5d6868593a | |||
| 201a8fc73e | |||
| 13bdcdefc2 | |||
| 6902fad9e7 | |||
| 3710136a39 | |||
| 6c3a251c89 | |||
| 964ded00f6 | |||
| e21a629bf3 | |||
| bb1ba83ade | |||
| 573290525b | |||
| 928dd7a58c | |||
| a1e4bba9d9 | |||
| a76bfa2830 | |||
| 15a613adb5 | |||
| ed8d586d59 | |||
| 130c5f8b00 | |||
| fd27e5246b | |||
| ee10f43a15 | |||
| cb60d22549 | |||
| 7d7b92678b | |||
| c33a2dfd33 | |||
| e4ed695eb9 | |||
| 070e32bb74 | |||
| 40adeb920e | |||
| 9811ad1b7f | |||
| d03b61e193 | |||
| 58416cc543 | |||
| 4b117f1cd9 | |||
| cff97f0e74 | |||
| 3f77e88c62 | |||
| 128b0a8a11 | |||
| 9533ed8848 | |||
| fb130585cc | |||
| b179575311 | |||
| d4e4a2229b | |||
| 6580f66e91 | |||
| acac519e9a | |||
| 03e47a98a0 | |||
| f77e8815d1 | |||
| 86ea701a8e | |||
| c5ef7180c7 | |||
| 3a44b9d79e | |||
| e7a03383e6 | |||
| 7edba830a5 | |||
| 7749596859 | |||
| b2ca7467ce | |||
| 431e9de9a1 | |||
| 934f572f38 | |||
| f5c2de983f | |||
| e367f1def9 | |||
| 90f1deb43d | |||
| 23c4743ee8 | |||
| e132a22578 | |||
| 46368ad89b | |||
| 4f846ccbd6 | |||
| ca2848f92a | |||
| a3f89ec528 | |||
| 01236ca7d3 | |||
| db436f34ed | |||
| c05e2447b0 | |||
| 4abc3968c1 | |||
| 06a974e557 | |||
| 7a5b027c68 | |||
| afebfe75b1 |
@@ -4,3 +4,6 @@ updates:
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
ignore:
|
||||
- dependency-name: "@types*"
|
||||
update-types: ["version-update:semver-major", "version-update:semver-minor"]
|
||||
|
||||
@@ -4,7 +4,7 @@ on:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
build-webui:
|
||||
build-psn:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
|
||||
@@ -22,5 +22,3 @@ jobs:
|
||||
|
||||
- name: Publish to NPM
|
||||
run: npm publish --provenance --access=public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
name: Run @jwetzell/posistagenet tests
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'src/**'
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
|
||||
with:
|
||||
node-version-file: '.nvmrc'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: './package-lock.json'
|
||||
|
||||
- name: Install Node.js dependencies
|
||||
run: npm ci
|
||||
|
||||
- run: npm run test
|
||||
Vendored
+2
-2
@@ -2,7 +2,7 @@
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll": true,
|
||||
"source.organizeImports": true
|
||||
"source.fixAll": "explicit",
|
||||
"source.organizeImports": "explicit"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ decoder.decode(infoPacketBuffer)
|
||||
decoder.decode(dataPacketBuffer)
|
||||
|
||||
// the system_name from info packets if available
|
||||
console.log(decoder.system_name)
|
||||
console.log(decoder.systemName)
|
||||
|
||||
// map of trackers populated with any data that has been received
|
||||
// this merges both info and data packet properties into one
|
||||
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
const { Encoder, Decoder, Tracker } = require('./dist');
|
||||
const { Encoder, Decoder, Tracker } = require('./dist/cjs');
|
||||
|
||||
const testSizes = [1, 10, 100, 1000];
|
||||
|
||||
@@ -40,7 +40,7 @@ function benchmark(trackerCount, iterations) {
|
||||
for (let index = 0; index < iterations; index += 1) {
|
||||
latestEncodedPackets = encoder.getDataPackets(Date.now(), trackers);
|
||||
}
|
||||
benchmarkResults.data.encode = `${(performance.now() - dataEncoderStart).toFixed(2)}ms`;
|
||||
benchmarkResults.data.encode = performance.now() - dataEncoderStart;
|
||||
|
||||
const dataDecodedStart = performance.now();
|
||||
for (let index = 0; index < iterations; index += 1) {
|
||||
@@ -48,14 +48,14 @@ function benchmark(trackerCount, iterations) {
|
||||
decoder.decode(packet);
|
||||
});
|
||||
}
|
||||
benchmarkResults.data.decode = `${(performance.now() - dataDecodedStart).toFixed(2)}ms`;
|
||||
benchmarkResults.data.decode = performance.now() - dataDecodedStart;
|
||||
|
||||
// INFO
|
||||
const infoEncoderStart = performance.now();
|
||||
for (let index = 0; index < iterations; index += 1) {
|
||||
latestEncodedPackets = encoder.getInfoPackets(Date.now(), trackers);
|
||||
}
|
||||
benchmarkResults.info.encode = `${(performance.now() - infoEncoderStart).toFixed(2)}ms`;
|
||||
benchmarkResults.info.encode = performance.now() - infoEncoderStart;
|
||||
|
||||
const infoDecodeStart = performance.now();
|
||||
for (let index = 0; index < iterations; index += 1) {
|
||||
@@ -63,9 +63,9 @@ function benchmark(trackerCount, iterations) {
|
||||
decoder.decode(packet);
|
||||
});
|
||||
}
|
||||
benchmarkResults.info.decode = `${(performance.now() - infoDecodeStart).toFixed(2)}ms`;
|
||||
benchmarkResults.info.decode = performance.now() - infoDecodeStart;
|
||||
|
||||
console.table(benchmarkResults);
|
||||
console.log(benchmarkResults);
|
||||
}
|
||||
|
||||
testSizes.forEach((iterations) => {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import pluginJs from '@eslint/js';
|
||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
{ files: ['**/*.{js,mjs,cjs,ts}'] },
|
||||
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
|
||||
pluginJs.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
eslintPluginPrettierRecommended,
|
||||
];
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
const { Decoder } = require('../dist');
|
||||
const { Decoder } = require('../dist/cjs');
|
||||
|
||||
const decoder = new Decoder();
|
||||
|
||||
const infoPacketBuffer = new Uint8Array([
|
||||
@@ -16,7 +17,7 @@ decoder.decode(infoPacketBuffer);
|
||||
decoder.decode(dataPacketBuffer);
|
||||
|
||||
// the system_name from info packets if available
|
||||
console.log(decoder.system_name);
|
||||
console.log(decoder.systemName);
|
||||
|
||||
// map of trackers populated with any data that has been received
|
||||
// this merges both info and data packet properties into one
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
const { Encoder, Tracker } = require('../dist');
|
||||
const encoder = new Encoder('Server Name', 2, 3); //server name, version high, version low
|
||||
const { Encoder, Tracker } = require('../dist/cjs');
|
||||
|
||||
const encoder = new Encoder('Server Name', 2, 3); // server name, version high, version low
|
||||
|
||||
const trackers = [];
|
||||
|
||||
|
||||
+8
-10
@@ -1,6 +1,6 @@
|
||||
// recreation of psn_client.cpp example from https://github.com/vyv/psn-cpp
|
||||
const dgram = require('dgram');
|
||||
const { Decoder } = require('../dist');
|
||||
const { Decoder } = require('../dist/cjs');
|
||||
|
||||
const client = dgram.createSocket('udp4');
|
||||
const decoder = new Decoder();
|
||||
@@ -23,18 +23,18 @@ setInterval(() => {
|
||||
}
|
||||
|
||||
Object.entries(decoder.trackers).forEach(([trackerId, tracker]) => {
|
||||
const trackerName = decoder.trackers[trackerId]?.tracker_name?.tracker_name;
|
||||
const trackerName = decoder.trackers[trackerId]?.name;
|
||||
console.log(`Tracker - id: ${trackerId} | name: ${trackerName || ''}`);
|
||||
if (tracker.pos) {
|
||||
console.log(`\tpos: ${tracker.pos.pos_x}, ${tracker.pos.pos_y}, ${tracker.pos.pos_z}`);
|
||||
console.log(`\tpos: ${tracker.pos.x}, ${tracker.pos.x}, ${tracker.pos.x}`);
|
||||
}
|
||||
|
||||
if (tracker.speed) {
|
||||
console.log(`\tspeed: ${tracker.speed.speed_x}, ${tracker.speed.speed_y}, ${tracker.speed.speed_z}`);
|
||||
console.log(`\tspeed: ${tracker.speed.x}, ${tracker.speed.y}, ${tracker.speed.z}`);
|
||||
}
|
||||
|
||||
if (tracker.ori) {
|
||||
console.log(`\tori: ${tracker.ori.ori_x}, ${tracker.ori.ori_y}, ${tracker.ori.ori_z}`);
|
||||
console.log(`\tori: ${tracker.ori.x}, ${tracker.ori.y}, ${tracker.ori.z}`);
|
||||
}
|
||||
|
||||
if (tracker.status) {
|
||||
@@ -42,17 +42,15 @@ setInterval(() => {
|
||||
}
|
||||
|
||||
if (tracker.accel) {
|
||||
console.log(`\taccel: ${tracker.accel.accel_x}, ${tracker.accel.accel_y}, ${tracker.accel.accel_z}`);
|
||||
console.log(`\taccel: ${tracker.accel.x}, ${tracker.accel.y}, ${tracker.accel.z}`);
|
||||
}
|
||||
|
||||
if (tracker.trgtpos) {
|
||||
console.log(
|
||||
`\ttrgtpos: ${tracker.trgtpos.trgtpos_x}, ${tracker.trgtpos.trgtpos_y}, ${tracker.trgtpos.trgtpos_z}`
|
||||
);
|
||||
console.log(`\ttrgtpos: ${tracker.trgtpos.x}, ${tracker.trgtpos.y}, ${tracker.trgtpos.z}`);
|
||||
}
|
||||
|
||||
if (tracker.timestamp) {
|
||||
console.log(`\ttimestamp: ${tracker.timestamp.tracker_timestamp}`);
|
||||
console.log(`\ttimestamp: ${tracker.timestamp}`);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
+5
-13
@@ -1,10 +1,9 @@
|
||||
// recreation of psn_server.cpp example from https://github.com/vyv/psn-cpp
|
||||
const dgram = require('dgram');
|
||||
const { Encoder, Tracker, Decoder } = require('../dist');
|
||||
const { Encoder, Tracker } = require('../dist/cjs');
|
||||
|
||||
const client = dgram.createSocket('udp4');
|
||||
const encoder = new Encoder('Test PSN Server', 2, 0);
|
||||
const decoder = new Decoder();
|
||||
|
||||
const trackers = [];
|
||||
|
||||
@@ -40,25 +39,18 @@ setInterval(() => {
|
||||
trackers[index].setTimestamp(timestamp);
|
||||
});
|
||||
|
||||
console.log(`Sending Data Packets`);
|
||||
const dataPackets = encoder.getDataPackets(timestamp, trackers);
|
||||
dataPackets.forEach((packet, index) => {
|
||||
const decodedPacket = decoder.decode(packet);
|
||||
console.log(
|
||||
`Sending PSN_DATA_PACKET : Frame Id = ${decodedPacket.packet_header.frame_id} , Packet Count = ${index + 1}`
|
||||
);
|
||||
dataPackets.forEach((packet) => {
|
||||
client.send(packet, 56565, '236.10.10.10');
|
||||
});
|
||||
timestamp += 1;
|
||||
}, 5);
|
||||
|
||||
setInterval(() => {
|
||||
console.log(`Sending Info Packets`);
|
||||
const infoPackets = encoder.getInfoPackets(timestamp, trackers);
|
||||
infoPackets.forEach((packet, index) => {
|
||||
const decodedPacket = decoder.decode(packet);
|
||||
console.log(
|
||||
`Sending PSN_INFO_PACKET : Frame Id = ${decodedPacket.packet_header.frame_id} , Packet Count = ${index + 1}`
|
||||
);
|
||||
|
||||
infoPackets.forEach((packet) => {
|
||||
client.send(packet, 56565, '236.10.10.10');
|
||||
});
|
||||
}, 500);
|
||||
|
||||
Generated
+1615
-24
File diff suppressed because it is too large
Load Diff
+30
-8
@@ -1,15 +1,31 @@
|
||||
{
|
||||
"name": "@jwetzell/posistagenet",
|
||||
"version": "1.0.0",
|
||||
"version": "2.1.1",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/index.js",
|
||||
"require": "./dist/cjs/index.js",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist",
|
||||
"build": "tsc",
|
||||
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
||||
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
|
||||
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
|
||||
"build:types": "tsc -p tsconfig.types.json",
|
||||
"example:client": "node examples/psn_client.js",
|
||||
"example:server": "node examples/psn_server.js",
|
||||
"prepublishOnly": "npm run build"
|
||||
"prepublishOnly": "npm run build",
|
||||
"lint:check": "eslint ./src",
|
||||
"format:check": "prettier ./ --check",
|
||||
"format:write": "prettier ./ --write",
|
||||
"pretest": "npm run build",
|
||||
"test": "node --test --experimental-test-coverage"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
@@ -22,9 +38,15 @@
|
||||
"repository": "https://github.com/jwetzell/psn-js",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "22.7.7",
|
||||
"prettier": "3.3.3",
|
||||
"@eslint/js": "9.34.0",
|
||||
"@types/node": "24.7.2",
|
||||
"eslint": "9.18.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-prettier": "5.5.4",
|
||||
"globals": "16.4.0",
|
||||
"prettier": "3.6.2",
|
||||
"rimraf": "6.0.1",
|
||||
"typescript": "5.6.3"
|
||||
"typescript": "5.9.2",
|
||||
"typescript-eslint": "8.46.0"
|
||||
}
|
||||
}
|
||||
|
||||
+52
-70
@@ -1,33 +1,32 @@
|
||||
import { Decoders } from '.';
|
||||
import { DataPacketChunk, InfoPacketChunk, InfoTrackerChunk, PacketHeaderChunk } from './models';
|
||||
import { Decoders } from './index.js';
|
||||
import { DataPacketChunk, InfoPacketChunk, Tracker, TrackerFromData, TrackerFromInfo } from './models/index.js';
|
||||
|
||||
export class Decoder {
|
||||
// TODO(jwetzell): check if these last packet headers are necessary to hold on to
|
||||
lastInfoPacketHeader?: PacketHeaderChunk;
|
||||
|
||||
lastDataPacketHeader?: PacketHeaderChunk;
|
||||
|
||||
infoPacketFrames: { [key: number]: InfoPacketChunk[] } = {};
|
||||
|
||||
dataPacketFrames: { [key: number]: DataPacketChunk[] } = {};
|
||||
|
||||
trackers: { [key: string]: InfoTrackerChunk } = {};
|
||||
trackers: { [key: string]: Tracker } = {};
|
||||
|
||||
system_name: string = '';
|
||||
systemName: string = '';
|
||||
constructor() {}
|
||||
|
||||
updateInfo(framePackets: InfoPacketChunk[]) {
|
||||
framePackets.forEach((packet) => {
|
||||
if (packet.system_name) {
|
||||
this.system_name = packet.system_name.system_name;
|
||||
if (packet.data.systemName?.data) {
|
||||
this.systemName = packet.data.systemName?.data.systemName;
|
||||
}
|
||||
|
||||
if (packet.tracker_list?.trackers) {
|
||||
Object.entries(packet.tracker_list.trackers).forEach(([trackerId, tracker]) => {
|
||||
if (!this.trackers[trackerId]) {
|
||||
this.trackers[trackerId] = {};
|
||||
if (packet.data.trackerList?.data) {
|
||||
packet.data.trackerList.data.trackers.forEach((infoTrackerChunk) => {
|
||||
if (!this.trackers[infoTrackerChunk.chunk.header.id]) {
|
||||
const tracker = TrackerFromInfo(infoTrackerChunk);
|
||||
if (tracker) {
|
||||
this.trackers[infoTrackerChunk.chunk.header.id] = tracker;
|
||||
}
|
||||
}
|
||||
this.trackers[trackerId].tracker_name = tracker.tracker_name;
|
||||
const tracker = this.trackers[infoTrackerChunk.chunk.header.id];
|
||||
tracker.updateInfo(infoTrackerChunk);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -35,97 +34,80 @@ export class Decoder {
|
||||
|
||||
updateData(framePackets: DataPacketChunk[]) {
|
||||
framePackets.forEach((packet) => {
|
||||
if (packet.tracker_list) {
|
||||
Object.entries(packet.tracker_list.trackers).forEach(([trackerId, tracker]) => {
|
||||
this.trackers[trackerId] = {
|
||||
...this.trackers[trackerId],
|
||||
...tracker,
|
||||
};
|
||||
if (packet.data.trackerList) {
|
||||
packet.data.trackerList?.data.trackers.forEach((dataTrackerChunk) => {
|
||||
if (!this.trackers[dataTrackerChunk.chunk.header.id]) {
|
||||
const tracker = TrackerFromData(dataTrackerChunk);
|
||||
if (tracker) {
|
||||
this.trackers[dataTrackerChunk.chunk.header.id] = tracker;
|
||||
}
|
||||
}
|
||||
const tracker = this.trackers[dataTrackerChunk.chunk.header.id];
|
||||
tracker.updateData(dataTrackerChunk);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO(jwetzell): add invalid frame id decoding. Scenario where a frame id is reused before one is complete
|
||||
decode(packetBuf: Uint8Array): DataPacketChunk | InfoPacketChunk | undefined {
|
||||
const packet = Decoders.Packet(packetBuf);
|
||||
decode(packetBuf: Uint8Array) {
|
||||
const packet = Decoders.Chunk(packetBuf);
|
||||
if (packet === undefined) {
|
||||
return packet;
|
||||
}
|
||||
|
||||
if (packet.id === 0x6756) {
|
||||
const infoPacket = packet as InfoPacketChunk;
|
||||
if (infoPacket && infoPacket.has_subchunks) {
|
||||
const currentInfoPacketHeader = infoPacket.packet_header;
|
||||
if (packet.header.id === 0x6756) {
|
||||
const infoPacket = Decoders.InfoPacketChunk(packetBuf);
|
||||
if (infoPacket && infoPacket.chunk.header.hasSubchunks) {
|
||||
const currentInfoPacketHeader = infoPacket.data.packetHeader;
|
||||
if (!currentInfoPacketHeader) {
|
||||
// NOTE(jwetzell): not sure that info packets without a header subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
|
||||
const systemSubChunk = infoPacket.system_name;
|
||||
const systemSubChunk = infoPacket.data.systemName;
|
||||
if (!systemSubChunk) {
|
||||
// NOTE(jwetzell): not sure that info packets without a system subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
if (currentInfoPacketHeader.frame_id) {
|
||||
if (this.infoPacketFrames[currentInfoPacketHeader.frame_id] === undefined) {
|
||||
this.infoPacketFrames[currentInfoPacketHeader.frame_id] = [];
|
||||
if (currentInfoPacketHeader.data.frameId) {
|
||||
if (this.infoPacketFrames[currentInfoPacketHeader.data.frameId] === undefined) {
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId] = [];
|
||||
}
|
||||
this.infoPacketFrames[currentInfoPacketHeader.frame_id].push(infoPacket);
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId].push(infoPacket);
|
||||
|
||||
if (
|
||||
this.infoPacketFrames[currentInfoPacketHeader.frame_id].length ===
|
||||
currentInfoPacketHeader.frame_packet_count
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId].length ===
|
||||
currentInfoPacketHeader.data.framePacketCount
|
||||
) {
|
||||
this.updateInfo(this.infoPacketFrames[currentInfoPacketHeader.frame_id]);
|
||||
delete this.infoPacketFrames[currentInfoPacketHeader.frame_id];
|
||||
this.updateInfo(this.infoPacketFrames[currentInfoPacketHeader.data.frameId]);
|
||||
delete this.infoPacketFrames[currentInfoPacketHeader.data.frameId];
|
||||
}
|
||||
}
|
||||
|
||||
this.lastInfoPacketHeader = currentInfoPacketHeader;
|
||||
}
|
||||
} else if (packet.id === 0x6755) {
|
||||
const dataPacket = packet as DataPacketChunk;
|
||||
if (dataPacket.has_subchunks) {
|
||||
const currentDataPacketHeader = dataPacket.packet_header;
|
||||
} else if (packet.header.id === 0x6755) {
|
||||
const dataPacket = Decoders.DataPacketChunk(packetBuf);
|
||||
if (dataPacket.chunk.header.hasSubchunks) {
|
||||
const currentDataPacketHeader = dataPacket.data.packetHeader;
|
||||
if (!currentDataPacketHeader) {
|
||||
// NOTE(jwetzell): not sure that info packets without a header subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
|
||||
if (currentDataPacketHeader.frame_id) {
|
||||
if (this.dataPacketFrames[currentDataPacketHeader.frame_id] === undefined) {
|
||||
this.dataPacketFrames[currentDataPacketHeader.frame_id] = [];
|
||||
if (currentDataPacketHeader.data.frameId) {
|
||||
if (this.dataPacketFrames[currentDataPacketHeader.data.frameId] === undefined) {
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId] = [];
|
||||
}
|
||||
this.dataPacketFrames[currentDataPacketHeader.frame_id].push(dataPacket);
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId].push(dataPacket);
|
||||
if (
|
||||
this.dataPacketFrames[currentDataPacketHeader.frame_id].length ===
|
||||
currentDataPacketHeader.frame_packet_count
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId].length ===
|
||||
currentDataPacketHeader.data.framePacketCount
|
||||
) {
|
||||
this.updateData(this.dataPacketFrames[currentDataPacketHeader.frame_id]);
|
||||
delete this.dataPacketFrames[currentDataPacketHeader.frame_id];
|
||||
this.updateData(this.dataPacketFrames[currentDataPacketHeader.data.frameId]);
|
||||
delete this.dataPacketFrames[currentDataPacketHeader.data.frameId];
|
||||
}
|
||||
}
|
||||
this.lastDataPacketHeader = currentDataPacketHeader;
|
||||
}
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
// NOTE(jwetzell): gets merged set of tracker field keys minus the guaranteed properties
|
||||
getTrackerFields(): Set<string> {
|
||||
const keys = new Set(
|
||||
Object.values(this.trackers)
|
||||
.map((tracker) => Object.keys(tracker))
|
||||
.flat(1)
|
||||
);
|
||||
|
||||
// NOTE(jwetzell): remove fields that definitely exist
|
||||
keys.delete('id');
|
||||
keys.delete('has_subchunks');
|
||||
keys.delete('data_len');
|
||||
keys.delete('chunk_data');
|
||||
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
+24
-14
@@ -1,19 +1,29 @@
|
||||
import { Chunk } from '../models/chunk';
|
||||
import { Chunk } from '../models/chunk.js';
|
||||
|
||||
export default (buffer: Uint8Array, dataDecoder: Function): Chunk => {
|
||||
let offset = 0;
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
||||
const chunk: Chunk = {};
|
||||
chunk.id = view.getUint16(offset, true);
|
||||
offset += 2;
|
||||
export default (buffer: Uint8Array): Chunk => {
|
||||
if (buffer.length < 4) {
|
||||
throw new Error('Chunk buffer must be at least 4 bytes');
|
||||
}
|
||||
|
||||
// NOTE(jwetzell): this data is split up as 1 bit for has_subchunks and 15 bits for the data_len
|
||||
const combinedLengthAndFlag = view.getUint16(offset, true);
|
||||
chunk.has_subchunks = combinedLengthAndFlag > 32768;
|
||||
chunk.data_len = chunk.has_subchunks ? combinedLengthAndFlag - 32768 : combinedLengthAndFlag;
|
||||
offset += 2;
|
||||
chunk.chunk_data = buffer.slice(offset, offset + chunk.data_len);
|
||||
const id = (buffer[1] << 8) + buffer[0];
|
||||
|
||||
// NOTE(jwetzell): this data is split up as 1 bit for hasSubchunks and 15 bits for the dataLen
|
||||
const combinedLengthAndFlag = (buffer[3] << 8) + buffer[2];
|
||||
const hasSubchunks = combinedLengthAndFlag > 32768;
|
||||
const dataLen = hasSubchunks ? combinedLengthAndFlag - 32768 : combinedLengthAndFlag;
|
||||
|
||||
const header = {
|
||||
id,
|
||||
dataLen,
|
||||
hasSubchunks,
|
||||
};
|
||||
|
||||
const chunkData = buffer.subarray(4, 4 + header.dataLen);
|
||||
|
||||
const chunk = {
|
||||
chunkData,
|
||||
header,
|
||||
};
|
||||
|
||||
dataDecoder(chunk);
|
||||
return chunk;
|
||||
};
|
||||
|
||||
@@ -1,30 +1,29 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { DataPacketChunk } from '../../models/data/data-packet-chunk';
|
||||
import { Constants } from '../../constants.js';
|
||||
import { DataPacketChunk, DataPacketChunkData } from '../../models/data/data-packet-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeDataPacketChunk(dataPacketChunk: DataPacketChunk) {
|
||||
if (dataPacketChunk.has_subchunks && dataPacketChunk.chunk_data && dataPacketChunk.data_len) {
|
||||
export default (buffer: Uint8Array): DataPacketChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: DataPacketChunkData = {};
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < dataPacketChunk.data_len) {
|
||||
const view = new DataView(
|
||||
dataPacketChunk.chunk_data.buffer,
|
||||
dataPacketChunk.chunk_data.byteOffset,
|
||||
dataPacketChunk.chunk_data.byteLength
|
||||
);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
dataPacketChunk.packet_header = Decoders.PacketHeaderChunk(dataPacketChunk.chunk_data.slice(offset));
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (dataPacketChunk.packet_header?.data_len) {
|
||||
offset += dataPacketChunk.packet_header.data_len;
|
||||
if (data.packetHeader.chunk.header.dataLen) {
|
||||
offset += data.packetHeader.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0001:
|
||||
dataPacketChunk.tracker_list = Decoders.DataTrackerListChunk(dataPacketChunk.chunk_data.slice(offset));
|
||||
data.trackerList = Decoders.DataTrackerListChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (dataPacketChunk.tracker_list.data_len) {
|
||||
offset += dataPacketChunk.tracker_list.data_len;
|
||||
if (data.trackerList.chunk.header.dataLen) {
|
||||
offset += data.trackerList.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -32,7 +31,9 @@ function decodeDataPacketChunk(dataPacketChunk: DataPacketChunk) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (buffer: Uint8Array): DataPacketChunk =>
|
||||
Decoders.Chunk(buffer, decodeDataPacketChunk) as DataPacketChunk;
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,43 +1,46 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { DataTrackerChunk } from '../../models/data/data-tracker-chunk';
|
||||
import { Constants } from '../../constants.js';
|
||||
import { DataTrackerChunk, DataTrackerChunkData } from '../../models/data/data-tracker-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeTrackerChunk(trackerChunk: DataTrackerChunk) {
|
||||
if (trackerChunk.chunk_data && trackerChunk.data_len) {
|
||||
export default (buffer: Uint8Array): DataTrackerChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const data: DataTrackerChunkData = {};
|
||||
if (chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < trackerChunk.data_len) {
|
||||
const trackerFieldChunk = Decoders.DataTrackerFieldChunk(trackerChunk.chunk_data.slice(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerFieldChunk.data_len) {
|
||||
offset += trackerFieldChunk.data_len;
|
||||
switch (trackerFieldChunk.id) {
|
||||
case 0x0000:
|
||||
trackerChunk.pos = trackerFieldChunk;
|
||||
break;
|
||||
case 0x0001:
|
||||
trackerChunk.speed = trackerFieldChunk;
|
||||
break;
|
||||
case 0x0002:
|
||||
trackerChunk.ori = trackerFieldChunk;
|
||||
break;
|
||||
case 0x0003:
|
||||
trackerChunk.status = trackerFieldChunk;
|
||||
break;
|
||||
case 0x0004:
|
||||
trackerChunk.accel = trackerFieldChunk;
|
||||
break;
|
||||
case 0x0005:
|
||||
trackerChunk.trgtpos = trackerFieldChunk;
|
||||
break;
|
||||
case 0x0006:
|
||||
trackerChunk.timestamp = trackerFieldChunk;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const trackerFieldChunk = Decoders.Chunk(chunk.chunkData.subarray(offset));
|
||||
switch (trackerFieldChunk.header.id) {
|
||||
case 0x0000:
|
||||
data.pos = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0001:
|
||||
data.speed = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0002:
|
||||
data.ori = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0003:
|
||||
data.status = Decoders.DataTrackerStatusChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0004:
|
||||
data.accel = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0005:
|
||||
data.trgtpos = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0006:
|
||||
data.timestamp = Decoders.DataTrackerTimestampChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
offset += trackerFieldChunk.header.dataLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerChunk => Decoders.Chunk(buffer, decodeTrackerChunk) as DataTrackerChunk;
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
|
||||
import { Decoders } from '..';
|
||||
import { DataTrackerFieldChunk } from '../../models/data/data-tracker-field-chunk';
|
||||
|
||||
function readXYZ(trackerFieldChunk: DataTrackerFieldChunk, prefix: string = '') {
|
||||
if (trackerFieldChunk.chunk_data) {
|
||||
const view = new DataView(
|
||||
trackerFieldChunk.chunk_data.buffer,
|
||||
trackerFieldChunk.chunk_data.byteOffset,
|
||||
trackerFieldChunk.chunk_data.byteLength
|
||||
);
|
||||
trackerFieldChunk[`${prefix}x`] = view.getFloat32(0, true);
|
||||
trackerFieldChunk[`${prefix}y`] = view.getFloat32(4, true);
|
||||
trackerFieldChunk[`${prefix}z`] = view.getFloat32(8, true);
|
||||
}
|
||||
}
|
||||
function decodeTrackerFieldChunk(trackerFieldChunk: DataTrackerFieldChunk) {
|
||||
if (trackerFieldChunk.id !== undefined) {
|
||||
switch (trackerFieldChunk.id) {
|
||||
case 0x0000:
|
||||
readXYZ(trackerFieldChunk, 'pos_');
|
||||
break;
|
||||
case 0x0001:
|
||||
readXYZ(trackerFieldChunk, 'speed_');
|
||||
break;
|
||||
case 0x0002:
|
||||
readXYZ(trackerFieldChunk, 'ori_');
|
||||
break;
|
||||
case 0x0003:
|
||||
if (trackerFieldChunk.chunk_data) {
|
||||
const view = new DataView(
|
||||
trackerFieldChunk.chunk_data.buffer,
|
||||
trackerFieldChunk.chunk_data.byteOffset,
|
||||
trackerFieldChunk.chunk_data.byteLength
|
||||
);
|
||||
trackerFieldChunk.validity = view.getFloat32(0, true);
|
||||
}
|
||||
break;
|
||||
case 0x0004:
|
||||
readXYZ(trackerFieldChunk, 'accel_');
|
||||
break;
|
||||
case 0x0005:
|
||||
readXYZ(trackerFieldChunk, 'trgtpos_');
|
||||
break;
|
||||
case 0x0006:
|
||||
if (trackerFieldChunk.chunk_data) {
|
||||
const view = new DataView(
|
||||
trackerFieldChunk.chunk_data.buffer,
|
||||
trackerFieldChunk.chunk_data.byteOffset,
|
||||
trackerFieldChunk.chunk_data.byteLength
|
||||
);
|
||||
trackerFieldChunk.tracker_timestamp = view.getBigUint64(0, true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerFieldChunk =>
|
||||
Decoders.Chunk(buffer, decodeTrackerFieldChunk) as DataTrackerFieldChunk;
|
||||
@@ -1,24 +1,33 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { DataTrackerListChunk } from '../../models/data/data-tracker-list-chunk';
|
||||
import { Constants } from '../../constants.js';
|
||||
import { DataTrackerListChunk, DataTrackerListChunkData } from '../../models/data/data-tracker-list-chunk.js';
|
||||
import { DataTrackerChunk } from '../../models/index.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeDataTrackerListChunk(dataTrackerListChunk: DataTrackerListChunk) {
|
||||
dataTrackerListChunk.trackers = {};
|
||||
export default (buffer: Uint8Array): DataTrackerListChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const trackers: DataTrackerChunk[] = [];
|
||||
|
||||
// TODO(jwetzell): add error handling
|
||||
let offset = 0;
|
||||
if (dataTrackerListChunk.chunk_data) {
|
||||
while (offset < dataTrackerListChunk.chunk_data.length) {
|
||||
const trackerChunk = Decoders.DataTrackerChunk(dataTrackerListChunk.chunk_data.slice(offset));
|
||||
if (chunk.chunkData) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.chunkData.length) {
|
||||
const trackerChunk = Decoders.DataTrackerChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerChunk.data_len) {
|
||||
offset += trackerChunk.data_len;
|
||||
if (trackerChunk.chunk.header.dataLen) {
|
||||
offset += trackerChunk.chunk.header.dataLen;
|
||||
}
|
||||
if (trackerChunk.id !== undefined) {
|
||||
dataTrackerListChunk.trackers[trackerChunk.id] = trackerChunk;
|
||||
if (trackerChunk.chunk.header.id !== undefined) {
|
||||
trackers.push(trackerChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export default (buffer: Uint8Array): DataTrackerListChunk =>
|
||||
Decoders.Chunk(buffer, decodeDataTrackerListChunk) as DataTrackerListChunk;
|
||||
|
||||
const data: DataTrackerListChunkData = {
|
||||
trackers,
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { DataTrackerStatusChunk, DataTrackerStatusChunkData } from '../../models/data/data-tracker-status-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerStatusChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const validity = view.getFloat32(0, true);
|
||||
|
||||
const data: DataTrackerStatusChunkData = {
|
||||
validity,
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerTimestampChunkData,
|
||||
} from '../../models/data/data-tracker-timestamp-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerTimestampChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const timestamp = view.getBigUint64(0, true);
|
||||
|
||||
const data: DataTrackerTimestampChunkData = {
|
||||
timestamp,
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import { DataTrackerXYZChunk, DataTrackerXYZChunkData } from '../../models/data/data-tracker-xyz-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerXYZChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
// TODO(jwetzell): add error handling
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
|
||||
const data: DataTrackerXYZChunkData = {
|
||||
x: view.getFloat32(0, true),
|
||||
y: view.getFloat32(4, true),
|
||||
z: view.getFloat32(8, true),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
+16
-14
@@ -1,25 +1,27 @@
|
||||
import Chunk from './chunk';
|
||||
import Packet from './packet';
|
||||
import PacketHeaderChunk from './packet-header-chunk';
|
||||
import Chunk from './chunk.js';
|
||||
import PacketHeaderChunk from './packet-header-chunk.js';
|
||||
|
||||
import DataPacketChunk from './data/data-packet-chunk';
|
||||
import DataTrackerChunk from './data/data-tracker-chunk';
|
||||
import DataTrackerFieldChunk from './data/data-tracker-field-chunk';
|
||||
import DataTrackerListChunk from './data/data-tracker-list-chunk';
|
||||
import DataPacketChunk from './data/data-packet-chunk.js';
|
||||
import DataTrackerChunk from './data/data-tracker-chunk.js';
|
||||
import DataTrackerListChunk from './data/data-tracker-list-chunk.js';
|
||||
import DataTrackerStatusChunk from './data/data-tracker-status-chunk.js';
|
||||
import DataTrackerTimestampChunk from './data/data-tracker-timestamp-chunk.js';
|
||||
import DataTrackerXYZChunk from './data/data-tracker-xyz-chunk.js';
|
||||
|
||||
import InfoPacketChunk from './info/info-packet-chunk';
|
||||
import InfoSystemNameChunk from './info/info-system-name-chunk';
|
||||
import InfoTrackerChunk from './info/info-tracker-chunk';
|
||||
import InfoTrackerListChunk from './info/info-tracker-list-chunk';
|
||||
import InfoTrackerNameChunk from './info/info-tracker-name-chunk';
|
||||
import InfoPacketChunk from './info/info-packet-chunk.js';
|
||||
import InfoSystemNameChunk from './info/info-system-name-chunk.js';
|
||||
import InfoTrackerChunk from './info/info-tracker-chunk.js';
|
||||
import InfoTrackerListChunk from './info/info-tracker-list-chunk.js';
|
||||
import InfoTrackerNameChunk from './info/info-tracker-name-chunk.js';
|
||||
|
||||
export const Decoders = {
|
||||
Chunk,
|
||||
PacketHeaderChunk,
|
||||
Packet,
|
||||
DataPacketChunk,
|
||||
DataTrackerChunk,
|
||||
DataTrackerFieldChunk,
|
||||
DataTrackerXYZChunk,
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerListChunk,
|
||||
InfoPacketChunk,
|
||||
InfoSystemNameChunk,
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoPacketChunk } from '../../models/info/info-packet-chunk';
|
||||
import { Constants } from '../../constants.js';
|
||||
import { InfoPacketChunk, InfoPacketChunkData } from '../../models/info/info-packet-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeInfoPacketChunk(infoPacketChunk: InfoPacketChunk) {
|
||||
if (infoPacketChunk.has_subchunks && infoPacketChunk.chunk_data && infoPacketChunk.data_len) {
|
||||
export default (buffer: Uint8Array): InfoPacketChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoPacketChunkData = {};
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < infoPacketChunk.data_len) {
|
||||
const view = new DataView(
|
||||
infoPacketChunk.chunk_data.buffer,
|
||||
infoPacketChunk.chunk_data.byteOffset,
|
||||
infoPacketChunk.chunk_data.byteLength
|
||||
);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
infoPacketChunk.packet_header = Decoders.PacketHeaderChunk(infoPacketChunk.chunk_data.slice(offset));
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoPacketChunk.packet_header?.data_len) {
|
||||
offset += infoPacketChunk.packet_header.data_len;
|
||||
if (data.packetHeader?.chunk.header.dataLen) {
|
||||
offset += data.packetHeader.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0001:
|
||||
infoPacketChunk.system_name = Decoders.InfoSystemNameChunk(infoPacketChunk.chunk_data.slice(offset));
|
||||
data.systemName = Decoders.InfoSystemNameChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoPacketChunk.system_name?.data_len) {
|
||||
offset += infoPacketChunk.system_name.data_len;
|
||||
if (data.systemName?.chunk.header.dataLen) {
|
||||
offset += data.systemName?.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0002:
|
||||
infoPacketChunk.tracker_list = Decoders.InfoTrackerListChunk(infoPacketChunk.chunk_data.slice(offset));
|
||||
data.trackerList = Decoders.InfoTrackerListChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoPacketChunk.tracker_list?.data_len) {
|
||||
offset += infoPacketChunk.tracker_list.data_len;
|
||||
if (data.trackerList?.chunk.header.dataLen) {
|
||||
offset += data.trackerList.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -39,7 +38,9 @@ function decodeInfoPacketChunk(infoPacketChunk: InfoPacketChunk) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (buffer: Uint8Array): InfoPacketChunk =>
|
||||
Decoders.Chunk(buffer, decodeInfoPacketChunk) as InfoPacketChunk;
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { Decoders } from '..';
|
||||
import { InfoSystemNameChunk } from '../../models/info/info-system-name-chunk';
|
||||
import { InfoSystemNameChunk, InfoSystemNameChunkData } from '../../models/info/info-system-name-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeSystemNameChunk(systemNameChunk: InfoSystemNameChunk) {
|
||||
if (systemNameChunk.chunk_data !== undefined && systemNameChunk.data_len !== undefined) {
|
||||
systemNameChunk.system_name = new TextDecoder().decode(
|
||||
systemNameChunk.chunk_data.slice(0, systemNameChunk.data_len)
|
||||
);
|
||||
}
|
||||
}
|
||||
const nameDecoder = new TextDecoder();
|
||||
export default (buffer: Uint8Array): InfoSystemNameChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
export default (buffer: Uint8Array): InfoSystemNameChunk =>
|
||||
Decoders.Chunk(buffer, decodeSystemNameChunk) as InfoSystemNameChunk;
|
||||
const data: InfoSystemNameChunkData = {
|
||||
systemName: nameDecoder.decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,31 +1,35 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoTrackerChunk } from '../../models/info/info-tracker-chunk';
|
||||
import { Constants } from '../../constants.js';
|
||||
import { InfoTrackerChunk, InfoTrackerChunkData } from '../../models/info/info-tracker-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeInfoTrackerChunk(infoTrackerChunk: InfoTrackerChunk) {
|
||||
if (infoTrackerChunk.has_subchunks && infoTrackerChunk.chunk_data && infoTrackerChunk.data_len) {
|
||||
export default (buffer: Uint8Array): InfoTrackerChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < infoTrackerChunk.data_len) {
|
||||
const view = new DataView(
|
||||
infoTrackerChunk.chunk_data.buffer,
|
||||
infoTrackerChunk.chunk_data.byteOffset,
|
||||
infoTrackerChunk.chunk_data.byteLength
|
||||
);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
infoTrackerChunk.tracker_name = Decoders.InfoTrackerNameChunk(infoTrackerChunk.chunk_data.slice(offset));
|
||||
case 0x0000: {
|
||||
const data: InfoTrackerChunkData = {
|
||||
trackerName: Decoders.InfoTrackerNameChunk(chunk.chunkData.subarray(offset)),
|
||||
};
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoTrackerChunk.tracker_name?.data_len) {
|
||||
offset += infoTrackerChunk?.tracker_name?.data_len;
|
||||
if (data.trackerName.chunk.header.dataLen) {
|
||||
offset += data.trackerName.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (buffer: Uint8Array): InfoTrackerChunk => Decoders.Chunk(buffer, decodeInfoTrackerChunk);
|
||||
return {
|
||||
chunk,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoTrackerListChunk } from '../../models/info/info-tracker-list-chunk';
|
||||
import { Constants } from '../../constants.js';
|
||||
import { InfoTrackerChunk } from '../../models/info/info-tracker-chunk.js';
|
||||
import { InfoTrackerListChunk, InfoTrackerListChunkData } from '../../models/info/info-tracker-list-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeInfoTrackerListChunk(infoTrackerListChunk: InfoTrackerListChunk) {
|
||||
infoTrackerListChunk.trackers = {};
|
||||
if (infoTrackerListChunk.has_subchunks && infoTrackerListChunk.chunk_data) {
|
||||
export default (buffer: Uint8Array): InfoTrackerListChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const trackers: InfoTrackerChunk[] = [];
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData) {
|
||||
let offset = 0;
|
||||
if (infoTrackerListChunk.data_len) {
|
||||
while (offset < infoTrackerListChunk.data_len) {
|
||||
const trackerChunk = Decoders.InfoTrackerChunk(infoTrackerListChunk.chunk_data.slice(offset));
|
||||
if (chunk.header.dataLen) {
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const trackerChunk = Decoders.InfoTrackerChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerChunk.data_len) {
|
||||
offset += trackerChunk.data_len;
|
||||
if (trackerChunk.chunk.header.dataLen) {
|
||||
offset += trackerChunk.chunk.header.dataLen;
|
||||
}
|
||||
if (trackerChunk.id !== undefined) {
|
||||
infoTrackerListChunk.trackers[trackerChunk.id] = trackerChunk;
|
||||
if (trackerChunk.chunk.header.id !== undefined) {
|
||||
trackers.push(trackerChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export default (buffer: Uint8Array): InfoTrackerListChunk =>
|
||||
Decoders.Chunk(buffer, decodeInfoTrackerListChunk) as InfoTrackerListChunk;
|
||||
const data: InfoTrackerListChunkData = {
|
||||
trackers,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { Decoders } from '..';
|
||||
import { InfoTrackerNameChunk } from '../../models/info/info-tracker-name-chunk';
|
||||
import { InfoTrackerNameChunk, InfoTrackerNameChunkData } from '../../models/info/info-tracker-name-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
function decodeTrackerNameChunk(trackerNameChunk: InfoTrackerNameChunk) {
|
||||
if (trackerNameChunk.chunk_data !== undefined && trackerNameChunk.data_len !== undefined) {
|
||||
trackerNameChunk.tracker_name = new TextDecoder().decode(
|
||||
trackerNameChunk.chunk_data.slice(0, trackerNameChunk.data_len)
|
||||
);
|
||||
}
|
||||
}
|
||||
export default (buffer: Uint8Array): InfoTrackerNameChunk =>
|
||||
Decoders.Chunk(buffer, decodeTrackerNameChunk) as InfoTrackerNameChunk;
|
||||
const nameDecoder = new TextDecoder();
|
||||
export default (buffer: Uint8Array): InfoTrackerNameChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoTrackerNameChunkData = {
|
||||
trackerName: nameDecoder.decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import { Decoders } from '.';
|
||||
import { PacketHeaderChunk } from '../models/packet-header-chunk';
|
||||
|
||||
function decodePacketHeaderChunk(packetHeaderChunk: PacketHeaderChunk) {
|
||||
if (packetHeaderChunk.chunk_data) {
|
||||
const view = new DataView(
|
||||
packetHeaderChunk.chunk_data.buffer,
|
||||
packetHeaderChunk.chunk_data.byteOffset,
|
||||
packetHeaderChunk.chunk_data.byteLength
|
||||
);
|
||||
packetHeaderChunk.packet_timestamp = view.getBigUint64(0, true);
|
||||
packetHeaderChunk.version_high = view.getUint8(8);
|
||||
packetHeaderChunk.version_low = view.getUint8(9);
|
||||
packetHeaderChunk.frame_id = view.getUint8(10);
|
||||
packetHeaderChunk.frame_packet_count = view.getUint8(11);
|
||||
}
|
||||
}
|
||||
import { PacketHeaderChunk, PacketHeaderChunkData } from '../models/packet-header-chunk.js';
|
||||
import { Decoders } from './index.js';
|
||||
|
||||
export default (buffer: Uint8Array): PacketHeaderChunk => {
|
||||
return Decoders.Chunk(buffer, decodePacketHeaderChunk);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
let packetTimestamp = BigInt(chunk.chunkData[7]) << BigInt(56);
|
||||
packetTimestamp += BigInt(chunk.chunkData[6]) << BigInt(48);
|
||||
packetTimestamp += BigInt(chunk.chunkData[5]) << BigInt(40);
|
||||
packetTimestamp += BigInt(chunk.chunkData[4]) << BigInt(32);
|
||||
packetTimestamp += BigInt(chunk.chunkData[3]) << BigInt(24);
|
||||
packetTimestamp += BigInt(chunk.chunkData[2]) << BigInt(16);
|
||||
packetTimestamp += BigInt(chunk.chunkData[1]) << BigInt(8);
|
||||
packetTimestamp += BigInt(chunk.chunkData[0]);
|
||||
const data: PacketHeaderChunkData = {
|
||||
packetTimestamp,
|
||||
versionHigh: chunk.chunkData[8],
|
||||
versionLow: chunk.chunkData[9],
|
||||
frameId: chunk.chunkData[10],
|
||||
framePacketCount: chunk.chunkData[11],
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Decoders } from '.';
|
||||
import { DataPacketChunk } from '../models/data/data-packet-chunk';
|
||||
import { InfoPacketChunk } from '../models/info/info-packet-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): InfoPacketChunk | DataPacketChunk | undefined => {
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
||||
const chunkId = view.getUint16(0, true);
|
||||
|
||||
switch (chunkId) {
|
||||
case 0x6756:
|
||||
return Decoders.InfoPacketChunk(buffer);
|
||||
case 0x6755:
|
||||
return Decoders.DataPacketChunk(buffer);
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { Encoders, Tracker } from '.';
|
||||
import { Constants } from './constants';
|
||||
import { Constants } from './constants.js';
|
||||
import { Encoders, Tracker } from './index.js';
|
||||
|
||||
export class Encoder {
|
||||
private systemName: string;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const header = new DataView(new ArrayBuffer(4));
|
||||
export default (id: number, chunkData: Uint8Array, hasSubchunks: boolean): Uint8Array => {
|
||||
if (!Number.isInteger(id)) {
|
||||
throw new Error('chunk id must be an integer');
|
||||
@@ -11,7 +12,6 @@ export default (id: number, chunkData: Uint8Array, hasSubchunks: boolean): Uint8
|
||||
throw new Error('chunkData can not be greater than 32767 bytes');
|
||||
}
|
||||
|
||||
const header = new DataView(new ArrayBuffer(4));
|
||||
header.setUint16(0, id, true);
|
||||
const hasSubChunksBit = (hasSubchunks ? 1 : 0) << 15;
|
||||
header.setUint16(2, hasSubChunksBit + chunkData.length, true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
export default (packetHeaderChunk: Uint8Array, trackerListChunk: Uint8Array): Uint8Array => {
|
||||
const chunkData = new Uint8Array(packetHeaderChunk.length + trackerListChunk.length);
|
||||
chunkData.set(packetHeaderChunk);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
return chunk(0x0004, new Uint8Array(buf.buffer), false);
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0004, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerId: number, fieldChunks: Uint8Array[]): Uint8Array => {
|
||||
let fieldChunksTotalLength = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerChunks: Uint8Array[]) => {
|
||||
let trackerChunksTotalLength = 0;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
return chunk(0x0002, new Uint8Array(buf.buffer), false);
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0002, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
|
||||
return chunk(0x0000, new Uint8Array(buf.buffer), false);
|
||||
return chunk(0x0000, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
|
||||
return chunk(0x0001, new Uint8Array(buf.buffer), false);
|
||||
return chunk(0x0001, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(1);
|
||||
export default (validity: number): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(4));
|
||||
buf.setFloat32(0, validity, true);
|
||||
return chunk(0x0003, new Uint8Array(buf.buffer), false);
|
||||
floatArray[0] = validity;
|
||||
return chunk(0x0003, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const buf = new DataView(new ArrayBuffer(8));
|
||||
export default (timestamp: bigint): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(8));
|
||||
buf.setBigUint64(0, BigInt(timestamp), true);
|
||||
return chunk(0x0006, new Uint8Array(buf.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
|
||||
return chunk(0x0005, new Uint8Array(buf.buffer), false);
|
||||
return chunk(0x0005, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
+17
-17
@@ -1,21 +1,21 @@
|
||||
import Chunk from './chunk';
|
||||
import DataPacketChunk from './data/data-packet-chunk';
|
||||
import DataTrackerAccelChunk from './data/data-tracker-accel-chunk';
|
||||
import DataTrackerChunk from './data/data-tracker-chunk';
|
||||
import DataTrackerListChunk from './data/data-tracker-list-chunk';
|
||||
import DataTrackerOriChunk from './data/data-tracker-ori-chunk';
|
||||
import DataTrackerPosChunk from './data/data-tracker-pos-chunk';
|
||||
import DataTrackerSpeedChunk from './data/data-tracker-speed-chunk';
|
||||
import DataTrackerStatusChunk from './data/data-tracker-status-chunk';
|
||||
import DataTrackerTimestampChunk from './data/data-tracker-timestamp-chunk';
|
||||
import DataTrackerTrgtposChunk from './data/data-tracker-trgtpos-chunk';
|
||||
import PacketHeaderChunk from './packet-header-chunk';
|
||||
import Chunk from './chunk.js';
|
||||
import DataPacketChunk from './data/data-packet-chunk.js';
|
||||
import DataTrackerAccelChunk from './data/data-tracker-accel-chunk.js';
|
||||
import DataTrackerChunk from './data/data-tracker-chunk.js';
|
||||
import DataTrackerListChunk from './data/data-tracker-list-chunk.js';
|
||||
import DataTrackerOriChunk from './data/data-tracker-ori-chunk.js';
|
||||
import DataTrackerPosChunk from './data/data-tracker-pos-chunk.js';
|
||||
import DataTrackerSpeedChunk from './data/data-tracker-speed-chunk.js';
|
||||
import DataTrackerStatusChunk from './data/data-tracker-status-chunk.js';
|
||||
import DataTrackerTimestampChunk from './data/data-tracker-timestamp-chunk.js';
|
||||
import DataTrackerTrgtposChunk from './data/data-tracker-trgtpos-chunk.js';
|
||||
import PacketHeaderChunk from './packet-header-chunk.js';
|
||||
|
||||
import InfoPacketChunk from './info/info-packet-chunk';
|
||||
import InfoSystemNameChunk from './info/info-system-name-chunk';
|
||||
import InfoTrackerChunk from './info/info-tracker-chunk';
|
||||
import InfoTrackerListChunk from './info/info-tracker-list-chunk';
|
||||
import InfoTrackerNameChunk from './info/info-tracker-name-chunk';
|
||||
import InfoPacketChunk from './info/info-packet-chunk.js';
|
||||
import InfoSystemNameChunk from './info/info-system-name-chunk.js';
|
||||
import InfoTrackerChunk from './info/info-tracker-chunk.js';
|
||||
import InfoTrackerListChunk from './info/info-tracker-list-chunk.js';
|
||||
import InfoTrackerNameChunk from './info/info-tracker-name-chunk.js';
|
||||
|
||||
export const Encoders = {
|
||||
DataPacketChunk,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (
|
||||
packetHeaderChunk: Uint8Array,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (systemName: string): Uint8Array => chunk(0x0001, new TextEncoder().encode(systemName), false);
|
||||
import chunk from '../chunk.js';
|
||||
const nameEncoder = new TextEncoder();
|
||||
export default (systemName: string): Uint8Array => chunk(0x0001, nameEncoder.encode(systemName), false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerId: number, trackerNameChunk: Uint8Array): Uint8Array =>
|
||||
chunk(trackerId, trackerNameChunk, true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerChunks: Uint8Array[]): Uint8Array => {
|
||||
let trackerChunksTotalLength = 0;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerName: string) => chunk(0x0000, new TextEncoder().encode(trackerName), false);
|
||||
const nameEncoder = new TextEncoder();
|
||||
export default (trackerName: string) => chunk(0x0000, nameEncoder.encode(trackerName), false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import chunk from './chunk';
|
||||
import chunk from './chunk.js';
|
||||
|
||||
const packetHeader = new DataView(new ArrayBuffer(12));
|
||||
export default (
|
||||
timestamp: bigint,
|
||||
versionHigh: number,
|
||||
@@ -33,7 +34,6 @@ export default (
|
||||
throw new Error('frame packet count must be >= 0 and <= 255');
|
||||
}
|
||||
|
||||
const packetHeader = new DataView(new ArrayBuffer(12));
|
||||
packetHeader.setBigUint64(0, BigInt(timestamp), true);
|
||||
packetHeader.setUint8(8, versionHigh);
|
||||
packetHeader.setUint8(9, versionLow);
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
export { Decoder } from './decoder';
|
||||
export * from './decoders';
|
||||
export { Encoder } from './encoder';
|
||||
export * from './encoders';
|
||||
export * from './models';
|
||||
export { Decoder } from './decoder.js';
|
||||
export * from './decoders/index.js';
|
||||
export { Encoder } from './encoder.js';
|
||||
export * from './encoders/index.js';
|
||||
export * from './models/index.js';
|
||||
|
||||
+9
-5
@@ -1,6 +1,10 @@
|
||||
export interface Chunk {
|
||||
id?: number;
|
||||
has_subchunks?: boolean;
|
||||
data_len?: number;
|
||||
chunk_data?: Uint8Array;
|
||||
export interface ChunkHeader {
|
||||
id: number;
|
||||
dataLen: number;
|
||||
hasSubchunks: boolean;
|
||||
}
|
||||
|
||||
export interface Chunk {
|
||||
chunkData: Uint8Array;
|
||||
header: ChunkHeader;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { PacketHeaderChunk } from '../packet-header-chunk';
|
||||
import { DataTrackerListChunk } from './data-tracker-list-chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
import { PacketHeaderChunk } from '../packet-header-chunk.js';
|
||||
import { DataTrackerListChunk } from './data-tracker-list-chunk.js';
|
||||
|
||||
export interface DataPacketChunk extends Chunk {
|
||||
packet_header: PacketHeaderChunk;
|
||||
tracker_list: DataTrackerListChunk;
|
||||
export interface DataPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
trackerList?: DataTrackerListChunk;
|
||||
}
|
||||
|
||||
export interface DataPacketChunk {
|
||||
chunk: Chunk;
|
||||
data: DataPacketChunkData;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { DataTrackerFieldChunk } from './data-tracker-field-chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
import { DataTrackerStatusChunk } from './data-tracker-status-chunk.js';
|
||||
import { DataTrackerTimestampChunk } from './data-tracker-timestamp-chunk.js';
|
||||
import { DataTrackerXYZChunk } from './data-tracker-xyz-chunk.js';
|
||||
|
||||
export interface DataTrackerChunk extends Chunk {
|
||||
pos?: DataTrackerFieldChunk;
|
||||
speed?: DataTrackerFieldChunk;
|
||||
ori?: DataTrackerFieldChunk;
|
||||
status?: DataTrackerFieldChunk;
|
||||
accel?: DataTrackerFieldChunk;
|
||||
trgtpos?: DataTrackerFieldChunk;
|
||||
timestamp?: DataTrackerFieldChunk;
|
||||
export interface DataTrackerChunkData {
|
||||
pos?: DataTrackerXYZChunk;
|
||||
speed?: DataTrackerXYZChunk;
|
||||
ori?: DataTrackerXYZChunk;
|
||||
status?: DataTrackerStatusChunk;
|
||||
accel?: DataTrackerXYZChunk;
|
||||
trgtpos?: DataTrackerXYZChunk;
|
||||
timestamp?: DataTrackerTimestampChunk;
|
||||
}
|
||||
|
||||
export interface DataTrackerChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerChunkData;
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerFieldChunk extends Chunk {
|
||||
[key: string]: number | bigint | number[] | Uint8Array | undefined | boolean;
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { DataTrackerChunk } from './data-tracker-chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
import { DataTrackerChunk } from './data-tracker-chunk.js';
|
||||
|
||||
export interface DataTrackerListChunk extends Chunk {
|
||||
trackers: {
|
||||
[key: number]: DataTrackerChunk;
|
||||
};
|
||||
export interface DataTrackerListChunkData {
|
||||
trackers: DataTrackerChunk[];
|
||||
}
|
||||
|
||||
export interface DataTrackerListChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerListChunkData;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Chunk } from '../chunk.js';
|
||||
|
||||
export interface DataTrackerStatusChunkData {
|
||||
validity: number;
|
||||
}
|
||||
|
||||
export interface DataTrackerStatusChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerStatusChunkData;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Chunk } from '../chunk.js';
|
||||
|
||||
export interface DataTrackerTimestampChunkData {
|
||||
timestamp: bigint;
|
||||
}
|
||||
|
||||
export interface DataTrackerTimestampChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerTimestampChunkData;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Chunk } from '../chunk.js';
|
||||
|
||||
export interface DataTrackerXYZChunkData {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
}
|
||||
|
||||
export interface DataTrackerXYZChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerXYZChunkData;
|
||||
}
|
||||
+11
-12
@@ -1,12 +1,11 @@
|
||||
export * from './chunk';
|
||||
export * from './data/data-packet-chunk';
|
||||
export * from './data/data-tracker-chunk';
|
||||
export * from './data/data-tracker-field-chunk';
|
||||
export * from './data/data-tracker-list-chunk';
|
||||
export * from './info/info-packet-chunk';
|
||||
export * from './info/info-system-name-chunk';
|
||||
export * from './info/info-tracker-chunk';
|
||||
export * from './info/info-tracker-list-chunk';
|
||||
export * from './info/info-tracker-name-chunk';
|
||||
export * from './packet-header-chunk';
|
||||
export * from './tracker';
|
||||
export * from './chunk.js';
|
||||
export * from './data/data-packet-chunk.js';
|
||||
export * from './data/data-tracker-chunk.js';
|
||||
export * from './data/data-tracker-list-chunk.js';
|
||||
export * from './info/info-packet-chunk.js';
|
||||
export * from './info/info-system-name-chunk.js';
|
||||
export * from './info/info-tracker-chunk.js';
|
||||
export * from './info/info-tracker-list-chunk.js';
|
||||
export * from './info/info-tracker-name-chunk.js';
|
||||
export * from './packet-header-chunk.js';
|
||||
export * from './tracker.js';
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { PacketHeaderChunk } from '../packet-header-chunk';
|
||||
import { InfoSystemNameChunk } from './info-system-name-chunk';
|
||||
import { InfoTrackerListChunk } from './info-tracker-list-chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
import { PacketHeaderChunk } from '../packet-header-chunk.js';
|
||||
import { InfoSystemNameChunk } from './info-system-name-chunk.js';
|
||||
import { InfoTrackerListChunk } from './info-tracker-list-chunk.js';
|
||||
|
||||
export interface InfoPacketChunk extends Chunk {
|
||||
packet_header: PacketHeaderChunk;
|
||||
system_name: InfoSystemNameChunk;
|
||||
tracker_list: InfoTrackerListChunk;
|
||||
export interface InfoPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
systemName?: InfoSystemNameChunk;
|
||||
trackerList?: InfoTrackerListChunk;
|
||||
}
|
||||
export interface InfoPacketChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoPacketChunkData;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
|
||||
export interface InfoSystemNameChunk extends Chunk {
|
||||
system_name: string;
|
||||
export interface InfoSystemNameChunkData {
|
||||
systemName: string;
|
||||
}
|
||||
|
||||
export interface InfoSystemNameChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoSystemNameChunkData;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { InfoTrackerNameChunk } from './info-tracker-name-chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
import { InfoTrackerNameChunk } from './info-tracker-name-chunk.js';
|
||||
|
||||
export interface InfoTrackerChunk extends Chunk {
|
||||
tracker_name?: InfoTrackerNameChunk;
|
||||
export interface InfoTrackerChunkData {
|
||||
trackerName: InfoTrackerNameChunk;
|
||||
}
|
||||
|
||||
export interface InfoTrackerChunk {
|
||||
chunk: Chunk;
|
||||
data?: InfoTrackerChunkData;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { InfoTrackerChunk } from './info-tracker-chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
import { InfoTrackerChunk } from './info-tracker-chunk.js';
|
||||
|
||||
export interface InfoTrackerListChunk extends Chunk {
|
||||
trackers: {
|
||||
[key: number]: InfoTrackerChunk;
|
||||
};
|
||||
export interface InfoTrackerListChunkData {
|
||||
trackers: InfoTrackerChunk[];
|
||||
}
|
||||
|
||||
export interface InfoTrackerListChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerListChunkData;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { Chunk } from '../chunk.js';
|
||||
|
||||
export interface InfoTrackerNameChunk extends Chunk {
|
||||
tracker_name: string;
|
||||
export interface InfoTrackerNameChunkData {
|
||||
trackerName: string;
|
||||
}
|
||||
|
||||
export interface InfoTrackerNameChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerNameChunkData;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { Chunk } from './chunk';
|
||||
import { Chunk } from './chunk.js';
|
||||
|
||||
export interface PacketHeaderChunk extends Chunk {
|
||||
packet_timestamp?: bigint;
|
||||
version_high?: number;
|
||||
version_low?: number;
|
||||
frame_id?: number;
|
||||
frame_packet_count?: number;
|
||||
export interface PacketHeaderChunkData {
|
||||
packetTimestamp: bigint;
|
||||
versionHigh: number;
|
||||
versionLow: number;
|
||||
frameId: number;
|
||||
framePacketCount: number;
|
||||
}
|
||||
|
||||
export interface PacketHeaderChunk {
|
||||
chunk: Chunk;
|
||||
data: PacketHeaderChunkData;
|
||||
}
|
||||
|
||||
+147
-25
@@ -1,23 +1,31 @@
|
||||
import dataTrackerAccelChunk from '../encoders/data/data-tracker-accel-chunk';
|
||||
import dataTrackerChunk from '../encoders/data/data-tracker-chunk';
|
||||
import dataTrackerOriChunk from '../encoders/data/data-tracker-ori-chunk';
|
||||
import dataTrackerPosChunk from '../encoders/data/data-tracker-pos-chunk';
|
||||
import dataTrackerSpeedChunk from '../encoders/data/data-tracker-speed-chunk';
|
||||
import dataTrackerStatusChunk from '../encoders/data/data-tracker-status-chunk';
|
||||
import dataTrackerTimestampChunk from '../encoders/data/data-tracker-timestamp-chunk';
|
||||
import dataTrackerTrgtposChunk from '../encoders/data/data-tracker-trgtpos-chunk';
|
||||
import infoTrackerChunk from '../encoders/info/info-tracker-chunk';
|
||||
import infoTrackerNameChunk from '../encoders/info/info-tracker-name-chunk';
|
||||
import dataTrackerAccelChunk from '../encoders/data/data-tracker-accel-chunk.js';
|
||||
import dataTrackerChunk from '../encoders/data/data-tracker-chunk.js';
|
||||
import dataTrackerOriChunk from '../encoders/data/data-tracker-ori-chunk.js';
|
||||
import dataTrackerPosChunk from '../encoders/data/data-tracker-pos-chunk.js';
|
||||
import dataTrackerSpeedChunk from '../encoders/data/data-tracker-speed-chunk.js';
|
||||
import dataTrackerStatusChunk from '../encoders/data/data-tracker-status-chunk.js';
|
||||
import dataTrackerTimestampChunk from '../encoders/data/data-tracker-timestamp-chunk.js';
|
||||
import dataTrackerTrgtposChunk from '../encoders/data/data-tracker-trgtpos-chunk.js';
|
||||
import infoTrackerChunk from '../encoders/info/info-tracker-chunk.js';
|
||||
import infoTrackerNameChunk from '../encoders/info/info-tracker-name-chunk.js';
|
||||
import { DataTrackerChunk } from './data/data-tracker-chunk.js';
|
||||
import { InfoTrackerChunk } from './info/info-tracker-chunk.js';
|
||||
|
||||
export type XYZData = {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
|
||||
export class Tracker {
|
||||
id: number;
|
||||
name: string;
|
||||
pos?: [number, number, number];
|
||||
speed?: [number, number, number];
|
||||
ori?: [number, number, number];
|
||||
pos?: XYZData;
|
||||
speed?: XYZData;
|
||||
ori?: XYZData;
|
||||
validity?: number;
|
||||
accel?: [number, number, number];
|
||||
trgtpos?: [number, number, number];
|
||||
accel?: XYZData;
|
||||
trgtpos?: XYZData;
|
||||
timestamp?: bigint;
|
||||
|
||||
constructor(id: number, name: string) {
|
||||
@@ -33,15 +41,45 @@ export class Tracker {
|
||||
}
|
||||
|
||||
setPos(x: number, y: number, z: number) {
|
||||
this.pos = [x, y, z];
|
||||
if (this.pos === undefined) {
|
||||
this.pos = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.pos.x = x;
|
||||
this.pos.y = y;
|
||||
this.pos.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setSpeed(x: number, y: number, z: number) {
|
||||
this.speed = [x, y, z];
|
||||
if (this.speed === undefined) {
|
||||
this.speed = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.speed.x = x;
|
||||
this.speed.y = y;
|
||||
this.speed.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setOri(x: number, y: number, z: number) {
|
||||
this.ori = [x, y, z];
|
||||
if (this.ori === undefined) {
|
||||
this.ori = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.ori.x = x;
|
||||
this.ori.y = y;
|
||||
this.ori.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setStatus(validity: number) {
|
||||
@@ -49,11 +87,31 @@ export class Tracker {
|
||||
}
|
||||
|
||||
setAccel(x: number, y: number, z: number) {
|
||||
this.accel = [x, y, z];
|
||||
if (this.accel === undefined) {
|
||||
this.accel = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.accel.x = x;
|
||||
this.accel.y = y;
|
||||
this.accel.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setTrgtPos(x: number, y: number, z: number) {
|
||||
this.trgtpos = [x, y, z];
|
||||
if (this.trgtpos === undefined) {
|
||||
this.trgtpos = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.trgtpos.x = x;
|
||||
this.trgtpos.y = y;
|
||||
this.trgtpos.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setTimestamp(timestamp: bigint) {
|
||||
@@ -64,15 +122,15 @@ export class Tracker {
|
||||
const fieldChunks: Uint8Array[] = [];
|
||||
|
||||
if (this.pos) {
|
||||
fieldChunks.push(dataTrackerPosChunk(...this.pos));
|
||||
fieldChunks.push(dataTrackerPosChunk(this.pos.x, this.pos.y, this.pos.z));
|
||||
}
|
||||
|
||||
if (this.speed) {
|
||||
fieldChunks.push(dataTrackerSpeedChunk(...this.speed));
|
||||
fieldChunks.push(dataTrackerSpeedChunk(this.speed.x, this.speed.y, this.speed.z));
|
||||
}
|
||||
|
||||
if (this.ori) {
|
||||
fieldChunks.push(dataTrackerOriChunk(...this.ori));
|
||||
fieldChunks.push(dataTrackerOriChunk(this.ori.x, this.ori.y, this.ori.z));
|
||||
}
|
||||
|
||||
if (this.validity) {
|
||||
@@ -80,11 +138,11 @@ export class Tracker {
|
||||
}
|
||||
|
||||
if (this.accel) {
|
||||
fieldChunks.push(dataTrackerAccelChunk(...this.accel));
|
||||
fieldChunks.push(dataTrackerAccelChunk(this.accel.x, this.accel.y, this.accel.z));
|
||||
}
|
||||
|
||||
if (this.trgtpos) {
|
||||
fieldChunks.push(dataTrackerTrgtposChunk(...this.trgtpos));
|
||||
fieldChunks.push(dataTrackerTrgtposChunk(this.trgtpos.x, this.trgtpos.y, this.trgtpos.z));
|
||||
}
|
||||
|
||||
if (this.timestamp) {
|
||||
@@ -97,4 +155,68 @@ export class Tracker {
|
||||
getInfoChunk() {
|
||||
return infoTrackerChunk(this.id, infoTrackerNameChunk(this.name));
|
||||
}
|
||||
|
||||
updateInfo(infoTrackerChunk: InfoTrackerChunk) {
|
||||
if (infoTrackerChunk.data) {
|
||||
this.name = infoTrackerChunk.data.trackerName.data.trackerName;
|
||||
}
|
||||
}
|
||||
|
||||
updateData(dataTrackerChunk: DataTrackerChunk) {
|
||||
if (dataTrackerChunk.data.pos) {
|
||||
this.setPos(dataTrackerChunk.data.pos.data.x, dataTrackerChunk.data.pos.data.y, dataTrackerChunk.data.pos.data.z);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.speed) {
|
||||
this.setSpeed(
|
||||
dataTrackerChunk.data.speed.data.x,
|
||||
dataTrackerChunk.data.speed.data.y,
|
||||
dataTrackerChunk.data.speed.data.z
|
||||
);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.ori) {
|
||||
this.setOri(dataTrackerChunk.data.ori.data.x, dataTrackerChunk.data.ori.data.y, dataTrackerChunk.data.ori.data.z);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.status) {
|
||||
this.setStatus(dataTrackerChunk.data.status.data.validity);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.accel) {
|
||||
this.setAccel(
|
||||
dataTrackerChunk.data.accel.data.x,
|
||||
dataTrackerChunk.data.accel.data.y,
|
||||
dataTrackerChunk.data.accel.data.z
|
||||
);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.trgtpos) {
|
||||
this.setTrgtPos(
|
||||
dataTrackerChunk.data.trgtpos.data.x,
|
||||
dataTrackerChunk.data.trgtpos.data.y,
|
||||
dataTrackerChunk.data.trgtpos.data.z
|
||||
);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.timestamp) {
|
||||
this.setTimestamp(dataTrackerChunk.data.timestamp.data.timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function TrackerFromInfo(infoTrackerChunk: InfoTrackerChunk) {
|
||||
if (infoTrackerChunk.data) {
|
||||
return new Tracker(infoTrackerChunk.chunk.header.id, infoTrackerChunk.data.trackerName.data.trackerName);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function TrackerFromData(dataTrackerChunk: DataTrackerChunk) {
|
||||
if (dataTrackerChunk.data) {
|
||||
const tracker = new Tracker(dataTrackerChunk.chunk.header.id, '');
|
||||
tracker.updateData(dataTrackerChunk);
|
||||
return tracker;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,647 @@
|
||||
const { deepEqual, throws } = require('assert');
|
||||
const { describe, it } = require('node:test');
|
||||
const { Decoders } = require('../dist/cjs/decoders');
|
||||
|
||||
const goodTests = [
|
||||
{
|
||||
description: 'DataTrackerPosChunk',
|
||||
bytes: new Uint8Array([0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerXYZChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerSpeedChunk',
|
||||
bytes: new Uint8Array([1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 1, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerXYZChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerOriChunk',
|
||||
bytes: new Uint8Array([2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 2, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerXYZChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerStatusChunk',
|
||||
bytes: new Uint8Array([3, 0, 4, 0, 0, 0, 128, 63]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63]),
|
||||
header: { dataLen: 4, id: 3, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
validity: 1.0,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerStatusChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerAccelChunk',
|
||||
bytes: new Uint8Array([4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 4, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerXYZChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerTrgtPosChunk',
|
||||
bytes: new Uint8Array([5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 5, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerXYZChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerTimestampChunk',
|
||||
bytes: new Uint8Array([6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0]),
|
||||
header: { dataLen: 8, id: 6, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
timestamp: 1234567890n,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerTimestampChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerChunk',
|
||||
bytes: new Uint8Array([
|
||||
1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0,
|
||||
0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0, 0,
|
||||
128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2,
|
||||
150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([
|
||||
0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
|
||||
2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0, 0, 128, 63,
|
||||
0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2, 150, 73,
|
||||
0, 0, 0, 0,
|
||||
]),
|
||||
header: { dataLen: 100, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
pos: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
speed: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 1, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
ori: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 2, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
status: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63]),
|
||||
header: { dataLen: 4, id: 3, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
validity: 1.0,
|
||||
},
|
||||
},
|
||||
accel: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 4, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
trgtpos: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 5, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
timestamp: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0]),
|
||||
header: { dataLen: 8, id: 6, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
timestamp: 1234567890n,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerListChunk',
|
||||
bytes: new Uint8Array([
|
||||
1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63,
|
||||
0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0,
|
||||
12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8,
|
||||
0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([
|
||||
1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0,
|
||||
64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12,
|
||||
0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8,
|
||||
0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
header: { dataLen: 104, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
trackers: [
|
||||
{
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([
|
||||
0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0,
|
||||
64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0,
|
||||
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0,
|
||||
8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
header: { dataLen: 100, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
pos: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
speed: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 1, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
ori: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 2, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
status: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63]),
|
||||
header: { dataLen: 4, id: 3, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
validity: 1.0,
|
||||
},
|
||||
},
|
||||
accel: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 4, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
trgtpos: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 5, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
timestamp: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0]),
|
||||
header: { dataLen: 8, id: 6, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
timestamp: 1234567890n,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataTrackerListChunk,
|
||||
},
|
||||
{
|
||||
description: 'DataPacketChunk',
|
||||
bytes: new Uint8Array([
|
||||
85, 103, 124, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0,
|
||||
12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12,
|
||||
0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
|
||||
0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([
|
||||
0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0,
|
||||
128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 0,
|
||||
128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0,
|
||||
64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
header: { dataLen: 124, id: 26453, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
packetHeader: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
|
||||
header: { dataLen: 12, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
packetTimestamp: 1234567890n,
|
||||
versionHigh: 2,
|
||||
versionLow: 3,
|
||||
frameId: 1,
|
||||
framePacketCount: 123,
|
||||
},
|
||||
},
|
||||
trackerList: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([
|
||||
1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0,
|
||||
0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4,
|
||||
0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
|
||||
6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
header: { dataLen: 104, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
trackers: [
|
||||
{
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([
|
||||
0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0,
|
||||
0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0,
|
||||
12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64,
|
||||
64, 6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
header: { dataLen: 100, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
pos: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
speed: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 1, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
ori: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 2, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
status: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63]),
|
||||
header: { dataLen: 4, id: 3, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
validity: 1.0,
|
||||
},
|
||||
},
|
||||
accel: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 4, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
trgtpos: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
header: { dataLen: 12, id: 5, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0,
|
||||
},
|
||||
},
|
||||
timestamp: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0]),
|
||||
header: { dataLen: 8, id: 6, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
timestamp: 1234567890n,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
decoder: Decoders.DataPacketChunk,
|
||||
},
|
||||
{
|
||||
description: 'InfoTrackerNameChunk',
|
||||
bytes: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 9, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
trackerName: 'Tracker 1',
|
||||
},
|
||||
},
|
||||
decoder: Decoders.InfoTrackerNameChunk,
|
||||
},
|
||||
{
|
||||
description: 'InfoSystemNameChunk',
|
||||
bytes: new Uint8Array([1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([80, 83, 78, 32, 83, 101, 114, 118, 101, 114]),
|
||||
header: { dataLen: 10, id: 1, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
systemName: 'PSN Server',
|
||||
},
|
||||
},
|
||||
decoder: Decoders.InfoSystemNameChunk,
|
||||
},
|
||||
{
|
||||
description: 'InfoTrackerChunk',
|
||||
bytes: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 13, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
trackerName: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 9, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
trackerName: 'Tracker 1',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
decoder: Decoders.InfoTrackerChunk,
|
||||
},
|
||||
{
|
||||
description: 'InfoTrackerListChunk',
|
||||
bytes: new Uint8Array([2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 17, id: 2, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
trackers: [
|
||||
{
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 13, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
trackerName: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 9, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
trackerName: 'Tracker 1',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
decoder: Decoders.InfoTrackerListChunk,
|
||||
},
|
||||
{
|
||||
description: 'PacketHeaderChunk',
|
||||
bytes: new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
|
||||
header: { dataLen: 12, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
packetTimestamp: 1234567890n,
|
||||
versionHigh: 2,
|
||||
versionLow: 3,
|
||||
frameId: 1,
|
||||
framePacketCount: 123,
|
||||
},
|
||||
},
|
||||
decoder: Decoders.PacketHeaderChunk,
|
||||
},
|
||||
{
|
||||
description: 'InfoPacketChunk',
|
||||
bytes: new Uint8Array([
|
||||
86, 103, 51, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 10, 0, 80, 83, 78, 32, 83, 101,
|
||||
114, 118, 101, 114, 2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
|
||||
]),
|
||||
expected: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([
|
||||
0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101,
|
||||
114, 2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
|
||||
]),
|
||||
header: { dataLen: 51, id: 26454, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
packetHeader: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
|
||||
header: { dataLen: 12, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
packetTimestamp: 1234567890n,
|
||||
versionHigh: 2,
|
||||
versionLow: 3,
|
||||
frameId: 1,
|
||||
framePacketCount: 123,
|
||||
},
|
||||
},
|
||||
systemName: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([80, 83, 78, 32, 83, 101, 114, 118, 101, 114]),
|
||||
header: { dataLen: 10, id: 1, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
systemName: 'PSN Server',
|
||||
},
|
||||
},
|
||||
trackerList: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 17, id: 2, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
trackers: [
|
||||
{
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 13, id: 1, hasSubchunks: true },
|
||||
},
|
||||
data: {
|
||||
trackerName: {
|
||||
chunk: {
|
||||
chunkData: new Uint8Array([84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
header: { dataLen: 9, id: 0, hasSubchunks: false },
|
||||
},
|
||||
data: {
|
||||
trackerName: 'Tracker 1',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
decoder: Decoders.InfoPacketChunk,
|
||||
},
|
||||
];
|
||||
|
||||
describe('PSN Bytes Decoding', () => {
|
||||
goodTests.forEach((bytesTest) => {
|
||||
it(bytesTest.description, () => {
|
||||
const decoded = bytesTest.decoder(bytesTest.bytes);
|
||||
deepEqual(decoded, bytesTest.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// TODO(jwetzell): add error tests
|
||||
const badTests = [];
|
||||
describe('PSN Bytes Decoding Throws', () => {
|
||||
badTests.forEach((bytesTest) => {
|
||||
it(bytesTest.description, () => {
|
||||
throws(() => {
|
||||
bytesTest.decoder(bytesTest.bytes);
|
||||
}, bytesTest.throwsMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,152 @@
|
||||
const { deepEqual, throws, equal } = require('assert');
|
||||
const { describe, it } = require('node:test');
|
||||
const { Encoders } = require('../dist/cjs/encoders');
|
||||
|
||||
const goodTests = [
|
||||
{
|
||||
description: 'DataTrackerPosChunk',
|
||||
expected: new Uint8Array([0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
bytes: Encoders.DataTrackerPosChunk(1.0, 2.0, 3.0),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerSpeedChunk',
|
||||
expected: new Uint8Array([1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
bytes: Encoders.DataTrackerSpeedChunk(1.0, 2.0, 3.0),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerOriChunk',
|
||||
expected: new Uint8Array([2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
bytes: Encoders.DataTrackerOriChunk(1.0, 2.0, 3.0),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerStatusChunk',
|
||||
expected: new Uint8Array([3, 0, 4, 0, 0, 0, 128, 63]),
|
||||
bytes: Encoders.DataTrackerStatusChunk(1.0),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerAccelChunk',
|
||||
expected: new Uint8Array([4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
bytes: Encoders.DataTrackerAccelChunk(1.0, 2.0, 3.0),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerTrgtposChunk',
|
||||
expected: new Uint8Array([5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
bytes: Encoders.DataTrackerTrgtposChunk(1.0, 2.0, 3.0),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerTimestampChunk',
|
||||
expected: new Uint8Array([6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0]),
|
||||
bytes: Encoders.DataTrackerTimestampChunk(1234567890n),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerChunk',
|
||||
expected: new Uint8Array([
|
||||
1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0,
|
||||
0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0, 0,
|
||||
128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2,
|
||||
150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
bytes: Encoders.DataTrackerChunk(1, [
|
||||
new Uint8Array([0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
new Uint8Array([1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
new Uint8Array([2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
new Uint8Array([3, 0, 4, 0, 0, 0, 128, 63]),
|
||||
new Uint8Array([4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
new Uint8Array([5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
|
||||
new Uint8Array([6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0]),
|
||||
]),
|
||||
},
|
||||
{
|
||||
description: 'DataTrackerListChunk',
|
||||
expected: new Uint8Array([
|
||||
1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63,
|
||||
0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0,
|
||||
12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8,
|
||||
0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
bytes: Encoders.DataTrackerListChunk([
|
||||
new Uint8Array([
|
||||
1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
|
||||
0, 0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0,
|
||||
0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210,
|
||||
2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
]),
|
||||
},
|
||||
{
|
||||
description: 'DataPacketChunk',
|
||||
expected: new Uint8Array([
|
||||
85, 103, 124, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0,
|
||||
12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12,
|
||||
0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
|
||||
0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
]),
|
||||
bytes: Encoders.DataPacketChunk(
|
||||
new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
|
||||
new Uint8Array([
|
||||
1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128,
|
||||
63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63,
|
||||
4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6,
|
||||
0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
|
||||
])
|
||||
),
|
||||
},
|
||||
{
|
||||
description: 'InfoTrackerNameChunk',
|
||||
expected: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
bytes: Encoders.InfoTrackerNameChunk('Tracker 1'),
|
||||
},
|
||||
{
|
||||
description: 'InfoSystemNameChunk',
|
||||
expected: new Uint8Array([1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114]),
|
||||
bytes: Encoders.InfoSystemNameChunk('PSN Server'),
|
||||
},
|
||||
{
|
||||
description: 'InfoTrackerChunk',
|
||||
expected: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
bytes: Encoders.InfoTrackerChunk(1, new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49])),
|
||||
},
|
||||
{
|
||||
description: 'InfoTrackerListChunk',
|
||||
expected: new Uint8Array([2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
bytes: Encoders.InfoTrackerListChunk([
|
||||
new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]),
|
||||
]),
|
||||
},
|
||||
{
|
||||
description: 'PacketHeaderChunk',
|
||||
expected: new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
|
||||
bytes: Encoders.PacketHeaderChunk(1234567890n, 2, 3, 1, 123),
|
||||
},
|
||||
{
|
||||
description: 'InfoPacketChunk',
|
||||
expected: new Uint8Array([
|
||||
86, 103, 51, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 10, 0, 80, 83, 78, 32, 83, 101,
|
||||
114, 118, 101, 114, 2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
|
||||
]),
|
||||
bytes: Encoders.InfoPacketChunk(
|
||||
new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
|
||||
new Uint8Array([1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114]),
|
||||
new Uint8Array([2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49])
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
describe('PSN Message Encoding', () => {
|
||||
goodTests.forEach((messageTest) => {
|
||||
it(messageTest.description, () => {
|
||||
deepEqual(messageTest.bytes, messageTest.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//TODO(jwetzell): add tests that handle errors
|
||||
const badTests = [];
|
||||
|
||||
describe('PSN Message Encoding Throws', () => {
|
||||
badTests.forEach((messageTest) => {
|
||||
it(messageTest.description, () => {
|
||||
throws(() => {}, messageTest.throwsMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"declaration": false,
|
||||
"outDir": "./dist/cjs"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"declaration": false,
|
||||
"outDir": "./dist/esm"
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "Node",
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"esModuleInterop": true,
|
||||
"module": "commonjs",
|
||||
"target": "ES2020",
|
||||
"declaration": true,
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"outDir": "dist"
|
||||
"isolatedModules": true,
|
||||
"rootDir": "src/",
|
||||
"strict": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist", "examples"]
|
||||
"include": ["src/"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"emitDeclarationOnly": true,
|
||||
"declaration": true,
|
||||
"outDir": "./dist/types"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user