You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
2.0 KiB
49 lines
2.0 KiB
package com.yablochkov.ocppstub;
|
|
|
|
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
|
|
import eu.chargetime.ocpp.model.core.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.UUID;
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class ConfigService {
|
|
private final static String DEFAULT_KEY = "0001020304050607FFFFFFFFFFFFFFFFFFFFFFFF";
|
|
@Lazy
|
|
@Autowired private OcppStub server;
|
|
@Lazy
|
|
@Autowired private ServerCoreProfile coreProfile;
|
|
|
|
public void sengConfig(UUID sessionIndex) {
|
|
log.info("Sending configuration");
|
|
ChangeConfigurationRequest configurationRequest = coreProfile
|
|
.createChangeConfigurationRequest("AuthorizationKey", DEFAULT_KEY);
|
|
|
|
try {
|
|
server.send(sessionIndex, configurationRequest)
|
|
.thenApply(confirmation -> {
|
|
log.debug("Get confirmation");
|
|
if (confirmation instanceof ChangeConfigurationConfirmation) {
|
|
log.debug("Confirmation type is ChangeConfigurationConfirmation");
|
|
ConfigurationStatus status = ((ChangeConfigurationConfirmation) confirmation).getStatus();
|
|
if (status == ConfigurationStatus.Accepted) {
|
|
log.debug("Confirmation status is accepted");
|
|
return Void.TYPE;
|
|
}
|
|
}
|
|
log.error("Charge point don't confirm password change");
|
|
throw new RuntimeException("CP don't confirm pass change");
|
|
})
|
|
.thenRunAsync(() -> {
|
|
log.info("Closing session {}", sessionIndex);
|
|
server.closeSession(sessionIndex);
|
|
});
|
|
} catch (Exception e) {
|
|
log.error("Exception on ChangeConfiguration", e);
|
|
}
|
|
}
|
|
}
|
|
|