mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-09-02 12:49:02 +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 OrientationEuler from './motion/orientation-euler';
|
||||
import OrientationQuaternion from './motion/orientation-quaternion';
|
||||
import TrackedPointAccelVelocity from './motion/tracked-point-accel-velocity';
|
||||
import TrackedPointPosition from './motion/tracked-point-position';
|
||||
import RTTrPHeader from './rttrp';
|
||||
|
||||
export const Decoders = {
|
||||
RTTrPHeader,
|
||||
CentroidPosition,
|
||||
CentroidAccelVelocity,
|
||||
TrackedPointPosition,
|
||||
TrackedPointAccelVelocity,
|
||||
OrientationQuaternion,
|
||||
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;
|
||||
};
|
||||
|
||||
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 = {
|
||||
type: number;
|
||||
@@ -29,6 +42,21 @@ export type TrackedPointPosition = {
|
||||
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 = {
|
||||
type: number;
|
||||
size: number;
|
||||
|
||||
Reference in New Issue
Block a user