}
}
- public setChargingProfile(connectorId: number, cp: ChargingProfile): void {
- if (Utils.isNullOrUndefined(this.getConnectorStatus(connectorId).chargingProfiles)) {
- logger.error(
- `${this.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization`
- );
- this.getConnectorStatus(connectorId).chargingProfiles = [];
- }
- if (Array.isArray(this.getConnectorStatus(connectorId).chargingProfiles) === false) {
- logger.error(
- `${this.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`
- );
- this.getConnectorStatus(connectorId).chargingProfiles = [];
- }
- let cpReplaced = false;
- if (!Utils.isEmptyArray(this.getConnectorStatus(connectorId).chargingProfiles)) {
- this.getConnectorStatus(connectorId).chargingProfiles?.forEach(
- (chargingProfile: ChargingProfile, index: number) => {
- if (
- chargingProfile.chargingProfileId === cp.chargingProfileId ||
- (chargingProfile.stackLevel === cp.stackLevel &&
- chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)
- ) {
- this.getConnectorStatus(connectorId).chargingProfiles[index] = cp;
- cpReplaced = true;
- }
- }
- );
- }
- !cpReplaced && this.getConnectorStatus(connectorId).chargingProfiles?.push(cp);
- }
-
public resetConnectorStatus(connectorId: number): void {
this.getConnectorStatus(connectorId).idTagLocalAuthorized = false;
this.getConnectorStatus(connectorId).idTagAuthorized = false;
return unitDivider;
}
+ public static setChargingProfile(
+ chargingStation: ChargingStation,
+ connectorId: number,
+ cp: ChargingProfile
+ ): void {
+ if (Utils.isNullOrUndefined(chargingStation.getConnectorStatus(connectorId).chargingProfiles)) {
+ logger.error(
+ `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization`
+ );
+ chargingStation.getConnectorStatus(connectorId).chargingProfiles = [];
+ }
+ if (Array.isArray(chargingStation.getConnectorStatus(connectorId).chargingProfiles) === false) {
+ logger.error(
+ `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`
+ );
+ chargingStation.getConnectorStatus(connectorId).chargingProfiles = [];
+ }
+ let cpReplaced = false;
+ if (!Utils.isEmptyArray(chargingStation.getConnectorStatus(connectorId).chargingProfiles)) {
+ chargingStation
+ .getConnectorStatus(connectorId)
+ .chargingProfiles?.forEach((chargingProfile: ChargingProfile, index: number) => {
+ if (
+ chargingProfile.chargingProfileId === cp.chargingProfileId ||
+ (chargingProfile.stackLevel === cp.stackLevel &&
+ chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)
+ ) {
+ chargingStation.getConnectorStatus(connectorId).chargingProfiles[index] = cp;
+ cpReplaced = true;
+ }
+ });
+ }
+ !cpReplaced && chargingStation.getConnectorStatus(connectorId).chargingProfiles?.push(cp);
+ }
+
/**
* Charging profiles should already be sorted by connectorId and stack level (highest stack level has priority)
*
) {
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
- chargingStation.setChargingProfile(
+ ChargingStationUtils.setChargingProfile(
+ chargingStation,
commandPayload.connectorId,
commandPayload.csChargingProfiles
);
cp: OCPP16ChargingProfile
): boolean {
if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
- chargingStation.setChargingProfile(connectorId, cp);
+ ChargingStationUtils.setChargingProfile(chargingStation, connectorId, cp);
logger.debug(
`${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}, dump their stack: %j`,
chargingStation.getConnectorStatus(connectorId).chargingProfiles
const uuid = Utils.generateUUID();
this.responseHandlers.set(uuid, res);
try {
- if (UIServiceUtils.isProtocolAndVersionSupported(protocol, version) === false) {
- throw new BaseError(`Unsupported UI protocol version: '/${protocol}/${version}'`);
+ const fullProtocol = `${protocol}${version}`;
+ if (UIServiceUtils.isProtocolAndVersionSupported(fullProtocol) === false) {
+ throw new BaseError(`Unsupported UI protocol version: '${fullProtocol}'`);
}
this.registerProtocolVersionUIService(version);
req.on('error', (error) => {
public start(): void {
this.webSocketServer.on('connection', (ws: WebSocket, req: IncomingMessage): void => {
- const [protocol, version] = UIServiceUtils.getProtocolAndVersion(ws.protocol);
- if (UIServiceUtils.isProtocolAndVersionSupported(protocol, version) === false) {
+ if (UIServiceUtils.isProtocolAndVersionSupported(ws.protocol) === false) {
logger.error(
`${this.logPrefix(
moduleName,
'start.server.onconnection'
- )} Unsupported UI protocol version: '${protocol}${version}'`
+ )} Unsupported UI protocol version: '${ws.protocol}'`
);
ws.close(WebSocketCloseEventStatusCode.CLOSE_PROTOCOL_ERROR);
}
+ const [, version] = UIServiceUtils.getProtocolAndVersion(ws.protocol);
this.registerProtocolVersionUIService(version);
ws.on('message', (rawData) => {
const request = this.validateRawDataRequest(rawData);
public static handleProtocols = (
protocols: Set<string>,
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
request: IncomingMessage
): string | false => {
let protocol: Protocol;
return false;
}
for (const fullProtocol of protocols) {
- [protocol, version] = UIServiceUtils.getProtocolAndVersion(fullProtocol);
- if (UIServiceUtils.isProtocolAndVersionSupported(protocol, version) === true) {
+ if (UIServiceUtils.isProtocolAndVersionSupported(fullProtocol) === true) {
return fullProtocol;
}
}
return false;
};
- public static isProtocolAndVersionSupported = (
- protocol: Protocol,
- version: ProtocolVersion
- ): boolean =>
- Object.values(Protocol).includes(protocol) === true &&
- Object.values(ProtocolVersion).includes(version) === true;
+ public static isProtocolAndVersionSupported = (protocolStr: string): boolean => {
+ const [protocol, version] = UIServiceUtils.getProtocolAndVersion(protocolStr);
+ return (
+ Object.values(Protocol).includes(protocol) === true &&
+ Object.values(ProtocolVersion).includes(version) === true
+ );
+ };
public static getProtocolAndVersion = (protocolStr: string): [Protocol, ProtocolVersion] => {
const protocolIndex = protocolStr.indexOf(Protocol.UI);