- // Monitor authorization file
- FileUtils.watchJsonFile<string[]>(
- this.logPrefix(),
- FileType.Authorization,
- ChargingStationUtils.getAuthorizationFile(this.stationInfo),
- this.authorizedTags
- );
- // Monitor charging station template file
- FileUtils.watchJsonFile(
- this.logPrefix(),
- FileType.ChargingStationTemplate,
- this.templateFile,
- null,
- (event, filename): void => {
- if (filename && event === 'change') {
- try {
- logger.debug(
- `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
- this.templateFile
- } file have changed, reload`
- );
- // Initialize
- this.initialize();
- // Restart the ATG
- this.stopAutomaticTransactionGenerator();
- this.startAutomaticTransactionGenerator();
- if (this.getEnableStatistics()) {
- this.performanceStatistics.restart();
- } else {
- this.performanceStatistics.stop();
- }
- // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
- } catch (error) {
- logger.error(
- `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error: %j`,
- error
- );
- }
- }
- }
- );
- parentPort.postMessage({
- id: ChargingStationWorkerMessageEvents.STARTED,
- data: { id: this.stationInfo.chargingStationId },
- });
- }
-
- public async stop(reason: StopTransactionReason = StopTransactionReason.NONE): Promise<void> {
- // Stop message sequence
- await this.stopMessageSequence(reason);
- for (const connectorId of this.connectors.keys()) {
- if (connectorId > 0) {
- await this.ocppRequestService.requestHandler<
- StatusNotificationRequest,
- StatusNotificationResponse
- >(this, RequestCommand.STATUS_NOTIFICATION, {
- connectorId,
- status: ChargePointStatus.UNAVAILABLE,
- errorCode: ChargePointErrorCode.NO_ERROR,
- });
- this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE;
- }
- }
- if (this.isWebSocketConnectionOpened()) {
- this.wsConnection.close();
- }
- if (this.getEnableStatistics()) {
- this.performanceStatistics.stop();
- }
- this.bootNotificationResponse = null;
- parentPort.postMessage({
- id: ChargingStationWorkerMessageEvents.STOPPED,
- data: { id: this.stationInfo.chargingStationId },
- });
- this.stopped = true;
- }
-
- public async reset(reason?: StopTransactionReason): Promise<void> {
- await this.stop(reason);
- await Utils.sleep(this.stationInfo.resetTime);
- this.initialize();
- this.start();