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
Hook the OCPP 2.0 stack into the main code
[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 29c740a187310d11fe5a0dedf4ea3e05de8d016c..125baf4073366623f05c67797d6e375ef532f148 100644
(file)
--- a/
src/charging-station/ocpp/OCPPRequestService.ts
+++ b/
src/charging-station/ocpp/OCPPRequestService.ts
@@
-10,11
+10,13
@@
import type { JsonObject, JsonType } from '../../types/JsonType';
import { ErrorType } from '../../types/ocpp/ErrorType';
import { MessageType } from '../../types/ocpp/MessageType';
import {
import { ErrorType } from '../../types/ocpp/ErrorType';
import { MessageType } from '../../types/ocpp/MessageType';
import {
- IncomingRequestCommand,
- OutgoingRequest,
+ type ErrorCallback,
+ type IncomingRequestCommand,
+ type OutgoingRequest,
RequestCommand,
RequestCommand,
- RequestParams,
- ResponseType,
+ type RequestParams,
+ type ResponseCallback,
+ type ResponseType,
} from '../../types/ocpp/Requests';
import type { ErrorResponse, Response } from '../../types/ocpp/Responses';
import Constants from '../../utils/Constants';
} from '../../types/ocpp/Requests';
import type { ErrorResponse, Response } from '../../types/ocpp/Responses';
import Constants from '../../utils/Constants';
@@
-187,10
+189,10
@@
export default abstract class OCPPRequestService {
// Check if wsConnection opened
if (chargingStation.isWebSocketConnectionOpened() === true) {
// Yes: Send Message
// Check if wsConnection opened
if (chargingStation.isWebSocketConnectionOpened() === true) {
// Yes: Send Message
- const beginId = PerformanceStatistics.beginMeasure(commandName);
+ const beginId = PerformanceStatistics.beginMeasure(commandName
as string
);
// FIXME: Handle sending error
chargingStation.wsConnection.send(messageToSend);
// FIXME: Handle sending error
chargingStation.wsConnection.send(messageToSend);
- PerformanceStatistics.endMeasure(commandName, beginId);
+ PerformanceStatistics.endMeasure(commandName
as string
, beginId);
logger.debug(
`${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
messageType
logger.debug(
`${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
messageType
@@
-231,13
+233,10
@@
export default abstract class OCPPRequestService {
/**
* Function that will receive the request's response
*
/**
* Function that will receive the request's response
*
- * @param payload
- * @param requestPayload
+ * @param payload
-
+ * @param requestPayload
-
*/
*/
- async function responseCallback(
- payload: JsonType,
- requestPayload: JsonType
- ): Promise<void> {
+ function responseCallback(payload: JsonType, requestPayload: JsonType): void {
if (chargingStation.getEnableStatistics() === true) {
chargingStation.performanceStatistics.addRequestStatistic(
commandName,
if (chargingStation.getEnableStatistics() === true) {
chargingStation.performanceStatistics.addRequestStatistic(
commandName,
@@
-245,26
+244,29
@@
export default abstract class OCPPRequestService {
);
}
// Handle the request's response
);
}
// Handle the request's response
- try {
-
await self.ocppResponseService
.responseHandler(
+ self.ocppResponseService
+ .responseHandler(
chargingStation,
commandName as RequestCommand,
payload,
requestPayload
chargingStation,
commandName as RequestCommand,
payload,
requestPayload
- );
- resolve(payload);
- } catch (error) {
- reject(error);
- } finally {
- chargingStation.requests.delete(messageId);
- }
+ )
+ .then(() => {
+ resolve(payload);
+ })
+ .catch((error) => {
+ reject(error);
+ })
+ .finally(() => {
+ chargingStation.requests.delete(messageId);
+ });
}
/**
* Function that will receive the request's error response
*
}
/**
* Function that will receive the request's error response
*
- * @param error
- * @param requestStatistic
+ * @param error
-
+ * @param requestStatistic
-
*/
function errorCallback(error: OCPPError, requestStatistic = true): void {
if (requestStatistic === true && chargingStation.getEnableStatistics() === true) {
*/
function errorCallback(error: OCPPError, requestStatistic = true): void {
if (requestStatistic === true && chargingStation.getEnableStatistics() === true) {
@@
-308,8
+310,8
@@
export default abstract class OCPPRequestService {
messagePayload: JsonType | OCPPError,
messageType: MessageType,
commandName?: RequestCommand | IncomingRequestCommand,
messagePayload: JsonType | OCPPError,
messageType: MessageType,
commandName?: RequestCommand | IncomingRequestCommand,
- responseCallback?:
(payload: JsonType, requestPayload: JsonType) => Promise<void>
,
- errorCallback?:
(error: OCPPError, requestStatistic?: boolean) => void
+ responseCallback?:
ResponseCallback
,
+ errorCallback?:
ErrorCallback
): string {
let messageToSend: string;
// Type of message
): string {
let messageToSend: string;
// Type of message
@@
-374,10
+376,10
@@
export default abstract class OCPPRequestService {
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- public abstract requestHandler<Req
uestType extends JsonType, Response
Type extends JsonType>(
+ public abstract requestHandler<Req
Type extends JsonType, Res
Type extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand,
commandParams?: JsonType,
params?: RequestParams
chargingStation: ChargingStation,
commandName: RequestCommand,
commandParams?: JsonType,
params?: RequestParams
- ): Promise<Res
ponse
Type>;
+ ): Promise<ResType>;
}
}