@robotical/roboticaljs
Version:
Javascript/TS library for Robotical products
153 lines • 5.54 kB
JavaScript
"use strict";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// RICJS
// Communications Library
//
// Rob Dobson & Chris Greening 2020-2022
// (C) 2020-2022
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object.defineProperty(exports, "__esModule", { value: true });
class RICCommsStats {
constructor() {
this._msgSmartServos = 0;
this._msgIMU = 0;
this._msgPowerStatus = 0;
this._msgAddOnPub = 0;
this._msgRobotStatus = 0;
this._msgSmartServosPS = 0;
this._msgIMUPS = 0;
this._msgPowerStatusPS = 0;
this._msgAddOnPubPS = 0;
this._msgRobotStatusPS = 0;
this._msgSmartServosCountInWindow = 0;
this._msgIMUCountInWindow = 0;
this._msgPowerStatusCountInWindow = 0;
this._msgAddOnPubCountInWindow = 0;
this._msgRobotStatusCountInWindow = 0;
this._msgSmartServosLastCalcMs = 0;
this._msgIMULastCalcMs = 0;
this._msgPowerStatusLastCalcMs = 0;
this._msgAddOnPubLastCalcMs = 0;
this._msgRobotStatusLastCalcMs = 0;
this._msgOtherTopic = 0;
this._rosSerialRxRate = 0;
this._rosSerialRxTotalBytes = 0;
this._rosSerialRxTotalTimeMs = 0;
}
clear() {
this._msgSmartServos = 0;
this._msgIMU = 0;
this._msgPowerStatus = 0;
this._msgAddOnPub = 0;
this._msgRobotStatus = 0;
this._msgSmartServosPS = 0;
this._msgIMUPS = 0;
this._msgPowerStatusPS = 0;
this._msgAddOnPubPS = 0;
this._msgRobotStatusPS = 0;
this._msgSmartServosCountInWindow = 0;
this._msgIMUCountInWindow = 0;
this._msgPowerStatusCountInWindow = 0;
this._msgAddOnPubCountInWindow = 0;
this._msgRobotStatusCountInWindow = 0;
this._msgSmartServosLastCalcMs = Date.now();
this._msgIMULastCalcMs = Date.now();
this._msgPowerStatusLastCalcMs = Date.now();
this._msgAddOnPubLastCalcMs = Date.now();
this._msgRobotStatusLastCalcMs = Date.now();
this._rosSerialRxRate = 0;
this._rosSerialRxTotalBytes = 0;
this._rosSerialRxTotalTimeMs = 0;
}
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;
}
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;
}
getROSSerialRate() {
if (this._rosSerialRxTotalTimeMs > 0) {
return ((1000.0 * this._rosSerialRxTotalBytes) / this._rosSerialRxTotalTimeMs);
}
return 0;
}
recordSmartServos() {
this._msgSmartServos++;
this._msgSmartServosCountInWindow++;
}
recordIMU() {
this._msgIMU++;
this._msgIMUCountInWindow++;
// Don't call msgRx() as double counting msgs with smartServos
}
recordPowerStatus() {
this._msgPowerStatus++;
this._msgPowerStatusCountInWindow++;
}
recordAddOnPub() {
this._msgAddOnPub++;
this._msgAddOnPubCountInWindow++;
}
recordRobotStatus() {
this._msgRobotStatus++;
this._msgRobotStatusCountInWindow++;
}
recordOtherTopic() {
this._msgOtherTopic++;
}
updateROSSerialRxRate(frameLen, timeMs) {
if ((frameLen != 0) && (timeMs != 0)) {
this._rosSerialRxRate = (1000 * frameLen) / timeMs;
this._rosSerialRxTotalTimeMs += timeMs;
this._rosSerialRxTotalBytes += frameLen;
}
}
}
exports.default = RICCommsStats;
//# sourceMappingURL=RICCommsStats.js.map