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
feat: add message buffer flush interval
[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 1b5cf72c2bbd6a76243fa6f8fc7bc68b21648098..0d657d99f7bd67b365660c3e2888653157485e5c 100644
(file)
--- a/
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
+++ b/
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
@@
-2,24
+2,24
@@
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 {
ErrorType,
type IncomingRequestHandler,
import type { ChargingStation } from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
ErrorType,
type IncomingRequestHandler,
- type JsonObject,
type JsonType,
type OCPP20ClearCacheRequest,
OCPP20IncomingRequestCommand,
OCPPVersion,
} from '../../../types';
import { logger } from '../../../utils';
type JsonType,
type OCPP20ClearCacheRequest,
OCPP20IncomingRequestCommand,
OCPPVersion,
} from '../../../types';
import { logger } from '../../../utils';
-import { OCPP
20ServiceUtils, OCPPIncomingRequestService } from '../internal
';
+import { OCPP
IncomingRequestService } from '../OCPPIncomingRequestService
';
const moduleName = 'OCPP20IncomingRequestService';
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
const moduleName = 'OCPP20IncomingRequestService';
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
- protected jsonSchemas: Map<OCPP20IncomingRequestCommand, JSONSchemaType<Json
Object
>>;
+ protected jsonSchemas: Map<OCPP20IncomingRequestCommand, JSONSchemaType<Json
Type
>>;
private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
public constructor() {
private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
public constructor() {
@@
-30,29
+30,33
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
[OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
]);
this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
[OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
]);
- this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<Json
Object
>>([
+ this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<Json
Type
>>([
[
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 (
if (
- chargingStation.
getOcppStrictCompliance()
=== true &&
- chargingStation.i
sI
nPendingState() === true &&
+ chargingStation.
stationInfo?.ocppStrictCompliance
=== true &&
+ chargingStation.inPendingState() === true &&
(commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION ||
commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION)
) {
(commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION ||
commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION)
) {
@@
-60,17
+64,17
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
ErrorType.SECURITY_ERROR,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
ErrorType.SECURITY_ERROR,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
-
null
,
- 2
+
undefined
,
+ 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 ||
);
}
if (
chargingStation.isRegistered() === true ||
- (chargingStation.
getOcppStrictCompliance()
=== false &&
- chargingStation.i
sI
nUnknownState() === true)
+ (chargingStation.
stationInfo?.ocppStrictCompliance
=== false &&
+ chargingStation.inUnknownState() === true)
) {
if (
this.incomingRequestHandlers.has(commandName) === true &&
) {
if (
this.incomingRequestHandlers.has(commandName) === true &&
@@
-79,15
+83,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;
}
@@
-97,11
+101,11
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
ErrorType.NOT_IMPLEMENTED,
`${commandName} is not implemented to handle request PDU ${JSON.stringify(
commandPayload,
ErrorType.NOT_IMPLEMENTED,
`${commandName} is not implemented to handle request PDU ${JSON.stringify(
commandPayload,
-
null
,
- 2
+
undefined
,
+ 2
,
)}`,
commandName,
)}`,
commandName,
- commandPayload
+ commandPayload
,
);
}
} else {
);
}
} else {
@@
-109,11
+113,11
@@
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
ErrorType.SECURITY_ERROR,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
ErrorType.SECURITY_ERROR,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
-
null
,
- 2
+
undefined
,
+ 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
+125,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;
}