add decoder for universe

This commit is contained in:
2025-03-15 12:11:28 -05:00
parent b0c050035b
commit c4ceaa427a
5 changed files with 82 additions and 1 deletions
+2
View File
@@ -1,5 +1,6 @@
import ChannelBlock from './lighting/channel-block';
import Spot from './lighting/spot';
import Universe from './lighting/universe';
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
import CentroidPosition from './motion/centroid-position';
import OrientationEuler from './motion/orientation-euler';
@@ -26,4 +27,5 @@ export const Decoders = {
ZoneObject,
Spot,
ChannelBlock,
Universe,
};
+1 -1
View File
@@ -13,7 +13,7 @@ export default (bytes: Uint8Array, isLittleEndian: boolean = false): Spot => {
const size = view.getUint16(dataOffset, isLittleEndian);
dataOffset += 2;
if (size !== bytes.byteLength) {
if (size < bytes.byteLength) {
throw new Error('Spot module size mismatch');
}
const id = view.getUint16(dataOffset, isLittleEndian);
+41
View File
@@ -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,
};
};
+8
View File
@@ -115,6 +115,14 @@ export type ZoneObject = {
name: string;
};
export type Universe = {
type: number;
size: number;
id: number;
numberOfSpots: number;
spots: Spot[];
};
export type Spot = {
type: number;
size: number;