diff --git a/src/encoders/index.ts b/src/encoders/index.ts index 0b7a353..f4d8555 100644 --- a/src/encoders/index.ts +++ b/src/encoders/index.ts @@ -1,5 +1,6 @@ import ChannelBlock from './lighting/channel-block'; import LightingOutput from './lighting/lighting-output'; +import RTTrPL from './lighting/rttrpl'; import Spot from './lighting/spot'; import Universe from './lighting/universe'; import CentroidAccelVelocity from './motion/centroid-accel-velocity'; @@ -17,6 +18,7 @@ import RTTrPHeader from './rttrp-header'; export const Encoders = { RTTrPHeader, RTTrPM, + RTTrPL, Trackable, CentroidPosition, OrientationQuaternion, diff --git a/src/encoders/lighting/rttrpl.ts b/src/encoders/lighting/rttrpl.ts new file mode 100644 index 0000000..4b4579d --- /dev/null +++ b/src/encoders/lighting/rttrpl.ts @@ -0,0 +1,27 @@ +import RTTrPHeader from '../rttrp-header'; + +export default ( + packetId: number, + context: number, + lightingOutputs: Uint8Array[], + isLittleEndian: boolean = false +): Uint8Array => { + let totalPacketSize = 18; //header size + + lightingOutputs.forEach((lightingOutput) => { + totalPacketSize += lightingOutput.length; + }); + const bytes = new Uint8Array(totalPacketSize); + + let dataOffset = 0; + + const headerBytes = RTTrPHeader(0x4434, 0x02, packetId, 0x00, context, lightingOutputs, isLittleEndian); + + bytes.set(headerBytes, dataOffset); + dataOffset += headerBytes.length; + lightingOutputs.forEach((lightingOutput) => { + bytes.set(lightingOutput, dataOffset); + dataOffset += lightingOutput.length; + }); + return bytes; +}; diff --git a/tests/lighting-encode.test.js b/tests/lighting-encode.test.js index d1f8058..0a924af 100644 --- a/tests/lighting-encode.test.js +++ b/tests/lighting-encode.test.js @@ -3,6 +3,21 @@ const { describe, it } = require('node:test'); const { Encoders } = require('../'); const goodTests = [ + { + description: 'RTTrPL + Lighting Output + Universe + Spot + Single Channel Block', + expected: new Uint8Array([ + 65, 84, 0x44, 0x34, 0, 2, 0, 0, 0, 1, 0, 0, 53, 18, 52, 86, 120, 1, 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.RTTrPL(1, 0x12345678, [ + Encoders.LightingOutput(1, 1, 100, [ + Encoders.Universe(0x1234, [Encoders.Spot(0x1234, 1, [Encoders.ChannelBlock(8, 6, 64)])]), + ]), + ]); + }, + }, { description: 'Lighting Output + Universe + Spot + Single Channel Block', expected: new Uint8Array([