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
fix: avoid worker-threads restart at error during startup
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
2.0
/
OCPP20IncomingRequestService.ts
diff --git
a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
index 1c70027293887f8f06d5f6063b44784bcbdcf630..bda78d54f3147f5eb621ae5108836c34eea8ee6d 100644
(file)
--- a/
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
+++ b/
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
@@
-2,6
+2,7
@@
import type { JSONSchemaType } from 'ajv';
import type { JSONSchemaType } from 'ajv';
+import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
import type { ChargingStation } from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
import type { ChargingStation } from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
@@
-13,8
+14,8
@@
import {
OCPP20IncomingRequestCommand,
OCPPVersion,
} from '../../../types';
OCPP20IncomingRequestCommand,
OCPPVersion,
} from '../../../types';
-import { logger } from '../../../utils
/Logger
';
-import { OCPP
20ServiceUtils, OCPPIncomingRequestService } from '../internal
';
+import { logger } from '../../../utils';
+import { OCPP
IncomingRequestService } from '../OCPPIncomingRequestService
';
const moduleName = 'OCPP20IncomingRequestService';
const moduleName = 'OCPP20IncomingRequestService';
@@
-23,9
+24,9
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
public constructor() {
private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
public constructor() {
- if (new.target?.name === moduleName) {
- throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
- }
+
//
if (new.target?.name === moduleName) {
+
//
throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+
//
}
super(OCPPVersion.VERSION_20);
this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
[OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
super(OCPPVersion.VERSION_20);
this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
[OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
@@
-34,25
+35,29
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
- '
../../../
assets/json-schemas/ocpp/2.0/ClearCacheRequest.json',
+ 'assets/json-schemas/ocpp/2.0/ClearCacheRequest.json',
moduleName,
moduleName,
- 'constructor'
+ 'constructor'
,
),
],
]);
),
],
]);
- this.validatePayload.bind(this);
+ this.validatePayload = this.validatePayload.bind(this) as (
+ chargingStation: ChargingStation,
+ commandName: OCPP20IncomingRequestCommand,
+ commandPayload: JsonType,
+ ) => boolean;
}
}
- public async incomingRequestHandler(
+ public async incomingRequestHandler
<ReqType extends JsonType, ResType extends JsonType>
(
chargingStation: ChargingStation,
messageId: string,
commandName: OCPP20IncomingRequestCommand,
chargingStation: ChargingStation,
messageId: string,
commandName: OCPP20IncomingRequestCommand,
- commandPayload:
JsonType
+ commandPayload:
ReqType,
): Promise<void> {
): Promise<void> {
- let response:
Json
Type;
+ let response:
Res
Type;
if (
chargingStation.getOcppStrictCompliance() === true &&
if (
chargingStation.getOcppStrictCompliance() === true &&
- chargingStation.i
sI
nPendingState() === true &&
+ chargingStation.inPendingState() === true &&
(commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION ||
commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION)
) {
(commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION ||
commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION)
) {
@@
-61,16
+66,16
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
null,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
null,
- 2
+ 2
,
)} while the charging station is in pending state on the central server`,
commandName,
)} while the charging station is in pending state on the central server`,
commandName,
- commandPayload
+ commandPayload
,
);
}
if (
chargingStation.isRegistered() === true ||
(chargingStation.getOcppStrictCompliance() === false &&
);
}
if (
chargingStation.isRegistered() === true ||
(chargingStation.getOcppStrictCompliance() === false &&
- chargingStation.i
sI
nUnknownState() === true)
+ chargingStation.inUnknownState() === true)
) {
if (
this.incomingRequestHandlers.has(commandName) === true &&
) {
if (
this.incomingRequestHandlers.has(commandName) === true &&
@@
-79,15
+84,15
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
try {
this.validatePayload(chargingStation, commandName, commandPayload);
// Call the method to build the response
try {
this.validatePayload(chargingStation, commandName, commandPayload);
// Call the method to build the response
- response =
await this.incomingRequestHandlers.get(commandName)
(
+ response =
(await this.incomingRequestHandlers.get(commandName)!
(
chargingStation,
chargingStation,
- commandPayload
- );
+ commandPayload
,
+ )
) as ResType
;
} catch (error) {
// Log
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: Handle incoming request error:`,
} catch (error) {
// Log
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: Handle incoming request error:`,
- error
+ error
,
);
throw error;
}
);
throw error;
}
@@
-98,10
+103,10
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
`${commandName} is not implemented to handle request PDU ${JSON.stringify(
commandPayload,
null,
`${commandName} is not implemented to handle request PDU ${JSON.stringify(
commandPayload,
null,
- 2
+ 2
,
)}`,
commandName,
)}`,
commandName,
- commandPayload
+ commandPayload
,
);
}
} else {
);
}
} else {
@@
-110,10
+115,10
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
null,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
null,
- 2
+ 2
,
)} while the charging station is not registered on the central server.`,
commandName,
)} while the charging station is not registered on the central server.`,
commandName,
- commandPayload
+ commandPayload
,
);
}
// Send the built response
);
}
// Send the built response
@@
-121,25
+126,25
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
chargingStation,
messageId,
response,
chargingStation,
messageId,
response,
- commandName
+ commandName
,
);
}
private validatePayload(
chargingStation: ChargingStation,
commandName: OCPP20IncomingRequestCommand,
);
}
private validatePayload(
chargingStation: ChargingStation,
commandName: OCPP20IncomingRequestCommand,
- commandPayload: JsonType
+ commandPayload: JsonType
,
): boolean {
if (this.jsonSchemas.has(commandName) === true) {
return this.validateIncomingRequestPayload(
chargingStation,
commandName,
): boolean {
if (this.jsonSchemas.has(commandName) === true) {
return this.validateIncomingRequestPayload(
chargingStation,
commandName,
- this.jsonSchemas.get(commandName),
- commandPayload
+ this.jsonSchemas.get(commandName)
!
,
+ commandPayload
,
);
}
logger.warn(
);
}
logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command '${commandName}' PDU validation`
+ `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command '${commandName}' PDU validation`
,
);
return false;
}
);
return false;
}