mirror of
https://github.com/jwetzell/rttrp-js.git
synced 2026-09-12 01:19:32 +00:00
add decoder for tracked point position submodule
This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user