mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-08-20 06:19:03 +00:00
add encoder for universe module
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import ChannelBlock from './lighting/channel-block';
|
||||
import Spot from './lighting/spot';
|
||||
import Universe from './lighting/universe';
|
||||
import CentroidAccelVelocity from './motion/centroid-accel-velocity';
|
||||
import CentroidPosition from './motion/centroid-position';
|
||||
import OrientationEuler from './motion/orientation-euler';
|
||||
@@ -24,6 +25,7 @@ export const Encoders = {
|
||||
TrackedPointAccelVelocity,
|
||||
ZoneCollisionDetection,
|
||||
ZoneObject,
|
||||
Universe,
|
||||
Spot,
|
||||
ChannelBlock,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
export default (id: number, spotModules: Uint8Array[], isLittleEndian: boolean = false): Uint8Array => {
|
||||
let totalSpotModuleSize = 1 + 2 + 2 + 2;
|
||||
|
||||
spotModules.forEach((spotModule) => {
|
||||
totalSpotModuleSize += spotModule.byteLength;
|
||||
});
|
||||
|
||||
const bytes = new Uint8Array(totalSpotModuleSize);
|
||||
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||
|
||||
let dataOffset = 0;
|
||||
view.setUint8(dataOffset, 0x09);
|
||||
dataOffset += 1;
|
||||
view.setUint16(dataOffset, bytes.byteLength, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
view.setUint16(dataOffset, id, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
view.setUint16(dataOffset, spotModules.length, isLittleEndian);
|
||||
dataOffset += 2;
|
||||
spotModules.forEach((spotModule) => {
|
||||
bytes.set(spotModule, dataOffset);
|
||||
dataOffset += spotModule.length;
|
||||
});
|
||||
return bytes;
|
||||
};
|
||||
Reference in New Issue
Block a user