add decoder for channel block

This commit is contained in:
2025-03-15 12:01:50 -05:00
parent ca53943374
commit 9a8832fe90
4 changed files with 38 additions and 0 deletions
+2
View File
@@ -1,3 +1,4 @@
import ChannelBlock from './lighting/channel-block';
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
import CentroidPosition from './motion/centroid-position';
import OrientationEuler from './motion/orientation-euler';
@@ -22,4 +23,5 @@ export const Decoders = {
OrientationEuler,
ZoneCollisionDetection,
ZoneObject,
ChannelBlock,
};
+20
View File
@@ -0,0 +1,20 @@
import { ChannelBlock } from '../../models';
export default (bytes: Uint8Array, isLittleEndian: boolean = false): ChannelBlock => {
if (bytes.length !== 5) {
throw new Error('Channel Block module must be 5 bytes');
}
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const offset = view.getUint16(0);
const fade = view.getUint16(2, isLittleEndian);
const value = view.getUint8(4);
return {
offset,
fade,
value,
};
};
+6
View File
@@ -114,3 +114,9 @@ export type ZoneObject = {
nameLength: number;
name: string;
};
export type ChannelBlock = {
offset: number;
fade: number;
value: number;
};
+10
View File
@@ -251,6 +251,16 @@ const goodTests = [
},
decoder: Decoders.RTTrPM,
},
{
description: 'Channel Block',
bytes: new Uint8Array([0x00, 0x08, 0x00, 0x06, 0x40]),
expected: {
offset: 0x08,
fade: 0x06,
value: 0x40,
},
decoder: Decoders.ChannelBlock,
},
];
describe('RTTrP Bytes Decoding', () => {