add decoder for centroid position submodule

This commit is contained in:
2025-03-15 08:37:44 -05:00
parent 2f3d8486a0
commit 3c5cd86ae2
4 changed files with 59 additions and 0 deletions
+2
View File
@@ -1,5 +1,7 @@
import CentroidPosition from './motion/centroid-position';
import RTTrPHeader from './rttrp';
export const Decoders = {
RTTrPHeader,
CentroidPosition,
};
+31
View File
@@ -0,0 +1,31 @@
import { CentroidPosition } from '../../models';
export default (bytes: Uint8Array, isLittleEndian: boolean = false): CentroidPosition => {
if (bytes.length !== 29) {
throw new Error('Centroid Position module must be 29 bytes');
}
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const type = view.getUint8(0);
if (type !== 0x02) {
throw new Error('Centroid Position module must have a type of 0x02');
}
const size = view.getUint16(1, isLittleEndian);
if (size !== 29) {
throw new Error('Centroid Position module must be 29 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);
return {
type,
size,
latency,
x,
y,
z,
};
};
+10
View File
@@ -8,4 +8,14 @@ export type RTTrPHeader = {
context: number;
subModuleCount: number;
};
export type CentroidPosition = {
type: number;
size: number;
latency: number;
x: number;
y: number;
z: number;
};
};