Added WS sendResponse() method
MODIFY
src/server/ocpp/json/JsonRestWSConnection.ts
src/server/ocpp/json/JsonRestWSConnection.ts
@@ -110,7 +110,7 @@ export default class JsonRestWSConnection extends WSConnection {
// Call the method
const result = await chargingStationClient[actionMethod](commandPayload);
// Send Response
- await this.sendMessage(messageId, OCPPMessageType.CALL_RESULT_MESSAGE, command, result);
+ await this.sendResponse(messageId, command, result);
} else {
// Error
throw new BackendError({

MODIFY
src/server/ocpp/json/JsonWSConnection.ts
src/server/ocpp/json/JsonWSConnection.ts
@@ -166,7 +166,7 @@ export default class JsonWSConnection extends WSConnection {
// Call it
result = await this.chargingStationService[methodName](this.headers, commandPayload);
// Send Response
- await this.sendMessage(messageId, OCPPMessageType.CALL_RESULT_MESSAGE, command, result);
+ await this.sendResponse(messageId, command, result);
} finally {
// Clean the header
delete this.headers.chargingStation;

MODIFY
src/server/ocpp/json/WSConnection.ts
src/server/ocpp/json/WSConnection.ts
@@ -170,11 +170,15 @@ export default abstract class WSConnection {
return this.clientIP;
}
- public async sendError(messageId: string, error: OCPPError): Promise<unknown> {
- return this.sendMessage(messageId, OCPPMessageType.CALL_ERROR_MESSAGE, null, null, error);
+ public async sendResponse(messageID: string, command: Command, response: Record<string, string>): Promise<Record<string, any>> {
+ return this.sendMessage(messageID, OCPPMessageType.CALL_RESULT_MESSAGE, command, response);
}
- public async sendMessage(messageID: string, messageType: OCPPMessageType, command: Command, commandParams: Record<string, unknown>, error?: OCPPError): Promise<unknown> {
+ public async sendError(messageID: string, error: OCPPError): Promise<unknown> {
+ return this.sendMessage(messageID, OCPPMessageType.CALL_ERROR_MESSAGE, null, null, error);
+ }
+
+ public async sendMessage(messageID: string, messageType: OCPPMessageType, command?: Command, data?: Record<string, unknown>, error?: OCPPError): Promise<unknown> {
// Create a promise
return new Promise((resolve, reject) => {
let messageToSend: string;
@@ -196,12 +200,12 @@ export default abstract class WSConnection {
case OCPPMessageType.CALL_MESSAGE:
// Build request
this.ocppRequests[messageID] = [responseCallback, rejectCallback, command];
- messageToSend = JSON.stringify([messageType, messageID, command, commandParams]);
+ messageToSend = JSON.stringify([messageType, messageID, command, data]);
break;
// Response
case OCPPMessageType.CALL_RESULT_MESSAGE:
// Build response
- messageToSend = JSON.stringify([messageType, messageID, commandParams]);
+ messageToSend = JSON.stringify([messageType, messageID, data]);
break;
// Error Message
case OCPPMessageType.CALL_ERROR_MESSAGE:

Added WS sendResponse() method