add decoder for RTTrPL

This commit is contained in:
2025-03-15 12:32:13 -05:00
parent 1e605df6c8
commit e11f16f427
4 changed files with 140 additions and 0 deletions
+2
View File
@@ -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 Decoders = {
RTTrPHeader,
RTTrPM,
RTTrPL,
Trackable,
CentroidPosition,
CentroidAccelVelocity,
+37
View File
@@ -0,0 +1,37 @@
import { Decoders } from '..';
import { LightingOutput, RTTrPL } from '../../models';
export default (bytes: Uint8Array): RTTrPL => {
if (bytes.byteLength < 18) {
throw new Error('RTTrPL packet must be at least 18 bytes long');
}
const header = Decoders.RTTrPHeader(bytes.subarray(0, 18));
if (bytes.byteLength !== header.size) {
throw new Error('RTTrPL packet size mismatch');
}
const modules: LightingOutput[] = [];
let packetModuleOffset = 18;
for (let index = 0; index < header.subModuleCount; index++) {
const moduleData = bytes.subarray(packetModuleOffset);
const moduleType = moduleData[0];
switch (moduleType) {
case 0x07: {
const module = Decoders.LightingOutput(moduleData, header.isLittleEndian);
modules.push(module);
packetModuleOffset += module.size;
break;
}
default:
console.error(`unknown RTTrPL submodule type: ${moduleType}`);
break;
}
}
return {
header,
modules,
};
};
+5
View File
@@ -15,6 +15,11 @@ export type RTTrPM = {
modules: Trackable[];
};
export type RTTrPL = {
header: RTTrPHeader;
modules: LightingOutput[];
};
export type TrackableModule =
| CentroidPosition
| CentroidAccelVelocity