add encoder for lighting output module

This commit is contained in:
2025-03-15 13:20:15 -05:00
parent a184e0899b
commit bd427c2de3
3 changed files with 50 additions and 0 deletions
+2
View File
@@ -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,
+36
View File
@@ -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;
};