for (const [evseId, evseStatus] of this.evses) {
if (evseId > 0) {
for (const [connectorId, connectorStatus] of evseStatus.connectors) {
- const connectorBootStatus = getBootConnectorStatus(this, connectorId, connectorStatus)
- await sendAndSetConnectorStatus(this, connectorId, connectorBootStatus, evseId)
+ await sendAndSetConnectorStatus(
+ this,
+ connectorId,
+ getBootConnectorStatus(this, connectorId, connectorStatus),
+ evseId
+ )
}
}
}
} else {
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
- const connectorBootStatus = getBootConnectorStatus(
+ await sendAndSetConnectorStatus(
this,
connectorId,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.getConnectorStatus(connectorId)!
+ getBootConnectorStatus(
+ this,
+ connectorId,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.getConnectorStatus(connectorId)!
+ )
)
- await sendAndSetConnectorStatus(this, connectorId, connectorBootStatus)
}
}
}
): Promise<GenericResponse> {
const { connectorId: transactionConnectorId, idTag, chargingProfile } = commandPayload
if (!chargingStation.hasConnector(transactionConnectorId)) {
- return await this.notifyRemoteStartTransactionRejected(
+ return this.notifyRemoteStartTransactionRejected(
chargingStation,
transactionConnectorId,
idTag
!chargingStation.isChargingStationAvailable() ||
!chargingStation.isConnectorAvailable(transactionConnectorId)
) {
- return await this.notifyRemoteStartTransactionRejected(
+ return this.notifyRemoteStartTransactionRejected(
chargingStation,
transactionConnectorId,
idTag
chargingStation.getAuthorizeRemoteTxRequests() &&
!(await OCPP16ServiceUtils.isIdTagAuthorized(chargingStation, transactionConnectorId, idTag))
) {
- return await this.notifyRemoteStartTransactionRejected(
+ return this.notifyRemoteStartTransactionRejected(
chargingStation,
transactionConnectorId,
idTag
)
}
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- transactionConnectorId,
- OCPP16ChargePointStatus.Preparing
- )
if (
chargingProfile != null &&
!this.setRemoteStartTransactionChargingProfile(
chargingProfile
)
) {
- return await this.notifyRemoteStartTransactionRejected(
+ return this.notifyRemoteStartTransactionRejected(
chargingStation,
transactionConnectorId,
idTag
)
}
logger.debug(
- `${chargingStation.logPrefix()} Remote start transaction ACCEPTED on connector id ${transactionConnectorId}, idTag '${idTag}'`
+ `${chargingStation.logPrefix()} Remote start transaction ACCEPTED on ${chargingStation.stationInfo?.chargingStationId}#${transactionConnectorId}}, idTag '${idTag}'`
)
return OCPP16Constants.OCPP_RESPONSE_ACCEPTED
}
- private async notifyRemoteStartTransactionRejected (
+ private notifyRemoteStartTransactionRejected (
chargingStation: ChargingStation,
connectorId: number,
idTag: string
- ): Promise<GenericResponse> {
+ ): GenericResponse {
const connectorStatus = chargingStation.getConnectorStatus(connectorId)
- if (connectorStatus?.status !== OCPP16ChargePointStatus.Available) {
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Available
- )
- }
logger.debug(
- `${chargingStation.logPrefix()} Remote start transaction REJECTED on connector id ${connectorId}, idTag '${idTag}', availability '${connectorStatus?.availability}', status '${connectorStatus?.status}'`
+ `${chargingStation.logPrefix()} Remote start transaction REJECTED on ${chargingStation.stationInfo?.chargingStationId}#${connectorId}, idTag '${idTag}', availability '${connectorStatus?.availability}', status '${connectorStatus?.status}'`
)
return OCPP16Constants.OCPP_RESPONSE_REJECTED
}
if (chargingProfile.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE) {
OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, chargingProfile)
logger.debug(
- `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`,
+ `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on ${chargingStation.stationInfo?.chargingStationId}#${connectorId}`,
chargingProfile
)
return true
public async requestHandler<RequestType extends JsonType, ResponseType extends JsonType>(
chargingStation: ChargingStation,
commandName: OCPP16RequestCommand,
- commandParams?: JsonType,
+ commandParams?: RequestType,
params?: RequestParams
): Promise<ResponseType> {
// FIXME?: add sanity checks on charging station availability, connector availability, connector status, etc.
if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName)) {
+ // Post request actions hook
+ switch (commandName) {
+ case OCPP16RequestCommand.START_TRANSACTION:
+ await OCPP16ServiceUtils.sendAndSetConnectorStatus(
+ chargingStation,
+ (commandParams as OCPP16StartTransactionRequest).connectorId,
+ OCPP16ChargePointStatus.Preparing
+ )
+ break
+ }
return (await this.sendMessage(
chargingStation,
generateUUID(),
chargingStation: ChargingStation,
connectorId: number
): Promise<void> {
+ chargingStation.stopMeterValues(connectorId)
const connectorStatus = chargingStation.getConnectorStatus(connectorId)
resetConnectorStatus(connectorStatus)
- chargingStation.stopMeterValues(connectorId)
- if (chargingStation.getReservationBy('connectorId', connectorId) != null) {
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Reserved
- )
- } else if (connectorStatus?.status !== OCPP16ChargePointStatus.Available) {
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Available
- )
- }
+ await OCPP16ServiceUtils.restoreConnectorStatus(chargingStation, connectorId, connectorStatus)
}
private async handleResponseStopTransaction (
public async requestHandler<RequestType extends JsonType, ResponseType extends JsonType>(
chargingStation: ChargingStation,
commandName: OCPP20RequestCommand,
- commandParams?: JsonType,
+ commandParams?: RequestType,
params?: RequestParams
): Promise<ResponseType> {
// FIXME?: add sanity checks on charging station availability, connector availability, connector status, etc.
if (OCPP20ServiceUtils.isRequestCommandSupported(chargingStation, commandName)) {
+ // TODO: post request actions hook
return (await this.sendMessage(
chargingStation,
generateUUID(),
public abstract requestHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand,
- // FIXME: should be ReqType
- commandParams?: JsonType,
+ commandParams?: ReqType,
params?: RequestParams
): Promise<ResType>
}
type AuthorizeResponse,
ChargePointErrorCode,
ChargingStationEvents,
- type ConnectorStatusEnum,
+ type ConnectorStatus,
+ ConnectorStatusEnum,
CurrentType,
ErrorType,
FileType,
})
}
+export const restoreConnectorStatus = async (
+ chargingStation: ChargingStation,
+ connectorId: number,
+ connectorStatus: ConnectorStatus | undefined
+): Promise<void> => {
+ if (connectorStatus?.reservation != null) {
+ await sendAndSetConnectorStatus(chargingStation, connectorId, ConnectorStatusEnum.Reserved)
+ } else if (connectorStatus?.status !== ConnectorStatusEnum.Available) {
+ await sendAndSetConnectorStatus(chargingStation, connectorId, ConnectorStatusEnum.Available)
+ }
+}
+
const checkConnectorStatusTransition = (
chargingStation: ChargingStation,
connectorId: number,
export class OCPPServiceUtils {
public static readonly getMessageTypeString = getMessageTypeString
public static readonly sendAndSetConnectorStatus = sendAndSetConnectorStatus
+ public static readonly restoreConnectorStatus = restoreConnectorStatus
public static readonly isIdTagAuthorized = isIdTagAuthorized
public static readonly buildTransactionEndMeterValue = buildTransactionEndMeterValue
protected static getSampledValueTemplate = getSampledValueTemplate