mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-08-21 14:59:05 +00:00
add decoder for spot
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import ChannelBlock from './lighting/channel-block';
|
||||
import Spot from './lighting/spot';
|
||||
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
|
||||
import CentroidPosition from './motion/centroid-position';
|
||||
import OrientationEuler from './motion/orientation-euler';
|
||||
@@ -23,5 +24,6 @@ export const Decoders = {
|
||||
OrientationEuler,
|
||||
ZoneCollisionDetection,
|
||||
ZoneObject,
|
||||
Spot,
|
||||
ChannelBlock,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Decoders } from '..';
|
||||
import { ChannelBlock, Spot } from '../../models';
|
||||
|
||||
export default (bytes: Uint8Array, isLittleEndian: boolean = false): Spot => {
|
||||
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||
|
||||
let dataOffset = 0;
|
||||
const type = view.getUint8(dataOffset);
|
||||
dataOffset += 1;
|
||||
if (type !== 0x0a) {
|
||||
throw new Error('Spot module must have a type of 0x0a');
|
||||
}
|
||||
|
||||
const size = view.getUint16(dataOffset, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
if (size !== bytes.byteLength) {
|
||||
throw new Error('Spot module size mismatch');
|
||||
}
|
||||
const id = view.getUint16(dataOffset, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
const offset = view.getUint16(dataOffset, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
const numberOfChannelBlocks = view.getUint16(dataOffset, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
|
||||
const channelBlocks: ChannelBlock[] = [];
|
||||
let zoneObjectOffset = dataOffset;
|
||||
|
||||
for (let index = 0; index < numberOfChannelBlocks; index++) {
|
||||
const channelBlockData = bytes.subarray(zoneObjectOffset, zoneObjectOffset + 5);
|
||||
console.log(channelBlockData);
|
||||
const channelBlock = Decoders.ChannelBlock(channelBlockData);
|
||||
channelBlocks.push(channelBlock);
|
||||
zoneObjectOffset += channelBlockData.byteLength;
|
||||
}
|
||||
return {
|
||||
type,
|
||||
size,
|
||||
id,
|
||||
offset,
|
||||
numberOfChannelBlocks,
|
||||
channelBlocks,
|
||||
};
|
||||
};
|
||||
@@ -115,6 +115,15 @@ export type ZoneObject = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type Spot = {
|
||||
type: number;
|
||||
size: number;
|
||||
id: number;
|
||||
offset: number;
|
||||
numberOfChannelBlocks: number;
|
||||
channelBlocks: ChannelBlock[];
|
||||
};
|
||||
|
||||
export type ChannelBlock = {
|
||||
offset: number;
|
||||
fade: number;
|
||||
|
||||
Reference in New Issue
Block a user