Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChargeParametersDiscovery checks unnecessarily if the message received is a CableCheck or PowerDelivery #31

Closed
tropxy opened this issue Apr 10, 2022 · 0 comments

Comments

@tropxy
Copy link
Contributor

tropxy commented Apr 10, 2022

As far as I know, a ChargeParameterDiscoveryReq must always have either the ac_ev_charge_parameter or the dc_ev_charge_parameter present and based on that we know that we need either to transit to PowerDelivery or CableCheck.

Currently, we do the right jump, but at the beginning of the ChargeParameterDiscovery, we continue to check which message have we received, when we know that if we remain in this state we will only receive a ChargeParameterDiscovery message.

class ChargeParameterDiscovery(StateSECC):
    """
    The ISO 15118-2 state in which the SECC processes an
    ChargeParameterDiscoveryReq message from the EVCC.

    The EVCC may send one of the following requests in this state:
    1. a ChargeParameterDiscoveryReq
    2. a PowerDeliveryReq (AC)
    3. a CableCheckreq (DC)

    Upon first initialisation of this state, we expect a
    ChargeParameterDiscoveryReq, but after that, the next possible request could
    be either another ChargeParameterDiscoveryReq (if EVSEProcessing=Ongoing in
    the ChargeParameterDiscoveryRes) or a PowerDeliveryReq. So we remain in this
    state until we know which is the following request from the EVCC and then
    transition to the appropriate state (or terminate if the incoming message
    doesn't fit any of the expected requests).

    As a result, the create_next_message() method might be called with
    next_state = None.
    """

    def __init__(self, comm_session: SECCCommunicationSession):
        super().__init__(comm_session, Timeouts.V2G_SECC_SEQUENCE_TIMEOUT)
        self.expecting_charge_parameter_discovery_req = True

    def process_message(
        self,
        message: Union[
            SupportedAppProtocolReq,
            SupportedAppProtocolRes,
            V2GMessageV2,
            V2GMessageV20,
            V2GMessageDINSPEC,
        ],
    ):
        msg = self.check_msg_v2(
            message,
            [ChargeParameterDiscoveryReq, PowerDeliveryReq, CableCheckReq],
            self.expecting_charge_parameter_discovery_req,
        )
        if not msg:
            return

        if msg.body.power_delivery_req:
            PowerDelivery(self.comm_session).process_message(message)
            return

        if msg.body.cable_check_req:
            CableCheck(self.comm_session).process_message(message)
            return

        charge_params_req: ChargeParameterDiscoveryReq = (
            msg.body.charge_parameter_discovery_req
        )

        if charge_params_req.requested_energy_mode not in (
            self.comm_session.evse_controller.get_supported_energy_transfer_modes(
                Protocol.ISO_15118_2
            )
        ):  # noqa: E501
            self.stop_state_machine(
                f"{charge_params_req.requested_energy_mode} not "
                f"offered as energy transfer mode",
                message,
                ResponseCode.FAILED_WRONG_ENERGY_TRANSFER_MODE,
            )
            return

        self.comm_session.selected_energy_mode = charge_params_req.requested_energy_mode
        self.comm_session.selected_charging_type_is_ac = (
            self.comm_session.selected_energy_mode.value.startswith("AC")
        )

        max_schedule_entries: Optional[
            int
        ] = charge_params_req.max_entries_sa_schedule_tuple

        ac_evse_charge_params: Optional[ACEVSEChargeParameter] = None
        dc_evse_charge_params: Optional[DCEVSEChargeParameter] = None
        if charge_params_req.ac_ev_charge_parameter:
            ac_evse_charge_params = (
                self.comm_session.evse_controller.get_ac_evse_charge_parameter()
            )
            departure_time = charge_params_req.ac_ev_charge_parameter.departure_time
        else:
            dc_evse_charge_params = (
                self.comm_session.evse_controller.get_dc_evse_charge_parameter()
            )
            departure_time = charge_params_req.dc_ev_charge_parameter.departure_time

        if not departure_time:
            departure_time = 0
        sa_schedule_list = self.comm_session.evse_controller.get_sa_schedule_list(
            max_schedule_entries, departure_time
        )

        signature = None
        next_state = None
        if sa_schedule_list:
            self.comm_session.offered_schedules = sa_schedule_list
            if charge_params_req.ac_ev_charge_parameter:
                next_state = PowerDelivery
            else:
                next_state = CableCheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant