mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-09-12 01:19:32 +00:00
add decoder for universe
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import ChannelBlock from './lighting/channel-block';
|
import ChannelBlock from './lighting/channel-block';
|
||||||
import Spot from './lighting/spot';
|
import Spot from './lighting/spot';
|
||||||
|
import Universe from './lighting/universe';
|
||||||
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
|
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
|
||||||
import CentroidPosition from './motion/centroid-position';
|
import CentroidPosition from './motion/centroid-position';
|
||||||
import OrientationEuler from './motion/orientation-euler';
|
import OrientationEuler from './motion/orientation-euler';
|
||||||
@@ -26,4 +27,5 @@ export const Decoders = {
|
|||||||
ZoneObject,
|
ZoneObject,
|
||||||
Spot,
|
Spot,
|
||||||
ChannelBlock,
|
ChannelBlock,
|
||||||
|
Universe,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export default (bytes: Uint8Array, isLittleEndian: boolean = false): Spot => {
|
|||||||
|
|
||||||
const size = view.getUint16(dataOffset, isLittleEndian);
|
const size = view.getUint16(dataOffset, isLittleEndian);
|
||||||
dataOffset += 2;
|
dataOffset += 2;
|
||||||
if (size !== bytes.byteLength) {
|
if (size < bytes.byteLength) {
|
||||||
throw new Error('Spot module size mismatch');
|
throw new Error('Spot module size mismatch');
|
||||||
}
|
}
|
||||||
const id = view.getUint16(dataOffset, isLittleEndian);
|
const id = view.getUint16(dataOffset, isLittleEndian);
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { Decoders } from '..';
|
||||||
|
import { Spot, Universe } from '../../models';
|
||||||
|
|
||||||
|
export default (bytes: Uint8Array, isLittleEndian: boolean = false): Universe => {
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
|
||||||
|
let dataOffset = 0;
|
||||||
|
const type = view.getUint8(dataOffset);
|
||||||
|
dataOffset += 1;
|
||||||
|
if (type !== 0x09) {
|
||||||
|
throw new Error('Universe module must have a type of 0x09');
|
||||||
|
}
|
||||||
|
|
||||||
|
const size = view.getUint16(dataOffset, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
if (size !== bytes.byteLength) {
|
||||||
|
throw new Error('Universe module size mismatch');
|
||||||
|
}
|
||||||
|
const id = view.getUint16(dataOffset, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
const numberOfSpots = view.getUint16(dataOffset, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
|
||||||
|
const spots: Spot[] = [];
|
||||||
|
let spotOffset = dataOffset;
|
||||||
|
|
||||||
|
for (let index = 0; index < numberOfSpots; index++) {
|
||||||
|
const spotData = bytes.subarray(spotOffset);
|
||||||
|
console.log(spotData);
|
||||||
|
const spot = Decoders.Spot(spotData);
|
||||||
|
spots.push(spot);
|
||||||
|
spotOffset += spot.size;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
size,
|
||||||
|
id,
|
||||||
|
numberOfSpots,
|
||||||
|
spots,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -115,6 +115,14 @@ export type ZoneObject = {
|
|||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Universe = {
|
||||||
|
type: number;
|
||||||
|
size: number;
|
||||||
|
id: number;
|
||||||
|
numberOfSpots: number;
|
||||||
|
spots: Spot[];
|
||||||
|
};
|
||||||
|
|
||||||
export type Spot = {
|
export type Spot = {
|
||||||
type: number;
|
type: number;
|
||||||
size: number;
|
size: number;
|
||||||
|
|||||||
@@ -251,6 +251,36 @@ const goodTests = [
|
|||||||
},
|
},
|
||||||
decoder: Decoders.RTTrPM,
|
decoder: Decoders.RTTrPM,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'Universe + Spot + Single Channel Block',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
0x09, 0x00, 0x15, 0x12, 0x34, 0x00, 0x01, 0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00,
|
||||||
|
0x06, 0x40,
|
||||||
|
]),
|
||||||
|
expected: {
|
||||||
|
type: 0x09,
|
||||||
|
size: 21,
|
||||||
|
id: 0x1234,
|
||||||
|
numberOfSpots: 1,
|
||||||
|
spots: [
|
||||||
|
{
|
||||||
|
type: 0x0a,
|
||||||
|
size: 14,
|
||||||
|
id: 0x1234,
|
||||||
|
offset: 1,
|
||||||
|
numberOfChannelBlocks: 1,
|
||||||
|
channelBlocks: [
|
||||||
|
{
|
||||||
|
offset: 0x08,
|
||||||
|
fade: 0x06,
|
||||||
|
value: 0x40,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
decoder: Decoders.Universe,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: 'Spot + Single Channel Block',
|
description: 'Spot + Single Channel Block',
|
||||||
bytes: new Uint8Array([0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x06, 0x40]),
|
bytes: new Uint8Array([0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x06, 0x40]),
|
||||||
|
|||||||
Reference in New Issue
Block a user