mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-08-21 06:49:07 +00:00
add decoder for channel block
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -114,3 +114,9 @@ export type ZoneObject = {
|
||||
nameLength: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type ChannelBlock = {
|
||||
offset: number;
|
||||
fade: number;
|
||||
value: number;
|
||||
};
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user