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

Move firmware update to new functional block #952

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <ocpp/v201/functional_blocks/data_transfer.hpp>
#include <ocpp/v201/functional_blocks/diagnostics.hpp>
#include <ocpp/v201/functional_blocks/display_message.hpp>
#include <ocpp/v201/functional_blocks/firmware_update.hpp>
#include <ocpp/v201/functional_blocks/meter_values.hpp>
#include <ocpp/v201/functional_blocks/reservation.hpp>
#include <ocpp/v201/functional_blocks/security.hpp>
Expand Down Expand Up @@ -67,7 +68,6 @@
#include <ocpp/v201/messages/TransactionEvent.hpp>
#include <ocpp/v201/messages/TriggerMessage.hpp>
#include <ocpp/v201/messages/UnlockConnector.hpp>
#include <ocpp/v201/messages/UpdateFirmware.hpp>

#include "component_state_manager.hpp"

Expand Down Expand Up @@ -369,6 +369,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
std::unique_ptr<DiagnosticsInterface> diagnostics;
std::unique_ptr<SecurityInterface> security;
std::unique_ptr<DisplayMessageInterface> display_message;
std::unique_ptr<FirmwareUpdateInterface> firmware_update;
std::unique_ptr<MeterValuesInterface> meter_values;
std::unique_ptr<TariffAndCostInterface> tariff_and_cost;

Expand All @@ -383,11 +384,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

// states
std::atomic<RegistrationStatusEnum> registration_status;
FirmwareStatusEnum firmware_status;
// The request ID in the last firmware update status received
std::optional<int32_t> firmware_status_id;
// The last firmware status which will be posted before the firmware is installed.
FirmwareStatusEnum firmware_status_before_installing = FirmwareStatusEnum::SignatureVerified;
UploadLogStatusEnum upload_log_status;
int32_t upload_log_status_id;
BootReasonEnum bootreason;
Expand Down Expand Up @@ -458,15 +454,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
set_variables_internal(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source,
const bool allow_read_only);

/// \brief Changes all unoccupied connectors to unavailable. If a transaction is running schedule an availabilty
/// change
/// If all connectors are unavailable signal to the firmware updater that installation of the firmware update can
/// proceed
void change_all_connectors_to_unavailable_for_firmware_update();

/// \brief Restores all connectors to their persisted state
void restore_all_connector_states();

///
/// \brief Check if EVSE connector is reserved for another than the given id token and / or group id token.
/// \param evse The evse id that must be checked. Reservation will be checked for all connectors.
Expand Down Expand Up @@ -552,9 +539,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
void handle_get_charging_profiles_req(Call<GetChargingProfilesRequest> call);
void handle_get_composite_schedule_req(Call<GetCompositeScheduleRequest> call);

// Functional Block L: Firmware management
void handle_firmware_update_req(Call<UpdateFirmwareRequest> call);

