UNPKG

node-insim

Version:

An InSim library for NodeJS with TypeScript support

151 lines (150 loc) 4.95 kB
import { __decorate } from "tslib"; import { array, byte, float, int, string, struct, unsigned, } from '../decorators'; import { Struct } from '../packets'; import { OutSimInputs } from './OutSimInputs'; import { OutSimMain } from './OutSimMain'; import { OutSimOptions } from './OutSimOptions'; import { OutSimWheel } from './OutSimWheel'; /** * An extended and modular version of the {@link OutSimPack} packet. * * To receive this packet, set "OutSim Opts" integer in cfg.txt to a value greater than 0. * * OutSim Opts is hexadecimal - for all fields set OutSim Opts to 1ff. * * The resulting UDP packet size is 280. */ export class OutSimPack2 extends Struct { constructor(outSimOpts) { super(); // if (OSOpts & OSO_HEADER) /** Header of packet. Should be 'LFST' if OSOpts contains OSO_HEADER flag */ this.Header = ''; // if (OSOpts & OSO_ID) /** OutSim ID from cfg.txt */ this.ID = 0; // if (OSOpts & OSO_TIME) /** time in milliseconds (to check order) */ this.Time = 0; // if (OSOpts & OSO_MAIN) /** Vehicle position and velocity part */ this.OSMain = new OutSimMain(); // if (OSOpts & OSO_INPUTS) /** Vehicle inputs part */ this.OSInputs = new OutSimInputs(); // if (OSOpts & OSO_DRIVE) /** 0=R, 1=N, 2=first gear */ this.Gear = 0; /** spare */ this.Sp1 = 0; /** spare */ this.Sp2 = 0; /** spare */ this.Sp3 = 0; /** radians/s */ this.EngineAngVel = 0; /** Nm : output torque for throttle 1.0 */ this.MaxTorqueAtVel = 0; // if (OSOpts & OSO_DISTANCE) /** m - travelled by car */ this.CurrentLapDist = 0; /** m - track ruler measurement */ this.IndexedDistance = 0; // if (OSOpts & OSO_WHEELS) /** Wheels data */ this.OSWheels = Array.from(new Array(4)).map(() => new OutSimWheel()); // if (OSOpts & OSO_EXTRA_1) /** Nm : steering torque on front wheels (proportional to force feedback) */ this.SteerTorque = 0; /** spare */ this.Spare = 0; this.OSOpts = outSimOpts; } getValidPropertyNames() { // manually setting property names for dynamic LFS data based on OSOpts const validPropertyNames = []; if (this.OSOpts & OutSimOptions.OSO_HEADER) { validPropertyNames.push('Header'); } if (this.OSOpts & OutSimOptions.OSO_ID) { validPropertyNames.push('ID'); } if (this.OSOpts & OutSimOptions.OSO_TIME) { validPropertyNames.push('Time'); } if (this.OSOpts & OutSimOptions.OSO_MAIN) { validPropertyNames.push('OSMain'); } if (this.OSOpts & OutSimOptions.OSO_INPUTS) { validPropertyNames.push('OSInputs'); } if (this.OSOpts & OutSimOptions.OSO_DRIVE) { validPropertyNames.push('Gear'); validPropertyNames.push('Sp1'); validPropertyNames.push('Sp2'); validPropertyNames.push('Sp3'); validPropertyNames.push('EngineAngVel'); validPropertyNames.push('MaxTorqueAtVel'); } if (this.OSOpts & OutSimOptions.OSO_DISTANCE) { validPropertyNames.push('CurrentLapDist'); validPropertyNames.push('IndexedDistance'); } if (this.OSOpts & OutSimOptions.OSO_WHEELS) { validPropertyNames.push('OSWheels'); } if (this.OSOpts & OutSimOptions.OSO_EXTRA_1) { validPropertyNames.push('SteerTorque'); validPropertyNames.push('Spare'); } return validPropertyNames; } } __decorate([ string(4) ], OutSimPack2.prototype, "Header", void 0); __decorate([ int() ], OutSimPack2.prototype, "ID", void 0); __decorate([ unsigned() ], OutSimPack2.prototype, "Time", void 0); __decorate([ struct(OutSimMain) ], OutSimPack2.prototype, "OSMain", void 0); __decorate([ struct(OutSimInputs) ], OutSimPack2.prototype, "OSInputs", void 0); __decorate([ byte() ], OutSimPack2.prototype, "Gear", void 0); __decorate([ byte() ], OutSimPack2.prototype, "Sp1", void 0); __decorate([ byte() ], OutSimPack2.prototype, "Sp2", void 0); __decorate([ byte() ], OutSimPack2.prototype, "Sp3", void 0); __decorate([ float() ], OutSimPack2.prototype, "EngineAngVel", void 0); __decorate([ float() ], OutSimPack2.prototype, "MaxTorqueAtVel", void 0); __decorate([ float() ], OutSimPack2.prototype, "CurrentLapDist", void 0); __decorate([ float() ], OutSimPack2.prototype, "IndexedDistance", void 0); __decorate([ array(OutSimWheel, 4) ], OutSimPack2.prototype, "OSWheels", void 0); __decorate([ float() ], OutSimPack2.prototype, "SteerTorque", void 0); __decorate([ float() ], OutSimPack2.prototype, "Spare", void 0);