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.
85 lines
3.4 KiB
85 lines
3.4 KiB
package com.yablochkov.ocppstub;
|
|
|
|
import eu.chargetime.ocpp.ServerEvents;
|
|
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
|
|
import eu.chargetime.ocpp.model.SessionInformation;
|
|
import eu.chargetime.ocpp.model.core.*;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.UUID;
|
|
|
|
@Slf4j
|
|
@Component
|
|
@RequiredArgsConstructor
|
|
public class EventHandler implements ServerCoreEventHandler, ServerEvents {
|
|
private final SessionService sessionService;
|
|
private final BootService bootService;
|
|
private final HeartbeatService heartbeatService;
|
|
private final ConfigService configService;
|
|
private final ConnectorStatusService connectorService;
|
|
private final Communicator communicator;
|
|
private final AuthService authService;
|
|
private final TransactionService transactionService;
|
|
|
|
@Override
|
|
public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
|
|
return new AuthorizeConfirmation(authService.authorize(request.getIdTag()));
|
|
}
|
|
|
|
@Override
|
|
public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
|
|
BootNotificationConfirmation response = bootService.handle(sessionIndex, request);
|
|
if (response.getStatus() == RegistrationStatus.Pending) {
|
|
configService.sengConfig(sessionIndex);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
@Override
|
|
public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
|
|
return new DataTransferConfirmation(DataTransferStatus.Rejected);
|
|
}
|
|
|
|
@Override
|
|
public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
|
|
log.info("Heartbeat for session {}", sessionIndex);
|
|
communicator.handleHeartbeat(sessionIndex, request);
|
|
return heartbeatService.handle(sessionIndex, request);
|
|
}
|
|
|
|
@Override
|
|
public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
|
|
return new MeterValuesConfirmation();
|
|
}
|
|
|
|
@Override
|
|
public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
|
|
return transactionService.startByRequest(sessionIndex, request.getConnectorId(), request.getIdTag());
|
|
}
|
|
|
|
@Override
|
|
public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
|
|
communicator.handleStatusNotification(sessionIndex, request);
|
|
return connectorService.handle(sessionIndex, request);
|
|
}
|
|
|
|
@Override
|
|
public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
|
|
log.info("Stop transaction request {}", request);
|
|
transactionService.stopByRequest(sessionIndex, request.getTransactionId());
|
|
return new StopTransactionConfirmation();
|
|
}
|
|
|
|
@Override
|
|
public void newSession(UUID sessionIndex, SessionInformation information) {
|
|
log.info("Start new session {} {} {}", sessionIndex, information.getAddress(), information.getIdentifier());
|
|
sessionService.register(sessionIndex, information);
|
|
}
|
|
|
|
@Override
|
|
public void lostSession(UUID sessionIndex) {
|
|
sessionService.unregister(sessionIndex);
|
|
}
|
|
}
|
|
|