// Generates async sending callbacks
template <class RequestType, class ResponseType>
std::function<ResponseType(RequestType)> send_callback(MessageType expected_response_message_type) {
Expand Down
80 changes: 80 additions & 0 deletions include/ocpp/v201/functional_blocks/firmware_update.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#pragma once

#include <ocpp/common/message_dispatcher.hpp>
#include <ocpp/v201/message_handler.hpp>
#include <ocpp/v201/messages/UpdateFirmware.hpp>

namespace ocpp {

// Forward declarations.
class EvseSecurity;

namespace v201 {

// Formward declarations.
class DeviceModel;
class EvseManagerInterface;
class AvailabilityInterface;
class SecurityInterface;

// Typedef
typedef std::function<UpdateFirmwareResponse(const UpdateFirmwareRequest& request)> UpdateFirmwareRequestCallback;
typedef std::function<void()> AllConnectorsUnavailableCallback;

class FirmwareUpdateInterface : public MessageHandlerInterface {
public:
virtual ~FirmwareUpdateInterface() {
}

virtual void on_firmware_update_status_notification(int32_t request_id,
const FirmwareStatusEnum& firmware_update_status) = 0;
virtual void on_firmware_status_notification_request() = 0;
};

class FirmwareUpdate : public FirmwareUpdateInterface {
private: // Members
MessageDispatcherInterface<MessageType>& message_dispatcher;
DeviceModel& device_model;
EvseManagerInterface& evse_manager;
EvseSecurity& evse_security;
AvailabilityInterface& availability;
SecurityInterface& security;

UpdateFirmwareRequestCallback update_firmware_request_callback;
std::optional<AllConnectorsUnavailableCallback> all_connectors_unavailable_callback;

FirmwareStatusEnum firmware_status;
// The request ID in the last firmware update status received
std::optional<int32_t> firmware_status_id;
// The last firmware status which will be posted before the firmware is installed.
FirmwareStatusEnum firmware_status_before_installing = FirmwareStatusEnum::SignatureVerified;

public:
FirmwareUpdate(MessageDispatcherInterface<MessageType>& message_dispatcher, DeviceModel& device_model,
EvseManagerInterface& evse_manager, EvseSecurity& evse_security,
ocpp::v201::AvailabilityInterface& availability, SecurityInterface& security,
UpdateFirmwareRequestCallback update_firmware_request_callback,
std::optional<AllConnectorsUnavailableCallback> all_connectors_unavailable_callback);
void handle_message(const ocpp::EnhancedMessage<MessageType>& message) override;
void on_firmware_update_status_notification(int32_t request_id,
const FirmwareStatusEnum& firmware_update_status) override;
void on_firmware_status_notification_request() override;

private: // Functions
// Functional Block L: Firmware management
void handle_firmware_update_req(Call<UpdateFirmwareRequest> call);

/// \brief Changes all unoccupied connectors to unavailable. If a transaction is running schedule an availabilty
/// change
/// If all connectors are unavailable signal to the firmware updater that installation of the firmware update can
/// proceed
void change_all_connectors_to_unavailable_for_firmware_update();

/// \brief Restores all connectors to their persisted state
void restore_all_connector_states();
};
} // namespace v201
} // namespace ocpp
16 changes: 8 additions & 8 deletions include/ocpp/v201/functional_blocks/security.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class Security : public SecurityInterface {
Get15118EVCertificateResponse
on_get_15118_ev_certificate_request(const Get15118EVCertificateRequest& request) override;

/* OCPP message requests */
virtual void security_event_notification_req(const CiString<50>& event_type,
const std::optional<CiString<255>>& tech_info,
const bool triggered_internally, const bool critical,
const std::optional<DateTime>& timestamp = std::nullopt) override;
virtual void sign_certificate_req(const ocpp::CertificateSigningUseEnum& certificate_signing_use,
const bool initiated_by_trigger_message = false) override;

private: // Members
MessageDispatcherInterface<MessageType>& message_dispatcher;
DeviceModel& device_model;
Expand All @@ -69,14 +77,6 @@ class Security : public SecurityInterface {
Everest::SteadyTimer v2g_certificate_expiration_check_timer;

private: // Functions
/* OCPP message requests */
virtual void security_event_notification_req(const CiString<50>& event_type,
const std::optional<CiString<255>>& tech_info,
const bool triggered_internally, const bool critical,
const std::optional<DateTime>& timestamp = std::nullopt) override;
virtual void sign_certificate_req(const ocpp::CertificateSigningUseEnum& certificate_signing_use,
const bool initiated_by_trigger_message = false) override;

/* OCPP message handlers */

// Functional Block A: Security
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ if(LIBOCPP_ENABLE_V201)
ocpp/v201/functional_blocks/availability.cpp
ocpp/v201/functional_blocks/security.cpp
ocpp/v201/functional_blocks/data_transfer.cpp
ocpp/v201/functional_blocks/firmware_update.cpp
ocpp/v201/functional_blocks/reservation.cpp
ocpp/v201/functional_blocks/diagnostics.cpp
ocpp/v201/functional_blocks/display_message.cpp
Expand Down
Loading