|
|
|
@ -2,7 +2,6 @@ package com.yablochkov.ocppstub; |
|
|
|
|
|
|
|
|
|
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile; |
|
|
|
|
import eu.chargetime.ocpp.model.core.*; |
|
|
|
|
import java.util.concurrent.CompletionStage; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
@ -19,36 +18,32 @@ public class ConfigService { |
|
|
|
|
@Lazy |
|
|
|
|
@Autowired private ServerCoreProfile coreProfile; |
|
|
|
|
|
|
|
|
|
public boolean sengConfig(UUID sessionIndex) { |
|
|
|
|
public void sengConfig(UUID sessionIndex) { |
|
|
|
|
log.info("Sending configuration"); |
|
|
|
|
ChangeConfigurationRequest configurationRequest = coreProfile |
|
|
|
|
.createChangeConfigurationRequest("AuthorizationKey", DEFAULT_KEY); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
var feature = 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 true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
log.error("Charge point don't confirm password change"); |
|
|
|
|
throw new RuntimeException("CP don't confirm pass change"); |
|
|
|
|
}) |
|
|
|
|
.thenApply((state) -> { |
|
|
|
|
log.info("Closing session {}", sessionIndex); |
|
|
|
|
server.closeSession(sessionIndex); |
|
|
|
|
return state; |
|
|
|
|
}); |
|
|
|
|
return feature.toCompletableFuture().get(); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|