import type ChargingStation from './ChargingStation';
import Constants from '../utils/Constants';
+import { MeterValuesResponse } from '../types/ocpp/Responses';
import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils';
import PerformanceStatistics from '../performance/PerformanceStatistics';
import { RequestCommand } from '../types/ocpp/Requests';
this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag;
// Authorize idTag
const authorizeResponse: AuthorizeResponse =
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<AuthorizeResponse>(
RequestCommand.AUTHORIZE,
{
idTag,
}
- )) as AuthorizeResponse;
+ );
this.connectorsStatus.get(connectorId).authorizeRequests++;
if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++;
logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
// Start transaction
- startResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
- RequestCommand.START_TRANSACTION,
- {
- connectorId,
- idTag,
- }
- )) as StartTransactionResponse;
+ startResponse =
+ await this.chargingStation.ocppRequestService.sendMessageHandler<StartTransactionResponse>(
+ RequestCommand.START_TRANSACTION,
+ {
+ connectorId,
+ idTag,
+ }
+ );
PerformanceStatistics.endMeasure(measureId, beginId);
return startResponse;
}
}
logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
// Start transaction
- startResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
- RequestCommand.START_TRANSACTION,
- {
- connectorId,
- idTag,
- }
- )) as StartTransactionResponse;
+ startResponse =
+ await this.chargingStation.ocppRequestService.sendMessageHandler<StartTransactionResponse>(
+ RequestCommand.START_TRANSACTION,
+ {
+ connectorId,
+ idTag,
+ }
+ );
PerformanceStatistics.endMeasure(measureId, beginId);
return startResponse;
}
logger.info(this.logPrefix(connectorId) + ' start transaction without an idTag');
- startResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
- RequestCommand.START_TRANSACTION,
- { connectorId }
- )) as StartTransactionResponse;
+ startResponse =
+ await this.chargingStation.ocppRequestService.sendMessageHandler<StartTransactionResponse>(
+ RequestCommand.START_TRANSACTION,
+ { connectorId }
+ );
PerformanceStatistics.endMeasure(measureId, beginId);
return startResponse;
}
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<MeterValuesResponse>(
RequestCommand.METER_VALUES,
{
connectorId,
}
);
}
- stopResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
- RequestCommand.STOP_TRANSACTION,
- {
- transactionId,
- meterStop:
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- idTag: this.chargingStation.getTransactionIdTag(transactionId),
- reason,
- }
- )) as StopTransactionResponse;
+ stopResponse =
+ await this.chargingStation.ocppRequestService.sendMessageHandler<StopTransactionResponse>(
+ RequestCommand.STOP_TRANSACTION,
+ {
+ transactionId,
+ meterStop:
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ reason,
+ }
+ );
this.connectorsStatus.get(connectorId).stopTransactionRequests++;
} else {
logger.warn(
IncomingRequestCommand,
RequestCommand,
} from '../types/ocpp/Requests';
-import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses';
+import {
+ BootNotificationResponse,
+ HeartbeatResponse,
+ MeterValuesResponse,
+ RegistrationStatus,
+ StatusNotificationResponse,
+} from '../types/ocpp/Responses';
import ChargingStationConfiguration, {
ConfigurationKey,
} from '../types/ChargingStationConfiguration';
VendorDefaultParametersKey,
} from '../types/ocpp/Configuration';
import { MeterValue, MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
+import { StopTransactionReason, StopTransactionResponse } from '../types/ocpp/Transaction';
import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket';
import WebSocket, { ClientOptions, Data, OPEN, RawData } from 'ws';
import { OCPPVersion } from '../types/ocpp/OCPPVersion';
import PerformanceStatistics from '../performance/PerformanceStatistics';
import { SampledValueTemplate } from '../types/MeasurandPerPhaseSampledValueTemplates';
-import { StopTransactionReason } from '../types/ocpp/Transaction';
import { SupervisionUrlDistribution } from '../types/ConfigurationData';
import { URL } from 'url';
import Utils from '../utils/Utils';
) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.heartbeatSetInterval = setInterval(async (): Promise<void> => {
- await this.ocppRequestService.sendMessageHandler(RequestCommand.HEARTBEAT);
+ await this.ocppRequestService.sendMessageHandler<HeartbeatResponse>(
+ RequestCommand.HEARTBEAT
+ );
}, this.getHeartbeatInterval());
logger.info(
this.logPrefix() +
this.getConnectorStatus(connectorId).transactionId,
interval
);
- await this.ocppRequestService.sendMessageHandler(RequestCommand.METER_VALUES, {
- connectorId,
- transactionId: this.getConnectorStatus(connectorId).transactionId,
- meterValue: [meterValue],
- });
+ await this.ocppRequestService.sendMessageHandler<MeterValuesResponse>(
+ RequestCommand.METER_VALUES,
+ {
+ connectorId,
+ transactionId: this.getConnectorStatus(connectorId).transactionId,
+ meterValue: [meterValue],
+ }
+ );
},
interval
);
await this.stopMessageSequence(reason);
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
- await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
- connectorId,
- status: ChargePointStatus.UNAVAILABLE,
- errorCode: ChargePointErrorCode.NO_ERROR,
- });
+ await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
+ RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: ChargePointStatus.UNAVAILABLE,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ }
+ );
this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE;
}
}
// Send BootNotification
let registrationRetryCount = 0;
do {
- this.bootNotificationResponse = (await this.ocppRequestService.sendMessageHandler(
- RequestCommand.BOOT_NOTIFICATION,
- {
- chargePointModel: this.bootNotificationRequest.chargePointModel,
- chargePointVendor: this.bootNotificationRequest.chargePointVendor,
- chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
- firmwareVersion: this.bootNotificationRequest.firmwareVersion,
- chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
- iccid: this.bootNotificationRequest.iccid,
- imsi: this.bootNotificationRequest.imsi,
- meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
- meterType: this.bootNotificationRequest.meterType,
- },
- { skipBufferingOnError: true }
- )) as BootNotificationResponse;
+ this.bootNotificationResponse =
+ await this.ocppRequestService.sendMessageHandler<BootNotificationResponse>(
+ RequestCommand.BOOT_NOTIFICATION,
+ {
+ chargePointModel: this.bootNotificationRequest.chargePointModel,
+ chargePointVendor: this.bootNotificationRequest.chargePointVendor,
+ chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
+ firmwareVersion: this.bootNotificationRequest.firmwareVersion,
+ chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
+ iccid: this.bootNotificationRequest.iccid,
+ imsi: this.bootNotificationRequest.imsi,
+ meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
+ meterType: this.bootNotificationRequest.meterType,
+ },
+ { skipBufferingOnError: true }
+ );
if (!this.isInAcceptedState()) {
this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
await Utils.sleep(
private async startMessageSequence(): Promise<void> {
if (this.stationInfo.autoRegister) {
- await this.ocppRequestService.sendMessageHandler(
+ await this.ocppRequestService.sendMessageHandler<BootNotificationResponse>(
RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel: this.bootNotificationRequest.chargePointModel,
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template at startup
- await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
- connectorId,
- status: this.getConnectorStatus(connectorId).bootStatus,
- errorCode: ChargePointErrorCode.NO_ERROR,
- });
+ await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
+ RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: this.getConnectorStatus(connectorId).bootStatus,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ }
+ );
this.getConnectorStatus(connectorId).status =
this.getConnectorStatus(connectorId).bootStatus;
} else if (
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template after reset
- await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
- connectorId,
- status: this.getConnectorStatus(connectorId).bootStatus,
- errorCode: ChargePointErrorCode.NO_ERROR,
- });
+ await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
+ RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: this.getConnectorStatus(connectorId).bootStatus,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ }
+ );
this.getConnectorStatus(connectorId).status =
this.getConnectorStatus(connectorId).bootStatus;
} else if (!this.stopped && this.getConnectorStatus(connectorId)?.status) {
// Send previous status at template reload
- await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
- connectorId,
- status: this.getConnectorStatus(connectorId).status,
- errorCode: ChargePointErrorCode.NO_ERROR,
- });
+ await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
+ RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: this.getConnectorStatus(connectorId).status,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ }
+ );
} else {
// Send default status
- await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
- connectorId,
- status: ChargePointStatus.AVAILABLE,
- errorCode: ChargePointErrorCode.NO_ERROR,
- });
+ await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
+ RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: ChargePointStatus.AVAILABLE,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ }
+ );
this.getConnectorStatus(connectorId).status = ChargePointStatus.AVAILABLE;
}
}
connectorId,
this.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
- await this.ocppRequestService.sendMessageHandler(RequestCommand.METER_VALUES, {
- connectorId,
- transactionId,
- meterValue: transactionEndMeterValue,
- });
+ await this.ocppRequestService.sendMessageHandler<MeterValuesResponse>(
+ RequestCommand.METER_VALUES,
+ {
+ connectorId,
+ transactionId,
+ meterValue: transactionEndMeterValue,
+ }
+ );
}
- await this.ocppRequestService.sendMessageHandler(RequestCommand.STOP_TRANSACTION, {
- transactionId,
- meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId),
- idTag: this.getTransactionIdTag(transactionId),
- reason,
- });
+ await this.ocppRequestService.sendMessageHandler<StopTransactionResponse>(
+ RequestCommand.STOP_TRANSACTION,
+ {
+ transactionId,
+ meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.getTransactionIdTag(transactionId),
+ reason,
+ }
+ );
}
}
}
ChangeAvailabilityResponse,
ChangeConfigurationResponse,
ClearChargingProfileResponse,
+ DiagnosticsStatusNotificationResponse,
GetConfigurationResponse,
GetDiagnosticsResponse,
+ OCPP16BootNotificationResponse,
+ OCPP16HeartbeatResponse,
+ OCPP16StatusNotificationResponse,
OCPP16TriggerMessageResponse,
SetChargingProfileResponse,
UnlockConnectorResponse,
import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
+import { OCPP16MeterValuesResponse } from '../../../types/ocpp/1.6/MeterValues';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
OCPP16RequestCommand.METER_VALUES,
{
connectorId,
}
);
}
- const stopResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
- OCPP16RequestCommand.STOP_TRANSACTION,
- {
- transactionId,
- meterStop:
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- idTag: this.chargingStation.getTransactionIdTag(transactionId),
- reason: OCPP16StopTransactionReason.UNLOCK_COMMAND,
- }
- )) as OCPP16StopTransactionResponse;
+ const stopResponse =
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StopTransactionResponse>(
+ OCPP16RequestCommand.STOP_TRANSACTION,
+ {
+ transactionId,
+ meterStop:
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ reason: OCPP16StopTransactionReason.UNLOCK_COMMAND,
+ }
+ );
if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
return Constants.OCPP_RESPONSE_UNLOCKED;
}
return Constants.OCPP_RESPONSE_UNLOCK_FAILED;
}
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId,
}
this.chargingStation.getConnectorStatus(id).availability = commandPayload.type;
if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId: id,
return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{ connectorId, status: chargePointStatus, errorCode: OCPP16ChargePointErrorCode.NO_ERROR }
);
const transactionConnectorId = commandPayload.connectorId;
const connectorStatus = this.chargingStation.getConnectorStatus(transactionConnectorId);
if (transactionConnectorId) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId: transactionConnectorId,
} else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) {
connectorStatus.authorizeIdTag = commandPayload.idTag;
const authorizeResponse: OCPP16AuthorizeResponse =
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16AuthorizeResponse>(
OCPP16RequestCommand.AUTHORIZE,
{
idTag: commandPayload.idTag,
}
- )) as OCPP16AuthorizeResponse;
+ );
if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
authorized = true;
}
connectorStatus.transactionRemoteStarted = true;
if (
(
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StartTransactionResponse>(
OCPP16RequestCommand.START_TRANSACTION,
{
connectorId: transactionConnectorId,
idTag: commandPayload.idTag,
}
- )) as OCPP16StartTransactionResponse
+ )
).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
) {
logger.debug(
connectorStatus.transactionRemoteStarted = true;
if (
(
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StartTransactionResponse>(
OCPP16RequestCommand.START_TRANSACTION,
{
connectorId: transactionConnectorId,
idTag: commandPayload.idTag,
}
- )) as OCPP16StartTransactionResponse
+ )
).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
) {
logger.debug(
this.chargingStation.getConnectorStatus(connectorId).status !==
OCPP16ChargePointStatus.AVAILABLE
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId,
connectorId > 0 &&
this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId,
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
OCPP16RequestCommand.METER_VALUES,
{
connectorId,
}
);
}
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StopTransactionResponse>(
OCPP16RequestCommand.STOP_TRANSACTION,
{
transactionId,
info.bytes / 1024
} bytes transferred from diagnostics archive ${info.name}`
);
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
{
status: OCPP16DiagnosticsStatus.Uploading,
uri.pathname + diagnosticsArchive
);
if (uploadResponse.code === 226) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
{
status: OCPP16DiagnosticsStatus.Uploaded,
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
);
} catch (error) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
{
status: OCPP16DiagnosticsStatus.UploadFailed,
uri.protocol
} to transfer the diagnostic logs archive`
);
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
{
status: OCPP16DiagnosticsStatus.UploadFailed,
case MessageTrigger.BootNotification:
setTimeout(() => {
this.chargingStation.ocppRequestService
- .sendMessageHandler(
+ .sendMessageHandler<OCPP16BootNotificationResponse>(
OCPP16RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel:
case MessageTrigger.Heartbeat:
setTimeout(() => {
this.chargingStation.ocppRequestService
- .sendMessageHandler(OCPP16RequestCommand.HEARTBEAT, null, { triggerMessage: true })
+ .sendMessageHandler<OCPP16HeartbeatResponse>(OCPP16RequestCommand.HEARTBEAT, null, {
+ triggerMessage: true,
+ })
.catch(() => {
/* This is intentional */
});
// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
-import {
- AuthorizeRequest,
- StartTransactionRequest,
- StopTransactionRequest,
-} from '../../../types/ocpp/1.6/Transaction';
-import {
- DiagnosticsStatusNotificationRequest,
- HeartbeatRequest,
- OCPP16BootNotificationRequest,
- OCPP16RequestCommand,
- StatusNotificationRequest,
-} from '../../../types/ocpp/1.6/Requests';
-import { ResponseType, SendParams } from '../../../types/ocpp/Requests';
-
import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { JsonType } from '../../../types/JsonType';
-import { MeterValuesRequest } from '../../../types/ocpp/1.6/MeterValues';
+import { OCPP16RequestCommand } from '../../../types/ocpp/1.6/Requests';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
import OCPPError from '../../../exception/OCPPError';
import OCPPRequestService from '../OCPPRequestService';
import type OCPPResponseService from '../OCPPResponseService';
+import { SendParams } from '../../../types/ocpp/Requests';
import Utils from '../../../utils/Utils';
const moduleName = 'OCPP16RequestService';
super(chargingStation, ocppResponseService);
}
- public async sendMessageHandler(
+ public async sendMessageHandler<Response extends JsonType>(
commandName: OCPP16RequestCommand,
commandParams?: JsonType,
params?: SendParams
- ): Promise<ResponseType> {
+ ): Promise<Response> {
if (Object.values(OCPP16RequestCommand).includes(commandName)) {
- return this.sendMessage(
+ return (await this.sendMessage(
Utils.generateUUID(),
this.buildCommandPayload(commandName, commandParams),
commandName,
params
- );
+ )) as unknown as Response;
}
throw new OCPPError(
ErrorType.NOT_SUPPORTED,
);
}
- private buildCommandPayload(
+ private buildCommandPayload<Request extends JsonType>(
commandName: OCPP16RequestCommand,
commandParams?: JsonType
- ): JsonType {
+ ): Request {
let connectorId: number;
switch (commandName) {
case OCPP16RequestCommand.AUTHORIZE:
...(!Utils.isUndefined(commandParams?.idTag)
? { idTag: commandParams.idTag }
: { idTag: Constants.DEFAULT_IDTAG }),
- } as AuthorizeRequest;
+ } as unknown as Request;
case OCPP16RequestCommand.BOOT_NOTIFICATION:
return {
chargePointModel: commandParams?.chargePointModel,
...(!Utils.isUndefined(commandParams?.meterType) && {
meterType: commandParams.meterType,
}),
- } as OCPP16BootNotificationRequest;
+ } as unknown as Request;
case OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION:
return {
status: commandParams?.diagnosticsStatus,
- } as DiagnosticsStatusNotificationRequest;
+ } as unknown as Request;
case OCPP16RequestCommand.HEARTBEAT:
- return {} as HeartbeatRequest;
+ return {} as unknown as Request;
case OCPP16RequestCommand.METER_VALUES:
return {
connectorId: commandParams?.connectorId,
meterValue: Array.isArray(commandParams?.meterValue)
? commandParams?.meterValue
: [commandParams?.meterValue],
- } as MeterValuesRequest;
+ } as unknown as Request;
case OCPP16RequestCommand.STATUS_NOTIFICATION:
return {
connectorId: commandParams?.connectorId,
status: commandParams?.status,
errorCode: commandParams?.errorCode,
- } as StatusNotificationRequest;
+ } as unknown as Request;
case OCPP16RequestCommand.START_TRANSACTION:
return {
connectorId: commandParams?.connectorId,
commandParams?.connectorId as number
),
timestamp: new Date().toISOString(),
- } as StartTransactionRequest;
+ } as unknown as Request;
case OCPP16RequestCommand.STOP_TRANSACTION:
connectorId = this.chargingStation.getConnectorIdByTransactionId(
commandParams?.transactionId as number
)
),
}),
- } as StopTransactionRequest;
+ } as unknown as Request;
default:
throw new OCPPError(
ErrorType.NOT_SUPPORTED,
OCPP16RequestCommand,
StatusNotificationRequest,
} from '../../../types/ocpp/1.6/Requests';
+import { MeterValuesRequest, OCPP16MeterValuesResponse } from '../../../types/ocpp/1.6/MeterValues';
import {
- HeartbeatResponse,
OCPP16BootNotificationResponse,
+ OCPP16HeartbeatResponse,
OCPP16RegistrationStatus,
- StatusNotificationResponse,
+ OCPP16StatusNotificationResponse,
} from '../../../types/ocpp/1.6/Responses';
-import { MeterValuesRequest, MeterValuesResponse } from '../../../types/ocpp/1.6/MeterValues';
import type ChargingStation from '../../ChargingStation';
import { ErrorType } from '../../../types/ocpp/ErrorType';
}
private handleResponseHeartbeat(
- payload: HeartbeatResponse,
+ payload: OCPP16HeartbeatResponse,
requestPayload: HeartbeatRequest
): void {
logger.debug(
requestPayload.meterStart
);
this.chargingStation.getBeginEndMeterValues() &&
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ (await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
OCPP16RequestCommand.METER_VALUES,
{
connectorId,
this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
}
));
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId,
this.chargingStation.getConnectorStatus(connectorId).status !==
OCPP16ChargePointStatus.AVAILABLE
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId,
this.chargingStation.getBeginEndMeterValues() &&
!this.chargingStation.getOcppStrictCompliance() &&
this.chargingStation.getOutOfOrderEndMeterValues() &&
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ (await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
OCPP16RequestCommand.METER_VALUES,
{
connectorId: transactionConnectorId,
!this.chargingStation.isChargingStationAvailable() ||
!this.chargingStation.isConnectorAvailable(transactionConnectorId)
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId: transactionConnectorId,
this.chargingStation.getConnectorStatus(transactionConnectorId).status =
OCPP16ChargePointStatus.UNAVAILABLE;
} else {
- await this.chargingStation.ocppRequestService.sendMessageHandler(
+ await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16BootNotificationResponse>(
OCPP16RequestCommand.STATUS_NOTIFICATION,
{
connectorId: transactionConnectorId,
private handleResponseStatusNotification(
payload: StatusNotificationRequest,
- requestPayload: StatusNotificationResponse
+ requestPayload: OCPP16StatusNotificationResponse
): void {
logger.debug(
this.chargingStation.logPrefix() +
private handleResponseMeterValues(
payload: MeterValuesRequest,
- requestPayload: MeterValuesResponse
+ requestPayload: OCPP16MeterValuesResponse
): void {
logger.debug(
this.chargingStation.logPrefix() +
}
}
- public abstract sendMessageHandler(
+ public abstract sendMessageHandler<Response extends JsonType>(
commandName: RequestCommand,
commandParams?: JsonType,
params?: SendParams
- ): Promise<ResponseType>;
+ ): Promise<Response>;
}
meterValue: OCPP16MeterValue[];
}
-export type MeterValuesResponse = EmptyObject;
+export type OCPP16MeterValuesResponse = EmptyObject;
import { JsonType } from '../../JsonType';
import { OCPPConfigurationKey } from '../Configuration';
-export interface HeartbeatResponse extends JsonType {
+export interface OCPP16HeartbeatResponse extends JsonType {
currentTime: string;
}
interval: number;
}
-export type StatusNotificationResponse = EmptyObject;
+export type OCPP16StatusNotificationResponse = EmptyObject;
export interface GetConfigurationResponse extends JsonType {
configurationKey: OCPPConfigurationKey[];
OCPP16ChargingProfileStatus,
OCPP16ClearChargingProfileStatus,
OCPP16ConfigurationStatus,
+ OCPP16HeartbeatResponse,
OCPP16RegistrationStatus,
+ OCPP16StatusNotificationResponse,
OCPP16TriggerMessageStatus,
OCPP16UnlockStatus,
} from './1.6/Responses';
import { JsonType } from '../JsonType';
+import { OCPP16MeterValuesResponse } from './1.6/MeterValues';
export type ResponseHandler = (
payload: JsonType | string,
export type BootNotificationResponse = OCPP16BootNotificationResponse;
+export type HeartbeatResponse = OCPP16HeartbeatResponse;
+
+export type StatusNotificationResponse = OCPP16StatusNotificationResponse;
+
+export type MeterValuesResponse = OCPP16MeterValuesResponse;
+
export enum DefaultStatus {
ACCEPTED = 'Accepted',
REJECTED = 'Rejected',