mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-17 13:23:43 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f6ebece34 |
@@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
node: true,
|
||||
commonjs: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: ['airbnb', 'prettier'],
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
},
|
||||
ignorePatterns: ['**/node_modules', '**/dist'],
|
||||
};
|
||||
@@ -4,6 +4,3 @@ 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:
|
||||
build-webui:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
|
||||
@@ -22,3 +22,5 @@ jobs:
|
||||
|
||||
- name: Publish to NPM
|
||||
run: npm publish --provenance --access=public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
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
|
||||
@@ -28,7 +28,7 @@ decoder.decode(infoPacketBuffer)
|
||||
decoder.decode(dataPacketBuffer)
|
||||
|
||||
// the system_name from info packets if available
|
||||
console.log(decoder.systemName)
|
||||
console.log(decoder.system_name)
|
||||
|
||||
// map of trackers populated with any data that has been received
|
||||
// this merges both info and data packet properties into one
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
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,
|
||||
];
|
||||
Generated
+3123
-1435
File diff suppressed because it is too large
Load Diff
+21
-24
@@ -1,28 +1,29 @@
|
||||
{
|
||||
"name": "@jwetzell/posistagenet",
|
||||
"version": "2.1.2",
|
||||
"version": "2.0.0",
|
||||
"description": "",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.cts",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
"import": "./dist/esm/index.js",
|
||||
"require": "./dist/cjs/index.js",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist",
|
||||
"build": "tsdown",
|
||||
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
||||
"build:cjs": "tsc -p tsconfig.cjs.json",
|
||||
"build:esm": "tsc -p tsconfig.esm.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",
|
||||
"lint:check": "eslint ./src",
|
||||
"lint:check": "eslint ./",
|
||||
"format:check": "prettier ./ --check",
|
||||
"format:write": "prettier ./ --write",
|
||||
"pretest": "npm run build",
|
||||
"test": "node --test --experimental-test-coverage"
|
||||
"format:write": "prettier ./ --write"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
@@ -35,16 +36,12 @@
|
||||
"repository": "https://github.com/jwetzell/psn-js",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "10.0.1",
|
||||
"@types/node": "24.7.2",
|
||||
"eslint": "10.5.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-prettier": "5.5.6",
|
||||
"globals": "17.6.0",
|
||||
"prettier": "3.8.4",
|
||||
"rimraf": "6.1.3",
|
||||
"tsdown": "0.22.2",
|
||||
"typescript": "6.0.3",
|
||||
"typescript-eslint": "8.61.0"
|
||||
"@types/node": "22.10.2",
|
||||
"prettier": "3.4.2",
|
||||
"rimraf": "6.0.1",
|
||||
"typescript": "5.7.2",
|
||||
"eslint": "8.48.0",
|
||||
"eslint-config-airbnb": "19.0.4",
|
||||
"eslint-config-prettier": "9.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-8
@@ -1,11 +1,5 @@
|
||||
import { Decoders } from './index.js';
|
||||
import {
|
||||
type DataPacketChunk,
|
||||
type InfoPacketChunk,
|
||||
Tracker,
|
||||
TrackerFromData,
|
||||
TrackerFromInfo,
|
||||
} from './models/index.js';
|
||||
import { Decoders } from '.';
|
||||
import { DataPacketChunk, InfoPacketChunk, Tracker, TrackerFromData, TrackerFromInfo } from './models';
|
||||
|
||||
export class Decoder {
|
||||
infoPacketFrames: { [key: number]: InfoPacketChunk[] } = {};
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { Chunk } from '../models/chunk.js';
|
||||
import { Chunk } from '../models/chunk';
|
||||
|
||||
export default (buffer: Uint8Array): Chunk => {
|
||||
if (buffer.length < 4) {
|
||||
throw new Error('Chunk buffer must be at least 4 bytes');
|
||||
}
|
||||
let offset = 0;
|
||||
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
||||
const id = view.getUint16(offset, true);
|
||||
offset += 2;
|
||||
|
||||
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];
|
||||
// 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);
|
||||
const hasSubchunks = combinedLengthAndFlag > 32768;
|
||||
const dataLen = hasSubchunks ? combinedLengthAndFlag - 32768 : combinedLengthAndFlag;
|
||||
offset += 2;
|
||||
|
||||
const header = {
|
||||
id,
|
||||
@@ -18,7 +18,7 @@ export default (buffer: Uint8Array): Chunk => {
|
||||
hasSubchunks,
|
||||
};
|
||||
|
||||
const chunkData = buffer.subarray(4, 4 + header.dataLen);
|
||||
const chunkData = buffer.subarray(offset, offset + header.dataLen);
|
||||
|
||||
const chunk = {
|
||||
chunkData,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Constants } from '../../constants.js';
|
||||
import type { DataPacketChunk, DataPacketChunkData } from '../../models/data/data-packet-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { DataPacketChunk, DataPacketChunkData } from '../../models/data/data-packet-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): DataPacketChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
@@ -10,7 +10,8 @@ export default (buffer: Uint8Array): DataPacketChunk => {
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Constants } from '../../constants.js';
|
||||
import type { DataTrackerChunk, DataTrackerChunkData } from '../../models/data/data-tracker-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { DataTrackerChunk, DataTrackerChunkData } from '../../models/data/data-tracker-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Constants } from '../../constants.js';
|
||||
import type { DataTrackerListChunk, DataTrackerListChunkData } from '../../models/data/data-tracker-list-chunk.js';
|
||||
import type { DataTrackerChunk } from '../../models/index.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { DataTrackerChunk } from '../../models';
|
||||
import { DataTrackerListChunk, DataTrackerListChunkData } from '../../models/data/data-tracker-list-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerListChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type {
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerStatusChunkData,
|
||||
} from '../../models/data/data-tracker-status-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
/* eslint-disable no-case-declarations */
|
||||
|
||||
import { Decoders } from '..';
|
||||
import { DataTrackerStatusChunk, DataTrackerStatusChunkData } from '../../models/data/data-tracker-status-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerStatusChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import type {
|
||||
/* eslint-disable no-case-declarations */
|
||||
|
||||
import { Decoders } from '..';
|
||||
import {
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerTimestampChunkData,
|
||||
} from '../../models/data/data-tracker-timestamp-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
} from '../../models/data/data-tracker-timestamp-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerTimestampChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { DataTrackerXYZChunk, DataTrackerXYZChunkData } from '../../models/data/data-tracker-xyz-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { DataTrackerXYZChunk, DataTrackerXYZChunkData } from '../../models/data/data-tracker-xyz-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerXYZChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
+15
-13
@@ -1,22 +1,24 @@
|
||||
import Chunk from './chunk.js';
|
||||
import PacketHeaderChunk from './packet-header-chunk.js';
|
||||
import Chunk from './chunk';
|
||||
import Packet from './packet';
|
||||
import PacketHeaderChunk from './packet-header-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 DataPacketChunk from './data/data-packet-chunk';
|
||||
import DataTrackerChunk from './data/data-tracker-chunk';
|
||||
import DataTrackerListChunk from './data/data-tracker-list-chunk';
|
||||
import DataTrackerStatusChunk from './data/data-tracker-status-chunk';
|
||||
import DataTrackerTimestampChunk from './data/data-tracker-timestamp-chunk';
|
||||
import DataTrackerXYZChunk from './data/data-tracker-xyz-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';
|
||||
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';
|
||||
|
||||
export const Decoders = {
|
||||
Chunk,
|
||||
PacketHeaderChunk,
|
||||
Packet,
|
||||
DataPacketChunk,
|
||||
DataTrackerChunk,
|
||||
DataTrackerXYZChunk,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Constants } from '../../constants.js';
|
||||
import type { InfoPacketChunk, InfoPacketChunkData } from '../../models/info/info-packet-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoPacketChunk, InfoPacketChunkData } from '../../models/info/info-packet-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): InfoPacketChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
@@ -10,7 +10,8 @@ export default (buffer: Uint8Array): InfoPacketChunk => {
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset));
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import type { InfoSystemNameChunk, InfoSystemNameChunkData } from '../../models/info/info-system-name-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { InfoSystemNameChunk, InfoSystemNameChunkData } from '../../models/info/info-system-name-chunk';
|
||||
|
||||
const nameDecoder = new TextDecoder();
|
||||
export default (buffer: Uint8Array): InfoSystemNameChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoSystemNameChunkData = {
|
||||
systemName: nameDecoder.decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
systemName: new TextDecoder().decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Constants } from '../../constants.js';
|
||||
import type { InfoTrackerChunk, InfoTrackerChunkData } from '../../models/info/info-tracker-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoTrackerChunk, InfoTrackerChunkData } from '../../models/info/info-tracker-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): InfoTrackerChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
@@ -8,9 +8,10 @@ export default (buffer: Uint8Array): InfoTrackerChunk => {
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
switch (chunkId) {
|
||||
case 0x0000: {
|
||||
case 0x0000:
|
||||
const data: InfoTrackerChunkData = {
|
||||
trackerName: Decoders.InfoTrackerNameChunk(chunk.chunkData.subarray(offset)),
|
||||
};
|
||||
@@ -22,7 +23,7 @@ export default (buffer: Uint8Array): InfoTrackerChunk => {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Constants } from '../../constants.js';
|
||||
import type { InfoTrackerChunk } from '../../models/info/info-tracker-chunk.js';
|
||||
import type { InfoTrackerListChunk, InfoTrackerListChunkData } from '../../models/info/info-tracker-list-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoTrackerChunk } from '../../models/info/info-tracker-chunk';
|
||||
import { InfoTrackerListChunk, InfoTrackerListChunkData } from '../../models/info/info-tracker-list-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): InfoTrackerListChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import type { InfoTrackerNameChunk, InfoTrackerNameChunkData } from '../../models/info/info-tracker-name-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
import { Decoders } from '..';
|
||||
import { InfoTrackerNameChunk, InfoTrackerNameChunkData } from '../../models/info/info-tracker-name-chunk';
|
||||
|
||||
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)),
|
||||
trackerName: new TextDecoder().decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
import type { PacketHeaderChunk, PacketHeaderChunkData } from '../models/packet-header-chunk.js';
|
||||
import { Decoders } from './index.js';
|
||||
import { Decoders } from '.';
|
||||
import { PacketHeaderChunk, PacketHeaderChunkData } from '../models/packet-header-chunk';
|
||||
|
||||
export default (buffer: Uint8Array): PacketHeaderChunk => {
|
||||
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 view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const data: PacketHeaderChunkData = {
|
||||
packetTimestamp,
|
||||
packetTimestamp: view.getBigUint64(0, true),
|
||||
versionHigh: chunk.chunkData[8],
|
||||
versionLow: chunk.chunkData[9],
|
||||
frameId: chunk.chunkData[10],
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
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 { Constants } from './constants.js';
|
||||
import { Encoders, Tracker } from './index.js';
|
||||
import { Encoders, Tracker } from '.';
|
||||
import { Constants } from './constants';
|
||||
|
||||
export class Encoder {
|
||||
private systemName: string;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
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');
|
||||
@@ -12,6 +11,7 @@ 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.js';
|
||||
import chunk from '../chunk';
|
||||
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.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0004, new Uint8Array(floatArray.buffer), false);
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerId: number, fieldChunks: Uint8Array[]): Uint8Array => {
|
||||
let fieldChunksTotalLength = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerChunks: Uint8Array[]) => {
|
||||
let trackerChunksTotalLength = 0;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0002, new Uint8Array(floatArray.buffer), false);
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
|
||||
return chunk(0x0000, new Uint8Array(floatArray.buffer), false);
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
|
||||
return chunk(0x0000, new Uint8Array(buf.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
|
||||
return chunk(0x0001, new Uint8Array(floatArray.buffer), false);
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
|
||||
return chunk(0x0001, new Uint8Array(buf.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
const floatArray = new Float32Array(1);
|
||||
export default (validity: number): Uint8Array => {
|
||||
floatArray[0] = validity;
|
||||
return chunk(0x0003, new Uint8Array(floatArray.buffer), false);
|
||||
const buf = new DataView(new ArrayBuffer(4));
|
||||
buf.setFloat32(0, validity, true);
|
||||
return chunk(0x0003, new Uint8Array(buf.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
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,10 +1,11 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
const buf = new DataView(new ArrayBuffer(12));
|
||||
|
||||
return chunk(0x0005, new Uint8Array(floatArray.buffer), false);
|
||||
buf.setFloat32(0, x, true);
|
||||
buf.setFloat32(4, y, true);
|
||||
buf.setFloat32(8, z, true);
|
||||
|
||||
return chunk(0x0005, new Uint8Array(buf.buffer), false);
|
||||
};
|
||||
|
||||
+17
-17
@@ -1,21 +1,21 @@
|
||||
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 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 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';
|
||||
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';
|
||||
|
||||
export const Encoders = {
|
||||
DataPacketChunk,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (
|
||||
packetHeaderChunk: Uint8Array,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import chunk from '../chunk.js';
|
||||
const nameEncoder = new TextEncoder();
|
||||
export default (systemName: string): Uint8Array => chunk(0x0001, nameEncoder.encode(systemName), false);
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (systemName: string): Uint8Array => chunk(0x0001, new TextEncoder().encode(systemName), false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerId: number, trackerNameChunk: Uint8Array): Uint8Array =>
|
||||
chunk(trackerId, trackerNameChunk, true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerChunks: Uint8Array[]): Uint8Array => {
|
||||
let trackerChunksTotalLength = 0;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import chunk from '../chunk.js';
|
||||
import chunk from '../chunk';
|
||||
|
||||
const nameEncoder = new TextEncoder();
|
||||
export default (trackerName: string) => chunk(0x0000, nameEncoder.encode(trackerName), false);
|
||||
export default (trackerName: string) => chunk(0x0000, new TextEncoder().encode(trackerName), false);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import chunk from './chunk.js';
|
||||
import chunk from './chunk';
|
||||
|
||||
const packetHeader = new DataView(new ArrayBuffer(12));
|
||||
export default (
|
||||
timestamp: bigint,
|
||||
versionHigh: number,
|
||||
@@ -34,6 +33,7 @@ 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.js';
|
||||
export * from './decoders/index.js';
|
||||
export { Encoder } from './encoder.js';
|
||||
export * from './encoders/index.js';
|
||||
export * from './models/index.js';
|
||||
export { Decoder } from './decoder';
|
||||
export * from './decoders';
|
||||
export { Encoder } from './encoder';
|
||||
export * from './encoders';
|
||||
export * from './models';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import type { PacketHeaderChunk } from '../packet-header-chunk.js';
|
||||
import type { DataTrackerListChunk } from './data-tracker-list-chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
import { PacketHeaderChunk } from '../packet-header-chunk';
|
||||
import { DataTrackerListChunk } from './data-tracker-list-chunk';
|
||||
|
||||
export interface DataPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import type { DataTrackerStatusChunk } from './data-tracker-status-chunk.js';
|
||||
import type { DataTrackerTimestampChunk } from './data-tracker-timestamp-chunk.js';
|
||||
import type { DataTrackerXYZChunk } from './data-tracker-xyz-chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
import { DataTrackerStatusChunk } from './data-tracker-status-chunk';
|
||||
import { DataTrackerTimestampChunk } from './data-tracker-timestamp-chunk';
|
||||
import { DataTrackerXYZChunk } from './data-tracker-xyz-chunk';
|
||||
|
||||
export interface DataTrackerChunkData {
|
||||
pos?: DataTrackerXYZChunk;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import type { DataTrackerChunk } from './data-tracker-chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
import { DataTrackerChunk } from './data-tracker-chunk';
|
||||
|
||||
export interface DataTrackerListChunkData {
|
||||
trackers: DataTrackerChunk[];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerStatusChunkData {
|
||||
validity: number;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerTimestampChunkData {
|
||||
timestamp: bigint;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerXYZChunkData {
|
||||
x: number;
|
||||
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
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';
|
||||
export * from './chunk';
|
||||
export * from './data/data-packet-chunk';
|
||||
export * from './data/data-tracker-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';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import type { PacketHeaderChunk } from '../packet-header-chunk.js';
|
||||
import type { InfoSystemNameChunk } from './info-system-name-chunk.js';
|
||||
import type { InfoTrackerListChunk } from './info-tracker-list-chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
import { PacketHeaderChunk } from '../packet-header-chunk';
|
||||
import { InfoSystemNameChunk } from './info-system-name-chunk';
|
||||
import { InfoTrackerListChunk } from './info-tracker-list-chunk';
|
||||
|
||||
export interface InfoPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface InfoSystemNameChunkData {
|
||||
systemName: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import type { InfoTrackerNameChunk } from './info-tracker-name-chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
import { InfoTrackerNameChunk } from './info-tracker-name-chunk';
|
||||
|
||||
export interface InfoTrackerChunkData {
|
||||
trackerName: InfoTrackerNameChunk;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import type { InfoTrackerChunk } from './info-tracker-chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
import { InfoTrackerChunk } from './info-tracker-chunk';
|
||||
|
||||
export interface InfoTrackerListChunkData {
|
||||
trackers: InfoTrackerChunk[];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface InfoTrackerNameChunkData {
|
||||
trackerName: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Chunk } from './chunk.js';
|
||||
import { Chunk } from './chunk';
|
||||
|
||||
export interface PacketHeaderChunkData {
|
||||
packetTimestamp: bigint;
|
||||
|
||||
+12
-12
@@ -1,15 +1,15 @@
|
||||
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 type { DataTrackerChunk } from './data/data-tracker-chunk.js';
|
||||
import type { InfoTrackerChunk } from './info/info-tracker-chunk.js';
|
||||
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 { DataTrackerChunk } from './data/data-tracker-chunk';
|
||||
import { InfoTrackerChunk } from './info/info-tracker-chunk';
|
||||
|
||||
export type XYZData = {
|
||||
x: number;
|
||||
|
||||
@@ -1,647 +0,0 @@
|
||||
import { Decoders } from '@jwetzell/posistagenet';
|
||||
import { deepEqual, throws } from 'assert';
|
||||
import { describe, it } from 'node:test';
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,152 +0,0 @@
|
||||
import { Encoders } from '@jwetzell/posistagenet';
|
||||
import { deepEqual, throws } from 'assert';
|
||||
import { describe, it } from 'node:test';
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
+6
-14
@@ -1,20 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"lib": ["es2023"],
|
||||
"moduleDetection": "force",
|
||||
"module": "preserve",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"types": ["node"],
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"moduleResolution": "Node",
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"skipLibCheck": true
|
||||
"rootDir": "src/",
|
||||
"strict": true
|
||||
},
|
||||
"include": ["src"]
|
||||
"include": ["src/"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"emitDeclarationOnly": true,
|
||||
"declaration": true,
|
||||
"outDir": "./dist/types"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { defineConfig } from 'tsdown'
|
||||
|
||||
export default defineConfig({
|
||||
entry: 'src/index.ts',
|
||||
exports: true,
|
||||
format: {
|
||||
esm: {},
|
||||
cjs: {},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user