node-insim
Version:
An InSim library for NodeJS with TypeScript support
178 lines (177 loc) • 7.29 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutSimPack2 = void 0;
var decorators_1 = require("../decorators");
var packets_1 = require("../packets");
var OutSimInputs_1 = require("./OutSimInputs");
var OutSimMain_1 = require("./OutSimMain");
var OutSimOptions_1 = require("./OutSimOptions");
var OutSimWheel_1 = require("./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.
*/
var OutSimPack2 = /** @class */ (function (_super) {
__extends(OutSimPack2, _super);
function OutSimPack2(outSimOpts) {
var _this = _super.call(this) || this;
// 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_1.OutSimMain();
// if (OSOpts & OSO_INPUTS)
/** Vehicle inputs part */
_this.OSInputs = new OutSimInputs_1.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(function () { return new OutSimWheel_1.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;
return _this;
}
OutSimPack2.prototype.getValidPropertyNames = function () {
// manually setting property names for dynamic LFS data based on OSOpts
var validPropertyNames = [];
if (this.OSOpts & OutSimOptions_1.OutSimOptions.OSO_HEADER) {
validPropertyNames.push('Header');
}
if (this.OSOpts & OutSimOptions_1.OutSimOptions.OSO_ID) {
validPropertyNames.push('ID');
}
if (this.OSOpts & OutSimOptions_1.OutSimOptions.OSO_TIME) {
validPropertyNames.push('Time');
}
if (this.OSOpts & OutSimOptions_1.OutSimOptions.OSO_MAIN) {
validPropertyNames.push('OSMain');
}
if (this.OSOpts & OutSimOptions_1.OutSimOptions.OSO_INPUTS) {
validPropertyNames.push('OSInputs');
}
if (this.OSOpts & OutSimOptions_1.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_1.OutSimOptions.OSO_DISTANCE) {
validPropertyNames.push('CurrentLapDist');
validPropertyNames.push('IndexedDistance');
}
if (this.OSOpts & OutSimOptions_1.OutSimOptions.OSO_WHEELS) {
validPropertyNames.push('OSWheels');
}
if (this.OSOpts & OutSimOptions_1.OutSimOptions.OSO_EXTRA_1) {
validPropertyNames.push('SteerTorque');
validPropertyNames.push('Spare');
}
return validPropertyNames;
};
__decorate([
(0, decorators_1.string)(4)
], OutSimPack2.prototype, "Header", void 0);
__decorate([
(0, decorators_1.int)()
], OutSimPack2.prototype, "ID", void 0);
__decorate([
(0, decorators_1.unsigned)()
], OutSimPack2.prototype, "Time", void 0);
__decorate([
(0, decorators_1.struct)(OutSimMain_1.OutSimMain)
], OutSimPack2.prototype, "OSMain", void 0);
__decorate([
(0, decorators_1.struct)(OutSimInputs_1.OutSimInputs)
], OutSimPack2.prototype, "OSInputs", void 0);
__decorate([
(0, decorators_1.byte)()
], OutSimPack2.prototype, "Gear", void 0);
__decorate([
(0, decorators_1.byte)()
], OutSimPack2.prototype, "Sp1", void 0);
__decorate([
(0, decorators_1.byte)()
], OutSimPack2.prototype, "Sp2", void 0);
__decorate([
(0, decorators_1.byte)()
], OutSimPack2.prototype, "Sp3", void 0);
__decorate([
(0, decorators_1.float)()
], OutSimPack2.prototype, "EngineAngVel", void 0);
__decorate([
(0, decorators_1.float)()
], OutSimPack2.prototype, "MaxTorqueAtVel", void 0);
__decorate([
(0, decorators_1.float)()
], OutSimPack2.prototype, "CurrentLapDist", void 0);
__decorate([
(0, decorators_1.float)()
], OutSimPack2.prototype, "IndexedDistance", void 0);
__decorate([
(0, decorators_1.array)(OutSimWheel_1.OutSimWheel, 4)
], OutSimPack2.prototype, "OSWheels", void 0);
__decorate([
(0, decorators_1.float)()
], OutSimPack2.prototype, "SteerTorque", void 0);
__decorate([
(0, decorators_1.float)()
], OutSimPack2.prototype, "Spare", void 0);
return OutSimPack2;
}(packets_1.Struct));
exports.OutSimPack2 = OutSimPack2;