add encoder for universe module

This commit is contained in:
2025-03-15 13:09:54 -05:00
parent 09719a8791
commit a184e0899b
3 changed files with 37 additions and 0 deletions
+2
View File
@@ -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';
@@ -24,6 +25,7 @@ export const Encoders = {
TrackedPointAccelVelocity, TrackedPointAccelVelocity,
ZoneCollisionDetection, ZoneCollisionDetection,
ZoneObject, ZoneObject,
Universe,
Spot, Spot,
ChannelBlock, ChannelBlock,
}; };
+25
View File
@@ -0,0 +1,25 @@
export default (id: number, spotModules: Uint8Array[], isLittleEndian: boolean = false): Uint8Array => {
let totalSpotModuleSize = 1 + 2 + 2 + 2;
spotModules.forEach((spotModule) => {
totalSpotModuleSize += spotModule.byteLength;
});
const bytes = new Uint8Array(totalSpotModuleSize);
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
let dataOffset = 0;
view.setUint8(dataOffset, 0x09);
dataOffset += 1;
view.setUint16(dataOffset, bytes.byteLength, isLittleEndian);
dataOffset += 2;
view.setUint16(dataOffset, id, isLittleEndian);
dataOffset += 2;
view.setUint16(dataOffset, spotModules.length, isLittleEndian);
dataOffset += 2;
spotModules.forEach((spotModule) => {
bytes.set(spotModule, dataOffset);
dataOffset += spotModule.length;
});
return bytes;
};
+10
View File
@@ -3,6 +3,16 @@ const { describe, it } = require('node:test');
const { Encoders } = require('../'); const { Encoders } = require('../');
const goodTests = [ const goodTests = [
{
description: 'Universe + Spot + Single Channel Block',
expected: new Uint8Array([
0x09, 0x00, 0x15, 0x12, 0x34, 0x00, 0x01, 0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00,
0x06, 0x40,
]),
bytes: () => {
return Encoders.Universe(0x1234, [Encoders.Spot(0x1234, 1, [Encoders.ChannelBlock(8, 6, 64)])]);
},
},
{ {
description: 'Spot + Single Channel Block', description: 'Spot + Single Channel Block',
expected: new Uint8Array([0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x06, 0x40]), expected: new Uint8Array([0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x06, 0x40]),