import CommandStatistics, { CommandStatisticsData, PerfEntry } from '../types/CommandStatistics';
+import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/1.6/Requests';
import CircularArray from './CircularArray';
import Configuration from './Configuration';
-import Constants from './Constants';
+import { MessageType } from '../types/ocpp/MessageType';
import { PerformanceEntry } from 'perf_hooks';
import Utils from './Utils';
import logger from './Logger';
return Statistics.instance;
}
- addMessage(command: string, messageType: number): void {
+ addMessage(command: RequestCommand | IncomingRequestCommand, messageType: MessageType): void {
switch (messageType) {
- case Constants.OCPP_JSON_CALL_MESSAGE:
+ case MessageType.CALL_MESSAGE:
if (this._commandsStatistics[command] && this._commandsStatistics[command].countRequest) {
this._commandsStatistics[command].countRequest++;
} else {
this._commandsStatistics[command].countRequest = 1;
}
break;
- case Constants.OCPP_JSON_CALL_RESULT_MESSAGE:
+ case MessageType.CALL_RESULT_MESSAGE:
if (this._commandsStatistics[command]) {
if (this._commandsStatistics[command].countResponse) {
this._commandsStatistics[command].countResponse++;
this._commandsStatistics[command].countResponse = 1;
}
break;
- case Constants.OCPP_JSON_CALL_ERROR_MESSAGE:
+ case MessageType.CALL_ERROR_MESSAGE:
if (this._commandsStatistics[command]) {
if (this._commandsStatistics[command].countError) {
this._commandsStatistics[command].countError++;
}
logPerformance(entry: PerformanceEntry, className: string): void {
- this.addPerformanceTimer(entry.name, entry.duration);
+ this.addPerformanceTimer(entry.name as RequestCommand | IncomingRequestCommand, entry.duration);
const perfEntry: PerfEntry = {} as PerfEntry;
perfEntry.name = entry.name;
perfEntry.entryType = entry.entryType;
return (sortedDataSet[(middleIndex - 1)] + sortedDataSet[middleIndex]) / 2;
}
- private addPerformanceTimer(command: string, duration: number): void {
+ private addPerformanceTimer(command: RequestCommand | IncomingRequestCommand, duration: number): void {
// Map to proper command name
const MAPCOMMAND = {
sendMeterValues: 'MeterValues',
stopTransaction: 'StopTransaction',
};
if (MAPCOMMAND[command]) {
- command = MAPCOMMAND[command] as string;
+ command = MAPCOMMAND[command] as RequestCommand | IncomingRequestCommand;
}
// Initialize command statistics
if (!this._commandsStatistics[command]) {