import {
AuthorizationStatus,
+ AuthorizeRequest,
AuthorizeResponse,
+ StartTransactionRequest,
StartTransactionResponse,
StopTransactionReason,
+ StopTransactionRequest,
StopTransactionResponse,
} from '../types/ocpp/Transaction';
+import { MeterValuesRequest, RequestCommand } from '../types/ocpp/Requests';
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';
import { Status } from '../types/AutomaticTransactionGenerator';
import Utils from '../utils/Utils';
import logger from '../utils/Logger';
this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag;
// Authorize idTag
const authorizeResponse: AuthorizeResponse =
- await this.chargingStation.ocppRequestService.sendMessageHandler<AuthorizeResponse>(
- RequestCommand.AUTHORIZE,
- {
- idTag,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ AuthorizeRequest,
+ AuthorizeResponse
+ >(RequestCommand.AUTHORIZE, {
+ idTag,
+ });
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<StartTransactionResponse>(
- RequestCommand.START_TRANSACTION,
- {
- connectorId,
- idTag,
- }
- );
+ startResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
+ StartTransactionRequest,
+ 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<StartTransactionResponse>(
- RequestCommand.START_TRANSACTION,
- {
- connectorId,
- idTag,
- }
- );
+ startResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
+ StartTransactionRequest,
+ 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<StartTransactionResponse>(
- RequestCommand.START_TRANSACTION,
- { connectorId }
- );
+ startResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
+ StartTransactionRequest,
+ StartTransactionResponse
+ >(RequestCommand.START_TRANSACTION, { connectorId });
PerformanceStatistics.endMeasure(measureId, beginId);
return startResponse;
}
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
- await this.chargingStation.ocppRequestService.sendMessageHandler<MeterValuesResponse>(
- RequestCommand.METER_VALUES,
- {
- connectorId,
- transactionId,
- meterValue: transactionEndMeterValue,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ MeterValuesRequest,
+ MeterValuesResponse
+ >(RequestCommand.METER_VALUES, {
+ connectorId,
+ transactionId,
+ meterValue: transactionEndMeterValue,
+ });
}
- stopResponse =
- await this.chargingStation.ocppRequestService.sendMessageHandler<StopTransactionResponse>(
- RequestCommand.STOP_TRANSACTION,
- {
- transactionId,
- meterStop:
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- idTag: this.chargingStation.getTransactionIdTag(transactionId),
- reason,
- }
- );
+ stopResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
+ StopTransactionRequest,
+ StopTransactionResponse
+ >(RequestCommand.STOP_TRANSACTION, {
+ transactionId,
+ meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ reason,
+ });
this.connectorsStatus.get(connectorId).stopTransactionRequests++;
} else {
logger.warn(
AvailabilityType,
BootNotificationRequest,
CachedRequest,
+ HeartbeatRequest,
IncomingRequest,
IncomingRequestCommand,
+ MeterValuesRequest,
RequestCommand,
+ StatusNotificationRequest,
} from '../types/ocpp/Requests';
import {
BootNotificationResponse,
VendorDefaultParametersKey,
} from '../types/ocpp/Configuration';
import { MeterValue, MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
-import { StopTransactionReason, StopTransactionResponse } from '../types/ocpp/Transaction';
+import {
+ StopTransactionReason,
+ StopTransactionRequest,
+ StopTransactionResponse,
+} from '../types/ocpp/Transaction';
import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket';
import WebSocket, { Data, OPEN, RawData } from 'ws';
) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.heartbeatSetInterval = setInterval(async (): Promise<void> => {
- await this.ocppRequestService.sendMessageHandler<HeartbeatResponse>(
+ await this.ocppRequestService.sendMessageHandler<HeartbeatRequest, HeartbeatResponse>(
RequestCommand.HEARTBEAT
);
}, this.getHeartbeatInterval());
this.getConnectorStatus(connectorId).transactionId,
interval
);
- await this.ocppRequestService.sendMessageHandler<MeterValuesResponse>(
+ await this.ocppRequestService.sendMessageHandler<MeterValuesRequest, MeterValuesResponse>(
RequestCommand.METER_VALUES,
{
connectorId,
await this.stopMessageSequence(reason);
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
- await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: ChargePointStatus.UNAVAILABLE,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ 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<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 }
- );
+ this.bootNotificationResponse = await this.ocppRequestService.sendMessageHandler<
+ BootNotificationRequest,
+ 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<BootNotificationResponse>(
+ await this.ocppRequestService.sendMessageHandler<
+ BootNotificationRequest,
+ BootNotificationResponse
+ >(
RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel: this.bootNotificationRequest.chargePointModel,
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template at startup
- await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: this.getConnectorStatus(connectorId).bootStatus,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ 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<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: this.getConnectorStatus(connectorId).bootStatus,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ 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<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: this.getConnectorStatus(connectorId).status,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ StatusNotificationResponse
+ >(RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: this.getConnectorStatus(connectorId).status,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
} else {
// Send default status
- await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: ChargePointStatus.AVAILABLE,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ 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<MeterValuesResponse>(
- RequestCommand.METER_VALUES,
- {
- connectorId,
- transactionId,
- meterValue: transactionEndMeterValue,
- }
- );
- }
- await this.ocppRequestService.sendMessageHandler<StopTransactionResponse>(
- RequestCommand.STOP_TRANSACTION,
- {
+ await this.ocppRequestService.sendMessageHandler<
+ MeterValuesRequest,
+ MeterValuesResponse
+ >(RequestCommand.METER_VALUES, {
+ connectorId,
transactionId,
- meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId),
- idTag: this.getTransactionIdTag(transactionId),
- reason,
- }
- );
+ meterValue: transactionEndMeterValue,
+ });
+ }
+ await this.ocppRequestService.sendMessageHandler<
+ StopTransactionRequest,
+ StopTransactionResponse
+ >(RequestCommand.STOP_TRANSACTION, {
+ transactionId,
+ meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.getTransactionIdTag(transactionId),
+ reason,
+ });
}
}
}
ChangeAvailabilityRequest,
ChangeConfigurationRequest,
ClearChargingProfileRequest,
+ DiagnosticsStatusNotificationRequest,
GetConfigurationRequest,
GetDiagnosticsRequest,
MessageTrigger,
OCPP16AvailabilityType,
+ OCPP16BootNotificationRequest,
+ OCPP16HeartbeatRequest,
OCPP16IncomingRequestCommand,
OCPP16RequestCommand,
+ OCPP16StatusNotificationRequest,
OCPP16TriggerMessageRequest,
RemoteStartTransactionRequest,
RemoteStopTransactionRequest,
import { Client, FTPResponse } from 'basic-ftp';
import {
OCPP16AuthorizationStatus,
+ OCPP16AuthorizeRequest,
OCPP16AuthorizeResponse,
+ OCPP16StartTransactionRequest,
OCPP16StartTransactionResponse,
OCPP16StopTransactionReason,
+ OCPP16StopTransactionRequest,
OCPP16StopTransactionResponse,
} from '../../../types/ocpp/1.6/Transaction';
+import {
+ OCPP16MeterValuesRequest,
+ OCPP16MeterValuesResponse,
+} from '../../../types/ocpp/1.6/MeterValues';
import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
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<OCPP16MeterValuesResponse>(
- OCPP16RequestCommand.METER_VALUES,
- {
- connectorId,
- transactionId,
- meterValue: transactionEndMeterValue,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16MeterValuesRequest,
+ OCPP16MeterValuesResponse
+ >(OCPP16RequestCommand.METER_VALUES, {
+ connectorId,
+ transactionId,
+ meterValue: transactionEndMeterValue,
+ });
}
- 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,
- }
- );
+ const stopResponse = await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StopTransactionRequest,
+ 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<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: OCPP16ChargePointStatus.AVAILABLE,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
return Constants.OCPP_RESPONSE_UNLOCKED;
}
}
this.chargingStation.getConnectorStatus(id).availability = commandPayload.type;
if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: id,
- status: chargePointStatus,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId: id,
+ status: chargePointStatus,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(id).status = chargePointStatus;
}
}
return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- { connectorId, status: chargePointStatus, errorCode: OCPP16ChargePointErrorCode.NO_ERROR }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: chargePointStatus,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(connectorId).status = chargePointStatus;
return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
}
const transactionConnectorId = commandPayload.connectorId;
const connectorStatus = this.chargingStation.getConnectorStatus(transactionConnectorId);
if (transactionConnectorId) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: transactionConnectorId,
- status: OCPP16ChargePointStatus.PREPARING,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId: transactionConnectorId,
+ status: OCPP16ChargePointStatus.PREPARING,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
connectorStatus.status = OCPP16ChargePointStatus.PREPARING;
if (this.chargingStation.isChargingStationAvailable() && connectorStatus) {
// Check if authorized
} else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) {
connectorStatus.authorizeIdTag = commandPayload.idTag;
const authorizeResponse: OCPP16AuthorizeResponse =
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16AuthorizeResponse>(
- OCPP16RequestCommand.AUTHORIZE,
- {
- idTag: commandPayload.idTag,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16AuthorizeRequest,
+ OCPP16AuthorizeResponse
+ >(OCPP16RequestCommand.AUTHORIZE, {
+ idTag: commandPayload.idTag,
+ });
if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
authorized = true;
}
connectorStatus.transactionRemoteStarted = true;
if (
(
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StartTransactionResponse>(
- OCPP16RequestCommand.START_TRANSACTION,
- {
- connectorId: transactionConnectorId,
- idTag: commandPayload.idTag,
- }
- )
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StartTransactionRequest,
+ OCPP16StartTransactionResponse
+ >(OCPP16RequestCommand.START_TRANSACTION, {
+ connectorId: transactionConnectorId,
+ idTag: commandPayload.idTag,
+ })
).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
) {
logger.debug(
connectorStatus.transactionRemoteStarted = true;
if (
(
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StartTransactionResponse>(
- OCPP16RequestCommand.START_TRANSACTION,
- {
- connectorId: transactionConnectorId,
- idTag: commandPayload.idTag,
- }
- )
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StartTransactionRequest,
+ OCPP16StartTransactionResponse
+ >(OCPP16RequestCommand.START_TRANSACTION, {
+ connectorId: transactionConnectorId,
+ idTag: commandPayload.idTag,
+ })
).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
) {
logger.debug(
this.chargingStation.getConnectorStatus(connectorId).status !==
OCPP16ChargePointStatus.AVAILABLE
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: OCPP16ChargePointStatus.AVAILABLE,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.AVAILABLE;
}
connectorId > 0 &&
this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: OCPP16ChargePointStatus.FINISHING,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: OCPP16ChargePointStatus.FINISHING,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.FINISHING;
if (
connectorId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
- OCPP16RequestCommand.METER_VALUES,
- {
- connectorId,
- transactionId,
- meterValue: transactionEndMeterValue,
- }
- );
- }
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StopTransactionResponse>(
- OCPP16RequestCommand.STOP_TRANSACTION,
- {
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16MeterValuesRequest,
+ OCPP16MeterValuesResponse
+ >(OCPP16RequestCommand.METER_VALUES, {
+ connectorId,
transactionId,
- meterStop:
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- idTag: this.chargingStation.getTransactionIdTag(transactionId),
- }
- );
+ meterValue: transactionEndMeterValue,
+ });
+ }
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StopTransactionRequest,
+ OCPP16StopTransactionResponse
+ >(OCPP16RequestCommand.STOP_TRANSACTION, {
+ transactionId,
+ meterStop:
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ });
return Constants.OCPP_RESPONSE_ACCEPTED;
}
}
info.bytes / 1024
} bytes transferred from diagnostics archive ${info.name}`
);
- await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
- OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- {
- status: OCPP16DiagnosticsStatus.Uploading,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ DiagnosticsStatusNotificationRequest,
+ DiagnosticsStatusNotificationResponse
+ >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+ status: OCPP16DiagnosticsStatus.Uploading,
+ });
});
uploadResponse = await ftpClient.uploadFrom(
path.join(path.resolve(__dirname, '../../../../'), diagnosticsArchive),
uri.pathname + diagnosticsArchive
);
if (uploadResponse.code === 226) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
- OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- {
- status: OCPP16DiagnosticsStatus.Uploaded,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ DiagnosticsStatusNotificationRequest,
+ DiagnosticsStatusNotificationResponse
+ >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+ status: OCPP16DiagnosticsStatus.Uploaded,
+ });
if (ftpClient) {
ftpClient.close();
}
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
);
} catch (error) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
- OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- {
- status: OCPP16DiagnosticsStatus.UploadFailed,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ DiagnosticsStatusNotificationRequest,
+ DiagnosticsStatusNotificationResponse
+ >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+ status: OCPP16DiagnosticsStatus.UploadFailed,
+ });
if (ftpClient) {
ftpClient.close();
}
uri.protocol
} to transfer the diagnostic logs archive`
);
- await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
- OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- {
- status: OCPP16DiagnosticsStatus.UploadFailed,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ DiagnosticsStatusNotificationRequest,
+ DiagnosticsStatusNotificationResponse
+ >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+ status: OCPP16DiagnosticsStatus.UploadFailed,
+ });
return Constants.OCPP_RESPONSE_EMPTY;
}
}
case MessageTrigger.BootNotification:
setTimeout(() => {
this.chargingStation.ocppRequestService
- .sendMessageHandler<OCPP16BootNotificationResponse>(
+ .sendMessageHandler<OCPP16BootNotificationRequest, OCPP16BootNotificationResponse>(
OCPP16RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel:
case MessageTrigger.Heartbeat:
setTimeout(() => {
this.chargingStation.ocppRequestService
- .sendMessageHandler<OCPP16HeartbeatResponse>(OCPP16RequestCommand.HEARTBEAT, null, {
- triggerMessage: true,
- })
+ .sendMessageHandler<OCPP16HeartbeatRequest, OCPP16HeartbeatResponse>(
+ OCPP16RequestCommand.HEARTBEAT,
+ null,
+ {
+ triggerMessage: true,
+ }
+ )
.catch(() => {
/* This is intentional */
});
super(chargingStation, ocppResponseService);
}
- public async sendMessageHandler<Response extends JsonType>(
+ public async sendMessageHandler<Request extends JsonType, Response extends JsonType>(
commandName: OCPP16RequestCommand,
commandParams?: JsonType,
params?: SendParams
if (Object.values(OCPP16RequestCommand).includes(commandName)) {
return (await this.sendMessage(
Utils.generateUUID(),
- this.buildCommandPayload(commandName, commandParams),
+ this.buildCommandPayload<Request>(commandName, commandParams),
commandName,
params
)) as unknown as Response;
// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
import {
- AuthorizeRequest,
OCPP16AuthorizationStatus,
+ OCPP16AuthorizeRequest,
OCPP16AuthorizeResponse,
+ OCPP16StartTransactionRequest,
OCPP16StartTransactionResponse,
+ OCPP16StopTransactionRequest,
OCPP16StopTransactionResponse,
- StartTransactionRequest,
- StopTransactionRequest,
} from '../../../types/ocpp/1.6/Transaction';
import {
- HeartbeatRequest,
+ OCPP16BootNotificationRequest,
+ OCPP16HeartbeatRequest,
OCPP16RequestCommand,
- StatusNotificationRequest,
+ OCPP16StatusNotificationRequest,
} from '../../../types/ocpp/1.6/Requests';
-import { MeterValuesRequest, OCPP16MeterValuesResponse } from '../../../types/ocpp/1.6/MeterValues';
import {
OCPP16BootNotificationResponse,
OCPP16HeartbeatResponse,
OCPP16RegistrationStatus,
OCPP16StatusNotificationResponse,
} from '../../../types/ocpp/1.6/Responses';
+import {
+ OCPP16MeterValuesRequest,
+ OCPP16MeterValuesResponse,
+} from '../../../types/ocpp/1.6/MeterValues';
import type ChargingStation from '../../ChargingStation';
import { ErrorType } from '../../../types/ocpp/ErrorType';
private handleResponseHeartbeat(
payload: OCPP16HeartbeatResponse,
- requestPayload: HeartbeatRequest
+ requestPayload: OCPP16HeartbeatRequest
): void {
logger.debug(
this.chargingStation.logPrefix() +
private handleResponseAuthorize(
payload: OCPP16AuthorizeResponse,
- requestPayload: AuthorizeRequest
+ requestPayload: OCPP16AuthorizeRequest
): void {
let authorizeConnectorId: number;
for (const connectorId of this.chargingStation.connectors.keys()) {
private async handleResponseStartTransaction(
payload: OCPP16StartTransactionResponse,
- requestPayload: StartTransactionRequest
+ requestPayload: OCPP16StartTransactionRequest
): Promise<void> {
const connectorId = requestPayload.connectorId;
requestPayload.meterStart
);
this.chargingStation.getBeginEndMeterValues() &&
- (await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
- OCPP16RequestCommand.METER_VALUES,
- {
- connectorId,
- transactionId: payload.transactionId,
- meterValue:
- this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
- }
- ));
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
+ (await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16MeterValuesRequest,
+ OCPP16MeterValuesResponse
+ >(OCPP16RequestCommand.METER_VALUES, {
connectorId,
- status: OCPP16ChargePointStatus.CHARGING,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ transactionId: payload.transactionId,
+ meterValue:
+ this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
+ }));
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: OCPP16ChargePointStatus.CHARGING,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.CHARGING;
logger.info(
this.chargingStation.getConnectorStatus(connectorId).status !==
OCPP16ChargePointStatus.AVAILABLE
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: OCPP16ChargePointStatus.AVAILABLE,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.AVAILABLE;
}
private async handleResponseStopTransaction(
payload: OCPP16StopTransactionResponse,
- requestPayload: StopTransactionRequest
+ requestPayload: OCPP16StopTransactionRequest
): Promise<void> {
const transactionConnectorId = this.chargingStation.getConnectorIdByTransactionId(
requestPayload.transactionId
this.chargingStation.getBeginEndMeterValues() &&
!this.chargingStation.getOcppStrictCompliance() &&
this.chargingStation.getOutOfOrderEndMeterValues() &&
- (await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16MeterValuesResponse>(
- OCPP16RequestCommand.METER_VALUES,
- {
- connectorId: transactionConnectorId,
- transactionId: requestPayload.transactionId,
- meterValue: OCPP16ServiceUtils.buildTransactionEndMeterValue(
- this.chargingStation,
- transactionConnectorId,
- requestPayload.meterStop
- ),
- }
- ));
+ (await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16MeterValuesRequest,
+ OCPP16MeterValuesResponse
+ >(OCPP16RequestCommand.METER_VALUES, {
+ connectorId: transactionConnectorId,
+ transactionId: requestPayload.transactionId,
+ meterValue: OCPP16ServiceUtils.buildTransactionEndMeterValue(
+ this.chargingStation,
+ transactionConnectorId,
+ requestPayload.meterStop
+ ),
+ }));
if (
!this.chargingStation.isChargingStationAvailable() ||
!this.chargingStation.isConnectorAvailable(transactionConnectorId)
) {
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16StatusNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: transactionConnectorId,
- status: OCPP16ChargePointStatus.UNAVAILABLE,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId: transactionConnectorId,
+ status: OCPP16ChargePointStatus.UNAVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(transactionConnectorId).status =
OCPP16ChargePointStatus.UNAVAILABLE;
} else {
- await this.chargingStation.ocppRequestService.sendMessageHandler<OCPP16BootNotificationResponse>(
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId: transactionConnectorId,
- status: OCPP16ChargePointStatus.AVAILABLE,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.chargingStation.ocppRequestService.sendMessageHandler<
+ OCPP16BootNotificationRequest,
+ OCPP16BootNotificationResponse
+ >(OCPP16RequestCommand.STATUS_NOTIFICATION, {
+ connectorId: transactionConnectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ });
this.chargingStation.getConnectorStatus(transactionConnectorId).status =
OCPP16ChargePointStatus.AVAILABLE;
}
}
private handleResponseStatusNotification(
- payload: StatusNotificationRequest,
+ payload: OCPP16StatusNotificationRequest,
requestPayload: OCPP16StatusNotificationResponse
): void {
logger.debug(
}
private handleResponseMeterValues(
- payload: MeterValuesRequest,
+ payload: OCPP16MeterValuesRequest,
requestPayload: OCPP16MeterValuesResponse
): void {
logger.debug(
}
}
- public abstract sendMessageHandler<Response extends JsonType>(
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ public abstract sendMessageHandler<Request extends JsonType, Response extends JsonType>(
commandName: RequestCommand,
commandParams?: JsonType,
params?: SendParams
sampledValue: OCPP16SampledValue[];
}
-export interface MeterValuesRequest extends JsonType {
+export interface OCPP16MeterValuesRequest extends JsonType {
connectorId: number;
transactionId?: number;
meterValue: OCPP16MeterValue[];
TRIGGER_MESSAGE = 'TriggerMessage',
}
-export type HeartbeatRequest = EmptyObject;
+export type OCPP16HeartbeatRequest = EmptyObject;
export interface OCPP16BootNotificationRequest extends JsonType {
chargeBoxSerialNumber?: string;
meterType?: string;
}
-export interface StatusNotificationRequest extends JsonType {
+export interface OCPP16StatusNotificationRequest extends JsonType {
connectorId: number;
errorCode: OCPP16ChargePointErrorCode;
info?: string;
expiryDate?: Date;
}
-export interface AuthorizeRequest extends JsonType {
+export interface OCPP16AuthorizeRequest extends JsonType {
idTag: string;
}
idTagInfo: IdTagInfo;
}
-export interface StartTransactionRequest extends JsonType {
+export interface OCPP16StartTransactionRequest extends JsonType {
connectorId: number;
idTag: string;
meterStart: number;
transactionId: number;
}
-export interface StopTransactionRequest extends JsonType {
+export interface OCPP16StopTransactionRequest extends JsonType {
idTag?: string;
meterStop: number;
timestamp: string;
import {
OCPP16AvailabilityType,
OCPP16BootNotificationRequest,
+ OCPP16HeartbeatRequest,
OCPP16IncomingRequestCommand,
OCPP16RequestCommand,
+ OCPP16StatusNotificationRequest,
} from './1.6/Requests';
import { JsonType } from '../JsonType';
import { MessageType } from './MessageType';
import { OCPP16DiagnosticsStatus } from './1.6/DiagnosticsStatus';
+import { OCPP16MeterValuesRequest } from './1.6/MeterValues';
import OCPPError from '../../exception/OCPPError';
export interface SendParams {
export type BootNotificationRequest = OCPP16BootNotificationRequest;
+export type HeartbeatRequest = OCPP16HeartbeatRequest;
+
+export type StatusNotificationRequest = OCPP16StatusNotificationRequest;
+
+export type MeterValuesRequest = OCPP16MeterValuesRequest;
+
export type AvailabilityType = OCPP16AvailabilityType;
export const AvailabilityType = {
import {
OCPP16AuthorizationStatus,
+ OCPP16AuthorizeRequest,
OCPP16AuthorizeResponse,
+ OCPP16StartTransactionRequest,
OCPP16StartTransactionResponse,
OCPP16StopTransactionReason,
+ OCPP16StopTransactionRequest,
OCPP16StopTransactionResponse,
} from './1.6/Transaction';
...OCPP16AuthorizationStatus,
};
+export type AuthorizeRequest = OCPP16AuthorizeRequest;
+
export type AuthorizeResponse = OCPP16AuthorizeResponse;
export type StopTransactionReason = OCPP16StopTransactionReason;
...OCPP16StopTransactionReason,
};
+export type StartTransactionRequest = OCPP16StartTransactionRequest;
+
export type StartTransactionResponse = OCPP16StartTransactionResponse;
+export type StopTransactionRequest = OCPP16StopTransactionRequest;
+
export type StopTransactionResponse = OCPP16StopTransactionResponse;