mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-19 22:24:17 +00:00
align structure more with underlying chunk layout
This commit is contained in:
+9
-5
@@ -1,6 +1,10 @@
|
||||
export interface Chunk {
|
||||
id?: number;
|
||||
has_subchunks?: boolean;
|
||||
data_len?: number;
|
||||
chunk_data?: Uint8Array;
|
||||
export interface ChunkHeader {
|
||||
id: number;
|
||||
dataLen: number;
|
||||
hasSubchunks: boolean;
|
||||
}
|
||||
|
||||
export interface Chunk {
|
||||
chunkData: Uint8Array;
|
||||
header: ChunkHeader;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,12 @@ import { Chunk } from '../chunk';
|
||||
import { PacketHeaderChunk } from '../packet-header-chunk';
|
||||
import { DataTrackerListChunk } from './data-tracker-list-chunk';
|
||||
|
||||
export interface DataPacketChunk extends Chunk {
|
||||
packet_header: PacketHeaderChunk;
|
||||
tracker_list: DataTrackerListChunk;
|
||||
export interface DataPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
trackerList?: DataTrackerListChunk;
|
||||
}
|
||||
|
||||
export interface DataPacketChunk {
|
||||
chunk: Chunk;
|
||||
data: DataPacketChunkData;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { DataTrackerFieldChunk } from './data-tracker-field-chunk';
|
||||
import { DataTrackerStatusChunk } from './data-tracker-status-chunk';
|
||||
import { DataTrackerTimestampChunk } from './data-tracker-timestamp-chunk';
|
||||
import { DataTrackerXYZChunk } from './data-tracker-xyz-chunk';
|
||||
|
||||
export interface DataTrackerChunk extends Chunk {
|
||||
pos?: DataTrackerFieldChunk;
|
||||
speed?: DataTrackerFieldChunk;
|
||||
ori?: DataTrackerFieldChunk;
|
||||
status?: DataTrackerFieldChunk;
|
||||
accel?: DataTrackerFieldChunk;
|
||||
trgtpos?: DataTrackerFieldChunk;
|
||||
timestamp?: DataTrackerFieldChunk;
|
||||
export interface DataTrackerChunkData {
|
||||
pos?: DataTrackerXYZChunk;
|
||||
speed?: DataTrackerXYZChunk;
|
||||
ori?: DataTrackerXYZChunk;
|
||||
status?: DataTrackerStatusChunk;
|
||||
accel?: DataTrackerXYZChunk;
|
||||
trgtpos?: DataTrackerXYZChunk;
|
||||
timestamp?: DataTrackerTimestampChunk;
|
||||
}
|
||||
|
||||
export interface DataTrackerChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerChunkData;
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerFieldChunk extends Chunk {
|
||||
[key: string]: number | bigint | number[] | Uint8Array | undefined | boolean;
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { DataTrackerChunk } from './data-tracker-chunk';
|
||||
|
||||
export interface DataTrackerListChunk extends Chunk {
|
||||
trackers: {
|
||||
[key: number]: DataTrackerChunk;
|
||||
};
|
||||
export interface DataTrackerListChunkData {
|
||||
trackers: DataTrackerChunk[];
|
||||
}
|
||||
|
||||
export interface DataTrackerListChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerListChunkData;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerStatusChunkData {
|
||||
validity: number;
|
||||
}
|
||||
|
||||
export interface DataTrackerStatusChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerStatusChunkData;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerTimestampChunkData {
|
||||
timestamp: bigint;
|
||||
}
|
||||
|
||||
export interface DataTrackerTimestampChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerTimestampChunkData;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface DataTrackerXYZChunkData {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
}
|
||||
|
||||
export interface DataTrackerXYZChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerXYZChunkData;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
export * from './chunk';
|
||||
export * from './data/data-packet-chunk';
|
||||
export * from './data/data-tracker-chunk';
|
||||
export * from './data/data-tracker-field-chunk';
|
||||
export * from './data/data-tracker-list-chunk';
|
||||
export * from './info/info-packet-chunk';
|
||||
export * from './info/info-system-name-chunk';
|
||||
|
||||
@@ -3,8 +3,12 @@ import { PacketHeaderChunk } from '../packet-header-chunk';
|
||||
import { InfoSystemNameChunk } from './info-system-name-chunk';
|
||||
import { InfoTrackerListChunk } from './info-tracker-list-chunk';
|
||||
|
||||
export interface InfoPacketChunk extends Chunk {
|
||||
packet_header: PacketHeaderChunk;
|
||||
system_name: InfoSystemNameChunk;
|
||||
tracker_list: InfoTrackerListChunk;
|
||||
export interface InfoPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
systemName?: InfoSystemNameChunk;
|
||||
trackerList?: InfoTrackerListChunk;
|
||||
}
|
||||
export interface InfoPacketChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoPacketChunkData;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface InfoSystemNameChunk extends Chunk {
|
||||
system_name: string;
|
||||
export interface InfoSystemNameChunkData {
|
||||
systemName: string;
|
||||
}
|
||||
|
||||
export interface InfoSystemNameChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoSystemNameChunkData;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { InfoTrackerNameChunk } from './info-tracker-name-chunk';
|
||||
|
||||
export interface InfoTrackerChunk extends Chunk {
|
||||
tracker_name?: InfoTrackerNameChunk;
|
||||
export interface InfoTrackerChunkData {
|
||||
trackerName: InfoTrackerNameChunk;
|
||||
}
|
||||
|
||||
export interface InfoTrackerChunk {
|
||||
chunk: Chunk;
|
||||
data?: InfoTrackerChunkData;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Chunk } from '../chunk';
|
||||
import { InfoTrackerChunk } from './info-tracker-chunk';
|
||||
|
||||
export interface InfoTrackerListChunk extends Chunk {
|
||||
trackers: {
|
||||
[key: number]: InfoTrackerChunk;
|
||||
};
|
||||
export interface InfoTrackerListChunkData {
|
||||
trackers: InfoTrackerChunk[];
|
||||
}
|
||||
|
||||
export interface InfoTrackerListChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerListChunkData;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { Chunk } from '../chunk';
|
||||
|
||||
export interface InfoTrackerNameChunk extends Chunk {
|
||||
tracker_name: string;
|
||||
export interface InfoTrackerNameChunkData {
|
||||
trackerName: string;
|
||||
}
|
||||
|
||||
export interface InfoTrackerNameChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerNameChunkData;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { Chunk } from './chunk';
|
||||
|
||||
export interface PacketHeaderChunk extends Chunk {
|
||||
packet_timestamp?: bigint;
|
||||
version_high?: number;
|
||||
version_low?: number;
|
||||
frame_id?: number;
|
||||
frame_packet_count?: number;
|
||||
export interface PacketHeaderChunkData {
|
||||
packetTimestamp: bigint;
|
||||
versionHigh: number;
|
||||
versionLow: number;
|
||||
frameId: number;
|
||||
framePacketCount: number;
|
||||
}
|
||||
|
||||
export interface PacketHeaderChunk {
|
||||
chunk: Chunk;
|
||||
data: PacketHeaderChunkData;
|
||||
}
|
||||
|
||||
+137
-15
@@ -8,16 +8,24 @@ import dataTrackerTimestampChunk from '../encoders/data/data-tracker-timestamp-c
|
||||
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;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
|
||||
export class Tracker {
|
||||
id: number;
|
||||
name: string;
|
||||
pos?: [number, number, number];
|
||||
speed?: [number, number, number];
|
||||
ori?: [number, number, number];
|
||||
pos?: XYZData;
|
||||
speed?: XYZData;
|
||||
ori?: XYZData;
|
||||
validity?: number;
|
||||
accel?: [number, number, number];
|
||||
trgtpos?: [number, number, number];
|
||||
accel?: XYZData;
|
||||
trgtpos?: XYZData;
|
||||
timestamp?: bigint;
|
||||
|
||||
constructor(id: number, name: string) {
|
||||
@@ -33,15 +41,45 @@ export class Tracker {
|
||||
}
|
||||
|
||||
setPos(x: number, y: number, z: number) {
|
||||
this.pos = [x, y, z];
|
||||
if (this.pos === undefined) {
|
||||
this.pos = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.pos.x = x;
|
||||
this.pos.y = y;
|
||||
this.pos.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setSpeed(x: number, y: number, z: number) {
|
||||
this.speed = [x, y, z];
|
||||
if (this.speed === undefined) {
|
||||
this.speed = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.speed.x = x;
|
||||
this.speed.y = y;
|
||||
this.speed.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setOri(x: number, y: number, z: number) {
|
||||
this.ori = [x, y, z];
|
||||
if (this.ori === undefined) {
|
||||
this.ori = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.ori.x = x;
|
||||
this.ori.y = y;
|
||||
this.ori.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setStatus(validity: number) {
|
||||
@@ -49,11 +87,31 @@ export class Tracker {
|
||||
}
|
||||
|
||||
setAccel(x: number, y: number, z: number) {
|
||||
this.accel = [x, y, z];
|
||||
if (this.accel === undefined) {
|
||||
this.accel = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.accel.x = x;
|
||||
this.accel.y = y;
|
||||
this.accel.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setTrgtPos(x: number, y: number, z: number) {
|
||||
this.trgtpos = [x, y, z];
|
||||
if (this.trgtpos === undefined) {
|
||||
this.trgtpos = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.trgtpos.x = x;
|
||||
this.trgtpos.y = y;
|
||||
this.trgtpos.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
setTimestamp(timestamp: bigint) {
|
||||
@@ -64,15 +122,15 @@ export class Tracker {
|
||||
const fieldChunks: Uint8Array[] = [];
|
||||
|
||||
if (this.pos) {
|
||||
fieldChunks.push(dataTrackerPosChunk(...this.pos));
|
||||
fieldChunks.push(dataTrackerPosChunk(this.pos.x, this.pos.y, this.pos.z));
|
||||
}
|
||||
|
||||
if (this.speed) {
|
||||
fieldChunks.push(dataTrackerSpeedChunk(...this.speed));
|
||||
fieldChunks.push(dataTrackerSpeedChunk(this.speed.x, this.speed.y, this.speed.z));
|
||||
}
|
||||
|
||||
if (this.ori) {
|
||||
fieldChunks.push(dataTrackerOriChunk(...this.ori));
|
||||
fieldChunks.push(dataTrackerOriChunk(this.ori.x, this.ori.y, this.ori.z));
|
||||
}
|
||||
|
||||
if (this.validity) {
|
||||
@@ -80,11 +138,11 @@ export class Tracker {
|
||||
}
|
||||
|
||||
if (this.accel) {
|
||||
fieldChunks.push(dataTrackerAccelChunk(...this.accel));
|
||||
fieldChunks.push(dataTrackerAccelChunk(this.accel.x, this.accel.y, this.accel.z));
|
||||
}
|
||||
|
||||
if (this.trgtpos) {
|
||||
fieldChunks.push(dataTrackerTrgtposChunk(...this.trgtpos));
|
||||
fieldChunks.push(dataTrackerTrgtposChunk(this.trgtpos.x, this.trgtpos.y, this.trgtpos.z));
|
||||
}
|
||||
|
||||
if (this.timestamp) {
|
||||
@@ -97,4 +155,68 @@ export class Tracker {
|
||||
getInfoChunk() {
|
||||
return infoTrackerChunk(this.id, infoTrackerNameChunk(this.name));
|
||||
}
|
||||
|
||||
updateInfo(infoTrackerChunk: InfoTrackerChunk) {
|
||||
if (infoTrackerChunk.data) {
|
||||
this.name = infoTrackerChunk.data.trackerName.data.trackerName;
|
||||
}
|
||||
}
|
||||
|
||||
updateData(dataTrackerChunk: DataTrackerChunk) {
|
||||
if (dataTrackerChunk.data.pos) {
|
||||
this.setPos(dataTrackerChunk.data.pos.data.x, dataTrackerChunk.data.pos.data.y, dataTrackerChunk.data.pos.data.z);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.speed) {
|
||||
this.setSpeed(
|
||||
dataTrackerChunk.data.speed.data.x,
|
||||
dataTrackerChunk.data.speed.data.y,
|
||||
dataTrackerChunk.data.speed.data.z
|
||||
);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.ori) {
|
||||
this.setOri(dataTrackerChunk.data.ori.data.x, dataTrackerChunk.data.ori.data.y, dataTrackerChunk.data.ori.data.z);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.status) {
|
||||
this.setStatus(dataTrackerChunk.data.status.data.validity);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.accel) {
|
||||
this.setAccel(
|
||||
dataTrackerChunk.data.accel.data.x,
|
||||
dataTrackerChunk.data.accel.data.y,
|
||||
dataTrackerChunk.data.accel.data.z
|
||||
);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.trgtpos) {
|
||||
this.setTrgtPos(
|
||||
dataTrackerChunk.data.trgtpos.data.x,
|
||||
dataTrackerChunk.data.trgtpos.data.y,
|
||||
dataTrackerChunk.data.trgtpos.data.z
|
||||
);
|
||||
}
|
||||
|
||||
if (dataTrackerChunk.data.timestamp) {
|
||||
this.setTimestamp(dataTrackerChunk.data.timestamp.data.timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function TrackerFromInfo(infoTrackerChunk: InfoTrackerChunk) {
|
||||
if (infoTrackerChunk.data) {
|
||||
return new Tracker(infoTrackerChunk.chunk.header.id, infoTrackerChunk.data.trackerName.data.trackerName);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function TrackerFromData(dataTrackerChunk: DataTrackerChunk) {
|
||||
if (dataTrackerChunk.data) {
|
||||
const tracker = new Tracker(dataTrackerChunk.chunk.header.id, '');
|
||||
tracker.updateData(dataTrackerChunk);
|
||||
return tracker;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user