mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-09-11 08:59:33 +00:00
add decoder for tracked point position submodule
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import CentroidPosition from './motion/centroid-position';
|
import CentroidPosition from './motion/centroid-position';
|
||||||
import OrientationEuler from './motion/orientation-euler';
|
import OrientationEuler from './motion/orientation-euler';
|
||||||
import OrientationQuaternion from './motion/orientation-quaternion';
|
import OrientationQuaternion from './motion/orientation-quaternion';
|
||||||
|
import TrackedPointPosition from './motion/tracked-point-position';
|
||||||
import RTTrPHeader from './rttrp';
|
import RTTrPHeader from './rttrp';
|
||||||
|
|
||||||
export const Decoders = {
|
export const Decoders = {
|
||||||
RTTrPHeader,
|
RTTrPHeader,
|
||||||
CentroidPosition,
|
CentroidPosition,
|
||||||
|
TrackedPointPosition,
|
||||||
OrientationQuaternion,
|
OrientationQuaternion,
|
||||||
OrientationEuler,
|
OrientationEuler,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { TrackedPointPosition } from '../../models';
|
||||||
|
|
||||||
|
export default (bytes: Uint8Array, isLittleEndian: boolean = false): TrackedPointPosition => {
|
||||||
|
if (bytes.length !== 30) {
|
||||||
|
throw new Error('Tracked Point Position module must be 30 bytes');
|
||||||
|
}
|
||||||
|
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
|
||||||
|
const type = view.getUint8(0);
|
||||||
|
if (type !== 0x06) {
|
||||||
|
throw new Error('Tracked Point Position module must have a type of 0x06');
|
||||||
|
}
|
||||||
|
|
||||||
|
const size = view.getUint16(1, isLittleEndian);
|
||||||
|
if (size !== 30) {
|
||||||
|
throw new Error('Tracked Point Position module must be 30 bytes');
|
||||||
|
}
|
||||||
|
const latency = view.getUint16(3, isLittleEndian);
|
||||||
|
const x = view.getFloat64(5, isLittleEndian);
|
||||||
|
const y = view.getFloat64(13, isLittleEndian);
|
||||||
|
const z = view.getFloat64(21, isLittleEndian);
|
||||||
|
const index = view.getUint8(29);
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
size,
|
||||||
|
latency,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
index,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -19,6 +19,16 @@ export type CentroidPosition = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export type TrackedPointPosition = {
|
||||||
|
type: number;
|
||||||
|
size: number;
|
||||||
|
latency: number;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
index: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type OrientationQuaternion = {
|
export type OrientationQuaternion = {
|
||||||
type: number;
|
type: number;
|
||||||
size: number;
|
size: number;
|
||||||
|
|||||||
@@ -35,6 +35,23 @@ const goodTests = [
|
|||||||
},
|
},
|
||||||
decoder: Decoders.CentroidPosition,
|
decoder: Decoders.CentroidPosition,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'Tracked Point Position',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
0x06, 0x00, 0x1e, 0x00, 0x10, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||||
|
]),
|
||||||
|
expected: {
|
||||||
|
type: 0x06,
|
||||||
|
size: 0x1e,
|
||||||
|
latency: 16,
|
||||||
|
x: 1.0,
|
||||||
|
y: 2.0,
|
||||||
|
z: 3.0,
|
||||||
|
index: 1,
|
||||||
|
},
|
||||||
|
decoder: Decoders.TrackedPointPosition,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: 'Orientation (Quaternion)',
|
description: 'Orientation (Quaternion)',
|
||||||
bytes: new Uint8Array([
|
bytes: new Uint8Array([
|
||||||
|
|||||||
Reference in New Issue
Block a user