@slimevr/firmware-protocol
Advanced tools
+8
-0
| # @slimevr/firmware-protocol | ||
| ## 0.5.1 | ||
| ### Patch Changes | ||
| - 85438bb: Allow Vector and Quaternion types to accept objects | ||
| - Updated dependencies [85438bb] | ||
| - @slimevr/common@0.0.3 | ||
| ## 0.5.0 | ||
@@ -4,0 +12,0 @@ |
+2
-2
| { | ||
| "name": "@slimevr/firmware-protocol", | ||
| "version": "0.5.0", | ||
| "version": "0.5.1", | ||
| "main": "dist/index.js", | ||
@@ -12,3 +12,3 @@ "types": "dist/index.d.ts", | ||
| "dependencies": { | ||
| "@slimevr/common": "0.0.2" | ||
| "@slimevr/common": "0.0.3" | ||
| }, | ||
@@ -15,0 +15,0 @@ "devDependencies": { |
@@ -1,2 +0,2 @@ | ||
| import { Vector } from '@slimevr/common'; | ||
| import { Vector, toVector } from '@slimevr/common'; | ||
| import { Packet } from './Packet'; | ||
@@ -30,6 +30,8 @@ | ||
| data.writeFloatBE(acceleration[0], 12); | ||
| data.writeFloatBE(acceleration[1], 16); | ||
| data.writeFloatBE(acceleration[2], 20); | ||
| const accelerationVector = toVector(acceleration); | ||
| data.writeFloatBE(accelerationVector[0], 12); | ||
| data.writeFloatBE(accelerationVector[1], 16); | ||
| data.writeFloatBE(accelerationVector[2], 20); | ||
| if (sensorId !== null) { | ||
@@ -36,0 +38,0 @@ data.writeUInt8(sensorId, 24); |
@@ -1,2 +0,2 @@ | ||
| import { Quaternion } from '@slimevr/common'; | ||
| import { Quaternion, toQuaternion } from '@slimevr/common'; | ||
| import { ServerBoundRotationPacket } from '.'; | ||
@@ -35,7 +35,10 @@ import { PacketWithSensorId } from './Packet'; | ||
| buf.writeUintBE(RotationDataType.NORMAL, 1, 1); | ||
| buf.writeFloatBE(packet.rotation[0], 2); | ||
| buf.writeFloatBE(packet.rotation[1], 6); | ||
| buf.writeFloatBE(packet.rotation[2], 10); | ||
| buf.writeFloatBE(packet.rotation[3], 14); | ||
| const rotationQuaternion = toQuaternion(packet.rotation); | ||
| buf.writeFloatBE(rotationQuaternion[0], 2); | ||
| buf.writeFloatBE(rotationQuaternion[1], 6); | ||
| buf.writeFloatBE(rotationQuaternion[2], 10); | ||
| buf.writeFloatBE(rotationQuaternion[3], 14); | ||
| // I'd rather not want to jump through the deserializer | ||
@@ -65,7 +68,10 @@ return new ServerBoundRotationDataPacket(packet.number, buf); | ||
| buf.writeUintBE(dataType, 13, 1); | ||
| buf.writeFloatBE(rotation[0], 14); | ||
| buf.writeFloatBE(rotation[1], 18); | ||
| buf.writeFloatBE(rotation[2], 22); | ||
| buf.writeFloatBE(rotation[3], 26); | ||
| const rotationQuaternion = toQuaternion(rotation); | ||
| buf.writeFloatBE(rotationQuaternion[0], 14); | ||
| buf.writeFloatBE(rotationQuaternion[1], 18); | ||
| buf.writeFloatBE(rotationQuaternion[2], 22); | ||
| buf.writeFloatBE(rotationQuaternion[3], 26); | ||
| buf.writeUintBE(accuracyInfo, 30, 1); | ||
@@ -72,0 +78,0 @@ |
| > @slimevr/firmware-protocol@0.5.0 build E:\Development\SlimeVR\slimevr-node\packages\firmware-protocol | ||
| > tsup src/index.ts --format cjs,esm --dts | ||
| [34mCLI[39m Building entry: src/index.ts | ||
| [34mCLI[39m Using tsconfig: tsconfig.json | ||
| [34mCLI[39m tsup v7.2.0 | ||
| [34mCLI[39m Target: es2020 | ||
| [34mCJS[39m Build start | ||
| [34mESM[39m Build start | ||
| [32mCJS[39m [1mdist\index.js [22m[32m34.29 KB[39m | ||
| [32mCJS[39m ⚡️ Build success in 32ms | ||
| [32mESM[39m [1mdist\index.mjs [22m[32m30.95 KB[39m | ||
| [32mESM[39m ⚡️ Build success in 33ms | ||
| [34mDTS[39m Build start | ||
| [32mDTS[39m ⚡️ Build success in 751ms | ||
| [32mDTS[39m [1mdist\index.d.ts [22m[32m13.24 KB[39m | ||
| [32mDTS[39m [1mdist\index.d.mts [22m[32m13.24 KB[39m |
-350
| import { Quaternion, Vector } from '@slimevr/common'; | ||
| declare enum Protocol { | ||
| UNKNOWN = 0, | ||
| OWO_LEGACY = 1, | ||
| SLIMEVR_RAW = 2 | ||
| } | ||
| declare enum SensorStatus { | ||
| UNKNOWN = 0, | ||
| OK = 1, | ||
| ERROR = 2 | ||
| } | ||
| declare enum RawCalibrationDataType { | ||
| INTERNAL_GYRO = 1, | ||
| INTERNAL_ACCEL = 2, | ||
| INTERNAL_MAG = 3, | ||
| EXTERNAL_ALL = 4, | ||
| EXTERNAL_GYRO = 5, | ||
| EXTERNAL_ACCEL = 6, | ||
| EXTERNAL_MAG = 7 | ||
| } | ||
| declare enum SensorType { | ||
| UNKNOWN = 0, | ||
| MPU9250 = 1, | ||
| MPU6500 = 2, | ||
| BNO080 = 3, | ||
| BNO085 = 4, | ||
| BNO055 = 5, | ||
| MPU6050 = 6, | ||
| BNO086 = 7, | ||
| BMI160 = 8, | ||
| ICM20948 = 9 | ||
| } | ||
| declare enum MCUType { | ||
| UNKNOWN = 0, | ||
| ESP8266 = 1, | ||
| ESP32 = 2 | ||
| } | ||
| declare enum BoardType { | ||
| UNKNOWN = 0, | ||
| SLIMEVR_LEGACY = 1, | ||
| SLIMEVR_DEV = 2, | ||
| NODEMCU = 3, | ||
| CUSTOM = 4, | ||
| WROOM32 = 5, | ||
| WEMOSD1MINI = 6, | ||
| TTGO_TBASE = 7, | ||
| ESP01 = 8, | ||
| SLIMEVR = 9, | ||
| LOLIN_C3_MINI = 10 | ||
| } | ||
| declare const makeFeatureFlagContainer: <T extends Record<string, number>>(available: T) => { | ||
| new (flags?: Map<keyof T, boolean> | undefined): { | ||
| readonly "__#1@#flags"?: Map<keyof T, boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: keyof T): boolean; | ||
| getAllEnabled(): (keyof T)[]; | ||
| }; | ||
| unpack(packed: Buffer): { | ||
| readonly "__#1@#flags"?: Map<keyof T, boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: keyof T): boolean; | ||
| getAllEnabled(): (keyof T)[]; | ||
| }; | ||
| }; | ||
| declare const AVAILABLE_SERVER_FEATURE_FLAGS: { | ||
| readonly PROTOCOL_BUNDLE_SUPPORT: 0; | ||
| }; | ||
| declare type ServerFeatureFlag = keyof typeof AVAILABLE_SERVER_FEATURE_FLAGS; | ||
| declare const ServerFeatureFlags: { | ||
| new (flags?: Map<"PROTOCOL_BUNDLE_SUPPORT", boolean> | undefined): { | ||
| readonly "__#1@#flags"?: Map<"PROTOCOL_BUNDLE_SUPPORT", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "PROTOCOL_BUNDLE_SUPPORT"): boolean; | ||
| getAllEnabled(): "PROTOCOL_BUNDLE_SUPPORT"[]; | ||
| }; | ||
| unpack(packed: Buffer): { | ||
| readonly "__#1@#flags"?: Map<"PROTOCOL_BUNDLE_SUPPORT", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "PROTOCOL_BUNDLE_SUPPORT"): boolean; | ||
| getAllEnabled(): "PROTOCOL_BUNDLE_SUPPORT"[]; | ||
| }; | ||
| }; | ||
| declare type ServerFeatureFlags = ReturnType<(typeof ServerFeatureFlags)['unpack']>; | ||
| declare const AVAILABLE_FIRMWARE_FEATURE_FLAGS: { | ||
| readonly LEGACY_SLIMEVR_TRACKER: 0; | ||
| readonly ROTATION_DATA: 1; | ||
| readonly POSITION_DATA: 2; | ||
| }; | ||
| declare type FirmwareFeatureFlag = keyof typeof AVAILABLE_FIRMWARE_FEATURE_FLAGS; | ||
| declare const FirmwareFeatureFlags: { | ||
| new (flags?: Map<"LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA", boolean> | undefined): { | ||
| readonly "__#1@#flags"?: Map<"LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA"): boolean; | ||
| getAllEnabled(): ("LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA")[]; | ||
| }; | ||
| unpack(packed: Buffer): { | ||
| readonly "__#1@#flags"?: Map<"LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA"): boolean; | ||
| getAllEnabled(): ("LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA")[]; | ||
| }; | ||
| }; | ||
| declare type FirmwareFeatureFlags = ReturnType<(typeof FirmwareFeatureFlags)['unpack']>; | ||
| declare abstract class Packet { | ||
| readonly number: bigint; | ||
| readonly type: number; | ||
| static readonly SERIAL = 11; | ||
| static readonly ROTATION_2 = 16; | ||
| static readonly PROTOCOL_CHANGE = 200; | ||
| constructor(number: bigint, type: number); | ||
| } | ||
| declare abstract class PacketWithSensorId extends Packet { | ||
| readonly sensorId: number; | ||
| constructor(number: bigint, type: number, sensorId: number); | ||
| } | ||
| declare class DeviceBoundFeatureFlagsPacket extends Packet { | ||
| readonly flags: ServerFeatureFlags; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, flags: ServerFeatureFlags): Buffer; | ||
| } | ||
| declare class DeviceBoundHandshakePacket extends Packet { | ||
| constructor(number: bigint); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(): Buffer; | ||
| } | ||
| declare class DeviceBoundHeartbeatPacket extends Packet { | ||
| constructor(number: bigint); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(num: bigint): Buffer; | ||
| } | ||
| declare class DeviceBoundPingPacket extends Packet { | ||
| readonly id: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, id: number): Buffer; | ||
| } | ||
| declare class DeviceBoundSensorInfoPacket extends PacketWithSensorId { | ||
| readonly sensorStatus: SensorStatus; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(sensorId: number, sensorStatus: SensorStatus): Buffer; | ||
| } | ||
| declare class ServerBoundCorrectionDataPacket extends Packet { | ||
| readonly sensorId: number; | ||
| readonly quaternion: Quaternion; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundFusedIMUDataPacket extends Packet { | ||
| readonly sensorId: number; | ||
| readonly quaternion: Quaternion; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundRawIMUDataPacket extends Packet { | ||
| readonly sensorId: number; | ||
| readonly rotation: Vector; | ||
| readonly acceleration: Vector; | ||
| readonly magnetometer: Vector; | ||
| readonly rotationAccuracy: number; | ||
| readonly accelerationAccuracy: number; | ||
| readonly magnetometerAccuracy: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class InspectionPacketParser { | ||
| static parseRawDataPacket: (number: bigint, data: Buffer) => ServerBoundRawIMUDataPacket | ServerBoundFusedIMUDataPacket | ServerBoundCorrectionDataPacket | null; | ||
| static get type(): number; | ||
| } | ||
| declare class ServerBoundAccelPacket extends Packet { | ||
| readonly acceleration: Vector; | ||
| readonly sensorId: number | null; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, sensorId: number | null, acceleration: Vector): Buffer; | ||
| } | ||
| declare class ServerBoundBatteryLevelPacket extends Packet { | ||
| readonly voltage: number; | ||
| readonly percentage: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, voltage: number, percentage: number): Buffer; | ||
| } | ||
| declare class ServerBoundBundlePacket extends Packet { | ||
| readonly packets: Packet[]; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundCalibrationFinishedPacket extends PacketWithSensorId { | ||
| readonly dataType: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundErrorPacket extends PacketWithSensorId { | ||
| readonly reason: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundFeatureFlagsPacket extends Packet { | ||
| readonly flags: FirmwareFeatureFlags; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundGyroPacket extends Packet { | ||
| readonly rotation: Vector; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundHandshakePacket extends Packet { | ||
| readonly boardType: BoardType; | ||
| readonly imuType: SensorType; | ||
| readonly mcuType: MCUType; | ||
| readonly firmwareBuild: number; | ||
| readonly firmware: string; | ||
| readonly mac: string; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| private readAscii; | ||
| toString(): string; | ||
| static encode(number: bigint, boardType: BoardType, imuType: SensorType, mcuType: MCUType, firmwareBuild: number, firmware: string, mac: [number, number, number, number, number, number]): Buffer; | ||
| } | ||
| declare class ServerBoundHeartbeatPacket extends Packet { | ||
| constructor(number: bigint); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint): Buffer; | ||
| } | ||
| declare class ServerBoundMagnetometerAccuracyPacket extends PacketWithSensorId { | ||
| readonly accuracy: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundPongPacket extends Packet { | ||
| readonly id: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, id: number): Buffer; | ||
| } | ||
| declare class ServerBoundRawCalibrationDataPacket extends PacketWithSensorId { | ||
| readonly dataType: RawCalibrationDataType; | ||
| readonly data: Vector; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare enum RotationDataType { | ||
| NORMAL = 1, | ||
| CORRECTION = 2 | ||
| } | ||
| declare class ServerBoundRotationDataPacket extends PacketWithSensorId { | ||
| readonly dataType: RotationDataType; | ||
| readonly rotation: Quaternion; | ||
| readonly accuracyInfo: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| static fromRotationPacket(packet: ServerBoundRotationPacket): ServerBoundRotationDataPacket; | ||
| toString(): string; | ||
| static encode(number: bigint, sensorId: number, dataType: RotationDataType, rotation: Quaternion, accuracyInfo: number): Buffer; | ||
| } | ||
| declare class ServerBoundRotationPacket extends Packet { | ||
| readonly rotation: Quaternion; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundSensorInfoPacket extends PacketWithSensorId { | ||
| readonly sensorStatus: SensorStatus; | ||
| readonly sensorType: SensorType; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| static encode(number: bigint, sensorId: number, sensorStatus: SensorStatus, sensorType: SensorType): Buffer; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundSignalStrengthPacket extends PacketWithSensorId { | ||
| readonly signalStrength: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundTapPacket extends PacketWithSensorId { | ||
| readonly value: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundTemperaturePacket extends PacketWithSensorId { | ||
| readonly temperature: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare const parse: (data: Buffer, isDeviceBound: boolean, isInBundle?: boolean) => DeviceBoundFeatureFlagsPacket | DeviceBoundHandshakePacket | DeviceBoundHeartbeatPacket | DeviceBoundPingPacket | DeviceBoundSensorInfoPacket | ServerBoundAccelPacket | ServerBoundBatteryLevelPacket | ServerBoundBundlePacket | ServerBoundHeartbeatPacket | ServerBoundRotationPacket | ServerBoundGyroPacket | ServerBoundHandshakePacket | ServerBoundRawCalibrationDataPacket | ServerBoundCalibrationFinishedPacket | ServerBoundPongPacket | ServerBoundTapPacket | ServerBoundErrorPacket | ServerBoundSensorInfoPacket | ServerBoundRotationDataPacket | ServerBoundFeatureFlagsPacket | ServerBoundMagnetometerAccuracyPacket | ServerBoundSignalStrengthPacket | ServerBoundTemperaturePacket | ServerBoundRawIMUDataPacket | ServerBoundFusedIMUDataPacket | ServerBoundCorrectionDataPacket | null; | ||
| export { AVAILABLE_FIRMWARE_FEATURE_FLAGS, AVAILABLE_SERVER_FEATURE_FLAGS, BoardType, DeviceBoundFeatureFlagsPacket, DeviceBoundHandshakePacket, DeviceBoundHeartbeatPacket, DeviceBoundPingPacket, DeviceBoundSensorInfoPacket, FirmwareFeatureFlag, FirmwareFeatureFlags, InspectionPacketParser, MCUType, Packet, PacketWithSensorId, Protocol, RawCalibrationDataType, RotationDataType, SensorStatus, SensorType, ServerBoundAccelPacket, ServerBoundBatteryLevelPacket, ServerBoundBundlePacket, ServerBoundCalibrationFinishedPacket, ServerBoundCorrectionDataPacket, ServerBoundErrorPacket, ServerBoundFeatureFlagsPacket, ServerBoundFusedIMUDataPacket, ServerBoundGyroPacket, ServerBoundHandshakePacket, ServerBoundHeartbeatPacket, ServerBoundMagnetometerAccuracyPacket, ServerBoundPongPacket, ServerBoundRawCalibrationDataPacket, ServerBoundRawIMUDataPacket, ServerBoundRotationDataPacket, ServerBoundRotationPacket, ServerBoundSensorInfoPacket, ServerBoundSignalStrengthPacket, ServerBoundTapPacket, ServerBoundTemperaturePacket, ServerFeatureFlag, ServerFeatureFlags, makeFeatureFlagContainer, parse }; |
-350
| import { Quaternion, Vector } from '@slimevr/common'; | ||
| declare enum Protocol { | ||
| UNKNOWN = 0, | ||
| OWO_LEGACY = 1, | ||
| SLIMEVR_RAW = 2 | ||
| } | ||
| declare enum SensorStatus { | ||
| UNKNOWN = 0, | ||
| OK = 1, | ||
| ERROR = 2 | ||
| } | ||
| declare enum RawCalibrationDataType { | ||
| INTERNAL_GYRO = 1, | ||
| INTERNAL_ACCEL = 2, | ||
| INTERNAL_MAG = 3, | ||
| EXTERNAL_ALL = 4, | ||
| EXTERNAL_GYRO = 5, | ||
| EXTERNAL_ACCEL = 6, | ||
| EXTERNAL_MAG = 7 | ||
| } | ||
| declare enum SensorType { | ||
| UNKNOWN = 0, | ||
| MPU9250 = 1, | ||
| MPU6500 = 2, | ||
| BNO080 = 3, | ||
| BNO085 = 4, | ||
| BNO055 = 5, | ||
| MPU6050 = 6, | ||
| BNO086 = 7, | ||
| BMI160 = 8, | ||
| ICM20948 = 9 | ||
| } | ||
| declare enum MCUType { | ||
| UNKNOWN = 0, | ||
| ESP8266 = 1, | ||
| ESP32 = 2 | ||
| } | ||
| declare enum BoardType { | ||
| UNKNOWN = 0, | ||
| SLIMEVR_LEGACY = 1, | ||
| SLIMEVR_DEV = 2, | ||
| NODEMCU = 3, | ||
| CUSTOM = 4, | ||
| WROOM32 = 5, | ||
| WEMOSD1MINI = 6, | ||
| TTGO_TBASE = 7, | ||
| ESP01 = 8, | ||
| SLIMEVR = 9, | ||
| LOLIN_C3_MINI = 10 | ||
| } | ||
| declare const makeFeatureFlagContainer: <T extends Record<string, number>>(available: T) => { | ||
| new (flags?: Map<keyof T, boolean> | undefined): { | ||
| readonly "__#1@#flags"?: Map<keyof T, boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: keyof T): boolean; | ||
| getAllEnabled(): (keyof T)[]; | ||
| }; | ||
| unpack(packed: Buffer): { | ||
| readonly "__#1@#flags"?: Map<keyof T, boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: keyof T): boolean; | ||
| getAllEnabled(): (keyof T)[]; | ||
| }; | ||
| }; | ||
| declare const AVAILABLE_SERVER_FEATURE_FLAGS: { | ||
| readonly PROTOCOL_BUNDLE_SUPPORT: 0; | ||
| }; | ||
| declare type ServerFeatureFlag = keyof typeof AVAILABLE_SERVER_FEATURE_FLAGS; | ||
| declare const ServerFeatureFlags: { | ||
| new (flags?: Map<"PROTOCOL_BUNDLE_SUPPORT", boolean> | undefined): { | ||
| readonly "__#1@#flags"?: Map<"PROTOCOL_BUNDLE_SUPPORT", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "PROTOCOL_BUNDLE_SUPPORT"): boolean; | ||
| getAllEnabled(): "PROTOCOL_BUNDLE_SUPPORT"[]; | ||
| }; | ||
| unpack(packed: Buffer): { | ||
| readonly "__#1@#flags"?: Map<"PROTOCOL_BUNDLE_SUPPORT", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "PROTOCOL_BUNDLE_SUPPORT"): boolean; | ||
| getAllEnabled(): "PROTOCOL_BUNDLE_SUPPORT"[]; | ||
| }; | ||
| }; | ||
| declare type ServerFeatureFlags = ReturnType<(typeof ServerFeatureFlags)['unpack']>; | ||
| declare const AVAILABLE_FIRMWARE_FEATURE_FLAGS: { | ||
| readonly LEGACY_SLIMEVR_TRACKER: 0; | ||
| readonly ROTATION_DATA: 1; | ||
| readonly POSITION_DATA: 2; | ||
| }; | ||
| declare type FirmwareFeatureFlag = keyof typeof AVAILABLE_FIRMWARE_FEATURE_FLAGS; | ||
| declare const FirmwareFeatureFlags: { | ||
| new (flags?: Map<"LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA", boolean> | undefined): { | ||
| readonly "__#1@#flags"?: Map<"LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA"): boolean; | ||
| getAllEnabled(): ("LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA")[]; | ||
| }; | ||
| unpack(packed: Buffer): { | ||
| readonly "__#1@#flags"?: Map<"LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA", boolean> | undefined; | ||
| readonly isAvailable: boolean; | ||
| pack(): Buffer; | ||
| has(flag: "LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA"): boolean; | ||
| getAllEnabled(): ("LEGACY_SLIMEVR_TRACKER" | "ROTATION_DATA" | "POSITION_DATA")[]; | ||
| }; | ||
| }; | ||
| declare type FirmwareFeatureFlags = ReturnType<(typeof FirmwareFeatureFlags)['unpack']>; | ||
| declare abstract class Packet { | ||
| readonly number: bigint; | ||
| readonly type: number; | ||
| static readonly SERIAL = 11; | ||
| static readonly ROTATION_2 = 16; | ||
| static readonly PROTOCOL_CHANGE = 200; | ||
| constructor(number: bigint, type: number); | ||
| } | ||
| declare abstract class PacketWithSensorId extends Packet { | ||
| readonly sensorId: number; | ||
| constructor(number: bigint, type: number, sensorId: number); | ||
| } | ||
| declare class DeviceBoundFeatureFlagsPacket extends Packet { | ||
| readonly flags: ServerFeatureFlags; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, flags: ServerFeatureFlags): Buffer; | ||
| } | ||
| declare class DeviceBoundHandshakePacket extends Packet { | ||
| constructor(number: bigint); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(): Buffer; | ||
| } | ||
| declare class DeviceBoundHeartbeatPacket extends Packet { | ||
| constructor(number: bigint); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(num: bigint): Buffer; | ||
| } | ||
| declare class DeviceBoundPingPacket extends Packet { | ||
| readonly id: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, id: number): Buffer; | ||
| } | ||
| declare class DeviceBoundSensorInfoPacket extends PacketWithSensorId { | ||
| readonly sensorStatus: SensorStatus; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(sensorId: number, sensorStatus: SensorStatus): Buffer; | ||
| } | ||
| declare class ServerBoundCorrectionDataPacket extends Packet { | ||
| readonly sensorId: number; | ||
| readonly quaternion: Quaternion; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundFusedIMUDataPacket extends Packet { | ||
| readonly sensorId: number; | ||
| readonly quaternion: Quaternion; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundRawIMUDataPacket extends Packet { | ||
| readonly sensorId: number; | ||
| readonly rotation: Vector; | ||
| readonly acceleration: Vector; | ||
| readonly magnetometer: Vector; | ||
| readonly rotationAccuracy: number; | ||
| readonly accelerationAccuracy: number; | ||
| readonly magnetometerAccuracy: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class InspectionPacketParser { | ||
| static parseRawDataPacket: (number: bigint, data: Buffer) => ServerBoundRawIMUDataPacket | ServerBoundFusedIMUDataPacket | ServerBoundCorrectionDataPacket | null; | ||
| static get type(): number; | ||
| } | ||
| declare class ServerBoundAccelPacket extends Packet { | ||
| readonly acceleration: Vector; | ||
| readonly sensorId: number | null; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, sensorId: number | null, acceleration: Vector): Buffer; | ||
| } | ||
| declare class ServerBoundBatteryLevelPacket extends Packet { | ||
| readonly voltage: number; | ||
| readonly percentage: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, voltage: number, percentage: number): Buffer; | ||
| } | ||
| declare class ServerBoundBundlePacket extends Packet { | ||
| readonly packets: Packet[]; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundCalibrationFinishedPacket extends PacketWithSensorId { | ||
| readonly dataType: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundErrorPacket extends PacketWithSensorId { | ||
| readonly reason: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundFeatureFlagsPacket extends Packet { | ||
| readonly flags: FirmwareFeatureFlags; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundGyroPacket extends Packet { | ||
| readonly rotation: Vector; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundHandshakePacket extends Packet { | ||
| readonly boardType: BoardType; | ||
| readonly imuType: SensorType; | ||
| readonly mcuType: MCUType; | ||
| readonly firmwareBuild: number; | ||
| readonly firmware: string; | ||
| readonly mac: string; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| private readAscii; | ||
| toString(): string; | ||
| static encode(number: bigint, boardType: BoardType, imuType: SensorType, mcuType: MCUType, firmwareBuild: number, firmware: string, mac: [number, number, number, number, number, number]): Buffer; | ||
| } | ||
| declare class ServerBoundHeartbeatPacket extends Packet { | ||
| constructor(number: bigint); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint): Buffer; | ||
| } | ||
| declare class ServerBoundMagnetometerAccuracyPacket extends PacketWithSensorId { | ||
| readonly accuracy: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundPongPacket extends Packet { | ||
| readonly id: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| static encode(number: bigint, id: number): Buffer; | ||
| } | ||
| declare class ServerBoundRawCalibrationDataPacket extends PacketWithSensorId { | ||
| readonly dataType: RawCalibrationDataType; | ||
| readonly data: Vector; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare enum RotationDataType { | ||
| NORMAL = 1, | ||
| CORRECTION = 2 | ||
| } | ||
| declare class ServerBoundRotationDataPacket extends PacketWithSensorId { | ||
| readonly dataType: RotationDataType; | ||
| readonly rotation: Quaternion; | ||
| readonly accuracyInfo: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| static fromRotationPacket(packet: ServerBoundRotationPacket): ServerBoundRotationDataPacket; | ||
| toString(): string; | ||
| static encode(number: bigint, sensorId: number, dataType: RotationDataType, rotation: Quaternion, accuracyInfo: number): Buffer; | ||
| } | ||
| declare class ServerBoundRotationPacket extends Packet { | ||
| readonly rotation: Quaternion; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundSensorInfoPacket extends PacketWithSensorId { | ||
| readonly sensorStatus: SensorStatus; | ||
| readonly sensorType: SensorType; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| static encode(number: bigint, sensorId: number, sensorStatus: SensorStatus, sensorType: SensorType): Buffer; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundSignalStrengthPacket extends PacketWithSensorId { | ||
| readonly signalStrength: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundTapPacket extends PacketWithSensorId { | ||
| readonly value: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare class ServerBoundTemperaturePacket extends PacketWithSensorId { | ||
| readonly temperature: number; | ||
| constructor(number: bigint, data: Buffer); | ||
| static get type(): number; | ||
| toString(): string; | ||
| } | ||
| declare const parse: (data: Buffer, isDeviceBound: boolean, isInBundle?: boolean) => DeviceBoundFeatureFlagsPacket | DeviceBoundHandshakePacket | DeviceBoundHeartbeatPacket | DeviceBoundPingPacket | DeviceBoundSensorInfoPacket | ServerBoundAccelPacket | ServerBoundBatteryLevelPacket | ServerBoundBundlePacket | ServerBoundHeartbeatPacket | ServerBoundRotationPacket | ServerBoundGyroPacket | ServerBoundHandshakePacket | ServerBoundRawCalibrationDataPacket | ServerBoundCalibrationFinishedPacket | ServerBoundPongPacket | ServerBoundTapPacket | ServerBoundErrorPacket | ServerBoundSensorInfoPacket | ServerBoundRotationDataPacket | ServerBoundFeatureFlagsPacket | ServerBoundMagnetometerAccuracyPacket | ServerBoundSignalStrengthPacket | ServerBoundTemperaturePacket | ServerBoundRawIMUDataPacket | ServerBoundFusedIMUDataPacket | ServerBoundCorrectionDataPacket | null; | ||
| export { AVAILABLE_FIRMWARE_FEATURE_FLAGS, AVAILABLE_SERVER_FEATURE_FLAGS, BoardType, DeviceBoundFeatureFlagsPacket, DeviceBoundHandshakePacket, DeviceBoundHeartbeatPacket, DeviceBoundPingPacket, DeviceBoundSensorInfoPacket, FirmwareFeatureFlag, FirmwareFeatureFlags, InspectionPacketParser, MCUType, Packet, PacketWithSensorId, Protocol, RawCalibrationDataType, RotationDataType, SensorStatus, SensorType, ServerBoundAccelPacket, ServerBoundBatteryLevelPacket, ServerBoundBundlePacket, ServerBoundCalibrationFinishedPacket, ServerBoundCorrectionDataPacket, ServerBoundErrorPacket, ServerBoundFeatureFlagsPacket, ServerBoundFusedIMUDataPacket, ServerBoundGyroPacket, ServerBoundHandshakePacket, ServerBoundHeartbeatPacket, ServerBoundMagnetometerAccuracyPacket, ServerBoundPongPacket, ServerBoundRawCalibrationDataPacket, ServerBoundRawIMUDataPacket, ServerBoundRotationDataPacket, ServerBoundRotationPacket, ServerBoundSensorInfoPacket, ServerBoundSignalStrengthPacket, ServerBoundTapPacket, ServerBoundTemperaturePacket, ServerFeatureFlag, ServerFeatureFlags, makeFeatureFlagContainer, parse }; |
-964
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __accessCheck = (obj, member, msg) => { | ||
| if (!member.has(obj)) | ||
| throw TypeError("Cannot " + msg); | ||
| }; | ||
| var __privateGet = (obj, member, getter) => { | ||
| __accessCheck(obj, member, "read from private field"); | ||
| return getter ? getter.call(obj) : member.get(obj); | ||
| }; | ||
| var __privateAdd = (obj, member, value) => { | ||
| if (member.has(obj)) | ||
| throw TypeError("Cannot add the same private member more than once"); | ||
| member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| }; | ||
| var __privateSet = (obj, member, value, setter) => { | ||
| __accessCheck(obj, member, "write to private field"); | ||
| setter ? setter.call(obj, value) : member.set(obj, value); | ||
| return value; | ||
| }; | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| AVAILABLE_FIRMWARE_FEATURE_FLAGS: () => AVAILABLE_FIRMWARE_FEATURE_FLAGS, | ||
| AVAILABLE_SERVER_FEATURE_FLAGS: () => AVAILABLE_SERVER_FEATURE_FLAGS, | ||
| BoardType: () => BoardType, | ||
| DeviceBoundFeatureFlagsPacket: () => DeviceBoundFeatureFlagsPacket, | ||
| DeviceBoundHandshakePacket: () => DeviceBoundHandshakePacket, | ||
| DeviceBoundHeartbeatPacket: () => DeviceBoundHeartbeatPacket, | ||
| DeviceBoundPingPacket: () => DeviceBoundPingPacket, | ||
| DeviceBoundSensorInfoPacket: () => DeviceBoundSensorInfoPacket, | ||
| FirmwareFeatureFlags: () => FirmwareFeatureFlags, | ||
| InspectionPacketParser: () => InspectionPacketParser, | ||
| MCUType: () => MCUType, | ||
| Packet: () => Packet, | ||
| PacketWithSensorId: () => PacketWithSensorId, | ||
| Protocol: () => Protocol, | ||
| RawCalibrationDataType: () => RawCalibrationDataType, | ||
| RotationDataType: () => RotationDataType, | ||
| SensorStatus: () => SensorStatus, | ||
| SensorType: () => SensorType, | ||
| ServerBoundAccelPacket: () => ServerBoundAccelPacket, | ||
| ServerBoundBatteryLevelPacket: () => ServerBoundBatteryLevelPacket, | ||
| ServerBoundBundlePacket: () => ServerBoundBundlePacket, | ||
| ServerBoundCalibrationFinishedPacket: () => ServerBoundCalibrationFinishedPacket, | ||
| ServerBoundCorrectionDataPacket: () => ServerBoundCorrectionDataPacket, | ||
| ServerBoundErrorPacket: () => ServerBoundErrorPacket, | ||
| ServerBoundFeatureFlagsPacket: () => ServerBoundFeatureFlagsPacket, | ||
| ServerBoundFusedIMUDataPacket: () => ServerBoundFusedIMUDataPacket, | ||
| ServerBoundGyroPacket: () => ServerBoundGyroPacket, | ||
| ServerBoundHandshakePacket: () => ServerBoundHandshakePacket, | ||
| ServerBoundHeartbeatPacket: () => ServerBoundHeartbeatPacket, | ||
| ServerBoundMagnetometerAccuracyPacket: () => ServerBoundMagnetometerAccuracyPacket, | ||
| ServerBoundPongPacket: () => ServerBoundPongPacket, | ||
| ServerBoundRawCalibrationDataPacket: () => ServerBoundRawCalibrationDataPacket, | ||
| ServerBoundRawIMUDataPacket: () => ServerBoundRawIMUDataPacket, | ||
| ServerBoundRotationDataPacket: () => ServerBoundRotationDataPacket, | ||
| ServerBoundRotationPacket: () => ServerBoundRotationPacket, | ||
| ServerBoundSensorInfoPacket: () => ServerBoundSensorInfoPacket, | ||
| ServerBoundSignalStrengthPacket: () => ServerBoundSignalStrengthPacket, | ||
| ServerBoundTapPacket: () => ServerBoundTapPacket, | ||
| ServerBoundTemperaturePacket: () => ServerBoundTemperaturePacket, | ||
| ServerFeatureFlags: () => ServerFeatureFlags, | ||
| makeFeatureFlagContainer: () => makeFeatureFlagContainer, | ||
| parse: () => parse | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| // src/constants.ts | ||
| var Protocol = /* @__PURE__ */ ((Protocol2) => { | ||
| Protocol2[Protocol2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| Protocol2[Protocol2["OWO_LEGACY"] = 1] = "OWO_LEGACY"; | ||
| Protocol2[Protocol2["SLIMEVR_RAW"] = 2] = "SLIMEVR_RAW"; | ||
| return Protocol2; | ||
| })(Protocol || {}); | ||
| var SensorStatus = /* @__PURE__ */ ((SensorStatus2) => { | ||
| SensorStatus2[SensorStatus2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| SensorStatus2[SensorStatus2["OK"] = 1] = "OK"; | ||
| SensorStatus2[SensorStatus2["ERROR"] = 2] = "ERROR"; | ||
| return SensorStatus2; | ||
| })(SensorStatus || {}); | ||
| var RawCalibrationDataType = /* @__PURE__ */ ((RawCalibrationDataType2) => { | ||
| RawCalibrationDataType2[RawCalibrationDataType2["INTERNAL_GYRO"] = 1] = "INTERNAL_GYRO"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["INTERNAL_ACCEL"] = 2] = "INTERNAL_ACCEL"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["INTERNAL_MAG"] = 3] = "INTERNAL_MAG"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_ALL"] = 4] = "EXTERNAL_ALL"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_GYRO"] = 5] = "EXTERNAL_GYRO"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_ACCEL"] = 6] = "EXTERNAL_ACCEL"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_MAG"] = 7] = "EXTERNAL_MAG"; | ||
| return RawCalibrationDataType2; | ||
| })(RawCalibrationDataType || {}); | ||
| var SensorType = /* @__PURE__ */ ((SensorType2) => { | ||
| SensorType2[SensorType2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| SensorType2[SensorType2["MPU9250"] = 1] = "MPU9250"; | ||
| SensorType2[SensorType2["MPU6500"] = 2] = "MPU6500"; | ||
| SensorType2[SensorType2["BNO080"] = 3] = "BNO080"; | ||
| SensorType2[SensorType2["BNO085"] = 4] = "BNO085"; | ||
| SensorType2[SensorType2["BNO055"] = 5] = "BNO055"; | ||
| SensorType2[SensorType2["MPU6050"] = 6] = "MPU6050"; | ||
| SensorType2[SensorType2["BNO086"] = 7] = "BNO086"; | ||
| SensorType2[SensorType2["BMI160"] = 8] = "BMI160"; | ||
| SensorType2[SensorType2["ICM20948"] = 9] = "ICM20948"; | ||
| return SensorType2; | ||
| })(SensorType || {}); | ||
| var MCUType = /* @__PURE__ */ ((MCUType2) => { | ||
| MCUType2[MCUType2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| MCUType2[MCUType2["ESP8266"] = 1] = "ESP8266"; | ||
| MCUType2[MCUType2["ESP32"] = 2] = "ESP32"; | ||
| return MCUType2; | ||
| })(MCUType || {}); | ||
| var BoardType = /* @__PURE__ */ ((BoardType2) => { | ||
| BoardType2[BoardType2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| BoardType2[BoardType2["SLIMEVR_LEGACY"] = 1] = "SLIMEVR_LEGACY"; | ||
| BoardType2[BoardType2["SLIMEVR_DEV"] = 2] = "SLIMEVR_DEV"; | ||
| BoardType2[BoardType2["NODEMCU"] = 3] = "NODEMCU"; | ||
| BoardType2[BoardType2["CUSTOM"] = 4] = "CUSTOM"; | ||
| BoardType2[BoardType2["WROOM32"] = 5] = "WROOM32"; | ||
| BoardType2[BoardType2["WEMOSD1MINI"] = 6] = "WEMOSD1MINI"; | ||
| BoardType2[BoardType2["TTGO_TBASE"] = 7] = "TTGO_TBASE"; | ||
| BoardType2[BoardType2["ESP01"] = 8] = "ESP01"; | ||
| BoardType2[BoardType2["SLIMEVR"] = 9] = "SLIMEVR"; | ||
| BoardType2[BoardType2["LOLIN_C3_MINI"] = 10] = "LOLIN_C3_MINI"; | ||
| return BoardType2; | ||
| })(BoardType || {}); | ||
| // src/FeatureFlags.ts | ||
| var makeFeatureFlagContainer = (available) => { | ||
| var _flags, _a; | ||
| const allFlags = Object.entries(available); | ||
| return _a = class { | ||
| constructor(flags) { | ||
| __privateAdd(this, _flags, void 0); | ||
| __privateSet(this, _flags, flags); | ||
| } | ||
| static unpack(packed) { | ||
| const flags = /* @__PURE__ */ new Map(); | ||
| for (const [key, position] of allFlags) { | ||
| const posInPacked = Math.floor(position / 8); | ||
| const posInByte = position % 8; | ||
| const flag = packed[posInPacked] & 1 << posInByte; | ||
| const enabled = flag != 0; | ||
| flags.set(key, enabled); | ||
| } | ||
| return new this(flags); | ||
| } | ||
| get isAvailable() { | ||
| return !!__privateGet(this, _flags); | ||
| } | ||
| pack() { | ||
| const packed = Buffer.alloc(Object.keys(available).length / 8 + 1); | ||
| for (const position of Array.from(__privateGet(this, _flags)?.entries() ?? []).filter(([_, v]) => v).map(([k]) => available[k])) { | ||
| const posInPacked = Math.floor(position / 8); | ||
| const posInByte = position % 8; | ||
| packed[posInPacked] |= 1 << posInByte; | ||
| } | ||
| return packed; | ||
| } | ||
| has(flag) { | ||
| return __privateGet(this, _flags)?.get(flag) ?? false; | ||
| } | ||
| getAllEnabled() { | ||
| return Array.from(__privateGet(this, _flags)?.entries() ?? []).filter(([_, v]) => v).map(([key]) => key); | ||
| } | ||
| }, _flags = new WeakMap(), _a; | ||
| }; | ||
| var AVAILABLE_SERVER_FEATURE_FLAGS = { | ||
| PROTOCOL_BUNDLE_SUPPORT: 0 | ||
| }; | ||
| var ServerFeatureFlags = makeFeatureFlagContainer(AVAILABLE_SERVER_FEATURE_FLAGS); | ||
| var AVAILABLE_FIRMWARE_FEATURE_FLAGS = { | ||
| // The tracker sends all information that firmware 0.3.3 and below sends | ||
| LEGACY_SLIMEVR_TRACKER: 0, | ||
| // The tracker sends rotation data | ||
| ROTATION_DATA: 1, | ||
| // The tracker sends position data | ||
| POSITION_DATA: 2 | ||
| }; | ||
| var FirmwareFeatureFlags = makeFeatureFlagContainer(AVAILABLE_FIRMWARE_FEATURE_FLAGS); | ||
| // src/packets/Packet.ts | ||
| var Packet = class { | ||
| constructor(number, type) { | ||
| this.number = number; | ||
| this.type = type; | ||
| } | ||
| }; | ||
| // Not implemented | ||
| Packet.SERIAL = 11; | ||
| Packet.ROTATION_2 = 16; | ||
| Packet.PROTOCOL_CHANGE = 200; | ||
| var PacketWithSensorId = class extends Packet { | ||
| constructor(number, type, sensorId) { | ||
| super(number, type); | ||
| this.sensorId = sensorId; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundFeatureFlagsPacket.ts | ||
| var DeviceBoundFeatureFlagsPacket = class _DeviceBoundFeatureFlagsPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _DeviceBoundFeatureFlagsPacket.type); | ||
| this.flags = ServerFeatureFlags.unpack(data); | ||
| } | ||
| static get type() { | ||
| return 22; | ||
| } | ||
| toString() { | ||
| return `DeviceBoundFeatureFlagsPacket{flags: ${this.flags.getAllEnabled().join(",")}}`; | ||
| } | ||
| static encode(number, flags) { | ||
| const packed = flags.pack(); | ||
| const buf = Buffer.alloc(4 + 8); | ||
| buf.writeInt32BE(_DeviceBoundFeatureFlagsPacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| return Buffer.concat([buf, packed]); | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundHandshakePacket.ts | ||
| var DeviceBoundHandshakePacket = class _DeviceBoundHandshakePacket extends Packet { | ||
| constructor(number) { | ||
| super(number, _DeviceBoundHandshakePacket.type); | ||
| } | ||
| static get type() { | ||
| return 3; | ||
| } | ||
| toString() { | ||
| return "DeviceBoundHandshakePacket{}"; | ||
| } | ||
| static encode() { | ||
| const buf = Buffer.alloc(14); | ||
| buf.writeUint8(this.type); | ||
| buf.write("Hey OVR =D 5", 1, "ascii"); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundHeartbeatPacket.ts | ||
| var DeviceBoundHeartbeatPacket = class _DeviceBoundHeartbeatPacket extends Packet { | ||
| constructor(number) { | ||
| super(number, _DeviceBoundHeartbeatPacket.type); | ||
| } | ||
| static get type() { | ||
| return 1; | ||
| } | ||
| toString() { | ||
| return "DeviceBoundHeartbeatPacket{}"; | ||
| } | ||
| static encode(num) { | ||
| const buf = Buffer.alloc(4 + 8); | ||
| buf.writeInt32BE(this.type); | ||
| buf.writeBigInt64BE(num, 4); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundPingPacket.ts | ||
| var DeviceBoundPingPacket = class _DeviceBoundPingPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _DeviceBoundPingPacket.type); | ||
| this.id = data.readInt32BE(0); | ||
| } | ||
| static get type() { | ||
| return 10; | ||
| } | ||
| toString() { | ||
| return `DeviceBoundPingPacket{id: ${this.id}}`; | ||
| } | ||
| static encode(number, id) { | ||
| const buf = Buffer.alloc(4 + 8 + 4); | ||
| buf.writeInt32BE(this.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeInt32BE(id, 12); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundSensorInfoPacket.ts | ||
| var DeviceBoundSensorInfoPacket = class _DeviceBoundSensorInfoPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _DeviceBoundSensorInfoPacket.type, data.readUint8(0)); | ||
| this.sensorStatus = data.readUint8(1); | ||
| } | ||
| static get type() { | ||
| return 15; | ||
| } | ||
| toString() { | ||
| return `DeviceBoundSensorInfoPacket{sensorId: ${this.sensorId}, sensorStatus: ${SensorStatus[this.sensorStatus]}}`; | ||
| } | ||
| static encode(sensorId, sensorStatus) { | ||
| const buffer = Buffer.alloc(4 + 1 + 1); | ||
| buffer.writeInt32BE(_DeviceBoundSensorInfoPacket.type, 0); | ||
| buffer.writeUInt8(sensorId, 4); | ||
| buffer.writeUInt8(sensorStatus, 5); | ||
| return buffer; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundAccelPacket.ts | ||
| var ServerBoundAccelPacket = class _ServerBoundAccelPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundAccelPacket.type); | ||
| this.acceleration = [data.readFloatBE(0), data.readFloatBE(4), data.readFloatBE(8)]; | ||
| this.sensorId = data.length >= 12 ? data.readUInt8(12) : null; | ||
| } | ||
| static get type() { | ||
| return 4; | ||
| } | ||
| toString() { | ||
| return `ServerBoundAccelPacket{acceleration: ${this.acceleration}, sensorId: ${this.sensorId}}`; | ||
| } | ||
| static encode(number, sensorId, acceleration) { | ||
| const data = Buffer.alloc(4 + 8 + 4 + 4 + 4 + (sensorId !== null ? 1 : 0)); | ||
| data.writeInt32BE(_ServerBoundAccelPacket.type, 0); | ||
| data.writeBigInt64BE(number, 4); | ||
| data.writeFloatBE(acceleration[0], 12); | ||
| data.writeFloatBE(acceleration[1], 16); | ||
| data.writeFloatBE(acceleration[2], 20); | ||
| if (sensorId !== null) { | ||
| data.writeUInt8(sensorId, 24); | ||
| } | ||
| return data; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundBatteryLevelPacket.ts | ||
| var ServerBoundBatteryLevelPacket = class _ServerBoundBatteryLevelPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundBatteryLevelPacket.type); | ||
| this.voltage = 0; | ||
| const tmp = data.readFloatBE(0); | ||
| data = data.slice(4); | ||
| if (data.length >= 4) { | ||
| this.percentage = data.readFloatBE(0) * 100; | ||
| this.voltage = tmp; | ||
| } else { | ||
| this.percentage = tmp; | ||
| } | ||
| } | ||
| static get type() { | ||
| return 12; | ||
| } | ||
| toString() { | ||
| return `ServerBoundBatteryLevelPacket{voltage: ${this.voltage}, percentage: ${this.percentage}}`; | ||
| } | ||
| static encode(number, voltage, percentage) { | ||
| const data = Buffer.alloc(4 + 8 + 4 + 4); | ||
| data.writeInt32BE(_ServerBoundBatteryLevelPacket.type, 0); | ||
| data.writeBigInt64BE(number, 4); | ||
| data.writeFloatBE(voltage, 12); | ||
| data.writeFloatBE(percentage / 100, 16); | ||
| return data; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundBundlePacket.ts | ||
| var ServerBoundBundlePacket = class _ServerBoundBundlePacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundBundlePacket.type); | ||
| this.packets = []; | ||
| while (data.length > 1) { | ||
| const length = data.readUInt16BE(0); | ||
| data = data.slice(2); | ||
| const packet = parse(data.slice(0, length), false, true); | ||
| data = data.slice(length); | ||
| if (packet === null) | ||
| continue; | ||
| this.packets.push(packet); | ||
| } | ||
| } | ||
| static get type() { | ||
| return 100; | ||
| } | ||
| toString() { | ||
| return `ServerBoundBundlePacket{count: ${this.packets.length}, packets: ${this.packets.map((p) => p.toString()).join(", ")}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundCalibrationFinishedPacket.ts | ||
| var ServerBoundCalibrationFinishedPacket = class _ServerBoundCalibrationFinishedPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundCalibrationFinishedPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.dataType = data.readInt32BE(1); | ||
| } | ||
| static get type() { | ||
| return 7; | ||
| } | ||
| toString() { | ||
| return `ServerBoundCalibrationFinishedPacket{sensorId: ${this.sensorId}, dataType: ${this.dataType}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundErrorPacket.ts | ||
| var ServerBoundErrorPacket = class _ServerBoundErrorPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundErrorPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.reason = data.readUintBE(1, 1); | ||
| } | ||
| static get type() { | ||
| return 14; | ||
| } | ||
| toString() { | ||
| return `ServerBoundErrorPacket{sensorId: ${this.sensorId}, reason: ${this.reason}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundFeatureFlagsPacket.ts | ||
| var ServerBoundFeatureFlagsPacket = class _ServerBoundFeatureFlagsPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundFeatureFlagsPacket.type); | ||
| this.flags = FirmwareFeatureFlags.unpack(data); | ||
| } | ||
| static get type() { | ||
| return 22; | ||
| } | ||
| toString() { | ||
| return `ServerBoundFeatureFlagsPacket{flags: ${this.flags.getAllEnabled().join(",")}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundGyroPacket.ts | ||
| var ServerBoundGyroPacket = class _ServerBoundGyroPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundGyroPacket.type); | ||
| this.rotation = [data.readFloatBE(0), data.readFloatBE(4), data.readFloatBE(8)]; | ||
| } | ||
| static get type() { | ||
| return 2; | ||
| } | ||
| toString() { | ||
| return `ServerBoundGyroPacket{rotation: ${this.rotation}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundHandshakePacket.ts | ||
| var import_common = require("@slimevr/common"); | ||
| var ServerBoundHandshakePacket = class _ServerBoundHandshakePacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundHandshakePacket.type); | ||
| this.boardType = 0 /* UNKNOWN */; | ||
| this.imuType = 0 /* UNKNOWN */; | ||
| this.mcuType = 0 /* UNKNOWN */; | ||
| this.firmwareBuild = -1; | ||
| this.firmware = ""; | ||
| this.mac = ""; | ||
| if (data.length === 0) { | ||
| return; | ||
| } | ||
| if (data.length >= 4) { | ||
| const rawBoardType = data.readInt32BE(); | ||
| if (rawBoardType > 0 && rawBoardType < 11) { | ||
| this.boardType = rawBoardType; | ||
| } | ||
| data = data.slice(4); | ||
| } | ||
| if (data.length >= 4) { | ||
| const rawIMUType = data.readInt32BE(); | ||
| if (rawIMUType > 0 && rawIMUType < 10) { | ||
| this.imuType = rawIMUType; | ||
| } | ||
| data = data.slice(4); | ||
| } | ||
| if (data.length >= 4) { | ||
| const rawMCUType = data.readInt32BE(); | ||
| if (rawMCUType > 0 && rawMCUType < 3) { | ||
| this.mcuType = rawMCUType; | ||
| } | ||
| data = data.slice(4); | ||
| } | ||
| if (data.length >= 12) { | ||
| data = data.slice(12); | ||
| } | ||
| if (data.length >= 4) { | ||
| this.firmwareBuild = data.readInt32BE(); | ||
| data = data.slice(4); | ||
| } | ||
| let length = 0; | ||
| if (data.length >= 4) { | ||
| length = data.readUintBE(0, 1); | ||
| data = data.slice(1); | ||
| } | ||
| this.firmware = this.readAscii(data, length); | ||
| data = data.slice(length); | ||
| if (data.length >= 6) { | ||
| this.mac = [ | ||
| data.readUint8(0), | ||
| data.readUint8(1), | ||
| data.readUint8(2), | ||
| data.readUint8(3), | ||
| data.readUint8(4), | ||
| data.readUint8(5) | ||
| ].map(import_common.formatMACAddressDigit).join(":"); | ||
| } | ||
| } | ||
| static get type() { | ||
| return 3; | ||
| } | ||
| readAscii(data, length) { | ||
| let buf = ""; | ||
| while (length-- > 0) { | ||
| const v = data.readUIntBE(0, 1) & 255; | ||
| if (v === 0) { | ||
| break; | ||
| } | ||
| buf += String.fromCharCode(v); | ||
| data = data.slice(1); | ||
| } | ||
| return buf; | ||
| } | ||
| toString() { | ||
| return `ServerBoundHandshakePacket{boardType: ${BoardType[this.boardType]}, imuType: ${SensorType[this.imuType]}, mcuType: ${MCUType[this.mcuType]}, firmwareBuild: ${this.firmwareBuild}, firmware: ${this.firmware}, mac: ${this.mac}}`; | ||
| } | ||
| static encode(number, boardType, imuType, mcuType, firmwareBuild, firmware, mac) { | ||
| const buf = Buffer.alloc(4 + 8 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 1 + firmware.length + 6); | ||
| buf.writeInt32BE(_ServerBoundHandshakePacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeInt32BE(boardType, 12); | ||
| buf.writeInt32BE(imuType, 16); | ||
| buf.writeInt32BE(mcuType, 20); | ||
| buf.writeInt32BE(0, 24); | ||
| buf.writeInt32BE(0, 28); | ||
| buf.writeInt32BE(0, 32); | ||
| buf.writeInt32BE(firmwareBuild, 36); | ||
| buf.writeUInt8(firmware.length, 40); | ||
| buf.write(firmware, 41); | ||
| buf.writeUInt8(mac[0], 41 + firmware.length); | ||
| buf.writeUInt8(mac[1], 41 + firmware.length + 1); | ||
| buf.writeUInt8(mac[2], 41 + firmware.length + 2); | ||
| buf.writeUInt8(mac[3], 41 + firmware.length + 3); | ||
| buf.writeUInt8(mac[4], 41 + firmware.length + 4); | ||
| buf.writeUInt8(mac[5], 41 + firmware.length + 5); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundHeartbeatPacket.ts | ||
| var ServerBoundHeartbeatPacket = class _ServerBoundHeartbeatPacket extends Packet { | ||
| constructor(number) { | ||
| super(number, _ServerBoundHeartbeatPacket.type); | ||
| } | ||
| static get type() { | ||
| return 0; | ||
| } | ||
| toString() { | ||
| return `ServerBoundHeartbeatPacket{}`; | ||
| } | ||
| static encode(number) { | ||
| const buf = Buffer.alloc(4 + 8); | ||
| buf.writeInt32BE(_ServerBoundHeartbeatPacket.type, 0); | ||
| buf.writeBigUInt64BE(number, 4); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundMagnetometerAccuracy.ts | ||
| var ServerBoundMagnetometerAccuracyPacket = class _ServerBoundMagnetometerAccuracyPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundMagnetometerAccuracyPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.accuracy = data.readFloatBE(1); | ||
| } | ||
| static get type() { | ||
| return 18; | ||
| } | ||
| toString() { | ||
| return `ServerBoundMagnetometerAccuracyPacket{sensorId: ${this.sensorId}, accuracy: ${this.accuracy}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundPongPacket.ts | ||
| var ServerBoundPongPacket = class _ServerBoundPongPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundPongPacket.type); | ||
| this.id = data.readInt32BE(0); | ||
| } | ||
| static get type() { | ||
| return 10; | ||
| } | ||
| toString() { | ||
| return `ServerBoundPongPacket{id: ${this.id}}`; | ||
| } | ||
| static encode(number, id) { | ||
| const buf = Buffer.alloc(4 + 8 + 4); | ||
| buf.writeInt32BE(_ServerBoundPongPacket.type, 0); | ||
| buf.writeBigUInt64BE(number, 4); | ||
| buf.writeInt32BE(id, 12); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundRawCalibrationDataPacket.ts | ||
| var ServerBoundRawCalibrationDataPacket = class _ServerBoundRawCalibrationDataPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRawCalibrationDataPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.dataType = data.readInt32BE(1); | ||
| this.data = [data.readFloatBE(5), data.readFloatBE(9), data.readFloatBE(13)]; | ||
| } | ||
| static get type() { | ||
| return 6; | ||
| } | ||
| toString() { | ||
| return `ServerBoundRawCalibrationDataPacket{sensorId: ${this.sensorId}, dataType: ${RawCalibrationDataType[this.dataType]}, data: ${this.data}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundRotationDataPacket.ts | ||
| var RotationDataType = /* @__PURE__ */ ((RotationDataType2) => { | ||
| RotationDataType2[RotationDataType2["NORMAL"] = 1] = "NORMAL"; | ||
| RotationDataType2[RotationDataType2["CORRECTION"] = 2] = "CORRECTION"; | ||
| return RotationDataType2; | ||
| })(RotationDataType || {}); | ||
| var ServerBoundRotationDataPacket = class _ServerBoundRotationDataPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRotationDataPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.dataType = data.readUintBE(1, 1) & 255; | ||
| this.rotation = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10), data.readFloatBE(14)]; | ||
| this.accuracyInfo = data.readUintBE(18, 1); | ||
| } | ||
| static get type() { | ||
| return 17; | ||
| } | ||
| static fromRotationPacket(packet) { | ||
| const buf = Buffer.alloc(18); | ||
| buf.writeUintBE(0, 0, 1); | ||
| buf.writeUintBE(1 /* NORMAL */, 1, 1); | ||
| buf.writeFloatBE(packet.rotation[0], 2); | ||
| buf.writeFloatBE(packet.rotation[1], 6); | ||
| buf.writeFloatBE(packet.rotation[2], 10); | ||
| buf.writeFloatBE(packet.rotation[3], 14); | ||
| return new _ServerBoundRotationDataPacket(packet.number, buf); | ||
| } | ||
| toString() { | ||
| return `ServerBoundRotationDataPacket{sensorId: ${this.sensorId}, dataType: ${RotationDataType[this.dataType]}, rotation: ${this.rotation}}, accuracyInfo: ${this.accuracyInfo}}`; | ||
| } | ||
| static encode(number, sensorId, dataType, rotation, accuracyInfo) { | ||
| const buf = Buffer.alloc(4 + 8 + 1 + 1 + 4 + 4 + 4 + 4 + 1); | ||
| buf.writeInt32BE(_ServerBoundRotationDataPacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeUintBE(sensorId, 12, 1); | ||
| buf.writeUintBE(dataType, 13, 1); | ||
| buf.writeFloatBE(rotation[0], 14); | ||
| buf.writeFloatBE(rotation[1], 18); | ||
| buf.writeFloatBE(rotation[2], 22); | ||
| buf.writeFloatBE(rotation[3], 26); | ||
| buf.writeUintBE(accuracyInfo, 30, 1); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundRotationPacket.ts | ||
| var ServerBoundRotationPacket = class _ServerBoundRotationPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRotationPacket.type); | ||
| this.rotation = [data.readFloatBE(0), data.readFloatBE(4), data.readFloatBE(8), data.readFloatBE(12)]; | ||
| } | ||
| static get type() { | ||
| return 1; | ||
| } | ||
| toString() { | ||
| return `ServerBoundRotationPacket{rotation: ${this.rotation}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundSensorInfoPacket.ts | ||
| var ServerBoundSensorInfoPacket = class _ServerBoundSensorInfoPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundSensorInfoPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.sensorStatus = data.readUintBE(1, 1) & 255; | ||
| this.sensorType = 0 /* UNKNOWN */; | ||
| if (data.length >= 3) { | ||
| const rawSensorType = data.readUintBE(2, 1); | ||
| if (rawSensorType > 0 && rawSensorType < 10) { | ||
| this.sensorType = rawSensorType; | ||
| } | ||
| } | ||
| } | ||
| static get type() { | ||
| return 15; | ||
| } | ||
| static encode(number, sensorId, sensorStatus, sensorType) { | ||
| const buf = Buffer.alloc(4 + 8 + 1 + 1 + 1); | ||
| buf.writeInt32BE(_ServerBoundSensorInfoPacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeUInt8(sensorId, 12); | ||
| buf.writeUInt8(sensorStatus, 13); | ||
| buf.writeUInt8(sensorType, 14); | ||
| return buf; | ||
| } | ||
| toString() { | ||
| return `ServerBoundSensorInfoPacket{sensorId: ${this.sensorId}, sensorStatus: ${SensorStatus[this.sensorStatus]}, sensorType: ${SensorType[this.sensorType]}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundSignalStrengthPacket.ts | ||
| var ServerBoundSignalStrengthPacket = class _ServerBoundSignalStrengthPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundSignalStrengthPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.signalStrength = data.readIntBE(1, 1); | ||
| } | ||
| static get type() { | ||
| return 19; | ||
| } | ||
| toString() { | ||
| return `ServerBoundSignalStrengthPacket{sensorId: ${this.sensorId}, signalStrength: ${this.signalStrength}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundTapPacket.ts | ||
| var ServerBoundTapPacket = class _ServerBoundTapPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundTapPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.value = data.readUintBE(1, 1); | ||
| } | ||
| static get type() { | ||
| return 13; | ||
| } | ||
| toString() { | ||
| return `ServerBoundTapPacket{sensorId: ${this.sensorId}, value: ${this.value}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundTemperaturePacket.ts | ||
| var ServerBoundTemperaturePacket = class _ServerBoundTemperaturePacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundTemperaturePacket.type, data.readUintBE(0, 1) & 255); | ||
| this.temperature = data.readFloatBE(1); | ||
| } | ||
| static get type() { | ||
| return 20; | ||
| } | ||
| toString() { | ||
| return `ServerBoundTemperaturePacket{sensorId: ${this.sensorId}, temperature: ${this.temperature}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/constants.ts | ||
| var PacketType = /* @__PURE__ */ ((PacketType2) => { | ||
| PacketType2[PacketType2["RAW"] = 1] = "RAW"; | ||
| PacketType2[PacketType2["FUSED"] = 2] = "FUSED"; | ||
| PacketType2[PacketType2["CORRECTION"] = 3] = "CORRECTION"; | ||
| return PacketType2; | ||
| })(PacketType || {}); | ||
| // src/packets/inspection/ServerBoundCorrectionDataPacket.ts | ||
| var ServerBoundCorrectionDataPacket = class _ServerBoundCorrectionDataPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundCorrectionDataPacket.type); | ||
| this.sensorId = data.readUInt8(0); | ||
| if (data.readUintBE(1, 1) !== 2 /* FLOAT */) { | ||
| throw new Error("ServerBoundCorrectionDataPacket: data type must be float"); | ||
| } | ||
| this.quaternion = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10), data.readFloatBE(14)]; | ||
| } | ||
| static get type() { | ||
| return 26883; | ||
| } | ||
| toString() { | ||
| return `ServerBoundCorrectionDataPacket{sensorId: ${this.sensorId}, quaternion: ${this.quaternion}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/ServerBoundFusedIMUDataPacket.ts | ||
| var ServerBoundFusedIMUDataPacket = class _ServerBoundFusedIMUDataPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundFusedIMUDataPacket.type); | ||
| this.sensorId = data.readUInt8(0); | ||
| if (data.readUintBE(1, 1) !== 2 /* FLOAT */) { | ||
| throw new Error("ServerBoundFusedIMUDataPacket: data type must be float"); | ||
| } | ||
| this.quaternion = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10), data.readFloatBE(14)]; | ||
| } | ||
| static get type() { | ||
| return 26882; | ||
| } | ||
| toString() { | ||
| return `ServerBoundFusedIMUDataPacket{sensorId: ${this.sensorId}, quaternion: ${this.quaternion}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/ServerBoundRawIMUDataPacket.ts | ||
| var ServerBoundRawIMUDataPacket = class _ServerBoundRawIMUDataPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRawIMUDataPacket.type); | ||
| this.sensorId = data.readUInt8(0); | ||
| const dataType = data.readUintBE(1, 1); | ||
| if (dataType === 1 /* INT */) { | ||
| this.rotation = [data.readInt32BE(2), data.readInt32BE(6), data.readInt32BE(10)]; | ||
| this.acceleration = [data.readInt32BE(15), data.readInt32BE(19), data.readInt32BE(23)]; | ||
| this.magnetometer = [data.readInt32BE(28), data.readInt32BE(32), data.readInt32BE(36)]; | ||
| } else if (dataType === 2 /* FLOAT */) { | ||
| this.rotation = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10)]; | ||
| this.acceleration = [data.readFloatBE(15), data.readFloatBE(19), data.readFloatBE(23)]; | ||
| this.magnetometer = [data.readFloatBE(28), data.readFloatBE(32), data.readFloatBE(36)]; | ||
| } else { | ||
| throw new Error("ServerBoundRawIMUDataPacket: data type must be float or int"); | ||
| } | ||
| this.rotationAccuracy = data.readUintBE(14, 1); | ||
| this.accelerationAccuracy = data.readUintBE(27, 1); | ||
| this.magnetometerAccuracy = data.readUintBE(40, 1); | ||
| } | ||
| static get type() { | ||
| return 26881; | ||
| } | ||
| toString() { | ||
| return `ServerBoundRawIMUDataPacket{sensorId: ${this.sensorId}, rotation: ${this.rotation}, rotationAccuracy: ${this.rotationAccuracy}, acceleration: ${this.acceleration}, accelerationAccuracy: ${this.accelerationAccuracy}, magnetometer: ${this.magnetometer}, magnetometerAccuracy: ${this.magnetometerAccuracy}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/PacketParser.ts | ||
| var InspectionPacketParser = class { | ||
| static get type() { | ||
| return 105; | ||
| } | ||
| }; | ||
| InspectionPacketParser.parseRawDataPacket = (number, data) => { | ||
| const packetType = data.readUInt8(0); | ||
| data = data.slice(1); | ||
| switch (packetType) { | ||
| case 1 /* RAW */: | ||
| return new ServerBoundRawIMUDataPacket(number, data); | ||
| case 2 /* FUSED */: | ||
| return new ServerBoundFusedIMUDataPacket(number, data); | ||
| case 3 /* CORRECTION */: | ||
| return new ServerBoundCorrectionDataPacket(number, data); | ||
| default: | ||
| console.log(`Unknown packet type: ${PacketType}`); | ||
| return null; | ||
| } | ||
| }; | ||
| // src/packets/PacketParser.ts | ||
| var parse = (data, isDeviceBound, isInBundle = false) => { | ||
| if (isDeviceBound) { | ||
| if (data.readUint8(0) === DeviceBoundHandshakePacket.type) { | ||
| return new DeviceBoundHandshakePacket(0n); | ||
| } | ||
| const type = data.readUInt32BE(); | ||
| if (type === DeviceBoundSensorInfoPacket.type) { | ||
| return new DeviceBoundSensorInfoPacket(0n, data); | ||
| } | ||
| const number = data.readBigInt64BE(4); | ||
| data = data.slice(12); | ||
| switch (type) { | ||
| case DeviceBoundHeartbeatPacket.type: | ||
| return new DeviceBoundHeartbeatPacket(number); | ||
| case DeviceBoundPingPacket.type: | ||
| return new DeviceBoundPingPacket(number, data); | ||
| case DeviceBoundFeatureFlagsPacket.type: | ||
| return new DeviceBoundFeatureFlagsPacket(number, data); | ||
| default: | ||
| console.log(data.toString("hex")); | ||
| console.log(`Unknown packet type: ${type}`); | ||
| return null; | ||
| } | ||
| } else { | ||
| const type = data.readUInt32BE(); | ||
| const number = isInBundle ? BigInt(0) : data.readBigInt64BE(4); | ||
| data = data.slice(isInBundle ? 4 : 12); | ||
| switch (type) { | ||
| case ServerBoundHeartbeatPacket.type: | ||
| return new ServerBoundHeartbeatPacket(number); | ||
| case ServerBoundRotationPacket.type: | ||
| return new ServerBoundRotationPacket(number, data); | ||
| case ServerBoundGyroPacket.type: | ||
| return new ServerBoundGyroPacket(number, data); | ||
| case ServerBoundHandshakePacket.type: | ||
| return new ServerBoundHandshakePacket(number, data); | ||
| case ServerBoundAccelPacket.type: | ||
| return new ServerBoundAccelPacket(number, data); | ||
| case ServerBoundRawCalibrationDataPacket.type: | ||
| return new ServerBoundRawCalibrationDataPacket(number, data); | ||
| case ServerBoundCalibrationFinishedPacket.type: | ||
| return new ServerBoundCalibrationFinishedPacket(number, data); | ||
| case ServerBoundPongPacket.type: | ||
| return new ServerBoundPongPacket(number, data); | ||
| case ServerBoundBatteryLevelPacket.type: | ||
| return new ServerBoundBatteryLevelPacket(number, data); | ||
| case ServerBoundTapPacket.type: | ||
| return new ServerBoundTapPacket(number, data); | ||
| case ServerBoundErrorPacket.type: | ||
| return new ServerBoundErrorPacket(number, data); | ||
| case ServerBoundSensorInfoPacket.type: | ||
| return new ServerBoundSensorInfoPacket(number, data); | ||
| case ServerBoundRotationDataPacket.type: | ||
| return new ServerBoundRotationDataPacket(number, data); | ||
| case ServerBoundFeatureFlagsPacket.type: | ||
| return new ServerBoundFeatureFlagsPacket(number, data); | ||
| case ServerBoundBundlePacket.type: | ||
| return new ServerBoundBundlePacket(number, data); | ||
| case ServerBoundMagnetometerAccuracyPacket.type: | ||
| return new ServerBoundMagnetometerAccuracyPacket(number, data); | ||
| case ServerBoundSignalStrengthPacket.type: | ||
| return new ServerBoundSignalStrengthPacket(number, data); | ||
| case ServerBoundTemperaturePacket.type: | ||
| return new ServerBoundTemperaturePacket(number, data); | ||
| case InspectionPacketParser.type: | ||
| return InspectionPacketParser.parseRawDataPacket(number, data); | ||
| default: | ||
| console.log(`Unknown packet type: ${type}`); | ||
| return null; | ||
| } | ||
| } | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| AVAILABLE_FIRMWARE_FEATURE_FLAGS, | ||
| AVAILABLE_SERVER_FEATURE_FLAGS, | ||
| BoardType, | ||
| DeviceBoundFeatureFlagsPacket, | ||
| DeviceBoundHandshakePacket, | ||
| DeviceBoundHeartbeatPacket, | ||
| DeviceBoundPingPacket, | ||
| DeviceBoundSensorInfoPacket, | ||
| FirmwareFeatureFlags, | ||
| InspectionPacketParser, | ||
| MCUType, | ||
| Packet, | ||
| PacketWithSensorId, | ||
| Protocol, | ||
| RawCalibrationDataType, | ||
| RotationDataType, | ||
| SensorStatus, | ||
| SensorType, | ||
| ServerBoundAccelPacket, | ||
| ServerBoundBatteryLevelPacket, | ||
| ServerBoundBundlePacket, | ||
| ServerBoundCalibrationFinishedPacket, | ||
| ServerBoundCorrectionDataPacket, | ||
| ServerBoundErrorPacket, | ||
| ServerBoundFeatureFlagsPacket, | ||
| ServerBoundFusedIMUDataPacket, | ||
| ServerBoundGyroPacket, | ||
| ServerBoundHandshakePacket, | ||
| ServerBoundHeartbeatPacket, | ||
| ServerBoundMagnetometerAccuracyPacket, | ||
| ServerBoundPongPacket, | ||
| ServerBoundRawCalibrationDataPacket, | ||
| ServerBoundRawIMUDataPacket, | ||
| ServerBoundRotationDataPacket, | ||
| ServerBoundRotationPacket, | ||
| ServerBoundSensorInfoPacket, | ||
| ServerBoundSignalStrengthPacket, | ||
| ServerBoundTapPacket, | ||
| ServerBoundTemperaturePacket, | ||
| ServerFeatureFlags, | ||
| makeFeatureFlagContainer, | ||
| parse | ||
| }); |
-897
| var __accessCheck = (obj, member, msg) => { | ||
| if (!member.has(obj)) | ||
| throw TypeError("Cannot " + msg); | ||
| }; | ||
| var __privateGet = (obj, member, getter) => { | ||
| __accessCheck(obj, member, "read from private field"); | ||
| return getter ? getter.call(obj) : member.get(obj); | ||
| }; | ||
| var __privateAdd = (obj, member, value) => { | ||
| if (member.has(obj)) | ||
| throw TypeError("Cannot add the same private member more than once"); | ||
| member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| }; | ||
| var __privateSet = (obj, member, value, setter) => { | ||
| __accessCheck(obj, member, "write to private field"); | ||
| setter ? setter.call(obj, value) : member.set(obj, value); | ||
| return value; | ||
| }; | ||
| // src/constants.ts | ||
| var Protocol = /* @__PURE__ */ ((Protocol2) => { | ||
| Protocol2[Protocol2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| Protocol2[Protocol2["OWO_LEGACY"] = 1] = "OWO_LEGACY"; | ||
| Protocol2[Protocol2["SLIMEVR_RAW"] = 2] = "SLIMEVR_RAW"; | ||
| return Protocol2; | ||
| })(Protocol || {}); | ||
| var SensorStatus = /* @__PURE__ */ ((SensorStatus2) => { | ||
| SensorStatus2[SensorStatus2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| SensorStatus2[SensorStatus2["OK"] = 1] = "OK"; | ||
| SensorStatus2[SensorStatus2["ERROR"] = 2] = "ERROR"; | ||
| return SensorStatus2; | ||
| })(SensorStatus || {}); | ||
| var RawCalibrationDataType = /* @__PURE__ */ ((RawCalibrationDataType2) => { | ||
| RawCalibrationDataType2[RawCalibrationDataType2["INTERNAL_GYRO"] = 1] = "INTERNAL_GYRO"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["INTERNAL_ACCEL"] = 2] = "INTERNAL_ACCEL"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["INTERNAL_MAG"] = 3] = "INTERNAL_MAG"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_ALL"] = 4] = "EXTERNAL_ALL"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_GYRO"] = 5] = "EXTERNAL_GYRO"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_ACCEL"] = 6] = "EXTERNAL_ACCEL"; | ||
| RawCalibrationDataType2[RawCalibrationDataType2["EXTERNAL_MAG"] = 7] = "EXTERNAL_MAG"; | ||
| return RawCalibrationDataType2; | ||
| })(RawCalibrationDataType || {}); | ||
| var SensorType = /* @__PURE__ */ ((SensorType2) => { | ||
| SensorType2[SensorType2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| SensorType2[SensorType2["MPU9250"] = 1] = "MPU9250"; | ||
| SensorType2[SensorType2["MPU6500"] = 2] = "MPU6500"; | ||
| SensorType2[SensorType2["BNO080"] = 3] = "BNO080"; | ||
| SensorType2[SensorType2["BNO085"] = 4] = "BNO085"; | ||
| SensorType2[SensorType2["BNO055"] = 5] = "BNO055"; | ||
| SensorType2[SensorType2["MPU6050"] = 6] = "MPU6050"; | ||
| SensorType2[SensorType2["BNO086"] = 7] = "BNO086"; | ||
| SensorType2[SensorType2["BMI160"] = 8] = "BMI160"; | ||
| SensorType2[SensorType2["ICM20948"] = 9] = "ICM20948"; | ||
| return SensorType2; | ||
| })(SensorType || {}); | ||
| var MCUType = /* @__PURE__ */ ((MCUType2) => { | ||
| MCUType2[MCUType2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| MCUType2[MCUType2["ESP8266"] = 1] = "ESP8266"; | ||
| MCUType2[MCUType2["ESP32"] = 2] = "ESP32"; | ||
| return MCUType2; | ||
| })(MCUType || {}); | ||
| var BoardType = /* @__PURE__ */ ((BoardType2) => { | ||
| BoardType2[BoardType2["UNKNOWN"] = 0] = "UNKNOWN"; | ||
| BoardType2[BoardType2["SLIMEVR_LEGACY"] = 1] = "SLIMEVR_LEGACY"; | ||
| BoardType2[BoardType2["SLIMEVR_DEV"] = 2] = "SLIMEVR_DEV"; | ||
| BoardType2[BoardType2["NODEMCU"] = 3] = "NODEMCU"; | ||
| BoardType2[BoardType2["CUSTOM"] = 4] = "CUSTOM"; | ||
| BoardType2[BoardType2["WROOM32"] = 5] = "WROOM32"; | ||
| BoardType2[BoardType2["WEMOSD1MINI"] = 6] = "WEMOSD1MINI"; | ||
| BoardType2[BoardType2["TTGO_TBASE"] = 7] = "TTGO_TBASE"; | ||
| BoardType2[BoardType2["ESP01"] = 8] = "ESP01"; | ||
| BoardType2[BoardType2["SLIMEVR"] = 9] = "SLIMEVR"; | ||
| BoardType2[BoardType2["LOLIN_C3_MINI"] = 10] = "LOLIN_C3_MINI"; | ||
| return BoardType2; | ||
| })(BoardType || {}); | ||
| // src/FeatureFlags.ts | ||
| var makeFeatureFlagContainer = (available) => { | ||
| var _flags, _a; | ||
| const allFlags = Object.entries(available); | ||
| return _a = class { | ||
| constructor(flags) { | ||
| __privateAdd(this, _flags, void 0); | ||
| __privateSet(this, _flags, flags); | ||
| } | ||
| static unpack(packed) { | ||
| const flags = /* @__PURE__ */ new Map(); | ||
| for (const [key, position] of allFlags) { | ||
| const posInPacked = Math.floor(position / 8); | ||
| const posInByte = position % 8; | ||
| const flag = packed[posInPacked] & 1 << posInByte; | ||
| const enabled = flag != 0; | ||
| flags.set(key, enabled); | ||
| } | ||
| return new this(flags); | ||
| } | ||
| get isAvailable() { | ||
| return !!__privateGet(this, _flags); | ||
| } | ||
| pack() { | ||
| const packed = Buffer.alloc(Object.keys(available).length / 8 + 1); | ||
| for (const position of Array.from(__privateGet(this, _flags)?.entries() ?? []).filter(([_, v]) => v).map(([k]) => available[k])) { | ||
| const posInPacked = Math.floor(position / 8); | ||
| const posInByte = position % 8; | ||
| packed[posInPacked] |= 1 << posInByte; | ||
| } | ||
| return packed; | ||
| } | ||
| has(flag) { | ||
| return __privateGet(this, _flags)?.get(flag) ?? false; | ||
| } | ||
| getAllEnabled() { | ||
| return Array.from(__privateGet(this, _flags)?.entries() ?? []).filter(([_, v]) => v).map(([key]) => key); | ||
| } | ||
| }, _flags = new WeakMap(), _a; | ||
| }; | ||
| var AVAILABLE_SERVER_FEATURE_FLAGS = { | ||
| PROTOCOL_BUNDLE_SUPPORT: 0 | ||
| }; | ||
| var ServerFeatureFlags = makeFeatureFlagContainer(AVAILABLE_SERVER_FEATURE_FLAGS); | ||
| var AVAILABLE_FIRMWARE_FEATURE_FLAGS = { | ||
| // The tracker sends all information that firmware 0.3.3 and below sends | ||
| LEGACY_SLIMEVR_TRACKER: 0, | ||
| // The tracker sends rotation data | ||
| ROTATION_DATA: 1, | ||
| // The tracker sends position data | ||
| POSITION_DATA: 2 | ||
| }; | ||
| var FirmwareFeatureFlags = makeFeatureFlagContainer(AVAILABLE_FIRMWARE_FEATURE_FLAGS); | ||
| // src/packets/Packet.ts | ||
| var Packet = class { | ||
| constructor(number, type) { | ||
| this.number = number; | ||
| this.type = type; | ||
| } | ||
| }; | ||
| // Not implemented | ||
| Packet.SERIAL = 11; | ||
| Packet.ROTATION_2 = 16; | ||
| Packet.PROTOCOL_CHANGE = 200; | ||
| var PacketWithSensorId = class extends Packet { | ||
| constructor(number, type, sensorId) { | ||
| super(number, type); | ||
| this.sensorId = sensorId; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundFeatureFlagsPacket.ts | ||
| var DeviceBoundFeatureFlagsPacket = class _DeviceBoundFeatureFlagsPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _DeviceBoundFeatureFlagsPacket.type); | ||
| this.flags = ServerFeatureFlags.unpack(data); | ||
| } | ||
| static get type() { | ||
| return 22; | ||
| } | ||
| toString() { | ||
| return `DeviceBoundFeatureFlagsPacket{flags: ${this.flags.getAllEnabled().join(",")}}`; | ||
| } | ||
| static encode(number, flags) { | ||
| const packed = flags.pack(); | ||
| const buf = Buffer.alloc(4 + 8); | ||
| buf.writeInt32BE(_DeviceBoundFeatureFlagsPacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| return Buffer.concat([buf, packed]); | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundHandshakePacket.ts | ||
| var DeviceBoundHandshakePacket = class _DeviceBoundHandshakePacket extends Packet { | ||
| constructor(number) { | ||
| super(number, _DeviceBoundHandshakePacket.type); | ||
| } | ||
| static get type() { | ||
| return 3; | ||
| } | ||
| toString() { | ||
| return "DeviceBoundHandshakePacket{}"; | ||
| } | ||
| static encode() { | ||
| const buf = Buffer.alloc(14); | ||
| buf.writeUint8(this.type); | ||
| buf.write("Hey OVR =D 5", 1, "ascii"); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundHeartbeatPacket.ts | ||
| var DeviceBoundHeartbeatPacket = class _DeviceBoundHeartbeatPacket extends Packet { | ||
| constructor(number) { | ||
| super(number, _DeviceBoundHeartbeatPacket.type); | ||
| } | ||
| static get type() { | ||
| return 1; | ||
| } | ||
| toString() { | ||
| return "DeviceBoundHeartbeatPacket{}"; | ||
| } | ||
| static encode(num) { | ||
| const buf = Buffer.alloc(4 + 8); | ||
| buf.writeInt32BE(this.type); | ||
| buf.writeBigInt64BE(num, 4); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundPingPacket.ts | ||
| var DeviceBoundPingPacket = class _DeviceBoundPingPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _DeviceBoundPingPacket.type); | ||
| this.id = data.readInt32BE(0); | ||
| } | ||
| static get type() { | ||
| return 10; | ||
| } | ||
| toString() { | ||
| return `DeviceBoundPingPacket{id: ${this.id}}`; | ||
| } | ||
| static encode(number, id) { | ||
| const buf = Buffer.alloc(4 + 8 + 4); | ||
| buf.writeInt32BE(this.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeInt32BE(id, 12); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/DeviceBoundSensorInfoPacket.ts | ||
| var DeviceBoundSensorInfoPacket = class _DeviceBoundSensorInfoPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _DeviceBoundSensorInfoPacket.type, data.readUint8(0)); | ||
| this.sensorStatus = data.readUint8(1); | ||
| } | ||
| static get type() { | ||
| return 15; | ||
| } | ||
| toString() { | ||
| return `DeviceBoundSensorInfoPacket{sensorId: ${this.sensorId}, sensorStatus: ${SensorStatus[this.sensorStatus]}}`; | ||
| } | ||
| static encode(sensorId, sensorStatus) { | ||
| const buffer = Buffer.alloc(4 + 1 + 1); | ||
| buffer.writeInt32BE(_DeviceBoundSensorInfoPacket.type, 0); | ||
| buffer.writeUInt8(sensorId, 4); | ||
| buffer.writeUInt8(sensorStatus, 5); | ||
| return buffer; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundAccelPacket.ts | ||
| var ServerBoundAccelPacket = class _ServerBoundAccelPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundAccelPacket.type); | ||
| this.acceleration = [data.readFloatBE(0), data.readFloatBE(4), data.readFloatBE(8)]; | ||
| this.sensorId = data.length >= 12 ? data.readUInt8(12) : null; | ||
| } | ||
| static get type() { | ||
| return 4; | ||
| } | ||
| toString() { | ||
| return `ServerBoundAccelPacket{acceleration: ${this.acceleration}, sensorId: ${this.sensorId}}`; | ||
| } | ||
| static encode(number, sensorId, acceleration) { | ||
| const data = Buffer.alloc(4 + 8 + 4 + 4 + 4 + (sensorId !== null ? 1 : 0)); | ||
| data.writeInt32BE(_ServerBoundAccelPacket.type, 0); | ||
| data.writeBigInt64BE(number, 4); | ||
| data.writeFloatBE(acceleration[0], 12); | ||
| data.writeFloatBE(acceleration[1], 16); | ||
| data.writeFloatBE(acceleration[2], 20); | ||
| if (sensorId !== null) { | ||
| data.writeUInt8(sensorId, 24); | ||
| } | ||
| return data; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundBatteryLevelPacket.ts | ||
| var ServerBoundBatteryLevelPacket = class _ServerBoundBatteryLevelPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundBatteryLevelPacket.type); | ||
| this.voltage = 0; | ||
| const tmp = data.readFloatBE(0); | ||
| data = data.slice(4); | ||
| if (data.length >= 4) { | ||
| this.percentage = data.readFloatBE(0) * 100; | ||
| this.voltage = tmp; | ||
| } else { | ||
| this.percentage = tmp; | ||
| } | ||
| } | ||
| static get type() { | ||
| return 12; | ||
| } | ||
| toString() { | ||
| return `ServerBoundBatteryLevelPacket{voltage: ${this.voltage}, percentage: ${this.percentage}}`; | ||
| } | ||
| static encode(number, voltage, percentage) { | ||
| const data = Buffer.alloc(4 + 8 + 4 + 4); | ||
| data.writeInt32BE(_ServerBoundBatteryLevelPacket.type, 0); | ||
| data.writeBigInt64BE(number, 4); | ||
| data.writeFloatBE(voltage, 12); | ||
| data.writeFloatBE(percentage / 100, 16); | ||
| return data; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundBundlePacket.ts | ||
| var ServerBoundBundlePacket = class _ServerBoundBundlePacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundBundlePacket.type); | ||
| this.packets = []; | ||
| while (data.length > 1) { | ||
| const length = data.readUInt16BE(0); | ||
| data = data.slice(2); | ||
| const packet = parse(data.slice(0, length), false, true); | ||
| data = data.slice(length); | ||
| if (packet === null) | ||
| continue; | ||
| this.packets.push(packet); | ||
| } | ||
| } | ||
| static get type() { | ||
| return 100; | ||
| } | ||
| toString() { | ||
| return `ServerBoundBundlePacket{count: ${this.packets.length}, packets: ${this.packets.map((p) => p.toString()).join(", ")}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundCalibrationFinishedPacket.ts | ||
| var ServerBoundCalibrationFinishedPacket = class _ServerBoundCalibrationFinishedPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundCalibrationFinishedPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.dataType = data.readInt32BE(1); | ||
| } | ||
| static get type() { | ||
| return 7; | ||
| } | ||
| toString() { | ||
| return `ServerBoundCalibrationFinishedPacket{sensorId: ${this.sensorId}, dataType: ${this.dataType}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundErrorPacket.ts | ||
| var ServerBoundErrorPacket = class _ServerBoundErrorPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundErrorPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.reason = data.readUintBE(1, 1); | ||
| } | ||
| static get type() { | ||
| return 14; | ||
| } | ||
| toString() { | ||
| return `ServerBoundErrorPacket{sensorId: ${this.sensorId}, reason: ${this.reason}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundFeatureFlagsPacket.ts | ||
| var ServerBoundFeatureFlagsPacket = class _ServerBoundFeatureFlagsPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundFeatureFlagsPacket.type); | ||
| this.flags = FirmwareFeatureFlags.unpack(data); | ||
| } | ||
| static get type() { | ||
| return 22; | ||
| } | ||
| toString() { | ||
| return `ServerBoundFeatureFlagsPacket{flags: ${this.flags.getAllEnabled().join(",")}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundGyroPacket.ts | ||
| var ServerBoundGyroPacket = class _ServerBoundGyroPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundGyroPacket.type); | ||
| this.rotation = [data.readFloatBE(0), data.readFloatBE(4), data.readFloatBE(8)]; | ||
| } | ||
| static get type() { | ||
| return 2; | ||
| } | ||
| toString() { | ||
| return `ServerBoundGyroPacket{rotation: ${this.rotation}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundHandshakePacket.ts | ||
| import { formatMACAddressDigit } from "@slimevr/common"; | ||
| var ServerBoundHandshakePacket = class _ServerBoundHandshakePacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundHandshakePacket.type); | ||
| this.boardType = 0 /* UNKNOWN */; | ||
| this.imuType = 0 /* UNKNOWN */; | ||
| this.mcuType = 0 /* UNKNOWN */; | ||
| this.firmwareBuild = -1; | ||
| this.firmware = ""; | ||
| this.mac = ""; | ||
| if (data.length === 0) { | ||
| return; | ||
| } | ||
| if (data.length >= 4) { | ||
| const rawBoardType = data.readInt32BE(); | ||
| if (rawBoardType > 0 && rawBoardType < 11) { | ||
| this.boardType = rawBoardType; | ||
| } | ||
| data = data.slice(4); | ||
| } | ||
| if (data.length >= 4) { | ||
| const rawIMUType = data.readInt32BE(); | ||
| if (rawIMUType > 0 && rawIMUType < 10) { | ||
| this.imuType = rawIMUType; | ||
| } | ||
| data = data.slice(4); | ||
| } | ||
| if (data.length >= 4) { | ||
| const rawMCUType = data.readInt32BE(); | ||
| if (rawMCUType > 0 && rawMCUType < 3) { | ||
| this.mcuType = rawMCUType; | ||
| } | ||
| data = data.slice(4); | ||
| } | ||
| if (data.length >= 12) { | ||
| data = data.slice(12); | ||
| } | ||
| if (data.length >= 4) { | ||
| this.firmwareBuild = data.readInt32BE(); | ||
| data = data.slice(4); | ||
| } | ||
| let length = 0; | ||
| if (data.length >= 4) { | ||
| length = data.readUintBE(0, 1); | ||
| data = data.slice(1); | ||
| } | ||
| this.firmware = this.readAscii(data, length); | ||
| data = data.slice(length); | ||
| if (data.length >= 6) { | ||
| this.mac = [ | ||
| data.readUint8(0), | ||
| data.readUint8(1), | ||
| data.readUint8(2), | ||
| data.readUint8(3), | ||
| data.readUint8(4), | ||
| data.readUint8(5) | ||
| ].map(formatMACAddressDigit).join(":"); | ||
| } | ||
| } | ||
| static get type() { | ||
| return 3; | ||
| } | ||
| readAscii(data, length) { | ||
| let buf = ""; | ||
| while (length-- > 0) { | ||
| const v = data.readUIntBE(0, 1) & 255; | ||
| if (v === 0) { | ||
| break; | ||
| } | ||
| buf += String.fromCharCode(v); | ||
| data = data.slice(1); | ||
| } | ||
| return buf; | ||
| } | ||
| toString() { | ||
| return `ServerBoundHandshakePacket{boardType: ${BoardType[this.boardType]}, imuType: ${SensorType[this.imuType]}, mcuType: ${MCUType[this.mcuType]}, firmwareBuild: ${this.firmwareBuild}, firmware: ${this.firmware}, mac: ${this.mac}}`; | ||
| } | ||
| static encode(number, boardType, imuType, mcuType, firmwareBuild, firmware, mac) { | ||
| const buf = Buffer.alloc(4 + 8 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 1 + firmware.length + 6); | ||
| buf.writeInt32BE(_ServerBoundHandshakePacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeInt32BE(boardType, 12); | ||
| buf.writeInt32BE(imuType, 16); | ||
| buf.writeInt32BE(mcuType, 20); | ||
| buf.writeInt32BE(0, 24); | ||
| buf.writeInt32BE(0, 28); | ||
| buf.writeInt32BE(0, 32); | ||
| buf.writeInt32BE(firmwareBuild, 36); | ||
| buf.writeUInt8(firmware.length, 40); | ||
| buf.write(firmware, 41); | ||
| buf.writeUInt8(mac[0], 41 + firmware.length); | ||
| buf.writeUInt8(mac[1], 41 + firmware.length + 1); | ||
| buf.writeUInt8(mac[2], 41 + firmware.length + 2); | ||
| buf.writeUInt8(mac[3], 41 + firmware.length + 3); | ||
| buf.writeUInt8(mac[4], 41 + firmware.length + 4); | ||
| buf.writeUInt8(mac[5], 41 + firmware.length + 5); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundHeartbeatPacket.ts | ||
| var ServerBoundHeartbeatPacket = class _ServerBoundHeartbeatPacket extends Packet { | ||
| constructor(number) { | ||
| super(number, _ServerBoundHeartbeatPacket.type); | ||
| } | ||
| static get type() { | ||
| return 0; | ||
| } | ||
| toString() { | ||
| return `ServerBoundHeartbeatPacket{}`; | ||
| } | ||
| static encode(number) { | ||
| const buf = Buffer.alloc(4 + 8); | ||
| buf.writeInt32BE(_ServerBoundHeartbeatPacket.type, 0); | ||
| buf.writeBigUInt64BE(number, 4); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundMagnetometerAccuracy.ts | ||
| var ServerBoundMagnetometerAccuracyPacket = class _ServerBoundMagnetometerAccuracyPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundMagnetometerAccuracyPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.accuracy = data.readFloatBE(1); | ||
| } | ||
| static get type() { | ||
| return 18; | ||
| } | ||
| toString() { | ||
| return `ServerBoundMagnetometerAccuracyPacket{sensorId: ${this.sensorId}, accuracy: ${this.accuracy}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundPongPacket.ts | ||
| var ServerBoundPongPacket = class _ServerBoundPongPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundPongPacket.type); | ||
| this.id = data.readInt32BE(0); | ||
| } | ||
| static get type() { | ||
| return 10; | ||
| } | ||
| toString() { | ||
| return `ServerBoundPongPacket{id: ${this.id}}`; | ||
| } | ||
| static encode(number, id) { | ||
| const buf = Buffer.alloc(4 + 8 + 4); | ||
| buf.writeInt32BE(_ServerBoundPongPacket.type, 0); | ||
| buf.writeBigUInt64BE(number, 4); | ||
| buf.writeInt32BE(id, 12); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundRawCalibrationDataPacket.ts | ||
| var ServerBoundRawCalibrationDataPacket = class _ServerBoundRawCalibrationDataPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRawCalibrationDataPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.dataType = data.readInt32BE(1); | ||
| this.data = [data.readFloatBE(5), data.readFloatBE(9), data.readFloatBE(13)]; | ||
| } | ||
| static get type() { | ||
| return 6; | ||
| } | ||
| toString() { | ||
| return `ServerBoundRawCalibrationDataPacket{sensorId: ${this.sensorId}, dataType: ${RawCalibrationDataType[this.dataType]}, data: ${this.data}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundRotationDataPacket.ts | ||
| var RotationDataType = /* @__PURE__ */ ((RotationDataType2) => { | ||
| RotationDataType2[RotationDataType2["NORMAL"] = 1] = "NORMAL"; | ||
| RotationDataType2[RotationDataType2["CORRECTION"] = 2] = "CORRECTION"; | ||
| return RotationDataType2; | ||
| })(RotationDataType || {}); | ||
| var ServerBoundRotationDataPacket = class _ServerBoundRotationDataPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRotationDataPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.dataType = data.readUintBE(1, 1) & 255; | ||
| this.rotation = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10), data.readFloatBE(14)]; | ||
| this.accuracyInfo = data.readUintBE(18, 1); | ||
| } | ||
| static get type() { | ||
| return 17; | ||
| } | ||
| static fromRotationPacket(packet) { | ||
| const buf = Buffer.alloc(18); | ||
| buf.writeUintBE(0, 0, 1); | ||
| buf.writeUintBE(1 /* NORMAL */, 1, 1); | ||
| buf.writeFloatBE(packet.rotation[0], 2); | ||
| buf.writeFloatBE(packet.rotation[1], 6); | ||
| buf.writeFloatBE(packet.rotation[2], 10); | ||
| buf.writeFloatBE(packet.rotation[3], 14); | ||
| return new _ServerBoundRotationDataPacket(packet.number, buf); | ||
| } | ||
| toString() { | ||
| return `ServerBoundRotationDataPacket{sensorId: ${this.sensorId}, dataType: ${RotationDataType[this.dataType]}, rotation: ${this.rotation}}, accuracyInfo: ${this.accuracyInfo}}`; | ||
| } | ||
| static encode(number, sensorId, dataType, rotation, accuracyInfo) { | ||
| const buf = Buffer.alloc(4 + 8 + 1 + 1 + 4 + 4 + 4 + 4 + 1); | ||
| buf.writeInt32BE(_ServerBoundRotationDataPacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeUintBE(sensorId, 12, 1); | ||
| buf.writeUintBE(dataType, 13, 1); | ||
| buf.writeFloatBE(rotation[0], 14); | ||
| buf.writeFloatBE(rotation[1], 18); | ||
| buf.writeFloatBE(rotation[2], 22); | ||
| buf.writeFloatBE(rotation[3], 26); | ||
| buf.writeUintBE(accuracyInfo, 30, 1); | ||
| return buf; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundRotationPacket.ts | ||
| var ServerBoundRotationPacket = class _ServerBoundRotationPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRotationPacket.type); | ||
| this.rotation = [data.readFloatBE(0), data.readFloatBE(4), data.readFloatBE(8), data.readFloatBE(12)]; | ||
| } | ||
| static get type() { | ||
| return 1; | ||
| } | ||
| toString() { | ||
| return `ServerBoundRotationPacket{rotation: ${this.rotation}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundSensorInfoPacket.ts | ||
| var ServerBoundSensorInfoPacket = class _ServerBoundSensorInfoPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundSensorInfoPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.sensorStatus = data.readUintBE(1, 1) & 255; | ||
| this.sensorType = 0 /* UNKNOWN */; | ||
| if (data.length >= 3) { | ||
| const rawSensorType = data.readUintBE(2, 1); | ||
| if (rawSensorType > 0 && rawSensorType < 10) { | ||
| this.sensorType = rawSensorType; | ||
| } | ||
| } | ||
| } | ||
| static get type() { | ||
| return 15; | ||
| } | ||
| static encode(number, sensorId, sensorStatus, sensorType) { | ||
| const buf = Buffer.alloc(4 + 8 + 1 + 1 + 1); | ||
| buf.writeInt32BE(_ServerBoundSensorInfoPacket.type, 0); | ||
| buf.writeBigInt64BE(number, 4); | ||
| buf.writeUInt8(sensorId, 12); | ||
| buf.writeUInt8(sensorStatus, 13); | ||
| buf.writeUInt8(sensorType, 14); | ||
| return buf; | ||
| } | ||
| toString() { | ||
| return `ServerBoundSensorInfoPacket{sensorId: ${this.sensorId}, sensorStatus: ${SensorStatus[this.sensorStatus]}, sensorType: ${SensorType[this.sensorType]}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundSignalStrengthPacket.ts | ||
| var ServerBoundSignalStrengthPacket = class _ServerBoundSignalStrengthPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundSignalStrengthPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.signalStrength = data.readIntBE(1, 1); | ||
| } | ||
| static get type() { | ||
| return 19; | ||
| } | ||
| toString() { | ||
| return `ServerBoundSignalStrengthPacket{sensorId: ${this.sensorId}, signalStrength: ${this.signalStrength}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundTapPacket.ts | ||
| var ServerBoundTapPacket = class _ServerBoundTapPacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundTapPacket.type, data.readUintBE(0, 1) & 255); | ||
| this.value = data.readUintBE(1, 1); | ||
| } | ||
| static get type() { | ||
| return 13; | ||
| } | ||
| toString() { | ||
| return `ServerBoundTapPacket{sensorId: ${this.sensorId}, value: ${this.value}}`; | ||
| } | ||
| }; | ||
| // src/packets/ServerBoundTemperaturePacket.ts | ||
| var ServerBoundTemperaturePacket = class _ServerBoundTemperaturePacket extends PacketWithSensorId { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundTemperaturePacket.type, data.readUintBE(0, 1) & 255); | ||
| this.temperature = data.readFloatBE(1); | ||
| } | ||
| static get type() { | ||
| return 20; | ||
| } | ||
| toString() { | ||
| return `ServerBoundTemperaturePacket{sensorId: ${this.sensorId}, temperature: ${this.temperature}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/constants.ts | ||
| var PacketType = /* @__PURE__ */ ((PacketType2) => { | ||
| PacketType2[PacketType2["RAW"] = 1] = "RAW"; | ||
| PacketType2[PacketType2["FUSED"] = 2] = "FUSED"; | ||
| PacketType2[PacketType2["CORRECTION"] = 3] = "CORRECTION"; | ||
| return PacketType2; | ||
| })(PacketType || {}); | ||
| // src/packets/inspection/ServerBoundCorrectionDataPacket.ts | ||
| var ServerBoundCorrectionDataPacket = class _ServerBoundCorrectionDataPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundCorrectionDataPacket.type); | ||
| this.sensorId = data.readUInt8(0); | ||
| if (data.readUintBE(1, 1) !== 2 /* FLOAT */) { | ||
| throw new Error("ServerBoundCorrectionDataPacket: data type must be float"); | ||
| } | ||
| this.quaternion = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10), data.readFloatBE(14)]; | ||
| } | ||
| static get type() { | ||
| return 26883; | ||
| } | ||
| toString() { | ||
| return `ServerBoundCorrectionDataPacket{sensorId: ${this.sensorId}, quaternion: ${this.quaternion}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/ServerBoundFusedIMUDataPacket.ts | ||
| var ServerBoundFusedIMUDataPacket = class _ServerBoundFusedIMUDataPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundFusedIMUDataPacket.type); | ||
| this.sensorId = data.readUInt8(0); | ||
| if (data.readUintBE(1, 1) !== 2 /* FLOAT */) { | ||
| throw new Error("ServerBoundFusedIMUDataPacket: data type must be float"); | ||
| } | ||
| this.quaternion = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10), data.readFloatBE(14)]; | ||
| } | ||
| static get type() { | ||
| return 26882; | ||
| } | ||
| toString() { | ||
| return `ServerBoundFusedIMUDataPacket{sensorId: ${this.sensorId}, quaternion: ${this.quaternion}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/ServerBoundRawIMUDataPacket.ts | ||
| var ServerBoundRawIMUDataPacket = class _ServerBoundRawIMUDataPacket extends Packet { | ||
| constructor(number, data) { | ||
| super(number, _ServerBoundRawIMUDataPacket.type); | ||
| this.sensorId = data.readUInt8(0); | ||
| const dataType = data.readUintBE(1, 1); | ||
| if (dataType === 1 /* INT */) { | ||
| this.rotation = [data.readInt32BE(2), data.readInt32BE(6), data.readInt32BE(10)]; | ||
| this.acceleration = [data.readInt32BE(15), data.readInt32BE(19), data.readInt32BE(23)]; | ||
| this.magnetometer = [data.readInt32BE(28), data.readInt32BE(32), data.readInt32BE(36)]; | ||
| } else if (dataType === 2 /* FLOAT */) { | ||
| this.rotation = [data.readFloatBE(2), data.readFloatBE(6), data.readFloatBE(10)]; | ||
| this.acceleration = [data.readFloatBE(15), data.readFloatBE(19), data.readFloatBE(23)]; | ||
| this.magnetometer = [data.readFloatBE(28), data.readFloatBE(32), data.readFloatBE(36)]; | ||
| } else { | ||
| throw new Error("ServerBoundRawIMUDataPacket: data type must be float or int"); | ||
| } | ||
| this.rotationAccuracy = data.readUintBE(14, 1); | ||
| this.accelerationAccuracy = data.readUintBE(27, 1); | ||
| this.magnetometerAccuracy = data.readUintBE(40, 1); | ||
| } | ||
| static get type() { | ||
| return 26881; | ||
| } | ||
| toString() { | ||
| return `ServerBoundRawIMUDataPacket{sensorId: ${this.sensorId}, rotation: ${this.rotation}, rotationAccuracy: ${this.rotationAccuracy}, acceleration: ${this.acceleration}, accelerationAccuracy: ${this.accelerationAccuracy}, magnetometer: ${this.magnetometer}, magnetometerAccuracy: ${this.magnetometerAccuracy}}`; | ||
| } | ||
| }; | ||
| // src/packets/inspection/PacketParser.ts | ||
| var InspectionPacketParser = class { | ||
| static get type() { | ||
| return 105; | ||
| } | ||
| }; | ||
| InspectionPacketParser.parseRawDataPacket = (number, data) => { | ||
| const packetType = data.readUInt8(0); | ||
| data = data.slice(1); | ||
| switch (packetType) { | ||
| case 1 /* RAW */: | ||
| return new ServerBoundRawIMUDataPacket(number, data); | ||
| case 2 /* FUSED */: | ||
| return new ServerBoundFusedIMUDataPacket(number, data); | ||
| case 3 /* CORRECTION */: | ||
| return new ServerBoundCorrectionDataPacket(number, data); | ||
| default: | ||
| console.log(`Unknown packet type: ${PacketType}`); | ||
| return null; | ||
| } | ||
| }; | ||
| // src/packets/PacketParser.ts | ||
| var parse = (data, isDeviceBound, isInBundle = false) => { | ||
| if (isDeviceBound) { | ||
| if (data.readUint8(0) === DeviceBoundHandshakePacket.type) { | ||
| return new DeviceBoundHandshakePacket(0n); | ||
| } | ||
| const type = data.readUInt32BE(); | ||
| if (type === DeviceBoundSensorInfoPacket.type) { | ||
| return new DeviceBoundSensorInfoPacket(0n, data); | ||
| } | ||
| const number = data.readBigInt64BE(4); | ||
| data = data.slice(12); | ||
| switch (type) { | ||
| case DeviceBoundHeartbeatPacket.type: | ||
| return new DeviceBoundHeartbeatPacket(number); | ||
| case DeviceBoundPingPacket.type: | ||
| return new DeviceBoundPingPacket(number, data); | ||
| case DeviceBoundFeatureFlagsPacket.type: | ||
| return new DeviceBoundFeatureFlagsPacket(number, data); | ||
| default: | ||
| console.log(data.toString("hex")); | ||
| console.log(`Unknown packet type: ${type}`); | ||
| return null; | ||
| } | ||
| } else { | ||
| const type = data.readUInt32BE(); | ||
| const number = isInBundle ? BigInt(0) : data.readBigInt64BE(4); | ||
| data = data.slice(isInBundle ? 4 : 12); | ||
| switch (type) { | ||
| case ServerBoundHeartbeatPacket.type: | ||
| return new ServerBoundHeartbeatPacket(number); | ||
| case ServerBoundRotationPacket.type: | ||
| return new ServerBoundRotationPacket(number, data); | ||
| case ServerBoundGyroPacket.type: | ||
| return new ServerBoundGyroPacket(number, data); | ||
| case ServerBoundHandshakePacket.type: | ||
| return new ServerBoundHandshakePacket(number, data); | ||
| case ServerBoundAccelPacket.type: | ||
| return new ServerBoundAccelPacket(number, data); | ||
| case ServerBoundRawCalibrationDataPacket.type: | ||
| return new ServerBoundRawCalibrationDataPacket(number, data); | ||
| case ServerBoundCalibrationFinishedPacket.type: | ||
| return new ServerBoundCalibrationFinishedPacket(number, data); | ||
| case ServerBoundPongPacket.type: | ||
| return new ServerBoundPongPacket(number, data); | ||
| case ServerBoundBatteryLevelPacket.type: | ||
| return new ServerBoundBatteryLevelPacket(number, data); | ||
| case ServerBoundTapPacket.type: | ||
| return new ServerBoundTapPacket(number, data); | ||
| case ServerBoundErrorPacket.type: | ||
| return new ServerBoundErrorPacket(number, data); | ||
| case ServerBoundSensorInfoPacket.type: | ||
| return new ServerBoundSensorInfoPacket(number, data); | ||
| case ServerBoundRotationDataPacket.type: | ||
| return new ServerBoundRotationDataPacket(number, data); | ||
| case ServerBoundFeatureFlagsPacket.type: | ||
| return new ServerBoundFeatureFlagsPacket(number, data); | ||
| case ServerBoundBundlePacket.type: | ||
| return new ServerBoundBundlePacket(number, data); | ||
| case ServerBoundMagnetometerAccuracyPacket.type: | ||
| return new ServerBoundMagnetometerAccuracyPacket(number, data); | ||
| case ServerBoundSignalStrengthPacket.type: | ||
| return new ServerBoundSignalStrengthPacket(number, data); | ||
| case ServerBoundTemperaturePacket.type: | ||
| return new ServerBoundTemperaturePacket(number, data); | ||
| case InspectionPacketParser.type: | ||
| return InspectionPacketParser.parseRawDataPacket(number, data); | ||
| default: | ||
| console.log(`Unknown packet type: ${type}`); | ||
| return null; | ||
| } | ||
| } | ||
| }; | ||
| export { | ||
| AVAILABLE_FIRMWARE_FEATURE_FLAGS, | ||
| AVAILABLE_SERVER_FEATURE_FLAGS, | ||
| BoardType, | ||
| DeviceBoundFeatureFlagsPacket, | ||
| DeviceBoundHandshakePacket, | ||
| DeviceBoundHeartbeatPacket, | ||
| DeviceBoundPingPacket, | ||
| DeviceBoundSensorInfoPacket, | ||
| FirmwareFeatureFlags, | ||
| InspectionPacketParser, | ||
| MCUType, | ||
| Packet, | ||
| PacketWithSensorId, | ||
| Protocol, | ||
| RawCalibrationDataType, | ||
| RotationDataType, | ||
| SensorStatus, | ||
| SensorType, | ||
| ServerBoundAccelPacket, | ||
| ServerBoundBatteryLevelPacket, | ||
| ServerBoundBundlePacket, | ||
| ServerBoundCalibrationFinishedPacket, | ||
| ServerBoundCorrectionDataPacket, | ||
| ServerBoundErrorPacket, | ||
| ServerBoundFeatureFlagsPacket, | ||
| ServerBoundFusedIMUDataPacket, | ||
| ServerBoundGyroPacket, | ||
| ServerBoundHandshakePacket, | ||
| ServerBoundHeartbeatPacket, | ||
| ServerBoundMagnetometerAccuracyPacket, | ||
| ServerBoundPongPacket, | ||
| ServerBoundRawCalibrationDataPacket, | ||
| ServerBoundRawIMUDataPacket, | ||
| ServerBoundRotationDataPacket, | ||
| ServerBoundRotationPacket, | ||
| ServerBoundSensorInfoPacket, | ||
| ServerBoundSignalStrengthPacket, | ||
| ServerBoundTapPacket, | ||
| ServerBoundTemperaturePacket, | ||
| ServerFeatureFlags, | ||
| makeFeatureFlagContainer, | ||
| parse | ||
| }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
36734
-71.95%38
-11.63%959
-68.85%1
Infinity%+ Added
- Removed
Updated