import type ChargingStation from '../../ChargingStation';
import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils';
import { ChargingStationUtils } from '../../ChargingStationUtils';
+import OCPPConstants from '../OCPPConstants';
import OCPPIncomingRequestService from '../OCPPIncomingRequestService';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
chargingStation.stationInfo.resetTime
)}`
);
- return Constants.OCPP_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
}
private handleRequestClearCache(chargingStation: ChargingStation): DefaultResponse {
chargingStation.authorizedTagsCache.deleteAuthorizedTags(
ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
);
- return Constants.OCPP_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
}
private async handleRequestUnlockConnector(
logger.error(
`${chargingStation.logPrefix()} Trying to unlock a non existing connector Id ${connectorId.toString()}`
);
- return Constants.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED;
+ return OCPPConstants.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED;
}
if (connectorId === 0) {
logger.error(
chargingStation.logPrefix() + ' Trying to unlock connector Id ' + connectorId.toString()
);
- return Constants.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED;
+ return OCPPConstants.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED;
}
if (chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
const stopResponse = await chargingStation.stopTransactionOnConnector(
OCPP16StopTransactionReason.UNLOCK_COMMAND
);
if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
- return Constants.OCPP_RESPONSE_UNLOCKED;
+ return OCPPConstants.OCPP_RESPONSE_UNLOCKED;
}
- return Constants.OCPP_RESPONSE_UNLOCK_FAILED;
+ return OCPPConstants.OCPP_RESPONSE_UNLOCK_FAILED;
}
await chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
});
chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
- return Constants.OCPP_RESPONSE_UNLOCKED;
+ return OCPPConstants.OCPP_RESPONSE_UNLOCKED;
}
private handleRequestGetConfiguration(
true
);
if (!keyToChange) {
- return Constants.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED;
+ return OCPPConstants.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED;
} else if (keyToChange && keyToChange.readonly) {
- return Constants.OCPP_CONFIGURATION_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_CONFIGURATION_RESPONSE_REJECTED;
} else if (keyToChange && !keyToChange.readonly) {
let valueChanged = false;
if (keyToChange.value !== commandPayload.value) {
chargingStation.restartWebSocketPing();
}
if (keyToChange.reboot) {
- return Constants.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED;
+ return OCPPConstants.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED;
}
- return Constants.OCPP_CONFIGURATION_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_CONFIGURATION_RESPONSE_ACCEPTED;
}
}
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE
) === false
) {
- return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED;
+ return OCPPConstants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED;
}
if (chargingStation.connectors.has(commandPayload.connectorId) === false) {
logger.error(
commandPayload.connectorId
}`
);
- return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
if (
commandPayload.csChargingProfiles.chargingProfilePurpose ===
ChargingProfilePurposeType.CHARGE_POINT_MAX_PROFILE &&
commandPayload.connectorId !== 0
) {
- return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
if (
commandPayload.csChargingProfiles.chargingProfilePurpose ===
commandPayload.connectorId
} without a started transaction`
);
- return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
OCPP16ServiceUtils.setChargingProfile(
chargingStation,
}, dump their stack: %j`,
chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles
);
- return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED;
}
private handleRequestClearChargingProfile(
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE
) === false
) {
- return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
+ return OCPPConstants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
if (chargingStation.connectors.has(commandPayload.connectorId) === false) {
logger.error(
commandPayload.connectorId
}`
);
- return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
+ return OCPPConstants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
const connectorStatus = chargingStation.getConnectorStatus(commandPayload.connectorId);
if (commandPayload.connectorId && !Utils.isEmptyArray(connectorStatus.chargingProfiles)) {
}, dump their stack: %j`,
connectorStatus.chargingProfiles
);
- return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
}
if (!commandPayload.connectorId) {
let clearedCP = false;
}
}
if (clearedCP) {
- return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
}
}
- return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
+ return OCPPConstants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
private async handleRequestChangeAvailability(
logger.error(
`${chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`
);
- return Constants.OCPP_AVAILABILITY_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_AVAILABILITY_RESPONSE_REJECTED;
}
const chargePointStatus: OCPP16ChargePointStatus =
commandPayload.type === OCPP16AvailabilityType.OPERATIVE
? OCPP16ChargePointStatus.AVAILABLE
: OCPP16ChargePointStatus.UNAVAILABLE;
if (connectorId === 0) {
- let response: ChangeAvailabilityResponse = Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
+ let response: ChangeAvailabilityResponse = OCPPConstants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
for (const id of chargingStation.connectors.keys()) {
if (chargingStation.getConnectorStatus(id)?.transactionStarted === true) {
- response = Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
+ response = OCPPConstants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
chargingStation.getConnectorStatus(id).availability = commandPayload.type;
- if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
+ if (response === OCPPConstants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
await chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
OCPP16StatusNotificationResponse
) {
if (chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
- return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
+ return OCPPConstants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
await chargingStation.ocppRequestService.requestHandler<
errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
});
chargingStation.getConnectorStatus(connectorId).status = chargePointStatus;
- return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
}
- return Constants.OCPP_AVAILABILITY_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_AVAILABILITY_RESPONSE_REJECTED;
}
private async handleRequestRemoteStartTransaction(
).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
) {
logger.debug(remoteStartTransactionLogMsg);
- return Constants.OCPP_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
}
return this.notifyRemoteStartTransactionRejected(
chargingStation,
).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
) {
logger.debug(remoteStartTransactionLogMsg);
- return Constants.OCPP_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
}
return this.notifyRemoteStartTransactionRejected(
chargingStation,
chargingStation.getConnectorStatus(connectorId).status +
"'"
);
- return Constants.OCPP_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_RESPONSE_REJECTED;
}
private setRemoteStartTransactionChargingProfile(
OCPP16StopTransactionReason.REMOTE
);
if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
- return Constants.OCPP_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_RESPONSE_ACCEPTED;
}
- return Constants.OCPP_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_RESPONSE_REJECTED;
}
}
logger.warn(
' Trying to remote stop a non existing transaction ' +
transactionId.toString()
);
- return Constants.OCPP_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_RESPONSE_REJECTED;
}
private handleRequestUpdateFirmware(
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE
) === false
) {
- return Constants.OCPP_RESPONSE_EMPTY;
+ return OCPPConstants.OCPP_RESPONSE_EMPTY;
}
logger.debug(
chargingStation.logPrefix() +
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS
) === false
) {
- return Constants.OCPP_RESPONSE_EMPTY;
+ return OCPPConstants.OCPP_RESPONSE_EMPTY;
}
logger.debug(
chargingStation.logPrefix() +
chargingStation,
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
error as Error,
- { errorResponse: Constants.OCPP_RESPONSE_EMPTY }
+ { errorResponse: OCPPConstants.OCPP_RESPONSE_EMPTY }
);
}
} else {
>(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
status: OCPP16DiagnosticsStatus.UploadFailed,
});
- return Constants.OCPP_RESPONSE_EMPTY;
+ return OCPPConstants.OCPP_RESPONSE_EMPTY;
}
}
commandPayload.requestedMessage
)
) {
- return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
+ return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
}
if (
!OCPP16ServiceUtils.isConnectorIdValid(
commandPayload.connectorId
)
) {
- return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED;
+ return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED;
}
try {
switch (commandPayload.requestedMessage) {
/* This is intentional */
});
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
- return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
case OCPP16MessageTrigger.Heartbeat:
setTimeout(() => {
chargingStation.ocppRequestService
/* This is intentional */
});
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
- return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
case OCPP16MessageTrigger.StatusNotification:
setTimeout(() => {
if (commandPayload?.connectorId) {
}
}
}, Constants.OCPP_TRIGGER_MESSAGE_DELAY);
- return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
+ return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED;
default:
- return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
+ return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
}
} catch (error) {
return this.handleIncomingRequestError(
chargingStation,
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
error as Error,
- { errorResponse: Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED }
+ { errorResponse: OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED }
);
}
}
chargingStation,
OCPP16IncomingRequestCommand.DATA_TRANSFER,
error as Error,
- { errorResponse: Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED }
+ { errorResponse: OCPPConstants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED }
);
}
}
--- /dev/null
+import {
+ AvailabilityStatus,
+ ChargingProfileStatus,
+ ClearChargingProfileStatus,
+ ConfigurationStatus,
+ DataTransferStatus,
+ DefaultStatus,
+ TriggerMessageStatus,
+ UnlockStatus,
+} from '../../types/ocpp/Responses';
+
+export default class OCPPConstants {
+ static readonly OCPP_RESPONSE_EMPTY = Object.freeze({});
+ static readonly OCPP_RESPONSE_ACCEPTED = Object.freeze({ status: DefaultStatus.ACCEPTED });
+ static readonly OCPP_RESPONSE_REJECTED = Object.freeze({ status: DefaultStatus.REJECTED });
+
+ static readonly OCPP_CONFIGURATION_RESPONSE_ACCEPTED = Object.freeze({
+ status: ConfigurationStatus.ACCEPTED,
+ });
+
+ static readonly OCPP_CONFIGURATION_RESPONSE_REJECTED = Object.freeze({
+ status: ConfigurationStatus.REJECTED,
+ });
+
+ static readonly OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED = Object.freeze({
+ status: ConfigurationStatus.REBOOT_REQUIRED,
+ });
+
+ static readonly OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED = Object.freeze({
+ status: ConfigurationStatus.NOT_SUPPORTED,
+ });
+
+ static readonly OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED = Object.freeze({
+ status: ChargingProfileStatus.ACCEPTED,
+ });
+
+ static readonly OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED = Object.freeze({
+ status: ChargingProfileStatus.REJECTED,
+ });
+
+ static readonly OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED = Object.freeze({
+ status: ChargingProfileStatus.NOT_SUPPORTED,
+ });
+
+ static readonly OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED = Object.freeze({
+ status: ClearChargingProfileStatus.ACCEPTED,
+ });
+
+ static readonly OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN = Object.freeze({
+ status: ClearChargingProfileStatus.UNKNOWN,
+ });
+
+ static readonly OCPP_RESPONSE_UNLOCKED = Object.freeze({ status: UnlockStatus.UNLOCKED });
+ static readonly OCPP_RESPONSE_UNLOCK_FAILED = Object.freeze({
+ status: UnlockStatus.UNLOCK_FAILED,
+ });
+
+ static readonly OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED = Object.freeze({
+ status: UnlockStatus.NOT_SUPPORTED,
+ });
+
+ static readonly OCPP_AVAILABILITY_RESPONSE_ACCEPTED = Object.freeze({
+ status: AvailabilityStatus.ACCEPTED,
+ });
+
+ static readonly OCPP_AVAILABILITY_RESPONSE_REJECTED = Object.freeze({
+ status: AvailabilityStatus.REJECTED,
+ });
+
+ static readonly OCPP_AVAILABILITY_RESPONSE_SCHEDULED = Object.freeze({
+ status: AvailabilityStatus.SCHEDULED,
+ });
+
+ static readonly OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED = Object.freeze({
+ status: TriggerMessageStatus.ACCEPTED,
+ });
+
+ static readonly OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED = Object.freeze({
+ status: TriggerMessageStatus.REJECTED,
+ });
+
+ static readonly OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED = Object.freeze({
+ status: TriggerMessageStatus.NOT_IMPLEMENTED,
+ });
+
+ static readonly OCPP_DATA_TRANSFER_RESPONSE_REJECTED = Object.freeze({
+ status: DataTransferStatus.REJECTED,
+ });
+
+ private constructor() {
+ // This is intentional
+ }
+}
import { MeterValueMeasurand } from '../types/ocpp/MeterValues';
-import {
- AvailabilityStatus,
- ChargingProfileStatus,
- ClearChargingProfileStatus,
- ConfigurationStatus,
- DataTransferStatus,
- DefaultStatus,
- TriggerMessageStatus,
- UnlockStatus,
-} from '../types/ocpp/Responses';
export default class Constants {
- static readonly OCPP_RESPONSE_EMPTY = Object.freeze({});
- static readonly OCPP_RESPONSE_ACCEPTED = Object.freeze({ status: DefaultStatus.ACCEPTED });
- static readonly OCPP_RESPONSE_REJECTED = Object.freeze({ status: DefaultStatus.REJECTED });
- static readonly OCPP_CONFIGURATION_RESPONSE_ACCEPTED = Object.freeze({
- status: ConfigurationStatus.ACCEPTED,
- });
-
- static readonly OCPP_CONFIGURATION_RESPONSE_REJECTED = Object.freeze({
- status: ConfigurationStatus.REJECTED,
- });
-
- static readonly OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED = Object.freeze({
- status: ConfigurationStatus.REBOOT_REQUIRED,
- });
-
- static readonly OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED = Object.freeze({
- status: ConfigurationStatus.NOT_SUPPORTED,
- });
-
- static readonly OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED = Object.freeze({
- status: ChargingProfileStatus.ACCEPTED,
- });
-
- static readonly OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED = Object.freeze({
- status: ChargingProfileStatus.REJECTED,
- });
-
- static readonly OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED = Object.freeze({
- status: ChargingProfileStatus.NOT_SUPPORTED,
- });
-
- static readonly OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED = Object.freeze({
- status: ClearChargingProfileStatus.ACCEPTED,
- });
-
- static readonly OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN = Object.freeze({
- status: ClearChargingProfileStatus.UNKNOWN,
- });
-
- static readonly OCPP_RESPONSE_UNLOCKED = Object.freeze({ status: UnlockStatus.UNLOCKED });
- static readonly OCPP_RESPONSE_UNLOCK_FAILED = Object.freeze({
- status: UnlockStatus.UNLOCK_FAILED,
- });
-
- static readonly OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED = Object.freeze({
- status: UnlockStatus.NOT_SUPPORTED,
- });
-
- static readonly OCPP_AVAILABILITY_RESPONSE_ACCEPTED = Object.freeze({
- status: AvailabilityStatus.ACCEPTED,
- });
-
- static readonly OCPP_AVAILABILITY_RESPONSE_REJECTED = Object.freeze({
- status: AvailabilityStatus.REJECTED,
- });
-
- static readonly OCPP_AVAILABILITY_RESPONSE_SCHEDULED = Object.freeze({
- status: AvailabilityStatus.SCHEDULED,
- });
-
- static readonly OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED = Object.freeze({
- status: TriggerMessageStatus.ACCEPTED,
- });
-
- static readonly OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED = Object.freeze({
- status: TriggerMessageStatus.REJECTED,
- });
-
- static readonly OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED = Object.freeze({
- status: TriggerMessageStatus.NOT_IMPLEMENTED,
- });
-
- static readonly OCPP_DATA_TRANSFER_RESPONSE_REJECTED = Object.freeze({
- status: DataTransferStatus.REJECTED,
- });
-
static readonly OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL = 60000; // Ms
static readonly OCPP_WEBSOCKET_TIMEOUT = 60000; // Ms
static readonly OCPP_TRIGGER_MESSAGE_DELAY = 500; // Ms