From 22e0d48e12052aaa7ed3f76fc59cac779ae67a5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 9 Jan 2023 22:03:39 +0100 Subject: [PATCH] Factor out some common code between OCPP 1.6 and 2.0.1 stack MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 7 ------- src/charging-station/ocpp/1.6/OCPP16RequestService.ts | 5 +---- .../ocpp/2.0/OCPP20IncomingRequestService.ts | 10 ---------- .../ocpp/OCPPIncomingRequestService.ts | 10 ++++++++++ src/types/ocpp/Responses.ts | 4 +++- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 0df0954f..9e0849e9 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -438,13 +438,6 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer return OCPPConstants.OCPP_RESPONSE_ACCEPTED; } - private handleRequestClearCache(chargingStation: ChargingStation): DefaultResponse { - chargingStation.authorizedTagsCache.deleteAuthorizedTags( - ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo) - ); - return OCPPConstants.OCPP_RESPONSE_ACCEPTED; - } - private async handleRequestUnlockConnector( chargingStation: ChargingStation, commandPayload: UnlockConnectorRequest diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 3c72faf2..3a38f02a 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -235,6 +235,7 @@ export default class OCPP16RequestService extends OCPPRequestService { }), } as unknown as Request; case OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION: + case OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION: return { status: commandParams?.status, } as unknown as Request; @@ -294,10 +295,6 @@ export default class OCPP16RequestService extends OCPPRequestService { } as unknown as Request; case OCPP16RequestCommand.DATA_TRANSFER: return commandParams as unknown as Request; - case OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION: - return { - status: commandParams?.status, - } as unknown as Request; default: // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError(). throw new OCPPError( diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index c3a241d4..ed4f1fe1 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -12,14 +12,11 @@ import { OCPP20ClearCacheRequest, OCPP20IncomingRequestCommand, } from '../../../types/ocpp/2.0/Requests'; -import type { OCPP20ClearCacheResponse } from '../../../types/ocpp/2.0/Responses'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; import type { IncomingRequestHandler } from '../../../types/ocpp/Requests'; import logger from '../../../utils/Logger'; import type ChargingStation from '../../ChargingStation'; -import { ChargingStationUtils } from '../../ChargingStationUtils'; -import OCPPConstants from '../OCPPConstants'; import OCPPIncomingRequestService from '../OCPPIncomingRequestService'; import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; @@ -154,11 +151,4 @@ export default class OCPP20IncomingRequestService extends OCPPIncomingRequestSer ); return false; } - - private handleRequestClearCache(chargingStation: ChargingStation): OCPP20ClearCacheResponse { - chargingStation.authorizedTagsCache.deleteAuthorizedTags( - ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo) - ); - return OCPPConstants.OCPP_RESPONSE_ACCEPTED; - } } diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 4b8c40f8..876e71d8 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -8,8 +8,11 @@ import type { HandleErrorParams } from '../../types/Error'; import type { JsonObject, JsonType } from '../../types/JsonType'; import type { OCPPVersion } from '../../types/ocpp/OCPPVersion'; import type { IncomingRequestCommand } from '../../types/ocpp/Requests'; +import type { ClearCacheResponse } from '../../types/ocpp/Responses'; import logger from '../../utils/Logger'; import type ChargingStation from '../ChargingStation'; +import { ChargingStationUtils } from '../ChargingStationUtils'; +import OCPPConstants from './OCPPConstants'; import { OCPPServiceUtils } from './OCPPServiceUtils'; const moduleName = 'OCPPIncomingRequestService'; @@ -86,6 +89,13 @@ export default abstract class OCPPIncomingRequestService { ); } + protected handleRequestClearCache(chargingStation: ChargingStation): ClearCacheResponse { + chargingStation.authorizedTagsCache.deleteAuthorizedTags( + ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo) + ); + return OCPPConstants.OCPP_RESPONSE_ACCEPTED; + } + public abstract incomingRequestHandler( chargingStation: ChargingStation, messageId: string, diff --git a/src/types/ocpp/Responses.ts b/src/types/ocpp/Responses.ts index c2b1f53a..90c5f1ea 100644 --- a/src/types/ocpp/Responses.ts +++ b/src/types/ocpp/Responses.ts @@ -16,7 +16,7 @@ import { OCPP16TriggerMessageStatus, OCPP16UnlockStatus, } from './1.6/Responses'; -import type { OCPP20BootNotificationResponse } from './2.0/Responses'; +import type { OCPP20BootNotificationResponse, OCPP20ClearCacheResponse } from './2.0/Responses'; import type { ErrorType } from './ErrorType'; import type { MessageType } from './MessageType'; @@ -36,6 +36,8 @@ export type BootNotificationResponse = export type HeartbeatResponse = OCPP16HeartbeatResponse; +export type ClearCacheResponse = DefaultResponse | OCPP20ClearCacheResponse; + export type StatusNotificationResponse = OCPP16StatusNotificationResponse; export type MeterValuesResponse = OCPP16MeterValuesResponse; -- 2.34.1