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,
const configurationKey: OCPPConfigurationKey[] = [];
const unknownKey: string[] = [];
if (Utils.isEmptyArray(commandPayload.key)) {
- for (const configuration of this.chargingStation.configuration.configurationKey) {
+ for (const configuration of this.chargingStation.ocppConfiguration.configurationKey) {
if (Utils.isUndefined(configuration.visible)) {
configuration.visible = true;
}
} else if (keyToChange && keyToChange.readonly) {
return Constants.OCPP_CONFIGURATION_RESPONSE_REJECTED;
} else if (keyToChange && !keyToChange.readonly) {
- const keyIndex = this.chargingStation.configuration.configurationKey.indexOf(keyToChange);
let valueChanged = false;
- if (
- this.chargingStation.configuration.configurationKey[keyIndex].value !== commandPayload.value
- ) {
- this.chargingStation.configuration.configurationKey[keyIndex].value = commandPayload.value;
+ if (keyToChange.value !== commandPayload.value) {
+ this.chargingStation.setConfigurationKeyValue(
+ commandPayload.key,
+ commandPayload.value,
+ true
+ );
valueChanged = true;
}
let triggerHeartbeatRestart = false;
private handleRequestClearChargingProfile(
commandPayload: ClearChargingProfileRequest
): ClearChargingProfileResponse {
- if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) {
+ const connectorStatus = this.chargingStation.getConnectorStatus(commandPayload.connectorId);
+ if (!connectorStatus) {
logger.error(
`${this.chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${
commandPayload.connectorId
);
return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
- if (
- commandPayload.connectorId &&
- !Utils.isEmptyArray(
- this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles
- )
- ) {
- this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles = [];
+ if (commandPayload.connectorId && !Utils.isEmptyArray(connectorStatus.chargingProfiles)) {
+ connectorStatus.chargingProfiles = [];
logger.debug(
`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`,
- this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles
+ connectorStatus.chargingProfiles
);
return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
}
clearCurrentCP = true;
}
if (clearCurrentCP) {
- this.chargingStation.getConnectorStatus(
- commandPayload.connectorId
- ).chargingProfiles[index] = {} as OCPP16ChargingProfile;
+ connectorStatus.chargingProfiles[index] = {} as OCPP16ChargingProfile;
logger.debug(
`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`,
- this.chargingStation.getConnectorStatus(commandPayload.connectorId)
- .chargingProfiles
+ connectorStatus.chargingProfiles
);
clearedCP = true;
}
}
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 }
);
private async handleRequestRemoteStartTransaction(
commandPayload: RemoteStartTransactionRequest
): Promise<DefaultResponse> {
- const transactionConnectorId: number = commandPayload.connectorId;
+ 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,
errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
}
);
- this.chargingStation.getConnectorStatus(transactionConnectorId).status =
- OCPP16ChargePointStatus.PREPARING;
- if (
- this.chargingStation.isChargingStationAvailable() &&
- this.chargingStation.isConnectorAvailable(transactionConnectorId)
- ) {
+ connectorStatus.status = OCPP16ChargePointStatus.PREPARING;
+ if (this.chargingStation.isChargingStationAvailable() && connectorStatus) {
// Check if authorized
if (this.chargingStation.getAuthorizeRemoteTxRequests()) {
let authorized = false;
this.chargingStation.hasAuthorizedTags() &&
this.chargingStation.authorizedTags.find((value) => value === commandPayload.idTag)
) {
- this.chargingStation.getConnectorStatus(transactionConnectorId).localAuthorizeIdTag =
- commandPayload.idTag;
- this.chargingStation.getConnectorStatus(transactionConnectorId).idTagLocalAuthorized =
- true;
+ connectorStatus.localAuthorizeIdTag = commandPayload.idTag;
+ connectorStatus.idTagLocalAuthorized = true;
authorized = true;
} else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) {
- this.chargingStation.getConnectorStatus(transactionConnectorId).authorizeIdTag =
- commandPayload.idTag;
+ 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;
}
commandPayload.chargingProfile
)
) {
- this.chargingStation.getConnectorStatus(
- transactionConnectorId
- ).transactionRemoteStarted = 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(
commandPayload.chargingProfile
)
) {
- this.chargingStation.getConnectorStatus(transactionConnectorId).transactionRemoteStarted =
- 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(
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.sendDiagnosticsStatusNotification(
- OCPP16DiagnosticsStatus.Uploading
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
+ OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+ {
+ status: OCPP16DiagnosticsStatus.Uploading,
+ }
);
});
uploadResponse = await ftpClient.uploadFrom(
uri.pathname + diagnosticsArchive
);
if (uploadResponse.code === 226) {
- await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(
- OCPP16DiagnosticsStatus.Uploaded
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
+ OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+ {
+ status: OCPP16DiagnosticsStatus.Uploaded,
+ }
);
if (ftpClient) {
ftpClient.close();
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
);
} catch (error) {
- await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(
- OCPP16DiagnosticsStatus.UploadFailed
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
+ OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+ {
+ status: OCPP16DiagnosticsStatus.UploadFailed,
+ }
);
if (ftpClient) {
ftpClient.close();
uri.protocol
} to transfer the diagnostic logs archive`
);
- await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(
- OCPP16DiagnosticsStatus.UploadFailed
+ await this.chargingStation.ocppRequestService.sendMessageHandler<DiagnosticsStatusNotificationResponse>(
+ OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+ {
+ status: OCPP16DiagnosticsStatus.UploadFailed,
+ }
);
return Constants.OCPP_RESPONSE_EMPTY;
}
case MessageTrigger.BootNotification:
setTimeout(() => {
this.chargingStation.ocppRequestService
- .sendMessageHandler(
+ .sendMessageHandler<OCPP16BootNotificationResponse>(
OCPP16RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel:
},
{ skipBufferingOnError: true, triggerMessage: true }
)
+ .then((value) => {
+ this.chargingStation.bootNotificationResponse = value;
+ })
.catch(() => {
/* This is intentional */
});
case MessageTrigger.Heartbeat:
setTimeout(() => {
this.chargingStation.ocppRequestService
- .sendMessageHandler(OCPP16RequestCommand.HEARTBEAT, null, { triggerMessage: true })
+ .sendMessageHandler<OCPP16HeartbeatResponse>(OCPP16RequestCommand.HEARTBEAT, null, {
+ triggerMessage: true,
+ })
.catch(() => {
/* This is intentional */
});