mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-09-11 17:09:30 +00:00
add encoder for zone sub modules
This commit is contained in:
@@ -6,6 +6,8 @@ import RTTrPM from './motion/rttrpm';
|
|||||||
import Trackable from './motion/trackable';
|
import Trackable from './motion/trackable';
|
||||||
import TrackedPointAccelVelocity from './motion/tracked-point-accel-velocity';
|
import TrackedPointAccelVelocity from './motion/tracked-point-accel-velocity';
|
||||||
import TrackedPointPosition from './motion/tracked-point-position';
|
import TrackedPointPosition from './motion/tracked-point-position';
|
||||||
|
import ZoneCollisionDetection from './motion/zone-collision-detection';
|
||||||
|
import ZoneObject from './motion/zone-object';
|
||||||
import RTTrPHeader from './rttrp-header';
|
import RTTrPHeader from './rttrp-header';
|
||||||
|
|
||||||
export const Encoders = {
|
export const Encoders = {
|
||||||
@@ -18,4 +20,6 @@ export const Encoders = {
|
|||||||
TrackedPointPosition,
|
TrackedPointPosition,
|
||||||
CentroidAccelVelocity,
|
CentroidAccelVelocity,
|
||||||
TrackedPointAccelVelocity,
|
TrackedPointAccelVelocity,
|
||||||
|
ZoneCollisionDetection,
|
||||||
|
ZoneObject,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export default (zoneObjectModules: Uint8Array[], isLittleEndian: boolean = false): Uint8Array => {
|
||||||
|
let totalZoneModuleSize = 1 + 2 + 1;
|
||||||
|
|
||||||
|
zoneObjectModules.forEach((zoneObjectModule) => {
|
||||||
|
totalZoneModuleSize += zoneObjectModule.byteLength;
|
||||||
|
});
|
||||||
|
|
||||||
|
const bytes = new Uint8Array(totalZoneModuleSize);
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
|
||||||
|
let dataOffset = 0;
|
||||||
|
view.setUint8(dataOffset, 0x22);
|
||||||
|
dataOffset += 1;
|
||||||
|
view.setUint16(dataOffset, bytes.byteLength, isLittleEndian);
|
||||||
|
dataOffset += 2;
|
||||||
|
view.setUint8(dataOffset, zoneObjectModules.length);
|
||||||
|
dataOffset += 1;
|
||||||
|
zoneObjectModules.forEach((zoneObjectModule) => {
|
||||||
|
bytes.set(zoneObjectModule, dataOffset);
|
||||||
|
dataOffset += zoneObjectModule.length;
|
||||||
|
});
|
||||||
|
return bytes;
|
||||||
|
};
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
const textEncoder = new TextEncoder();
|
||||||
|
|
||||||
|
export default (name: string): Uint8Array => {
|
||||||
|
const totalZoneObjectModuleSize = 1 + 1 + name.length;
|
||||||
|
const bytes = new Uint8Array(totalZoneObjectModuleSize);
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
|
||||||
|
let dataOffset = 0;
|
||||||
|
view.setUint8(dataOffset, totalZoneObjectModuleSize);
|
||||||
|
dataOffset += 1;
|
||||||
|
view.setUint8(dataOffset, name.length);
|
||||||
|
dataOffset += 1;
|
||||||
|
|
||||||
|
const nameBytes = textEncoder.encode(name);
|
||||||
|
nameBytes.forEach((byte) => {
|
||||||
|
view.setUint8(dataOffset, byte);
|
||||||
|
dataOffset += 1;
|
||||||
|
});
|
||||||
|
return bytes;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user