repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Release 1.0.8
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
OCPPRequestService.ts
diff --git
a/src/charging-station/ocpp/OCPPRequestService.ts
b/src/charging-station/ocpp/OCPPRequestService.ts
index 6ebb4e3841bc1b57c914fc890b1cc2f911d0cc07..70742ea8cb472e304df44beb7d95964bdc597fba 100644
(file)
--- a/
src/charging-station/ocpp/OCPPRequestService.ts
+++ b/
src/charging-station/ocpp/OCPPRequestService.ts
@@
-1,5
+1,5
@@
import { AuthorizeResponse, StartTransactionResponse, StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction';
import { AuthorizeResponse, StartTransactionResponse, StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction';
-import { IncomingRequestCommand, Request
, Request
Command } from '../../types/ocpp/Requests';
+import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests';
import { BootNotificationResponse } from '../../types/ocpp/Responses';
import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode';
import { BootNotificationResponse } from '../../types/ocpp/Responses';
import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode';
@@
-21,7
+21,7
@@
export default abstract class OCPPRequestService {
this.ocppResponseService = ocppResponseService;
}
this.ocppResponseService = ocppResponseService;
}
- public async sendMessage(messageId: string, commandParams: any, messageType: MessageType
= MessageType.CALL_RESULT_MESSAGE
, commandName: RequestCommand | IncomingRequestCommand): Promise<any> {
+ public async sendMessage(messageId: string, commandParams: any, messageType: MessageType, commandName: RequestCommand | IncomingRequestCommand): Promise<any> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
// Send a message through wsConnection
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
// Send a message through wsConnection
@@
-32,7
+32,7
@@
export default abstract class OCPPRequestService {
// Request
case MessageType.CALL_MESSAGE:
// Build request
// Request
case MessageType.CALL_MESSAGE:
// Build request
- this.chargingStation.requests[messageId] = [responseCallback, rejectCallback, commandParams
] as Request
;
+ this.chargingStation.requests[messageId] = [responseCallback, rejectCallback, commandParams
as Record<string, unknown>]
;
messageToSend = JSON.stringify([messageType, messageId, commandName, commandParams]);
break;
// Response
messageToSend = JSON.stringify([messageType, messageId, commandName, commandParams]);
break;
// Response
@@
-49,13
+49,13
@@
export default abstract class OCPPRequestService {
// Check if wsConnection opened and charging station registered
if (this.chargingStation.isWebSocketOpen() && (this.chargingStation.isRegistered() || commandName === RequestCommand.BOOT_NOTIFICATION)) {
if (this.chargingStation.getEnableStatistics()) {
// Check if wsConnection opened and charging station registered
if (this.chargingStation.isWebSocketOpen() && (this.chargingStation.isRegistered() || commandName === RequestCommand.BOOT_NOTIFICATION)) {
if (this.chargingStation.getEnableStatistics()) {
- this.chargingStation.
s
tatistics.addMessage(commandName, messageType);
+ this.chargingStation.
performanceS
tatistics.addMessage(commandName, messageType);
}
// Yes: Send Message
this.chargingStation.wsConnection.send(messageToSend);
} else if (commandName !== RequestCommand.BOOT_NOTIFICATION) {
// Buffer it
}
// Yes: Send Message
this.chargingStation.wsConnection.send(messageToSend);
} else if (commandName !== RequestCommand.BOOT_NOTIFICATION) {
// Buffer it
- this.chargingStation.add
MessageToBuffer
(messageToSend);
+ this.chargingStation.add
ToMessageQueue
(messageToSend);
// Reject it
return rejectCallback(new OCPPError(commandParams.code ? commandParams.code : ErrorType.GENERIC_ERROR, commandParams.message ? commandParams.message : `WebSocket closed for message id '${messageId}' with content '${messageToSend}', message buffered`, commandParams.details ? commandParams.details : {}));
}
// Reject it
return rejectCallback(new OCPPError(commandParams.code ? commandParams.code : ErrorType.GENERIC_ERROR, commandParams.message ? commandParams.message : `WebSocket closed for message id '${messageId}' with content '${messageToSend}', message buffered`, commandParams.details ? commandParams.details : {}));
}
@@
-68,20
+68,29
@@
export default abstract class OCPPRequestService {
setTimeout(() => rejectCallback(new OCPPError(commandParams.code ? commandParams.code : ErrorType.GENERIC_ERROR, commandParams.message ? commandParams.message : `Timeout for message id '${messageId}' with content '${messageToSend}'`, commandParams.details ? commandParams.details : {})), Constants.OCPP_ERROR_TIMEOUT);
}
setTimeout(() => rejectCallback(new OCPPError(commandParams.code ? commandParams.code : ErrorType.GENERIC_ERROR, commandParams.message ? commandParams.message : `Timeout for message id '${messageId}' with content '${messageToSend}'`, commandParams.details ? commandParams.details : {})), Constants.OCPP_ERROR_TIMEOUT);
}
- // Function that will receive the request's response
+ /**
+ * Function that will receive the request's response
+ *
+ * @param {Record<string, unknown> | string} payload
+ * @param {Record<string, unknown>} requestPayload
+ */
async function responseCallback(payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>): Promise<void> {
if (self.chargingStation.getEnableStatistics()) {
async function responseCallback(payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>): Promise<void> {
if (self.chargingStation.getEnableStatistics()) {
- self.chargingStation.
statistics.addMessage(commandName, messageType
);
+ self.chargingStation.
performanceStatistics.addMessage(commandName, MessageType.CALL_RESULT_MESSAGE
);
}
// Send the response
await self.ocppResponseService.handleResponse(commandName as RequestCommand, payload, requestPayload);
resolve(payload);
}
}
// Send the response
await self.ocppResponseService.handleResponse(commandName as RequestCommand, payload, requestPayload);
resolve(payload);
}
- // Function that will receive the request's rejection
+ /**
+ * Function that will receive the request's rejection
+ *
+ * @param {OCPPError} error
+ */
function rejectCallback(error: OCPPError): void {
if (self.chargingStation.getEnableStatistics()) {
function rejectCallback(error: OCPPError): void {
if (self.chargingStation.getEnableStatistics()) {
- self.chargingStation.
statistics.addMessage(commandName, messageType
);
+ self.chargingStation.
performanceStatistics.addMessage(commandName, MessageType.CALL_ERROR_MESSAGE
);
}
logger.debug(`${self.chargingStation.logPrefix()} Error: %j occurred when calling command %s with parameters: %j`, error, commandName, commandParams);
// Build Exception
}
logger.debug(`${self.chargingStation.logPrefix()} Error: %j occurred when calling command %s with parameters: %j`, error, commandName, commandParams);
// Build Exception