mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-09-12 17:39:33 +00:00
add decoder for accel velocity submodules
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
|
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';
|
||||||
import OrientationQuaternion from './motion/orientation-quaternion';
|
import OrientationQuaternion from './motion/orientation-quaternion';
|
||||||
|
import TrackedPointAccelVelocity from './motion/tracked-point-accel-velocity';
|
||||||
import TrackedPointPosition from './motion/tracked-point-position';
|
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,
|
||||||
|
CentroidAccelVelocity,
|
||||||
TrackedPointPosition,
|
TrackedPointPosition,
|
||||||
|
TrackedPointAccelVelocity,
|
||||||
OrientationQuaternion,
|
OrientationQuaternion,
|
||||||
OrientationEuler,
|
OrientationEuler,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { CentroidAccelVelocity } from '../../models';
|
||||||
|
|
||||||
|
export default (bytes: Uint8Array, isLittleEndian: boolean = false): CentroidAccelVelocity => {
|
||||||
|
if (bytes.length !== 51) {
|
||||||
|
throw new Error('Centroid Acceleration and Velocity module must be 51 bytes');
|
||||||
|
}
|
||||||
|
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
|
||||||
|
const type = view.getUint8(0);
|
||||||
|
if (type !== 0x20) {
|
||||||
|
throw new Error('Centroid Acceleration and Velocity module must have a type of 0x20');
|
||||||
|
}
|
||||||
|
|
||||||
|
const size = view.getUint16(1, isLittleEndian);
|
||||||
|
if (size !== 51) {
|
||||||
|
throw new Error('Centroid Acceleration and Velocity module must be 51 bytes');
|
||||||
|
}
|
||||||
|
const x = view.getFloat64(3, isLittleEndian);
|
||||||
|
const y = view.getFloat64(11, isLittleEndian);
|
||||||
|
const z = view.getFloat64(19, isLittleEndian);
|
||||||
|
|
||||||
|
const accelX = view.getFloat32(27, isLittleEndian);
|
||||||
|
const accelY = view.getFloat32(31, isLittleEndian);
|
||||||
|
const accelZ = view.getFloat32(35, isLittleEndian);
|
||||||
|
|
||||||
|
const velocityX = view.getFloat32(39, isLittleEndian);
|
||||||
|
const velocityY = view.getFloat32(43, isLittleEndian);
|
||||||
|
const velocityZ = view.getFloat32(47, isLittleEndian);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
size,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
accelX,
|
||||||
|
accelY,
|
||||||
|
accelZ,
|
||||||
|
velocityX,
|
||||||
|
velocityY,
|
||||||
|
velocityZ,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { TrackedPointAccelVelocity } from '../../models';
|
||||||
|
|
||||||
|
export default (bytes: Uint8Array, isLittleEndian: boolean = false): TrackedPointAccelVelocity => {
|
||||||
|
if (bytes.length !== 52) {
|
||||||
|
throw new Error('Tracked Point Acceleration and Velocity module must be 52 bytes');
|
||||||
|
}
|
||||||
|
|
||||||
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
|
|
||||||
|
const type = view.getUint8(0);
|
||||||
|
if (type !== 0x21) {
|
||||||
|
throw new Error('Tracked Point Acceleration and Velocity module must have a type of 0x21');
|
||||||
|
}
|
||||||
|
|
||||||
|
const size = view.getUint16(1, isLittleEndian);
|
||||||
|
if (size !== 52) {
|
||||||
|
throw new Error('Tracked Point Acceleration and Velocity module must be 52 bytes');
|
||||||
|
}
|
||||||
|
const x = view.getFloat64(3, isLittleEndian);
|
||||||
|
const y = view.getFloat64(11, isLittleEndian);
|
||||||
|
const z = view.getFloat64(19, isLittleEndian);
|
||||||
|
|
||||||
|
const accelX = view.getFloat32(27, isLittleEndian);
|
||||||
|
const accelY = view.getFloat32(31, isLittleEndian);
|
||||||
|
const accelZ = view.getFloat32(35, isLittleEndian);
|
||||||
|
|
||||||
|
const velocityX = view.getFloat32(39, isLittleEndian);
|
||||||
|
const velocityY = view.getFloat32(43, isLittleEndian);
|
||||||
|
const velocityZ = view.getFloat32(47, isLittleEndian);
|
||||||
|
|
||||||
|
const index = view.getUint8(51);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
size,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
accelX,
|
||||||
|
accelY,
|
||||||
|
accelZ,
|
||||||
|
velocityX,
|
||||||
|
velocityY,
|
||||||
|
velocityZ,
|
||||||
|
index,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -18,6 +18,19 @@ export type CentroidPosition = {
|
|||||||
z: number;
|
z: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CentroidAccelVelocity = {
|
||||||
|
type: number;
|
||||||
|
size: number;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
accelX: number;
|
||||||
|
accelY: number;
|
||||||
|
accelZ: number;
|
||||||
|
velocityX: number;
|
||||||
|
velocityY: number;
|
||||||
|
velocityZ: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type TrackedPointPosition = {
|
export type TrackedPointPosition = {
|
||||||
type: number;
|
type: number;
|
||||||
@@ -29,6 +42,21 @@ export type TrackedPointPosition = {
|
|||||||
index: number;
|
index: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TrackedPointAccelVelocity = {
|
||||||
|
type: number;
|
||||||
|
size: number;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
accelX: number;
|
||||||
|
accelY: number;
|
||||||
|
accelZ: number;
|
||||||
|
velocityX: number;
|
||||||
|
velocityY: number;
|
||||||
|
velocityZ: number;
|
||||||
|
index: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type OrientationQuaternion = {
|
export type OrientationQuaternion = {
|
||||||
type: number;
|
type: number;
|
||||||
size: number;
|
size: number;
|
||||||
|
|||||||
@@ -86,6 +86,51 @@ const goodTests = [
|
|||||||
},
|
},
|
||||||
decoder: Decoders.OrientationEuler,
|
decoder: Decoders.OrientationEuler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'Centroid Acceleration and Velocity',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
0x20, 0x00, 51, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x40, 0xa0, 0x00, 0x00, 0x40, 0xc0, 0x00,
|
||||||
|
0x00, 0x40, 0xe0, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x41, 0x10, 0x00, 0x00,
|
||||||
|
]),
|
||||||
|
expected: {
|
||||||
|
type: 0x20,
|
||||||
|
size: 51,
|
||||||
|
x: 1.0,
|
||||||
|
y: 2.0,
|
||||||
|
z: 3.0,
|
||||||
|
accelX: 4.0,
|
||||||
|
accelY: 5.0,
|
||||||
|
accelZ: 6.0,
|
||||||
|
velocityX: 7.0,
|
||||||
|
velocityY: 8.0,
|
||||||
|
velocityZ: 9.0,
|
||||||
|
},
|
||||||
|
decoder: Decoders.CentroidAccelVelocity,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: 'Tracked Point Acceleration and Velocity',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
0x21, 0x00, 52, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x40, 0xa0, 0x00, 0x00, 0x40, 0xc0, 0x00,
|
||||||
|
0x00, 0x40, 0xe0, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x41, 0x10, 0x00, 0x00, 0x01,
|
||||||
|
]),
|
||||||
|
expected: {
|
||||||
|
type: 0x21,
|
||||||
|
size: 52,
|
||||||
|
x: 1.0,
|
||||||
|
y: 2.0,
|
||||||
|
z: 3.0,
|
||||||
|
accelX: 4.0,
|
||||||
|
accelY: 5.0,
|
||||||
|
accelZ: 6.0,
|
||||||
|
velocityX: 7.0,
|
||||||
|
velocityY: 8.0,
|
||||||
|
velocityZ: 9.0,
|
||||||
|
index: 1,
|
||||||
|
},
|
||||||
|
decoder: Decoders.TrackedPointAccelVelocity,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('RTTrP Bytes Decoding', () => {
|
describe('RTTrP Bytes Decoding', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user