@z0mt3c/f1-telemetry-client
Version:
[](https://github.com/z0mt3c/f1-telemetry-client/actions/workflows/node.js.yml) [ • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PacketSessionHistoryDataParser = void 0;
const F1Parser_1 = require("../F1Parser");
const LapHistoryDataParser_1 = require("./LapHistoryDataParser");
const TyreStintsHistoryDataParser_1 = require("./TyreStintsHistoryDataParser");
const PacketHeaderParser_1 = require("./PacketHeaderParser");
class PacketSessionHistoryDataParser extends F1Parser_1.F1Parser {
constructor(buffer, packetFormat, bigintEnabled) {
super();
this.endianess('little')
.nest('m_header', {
type: new PacketHeaderParser_1.PacketHeaderParser(packetFormat, bigintEnabled),
})
.uint8('m_carIdx')
.uint8('m_numLaps')
.uint8('m_numTyreStints')
.uint8('m_bestLapTimeLapNum')
.uint8('m_bestSector1LapNum')
.uint8('m_bestSector2LapNum')
.uint8('m_bestSector3LapNum')
.array('m_lapHistoryData', {
length: 100,
type: new LapHistoryDataParser_1.LapHistoryDataParser(packetFormat),
})
.array('m_tyreStintsHistoryData', {
length: 8,
type: new TyreStintsHistoryDataParser_1.TyreStintsHistoryDataParser(),
});
this.data = this.postProcess(this.fromBuffer(buffer));
}
postProcess(packetSessionHistoryData) {
packetSessionHistoryData.m_lapHistoryData.forEach((lap) => {
if (lap.m_sector1TimeMinutes != null && lap.m_sector1TimeInMS != null && lap.m_sector1TimeMinutes > 0) {
lap.m_sector1TimeInMS += lap.m_sector1TimeMinutes * 60 * 1000;
lap.m_sector1TimeMinutes = undefined;
}
if (lap.m_sector2TimeMinutes != null && lap.m_sector2TimeInMS != null && lap.m_sector2TimeMinutes > 0) {
lap.m_sector2TimeInMS += lap.m_sector2TimeMinutes * 60 * 1000;
lap.m_sector2TimeMinutes = undefined;
}
if (lap.m_sector3TimeMinutes != null && lap.m_sector3TimeInMS != null && lap.m_sector3TimeMinutes > 0) {
lap.m_sector3TimeInMS += lap.m_sector3TimeMinutes * 60 * 1000;
lap.m_sector3TimeMinutes = undefined;
}
});
return packetSessionHistoryData;
}
}
exports.PacketSessionHistoryDataParser = PacketSessionHistoryDataParser;