mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-18 05:34:15 +00:00
format
This commit is contained in:
+3
-3
@@ -1,5 +1,5 @@
|
||||
export class Constants {
|
||||
static readonly PACKET_HEADER_SIZE = 16;
|
||||
static readonly MAX_UDP_PACKET_SIZE = 1500;
|
||||
static readonly CHUNK_HEADER_SIZE = 4;
|
||||
static readonly PACKET_HEADER_SIZE = 16;
|
||||
static readonly MAX_UDP_PACKET_SIZE = 1500;
|
||||
static readonly CHUNK_HEADER_SIZE = 4;
|
||||
}
|
||||
|
||||
+116
-102
@@ -1,119 +1,133 @@
|
||||
import { Decoders } from './index.js';
|
||||
import {
|
||||
type DataPacketChunk,
|
||||
type InfoPacketChunk,
|
||||
Tracker,
|
||||
TrackerFromData,
|
||||
TrackerFromInfo,
|
||||
type DataPacketChunk,
|
||||
type InfoPacketChunk,
|
||||
Tracker,
|
||||
TrackerFromData,
|
||||
TrackerFromInfo,
|
||||
} from './models/index.js';
|
||||
|
||||
export class Decoder {
|
||||
infoPacketFrames: { [key: number]: InfoPacketChunk[] } = {};
|
||||
infoPacketFrames: { [key: number]: InfoPacketChunk[] } = {};
|
||||
|
||||
dataPacketFrames: { [key: number]: DataPacketChunk[] } = {};
|
||||
dataPacketFrames: { [key: number]: DataPacketChunk[] } = {};
|
||||
|
||||
trackers: { [key: string]: Tracker } = {};
|
||||
trackers: { [key: string]: Tracker } = {};
|
||||
|
||||
systemName: string = '';
|
||||
constructor() {}
|
||||
systemName: string = '';
|
||||
constructor() {}
|
||||
|
||||
updateInfo(framePackets: InfoPacketChunk[]) {
|
||||
framePackets.forEach((packet) => {
|
||||
if (packet.data.systemName?.data) {
|
||||
this.systemName = packet.data.systemName?.data.systemName;
|
||||
}
|
||||
updateInfo(framePackets: InfoPacketChunk[]) {
|
||||
framePackets.forEach((packet) => {
|
||||
if (packet.data.systemName?.data) {
|
||||
this.systemName = packet.data.systemName?.data.systemName;
|
||||
}
|
||||
|
||||
if (packet.data.trackerList?.data) {
|
||||
packet.data.trackerList.data.trackers.forEach((infoTrackerChunk) => {
|
||||
if (!this.trackers[infoTrackerChunk.chunk.header.id]) {
|
||||
const tracker = TrackerFromInfo(infoTrackerChunk);
|
||||
if (tracker) {
|
||||
this.trackers[infoTrackerChunk.chunk.header.id] = tracker;
|
||||
}
|
||||
}
|
||||
const tracker = this.trackers[infoTrackerChunk.chunk.header.id];
|
||||
tracker.updateInfo(infoTrackerChunk);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (packet.data.trackerList?.data) {
|
||||
packet.data.trackerList.data.trackers.forEach((infoTrackerChunk) => {
|
||||
if (!this.trackers[infoTrackerChunk.chunk.header.id]) {
|
||||
const tracker = TrackerFromInfo(infoTrackerChunk);
|
||||
if (tracker) {
|
||||
this.trackers[infoTrackerChunk.chunk.header.id] = tracker;
|
||||
}
|
||||
}
|
||||
const tracker = this.trackers[infoTrackerChunk.chunk.header.id];
|
||||
tracker.updateInfo(infoTrackerChunk);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateData(framePackets: DataPacketChunk[]) {
|
||||
framePackets.forEach((packet) => {
|
||||
if (packet.data.trackerList) {
|
||||
packet.data.trackerList?.data.trackers.forEach((dataTrackerChunk) => {
|
||||
if (!this.trackers[dataTrackerChunk.chunk.header.id]) {
|
||||
const tracker = TrackerFromData(dataTrackerChunk);
|
||||
if (tracker) {
|
||||
this.trackers[dataTrackerChunk.chunk.header.id] = tracker;
|
||||
}
|
||||
}
|
||||
const tracker = this.trackers[dataTrackerChunk.chunk.header.id];
|
||||
tracker.updateData(dataTrackerChunk);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
updateData(framePackets: DataPacketChunk[]) {
|
||||
framePackets.forEach((packet) => {
|
||||
if (packet.data.trackerList) {
|
||||
packet.data.trackerList?.data.trackers.forEach((dataTrackerChunk) => {
|
||||
if (!this.trackers[dataTrackerChunk.chunk.header.id]) {
|
||||
const tracker = TrackerFromData(dataTrackerChunk);
|
||||
if (tracker) {
|
||||
this.trackers[dataTrackerChunk.chunk.header.id] = tracker;
|
||||
}
|
||||
}
|
||||
const tracker = this.trackers[dataTrackerChunk.chunk.header.id];
|
||||
tracker.updateData(dataTrackerChunk);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO(jwetzell): add invalid frame id decoding. Scenario where a frame id is reused before one is complete
|
||||
decode(packetBuf: Uint8Array) {
|
||||
const packet = Decoders.Chunk(packetBuf);
|
||||
if (packet === undefined) {
|
||||
return packet;
|
||||
}
|
||||
// TODO(jwetzell): add invalid frame id decoding. Scenario where a frame id is reused before one is complete
|
||||
decode(packetBuf: Uint8Array) {
|
||||
const packet = Decoders.Chunk(packetBuf);
|
||||
if (packet === undefined) {
|
||||
return packet;
|
||||
}
|
||||
|
||||
if (packet.header.id === 0x6756) {
|
||||
const infoPacket = Decoders.InfoPacketChunk(packetBuf);
|
||||
if (infoPacket && infoPacket.chunk.header.hasSubchunks) {
|
||||
const currentInfoPacketHeader = infoPacket.data.packetHeader;
|
||||
if (!currentInfoPacketHeader) {
|
||||
// NOTE(jwetzell): not sure that info packets without a header subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
if (packet.header.id === 0x6756) {
|
||||
const infoPacket = Decoders.InfoPacketChunk(packetBuf);
|
||||
if (infoPacket && infoPacket.chunk.header.hasSubchunks) {
|
||||
const currentInfoPacketHeader = infoPacket.data.packetHeader;
|
||||
if (!currentInfoPacketHeader) {
|
||||
// NOTE(jwetzell): not sure that info packets without a header subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
|
||||
const systemSubChunk = infoPacket.data.systemName;
|
||||
if (!systemSubChunk) {
|
||||
// NOTE(jwetzell): not sure that info packets without a system subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
if (currentInfoPacketHeader.data.frameId) {
|
||||
if (this.infoPacketFrames[currentInfoPacketHeader.data.frameId] === undefined) {
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId] = [];
|
||||
}
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId].push(infoPacket);
|
||||
const systemSubChunk = infoPacket.data.systemName;
|
||||
if (!systemSubChunk) {
|
||||
// NOTE(jwetzell): not sure that info packets without a system subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
if (currentInfoPacketHeader.data.frameId) {
|
||||
if (
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId] ===
|
||||
undefined
|
||||
) {
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId] = [];
|
||||
}
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId].push(
|
||||
infoPacket
|
||||
);
|
||||
|
||||
if (
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId].length ===
|
||||
currentInfoPacketHeader.data.framePacketCount
|
||||
) {
|
||||
this.updateInfo(this.infoPacketFrames[currentInfoPacketHeader.data.frameId]);
|
||||
delete this.infoPacketFrames[currentInfoPacketHeader.data.frameId];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (packet.header.id === 0x6755) {
|
||||
const dataPacket = Decoders.DataPacketChunk(packetBuf);
|
||||
if (dataPacket.chunk.header.hasSubchunks) {
|
||||
const currentDataPacketHeader = dataPacket.data.packetHeader;
|
||||
if (!currentDataPacketHeader) {
|
||||
// NOTE(jwetzell): not sure that info packets without a header subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
if (
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId]
|
||||
.length === currentInfoPacketHeader.data.framePacketCount
|
||||
) {
|
||||
this.updateInfo(
|
||||
this.infoPacketFrames[currentInfoPacketHeader.data.frameId]
|
||||
);
|
||||
delete this.infoPacketFrames[currentInfoPacketHeader.data.frameId];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (packet.header.id === 0x6755) {
|
||||
const dataPacket = Decoders.DataPacketChunk(packetBuf);
|
||||
if (dataPacket.chunk.header.hasSubchunks) {
|
||||
const currentDataPacketHeader = dataPacket.data.packetHeader;
|
||||
if (!currentDataPacketHeader) {
|
||||
// NOTE(jwetzell): not sure that info packets without a header subchunk are valid?
|
||||
throw new Error('malformed packet');
|
||||
}
|
||||
|
||||
if (currentDataPacketHeader.data.frameId) {
|
||||
if (this.dataPacketFrames[currentDataPacketHeader.data.frameId] === undefined) {
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId] = [];
|
||||
}
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId].push(dataPacket);
|
||||
if (
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId].length ===
|
||||
currentDataPacketHeader.data.framePacketCount
|
||||
) {
|
||||
this.updateData(this.dataPacketFrames[currentDataPacketHeader.data.frameId]);
|
||||
delete this.dataPacketFrames[currentDataPacketHeader.data.frameId];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentDataPacketHeader.data.frameId) {
|
||||
if (
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId] ===
|
||||
undefined
|
||||
) {
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId] = [];
|
||||
}
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId].push(
|
||||
dataPacket
|
||||
);
|
||||
if (
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId]
|
||||
.length === currentDataPacketHeader.data.framePacketCount
|
||||
) {
|
||||
this.updateData(
|
||||
this.dataPacketFrames[currentDataPacketHeader.data.frameId]
|
||||
);
|
||||
delete this.dataPacketFrames[currentDataPacketHeader.data.frameId];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-19
@@ -1,29 +1,31 @@
|
||||
import type { Chunk } from '../models/chunk.js';
|
||||
|
||||
export default (buffer: Uint8Array): Chunk => {
|
||||
if (buffer.length < 4) {
|
||||
throw new Error('Chunk buffer must be at least 4 bytes');
|
||||
}
|
||||
if (buffer.length < 4) {
|
||||
throw new Error('Chunk buffer must be at least 4 bytes');
|
||||
}
|
||||
|
||||
const id = (buffer[1] << 8) + buffer[0];
|
||||
const id = (buffer[1] << 8) + buffer[0];
|
||||
|
||||
// NOTE(jwetzell): this data is split up as 1 bit for hasSubchunks and 15 bits for the dataLen
|
||||
const combinedLengthAndFlag = (buffer[3] << 8) + buffer[2];
|
||||
const hasSubchunks = combinedLengthAndFlag > 32768;
|
||||
const dataLen = hasSubchunks ? combinedLengthAndFlag - 32768 : combinedLengthAndFlag;
|
||||
// NOTE(jwetzell): this data is split up as 1 bit for hasSubchunks and 15 bits for the dataLen
|
||||
const combinedLengthAndFlag = (buffer[3] << 8) + buffer[2];
|
||||
const hasSubchunks = combinedLengthAndFlag > 32768;
|
||||
const dataLen = hasSubchunks
|
||||
? combinedLengthAndFlag - 32768
|
||||
: combinedLengthAndFlag;
|
||||
|
||||
const header = {
|
||||
id,
|
||||
dataLen,
|
||||
hasSubchunks,
|
||||
};
|
||||
const header = {
|
||||
id,
|
||||
dataLen,
|
||||
hasSubchunks,
|
||||
};
|
||||
|
||||
const chunkData = buffer.subarray(4, 4 + header.dataLen);
|
||||
const chunkData = buffer.subarray(4, 4 + header.dataLen);
|
||||
|
||||
const chunk = {
|
||||
chunkData,
|
||||
header,
|
||||
};
|
||||
const chunk = {
|
||||
chunkData,
|
||||
header,
|
||||
};
|
||||
|
||||
return chunk;
|
||||
return chunk;
|
||||
};
|
||||
|
||||
@@ -1,39 +1,48 @@
|
||||
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';
|
||||
|
||||
export default (buffer: Uint8Array): DataPacketChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: DataPacketChunkData = {};
|
||||
const data: DataPacketChunkData = {};
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.packetHeader.chunk.header.dataLen) {
|
||||
offset += data.packetHeader.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0001:
|
||||
data.trackerList = Decoders.DataTrackerListChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.trackerList.chunk.header.dataLen) {
|
||||
offset += data.trackerList.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId =
|
||||
(chunk.chunkData.subarray(offset)[1] << 8) +
|
||||
chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.packetHeader.chunk.header.dataLen) {
|
||||
offset += data.packetHeader.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0001:
|
||||
data.trackerList = Decoders.DataTrackerListChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.trackerList.chunk.header.dataLen) {
|
||||
offset += data.trackerList.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,46 +1,65 @@
|
||||
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';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const data: DataTrackerChunkData = {};
|
||||
if (chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const trackerFieldChunk = Decoders.Chunk(chunk.chunkData.subarray(offset));
|
||||
switch (trackerFieldChunk.header.id) {
|
||||
case 0x0000:
|
||||
data.pos = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0001:
|
||||
data.speed = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0002:
|
||||
data.ori = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0003:
|
||||
data.status = Decoders.DataTrackerStatusChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0004:
|
||||
data.accel = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0005:
|
||||
data.trgtpos = Decoders.DataTrackerXYZChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
case 0x0006:
|
||||
data.timestamp = Decoders.DataTrackerTimestampChunk(chunk.chunkData.subarray(offset));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
offset += trackerFieldChunk.header.dataLen;
|
||||
}
|
||||
}
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const data: DataTrackerChunkData = {};
|
||||
if (chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const trackerFieldChunk = Decoders.Chunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
switch (trackerFieldChunk.header.id) {
|
||||
case 0x0000:
|
||||
data.pos = Decoders.DataTrackerXYZChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
break;
|
||||
case 0x0001:
|
||||
data.speed = Decoders.DataTrackerXYZChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
break;
|
||||
case 0x0002:
|
||||
data.ori = Decoders.DataTrackerXYZChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
break;
|
||||
case 0x0003:
|
||||
data.status = Decoders.DataTrackerStatusChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
break;
|
||||
case 0x0004:
|
||||
data.accel = Decoders.DataTrackerXYZChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
break;
|
||||
case 0x0005:
|
||||
data.trgtpos = Decoders.DataTrackerXYZChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
break;
|
||||
case 0x0006:
|
||||
data.timestamp = Decoders.DataTrackerTimestampChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
offset += trackerFieldChunk.header.dataLen;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
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 { Decoders } from '../index.js';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerListChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const trackers: DataTrackerChunk[] = [];
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const trackers: DataTrackerChunk[] = [];
|
||||
|
||||
// TODO(jwetzell): add error handling
|
||||
if (chunk.chunkData) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.chunkData.length) {
|
||||
const trackerChunk = Decoders.DataTrackerChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerChunk.chunk.header.dataLen) {
|
||||
offset += trackerChunk.chunk.header.dataLen;
|
||||
}
|
||||
if (trackerChunk.chunk.header.id !== undefined) {
|
||||
trackers.push(trackerChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO(jwetzell): add error handling
|
||||
if (chunk.chunkData) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.chunkData.length) {
|
||||
const trackerChunk = Decoders.DataTrackerChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerChunk.chunk.header.dataLen) {
|
||||
offset += trackerChunk.chunk.header.dataLen;
|
||||
}
|
||||
if (trackerChunk.chunk.header.id !== undefined) {
|
||||
trackers.push(trackerChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const data: DataTrackerListChunkData = {
|
||||
trackers,
|
||||
};
|
||||
const data: DataTrackerListChunkData = {
|
||||
trackers,
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import type {
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerStatusChunkData,
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerStatusChunkData,
|
||||
} from '../../models/data/data-tracker-status-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerStatusChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const validity = view.getFloat32(0, true);
|
||||
const view = new DataView(
|
||||
chunk.chunkData.buffer,
|
||||
chunk.chunkData.byteOffset,
|
||||
chunk.chunkData.byteLength
|
||||
);
|
||||
const validity = view.getFloat32(0, true);
|
||||
|
||||
const data: DataTrackerStatusChunkData = {
|
||||
validity,
|
||||
};
|
||||
const data: DataTrackerStatusChunkData = {
|
||||
validity,
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import type {
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerTimestampChunkData,
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerTimestampChunkData,
|
||||
} from '../../models/data/data-tracker-timestamp-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerTimestampChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const timestamp = view.getBigUint64(0, true);
|
||||
const view = new DataView(
|
||||
chunk.chunkData.buffer,
|
||||
chunk.chunkData.byteOffset,
|
||||
chunk.chunkData.byteLength
|
||||
);
|
||||
const timestamp = view.getBigUint64(0, true);
|
||||
|
||||
const data: DataTrackerTimestampChunkData = {
|
||||
timestamp,
|
||||
};
|
||||
const data: DataTrackerTimestampChunkData = {
|
||||
timestamp,
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
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';
|
||||
|
||||
export default (buffer: Uint8Array): DataTrackerXYZChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
// TODO(jwetzell): add error handling
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
// TODO(jwetzell): add error handling
|
||||
const view = new DataView(
|
||||
chunk.chunkData.buffer,
|
||||
chunk.chunkData.byteOffset,
|
||||
chunk.chunkData.byteLength
|
||||
);
|
||||
|
||||
const data: DataTrackerXYZChunkData = {
|
||||
x: view.getFloat32(0, true),
|
||||
y: view.getFloat32(4, true),
|
||||
z: view.getFloat32(8, true),
|
||||
};
|
||||
const data: DataTrackerXYZChunkData = {
|
||||
x: view.getFloat32(0, true),
|
||||
y: view.getFloat32(4, true),
|
||||
z: view.getFloat32(8, true),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
+13
-13
@@ -15,17 +15,17 @@ import InfoTrackerListChunk from './info/info-tracker-list-chunk.js';
|
||||
import InfoTrackerNameChunk from './info/info-tracker-name-chunk.js';
|
||||
|
||||
export const Decoders = {
|
||||
Chunk,
|
||||
PacketHeaderChunk,
|
||||
DataPacketChunk,
|
||||
DataTrackerChunk,
|
||||
DataTrackerXYZChunk,
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerListChunk,
|
||||
InfoPacketChunk,
|
||||
InfoSystemNameChunk,
|
||||
InfoTrackerChunk,
|
||||
InfoTrackerListChunk,
|
||||
InfoTrackerNameChunk,
|
||||
Chunk,
|
||||
PacketHeaderChunk,
|
||||
DataPacketChunk,
|
||||
DataTrackerChunk,
|
||||
DataTrackerXYZChunk,
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerListChunk,
|
||||
InfoPacketChunk,
|
||||
InfoSystemNameChunk,
|
||||
InfoTrackerChunk,
|
||||
InfoTrackerListChunk,
|
||||
InfoTrackerNameChunk,
|
||||
};
|
||||
|
||||
@@ -1,46 +1,57 @@
|
||||
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';
|
||||
|
||||
export default (buffer: Uint8Array): InfoPacketChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoPacketChunkData = {};
|
||||
const data: InfoPacketChunkData = {};
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.packetHeader?.chunk.header.dataLen) {
|
||||
offset += data.packetHeader.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0001:
|
||||
data.systemName = Decoders.InfoSystemNameChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.systemName?.chunk.header.dataLen) {
|
||||
offset += data.systemName?.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0002:
|
||||
data.trackerList = Decoders.InfoTrackerListChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.trackerList?.chunk.header.dataLen) {
|
||||
offset += data.trackerList.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId =
|
||||
(chunk.chunkData.subarray(offset)[1] << 8) +
|
||||
chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.packetHeader?.chunk.header.dataLen) {
|
||||
offset += data.packetHeader.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0001:
|
||||
data.systemName = Decoders.InfoSystemNameChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.systemName?.chunk.header.dataLen) {
|
||||
offset += data.systemName?.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0002:
|
||||
data.trackerList = Decoders.InfoTrackerListChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.trackerList?.chunk.header.dataLen) {
|
||||
offset += data.trackerList.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
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';
|
||||
|
||||
const nameDecoder = new TextDecoder();
|
||||
export default (buffer: Uint8Array): InfoSystemNameChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoSystemNameChunkData = {
|
||||
systemName: nameDecoder.decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
const data: InfoSystemNameChunkData = {
|
||||
systemName: nameDecoder.decode(
|
||||
chunk.chunkData.subarray(0, chunk.header.dataLen)
|
||||
),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,35 +1,42 @@
|
||||
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';
|
||||
|
||||
export default (buffer: Uint8Array): InfoTrackerChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId = (chunk.chunkData.subarray(offset)[1] << 8) + chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000: {
|
||||
const data: InfoTrackerChunkData = {
|
||||
trackerName: Decoders.InfoTrackerNameChunk(chunk.chunkData.subarray(offset)),
|
||||
};
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.trackerName.chunk.header.dataLen) {
|
||||
offset += data.trackerName.chunk.header.dataLen;
|
||||
}
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const chunkId =
|
||||
(chunk.chunkData.subarray(offset)[1] << 8) +
|
||||
chunk.chunkData.subarray(offset)[0];
|
||||
switch (chunkId) {
|
||||
case 0x0000: {
|
||||
const data: InfoTrackerChunkData = {
|
||||
trackerName: Decoders.InfoTrackerNameChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
),
|
||||
};
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (data.trackerName.chunk.header.dataLen) {
|
||||
offset += data.trackerName.chunk.header.dataLen;
|
||||
}
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
chunk,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
import { Constants } from '../../constants.js';
|
||||
import type { InfoTrackerChunk } from '../../models/info/info-tracker-chunk.js';
|
||||
import type { InfoTrackerListChunk, InfoTrackerListChunkData } from '../../models/info/info-tracker-list-chunk.js';
|
||||
import type {
|
||||
InfoTrackerListChunk,
|
||||
InfoTrackerListChunkData,
|
||||
} from '../../models/info/info-tracker-list-chunk.js';
|
||||
import { Decoders } from '../index.js';
|
||||
|
||||
export default (buffer: Uint8Array): InfoTrackerListChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const trackers: InfoTrackerChunk[] = [];
|
||||
const trackers: InfoTrackerChunk[] = [];
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData) {
|
||||
let offset = 0;
|
||||
if (chunk.header.dataLen) {
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const trackerChunk = Decoders.InfoTrackerChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerChunk.chunk.header.dataLen) {
|
||||
offset += trackerChunk.chunk.header.dataLen;
|
||||
}
|
||||
if (trackerChunk.chunk.header.id !== undefined) {
|
||||
trackers.push(trackerChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const data: InfoTrackerListChunkData = {
|
||||
trackers,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData) {
|
||||
let offset = 0;
|
||||
if (chunk.header.dataLen) {
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const trackerChunk = Decoders.InfoTrackerChunk(
|
||||
chunk.chunkData.subarray(offset)
|
||||
);
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerChunk.chunk.header.dataLen) {
|
||||
offset += trackerChunk.chunk.header.dataLen;
|
||||
}
|
||||
if (trackerChunk.chunk.header.id !== undefined) {
|
||||
trackers.push(trackerChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const data: InfoTrackerListChunkData = {
|
||||
trackers,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
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';
|
||||
|
||||
const nameDecoder = new TextDecoder();
|
||||
export default (buffer: Uint8Array): InfoTrackerNameChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoTrackerNameChunkData = {
|
||||
trackerName: nameDecoder.decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
const data: InfoTrackerNameChunkData = {
|
||||
trackerName: nameDecoder.decode(
|
||||
chunk.chunkData.subarray(0, chunk.header.dataLen)
|
||||
),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
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';
|
||||
|
||||
export default (buffer: Uint8Array): PacketHeaderChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
let packetTimestamp = BigInt(chunk.chunkData[7]) << BigInt(56);
|
||||
packetTimestamp += BigInt(chunk.chunkData[6]) << BigInt(48);
|
||||
packetTimestamp += BigInt(chunk.chunkData[5]) << BigInt(40);
|
||||
packetTimestamp += BigInt(chunk.chunkData[4]) << BigInt(32);
|
||||
packetTimestamp += BigInt(chunk.chunkData[3]) << BigInt(24);
|
||||
packetTimestamp += BigInt(chunk.chunkData[2]) << BigInt(16);
|
||||
packetTimestamp += BigInt(chunk.chunkData[1]) << BigInt(8);
|
||||
packetTimestamp += BigInt(chunk.chunkData[0]);
|
||||
const data: PacketHeaderChunkData = {
|
||||
packetTimestamp,
|
||||
versionHigh: chunk.chunkData[8],
|
||||
versionLow: chunk.chunkData[9],
|
||||
frameId: chunk.chunkData[10],
|
||||
framePacketCount: chunk.chunkData[11],
|
||||
};
|
||||
let packetTimestamp = BigInt(chunk.chunkData[7]) << BigInt(56);
|
||||
packetTimestamp += BigInt(chunk.chunkData[6]) << BigInt(48);
|
||||
packetTimestamp += BigInt(chunk.chunkData[5]) << BigInt(40);
|
||||
packetTimestamp += BigInt(chunk.chunkData[4]) << BigInt(32);
|
||||
packetTimestamp += BigInt(chunk.chunkData[3]) << BigInt(24);
|
||||
packetTimestamp += BigInt(chunk.chunkData[2]) << BigInt(16);
|
||||
packetTimestamp += BigInt(chunk.chunkData[1]) << BigInt(8);
|
||||
packetTimestamp += BigInt(chunk.chunkData[0]);
|
||||
const data: PacketHeaderChunkData = {
|
||||
packetTimestamp,
|
||||
versionHigh: chunk.chunkData[8],
|
||||
versionLow: chunk.chunkData[9],
|
||||
frameId: chunk.chunkData[10],
|
||||
framePacketCount: chunk.chunkData[11],
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
+133
-108
@@ -2,131 +2,156 @@ import { Constants } from './constants.js';
|
||||
import { Encoders, Tracker } from './index.js';
|
||||
|
||||
export class Encoder {
|
||||
private systemName: string;
|
||||
private versionHigh: number;
|
||||
private versionLow: number;
|
||||
dataFrameId: number = 1;
|
||||
infoFrameId: number = 1;
|
||||
constructor(systemName: string, versionHigh: number = 2, versionLow: number = 3) {
|
||||
this.systemName = systemName;
|
||||
this.versionHigh = versionHigh;
|
||||
this.versionLow = versionLow;
|
||||
}
|
||||
private systemName: string;
|
||||
private versionHigh: number;
|
||||
private versionLow: number;
|
||||
dataFrameId: number = 1;
|
||||
infoFrameId: number = 1;
|
||||
constructor(
|
||||
systemName: string,
|
||||
versionHigh: number = 2,
|
||||
versionLow: number = 3
|
||||
) {
|
||||
this.systemName = systemName;
|
||||
this.versionHigh = versionHigh;
|
||||
this.versionLow = versionLow;
|
||||
}
|
||||
|
||||
setSystemName(systemName: string) {
|
||||
this.systemName = systemName;
|
||||
}
|
||||
setVersionHigh(versionHigh: number) {
|
||||
this.versionHigh = versionHigh;
|
||||
}
|
||||
setSystemName(systemName: string) {
|
||||
this.systemName = systemName;
|
||||
}
|
||||
setVersionHigh(versionHigh: number) {
|
||||
this.versionHigh = versionHigh;
|
||||
}
|
||||
|
||||
setVersionLow(versionLow: number) {
|
||||
this.versionLow = versionLow;
|
||||
}
|
||||
setVersionLow(versionLow: number) {
|
||||
this.versionLow = versionLow;
|
||||
}
|
||||
|
||||
resetDataFrameId() {
|
||||
this.dataFrameId = 1;
|
||||
}
|
||||
resetDataFrameId() {
|
||||
this.dataFrameId = 1;
|
||||
}
|
||||
|
||||
resetInfoFrameId() {
|
||||
this.infoFrameId = 1;
|
||||
}
|
||||
resetInfoFrameId() {
|
||||
this.infoFrameId = 1;
|
||||
}
|
||||
|
||||
getInfoPackets(timestamp: bigint, trackers: Tracker[], frameId?: number) {
|
||||
if (frameId !== undefined) {
|
||||
if (!Number.isInteger(frameId)) {
|
||||
throw new Error('frame id must be an integer');
|
||||
}
|
||||
getInfoPackets(timestamp: bigint, trackers: Tracker[], frameId?: number) {
|
||||
if (frameId !== undefined) {
|
||||
if (!Number.isInteger(frameId)) {
|
||||
throw new Error('frame id must be an integer');
|
||||
}
|
||||
|
||||
if (frameId > 255 || frameId < 0) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
}
|
||||
if (frameId > 255 || frameId < 0) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
}
|
||||
|
||||
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[][] = [];
|
||||
let currentTrackerList: Uint8Array[] = [];
|
||||
const trackerChunksLists: 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) => {
|
||||
if (currentInfoPacketSize + trackerChunk.length > Constants.MAX_UDP_PACKET_SIZE) {
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
currentTrackerList = [];
|
||||
currentInfoPacketSize = 0;
|
||||
}
|
||||
currentTrackerList.push(trackerChunk);
|
||||
currentInfoPacketSize += trackerChunk.length;
|
||||
});
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
const header = Encoders.PacketHeaderChunk(
|
||||
timestamp,
|
||||
this.versionHigh,
|
||||
this.versionLow,
|
||||
frameId ? frameId : this.infoFrameId,
|
||||
trackerChunksLists.length
|
||||
);
|
||||
trackerChunksLists.forEach((trackerChunkList) => {
|
||||
infoPackets.push(
|
||||
Encoders.InfoPacketChunk(header, systemNameChunk, Encoders.InfoTrackerListChunk(trackerChunkList))
|
||||
);
|
||||
});
|
||||
this.infoFrameId += 1;
|
||||
if (this.infoFrameId > 255) {
|
||||
this.infoFrameId = 0;
|
||||
}
|
||||
return infoPackets;
|
||||
}
|
||||
trackerChunks.forEach((trackerChunk: Uint8Array) => {
|
||||
if (
|
||||
currentInfoPacketSize + trackerChunk.length >
|
||||
Constants.MAX_UDP_PACKET_SIZE
|
||||
) {
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
currentTrackerList = [];
|
||||
currentInfoPacketSize = 0;
|
||||
}
|
||||
currentTrackerList.push(trackerChunk);
|
||||
currentInfoPacketSize += trackerChunk.length;
|
||||
});
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
const header = Encoders.PacketHeaderChunk(
|
||||
timestamp,
|
||||
this.versionHigh,
|
||||
this.versionLow,
|
||||
frameId ? frameId : this.infoFrameId,
|
||||
trackerChunksLists.length
|
||||
);
|
||||
trackerChunksLists.forEach((trackerChunkList) => {
|
||||
infoPackets.push(
|
||||
Encoders.InfoPacketChunk(
|
||||
header,
|
||||
systemNameChunk,
|
||||
Encoders.InfoTrackerListChunk(trackerChunkList)
|
||||
)
|
||||
);
|
||||
});
|
||||
this.infoFrameId += 1;
|
||||
if (this.infoFrameId > 255) {
|
||||
this.infoFrameId = 0;
|
||||
}
|
||||
return infoPackets;
|
||||
}
|
||||
|
||||
getDataPackets(timestamp: bigint, trackers: Tracker[], frameId?: number) {
|
||||
if (frameId !== undefined) {
|
||||
if (!Number.isInteger(frameId)) {
|
||||
throw new Error('frame id must be an integer');
|
||||
}
|
||||
getDataPackets(timestamp: bigint, trackers: Tracker[], frameId?: number) {
|
||||
if (frameId !== undefined) {
|
||||
if (!Number.isInteger(frameId)) {
|
||||
throw new Error('frame id must be an integer');
|
||||
}
|
||||
|
||||
if (frameId > 255 || frameId < 0) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
}
|
||||
if (frameId > 255 || frameId < 0) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
}
|
||||
|
||||
const allTrackerChunks = trackers.map((tracker) => tracker.getDataChunk());
|
||||
const dataPackets: Uint8Array[] = [];
|
||||
const allTrackerChunks = trackers.map((tracker) => tracker.getDataChunk());
|
||||
const dataPackets: Uint8Array[] = [];
|
||||
|
||||
const trackerChunksLists: Uint8Array[][] = [];
|
||||
let currentTrackerList: Uint8Array[] = [];
|
||||
const trackerChunksLists: 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) => {
|
||||
if (currentDataPacketSize + trackerChunk.length > Constants.MAX_UDP_PACKET_SIZE) {
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
currentTrackerList = [];
|
||||
currentDataPacketSize = 0;
|
||||
}
|
||||
currentTrackerList.push(trackerChunk);
|
||||
currentDataPacketSize += trackerChunk.length;
|
||||
});
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
allTrackerChunks.forEach((trackerChunk) => {
|
||||
if (
|
||||
currentDataPacketSize + trackerChunk.length >
|
||||
Constants.MAX_UDP_PACKET_SIZE
|
||||
) {
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
currentTrackerList = [];
|
||||
currentDataPacketSize = 0;
|
||||
}
|
||||
currentTrackerList.push(trackerChunk);
|
||||
currentDataPacketSize += trackerChunk.length;
|
||||
});
|
||||
trackerChunksLists.push(currentTrackerList);
|
||||
|
||||
const header = Encoders.PacketHeaderChunk(
|
||||
timestamp,
|
||||
this.versionHigh,
|
||||
this.versionLow,
|
||||
frameId ? frameId : this.dataFrameId,
|
||||
trackerChunksLists.length
|
||||
);
|
||||
trackerChunksLists.forEach((trackerChunks) => {
|
||||
dataPackets.push(Encoders.DataPacketChunk(header, Encoders.DataTrackerListChunk(trackerChunks)));
|
||||
});
|
||||
this.dataFrameId += 1;
|
||||
if (this.dataFrameId > 255) {
|
||||
this.dataFrameId = 0;
|
||||
}
|
||||
return dataPackets;
|
||||
}
|
||||
const header = Encoders.PacketHeaderChunk(
|
||||
timestamp,
|
||||
this.versionHigh,
|
||||
this.versionLow,
|
||||
frameId ? frameId : this.dataFrameId,
|
||||
trackerChunksLists.length
|
||||
);
|
||||
trackerChunksLists.forEach((trackerChunks) => {
|
||||
dataPackets.push(
|
||||
Encoders.DataPacketChunk(
|
||||
header,
|
||||
Encoders.DataTrackerListChunk(trackerChunks)
|
||||
)
|
||||
);
|
||||
});
|
||||
this.dataFrameId += 1;
|
||||
if (this.dataFrameId > 255) {
|
||||
this.dataFrameId = 0;
|
||||
}
|
||||
return dataPackets;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-18
@@ -1,25 +1,29 @@
|
||||
const header = new DataView(new ArrayBuffer(4));
|
||||
export default (id: number, chunkData: Uint8Array, hasSubchunks: boolean): Uint8Array => {
|
||||
if (!Number.isInteger(id)) {
|
||||
throw new Error('chunk id must be an integer');
|
||||
}
|
||||
export default (
|
||||
id: number,
|
||||
chunkData: Uint8Array,
|
||||
hasSubchunks: boolean
|
||||
): Uint8Array => {
|
||||
if (!Number.isInteger(id)) {
|
||||
throw new Error('chunk id must be an integer');
|
||||
}
|
||||
|
||||
if (id > 0xffff || id < 0) {
|
||||
throw new Error('chunk id must be >= 0 and <= 65535');
|
||||
}
|
||||
if (id > 0xffff || id < 0) {
|
||||
throw new Error('chunk id must be >= 0 and <= 65535');
|
||||
}
|
||||
|
||||
if (chunkData.length > 0x7fff) {
|
||||
throw new Error('chunkData can not be greater than 32767 bytes');
|
||||
}
|
||||
if (chunkData.length > 0x7fff) {
|
||||
throw new Error('chunkData can not be greater than 32767 bytes');
|
||||
}
|
||||
|
||||
header.setUint16(0, id, true);
|
||||
const hasSubChunksBit = (hasSubchunks ? 1 : 0) << 15;
|
||||
header.setUint16(2, hasSubChunksBit + chunkData.length, true);
|
||||
header.setUint16(0, id, true);
|
||||
const hasSubChunksBit = (hasSubchunks ? 1 : 0) << 15;
|
||||
header.setUint16(2, hasSubChunksBit + chunkData.length, true);
|
||||
|
||||
const headerBytes = new Uint8Array(header.buffer);
|
||||
const headerBytes = new Uint8Array(header.buffer);
|
||||
|
||||
const bytes = new Uint8Array(headerBytes.length + chunkData.length);
|
||||
bytes.set(headerBytes);
|
||||
bytes.set(chunkData, headerBytes.length);
|
||||
return bytes;
|
||||
const bytes = new Uint8Array(headerBytes.length + chunkData.length);
|
||||
bytes.set(headerBytes);
|
||||
bytes.set(chunkData, headerBytes.length);
|
||||
return bytes;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import chunk from '../chunk.js';
|
||||
export default (packetHeaderChunk: Uint8Array, trackerListChunk: Uint8Array): Uint8Array => {
|
||||
const chunkData = new Uint8Array(packetHeaderChunk.length + trackerListChunk.length);
|
||||
chunkData.set(packetHeaderChunk);
|
||||
chunkData.set(trackerListChunk, packetHeaderChunk.length);
|
||||
return chunk(0x6755, chunkData, true);
|
||||
export default (
|
||||
packetHeaderChunk: Uint8Array,
|
||||
trackerListChunk: Uint8Array
|
||||
): Uint8Array => {
|
||||
const chunkData = new Uint8Array(
|
||||
packetHeaderChunk.length + trackerListChunk.length
|
||||
);
|
||||
chunkData.set(packetHeaderChunk);
|
||||
chunkData.set(trackerListChunk, packetHeaderChunk.length);
|
||||
return chunk(0x6755, chunkData, true);
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@ import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0004, new Uint8Array(floatArray.buffer), false);
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0004, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerId: number, fieldChunks: Uint8Array[]): Uint8Array => {
|
||||
let fieldChunksTotalLength = 0;
|
||||
let fieldChunksTotalLength = 0;
|
||||
|
||||
fieldChunks.forEach((fieldChunk) => {
|
||||
fieldChunksTotalLength += fieldChunk.length;
|
||||
});
|
||||
fieldChunks.forEach((fieldChunk) => {
|
||||
fieldChunksTotalLength += fieldChunk.length;
|
||||
});
|
||||
|
||||
const fieldChunksBytes = new Uint8Array(fieldChunksTotalLength);
|
||||
const fieldChunksBytes = new Uint8Array(fieldChunksTotalLength);
|
||||
|
||||
let offset = 0;
|
||||
let offset = 0;
|
||||
|
||||
fieldChunks.forEach((fieldChunk) => {
|
||||
fieldChunksBytes.set(fieldChunk, offset);
|
||||
offset += fieldChunk.length;
|
||||
});
|
||||
fieldChunks.forEach((fieldChunk) => {
|
||||
fieldChunksBytes.set(fieldChunk, offset);
|
||||
offset += fieldChunk.length;
|
||||
});
|
||||
|
||||
return chunk(trackerId, fieldChunksBytes, fieldChunks.length > 0);
|
||||
return chunk(trackerId, fieldChunksBytes, fieldChunks.length > 0);
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerChunks: Uint8Array[]) => {
|
||||
let trackerChunksTotalLength = 0;
|
||||
let trackerChunksTotalLength = 0;
|
||||
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksTotalLength += trackerChunk.length;
|
||||
});
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksTotalLength += trackerChunk.length;
|
||||
});
|
||||
|
||||
const trackerChunksBytes = new Uint8Array(trackerChunksTotalLength);
|
||||
const trackerChunksBytes = new Uint8Array(trackerChunksTotalLength);
|
||||
|
||||
let offset = 0;
|
||||
let offset = 0;
|
||||
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksBytes.set(trackerChunk, offset);
|
||||
offset += trackerChunk.length;
|
||||
});
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksBytes.set(trackerChunk, offset);
|
||||
offset += trackerChunk.length;
|
||||
});
|
||||
|
||||
return chunk(0x0001, trackerChunksBytes, true);
|
||||
return chunk(0x0001, trackerChunksBytes, true);
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@ import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0002, new Uint8Array(floatArray.buffer), false);
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
return chunk(0x0002, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@ import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
|
||||
return chunk(0x0000, new Uint8Array(floatArray.buffer), false);
|
||||
return chunk(0x0000, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@ import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
|
||||
return chunk(0x0001, new Uint8Array(floatArray.buffer), false);
|
||||
return chunk(0x0001, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -2,6 +2,6 @@ import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(1);
|
||||
export default (validity: number): Uint8Array => {
|
||||
floatArray[0] = validity;
|
||||
return chunk(0x0003, new Uint8Array(floatArray.buffer), false);
|
||||
floatArray[0] = validity;
|
||||
return chunk(0x0003, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
@@ -2,6 +2,6 @@ import chunk from '../chunk.js';
|
||||
|
||||
const buf = new DataView(new ArrayBuffer(8));
|
||||
export default (timestamp: bigint): Uint8Array => {
|
||||
buf.setBigUint64(0, BigInt(timestamp), true);
|
||||
return chunk(0x0006, new Uint8Array(buf.buffer), false);
|
||||
buf.setBigUint64(0, BigInt(timestamp), true);
|
||||
return chunk(0x0006, new Uint8Array(buf.buffer), false);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@ import chunk from '../chunk.js';
|
||||
|
||||
const floatArray = new Float32Array(3);
|
||||
export default (x: number, y: number, z: number): Uint8Array => {
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
floatArray[0] = x;
|
||||
floatArray[1] = y;
|
||||
floatArray[2] = z;
|
||||
|
||||
return chunk(0x0005, new Uint8Array(floatArray.buffer), false);
|
||||
return chunk(0x0005, new Uint8Array(floatArray.buffer), false);
|
||||
};
|
||||
|
||||
+17
-17
@@ -18,21 +18,21 @@ import InfoTrackerListChunk from './info/info-tracker-list-chunk.js';
|
||||
import InfoTrackerNameChunk from './info/info-tracker-name-chunk.js';
|
||||
|
||||
export const Encoders = {
|
||||
DataPacketChunk,
|
||||
DataTrackerAccelChunk,
|
||||
DataTrackerChunk,
|
||||
DataTrackerListChunk,
|
||||
DataTrackerOriChunk,
|
||||
DataTrackerPosChunk,
|
||||
DataTrackerSpeedChunk,
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerTrgtposChunk,
|
||||
InfoPacketChunk,
|
||||
InfoSystemNameChunk,
|
||||
InfoTrackerChunk,
|
||||
InfoTrackerListChunk,
|
||||
InfoTrackerNameChunk,
|
||||
PacketHeaderChunk,
|
||||
Chunk,
|
||||
DataPacketChunk,
|
||||
DataTrackerAccelChunk,
|
||||
DataTrackerChunk,
|
||||
DataTrackerListChunk,
|
||||
DataTrackerOriChunk,
|
||||
DataTrackerPosChunk,
|
||||
DataTrackerSpeedChunk,
|
||||
DataTrackerStatusChunk,
|
||||
DataTrackerTimestampChunk,
|
||||
DataTrackerTrgtposChunk,
|
||||
InfoPacketChunk,
|
||||
InfoSystemNameChunk,
|
||||
InfoTrackerChunk,
|
||||
InfoTrackerListChunk,
|
||||
InfoTrackerNameChunk,
|
||||
PacketHeaderChunk,
|
||||
Chunk,
|
||||
};
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (
|
||||
packetHeaderChunk: Uint8Array,
|
||||
systemNameChunk: Uint8Array,
|
||||
trackerListChunk: Uint8Array
|
||||
packetHeaderChunk: Uint8Array,
|
||||
systemNameChunk: Uint8Array,
|
||||
trackerListChunk: 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(systemNameChunk, packetHeaderChunk.length);
|
||||
chunkData.set(trackerListChunk, packetHeaderChunk.length + systemNameChunk.length);
|
||||
return chunk(0x6756, chunkData, true);
|
||||
chunkData.set(packetHeaderChunk);
|
||||
chunkData.set(systemNameChunk, packetHeaderChunk.length);
|
||||
chunkData.set(
|
||||
trackerListChunk,
|
||||
packetHeaderChunk.length + systemNameChunk.length
|
||||
);
|
||||
return chunk(0x6756, chunkData, true);
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import chunk from '../chunk.js';
|
||||
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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerId: number, trackerNameChunk: Uint8Array): Uint8Array =>
|
||||
chunk(trackerId, trackerNameChunk, true);
|
||||
chunk(trackerId, trackerNameChunk, true);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
export default (trackerChunks: Uint8Array[]): Uint8Array => {
|
||||
let trackerChunksTotalLength = 0;
|
||||
let trackerChunksTotalLength = 0;
|
||||
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksTotalLength += trackerChunk.length;
|
||||
});
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksTotalLength += trackerChunk.length;
|
||||
});
|
||||
|
||||
const trackerChunksBytes = new Uint8Array(trackerChunksTotalLength);
|
||||
const trackerChunksBytes = new Uint8Array(trackerChunksTotalLength);
|
||||
|
||||
let offset = 0;
|
||||
let offset = 0;
|
||||
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksBytes.set(trackerChunk, offset);
|
||||
offset += trackerChunk.length;
|
||||
});
|
||||
return chunk(0x0002, trackerChunksBytes, true);
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksBytes.set(trackerChunk, offset);
|
||||
offset += trackerChunk.length;
|
||||
});
|
||||
return chunk(0x0002, trackerChunksBytes, true);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
const nameEncoder = new TextEncoder();
|
||||
export default (trackerName: string) => chunk(0x0000, nameEncoder.encode(trackerName), false);
|
||||
export default (trackerName: string) =>
|
||||
chunk(0x0000, nameEncoder.encode(trackerName), false);
|
||||
|
||||
@@ -2,43 +2,43 @@ import chunk from './chunk.js';
|
||||
|
||||
const packetHeader = new DataView(new ArrayBuffer(12));
|
||||
export default (
|
||||
timestamp: bigint,
|
||||
versionHigh: number,
|
||||
versionLow: number,
|
||||
frameId: number,
|
||||
framePacketCount: number
|
||||
timestamp: bigint,
|
||||
versionHigh: number,
|
||||
versionLow: number,
|
||||
frameId: number,
|
||||
framePacketCount: number
|
||||
): Uint8Array => {
|
||||
if (!Number.isInteger(versionHigh)) {
|
||||
throw new Error('version high must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(versionLow)) {
|
||||
throw new Error('version low must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(frameId)) {
|
||||
throw new Error('frame id must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(framePacketCount)) {
|
||||
throw new Error('frame packet count must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(versionHigh)) {
|
||||
throw new Error('version high must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(versionLow)) {
|
||||
throw new Error('version low must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(frameId)) {
|
||||
throw new Error('frame id must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(framePacketCount)) {
|
||||
throw new Error('frame packet count must be an integer');
|
||||
}
|
||||
|
||||
if (versionHigh > 255 || versionHigh < 0) {
|
||||
throw new Error('version high must be >= 0 and <= 255');
|
||||
}
|
||||
if (versionLow > 255 || versionLow < 0) {
|
||||
throw new Error('version low must be >= 0 and <= 255');
|
||||
}
|
||||
if (frameId > 255 || frameId < 0) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
if (framePacketCount > 255 || framePacketCount < 0) {
|
||||
throw new Error('frame packet count must be >= 0 and <= 255');
|
||||
}
|
||||
if (versionHigh > 255 || versionHigh < 0) {
|
||||
throw new Error('version high must be >= 0 and <= 255');
|
||||
}
|
||||
if (versionLow > 255 || versionLow < 0) {
|
||||
throw new Error('version low must be >= 0 and <= 255');
|
||||
}
|
||||
if (frameId > 255 || frameId < 0) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
if (framePacketCount > 255 || framePacketCount < 0) {
|
||||
throw new Error('frame packet count must be >= 0 and <= 255');
|
||||
}
|
||||
|
||||
packetHeader.setBigUint64(0, BigInt(timestamp), true);
|
||||
packetHeader.setUint8(8, versionHigh);
|
||||
packetHeader.setUint8(9, versionLow);
|
||||
packetHeader.setUint8(10, frameId);
|
||||
packetHeader.setUint8(11, framePacketCount);
|
||||
packetHeader.setBigUint64(0, BigInt(timestamp), true);
|
||||
packetHeader.setUint8(8, versionHigh);
|
||||
packetHeader.setUint8(9, versionLow);
|
||||
packetHeader.setUint8(10, frameId);
|
||||
packetHeader.setUint8(11, framePacketCount);
|
||||
|
||||
return chunk(0x0000, new Uint8Array(packetHeader.buffer), false);
|
||||
return chunk(0x0000, new Uint8Array(packetHeader.buffer), false);
|
||||
};
|
||||
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
export interface ChunkHeader {
|
||||
id: number;
|
||||
dataLen: number;
|
||||
hasSubchunks: boolean;
|
||||
id: number;
|
||||
dataLen: number;
|
||||
hasSubchunks: boolean;
|
||||
}
|
||||
|
||||
export interface Chunk {
|
||||
chunkData: Uint8Array;
|
||||
header: ChunkHeader;
|
||||
chunkData: Uint8Array;
|
||||
header: ChunkHeader;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import type { PacketHeaderChunk } from '../packet-header-chunk.js';
|
||||
import type { DataTrackerListChunk } from './data-tracker-list-chunk.js';
|
||||
|
||||
export interface DataPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
trackerList?: DataTrackerListChunk;
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
trackerList?: DataTrackerListChunk;
|
||||
}
|
||||
|
||||
export interface DataPacketChunk {
|
||||
chunk: Chunk;
|
||||
data: DataPacketChunkData;
|
||||
chunk: Chunk;
|
||||
data: DataPacketChunkData;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,16 @@ import type { DataTrackerTimestampChunk } from './data-tracker-timestamp-chunk.j
|
||||
import type { DataTrackerXYZChunk } from './data-tracker-xyz-chunk.js';
|
||||
|
||||
export interface DataTrackerChunkData {
|
||||
pos?: DataTrackerXYZChunk;
|
||||
speed?: DataTrackerXYZChunk;
|
||||
ori?: DataTrackerXYZChunk;
|
||||
status?: DataTrackerStatusChunk;
|
||||
accel?: DataTrackerXYZChunk;
|
||||
trgtpos?: DataTrackerXYZChunk;
|
||||
timestamp?: DataTrackerTimestampChunk;
|
||||
pos?: DataTrackerXYZChunk;
|
||||
speed?: DataTrackerXYZChunk;
|
||||
ori?: DataTrackerXYZChunk;
|
||||
status?: DataTrackerStatusChunk;
|
||||
accel?: DataTrackerXYZChunk;
|
||||
trgtpos?: DataTrackerXYZChunk;
|
||||
timestamp?: DataTrackerTimestampChunk;
|
||||
}
|
||||
|
||||
export interface DataTrackerChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerChunkData;
|
||||
chunk: Chunk;
|
||||
data: DataTrackerChunkData;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ import type { Chunk } from '../chunk.js';
|
||||
import type { DataTrackerChunk } from './data-tracker-chunk.js';
|
||||
|
||||
export interface DataTrackerListChunkData {
|
||||
trackers: DataTrackerChunk[];
|
||||
trackers: DataTrackerChunk[];
|
||||
}
|
||||
|
||||
export interface DataTrackerListChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerListChunkData;
|
||||
chunk: Chunk;
|
||||
data: DataTrackerListChunkData;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
|
||||
export interface DataTrackerStatusChunkData {
|
||||
validity: number;
|
||||
validity: number;
|
||||
}
|
||||
|
||||
export interface DataTrackerStatusChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerStatusChunkData;
|
||||
chunk: Chunk;
|
||||
data: DataTrackerStatusChunkData;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
|
||||
export interface DataTrackerTimestampChunkData {
|
||||
timestamp: bigint;
|
||||
timestamp: bigint;
|
||||
}
|
||||
|
||||
export interface DataTrackerTimestampChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerTimestampChunkData;
|
||||
chunk: Chunk;
|
||||
data: DataTrackerTimestampChunkData;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
|
||||
export interface DataTrackerXYZChunkData {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
}
|
||||
|
||||
export interface DataTrackerXYZChunk {
|
||||
chunk: Chunk;
|
||||
data: DataTrackerXYZChunkData;
|
||||
chunk: Chunk;
|
||||
data: DataTrackerXYZChunkData;
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import type { InfoSystemNameChunk } from './info-system-name-chunk.js';
|
||||
import type { InfoTrackerListChunk } from './info-tracker-list-chunk.js';
|
||||
|
||||
export interface InfoPacketChunkData {
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
systemName?: InfoSystemNameChunk;
|
||||
trackerList?: InfoTrackerListChunk;
|
||||
packetHeader?: PacketHeaderChunk;
|
||||
systemName?: InfoSystemNameChunk;
|
||||
trackerList?: InfoTrackerListChunk;
|
||||
}
|
||||
export interface InfoPacketChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoPacketChunkData;
|
||||
chunk: Chunk;
|
||||
data: InfoPacketChunkData;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
|
||||
export interface InfoSystemNameChunkData {
|
||||
systemName: string;
|
||||
systemName: string;
|
||||
}
|
||||
|
||||
export interface InfoSystemNameChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoSystemNameChunkData;
|
||||
chunk: Chunk;
|
||||
data: InfoSystemNameChunkData;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ import type { Chunk } from '../chunk.js';
|
||||
import type { InfoTrackerNameChunk } from './info-tracker-name-chunk.js';
|
||||
|
||||
export interface InfoTrackerChunkData {
|
||||
trackerName: InfoTrackerNameChunk;
|
||||
trackerName: InfoTrackerNameChunk;
|
||||
}
|
||||
|
||||
export interface InfoTrackerChunk {
|
||||
chunk: Chunk;
|
||||
data?: InfoTrackerChunkData;
|
||||
chunk: Chunk;
|
||||
data?: InfoTrackerChunkData;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ import type { Chunk } from '../chunk.js';
|
||||
import type { InfoTrackerChunk } from './info-tracker-chunk.js';
|
||||
|
||||
export interface InfoTrackerListChunkData {
|
||||
trackers: InfoTrackerChunk[];
|
||||
trackers: InfoTrackerChunk[];
|
||||
}
|
||||
|
||||
export interface InfoTrackerListChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerListChunkData;
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerListChunkData;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Chunk } from '../chunk.js';
|
||||
|
||||
export interface InfoTrackerNameChunkData {
|
||||
trackerName: string;
|
||||
trackerName: string;
|
||||
}
|
||||
|
||||
export interface InfoTrackerNameChunk {
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerNameChunkData;
|
||||
chunk: Chunk;
|
||||
data: InfoTrackerNameChunkData;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { Chunk } from './chunk.js';
|
||||
|
||||
export interface PacketHeaderChunkData {
|
||||
packetTimestamp: bigint;
|
||||
versionHigh: number;
|
||||
versionLow: number;
|
||||
frameId: number;
|
||||
framePacketCount: number;
|
||||
packetTimestamp: bigint;
|
||||
versionHigh: number;
|
||||
versionLow: number;
|
||||
frameId: number;
|
||||
framePacketCount: number;
|
||||
}
|
||||
|
||||
export interface PacketHeaderChunk {
|
||||
chunk: Chunk;
|
||||
data: PacketHeaderChunkData;
|
||||
chunk: Chunk;
|
||||
data: PacketHeaderChunkData;
|
||||
}
|
||||
|
||||
+189
-172
@@ -12,211 +12,228 @@ import type { DataTrackerChunk } from './data/data-tracker-chunk.js';
|
||||
import type { InfoTrackerChunk } from './info/info-tracker-chunk.js';
|
||||
|
||||
export type XYZData = {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
|
||||
export class Tracker {
|
||||
id: number;
|
||||
name: string;
|
||||
pos?: XYZData;
|
||||
speed?: XYZData;
|
||||
ori?: XYZData;
|
||||
validity?: number;
|
||||
accel?: XYZData;
|
||||
trgtpos?: XYZData;
|
||||
timestamp?: bigint;
|
||||
id: number;
|
||||
name: string;
|
||||
pos?: XYZData;
|
||||
speed?: XYZData;
|
||||
ori?: XYZData;
|
||||
validity?: number;
|
||||
accel?: XYZData;
|
||||
trgtpos?: XYZData;
|
||||
timestamp?: bigint;
|
||||
|
||||
constructor(id: number, name: string) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.pos = undefined;
|
||||
this.speed = undefined;
|
||||
this.ori = undefined;
|
||||
this.validity = undefined;
|
||||
this.accel = undefined;
|
||||
this.trgtpos = undefined;
|
||||
this.timestamp = undefined;
|
||||
}
|
||||
constructor(id: number, name: string) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.pos = undefined;
|
||||
this.speed = undefined;
|
||||
this.ori = undefined;
|
||||
this.validity = undefined;
|
||||
this.accel = undefined;
|
||||
this.trgtpos = undefined;
|
||||
this.timestamp = undefined;
|
||||
}
|
||||
|
||||
setPos(x: number, y: number, z: number) {
|
||||
if (this.pos === undefined) {
|
||||
this.pos = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.pos.x = x;
|
||||
this.pos.y = y;
|
||||
this.pos.z = z;
|
||||
}
|
||||
}
|
||||
setPos(x: number, y: number, z: number) {
|
||||
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) {
|
||||
if (this.speed === undefined) {
|
||||
this.speed = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.speed.x = x;
|
||||
this.speed.y = y;
|
||||
this.speed.z = z;
|
||||
}
|
||||
}
|
||||
setSpeed(x: number, y: number, z: number) {
|
||||
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) {
|
||||
if (this.ori === undefined) {
|
||||
this.ori = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.ori.x = x;
|
||||
this.ori.y = y;
|
||||
this.ori.z = z;
|
||||
}
|
||||
}
|
||||
setOri(x: number, y: number, z: number) {
|
||||
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) {
|
||||
this.validity = validity;
|
||||
}
|
||||
setStatus(validity: number) {
|
||||
this.validity = validity;
|
||||
}
|
||||
|
||||
setAccel(x: number, y: number, z: number) {
|
||||
if (this.accel === undefined) {
|
||||
this.accel = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.accel.x = x;
|
||||
this.accel.y = y;
|
||||
this.accel.z = z;
|
||||
}
|
||||
}
|
||||
setAccel(x: number, y: number, z: number) {
|
||||
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) {
|
||||
if (this.trgtpos === undefined) {
|
||||
this.trgtpos = {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
} else {
|
||||
this.trgtpos.x = x;
|
||||
this.trgtpos.y = y;
|
||||
this.trgtpos.z = z;
|
||||
}
|
||||
}
|
||||
setTrgtPos(x: number, y: number, z: number) {
|
||||
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) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
setTimestamp(timestamp: bigint) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
getDataChunk() {
|
||||
const fieldChunks: Uint8Array[] = [];
|
||||
getDataChunk() {
|
||||
const fieldChunks: Uint8Array[] = [];
|
||||
|
||||
if (this.pos) {
|
||||
fieldChunks.push(dataTrackerPosChunk(this.pos.x, this.pos.y, this.pos.z));
|
||||
}
|
||||
if (this.pos) {
|
||||
fieldChunks.push(dataTrackerPosChunk(this.pos.x, this.pos.y, this.pos.z));
|
||||
}
|
||||
|
||||
if (this.speed) {
|
||||
fieldChunks.push(dataTrackerSpeedChunk(this.speed.x, this.speed.y, this.speed.z));
|
||||
}
|
||||
if (this.speed) {
|
||||
fieldChunks.push(
|
||||
dataTrackerSpeedChunk(this.speed.x, this.speed.y, this.speed.z)
|
||||
);
|
||||
}
|
||||
|
||||
if (this.ori) {
|
||||
fieldChunks.push(dataTrackerOriChunk(this.ori.x, this.ori.y, this.ori.z));
|
||||
}
|
||||
if (this.ori) {
|
||||
fieldChunks.push(dataTrackerOriChunk(this.ori.x, this.ori.y, this.ori.z));
|
||||
}
|
||||
|
||||
if (this.validity) {
|
||||
fieldChunks.push(dataTrackerStatusChunk(this.validity));
|
||||
}
|
||||
if (this.validity) {
|
||||
fieldChunks.push(dataTrackerStatusChunk(this.validity));
|
||||
}
|
||||
|
||||
if (this.accel) {
|
||||
fieldChunks.push(dataTrackerAccelChunk(this.accel.x, this.accel.y, this.accel.z));
|
||||
}
|
||||
if (this.accel) {
|
||||
fieldChunks.push(
|
||||
dataTrackerAccelChunk(this.accel.x, this.accel.y, this.accel.z)
|
||||
);
|
||||
}
|
||||
|
||||
if (this.trgtpos) {
|
||||
fieldChunks.push(dataTrackerTrgtposChunk(this.trgtpos.x, this.trgtpos.y, this.trgtpos.z));
|
||||
}
|
||||
if (this.trgtpos) {
|
||||
fieldChunks.push(
|
||||
dataTrackerTrgtposChunk(this.trgtpos.x, this.trgtpos.y, this.trgtpos.z)
|
||||
);
|
||||
}
|
||||
|
||||
if (this.timestamp) {
|
||||
fieldChunks.push(dataTrackerTimestampChunk(this.timestamp));
|
||||
}
|
||||
if (this.timestamp) {
|
||||
fieldChunks.push(dataTrackerTimestampChunk(this.timestamp));
|
||||
}
|
||||
|
||||
return dataTrackerChunk(this.id, fieldChunks);
|
||||
}
|
||||
return dataTrackerChunk(this.id, fieldChunks);
|
||||
}
|
||||
|
||||
getInfoChunk() {
|
||||
return infoTrackerChunk(this.id, infoTrackerNameChunk(this.name));
|
||||
}
|
||||
getInfoChunk() {
|
||||
return infoTrackerChunk(this.id, infoTrackerNameChunk(this.name));
|
||||
}
|
||||
|
||||
updateInfo(infoTrackerChunk: InfoTrackerChunk) {
|
||||
if (infoTrackerChunk.data) {
|
||||
this.name = infoTrackerChunk.data.trackerName.data.trackerName;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
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.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.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.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.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.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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
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;
|
||||
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