mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-09-13 09:59:34 +00:00
add encoder for spot module
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import ChannelBlock from './lighting/channel-block';
|
import ChannelBlock from './lighting/channel-block';
|
||||||
|
import Spot from './lighting/spot';
|
||||||
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
|
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
|
||||||
import CentroidPosition from './motion/centroid-position';
|
import CentroidPosition from './motion/centroid-position';
|
||||||
import OrientationEuler from './motion/orientation-euler';
|
import OrientationEuler from './motion/orientation-euler';
|
||||||
@@ -23,5 +24,6 @@ export const Encoders = {
|
|||||||
TrackedPointAccelVelocity,
|
TrackedPointAccelVelocity,
|
||||||
ZoneCollisionDetection,
|
ZoneCollisionDetection,
|
||||||
ZoneObject,
|
ZoneObject,
|
||||||
|
Spot,
|
||||||
ChannelBlock,
|
ChannelBlock,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
export default (
|
||||||
|
id: number,
|
||||||
|
offset: number,
|
||||||
|
channelBlockModules: Uint8Array[],
|
||||||
|
isLittleEndian: boolean = false
|
||||||
|
): Uint8Array => {
|
||||||
|
let totalSpotModuleSize = 1 + 2 + 2 + 2 + 2;
|
||||||
|
|
||||||
|
channelBlockModules.forEach((channelBlockModule) => {
|
||||||
|
totalSpotModuleSize += channelBlockModule.byteLength;
|
||||||
|
});
|
||||||
|
|
||||||
|
const bytes = new Uint8Array(totalSpotModuleSize);
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
|
||||||
|
let dataOffset = 0;
|
||||||
|
view.setUint8(dataOffset, 0x0a);
|
||||||
|
dataOffset += 1;
|
||||||
|
view.setUint16(dataOffset, bytes.byteLength, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
view.setUint16(dataOffset, id, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
view.setUint16(dataOffset, offset, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
view.setUint16(dataOffset, channelBlockModules.length, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
channelBlockModules.forEach((channelBlockModule) => {
|
||||||
|
bytes.set(channelBlockModule, dataOffset);
|
||||||
|
dataOffset += channelBlockModule.length;
|
||||||
|
});
|
||||||
|
return bytes;
|
||||||
|
};
|
||||||
@@ -3,6 +3,13 @@ const { describe, it } = require('node:test');
|
|||||||
const { Encoders } = require('../');
|
const { Encoders } = require('../');
|
||||||
|
|
||||||
const goodTests = [
|
const goodTests = [
|
||||||
|
{
|
||||||
|
description: 'Spot + Single Channel Block',
|
||||||
|
expected: new Uint8Array([0x0a, 0x00, 0x0e, 0x12, 0x34, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00, 0x06, 0x40]),
|
||||||
|
bytes: () => {
|
||||||
|
return Encoders.Spot(0x1234, 1, [Encoders.ChannelBlock(8, 6, 64)]);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: 'Channel Block',
|
description: 'Channel Block',
|
||||||
expected: new Uint8Array([0x00, 0x08, 0x00, 0x06, 0x40]),
|
expected: new Uint8Array([0x00, 0x08, 0x00, 0x06, 0x40]),
|
||||||
|
|||||||
Reference in New Issue
Block a user