UNPKG

@robotical/ricjs

Version:

Javascript/TS library for Robotical RIC

272 lines 9.12 kB
"use strict"; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // RICJS // Communications Library // // Rob Dobson & Chris Greening 2020-2022 // (C) 2020-2022 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// Object.defineProperty(exports, "__esModule", { value: true }); class RICCommsStats { constructor() { this._msgRxCount = 0; this._msgRxCountInWindow = 0; this._msgRxLastCalcMs = 0; this._msgRxRate = 0; this._msgTooShort = 0; this._msgTxCount = 0; this._msgTxCountInWindow = 0; this._msgTxLastCalcMs = 0; this._msgTxRate = 0; this._msgNumCollisions = 0; this._msgNumUnmatched = 0; this._msgRoundtripWorstMs = 0; this._msgRoundtripBestMs = 0; this._msgRoundtripLastMs = 0; this._msgTimeout = 0; this._msgRetry = 0; this._msgSmartServos = 0; this._msgIMU = 0; this._msgMagneto = 0; this._msgPowerStatus = 0; this._msgAddOnPub = 0; this._msgRobotStatus = 0; this._msgSmartServosPS = 0; this._msgIMUPS = 0; this._msgMagnetoPS = 0; this._msgPowerStatusPS = 0; this._msgAddOnPubPS = 0; this._msgRobotStatusPS = 0; this._msgSmartServosCountInWindow = 0; this._msgIMUCountInWindow = 0; this._msgMagnetoCountInWindow = 0; this._msgPowerStatusCountInWindow = 0; this._msgAddOnPubCountInWindow = 0; this._msgRobotStatusCountInWindow = 0; this._msgSmartServosLastCalcMs = 0; this._msgIMULastCalcMs = 0; this._msgMagnetoLastCalcMs = 0; this._msgPowerStatusLastCalcMs = 0; this._msgAddOnPubLastCalcMs = 0; this._msgRobotStatusLastCalcMs = 0; this._msgOtherTopic = 0; this._msgNoConnection = 0; this._streamBytes = 0; this._fileBytes = 0; } clear() { this._msgRxCount = 0; this._msgRxCountInWindow = 0; this._msgRxLastCalcMs = Date.now(); this._msgRxRate = 0; this._msgTooShort = 0; this._msgTxCount = 0; this._msgTxCountInWindow = 0; this._msgTxLastCalcMs = Date.now(); this._msgTxRate = 0; this._msgNumCollisions = 0; this._msgNumUnmatched = 0; this._msgRoundtripBestMs = 0; this._msgRoundtripWorstMs = 0; this._msgRoundtripLastMs = 0; this._msgTimeout = 0; this._msgRetry = 0; this._msgSmartServos = 0; this._msgIMU = 0; this._msgMagneto = 0; this._msgPowerStatus = 0; this._msgAddOnPub = 0; this._msgRobotStatus = 0; this._msgSmartServosPS = 0; this._msgIMUPS = 0; this._msgMagnetoPS = 0; this._msgPowerStatusPS = 0; this._msgAddOnPubPS = 0; this._msgRobotStatusPS = 0; this._msgSmartServosCountInWindow = 0; this._msgIMUCountInWindow = 0; this._msgMagnetoCountInWindow = 0; this._msgPowerStatusCountInWindow = 0; this._msgAddOnPubCountInWindow = 0; this._msgRobotStatusCountInWindow = 0; this._msgSmartServosLastCalcMs = Date.now(); this._msgIMULastCalcMs = Date.now(); this._msgMagnetoLastCalcMs = Date.now(); this._msgPowerStatusLastCalcMs = Date.now(); this._msgAddOnPubLastCalcMs = Date.now(); this._msgRobotStatusLastCalcMs = Date.now(); this._msgOtherTopic = 0; this._msgNoConnection = 0; this._streamBytes = 0; this._fileBytes = 0; } msgRx() { this._msgRxCount++; this._msgRxCountInWindow++; } getMsgRxRate() { if (this._msgRxLastCalcMs + 1000 < Date.now()) { this._msgRxRate = (1000.0 * this._msgRxCountInWindow) / (Date.now() - this._msgRxLastCalcMs); this._msgRxLastCalcMs = Date.now(); this._msgRxCountInWindow = 0; } return this._msgRxRate; } msgTooShort() { this._msgTooShort++; } msgTx() { this._msgTxCount++; this._msgTxCountInWindow++; } getMsgTxRate() { if (this._msgTxLastCalcMs + 1000 < Date.now()) { this._msgTxRate = (1000.0 * this._msgTxCountInWindow) / (Date.now() - this._msgTxLastCalcMs); this._msgTxLastCalcMs = Date.now(); this._msgTxCountInWindow = 0; } return this._msgTxRate; } getSmartServosRate() { if (this._msgSmartServosLastCalcMs + 1000 < Date.now()) { this._msgSmartServosPS = (1000.0 * this._msgSmartServosCountInWindow) / (Date.now() - this._msgSmartServosLastCalcMs); this._msgSmartServosLastCalcMs = Date.now(); this._msgSmartServosCountInWindow = 0; } return this._msgSmartServosPS; } getIMURate() { if (this._msgIMULastCalcMs + 1000 < Date.now()) { this._msgIMUPS = (1000.0 * this._msgIMUCountInWindow) / (Date.now() - this._msgIMULastCalcMs); this._msgIMULastCalcMs = Date.now(); this._msgIMUCountInWindow = 0; } return this._msgIMUPS; } getMagnetoRate() { if (this._msgMagnetoLastCalcMs + 1000 < Date.now()) { this._msgMagnetoPS = (1000.0 * this._msgMagnetoCountInWindow) / (Date.now() - this._msgMagnetoLastCalcMs); this._msgMagnetoLastCalcMs = Date.now(); this._msgMagnetoCountInWindow = 0; } return this._msgMagnetoPS; } getPowerStatusRate() { if (this._msgPowerStatusLastCalcMs + 1000 < Date.now()) { this._msgPowerStatusPS = (1000.0 * this._msgPowerStatusCountInWindow) / (Date.now() - this._msgPowerStatusLastCalcMs); this._msgPowerStatusLastCalcMs = Date.now(); this._msgPowerStatusCountInWindow = 0; } return this._msgPowerStatusPS; } getAddOnPubRate() { if (this._msgAddOnPubLastCalcMs + 1000 < Date.now()) { this._msgAddOnPubPS = (1000.0 * this._msgAddOnPubCountInWindow) / (Date.now() - this._msgAddOnPubLastCalcMs); this._msgAddOnPubLastCalcMs = Date.now(); this._msgAddOnPubCountInWindow = 0; } return this._msgAddOnPubPS; } getRobotStatusRate() { if (this._msgRobotStatusLastCalcMs + 1000 < Date.now()) { this._msgRobotStatusPS = (1000.0 * this._msgRobotStatusCountInWindow) / (Date.now() - this._msgRobotStatusLastCalcMs); this._msgRobotStatusLastCalcMs = Date.now(); this._msgRobotStatusCountInWindow = 0; } return this._msgRobotStatusPS; } getRTWorstMs() { return this._msgRoundtripWorstMs; } getRTLastMs() { return this._msgRoundtripLastMs; } getRTBestMs() { return this._msgRoundtripBestMs; } getRetries() { return this._msgRetry; } recordMsgNumCollision() { this._msgNumCollisions++; } recordMsgNumUnmatched() { this._msgNumUnmatched++; } recordMsgResp(roundTripMs) { if (this._msgRoundtripWorstMs < roundTripMs) this._msgRoundtripWorstMs = roundTripMs; if (this._msgRoundtripBestMs == 0 || this._msgRoundtripBestMs > roundTripMs) this._msgRoundtripBestMs = roundTripMs; this._msgRoundtripLastMs = roundTripMs; } recordMsgTimeout() { this._msgTimeout++; } recordMsgNoConnection() { this._msgNoConnection++; } recordMsgRetry() { this._msgRetry++; } recordSmartServos() { this._msgSmartServos++; this._msgSmartServosCountInWindow++; this.msgRx(); } recordIMU() { this._msgIMU++; this._msgIMUCountInWindow++; // Don't call msgRx() as double counting msgs with smartServos } recordMagneto() { this._msgMagneto++; this._msgMagnetoCountInWindow++; // NT: Not sure if we should call msgRx() here or not (like with IMU above) } recordPowerStatus() { this._msgPowerStatus++; this._msgPowerStatusCountInWindow++; this.msgRx(); } recordAddOnPub() { this._msgAddOnPub++; this._msgAddOnPubCountInWindow++; this.msgRx(); } recordRobotStatus() { this._msgRobotStatus++; this._msgRobotStatusCountInWindow++; this.msgRx(); } recordOtherTopic() { this._msgOtherTopic++; this.msgRx(); } recordStreamBytes(bytes) { this._streamBytes += bytes; } recordFileBytes(bytes) { this._fileBytes += bytes; } } exports.default = RICCommsStats; //# sourceMappingURL=RICCommsStats.js.map