1 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
3 import * as url from
'url';
5 import { ChangeAvailabilityRequest
, ChangeConfigurationRequest
, ClearChargingProfileRequest
, GetConfigurationRequest
, GetDiagnosticsRequest
, OCPP16AvailabilityType
, OCPP16IncomingRequestCommand
, RemoteStartTransactionRequest
, RemoteStopTransactionRequest
, ResetRequest
, SetChargingProfileRequest
, UnlockConnectorRequest
} from
'../../../types/ocpp/1.6/Requests';
6 import { ChangeAvailabilityResponse
, ChangeConfigurationResponse
, ClearChargingProfileResponse
, GetConfigurationResponse
, GetDiagnosticsResponse
, SetChargingProfileResponse
, UnlockConnectorResponse
} from
'../../../types/ocpp/1.6/Responses';
7 import { ChargingProfilePurposeType
, OCPP16ChargingProfile
} from
'../../../types/ocpp/1.6/ChargingProfile';
8 import { Client
, FTPResponse
} from
'basic-ftp';
9 import { IncomingRequestCommand
, RequestCommand
} from
'../../../types/ocpp/Requests';
10 import { OCPP16AuthorizationStatus
, OCPP16StopTransactionReason
} from
'../../../types/ocpp/1.6/Transaction';
12 import Constants from
'../../../utils/Constants';
13 import { DefaultResponse
} from
'../../../types/ocpp/Responses';
14 import { ErrorType
} from
'../../../types/ocpp/ErrorType';
15 import { MessageType
} from
'../../../types/ocpp/MessageType';
16 import { OCPP16ChargePointStatus
} from
'../../../types/ocpp/1.6/ChargePointStatus';
17 import { OCPP16DiagnosticsStatus
} from
'../../../types/ocpp/1.6/DiagnosticsStatus';
18 import { OCPP16StandardParametersKey
} from
'../../../types/ocpp/1.6/Configuration';
19 import { OCPPConfigurationKey
} from
'../../../types/ocpp/Configuration';
20 import OCPPError from
'../OCPPError';
21 import OCPPIncomingRequestService from
'../OCPPIncomingRequestService';
22 import Utils from
'../../../utils/Utils';
24 import logger from
'../../../utils/Logger';
25 import path from
'path';
26 import tar from
'tar';
28 export default class OCPP16IncomingRequestService
extends OCPPIncomingRequestService
{
29 public async handleRequest(messageId
: string, commandName
: OCPP16IncomingRequestCommand
, commandPayload
: Record
<string, unknown
>): Promise
<void> {
31 const methodName
= `handleRequest${commandName}`;
33 if (typeof this[methodName
] === 'function') {
35 // Call the method to build the response
36 response
= await this[methodName
](commandPayload
);
39 logger
.error(this.chargingStation
.logPrefix() + ' Handle request error: %j', error
);
40 // Send back an error response to inform backend
41 await this.chargingStation
.ocppRequestService
.sendError(messageId
, error
, commandName
);
46 const error
= new OCPPError(ErrorType
.NOT_IMPLEMENTED
, `${commandName} is not implemented to handle payload ${JSON.stringify(commandPayload, null, 2)}`);
47 await this.chargingStation
.ocppRequestService
.sendError(messageId
, error
, commandName
);
50 // Send the built response
51 await this.chargingStation
.ocppRequestService
.sendMessage(messageId
, response
, MessageType
.CALL_RESULT_MESSAGE
, commandName
);
54 // Simulate charging station restart
55 private handleRequestReset(commandPayload
: ResetRequest
): DefaultResponse
{
56 // eslint-disable-next-line @typescript-eslint/no-misused-promises
57 setImmediate(async (): Promise
<void> => {
58 await this.chargingStation
.stop(commandPayload
.type + 'Reset' as OCPP16StopTransactionReason
);
59 await Utils
.sleep(this.chargingStation
.stationInfo
.resetTime
);
60 this.chargingStation
.start();
62 logger
.info(`${this.chargingStation.logPrefix()} ${commandPayload.type} reset command received, simulating it. The station will be back online in ${Utils.milliSecondsToHHMMSS(this.chargingStation.stationInfo.resetTime)}`);
63 return Constants
.OCPP_RESPONSE_ACCEPTED
;
66 private handleRequestClearCache(): DefaultResponse
{
67 return Constants
.OCPP_RESPONSE_ACCEPTED
;
70 private async handleRequestUnlockConnector(commandPayload
: UnlockConnectorRequest
): Promise
<UnlockConnectorResponse
> {
71 const connectorId
= commandPayload
.connectorId
;
72 if (connectorId
=== 0) {
73 logger
.error(this.chargingStation
.logPrefix() + ' Trying to unlock connector ' + connectorId
.toString());
74 return Constants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
76 if (this.chargingStation
.getConnector(connectorId
)?.transactionStarted
) {
77 const transactionId
= this.chargingStation
.getConnector(connectorId
).transactionId
;
78 const stopResponse
= await this.chargingStation
.ocppRequestService
.sendStopTransaction(transactionId
,
79 this.chargingStation
.getEnergyActiveImportRegisterByTransactionId(transactionId
),
80 this.chargingStation
.getTransactionIdTag(transactionId
),
81 OCPP16StopTransactionReason
.UNLOCK_COMMAND
);
82 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
83 return Constants
.OCPP_RESPONSE_UNLOCKED
;
85 return Constants
.OCPP_RESPONSE_UNLOCK_FAILED
;
87 await this.chargingStation
.ocppRequestService
.sendStatusNotification(connectorId
, OCPP16ChargePointStatus
.AVAILABLE
);
88 this.chargingStation
.getConnector(connectorId
).status = OCPP16ChargePointStatus
.AVAILABLE
;
89 return Constants
.OCPP_RESPONSE_UNLOCKED
;
92 private handleRequestGetConfiguration(commandPayload
: GetConfigurationRequest
): GetConfigurationResponse
{
93 const configurationKey
: OCPPConfigurationKey
[] = [];
94 const unknownKey
: string[] = [];
95 if (Utils
.isEmptyArray(commandPayload
.key
)) {
96 for (const configuration
of this.chargingStation
.configuration
.configurationKey
) {
97 if (Utils
.isUndefined(configuration
.visible
)) {
98 configuration
.visible
= true;
100 if (!configuration
.visible
) {
103 configurationKey
.push({
104 key
: configuration
.key
,
105 readonly: configuration
.readonly,
106 value
: configuration
.value
,
110 for (const key
of commandPayload
.key
) {
111 const keyFound
= this.chargingStation
.getConfigurationKey(key
);
113 if (Utils
.isUndefined(keyFound
.visible
)) {
114 keyFound
.visible
= true;
116 if (!keyFound
.visible
) {
119 configurationKey
.push({
121 readonly: keyFound
.readonly,
122 value
: keyFound
.value
,
125 unknownKey
.push(key
);
135 private handleRequestChangeConfiguration(commandPayload
: ChangeConfigurationRequest
): ChangeConfigurationResponse
{
136 // JSON request fields type sanity check
137 if (!Utils
.isString(commandPayload
.key
)) {
138 logger
.error(`${this.chargingStation.logPrefix()} ${RequestCommand.CHANGE_CONFIGURATION} request key field is not a string:`, commandPayload
);
140 if (!Utils
.isString(commandPayload
.value
)) {
141 logger
.error(`${this.chargingStation.logPrefix()} ${RequestCommand.CHANGE_CONFIGURATION} request value field is not a string:`, commandPayload
);
143 const keyToChange
= this.chargingStation
.getConfigurationKey(commandPayload
.key
, true);
145 return Constants
.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED
;
146 } else if (keyToChange
&& keyToChange
.readonly) {
147 return Constants
.OCPP_CONFIGURATION_RESPONSE_REJECTED
;
148 } else if (keyToChange
&& !keyToChange
.readonly) {
149 const keyIndex
= this.chargingStation
.configuration
.configurationKey
.indexOf(keyToChange
);
150 let valueChanged
= false;
151 if (this.chargingStation
.configuration
.configurationKey
[keyIndex
].value
!== commandPayload
.value
) {
152 this.chargingStation
.configuration
.configurationKey
[keyIndex
].value
= commandPayload
.value
;
155 let triggerHeartbeatRestart
= false;
156 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartBeatInterval
&& valueChanged
) {
157 this.chargingStation
.setConfigurationKeyValue(OCPP16StandardParametersKey
.HeartbeatInterval
, commandPayload
.value
);
158 triggerHeartbeatRestart
= true;
160 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartbeatInterval
&& valueChanged
) {
161 this.chargingStation
.setConfigurationKeyValue(OCPP16StandardParametersKey
.HeartBeatInterval
, commandPayload
.value
);
162 triggerHeartbeatRestart
= true;
164 if (triggerHeartbeatRestart
) {
165 this.chargingStation
.restartHeartbeat();
167 if (keyToChange
.key
=== OCPP16StandardParametersKey
.WebSocketPingInterval
&& valueChanged
) {
168 this.chargingStation
.restartWebSocketPing();
170 if (keyToChange
.reboot
) {
171 return Constants
.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED
;
173 return Constants
.OCPP_CONFIGURATION_RESPONSE_ACCEPTED
;
177 private handleRequestSetChargingProfile(commandPayload
: SetChargingProfileRequest
): SetChargingProfileResponse
{
178 if (!this.chargingStation
.getConnector(commandPayload
.connectorId
)) {
179 logger
.error(`${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
180 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
182 if (commandPayload
.csChargingProfiles
.chargingProfilePurpose
=== ChargingProfilePurposeType
.CHARGE_POINT_MAX_PROFILE
&& commandPayload
.connectorId
!== 0) {
183 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
185 if (commandPayload
.csChargingProfiles
.chargingProfilePurpose
=== ChargingProfilePurposeType
.TX_PROFILE
&& (commandPayload
.connectorId
=== 0 || !this.chargingStation
.getConnector(commandPayload
.connectorId
)?.transactionStarted
)) {
186 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
188 this.chargingStation
.setChargingProfile(commandPayload
.connectorId
, commandPayload
.csChargingProfiles
);
189 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set, dump their stack: %j`, this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
);
190 return Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
193 private handleRequestClearChargingProfile(commandPayload
: ClearChargingProfileRequest
): ClearChargingProfileResponse
{
194 if (!this.chargingStation
.getConnector(commandPayload
.connectorId
)) {
195 logger
.error(`${this.chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
196 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
198 if (commandPayload
.connectorId
&& !Utils
.isEmptyArray(this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
)) {
199 this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
= [];
200 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
);
201 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
203 if (!commandPayload
.connectorId
) {
204 let clearedCP
= false;
205 for (const connector
in this.chargingStation
.connectors
) {
206 if (!Utils
.isEmptyArray(this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).chargingProfiles
)) {
207 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).chargingProfiles
?.forEach((chargingProfile
: OCPP16ChargingProfile
, index
: number) => {
208 let clearCurrentCP
= false;
209 if (chargingProfile
.chargingProfileId
=== commandPayload
.id
) {
210 clearCurrentCP
= true;
212 if (!commandPayload
.chargingProfilePurpose
&& chargingProfile
.stackLevel
=== commandPayload
.stackLevel
) {
213 clearCurrentCP
= true;
215 if (!chargingProfile
.stackLevel
&& chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
) {
216 clearCurrentCP
= true;
218 if (chargingProfile
.stackLevel
=== commandPayload
.stackLevel
&& chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
) {
219 clearCurrentCP
= true;
221 if (clearCurrentCP
) {
222 this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
[index
] = {} as OCPP16ChargingProfile
;
223 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation
.getConnector(commandPayload
.connectorId
).chargingProfiles
);
230 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
233 return Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
236 private async handleRequestChangeAvailability(commandPayload
: ChangeAvailabilityRequest
): Promise
<ChangeAvailabilityResponse
> {
237 const connectorId
: number = commandPayload
.connectorId
;
238 if (!this.chargingStation
.getConnector(connectorId
)) {
239 logger
.error(`${this.chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`);
240 return Constants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
242 const chargePointStatus
: OCPP16ChargePointStatus
= commandPayload
.type === OCPP16AvailabilityType
.OPERATIVE
? OCPP16ChargePointStatus
.AVAILABLE
: OCPP16ChargePointStatus
.UNAVAILABLE
;
243 if (connectorId
=== 0) {
244 let response
: ChangeAvailabilityResponse
= Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
245 for (const connector
in this.chargingStation
.connectors
) {
246 if (this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).transactionStarted
) {
247 response
= Constants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
249 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).availability
= commandPayload
.type;
250 if (response
=== Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
) {
251 await this.chargingStation
.ocppRequestService
.sendStatusNotification(Utils
.convertToInt(connector
), chargePointStatus
);
252 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).status = chargePointStatus
;
256 } else if (connectorId
> 0 && (this.chargingStation
.getConnector(0).availability
=== OCPP16AvailabilityType
.OPERATIVE
|| (this.chargingStation
.getConnector(0).availability
=== OCPP16AvailabilityType
.INOPERATIVE
&& commandPayload
.type === OCPP16AvailabilityType
.INOPERATIVE
))) {
257 if (this.chargingStation
.getConnector(connectorId
)?.transactionStarted
) {
258 this.chargingStation
.getConnector(connectorId
).availability
= commandPayload
.type;
259 return Constants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
261 this.chargingStation
.getConnector(connectorId
).availability
= commandPayload
.type;
262 await this.chargingStation
.ocppRequestService
.sendStatusNotification(connectorId
, chargePointStatus
);
263 this.chargingStation
.getConnector(connectorId
).status = chargePointStatus
;
264 return Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
266 return Constants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
269 private async handleRequestRemoteStartTransaction(commandPayload
: RemoteStartTransactionRequest
): Promise
<DefaultResponse
> {
270 const transactionConnectorId
: number = commandPayload
.connectorId
;
271 if (transactionConnectorId
) {
272 await this.chargingStation
.ocppRequestService
.sendStatusNotification(transactionConnectorId
, OCPP16ChargePointStatus
.PREPARING
);
273 this.chargingStation
.getConnector(transactionConnectorId
).status = OCPP16ChargePointStatus
.PREPARING
;
274 if (this.chargingStation
.isChargingStationAvailable() && this.chargingStation
.isConnectorAvailable(transactionConnectorId
)) {
275 // Check if authorized
276 if (this.chargingStation
.getAuthorizeRemoteTxRequests()) {
277 let authorized
= false;
278 if (this.chargingStation
.getLocalAuthListEnabled() && this.chargingStation
.hasAuthorizedTags()
279 && this.chargingStation
.authorizedTags
.find((value
) => value
=== commandPayload
.idTag
)) {
282 if (!authorized
|| (authorized
&& this.chargingStation
.getMayAuthorizeAtRemoteStart())) {
283 const authorizeResponse
= await this.chargingStation
.ocppRequestService
.sendAuthorize(transactionConnectorId
, commandPayload
.idTag
);
284 if (authorizeResponse
?.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
291 // Authorization successful, start transaction
292 if (this.setRemoteStartTransactionChargingProfile(transactionConnectorId
, commandPayload
.chargingProfile
)) {
293 if ((await this.chargingStation
.ocppRequestService
.sendStartTransaction(transactionConnectorId
, commandPayload
.idTag
)).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
294 logger
.debug(this.chargingStation
.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation
.stationInfo
.chargingStationId
+ '#' + transactionConnectorId
.toString() + ' for idTag ' + commandPayload
.idTag
);
295 return Constants
.OCPP_RESPONSE_ACCEPTED
;
297 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
299 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
301 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
303 // No authorization check required, start transaction
304 if (this.setRemoteStartTransactionChargingProfile(transactionConnectorId
, commandPayload
.chargingProfile
)) {
305 if ((await this.chargingStation
.ocppRequestService
.sendStartTransaction(transactionConnectorId
, commandPayload
.idTag
)).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
306 logger
.debug(this.chargingStation
.logPrefix() + ' Transaction remotely STARTED on ' + this.chargingStation
.stationInfo
.chargingStationId
+ '#' + transactionConnectorId
.toString() + ' for idTag ' + commandPayload
.idTag
);
307 return Constants
.OCPP_RESPONSE_ACCEPTED
;
309 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
311 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
313 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
315 return this.notifyRemoteStartTransactionRejected(transactionConnectorId
, commandPayload
.idTag
);
318 private async notifyRemoteStartTransactionRejected(connectorId
: number, idTag
: string): Promise
<DefaultResponse
> {
319 if (this.chargingStation
.getConnector(connectorId
).status !== OCPP16ChargePointStatus
.AVAILABLE
) {
320 await this.chargingStation
.ocppRequestService
.sendStatusNotification(connectorId
, OCPP16ChargePointStatus
.AVAILABLE
);
321 this.chargingStation
.getConnector(connectorId
).status = OCPP16ChargePointStatus
.AVAILABLE
;
323 logger
.warn(this.chargingStation
.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + connectorId
.toString() + ', idTag ' + idTag
+ ', availability ' + this.chargingStation
.getConnector(connectorId
).availability
+ ', status ' + this.chargingStation
.getConnector(connectorId
).status);
324 return Constants
.OCPP_RESPONSE_REJECTED
;
327 private setRemoteStartTransactionChargingProfile(connectorId
: number, cp
: OCPP16ChargingProfile
): boolean {
328 if (cp
&& cp
.chargingProfilePurpose
=== ChargingProfilePurposeType
.TX_PROFILE
) {
329 this.chargingStation
.setChargingProfile(connectorId
, cp
);
330 logger
.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction, dump their stack: %j`, this.chargingStation
.getConnector(connectorId
).chargingProfiles
);
332 } else if (cp
&& cp
.chargingProfilePurpose
!== ChargingProfilePurposeType
.TX_PROFILE
) {
333 logger
.warn(`${this.chargingStation.logPrefix()} Not allowed to set ${cp.chargingProfilePurpose} charging profile(s) at remote start transaction`);
340 private async handleRequestRemoteStopTransaction(commandPayload
: RemoteStopTransactionRequest
): Promise
<DefaultResponse
> {
341 const transactionId
= commandPayload
.transactionId
;
342 for (const connector
in this.chargingStation
.connectors
) {
343 if (Utils
.convertToInt(connector
) > 0 && this.chargingStation
.getConnector(Utils
.convertToInt(connector
))?.transactionId
=== transactionId
) {
344 await this.chargingStation
.ocppRequestService
.sendStatusNotification(Utils
.convertToInt(connector
), OCPP16ChargePointStatus
.FINISHING
);
345 this.chargingStation
.getConnector(Utils
.convertToInt(connector
)).status = OCPP16ChargePointStatus
.FINISHING
;
346 await this.chargingStation
.ocppRequestService
.sendStopTransaction(transactionId
, this.chargingStation
.getEnergyActiveImportRegisterByTransactionId(transactionId
),
347 this.chargingStation
.getTransactionIdTag(transactionId
));
348 return Constants
.OCPP_RESPONSE_ACCEPTED
;
351 logger
.info(this.chargingStation
.logPrefix() + ' Trying to remote stop a non existing transaction ' + transactionId
.toString());
352 return Constants
.OCPP_RESPONSE_REJECTED
;
355 private async handleRequestGetDiagnostics(commandPayload
: GetDiagnosticsRequest
): Promise
<GetDiagnosticsResponse
> {
356 logger
.debug(this.chargingStation
.logPrefix() + ' ' + IncomingRequestCommand
.GET_DIAGNOSTICS
+ ' request received: %j', commandPayload
);
357 const uri
= new url
.URL(commandPayload
.location
);
358 if (uri
.protocol
.startsWith('ftp:')) {
359 let ftpClient
: Client
;
361 const logFiles
= fs
.readdirSync(path
.resolve(__dirname
, '../../../../')).filter((file
) => file
.endsWith('.log')).map((file
) => path
.join('./', file
));
362 const diagnosticsArchive
= this.chargingStation
.stationInfo
.chargingStationId
+ '_logs.tar.gz';
363 tar
.create({ gzip
: true }, logFiles
).pipe(fs
.createWriteStream(diagnosticsArchive
));
364 ftpClient
= new Client();
365 const accessResponse
= await ftpClient
.access({
367 ...(uri
.port
!== '') && { port
: Utils
.convertToInt(uri
.port
) },
368 ...(uri
.username
!== '') && { user
: uri
.username
},
369 ...(uri
.password
!== '') && { password
: uri
.password
},
371 let uploadResponse
: FTPResponse
;
372 if (accessResponse
.code
=== 220) {
373 // eslint-disable-next-line @typescript-eslint/no-misused-promises
374 ftpClient
.trackProgress(async (info
) => {
375 logger
.info(`${this.chargingStation.logPrefix()} ${info.bytes / 1024} bytes transferred from diagnostics archive ${info.name}`);
376 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.Uploading
);
378 uploadResponse
= await ftpClient
.uploadFrom(path
.join(path
.resolve(__dirname
, '../../../../'), diagnosticsArchive
), uri
.pathname
+ diagnosticsArchive
);
379 if (uploadResponse
.code
=== 226) {
380 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.Uploaded
);
384 return { fileName
: diagnosticsArchive
};
386 throw new OCPPError(ErrorType
.GENERIC_ERROR
, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`);
388 throw new OCPPError(ErrorType
.GENERIC_ERROR
, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`);
390 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.UploadFailed
);
394 return this.handleIncomingRequestError(IncomingRequestCommand
.GET_DIAGNOSTICS
, error
, Constants
.OCPP_RESPONSE_EMPTY
);
397 logger
.error(`${this.chargingStation.logPrefix()} Unsupported protocol ${uri.protocol} to transfer the diagnostic logs archive`);
398 await this.chargingStation
.ocppRequestService
.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus
.UploadFailed
);
399 return Constants
.OCPP_RESPONSE_EMPTY
;