import Connectors, { Connector } from '../types/Connectors';
import { MeterValue, MeterValueLocation, MeterValueMeasurand, MeterValuePhase, MeterValueUnit, MeterValuesRequest, MeterValuesResponse, SampledValue } from '../types/ocpp/1.6/MeterValues';
import { PerformanceObserver, performance } from 'perf_hooks';
-import Requests, { BootNotificationRequest, ChangeConfigurationRequest, GetConfigurationRequest, HeartbeatRequest, IncomingRequestCommand, RemoteStartTransactionRequest, RemoteStopTransactionRequest, RequestCommand, ResetRequest, SetChargingProfileRequest, StatusNotificationRequest, UnlockConnectorRequest } from '../types/ocpp/1.6/Requests';
+import Requests, { BootNotificationRequest, ChangeConfigurationRequest, GetConfigurationRequest, HeartbeatRequest, IncomingRequest, IncomingRequestCommand, RemoteStartTransactionRequest, RemoteStopTransactionRequest, Request, RequestCommand, ResetRequest, SetChargingProfileRequest, StatusNotificationRequest, UnlockConnectorRequest } from '../types/ocpp/1.6/Requests';
import WebSocket, { MessageEvent } from 'ws';
import AutomaticTransactionGenerator from './AutomaticTransactionGenerator';
}
async onMessage(messageEvent: MessageEvent): Promise<void> {
- let [messageType, messageId, commandName, commandPayload, errorDetails] = [0, '', Constants.ENTITY_CHARGING_STATION, '', ''];
+ let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, '', ''];
try {
// Parse the message
- [messageType, messageId, commandName, commandPayload, errorDetails] = JSON.parse(messageEvent.toString());
+ [messageType, messageId, commandName, commandPayload, errorDetails] = JSON.parse(messageEvent.toString()) as IncomingRequest;
// Check the Type of message
switch (messageType) {
// Incoming Message
case MessageType.CALL_MESSAGE:
if (this.getEnableStatistics()) {
- this._statistics.addMessage(commandName as IncomingRequestCommand, messageType);
+ this._statistics.addMessage(commandName , messageType);
}
// Process the call
- await this.handleRequest(messageId, commandName as IncomingRequestCommand, commandPayload);
+ await this.handleRequest(messageId, commandName , commandPayload);
break;
// Outcome Message
case MessageType.CALL_RESULT_MESSAGE:
}
} catch (error) {
// Log
- logger.error('%s Incoming message %j processing error %s on request content type %s', this._logPrefix(), messageEvent, error, this._requests[messageId]);
+ logger.error('%s Incoming message %j processing error %j on request content type %j', this._logPrefix(), messageEvent, error, this._requests[messageId]);
// Send error
- messageType !== MessageType.CALL_ERROR_MESSAGE && await this.sendError(messageId, error, commandName as IncomingRequestCommand);
+ messageType !== MessageType.CALL_ERROR_MESSAGE && await this.sendError(messageId, error, commandName);
}
}
// Request
case MessageType.CALL_MESSAGE:
// Build request
- this._requests[messageId] = [responseCallback, rejectCallback, commandParams];
+ this._requests[messageId] = [responseCallback, rejectCallback, commandParams] as Request;
messageToSend = JSON.stringify([messageType, messageId, commandName, commandParams]);
break;
// Response
import { ChargePointErrorCode } from './ChargePointErrorCode';
import { ChargePointStatus } from './ChargePointStatus';
import { ChargingProfile } from './ChargingProfile';
+import { MessageType } from '../MessageType';
import OCPPError from '../../../charging-station/OcppError';
export default interface Requests {
- [id: string]: [(payload?, requestPayload?) => void, (error?: OCPPError) => void, Record<string, unknown>];
+ [id: string]: Request;
}
+export type Request = [(payload?, requestPayload?) => void, (error?: OCPPError) => void, Record<string, unknown>];
+
+export type IncomingRequest = [MessageType, string, IncomingRequestCommand, string, string];
+
export enum RequestCommand {
BOOT_NOTIFICATION = 'BootNotification',
HEARTBEAT = 'Heartbeat',