2015-06-01 08:19:09 -07:00
|
|
|
/*******************************************************************************
|
2017-07-20 12:06:26 -07:00
|
|
|
* The MIT License (MIT)
|
2015-06-01 08:19:09 -07:00
|
|
|
*
|
2017-07-20 12:06:26 -07:00
|
|
|
* Copyright (c) 2015-207 V2G Clarity (Dr.-Ing. Marc Mültin)
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2015-06-01 08:19:09 -07:00
|
|
|
*******************************************************************************/
|
2017-10-13 03:30:15 -07:00
|
|
|
package com.v2gclarity.risev2g.secc.states;
|
2015-06-01 08:19:09 -07:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBElement;
|
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2017-10-13 03:30:15 -07:00
|
|
|
import com.v2gclarity.risev2g.secc.evseController.IACEVSEController;
|
|
|
|
import com.v2gclarity.risev2g.secc.evseController.IDCEVSEController;
|
|
|
|
import com.v2gclarity.risev2g.secc.session.V2GCommunicationSessionSECC;
|
|
|
|
import com.v2gclarity.risev2g.shared.enumerations.V2GMessages;
|
|
|
|
import com.v2gclarity.risev2g.shared.messageHandling.ReactionToIncomingMessage;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.ACEVChargeParameterType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.BodyBaseType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.ChargeParameterDiscoveryReqType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.ChargeParameterDiscoveryResType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.DCEVChargeParameterType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.EVSEProcessingType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.EnergyTransferModeType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.ResponseCodeType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.SAScheduleListType;
|
|
|
|
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.V2GMessage;
|
2015-06-01 08:19:09 -07:00
|
|
|
|
|
|
|
public class WaitForChargeParameterDiscoveryReq extends ServerState {
|
|
|
|
|
|
|
|
private ChargeParameterDiscoveryResType chargeParameterDiscoveryRes;
|
|
|
|
private boolean waitingForSchedule;
|
|
|
|
|
|
|
|
public WaitForChargeParameterDiscoveryReq(V2GCommunicationSessionSECC commSessionContext) {
|
|
|
|
super(commSessionContext);
|
|
|
|
chargeParameterDiscoveryRes = new ChargeParameterDiscoveryResType();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ReactionToIncomingMessage processIncomingMessage(Object message) {
|
|
|
|
if (isIncomingMessageValid(message, ChargeParameterDiscoveryReqType.class, chargeParameterDiscoveryRes)) {
|
|
|
|
V2GMessage v2gMessageReq = (V2GMessage) message;
|
|
|
|
ChargeParameterDiscoveryReqType chargeParameterDiscoveryReq =
|
|
|
|
(ChargeParameterDiscoveryReqType) v2gMessageReq.getBody().getBodyElement().getValue();
|
|
|
|
|
|
|
|
if (isResponseCodeOK(chargeParameterDiscoveryReq)) {
|
|
|
|
getCommSessionContext().setRequestedEnergyTransferMode(
|
|
|
|
chargeParameterDiscoveryReq.getRequestedEnergyTransferMode());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request a new schedule in case of first ChargeParameterDiscoveryReq.
|
2016-04-06 17:09:46 -07:00
|
|
|
* If EVSEProcessingType.ONGOING was sent in previous ChargeParameterDiscoveryRes
|
|
|
|
* message, do not request again.
|
2015-06-01 08:19:09 -07:00
|
|
|
*/
|
|
|
|
if (!isWaitingForSchedule()) {
|
|
|
|
// TODO we need a timeout mechanism here so that a response can be sent within 2s
|
|
|
|
setWaitingForSchedule(true);
|
2016-04-06 17:09:46 -07:00
|
|
|
|
|
|
|
// The max. number of PMaxScheduleEntries and SalesTariffEntries is 1024 if not provided otherwise by EVCC
|
|
|
|
int maxEntriesSAScheduleTuple = (chargeParameterDiscoveryReq.getMaxEntriesSAScheduleTuple() != null) ?
|
|
|
|
chargeParameterDiscoveryReq.getMaxEntriesSAScheduleTuple() : 1024;
|
|
|
|
|
2017-08-21 13:13:09 -07:00
|
|
|
Long departureTime = chargeParameterDiscoveryReq.getEVChargeParameter().getValue().getDepartureTime();
|
|
|
|
|
2015-06-01 08:19:09 -07:00
|
|
|
getCommSessionContext().setSaSchedules(
|
2016-04-06 17:09:46 -07:00
|
|
|
getCommSessionContext().getBackendInterface().getSAScheduleList(
|
|
|
|
maxEntriesSAScheduleTuple,
|
2017-08-21 13:13:09 -07:00
|
|
|
(departureTime != null) ? departureTime.longValue() : 0,
|
2016-04-06 17:09:46 -07:00
|
|
|
getXMLSignatureRefElements())
|
|
|
|
);
|
2015-06-01 08:19:09 -07:00
|
|
|
}
|
|
|
|
|
2017-09-15 07:15:25 -07:00
|
|
|
// TODO An integration to a backend system which provides the SalesTariff would be needed here
|
2015-06-01 08:19:09 -07:00
|
|
|
|
|
|
|
if (chargeParameterDiscoveryReq.getRequestedEnergyTransferMode().toString().startsWith("AC"))
|
|
|
|
chargeParameterDiscoveryRes.setEVSEChargeParameter(
|
|
|
|
((IACEVSEController) getCommSessionContext().getACEvseController()).getACEVSEChargeParameter());
|
|
|
|
else
|
|
|
|
chargeParameterDiscoveryRes.setEVSEChargeParameter(
|
|
|
|
((IDCEVSEController) getCommSessionContext().getDCEvseController()).getDCEVSEChargeParameter());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO The next state depends as well on the EVSENotification:
|
|
|
|
* - NONE: PowerDeliveryReq (ChargeProgress of ChargeParameterDiscoveryReq = Start)
|
|
|
|
* - RENEGOTIATION: ChargeParameterDiscoveryReq
|
|
|
|
* - STOP: PowerDeliveryReq (ChargeProgress of ChargeParameterDiscoveryReq = Stop)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (getCommSessionContext().getSaSchedules() == null) {
|
|
|
|
getLogger().debug("No SAScheduleList available yet, setting EVSEProcessingType to ONGOING");
|
|
|
|
chargeParameterDiscoveryRes.setEVSEProcessing(EVSEProcessingType.ONGOING);
|
|
|
|
return getSendMessage(chargeParameterDiscoveryRes, V2GMessages.CHARGE_PARAMETER_DISCOVERY_REQ);
|
|
|
|
} else {
|
|
|
|
getLogger().debug("SAScheduleList has been provided");
|
|
|
|
chargeParameterDiscoveryRes.setEVSEProcessing(EVSEProcessingType.FINISHED);
|
|
|
|
setWaitingForSchedule(false);
|
|
|
|
chargeParameterDiscoveryRes.setSASchedules(
|
|
|
|
getSASchedulesAsJAXBElement(getCommSessionContext().getSaSchedules()));
|
|
|
|
|
2017-07-20 06:50:43 -07:00
|
|
|
/*
|
|
|
|
* Note 3 of [V2G2-905] states:
|
|
|
|
* "If the secondary actor is unaware of which authentication mode is used during EVCC-SECC
|
|
|
|
* communication (EIM/ PnC), it can simply always sign the SalesTariff."
|
|
|
|
*
|
|
|
|
* Therefore, we do not check here if PnC is used but just always sign the SalesTariff.
|
|
|
|
* Without a real backend functionality, we must sign the SalesTariff by using the SecurityUtils
|
|
|
|
* class.
|
|
|
|
*/
|
|
|
|
//Set signing private key of Mobility Operator Sub-CA 2
|
|
|
|
setSignaturePrivateKey(getCommSessionContext().getBackendInterface().getMOSubCA2PrivateKey());
|
2016-04-06 17:09:46 -07:00
|
|
|
|
2015-06-01 08:19:09 -07:00
|
|
|
if (chargeParameterDiscoveryReq.getRequestedEnergyTransferMode().toString().startsWith("AC"))
|
|
|
|
return getSendMessage(chargeParameterDiscoveryRes, V2GMessages.POWER_DELIVERY_REQ);
|
|
|
|
else
|
|
|
|
return getSendMessage(chargeParameterDiscoveryRes, V2GMessages.CABLE_CHECK_REQ);
|
|
|
|
}
|
|
|
|
} else {
|
2017-08-20 14:26:22 -07:00
|
|
|
setMandatoryFieldsForFailedRes(chargeParameterDiscoveryRes, chargeParameterDiscoveryRes.getResponseCode());
|
2015-06-01 08:19:09 -07:00
|
|
|
}
|
2017-07-20 06:50:43 -07:00
|
|
|
} else {
|
2017-08-20 14:26:22 -07:00
|
|
|
if (chargeParameterDiscoveryRes.getResponseCode().equals(ResponseCodeType.FAILED_SEQUENCE_ERROR)) {
|
|
|
|
BodyBaseType responseMessage = getSequenceErrorResMessage(new ChargeParameterDiscoveryResType(), message);
|
|
|
|
|
|
|
|
return getSendMessage(responseMessage, V2GMessages.NONE, chargeParameterDiscoveryRes.getResponseCode());
|
|
|
|
} else {
|
|
|
|
setMandatoryFieldsForFailedRes(chargeParameterDiscoveryRes, chargeParameterDiscoveryRes.getResponseCode());
|
|
|
|
}
|
2017-07-20 06:50:43 -07:00
|
|
|
}
|
2015-06-01 08:19:09 -07:00
|
|
|
|
2017-08-20 14:26:22 -07:00
|
|
|
return getSendMessage(chargeParameterDiscoveryRes, V2GMessages.NONE, chargeParameterDiscoveryRes.getResponseCode());
|
2015-06-01 08:19:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isResponseCodeOK(ChargeParameterDiscoveryReqType chargeParameterDiscoveryReq) {
|
|
|
|
// Check if the EV's requested EnergyTransferModeType is supported
|
|
|
|
ArrayList<EnergyTransferModeType> evseSupported = getCommSessionContext().getSupportedEnergyTransferModes();
|
|
|
|
EnergyTransferModeType evRequested = chargeParameterDiscoveryReq.getRequestedEnergyTransferMode();
|
|
|
|
|
|
|
|
if (!evseSupported.contains(evRequested)) {
|
|
|
|
chargeParameterDiscoveryRes.setResponseCode(ResponseCodeType.FAILED_WRONG_ENERGY_TRANSFER_MODE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check as well if evRequested does not fit to the content of attribute EVChargeParameter
|
|
|
|
if ( (chargeParameterDiscoveryReq.getEVChargeParameter().getValue() instanceof ACEVChargeParameterType &&
|
|
|
|
evRequested.toString().startsWith("DC")) ||
|
|
|
|
(chargeParameterDiscoveryReq.getEVChargeParameter().getValue() instanceof DCEVChargeParameterType &&
|
|
|
|
evRequested.toString().startsWith("AC")) ) {
|
|
|
|
getLogger().error(chargeParameterDiscoveryReq.getEVChargeParameter().getValue().getClass().getSimpleName() +
|
|
|
|
" does not fit to EnergyTransferMode '" + evRequested.toString() + "'");
|
|
|
|
chargeParameterDiscoveryRes.setResponseCode(ResponseCodeType.FAILED_WRONG_ENERGY_TRANSFER_MODE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-20 14:26:22 -07:00
|
|
|
if (!verifyChargeParameter(chargeParameterDiscoveryReq)) {
|
|
|
|
chargeParameterDiscoveryRes.setResponseCode(ResponseCodeType.FAILED_WRONG_CHARGE_PARAMETER);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean verifyChargeParameter(ChargeParameterDiscoveryReqType chargeParameterDiscoveryReq) {
|
|
|
|
if (chargeParameterDiscoveryReq.getEVChargeParameter() == null) {
|
|
|
|
getLogger().error("EVChargeParameter is empty (null)");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chargeParameterDiscoveryReq.getEVChargeParameter().getValue() instanceof ACEVChargeParameterType) {
|
|
|
|
ACEVChargeParameterType acEVChargeParameter = (ACEVChargeParameterType) chargeParameterDiscoveryReq.getEVChargeParameter().getValue();
|
|
|
|
|
|
|
|
if ( // Check if mandatory charge parameters are null
|
|
|
|
(acEVChargeParameter.getEAmount() == null ||
|
|
|
|
acEVChargeParameter.getEVMaxVoltage() == null ||
|
|
|
|
acEVChargeParameter.getEVMaxCurrent() == null ||
|
|
|
|
acEVChargeParameter.getEVMinCurrent() == null
|
2015-06-01 08:19:09 -07:00
|
|
|
) ||
|
2017-08-20 14:26:22 -07:00
|
|
|
// Check if charge parameters are out of range
|
|
|
|
( acEVChargeParameter.getEAmount().getValue() < 0 ||
|
|
|
|
acEVChargeParameter.getEAmount().getValue() * Math.pow(10, acEVChargeParameter.getEAmount().getMultiplier()) > 200000 ||
|
|
|
|
acEVChargeParameter.getEVMaxVoltage().getValue() < 0 ||
|
|
|
|
acEVChargeParameter.getEVMaxVoltage().getValue() * Math.pow(10, acEVChargeParameter.getEVMaxVoltage().getMultiplier()) > 1000 ||
|
|
|
|
acEVChargeParameter.getEVMaxCurrent().getValue() < 0 ||
|
|
|
|
acEVChargeParameter.getEVMaxCurrent().getValue() * Math.pow(10, acEVChargeParameter.getEVMaxCurrent().getMultiplier()) > 400 ||
|
|
|
|
acEVChargeParameter.getEVMinCurrent().getValue() < 0 ||
|
|
|
|
acEVChargeParameter.getEVMinCurrent().getValue() * Math.pow(10, acEVChargeParameter.getEVMinCurrent().getMultiplier()) > 400
|
2015-06-01 08:19:09 -07:00
|
|
|
)
|
|
|
|
) {
|
2017-08-20 14:26:22 -07:00
|
|
|
getLogger().error("One of the AC_EVChargeParameter elements is either null or out of range");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chargeParameterDiscoveryReq.getEVChargeParameter().getValue() instanceof DCEVChargeParameterType) {
|
|
|
|
DCEVChargeParameterType dcEVChargeParameter = (DCEVChargeParameterType) chargeParameterDiscoveryReq.getEVChargeParameter().getValue();
|
|
|
|
|
|
|
|
if ( // Check if mandatory charge parameters are null
|
|
|
|
(dcEVChargeParameter.getDCEVStatus() == null ||
|
|
|
|
dcEVChargeParameter.getEVMaximumCurrentLimit() == null ||
|
|
|
|
dcEVChargeParameter.getEVMaximumVoltageLimit() == null
|
|
|
|
) ||
|
|
|
|
// Check if charge parameters are out of range
|
|
|
|
( dcEVChargeParameter.getDCEVStatus().getEVRESSSOC() < 0 ||
|
|
|
|
dcEVChargeParameter.getDCEVStatus().getEVRESSSOC() > 100 ||
|
|
|
|
dcEVChargeParameter.getEVMaximumCurrentLimit().getValue() < 0 ||
|
|
|
|
dcEVChargeParameter.getEVMaximumCurrentLimit().getValue() * Math.pow(10, dcEVChargeParameter.getEVMaximumCurrentLimit().getMultiplier()) > 400 ||
|
|
|
|
dcEVChargeParameter.getEVMaximumVoltageLimit().getValue() < 0 ||
|
|
|
|
dcEVChargeParameter.getEVMaximumVoltageLimit().getValue() * Math.pow(10, dcEVChargeParameter.getEVMaximumVoltageLimit().getMultiplier()) > 1000 ||
|
|
|
|
( // EVMaximumPowerLimit is optional
|
|
|
|
dcEVChargeParameter.getEVMaximumPowerLimit() != null && (
|
|
|
|
dcEVChargeParameter.getEVMaximumPowerLimit().getValue() < 0 ||
|
|
|
|
dcEVChargeParameter.getEVMaximumPowerLimit().getValue() * Math.pow(10, dcEVChargeParameter.getEVMaximumPowerLimit().getMultiplier()) > 200000
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
( // EVEnergyCapacity is optional
|
|
|
|
dcEVChargeParameter.getEVEnergyCapacity() != null && (
|
|
|
|
dcEVChargeParameter.getEVEnergyCapacity().getValue() < 0 ||
|
|
|
|
dcEVChargeParameter.getEVEnergyCapacity().getValue() * Math.pow(10, dcEVChargeParameter.getEVEnergyCapacity().getMultiplier()) > 200000
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
( // EVEnergyRequest is optional
|
|
|
|
dcEVChargeParameter.getEVEnergyRequest() != null && (
|
|
|
|
dcEVChargeParameter.getEVEnergyRequest().getValue() < 0 ||
|
|
|
|
dcEVChargeParameter.getEVEnergyRequest().getValue() * Math.pow(10, dcEVChargeParameter.getEVEnergyRequest().getMultiplier()) > 200000
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
( // FullSOC is optional
|
|
|
|
dcEVChargeParameter.getFullSOC() != null && (
|
|
|
|
dcEVChargeParameter.getFullSOC() < 0 ||
|
|
|
|
dcEVChargeParameter.getFullSOC() > 100
|
|
|
|
)
|
|
|
|
) ||
|
|
|
|
( // BulkSOC is optional
|
|
|
|
dcEVChargeParameter.getBulkSOC() != null && (
|
|
|
|
dcEVChargeParameter.getBulkSOC() < 0 ||
|
|
|
|
dcEVChargeParameter.getBulkSOC() > 100
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
getLogger().error("One of the DC_EVChargeParameter elements is either null or out of range");
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-01 08:19:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private JAXBElement<SAScheduleListType> getSASchedulesAsJAXBElement(SAScheduleListType saScheduleList) {
|
|
|
|
return new JAXBElement<SAScheduleListType>(
|
|
|
|
new QName("urn:iso:15118:2:2013:MsgDataTypes", "SAScheduleList"),
|
|
|
|
SAScheduleListType.class,
|
|
|
|
saScheduleList);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWaitingForSchedule() {
|
|
|
|
return waitingForSchedule;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setWaitingForSchedule(boolean waitingForSchedule) {
|
|
|
|
this.waitingForSchedule = waitingForSchedule;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:50:43 -07:00
|
|
|
@Override
|
2017-08-20 14:26:22 -07:00
|
|
|
public BodyBaseType getResponseMessage() {
|
|
|
|
return chargeParameterDiscoveryRes;
|
2017-07-20 06:50:43 -07:00
|
|
|
}
|
|
|
|
|
2015-06-01 08:19:09 -07:00
|
|
|
}
|