28 Commits

Author SHA1 Message Date
Joel Wetzell 8e98be1611 Merge pull request #260 from jwetzell/dependabot/npm_and_yarn/biomejs/biome-2.5.7
Bump @biomejs/biome from 2.5.6 to 2.5.7
2026-08-12 08:14:26 -05:00
Joel Wetzell 30d8263c14 Merge pull request #261 from jwetzell/dependabot/npm_and_yarn/globals-17.9.0
Bump globals from 17.8.0 to 17.9.0
2026-08-12 08:13:37 -05:00
dependabot[bot] 0ea5d443bc Bump globals from 17.8.0 to 17.9.0
Bumps [globals](https://github.com/sindresorhus/globals) from 17.8.0 to 17.9.0.
- [Release notes](https://github.com/sindresorhus/globals/releases)
- [Commits](https://github.com/sindresorhus/globals/compare/v17.8.0...v17.9.0)

---
updated-dependencies:
- dependency-name: globals
  dependency-version: 17.9.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-10 12:33:32 +00:00
dependabot[bot] 878130bef5 Bump @biomejs/biome from 2.5.6 to 2.5.7
Bumps [@biomejs/biome](https://github.com/biomejs/biome/tree/HEAD/packages/@biomejs/biome) from 2.5.6 to 2.5.7.
- [Release notes](https://github.com/biomejs/biome/releases)
- [Changelog](https://github.com/biomejs/biome/blob/main/packages/@biomejs/biome/CHANGELOG.md)
- [Commits](https://github.com/biomejs/biome/commits/@biomejs/biome@2.5.7/packages/@biomejs/biome)

---
updated-dependencies:
- dependency-name: "@biomejs/biome"
  dependency-version: 2.5.7
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-10 12:33:27 +00:00
Joel Wetzell 07194e10af Merge pull request #259 from jwetzell/dependabot/npm_and_yarn/biomejs/biome-2.5.6
Bump @biomejs/biome from 2.5.5 to 2.5.6
2026-08-06 08:16:25 -05:00
dependabot[bot] e29a118099 Bump @biomejs/biome from 2.5.5 to 2.5.6
Bumps [@biomejs/biome](https://github.com/biomejs/biome/tree/HEAD/packages/@biomejs/biome) from 2.5.5 to 2.5.6.
- [Release notes](https://github.com/biomejs/biome/releases)
- [Changelog](https://github.com/biomejs/biome/blob/main/packages/@biomejs/biome/CHANGELOG.md)
- [Commits](https://github.com/biomejs/biome/commits/@biomejs/biome@2.5.6/packages/@biomejs/biome)

---
updated-dependencies:
- dependency-name: "@biomejs/biome"
  dependency-version: 2.5.6
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-03 12:33:31 +00:00
Joel Wetzell 96fbd165c1 Merge pull request #256 from jwetzell/dependabot/npm_and_yarn/tsdown-0.22.14
Bump tsdown from 0.22.7 to 0.22.14
2026-07-29 08:34:21 -05:00
Joel Wetzell 886f37c6fd Merge pull request #257 from jwetzell/dependabot/npm_and_yarn/globals-17.8.0
Bump globals from 17.7.0 to 17.8.0
2026-07-29 08:34:09 -05:00
Joel Wetzell e46b87e330 Merge pull request #258 from jwetzell/dependabot/npm_and_yarn/biomejs/biome-2.5.5
Bump @biomejs/biome from 2.5.3 to 2.5.5
2026-07-29 08:33:35 -05:00
dependabot[bot] 5e3c68a343 Bump @biomejs/biome from 2.5.3 to 2.5.5
Bumps [@biomejs/biome](https://github.com/biomejs/biome/tree/HEAD/packages/@biomejs/biome) from 2.5.3 to 2.5.5.
- [Release notes](https://github.com/biomejs/biome/releases)
- [Changelog](https://github.com/biomejs/biome/blob/main/packages/@biomejs/biome/CHANGELOG.md)
- [Commits](https://github.com/biomejs/biome/commits/@biomejs/biome@2.5.5/packages/@biomejs/biome)

---
updated-dependencies:
- dependency-name: "@biomejs/biome"
  dependency-version: 2.5.5
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-27 12:33:36 +00:00
dependabot[bot] 8342f6dd31 Bump globals from 17.7.0 to 17.8.0
Bumps [globals](https://github.com/sindresorhus/globals) from 17.7.0 to 17.8.0.
- [Release notes](https://github.com/sindresorhus/globals/releases)
- [Commits](https://github.com/sindresorhus/globals/compare/v17.7.0...v17.8.0)

---
updated-dependencies:
- dependency-name: globals
  dependency-version: 17.8.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-27 12:33:30 +00:00
dependabot[bot] b0e2e37ba3 Bump tsdown from 0.22.7 to 0.22.14
Bumps [tsdown](https://github.com/rolldown/tsdown) from 0.22.7 to 0.22.14.
- [Release notes](https://github.com/rolldown/tsdown/releases)
- [Commits](https://github.com/rolldown/tsdown/compare/v0.22.7...v0.22.14)

---
updated-dependencies:
- dependency-name: tsdown
  dependency-version: 0.22.14
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-27 12:33:23 +00:00
Joel Wetzell 302d8ab407 Merge pull request #251 from jwetzell/dependabot/npm_and_yarn/typescript-7.0.2
Bump typescript from 6.0.3 to 7.0.2
2026-07-13 14:16:19 -05:00
Joel Wetzell 68db557090 linting 2026-07-13 14:15:47 -05:00
dependabot[bot] 899ae4a3a1 Bump typescript from 6.0.3 to 7.0.2
Bumps [typescript](https://github.com/microsoft/TypeScript) from 6.0.3 to 7.0.2.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Commits](https://github.com/microsoft/TypeScript/commits)

---
updated-dependencies:
- dependency-name: typescript
  dependency-version: 7.0.2
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-13 19:11:57 +00:00
Joel Wetzell 466228fb4a format 2026-07-13 14:09:21 -05:00
Joel Wetzell 4bb1e87e03 switch to biome 2026-07-13 14:05:42 -05:00
Joel Wetzell fbe6c5bdab update typescript-eslint 2026-07-13 13:53:15 -05:00
Joel Wetzell 3ddb33d65b Merge pull request #247 from jwetzell/dependabot/npm_and_yarn/globals-17.7.0
Bump globals from 17.6.0 to 17.7.0
2026-07-13 13:51:00 -05:00
dependabot[bot] 7fa6a17caf Bump globals from 17.6.0 to 17.7.0
Bumps [globals](https://github.com/sindresorhus/globals) from 17.6.0 to 17.7.0.
- [Release notes](https://github.com/sindresorhus/globals/releases)
- [Commits](https://github.com/sindresorhus/globals/compare/v17.6.0...v17.7.0)

---
updated-dependencies:
- dependency-name: globals
  dependency-version: 17.7.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-13 18:30:47 +00:00
Joel Wetzell 57946b4d44 Merge pull request #250 from jwetzell/dependabot/npm_and_yarn/prettier-3.9.5
Bump prettier from 3.8.4 to 3.9.5
2026-07-13 13:30:10 -05:00
Joel Wetzell 824b2640ec Merge pull request #252 from jwetzell/dependabot/npm_and_yarn/eslint-10.7.0
Bump eslint from 10.5.0 to 10.7.0
2026-07-13 13:28:45 -05:00
Joel Wetzell 63ac2a2c39 Merge pull request #253 from jwetzell/dependabot/npm_and_yarn/tsdown-0.22.7
Bump tsdown from 0.22.2 to 0.22.7
2026-07-13 13:28:34 -05:00
dependabot[bot] 5c518d95fa Bump tsdown from 0.22.2 to 0.22.7
Bumps [tsdown](https://github.com/rolldown/tsdown) from 0.22.2 to 0.22.7.
- [Release notes](https://github.com/rolldown/tsdown/releases)
- [Commits](https://github.com/rolldown/tsdown/compare/v0.22.2...v0.22.7)

---
updated-dependencies:
- dependency-name: tsdown
  dependency-version: 0.22.7
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-13 12:33:52 +00:00
dependabot[bot] ba64ac1525 Bump eslint from 10.5.0 to 10.7.0
Bumps [eslint](https://github.com/eslint/eslint) from 10.5.0 to 10.7.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Commits](https://github.com/eslint/eslint/compare/v10.5.0...v10.7.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-version: 10.7.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-13 12:33:37 +00:00
dependabot[bot] 3fd0c506ad Bump prettier from 3.8.4 to 3.9.5
Bumps [prettier](https://github.com/prettier/prettier) from 3.8.4 to 3.9.5.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/3.8.4...3.9.5)

---
updated-dependencies:
- dependency-name: prettier
  dependency-version: 3.9.5
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-13 12:33:13 +00:00
Joel Wetzell 8678e8a07c Merge pull request #249 from jwetzell/dependabot/npm_and_yarn/typescript-eslint-8.62.0
Bump typescript-eslint from 8.61.0 to 8.62.0
2026-07-09 14:03:48 -05:00
dependabot[bot] a11c137bed Bump typescript-eslint from 8.61.0 to 8.62.0
Bumps [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint) from 8.61.0 to 8.62.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.62.0/packages/typescript-eslint)

---
updated-dependencies:
- dependency-name: typescript-eslint
  dependency-version: 8.62.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-29 12:33:40 +00:00
66 changed files with 4129 additions and 4199 deletions
-2
View File
@@ -1,2 +0,0 @@
*.md
*.min.*
-8
View File
@@ -1,8 +0,0 @@
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: true,
singleQuote: true,
bracketSameLine: true,
printWidth: 120,
};
+1 -3
View File
@@ -1,8 +1,6 @@
{ {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true, "editor.formatOnSave": true,
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll": "explicit", "source.fixAll": "explicit"
"source.organizeImports": "explicit"
} }
} }
+35
View File
@@ -0,0 +1,35 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.3/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"linter": {
"enabled": true,
"rules": {
"preset": "recommended"
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "es5"
}
},
"assist": {
"enabled": true,
"actions": {
"source": {
"organizeImports": "on"
}
}
}
}
-13
View File
@@ -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,
];
+9 -6
View File
@@ -3,14 +3,17 @@ const { Decoder } = require('../dist/cjs');
const decoder = new Decoder(); const decoder = new Decoder();
const infoPacketBuffer = new Uint8Array([ const infoPacketBuffer = new Uint8Array([
0x56, 0x67, 0x34, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01, 0x56, 0x67, 0x34, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x0b, 0x00, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01, 0x01, 0x01, 0x00, 0x0b, 0x00, 0x53, 0x65,
0x80, 0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x20, 0x31, 0x72, 0x76, 0x65, 0x72, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x02, 0x00, 0x11, 0x80,
0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b,
0x65, 0x72, 0x20, 0x31,
]); ]);
const dataPacketBuffer = new Uint8Array([ const dataPacketBuffer = new Uint8Array([
0x55, 0x67, 0x28, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01, 0x55, 0x67, 0x28, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x14, 0x80, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01, 0x01, 0x01, 0x00, 0x14, 0x80, 0x01, 0x00,
0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x10, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80,
0x3f, 0x00, 0x00, 0x80, 0x3f,
]); ]);
decoder.decode(infoPacketBuffer); decoder.decode(infoPacketBuffer);
+17 -7
View File
@@ -1,6 +1,6 @@
// recreation of psn_client.cpp example from https://github.com/vyv/psn-cpp // recreation of psn_client.cpp example from https://github.com/vyv/psn-cpp
const dgram = require('dgram'); const dgram = require('node:dgram');
const { Decoder } = require('../dist/cjs'); const { Decoder } = require('@jwetzell/posistagenet');
const client = dgram.createSocket('udp4'); const client = dgram.createSocket('udp4');
const decoder = new Decoder(); const decoder = new Decoder();
@@ -26,15 +26,21 @@ setInterval(() => {
const trackerName = decoder.trackers[trackerId]?.name; const trackerName = decoder.trackers[trackerId]?.name;
console.log(`Tracker - id: ${trackerId} | name: ${trackerName || ''}`); console.log(`Tracker - id: ${trackerId} | name: ${trackerName || ''}`);
if (tracker.pos) { if (tracker.pos) {
console.log(`\tpos: ${tracker.pos.x}, ${tracker.pos.x}, ${tracker.pos.x}`); console.log(
`\tpos: ${tracker.pos.x}, ${tracker.pos.x}, ${tracker.pos.x}`
);
} }
if (tracker.speed) { if (tracker.speed) {
console.log(`\tspeed: ${tracker.speed.x}, ${tracker.speed.y}, ${tracker.speed.z}`); console.log(
`\tspeed: ${tracker.speed.x}, ${tracker.speed.y}, ${tracker.speed.z}`
);
} }
if (tracker.ori) { if (tracker.ori) {
console.log(`\tori: ${tracker.ori.x}, ${tracker.ori.y}, ${tracker.ori.z}`); console.log(
`\tori: ${tracker.ori.x}, ${tracker.ori.y}, ${tracker.ori.z}`
);
} }
if (tracker.status) { if (tracker.status) {
@@ -42,11 +48,15 @@ setInterval(() => {
} }
if (tracker.accel) { if (tracker.accel) {
console.log(`\taccel: ${tracker.accel.x}, ${tracker.accel.y}, ${tracker.accel.z}`); console.log(
`\taccel: ${tracker.accel.x}, ${tracker.accel.y}, ${tracker.accel.z}`
);
} }
if (tracker.trgtpos) { if (tracker.trgtpos) {
console.log(`\ttrgtpos: ${tracker.trgtpos.x}, ${tracker.trgtpos.y}, ${tracker.trgtpos.z}`); console.log(
`\ttrgtpos: ${tracker.trgtpos.x}, ${tracker.trgtpos.y}, ${tracker.trgtpos.z}`
);
} }
if (tracker.timestamp) { if (tracker.timestamp) {
+6 -4
View File
@@ -1,6 +1,6 @@
// recreation of psn_server.cpp example from https://github.com/vyv/psn-cpp // recreation of psn_server.cpp example from https://github.com/vyv/psn-cpp
const dgram = require('dgram'); const dgram = require('node:dgram');
const { Encoder, Tracker } = require('../dist/cjs'); const { Encoder, Tracker } = require('@jwetzell/posistagenet');
const client = dgram.createSocket('udp4'); const client = dgram.createSocket('udp4');
const encoder = new Encoder('Test PSN Server', 2, 0); const encoder = new Encoder('Test PSN Server', 2, 0);
@@ -19,11 +19,13 @@ trackers.push(new Tracker(8, 'Neptune'));
trackers.push(new Tracker(9, 'Pluto')); trackers.push(new Tracker(9, 'Pluto'));
const orbits = [1.0, 88.0, 224.7, 365.2, 687, 4332, 10760, 30700, 60200, 90600]; const orbits = [1.0, 88.0, 224.7, 365.2, 687, 4332, 10760, 30700, 60200, 90600];
const distFromSun = [0, 0.58, 1.08, 1.5, 2.28, 7.78, 14.29, 28.71, 45.04, 59.13]; const distFromSun = [
0, 0.58, 1.08, 1.5, 2.28, 7.78, 14.29, 28.71, 45.04, 59.13,
];
let timestamp = 0; let timestamp = 0;
setInterval(() => { setInterval(() => {
orbits.forEach((orbit, index) => { orbits.forEach((_, index) => {
const a = 1.0 / orbits[index]; const a = 1.0 / orbits[index];
const b = distFromSun[index]; const b = distFromSun[index];
const x = timestamp; const x = timestamp;
+1038 -1419
View File
File diff suppressed because it is too large Load Diff
+8 -11
View File
@@ -18,9 +18,10 @@
"example:client": "node examples/psn_client.js", "example:client": "node examples/psn_client.js",
"example:server": "node examples/psn_server.js", "example:server": "node examples/psn_server.js",
"prepublishOnly": "npm run build", "prepublishOnly": "npm run build",
"lint:check": "eslint ./src", "lint:check": "biome lint",
"format:check": "prettier ./ --check", "lint:write": "biome lint --write",
"format:write": "prettier ./ --write", "format:check": "biome format",
"format:write": "biome format --write",
"pretest": "npm run build", "pretest": "npm run build",
"test": "node --test --experimental-test-coverage" "test": "node --test --experimental-test-coverage"
}, },
@@ -35,16 +36,12 @@
"repository": "https://github.com/jwetzell/psn-js", "repository": "https://github.com/jwetzell/psn-js",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.5.7",
"@eslint/js": "10.0.1", "@eslint/js": "10.0.1",
"@types/node": "24.7.2", "@types/node": "24.7.2",
"eslint": "10.5.0", "globals": "17.9.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", "rimraf": "6.1.3",
"tsdown": "0.22.2", "tsdown": "0.22.14",
"typescript": "6.0.3", "typescript": "7.0.2"
"typescript-eslint": "8.61.0"
} }
} }
+26 -13
View File
@@ -2,7 +2,7 @@ import { Decoders } from './index.js';
import { import {
type DataPacketChunk, type DataPacketChunk,
type InfoPacketChunk, type InfoPacketChunk,
Tracker, type Tracker,
TrackerFromData, TrackerFromData,
TrackerFromInfo, TrackerFromInfo,
} from './models/index.js'; } from './models/index.js';
@@ -15,7 +15,6 @@ export class Decoder {
trackers: { [key: string]: Tracker } = {}; trackers: { [key: string]: Tracker } = {};
systemName: string = ''; systemName: string = '';
constructor() {}
updateInfo(framePackets: InfoPacketChunk[]) { updateInfo(framePackets: InfoPacketChunk[]) {
framePackets.forEach((packet) => { framePackets.forEach((packet) => {
@@ -64,7 +63,7 @@ export class Decoder {
if (packet.header.id === 0x6756) { if (packet.header.id === 0x6756) {
const infoPacket = Decoders.InfoPacketChunk(packetBuf); const infoPacket = Decoders.InfoPacketChunk(packetBuf);
if (infoPacket && infoPacket.chunk.header.hasSubchunks) { if (infoPacket?.chunk.header.hasSubchunks) {
const currentInfoPacketHeader = infoPacket.data.packetHeader; const currentInfoPacketHeader = infoPacket.data.packetHeader;
if (!currentInfoPacketHeader) { if (!currentInfoPacketHeader) {
// NOTE(jwetzell): not sure that info packets without a header subchunk are valid? // NOTE(jwetzell): not sure that info packets without a header subchunk are valid?
@@ -77,16 +76,23 @@ export class Decoder {
throw new Error('malformed packet'); throw new Error('malformed packet');
} }
if (currentInfoPacketHeader.data.frameId) { if (currentInfoPacketHeader.data.frameId) {
if (this.infoPacketFrames[currentInfoPacketHeader.data.frameId] === undefined) { if (
this.infoPacketFrames[currentInfoPacketHeader.data.frameId] ===
undefined
) {
this.infoPacketFrames[currentInfoPacketHeader.data.frameId] = []; this.infoPacketFrames[currentInfoPacketHeader.data.frameId] = [];
} }
this.infoPacketFrames[currentInfoPacketHeader.data.frameId].push(infoPacket); this.infoPacketFrames[currentInfoPacketHeader.data.frameId].push(
infoPacket
);
if ( if (
this.infoPacketFrames[currentInfoPacketHeader.data.frameId].length === this.infoPacketFrames[currentInfoPacketHeader.data.frameId]
currentInfoPacketHeader.data.framePacketCount .length === currentInfoPacketHeader.data.framePacketCount
) { ) {
this.updateInfo(this.infoPacketFrames[currentInfoPacketHeader.data.frameId]); this.updateInfo(
this.infoPacketFrames[currentInfoPacketHeader.data.frameId]
);
delete this.infoPacketFrames[currentInfoPacketHeader.data.frameId]; delete this.infoPacketFrames[currentInfoPacketHeader.data.frameId];
} }
} }
@@ -101,15 +107,22 @@ export class Decoder {
} }
if (currentDataPacketHeader.data.frameId) { if (currentDataPacketHeader.data.frameId) {
if (this.dataPacketFrames[currentDataPacketHeader.data.frameId] === undefined) { if (
this.dataPacketFrames[currentDataPacketHeader.data.frameId] ===
undefined
) {
this.dataPacketFrames[currentDataPacketHeader.data.frameId] = []; this.dataPacketFrames[currentDataPacketHeader.data.frameId] = [];
} }
this.dataPacketFrames[currentDataPacketHeader.data.frameId].push(dataPacket); this.dataPacketFrames[currentDataPacketHeader.data.frameId].push(
dataPacket
);
if ( if (
this.dataPacketFrames[currentDataPacketHeader.data.frameId].length === this.dataPacketFrames[currentDataPacketHeader.data.frameId]
currentDataPacketHeader.data.framePacketCount .length === currentDataPacketHeader.data.framePacketCount
) { ) {
this.updateData(this.dataPacketFrames[currentDataPacketHeader.data.frameId]); this.updateData(
this.dataPacketFrames[currentDataPacketHeader.data.frameId]
);
delete this.dataPacketFrames[currentDataPacketHeader.data.frameId]; delete this.dataPacketFrames[currentDataPacketHeader.data.frameId];
} }
} }
+3 -1
View File
@@ -10,7 +10,9 @@ export default (buffer: Uint8Array): Chunk => {
// NOTE(jwetzell): this data is split up as 1 bit for hasSubchunks and 15 bits for the dataLen // 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 combinedLengthAndFlag = (buffer[3] << 8) + buffer[2];
const hasSubchunks = combinedLengthAndFlag > 32768; const hasSubchunks = combinedLengthAndFlag > 32768;
const dataLen = hasSubchunks ? combinedLengthAndFlag - 32768 : combinedLengthAndFlag; const dataLen = hasSubchunks
? combinedLengthAndFlag - 32768
: combinedLengthAndFlag;
const header = { const header = {
id, id,
+13 -4
View File
@@ -1,5 +1,8 @@
import { Constants } from '../../constants.js'; import { Constants } from '../../constants.js';
import type { DataPacketChunk, DataPacketChunkData } from '../../models/data/data-packet-chunk.js'; import type {
DataPacketChunk,
DataPacketChunkData,
} from '../../models/data/data-packet-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
export default (buffer: Uint8Array): DataPacketChunk => { export default (buffer: Uint8Array): DataPacketChunk => {
@@ -10,17 +13,23 @@ export default (buffer: Uint8Array): DataPacketChunk => {
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) { if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
let offset = 0; let offset = 0;
while (offset < chunk.header.dataLen) { while (offset < chunk.header.dataLen) {
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0]; const chunkId =
(chunk.chunkData.subarray(offset)[1] << 8) +
chunk.chunkData.subarray(offset)[0];
switch (chunkId) { switch (chunkId) {
case 0x0000: case 0x0000:
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset)); data.packetHeader = Decoders.PacketHeaderChunk(
chunk.chunkData.subarray(offset)
);
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (data.packetHeader.chunk.header.dataLen) { if (data.packetHeader.chunk.header.dataLen) {
offset += data.packetHeader.chunk.header.dataLen; offset += data.packetHeader.chunk.header.dataLen;
} }
break; break;
case 0x0001: case 0x0001:
data.trackerList = Decoders.DataTrackerListChunk(chunk.chunkData.subarray(offset)); data.trackerList = Decoders.DataTrackerListChunk(
chunk.chunkData.subarray(offset)
);
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (data.trackerList.chunk.header.dataLen) { if (data.trackerList.chunk.header.dataLen) {
offset += data.trackerList.chunk.header.dataLen; offset += data.trackerList.chunk.header.dataLen;
+28 -9
View File
@@ -1,5 +1,8 @@
import { Constants } from '../../constants.js'; import { Constants } from '../../constants.js';
import type { DataTrackerChunk, DataTrackerChunkData } from '../../models/data/data-tracker-chunk.js'; import type {
DataTrackerChunk,
DataTrackerChunkData,
} from '../../models/data/data-tracker-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
export default (buffer: Uint8Array): DataTrackerChunk => { export default (buffer: Uint8Array): DataTrackerChunk => {
@@ -8,28 +11,44 @@ export default (buffer: Uint8Array): DataTrackerChunk => {
if (chunk.chunkData && chunk.header.dataLen) { if (chunk.chunkData && chunk.header.dataLen) {
let offset = 0; let offset = 0;
while (offset < chunk.header.dataLen) { while (offset < chunk.header.dataLen) {
const trackerFieldChunk = Decoders.Chunk(chunk.chunkData.subarray(offset)); const trackerFieldChunk = Decoders.Chunk(
chunk.chunkData.subarray(offset)
);
switch (trackerFieldChunk.header.id) { switch (trackerFieldChunk.header.id) {
case 0x0000: case 0x0000:
data.pos = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset)); data.pos = Decoders.DataTrackerXYZChunk(
chunk.chunkData.subarray(offset)
);
break; break;
case 0x0001: case 0x0001:
data.speed = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset)); data.speed = Decoders.DataTrackerXYZChunk(
chunk.chunkData.subarray(offset)
);
break; break;
case 0x0002: case 0x0002:
data.ori = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset)); data.ori = Decoders.DataTrackerXYZChunk(
chunk.chunkData.subarray(offset)
);
break; break;
case 0x0003: case 0x0003:
data.status = Decoders.DataTrackerStatusChunk(chunk.chunkData.subarray(offset)); data.status = Decoders.DataTrackerStatusChunk(
chunk.chunkData.subarray(offset)
);
break; break;
case 0x0004: case 0x0004:
data.accel = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset)); data.accel = Decoders.DataTrackerXYZChunk(
chunk.chunkData.subarray(offset)
);
break; break;
case 0x0005: case 0x0005:
data.trgtpos = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset)); data.trgtpos = Decoders.DataTrackerXYZChunk(
chunk.chunkData.subarray(offset)
);
break; break;
case 0x0006: case 0x0006:
data.timestamp = Decoders.DataTrackerTimestampChunk(chunk.chunkData.subarray(offset)); data.timestamp = Decoders.DataTrackerTimestampChunk(
chunk.chunkData.subarray(offset)
);
break; break;
default: default:
break; break;
+7 -2
View File
@@ -1,5 +1,8 @@
import { Constants } from '../../constants.js'; import { Constants } from '../../constants.js';
import type { DataTrackerListChunk, DataTrackerListChunkData } from '../../models/data/data-tracker-list-chunk.js'; import type {
DataTrackerListChunk,
DataTrackerListChunkData,
} from '../../models/data/data-tracker-list-chunk.js';
import type { DataTrackerChunk } from '../../models/index.js'; import type { DataTrackerChunk } from '../../models/index.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
@@ -11,7 +14,9 @@ export default (buffer: Uint8Array): DataTrackerListChunk => {
if (chunk.chunkData) { if (chunk.chunkData) {
let offset = 0; let offset = 0;
while (offset < chunk.chunkData.length) { while (offset < chunk.chunkData.length) {
const trackerChunk = Decoders.DataTrackerChunk(chunk.chunkData.subarray(offset)); const trackerChunk = Decoders.DataTrackerChunk(
chunk.chunkData.subarray(offset)
);
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (trackerChunk.chunk.header.dataLen) { if (trackerChunk.chunk.header.dataLen) {
offset += trackerChunk.chunk.header.dataLen; offset += trackerChunk.chunk.header.dataLen;
@@ -7,7 +7,11 @@ import { Decoders } from '../index.js';
export default (buffer: Uint8Array): DataTrackerStatusChunk => { export default (buffer: Uint8Array): DataTrackerStatusChunk => {
const chunk = Decoders.Chunk(buffer); const chunk = Decoders.Chunk(buffer);
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength); const view = new DataView(
chunk.chunkData.buffer,
chunk.chunkData.byteOffset,
chunk.chunkData.byteLength
);
const validity = view.getFloat32(0, true); const validity = view.getFloat32(0, true);
const data: DataTrackerStatusChunkData = { const data: DataTrackerStatusChunkData = {
@@ -7,7 +7,11 @@ import { Decoders } from '../index.js';
export default (buffer: Uint8Array): DataTrackerTimestampChunk => { export default (buffer: Uint8Array): DataTrackerTimestampChunk => {
const chunk = Decoders.Chunk(buffer); const chunk = Decoders.Chunk(buffer);
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength); const view = new DataView(
chunk.chunkData.buffer,
chunk.chunkData.byteOffset,
chunk.chunkData.byteLength
);
const timestamp = view.getBigUint64(0, true); const timestamp = view.getBigUint64(0, true);
const data: DataTrackerTimestampChunkData = { const data: DataTrackerTimestampChunkData = {
+9 -2
View File
@@ -1,11 +1,18 @@
import type { DataTrackerXYZChunk, DataTrackerXYZChunkData } from '../../models/data/data-tracker-xyz-chunk.js'; import type {
DataTrackerXYZChunk,
DataTrackerXYZChunkData,
} from '../../models/data/data-tracker-xyz-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
export default (buffer: Uint8Array): DataTrackerXYZChunk => { export default (buffer: Uint8Array): DataTrackerXYZChunk => {
const chunk = Decoders.Chunk(buffer); const chunk = Decoders.Chunk(buffer);
// TODO(jwetzell): add error handling // TODO(jwetzell): add error handling
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength); const view = new DataView(
chunk.chunkData.buffer,
chunk.chunkData.byteOffset,
chunk.chunkData.byteLength
);
const data: DataTrackerXYZChunkData = { const data: DataTrackerXYZChunkData = {
x: view.getFloat32(0, true), x: view.getFloat32(0, true),
+16 -5
View File
@@ -1,5 +1,8 @@
import { Constants } from '../../constants.js'; import { Constants } from '../../constants.js';
import type { InfoPacketChunk, InfoPacketChunkData } from '../../models/info/info-packet-chunk.js'; import type {
InfoPacketChunk,
InfoPacketChunkData,
} from '../../models/info/info-packet-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
export default (buffer: Uint8Array): InfoPacketChunk => { export default (buffer: Uint8Array): InfoPacketChunk => {
@@ -10,24 +13,32 @@ export default (buffer: Uint8Array): InfoPacketChunk => {
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) { if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
let offset = 0; let offset = 0;
while (offset < chunk.header.dataLen) { while (offset < chunk.header.dataLen) {
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0]; const chunkId =
(chunk.chunkData.subarray(offset)[1] << 8) +
chunk.chunkData.subarray(offset)[0];
switch (chunkId) { switch (chunkId) {
case 0x0000: case 0x0000:
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset)); data.packetHeader = Decoders.PacketHeaderChunk(
chunk.chunkData.subarray(offset)
);
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (data.packetHeader?.chunk.header.dataLen) { if (data.packetHeader?.chunk.header.dataLen) {
offset += data.packetHeader.chunk.header.dataLen; offset += data.packetHeader.chunk.header.dataLen;
} }
break; break;
case 0x0001: case 0x0001:
data.systemName = Decoders.InfoSystemNameChunk(chunk.chunkData.subarray(offset)); data.systemName = Decoders.InfoSystemNameChunk(
chunk.chunkData.subarray(offset)
);
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (data.systemName?.chunk.header.dataLen) { if (data.systemName?.chunk.header.dataLen) {
offset += data.systemName?.chunk.header.dataLen; offset += data.systemName?.chunk.header.dataLen;
} }
break; break;
case 0x0002: case 0x0002:
data.trackerList = Decoders.InfoTrackerListChunk(chunk.chunkData.subarray(offset)); data.trackerList = Decoders.InfoTrackerListChunk(
chunk.chunkData.subarray(offset)
);
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (data.trackerList?.chunk.header.dataLen) { if (data.trackerList?.chunk.header.dataLen) {
offset += data.trackerList.chunk.header.dataLen; offset += data.trackerList.chunk.header.dataLen;
+7 -2
View File
@@ -1,4 +1,7 @@
import type { InfoSystemNameChunk, InfoSystemNameChunkData } from '../../models/info/info-system-name-chunk.js'; import type {
InfoSystemNameChunk,
InfoSystemNameChunkData,
} from '../../models/info/info-system-name-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
const nameDecoder = new TextDecoder(); const nameDecoder = new TextDecoder();
@@ -6,7 +9,9 @@ export default (buffer: Uint8Array): InfoSystemNameChunk => {
const chunk = Decoders.Chunk(buffer); const chunk = Decoders.Chunk(buffer);
const data: InfoSystemNameChunkData = { const data: InfoSystemNameChunkData = {
systemName: nameDecoder.decode(chunk.chunkData.subarray(0, chunk.header.dataLen)), systemName: nameDecoder.decode(
chunk.chunkData.subarray(0, chunk.header.dataLen)
),
}; };
return { return {
+10 -3
View File
@@ -1,5 +1,8 @@
import { Constants } from '../../constants.js'; import { Constants } from '../../constants.js';
import type { InfoTrackerChunk, InfoTrackerChunkData } from '../../models/info/info-tracker-chunk.js'; import type {
InfoTrackerChunk,
InfoTrackerChunkData,
} from '../../models/info/info-tracker-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
export default (buffer: Uint8Array): InfoTrackerChunk => { export default (buffer: Uint8Array): InfoTrackerChunk => {
@@ -8,11 +11,15 @@ export default (buffer: Uint8Array): InfoTrackerChunk => {
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) { if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
let offset = 0; let offset = 0;
while (offset < chunk.header.dataLen) { while (offset < chunk.header.dataLen) {
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0]; const chunkId =
(chunk.chunkData.subarray(offset)[1] << 8) +
chunk.chunkData.subarray(offset)[0];
switch (chunkId) { switch (chunkId) {
case 0x0000: { case 0x0000: {
const data: InfoTrackerChunkData = { const data: InfoTrackerChunkData = {
trackerName: Decoders.InfoTrackerNameChunk(chunk.chunkData.subarray(offset)), trackerName: Decoders.InfoTrackerNameChunk(
chunk.chunkData.subarray(offset)
),
}; };
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (data.trackerName.chunk.header.dataLen) { if (data.trackerName.chunk.header.dataLen) {
+7 -2
View File
@@ -1,6 +1,9 @@
import { Constants } from '../../constants.js'; import { Constants } from '../../constants.js';
import type { InfoTrackerChunk } from '../../models/info/info-tracker-chunk.js'; import type { InfoTrackerChunk } from '../../models/info/info-tracker-chunk.js';
import type { InfoTrackerListChunk, InfoTrackerListChunkData } from '../../models/info/info-tracker-list-chunk.js'; import type {
InfoTrackerListChunk,
InfoTrackerListChunkData,
} from '../../models/info/info-tracker-list-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
export default (buffer: Uint8Array): InfoTrackerListChunk => { export default (buffer: Uint8Array): InfoTrackerListChunk => {
@@ -12,7 +15,9 @@ export default (buffer: Uint8Array): InfoTrackerListChunk => {
let offset = 0; let offset = 0;
if (chunk.header.dataLen) { if (chunk.header.dataLen) {
while (offset < chunk.header.dataLen) { while (offset < chunk.header.dataLen) {
const trackerChunk = Decoders.InfoTrackerChunk(chunk.chunkData.subarray(offset)); const trackerChunk = Decoders.InfoTrackerChunk(
chunk.chunkData.subarray(offset)
);
offset += Constants.CHUNK_HEADER_SIZE; offset += Constants.CHUNK_HEADER_SIZE;
if (trackerChunk.chunk.header.dataLen) { if (trackerChunk.chunk.header.dataLen) {
offset += trackerChunk.chunk.header.dataLen; offset += trackerChunk.chunk.header.dataLen;
+7 -2
View File
@@ -1,4 +1,7 @@
import type { InfoTrackerNameChunk, InfoTrackerNameChunkData } from '../../models/info/info-tracker-name-chunk.js'; import type {
InfoTrackerNameChunk,
InfoTrackerNameChunkData,
} from '../../models/info/info-tracker-name-chunk.js';
import { Decoders } from '../index.js'; import { Decoders } from '../index.js';
const nameDecoder = new TextDecoder(); const nameDecoder = new TextDecoder();
@@ -6,7 +9,9 @@ export default (buffer: Uint8Array): InfoTrackerNameChunk => {
const chunk = Decoders.Chunk(buffer); const chunk = Decoders.Chunk(buffer);
const data: InfoTrackerNameChunkData = { const data: InfoTrackerNameChunkData = {
trackerName: nameDecoder.decode(chunk.chunkData.subarray(0, chunk.header.dataLen)), trackerName: nameDecoder.decode(
chunk.chunkData.subarray(0, chunk.header.dataLen)
),
}; };
return { return {
+4 -1
View File
@@ -1,4 +1,7 @@
import type { PacketHeaderChunk, PacketHeaderChunkData } from '../models/packet-header-chunk.js'; import type {
PacketHeaderChunk,
PacketHeaderChunkData,
} from '../models/packet-header-chunk.js';
import { Decoders } from './index.js'; import { Decoders } from './index.js';
export default (buffer: Uint8Array): PacketHeaderChunk => { export default (buffer: Uint8Array): PacketHeaderChunk => {
+34 -9
View File
@@ -1,5 +1,5 @@
import { Constants } from './constants.js'; import { Constants } from './constants.js';
import { Encoders, Tracker } from './index.js'; import { Encoders, type Tracker } from './index.js';
export class Encoder { export class Encoder {
private systemName: string; private systemName: string;
@@ -7,7 +7,11 @@ export class Encoder {
private versionLow: number; private versionLow: number;
dataFrameId: number = 1; dataFrameId: number = 1;
infoFrameId: number = 1; infoFrameId: number = 1;
constructor(systemName: string, versionHigh: number = 2, versionLow: number = 3) { constructor(
systemName: string,
versionHigh: number = 2,
versionLow: number = 3
) {
this.systemName = systemName; this.systemName = systemName;
this.versionHigh = versionHigh; this.versionHigh = versionHigh;
this.versionLow = versionLow; this.versionLow = versionLow;
@@ -45,17 +49,25 @@ export class Encoder {
const systemNameChunk = Encoders.InfoSystemNameChunk(this.systemName); const systemNameChunk = Encoders.InfoSystemNameChunk(this.systemName);
const trackerChunks = trackers.map((tracker: Tracker) => tracker.getInfoChunk()); const trackerChunks = trackers.map((tracker: Tracker) =>
tracker.getInfoChunk()
);
const infoPackets: Uint8Array[] = []; const infoPackets: Uint8Array[] = [];
const trackerChunksLists: Uint8Array[][] = []; const trackerChunksLists: Uint8Array[][] = [];
let currentTrackerList: Uint8Array[] = []; let currentTrackerList: Uint8Array[] = [];
let currentInfoPacketSize = Constants.PACKET_HEADER_SIZE + systemNameChunk.length + Constants.CHUNK_HEADER_SIZE; let currentInfoPacketSize =
Constants.PACKET_HEADER_SIZE +
systemNameChunk.length +
Constants.CHUNK_HEADER_SIZE;
trackerChunks.forEach((trackerChunk: Uint8Array) => { trackerChunks.forEach((trackerChunk: Uint8Array) => {
if (currentInfoPacketSize + trackerChunk.length > Constants.MAX_UDP_PACKET_SIZE) { if (
currentInfoPacketSize + trackerChunk.length >
Constants.MAX_UDP_PACKET_SIZE
) {
trackerChunksLists.push(currentTrackerList); trackerChunksLists.push(currentTrackerList);
currentTrackerList = []; currentTrackerList = [];
currentInfoPacketSize = 0; currentInfoPacketSize = 0;
@@ -73,7 +85,11 @@ export class Encoder {
); );
trackerChunksLists.forEach((trackerChunkList) => { trackerChunksLists.forEach((trackerChunkList) => {
infoPackets.push( infoPackets.push(
Encoders.InfoPacketChunk(header, systemNameChunk, Encoders.InfoTrackerListChunk(trackerChunkList)) Encoders.InfoPacketChunk(
header,
systemNameChunk,
Encoders.InfoTrackerListChunk(trackerChunkList)
)
); );
}); });
this.infoFrameId += 1; this.infoFrameId += 1;
@@ -100,10 +116,14 @@ export class Encoder {
const trackerChunksLists: Uint8Array[][] = []; const trackerChunksLists: Uint8Array[][] = [];
let currentTrackerList: Uint8Array[] = []; let currentTrackerList: Uint8Array[] = [];
let currentDataPacketSize = Constants.PACKET_HEADER_SIZE + Constants.CHUNK_HEADER_SIZE; let currentDataPacketSize =
Constants.PACKET_HEADER_SIZE + Constants.CHUNK_HEADER_SIZE;
allTrackerChunks.forEach((trackerChunk) => { allTrackerChunks.forEach((trackerChunk) => {
if (currentDataPacketSize + trackerChunk.length > Constants.MAX_UDP_PACKET_SIZE) { if (
currentDataPacketSize + trackerChunk.length >
Constants.MAX_UDP_PACKET_SIZE
) {
trackerChunksLists.push(currentTrackerList); trackerChunksLists.push(currentTrackerList);
currentTrackerList = []; currentTrackerList = [];
currentDataPacketSize = 0; currentDataPacketSize = 0;
@@ -121,7 +141,12 @@ export class Encoder {
trackerChunksLists.length trackerChunksLists.length
); );
trackerChunksLists.forEach((trackerChunks) => { trackerChunksLists.forEach((trackerChunks) => {
dataPackets.push(Encoders.DataPacketChunk(header, Encoders.DataTrackerListChunk(trackerChunks))); dataPackets.push(
Encoders.DataPacketChunk(
header,
Encoders.DataTrackerListChunk(trackerChunks)
)
);
}); });
this.dataFrameId += 1; this.dataFrameId += 1;
if (this.dataFrameId > 255) { if (this.dataFrameId > 255) {
+5 -1
View File
@@ -1,5 +1,9 @@
const header = new DataView(new ArrayBuffer(4)); const header = new DataView(new ArrayBuffer(4));
export default (id: number, chunkData: Uint8Array, hasSubchunks: boolean): Uint8Array => { export default (
id: number,
chunkData: Uint8Array,
hasSubchunks: boolean
): Uint8Array => {
if (!Number.isInteger(id)) { if (!Number.isInteger(id)) {
throw new Error('chunk id must be an integer'); throw new Error('chunk id must be an integer');
} }
+7 -2
View File
@@ -1,6 +1,11 @@
import chunk from '../chunk.js'; import chunk from '../chunk.js';
export default (packetHeaderChunk: Uint8Array, trackerListChunk: Uint8Array): Uint8Array => { export default (
const chunkData = new Uint8Array(packetHeaderChunk.length + trackerListChunk.length); packetHeaderChunk: Uint8Array,
trackerListChunk: Uint8Array
): Uint8Array => {
const chunkData = new Uint8Array(
packetHeaderChunk.length + trackerListChunk.length
);
chunkData.set(packetHeaderChunk); chunkData.set(packetHeaderChunk);
chunkData.set(trackerListChunk, packetHeaderChunk.length); chunkData.set(trackerListChunk, packetHeaderChunk.length);
return chunk(0x6755, chunkData, true); return chunk(0x6755, chunkData, true);
+7 -2
View File
@@ -5,10 +5,15 @@ export default (
systemNameChunk: Uint8Array, systemNameChunk: Uint8Array,
trackerListChunk: Uint8Array trackerListChunk: Uint8Array
): Uint8Array => { ): Uint8Array => {
const chunkData = new Uint8Array(packetHeaderChunk.length + systemNameChunk.length + trackerListChunk.length); const chunkData = new Uint8Array(
packetHeaderChunk.length + systemNameChunk.length + trackerListChunk.length
);
chunkData.set(packetHeaderChunk); chunkData.set(packetHeaderChunk);
chunkData.set(systemNameChunk, packetHeaderChunk.length); chunkData.set(systemNameChunk, packetHeaderChunk.length);
chunkData.set(trackerListChunk, packetHeaderChunk.length + systemNameChunk.length); chunkData.set(
trackerListChunk,
packetHeaderChunk.length + systemNameChunk.length
);
return chunk(0x6756, chunkData, true); return chunk(0x6756, chunkData, true);
}; };
+2 -1
View File
@@ -1,3 +1,4 @@
import chunk from '../chunk.js'; import chunk from '../chunk.js';
const nameEncoder = new TextEncoder(); const nameEncoder = new TextEncoder();
export default (systemName: string): Uint8Array => chunk(0x0001, nameEncoder.encode(systemName), false); export default (systemName: string): Uint8Array =>
chunk(0x0001, nameEncoder.encode(systemName), false);
+2 -1
View File
@@ -1,4 +1,5 @@
import chunk from '../chunk.js'; import chunk from '../chunk.js';
const nameEncoder = new TextEncoder(); const nameEncoder = new TextEncoder();
export default (trackerName: string) => chunk(0x0000, nameEncoder.encode(trackerName), false); export default (trackerName: string) =>
chunk(0x0000, nameEncoder.encode(trackerName), false);
+23 -6
View File
@@ -126,7 +126,9 @@ export class Tracker {
} }
if (this.speed) { if (this.speed) {
fieldChunks.push(dataTrackerSpeedChunk(this.speed.x, this.speed.y, this.speed.z)); fieldChunks.push(
dataTrackerSpeedChunk(this.speed.x, this.speed.y, this.speed.z)
);
} }
if (this.ori) { if (this.ori) {
@@ -138,11 +140,15 @@ export class Tracker {
} }
if (this.accel) { if (this.accel) {
fieldChunks.push(dataTrackerAccelChunk(this.accel.x, this.accel.y, this.accel.z)); fieldChunks.push(
dataTrackerAccelChunk(this.accel.x, this.accel.y, this.accel.z)
);
} }
if (this.trgtpos) { if (this.trgtpos) {
fieldChunks.push(dataTrackerTrgtposChunk(this.trgtpos.x, this.trgtpos.y, this.trgtpos.z)); fieldChunks.push(
dataTrackerTrgtposChunk(this.trgtpos.x, this.trgtpos.y, this.trgtpos.z)
);
} }
if (this.timestamp) { if (this.timestamp) {
@@ -164,7 +170,11 @@ export class Tracker {
updateData(dataTrackerChunk: DataTrackerChunk) { updateData(dataTrackerChunk: DataTrackerChunk) {
if (dataTrackerChunk.data.pos) { if (dataTrackerChunk.data.pos) {
this.setPos(dataTrackerChunk.data.pos.data.x, dataTrackerChunk.data.pos.data.y, dataTrackerChunk.data.pos.data.z); this.setPos(
dataTrackerChunk.data.pos.data.x,
dataTrackerChunk.data.pos.data.y,
dataTrackerChunk.data.pos.data.z
);
} }
if (dataTrackerChunk.data.speed) { if (dataTrackerChunk.data.speed) {
@@ -176,7 +186,11 @@ export class Tracker {
} }
if (dataTrackerChunk.data.ori) { if (dataTrackerChunk.data.ori) {
this.setOri(dataTrackerChunk.data.ori.data.x, dataTrackerChunk.data.ori.data.y, dataTrackerChunk.data.ori.data.z); this.setOri(
dataTrackerChunk.data.ori.data.x,
dataTrackerChunk.data.ori.data.y,
dataTrackerChunk.data.ori.data.z
);
} }
if (dataTrackerChunk.data.status) { if (dataTrackerChunk.data.status) {
@@ -207,7 +221,10 @@ export class Tracker {
export function TrackerFromInfo(infoTrackerChunk: InfoTrackerChunk) { export function TrackerFromInfo(infoTrackerChunk: InfoTrackerChunk) {
if (infoTrackerChunk.data) { if (infoTrackerChunk.data) {
return new Tracker(infoTrackerChunk.chunk.header.id, infoTrackerChunk.data.trackerName.data.trackerName); return new Tracker(
infoTrackerChunk.chunk.header.id,
infoTrackerChunk.data.trackerName.data.trackerName
);
} }
return undefined; return undefined;
} }
+166 -75
View File
@@ -1,11 +1,13 @@
import { Decoders } from '@jwetzell/posistagenet'; import { Decoders } from '@jwetzell/posistagenet';
import { deepEqual, throws } from 'assert'; import { deepEqual, throws } from 'node:assert';
import { describe, it } from 'node:test'; import { describe, it } from 'node:test';
const goodTests = [ const goodTests = [
{ {
description: 'DataTrackerPosChunk', description: 'DataTrackerPosChunk',
bytes: new Uint8Array([0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), bytes: new Uint8Array([
0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
@@ -21,7 +23,9 @@ const goodTests = [
}, },
{ {
description: 'DataTrackerSpeedChunk', description: 'DataTrackerSpeedChunk',
bytes: new Uint8Array([1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), bytes: new Uint8Array([
1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
@@ -37,7 +41,9 @@ const goodTests = [
}, },
{ {
description: 'DataTrackerOriChunk', description: 'DataTrackerOriChunk',
bytes: new Uint8Array([2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), bytes: new Uint8Array([
2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
@@ -67,7 +73,9 @@ const goodTests = [
}, },
{ {
description: 'DataTrackerAccelChunk', description: 'DataTrackerAccelChunk',
bytes: new Uint8Array([4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), bytes: new Uint8Array([
4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
@@ -83,7 +91,9 @@ const goodTests = [
}, },
{ {
description: 'DataTrackerTrgtPosChunk', description: 'DataTrackerTrgtPosChunk',
bytes: new Uint8Array([5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), bytes: new Uint8Array([
5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
@@ -114,25 +124,29 @@ const goodTests = [
{ {
description: 'DataTrackerChunk', description: 'DataTrackerChunk',
bytes: new Uint8Array([ 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, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1,
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, 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, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12,
150, 73, 0, 0, 0, 0, 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: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([ 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, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12, 0, 0,
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, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 0, 128, 63, 0,
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, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12, 0, 0, 0,
0, 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 }, header: { dataLen: 100, id: 1, hasSubchunks: true },
}, },
data: { data: {
pos: { pos: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 0, hasSubchunks: false }, header: { dataLen: 12, id: 0, hasSubchunks: false },
}, },
data: { data: {
@@ -143,7 +157,9 @@ const goodTests = [
}, },
speed: { speed: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 1, hasSubchunks: false }, header: { dataLen: 12, id: 1, hasSubchunks: false },
}, },
data: { data: {
@@ -154,7 +170,9 @@ const goodTests = [
}, },
ori: { ori: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 2, hasSubchunks: false }, header: { dataLen: 12, id: 2, hasSubchunks: false },
}, },
data: { data: {
@@ -174,7 +192,9 @@ const goodTests = [
}, },
accel: { accel: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 4, hasSubchunks: false }, header: { dataLen: 12, id: 4, hasSubchunks: false },
}, },
data: { data: {
@@ -185,7 +205,9 @@ const goodTests = [
}, },
trgtpos: { trgtpos: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 5, hasSubchunks: false }, header: { dataLen: 12, id: 5, hasSubchunks: false },
}, },
data: { data: {
@@ -210,18 +232,22 @@ const goodTests = [
{ {
description: 'DataTrackerListChunk', description: 'DataTrackerListChunk',
bytes: new Uint8Array([ 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, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
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, 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, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128,
0, 210, 2, 150, 73, 0, 0, 0, 0, 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: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([ 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, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
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, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0,
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, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4,
0, 210, 2, 150, 73, 0, 0, 0, 0, 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 }, header: { dataLen: 104, id: 1, hasSubchunks: true },
}, },
@@ -230,17 +256,21 @@ const goodTests = [
{ {
chunk: { chunk: {
chunkData: new Uint8Array([ 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, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 0, 12,
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, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 12, 0, 0, 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, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63,
8, 0, 210, 2, 150, 73, 0, 0, 0, 0, 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 }, header: { dataLen: 100, id: 1, hasSubchunks: true },
}, },
data: { data: {
pos: { pos: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 0, hasSubchunks: false }, header: { dataLen: 12, id: 0, hasSubchunks: false },
}, },
data: { data: {
@@ -251,7 +281,9 @@ const goodTests = [
}, },
speed: { speed: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 1, hasSubchunks: false }, header: { dataLen: 12, id: 1, hasSubchunks: false },
}, },
data: { data: {
@@ -262,7 +294,9 @@ const goodTests = [
}, },
ori: { ori: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 2, hasSubchunks: false }, header: { dataLen: 12, id: 2, hasSubchunks: false },
}, },
data: { data: {
@@ -282,7 +316,9 @@ const goodTests = [
}, },
accel: { accel: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 4, hasSubchunks: false }, header: { dataLen: 12, id: 4, hasSubchunks: false },
}, },
data: { data: {
@@ -293,7 +329,9 @@ const goodTests = [
}, },
trgtpos: { trgtpos: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 5, hasSubchunks: false }, header: { dataLen: 12, id: 5, hasSubchunks: false },
}, },
data: { data: {
@@ -321,25 +359,33 @@ const goodTests = [
{ {
description: 'DataPacketChunk', description: 'DataPacketChunk',
bytes: new Uint8Array([ 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, 85, 103, 124, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
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, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
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, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0,
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, 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: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([ 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, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 104,
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, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 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, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 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, 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 }, header: { dataLen: 124, id: 26453, hasSubchunks: true },
}, },
data: { data: {
packetHeader: { packetHeader: {
chunk: { chunk: {
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]), chunkData: new Uint8Array([
210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
]),
header: { dataLen: 12, id: 0, hasSubchunks: false }, header: { dataLen: 12, id: 0, hasSubchunks: false },
}, },
data: { data: {
@@ -353,10 +399,12 @@ const goodTests = [
trackerList: { trackerList: {
chunk: { chunk: {
chunkData: new Uint8Array([ 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, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64,
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, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0,
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, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0,
6, 0, 8, 0, 210, 2, 150, 73, 0, 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 }, header: { dataLen: 104, id: 1, hasSubchunks: true },
}, },
@@ -365,9 +413,11 @@ const goodTests = [
{ {
chunk: { chunk: {
chunkData: new Uint8Array([ 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, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1, 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, 2, 0, 12,
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, 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, 64, 6, 0, 8, 0, 210, 2, 150, 73, 0, 0, 0, 0,
]), ]),
header: { dataLen: 100, id: 1, hasSubchunks: true }, header: { dataLen: 100, id: 1, hasSubchunks: true },
@@ -375,7 +425,9 @@ const goodTests = [
data: { data: {
pos: { pos: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 0, hasSubchunks: false }, header: { dataLen: 12, id: 0, hasSubchunks: false },
}, },
data: { data: {
@@ -386,7 +438,9 @@ const goodTests = [
}, },
speed: { speed: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 1, hasSubchunks: false }, header: { dataLen: 12, id: 1, hasSubchunks: false },
}, },
data: { data: {
@@ -397,7 +451,9 @@ const goodTests = [
}, },
ori: { ori: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 2, hasSubchunks: false }, header: { dataLen: 12, id: 2, hasSubchunks: false },
}, },
data: { data: {
@@ -417,7 +473,9 @@ const goodTests = [
}, },
accel: { accel: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 4, hasSubchunks: false }, header: { dataLen: 12, id: 4, hasSubchunks: false },
}, },
data: { data: {
@@ -428,7 +486,9 @@ const goodTests = [
}, },
trgtpos: { trgtpos: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), chunkData: new Uint8Array([
0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
]),
header: { dataLen: 12, id: 5, hasSubchunks: false }, header: { dataLen: 12, id: 5, hasSubchunks: false },
}, },
data: { data: {
@@ -471,10 +531,14 @@ const goodTests = [
}, },
{ {
description: 'InfoSystemNameChunk', description: 'InfoSystemNameChunk',
bytes: new Uint8Array([1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114]), bytes: new Uint8Array([
1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([80, 83, 78, 32, 83, 101, 114, 118, 101, 114]), chunkData: new Uint8Array([
80, 83, 78, 32, 83, 101, 114, 118, 101, 114,
]),
header: { dataLen: 10, id: 1, hasSubchunks: false }, header: { dataLen: 10, id: 1, hasSubchunks: false },
}, },
data: { data: {
@@ -485,10 +549,14 @@ const goodTests = [
}, },
{ {
description: 'InfoTrackerChunk', description: 'InfoTrackerChunk',
bytes: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), bytes: new Uint8Array([
1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), chunkData: new Uint8Array([
0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
header: { dataLen: 13, id: 1, hasSubchunks: true }, header: { dataLen: 13, id: 1, hasSubchunks: true },
}, },
data: { data: {
@@ -507,23 +575,32 @@ const goodTests = [
}, },
{ {
description: 'InfoTrackerListChunk', 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]), 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: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), 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 }, header: { dataLen: 17, id: 2, hasSubchunks: true },
}, },
data: { data: {
trackers: [ trackers: [
{ {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), chunkData: new Uint8Array([
0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
header: { dataLen: 13, id: 1, hasSubchunks: true }, header: { dataLen: 13, id: 1, hasSubchunks: true },
}, },
data: { data: {
trackerName: { trackerName: {
chunk: { chunk: {
chunkData: new Uint8Array([84, 114, 97, 99, 107, 101, 114, 32, 49]), chunkData: new Uint8Array([
84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
header: { dataLen: 9, id: 0, hasSubchunks: false }, header: { dataLen: 9, id: 0, hasSubchunks: false },
}, },
data: { data: {
@@ -539,7 +616,9 @@ const goodTests = [
}, },
{ {
description: 'PacketHeaderChunk', description: 'PacketHeaderChunk',
bytes: new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]), bytes: new Uint8Array([
0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
]),
expected: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]), chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
@@ -558,21 +637,25 @@ const goodTests = [
{ {
description: 'InfoPacketChunk', description: 'InfoPacketChunk',
bytes: new Uint8Array([ 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, 86, 103, 51, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
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, 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: { expected: {
chunk: { chunk: {
chunkData: new Uint8Array([ 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, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123, 1, 0, 10, 0,
114, 2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49, 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 }, header: { dataLen: 51, id: 26454, hasSubchunks: true },
}, },
data: { data: {
packetHeader: { packetHeader: {
chunk: { chunk: {
chunkData: new Uint8Array([210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]), chunkData: new Uint8Array([
210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
]),
header: { dataLen: 12, id: 0, hasSubchunks: false }, header: { dataLen: 12, id: 0, hasSubchunks: false },
}, },
data: { data: {
@@ -585,7 +668,9 @@ const goodTests = [
}, },
systemName: { systemName: {
chunk: { chunk: {
chunkData: new Uint8Array([80, 83, 78, 32, 83, 101, 114, 118, 101, 114]), chunkData: new Uint8Array([
80, 83, 78, 32, 83, 101, 114, 118, 101, 114,
]),
header: { dataLen: 10, id: 1, hasSubchunks: false }, header: { dataLen: 10, id: 1, hasSubchunks: false },
}, },
data: { data: {
@@ -594,20 +679,26 @@ const goodTests = [
}, },
trackerList: { trackerList: {
chunk: { chunk: {
chunkData: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), 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 }, header: { dataLen: 17, id: 2, hasSubchunks: true },
}, },
data: { data: {
trackers: [ trackers: [
{ {
chunk: { chunk: {
chunkData: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), chunkData: new Uint8Array([
0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
header: { dataLen: 13, id: 1, hasSubchunks: true }, header: { dataLen: 13, id: 1, hasSubchunks: true },
}, },
data: { data: {
trackerName: { trackerName: {
chunk: { chunk: {
chunkData: new Uint8Array([84, 114, 97, 99, 107, 101, 114, 32, 49]), chunkData: new Uint8Array([
84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
header: { dataLen: 9, id: 0, hasSubchunks: false }, header: { dataLen: 9, id: 0, hasSubchunks: false },
}, },
data: { data: {
+79 -38
View File
@@ -1,21 +1,27 @@
import { Encoders } from '@jwetzell/posistagenet'; import { deepEqual, throws } from 'node:assert';
import { deepEqual, throws } from 'assert';
import { describe, it } from 'node:test'; import { describe, it } from 'node:test';
import { Encoders } from '@jwetzell/posistagenet';
const goodTests = [ const goodTests = [
{ {
description: 'DataTrackerPosChunk', description: 'DataTrackerPosChunk',
expected: new Uint8Array([0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), 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), bytes: Encoders.DataTrackerPosChunk(1.0, 2.0, 3.0),
}, },
{ {
description: 'DataTrackerSpeedChunk', description: 'DataTrackerSpeedChunk',
expected: new Uint8Array([1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), 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), bytes: Encoders.DataTrackerSpeedChunk(1.0, 2.0, 3.0),
}, },
{ {
description: 'DataTrackerOriChunk', description: 'DataTrackerOriChunk',
expected: new Uint8Array([2, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), 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), bytes: Encoders.DataTrackerOriChunk(1.0, 2.0, 3.0),
}, },
{ {
@@ -25,12 +31,16 @@ const goodTests = [
}, },
{ {
description: 'DataTrackerAccelChunk', description: 'DataTrackerAccelChunk',
expected: new Uint8Array([4, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), 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), bytes: Encoders.DataTrackerAccelChunk(1.0, 2.0, 3.0),
}, },
{ {
description: 'DataTrackerTrgtposChunk', description: 'DataTrackerTrgtposChunk',
expected: new Uint8Array([5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), 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), bytes: Encoders.DataTrackerTrgtposChunk(1.0, 2.0, 3.0),
}, },
{ {
@@ -41,10 +51,11 @@ const goodTests = [
{ {
description: 'DataTrackerChunk', description: 'DataTrackerChunk',
expected: new Uint8Array([ 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, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 1,
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, 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, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 2, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0, 12,
150, 73, 0, 0, 0, 0, 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, [ bytes: Encoders.DataTrackerChunk(1, [
new Uint8Array([0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]), new Uint8Array([0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]),
@@ -59,75 +70,105 @@ const goodTests = [
{ {
description: 'DataTrackerListChunk', description: 'DataTrackerListChunk',
expected: new Uint8Array([ 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, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
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, 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, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128,
0, 210, 2, 150, 73, 0, 0, 0, 0, 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([ bytes: Encoders.DataTrackerListChunk([
new Uint8Array([ 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, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 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, 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, 5, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 6, 0, 8, 0, 210, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0, 128, 63, 4, 0,
2, 150, 73, 0, 0, 0, 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', description: 'DataPacketChunk',
expected: new Uint8Array([ 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, 85, 103, 124, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
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, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
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, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0,
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, 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( bytes: Encoders.DataPacketChunk(
new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]), new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]),
new Uint8Array([ 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, 1, 0, 104, 128, 1, 0, 100, 128, 0, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64,
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, 0, 0, 64, 64, 1, 0, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2,
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, 12, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 3, 0, 4, 0, 0, 0,
0, 8, 0, 210, 2, 150, 73, 0, 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', description: 'InfoTrackerNameChunk',
expected: new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), expected: new Uint8Array([
0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
bytes: Encoders.InfoTrackerNameChunk('Tracker 1'), bytes: Encoders.InfoTrackerNameChunk('Tracker 1'),
}, },
{ {
description: 'InfoSystemNameChunk', description: 'InfoSystemNameChunk',
expected: new Uint8Array([1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114]), expected: new Uint8Array([
1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114,
]),
bytes: Encoders.InfoSystemNameChunk('PSN Server'), bytes: Encoders.InfoSystemNameChunk('PSN Server'),
}, },
{ {
description: 'InfoTrackerChunk', description: 'InfoTrackerChunk',
expected: new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), expected: new Uint8Array([
bytes: Encoders.InfoTrackerChunk(1, new Uint8Array([0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49])), 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', 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]), 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([ bytes: Encoders.InfoTrackerListChunk([
new Uint8Array([1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]), new Uint8Array([
1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
]),
]), ]),
}, },
{ {
description: 'PacketHeaderChunk', description: 'PacketHeaderChunk',
expected: new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]), 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), bytes: Encoders.PacketHeaderChunk(1234567890n, 2, 3, 1, 123),
}, },
{ {
description: 'InfoPacketChunk', description: 'InfoPacketChunk',
expected: new Uint8Array([ 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, 86, 103, 51, 128, 0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
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, 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( bytes: Encoders.InfoPacketChunk(
new Uint8Array([0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123]), 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([
new Uint8Array([2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49]) 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,
])
), ),
}, },
]; ];
+2 -2
View File
@@ -1,4 +1,4 @@
import { defineConfig } from 'tsdown' import { defineConfig } from 'tsdown';
export default defineConfig({ export default defineConfig({
entry: 'src/index.ts', entry: 'src/index.ts',
@@ -7,4 +7,4 @@ export default defineConfig({
esm: {}, esm: {},
cjs: {}, cjs: {},
}, },
}) });