import { SupervisionUrlDistribution } from '../types/ConfigurationData';
import { URL } from 'url';
import Utils from '../utils/Utils';
-import chalk from 'chalk';
import crypto from 'crypto';
import fs from 'fs';
import logger from '../utils/Logger';
let errMsg: string;
try {
const request = JSON.parse(data.toString()) as IncomingRequest;
- const requestAsString = JSON.stringify(request);
- console.log(chalk`{yellow << Received message = ${requestAsString}}`);
if (Utils.isIterable(request)) {
// Parse the message
[messageType, messageId, commandName, commandPayload, errorDetails] = request;
throw new OCPPError(
ErrorType.PROTOCOL_ERROR,
'Incoming request is not iterable',
- commandName
+ Utils.isString(commandName) && commandName,
+ { payload: request }
);
}
// Check the Type of message
commandName,
commandPayload
);
+ logger.debug(
+ `${this.logPrefix()} << Command '${commandName}' received request payload: ${JSON.stringify(
+ request
+ )}`
+ );
break;
// Outcome Message
case MessageType.CALL_RESULT_MESSAGE:
// Respond
cachedRequest = this.requests.get(messageId);
if (Utils.isIterable(cachedRequest)) {
- [responseCallback, , , requestPayload] = cachedRequest;
+ [responseCallback, , requestCommandName, requestPayload] = cachedRequest;
} else {
throw new OCPPError(
ErrorType.PROTOCOL_ERROR,
`Cached request for message id ${messageId} response is not iterable`,
- commandName
+ requestCommandName
);
}
if (!responseCallback) {
throw new OCPPError(
ErrorType.INTERNAL_ERROR,
`Response for unknown message id ${messageId}`,
- commandName
+ requestCommandName
);
}
responseCallback(commandName, requestPayload);
+ logger.debug(
+ `${this.logPrefix()} << Command '${requestCommandName}' received response payload: ${JSON.stringify(
+ request
+ )}`
+ );
break;
// Error Message
case MessageType.CALL_ERROR_MESSAGE:
rejectCallback(
new OCPPError(commandName, commandPayload.toString(), requestCommandName, errorDetails)
);
+ logger.debug(
+ `${this.logPrefix()} << Command '${requestCommandName}' received error payload: ${JSON.stringify(
+ request
+ )}`
+ );
break;
// Error
default:
}
}
- private handleResponseHeartbeat(
- payload: OCPP16HeartbeatResponse,
- requestPayload: OCPP16HeartbeatRequest
- ): void {
- logger.debug(
- this.chargingStation.logPrefix() +
- ' Heartbeat response received: %j to Heartbeat request: %j',
- payload,
- requestPayload
- );
- }
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
+ private handleResponseHeartbeat(): void {}
private handleResponseAuthorize(
payload: OCPP16AuthorizeResponse,
}
}
- private handleResponseStatusNotification(
- payload: OCPP16StatusNotificationRequest,
- requestPayload: OCPP16StatusNotificationResponse
- ): void {
- logger.debug(
- this.chargingStation.logPrefix() +
- ' Status notification response received: %j to StatusNotification request: %j',
- payload,
- requestPayload
- );
- }
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
+ private handleResponseStatusNotification(): void {}
- private handleResponseMeterValues(
- payload: OCPP16MeterValuesRequest,
- requestPayload: OCPP16MeterValuesResponse
- ): void {
- logger.debug(
- this.chargingStation.logPrefix() +
- ' MeterValues response received: %j to MeterValues request: %j',
- payload,
- requestPayload
- );
- }
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
+ private handleResponseMeterValues(): void {}
}
import type OCPPResponseService from './OCPPResponseService';
import PerformanceStatistics from '../../performance/PerformanceStatistics';
import Utils from '../../utils/Utils';
-import chalk from 'chalk';
import logger from '../../utils/Logger';
export default abstract class OCPPRequestService {
if (this.chargingStation.isWebSocketConnectionOpened()) {
// Yes: Send Message
const beginId = PerformanceStatistics.beginMeasure(commandName);
- console.log(chalk`{blue >> Sending message = ${messageToSend}}`);
// FIXME: Handle sending error
this.chargingStation.wsConnection.send(messageToSend);
PerformanceStatistics.endMeasure(commandName, beginId);
+ let msgTypeStr: string;
+ switch (messageType) {
+ case MessageType.CALL_MESSAGE:
+ msgTypeStr = 'request';
+ break;
+ case MessageType.CALL_RESULT_MESSAGE:
+ msgTypeStr = 'response';
+ break;
+ case MessageType.CALL_ERROR_MESSAGE:
+ msgTypeStr = 'error';
+ break;
+ }
+ logger.debug(
+ `${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${msgTypeStr} payload: ${messageToSend}`
+ );
} else if (!params.skipBufferingOnError) {
// Buffer it
this.chargingStation.bufferMessage(messageToSend);