mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-07-26 10:28:48 +00:00
add decoder for RTTrPM packet
This commit is contained in:
@@ -2,6 +2,7 @@ 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 RTTrPM from './motion/rttrpm';
|
||||
import Trackable from './motion/trackable';
|
||||
import TrackedPointAccelVelocity from './motion/tracked-point-accel-velocity';
|
||||
import TrackedPointPosition from './motion/tracked-point-position';
|
||||
@@ -11,6 +12,7 @@ import RTTrPHeader from './rttrp-header';
|
||||
|
||||
export const Decoders = {
|
||||
RTTrPHeader,
|
||||
RTTrPM,
|
||||
Trackable,
|
||||
CentroidPosition,
|
||||
CentroidAccelVelocity,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Decoders } from '..';
|
||||
import { RTTrPM, Trackable } from '../../models';
|
||||
|
||||
export default (bytes: Uint8Array): RTTrPM => {
|
||||
if (bytes.byteLength < 18) {
|
||||
throw new Error('RTTrPM packet must be at least 18 bytes long');
|
||||
}
|
||||
const header = Decoders.RTTrPHeader(bytes.subarray(0, 18));
|
||||
|
||||
if (bytes.byteLength !== header.size) {
|
||||
throw new Error('RTTrPM packet size mismatch');
|
||||
}
|
||||
|
||||
const modules: Trackable[] = [];
|
||||
let packetModuleOffset = 18;
|
||||
|
||||
for (let index = 0; index < header.subModuleCount; index++) {
|
||||
const moduleData = bytes.subarray(packetModuleOffset);
|
||||
const moduleType = moduleData[0];
|
||||
switch (moduleType) {
|
||||
case 0x01:
|
||||
case 0x51: {
|
||||
const module = Decoders.Trackable(moduleData, header.isLittleEndian);
|
||||
modules.push(module);
|
||||
packetModuleOffset += module.size;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.error(`unknown RTTrPM submodule type: ${moduleType}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
header,
|
||||
modules,
|
||||
};
|
||||
};
|
||||
@@ -9,6 +9,10 @@ export type RTTrPHeader = {
|
||||
subModuleCount: number;
|
||||
isLittleEndian: boolean;
|
||||
};
|
||||
|
||||
export type RTTrPM = {
|
||||
header: RTTrPHeader;
|
||||
modules: Trackable[];
|
||||
};
|
||||
|
||||
export type TrackableModule =
|
||||
|
||||
@@ -16,6 +16,7 @@ const goodTests = [
|
||||
size: 18,
|
||||
context: 305419896,
|
||||
subModuleCount: 0,
|
||||
isLittleEndian: false,
|
||||
},
|
||||
decoder: Decoders.RTTrPHeader,
|
||||
},
|
||||
@@ -219,6 +220,37 @@ const goodTests = [
|
||||
},
|
||||
decoder: Decoders.Trackable,
|
||||
},
|
||||
{
|
||||
description: 'RTTrPM + Empty Trackable',
|
||||
bytes: new Uint8Array([
|
||||
65, 84, 67, 52, 0, 2, 0, 0, 0, 1, 0, 0, 27, 18, 52, 86, 120, 1, 1, 0, 9, 4, 84, 101, 115, 116, 0,
|
||||
]),
|
||||
expected: {
|
||||
header: {
|
||||
intHeader: 0x4154,
|
||||
floatHeader: 0x4334,
|
||||
version: 2,
|
||||
packetID: 1,
|
||||
packetFormat: 0,
|
||||
size: 27,
|
||||
context: 0x12345678,
|
||||
subModuleCount: 1,
|
||||
isLittleEndian: false,
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
type: 0x01,
|
||||
size: 9,
|
||||
nameLength: 4,
|
||||
name: 'Test',
|
||||
timestamp: undefined,
|
||||
numberOfModules: 0,
|
||||
modules: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
decoder: Decoders.RTTrPM,
|
||||
},
|
||||
];
|
||||
|
||||
describe('RTTrP Bytes Decoding', () => {
|
||||
|
||||
Reference in New Issue
Block a user