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
docs: refine README.md
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
OCPPIncomingRequestService.ts
diff --git
a/src/charging-station/ocpp/OCPPIncomingRequestService.ts
b/src/charging-station/ocpp/OCPPIncomingRequestService.ts
index 1206cede00d0493df941f54e73dc03cffedfc28c..b7ab8ef66382b1ac0e799294eccca7f676480855 100644
(file)
--- a/
src/charging-station/ocpp/OCPPIncomingRequestService.ts
+++ b/
src/charging-station/ocpp/OCPPIncomingRequestService.ts
@@
-5,7
+5,7
@@
import ajvFormats from 'ajv-formats';
import { OCPPConstants } from './OCPPConstants';
import { OCPPServiceUtils } from './OCPPServiceUtils';
import { OCPPConstants } from './OCPPConstants';
import { OCPPServiceUtils } from './OCPPServiceUtils';
-import { type ChargingStation,
ChargingStationUtils
} from '../../charging-station';
+import { type ChargingStation,
getIdTagsFile
} from '../../charging-station';
import { OCPPError } from '../../exception';
import type {
ClearCacheResponse,
import { OCPPError } from '../../exception';
import type {
ClearCacheResponse,
@@
-15,7
+15,7
@@
import type {
JsonType,
OCPPVersion,
} from '../../types';
JsonType,
OCPPVersion,
} from '../../types';
-import {
ErrorUtils, logger
} from '../../utils';
+import {
logger, setDefaultErrorParams
} from '../../utils';
const moduleName = 'OCPPIncomingRequestService';
const moduleName = 'OCPPIncomingRequestService';
@@
-33,19
+33,23
@@
export abstract class OCPPIncomingRequestService extends AsyncResource {
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
- this.incomingRequestHandler = this.incomingRequestHandler.bind(this) as (
+ this.incomingRequestHandler = this.incomingRequestHandler.bind(this) as <
+ ReqType extends JsonType,
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ ResType extends JsonType,
+ >(
chargingStation: ChargingStation,
messageId: string,
commandName: IncomingRequestCommand,
chargingStation: ChargingStation,
messageId: string,
commandName: IncomingRequestCommand,
- commandPayload:
JsonType
+ commandPayload:
ReqType,
) => Promise<void>;
this.validateIncomingRequestPayload = this.validateIncomingRequestPayload.bind(this) as <
) => Promise<void>;
this.validateIncomingRequestPayload = this.validateIncomingRequestPayload.bind(this) as <
- T extends JsonType
+ T extends JsonType
,
>(
chargingStation: ChargingStation,
commandName: IncomingRequestCommand,
schema: JSONSchemaType<T>,
>(
chargingStation: ChargingStation,
commandName: IncomingRequestCommand,
schema: JSONSchemaType<T>,
- payload: T
+ payload: T
,
) => boolean;
}
) => boolean;
}
@@
-60,12
+64,12
@@
export abstract class OCPPIncomingRequestService extends AsyncResource {
chargingStation: ChargingStation,
commandName: IncomingRequestCommand,
error: Error,
chargingStation: ChargingStation,
commandName: IncomingRequestCommand,
error: Error,
- params: HandleErrorParams<T> = { throwError: true, consoleOut: false }
+ params: HandleErrorParams<T> = { throwError: true, consoleOut: false }
,
): T | undefined {
): T | undefined {
-
ErrorUtils.handle
ErrorParams(params);
+
setDefault
ErrorParams(params);
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
- error
+ error
,
);
if (!params?.throwError && params?.errorResponse) {
return params?.errorResponse;
);
if (!params?.throwError && params?.errorResponse) {
return params?.errorResponse;
@@
-82,9
+86,9
@@
export abstract class OCPPIncomingRequestService extends AsyncResource {
chargingStation: ChargingStation,
commandName: IncomingRequestCommand,
schema: JSONSchemaType<T>,
chargingStation: ChargingStation,
commandName: IncomingRequestCommand,
schema: JSONSchemaType<T>,
- payload: T
+ payload: T
,
): boolean {
): boolean {
- if (chargingStation.get
PayloadSchemaValidation
() === false) {
+ if (chargingStation.get
OcppStrictCompliance
() === false) {
return true;
}
const validate = this.ajv.compile(schema);
return true;
}
const validate = this.ajv.compile(schema);
@@
-93,27
+97,28
@@
export abstract class OCPPIncomingRequestService extends AsyncResource {
}
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.validateIncomingRequestPayload: Command '${commandName}' incoming request PDU is invalid: %j`,
}
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.validateIncomingRequestPayload: Command '${commandName}' incoming request PDU is invalid: %j`,
- validate.errors
+ validate.errors
,
);
throw new OCPPError(
);
throw new OCPPError(
- OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors
!
),
'Incoming request PDU is invalid',
commandName,
'Incoming request PDU is invalid',
commandName,
- JSON.stringify(validate.errors, null, 2)
+ JSON.stringify(validate.errors, null, 2)
,
);
}
protected handleRequestClearCache(chargingStation: ChargingStation): ClearCacheResponse {
);
}
protected handleRequestClearCache(chargingStation: ChargingStation): ClearCacheResponse {
- chargingStation.idTagsCache.deleteIdTags(
- ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo)
- );
- return OCPPConstants.OCPP_RESPONSE_
ACCEP
TED;
+ if (chargingStation.idTagsCache.deleteIdTags(getIdTagsFile(chargingStation.stationInfo)!)) {
+ return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
+ }
+ return OCPPConstants.OCPP_RESPONSE_
REJEC
TED;
}
}
- public abstract incomingRequestHandler(
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ public abstract incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
messageId: string,
commandName: IncomingRequestCommand,
chargingStation: ChargingStation,
messageId: string,
commandName: IncomingRequestCommand,
- commandPayload:
JsonType
+ commandPayload:
ReqType,
): Promise<void>;
}
): Promise<void>;
}