1 import type ChargingStation from
'../ChargingStation';
2 import { HandleErrorParams
} from
'../../types/Error';
3 import { IncomingRequestCommand
} from
'../../types/ocpp/Requests';
4 import { JsonType
} from
'../../types/JsonType';
5 import logger from
'../../utils/Logger';
7 export default abstract class OCPPIncomingRequestService
{
8 private static instance
: OCPPIncomingRequestService
| null = null;
10 protected constructor() {
11 // This is intentional
14 public static getInstance
<T
extends OCPPIncomingRequestService
>(this: new () => T
): T
{
15 if (!OCPPIncomingRequestService
.instance
) {
16 OCPPIncomingRequestService
.instance
= new this();
18 return OCPPIncomingRequestService
.instance
as T
;
21 protected handleIncomingRequestError
<T
>(
22 chargingStation
: ChargingStation
,
23 commandName
: IncomingRequestCommand
,
25 params
: HandleErrorParams
<T
> = { throwError
: true }
28 chargingStation
.logPrefix() + ' Incoming request command %s error: %j',
32 if (!params
?.throwError
&& params
?.errorResponse
) {
33 return params
?.errorResponse
;
35 if (params
?.throwError
&& !params
?.errorResponse
) {
38 if (params
?.throwError
&& params
?.errorResponse
) {
39 return params
?.errorResponse
;
43 public abstract incomingRequestHandler(
44 chargingStation
: ChargingStation
,
46 commandName
: IncomingRequestCommand
,
47 commandPayload
: JsonType