mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-08-21 06:49:07 +00:00
add encoder for lighting output module
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import ChannelBlock from './lighting/channel-block';
|
||||
import LightingOutput from './lighting/lighting-output';
|
||||
import Spot from './lighting/spot';
|
||||
import Universe from './lighting/universe';
|
||||
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
|
||||
@@ -25,6 +26,7 @@ export const Encoders = {
|
||||
TrackedPointAccelVelocity,
|
||||
ZoneCollisionDetection,
|
||||
ZoneObject,
|
||||
LightingOutput,
|
||||
Universe,
|
||||
Spot,
|
||||
ChannelBlock,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
export default (
|
||||
sequence: number,
|
||||
action: number,
|
||||
holdTime: number,
|
||||
universeModules: Uint8Array[],
|
||||
isLittleEndian: boolean = false
|
||||
): Uint8Array => {
|
||||
let totalLightingOutputModuleSize = 1 + 2 + 4 + 1 + 4 + 2;
|
||||
|
||||
universeModules.forEach((universeModule) => {
|
||||
totalLightingOutputModuleSize += universeModule.byteLength;
|
||||
});
|
||||
|
||||
const bytes = new Uint8Array(totalLightingOutputModuleSize);
|
||||
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||
|
||||
let dataOffset = 0;
|
||||
view.setUint8(dataOffset, 0x07);
|
||||
dataOffset += 1;
|
||||
view.setUint16(dataOffset, bytes.byteLength, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
view.setUint32(dataOffset, sequence, isLittleEndian);
|
||||
dataOffset += 4;
|
||||
view.setUint8(dataOffset, action);
|
||||
dataOffset += 1;
|
||||
view.setUint32(dataOffset, holdTime, isLittleEndian);
|
||||
dataOffset += 4;
|
||||
view.setUint16(dataOffset, universeModules.length, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
|
||||
universeModules.forEach((universeModule) => {
|
||||
bytes.set(universeModule, dataOffset);
|
||||
dataOffset += universeModule.length;
|
||||
});
|
||||
return bytes;
|
||||
};
|
||||
@@ -3,6 +3,18 @@ const { describe, it } = require('node:test');
|
||||
const { Encoders } = require('../');
|
||||
|
||||
const goodTests = [
|
||||
{
|
||||
description: 'Lighting Output + Universe + Spot + Single Channel Block',
|
||||
expected: new Uint8Array([
|
||||
0x07, 0x00, 0x23, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x01, 0x09, 0x00, 0x15, 0x12, 0x34,
|
||||
0x00, 0x01, 0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x06, 0x40,
|
||||
]),
|
||||
bytes: () => {
|
||||
return Encoders.LightingOutput(1, 1, 100, [
|
||||
Encoders.Universe(0x1234, [Encoders.Spot(0x1234, 1, [Encoders.ChannelBlock(8, 6, 64)])]),
|
||||
]);
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'Universe + Spot + Single Channel Block',
|
||||
expected: new Uint8Array([
|
||||
|
||||
Reference in New Issue
Block a user