From 22a935025ce36ac6296f99f4f0ee03e746376ddc Mon Sep 17 00:00:00 2001 From: "Maaike Zijderveld, Alfen" Date: Tue, 26 Sep 2023 16:47:54 +0200 Subject: [PATCH] Add ChargePoint constructor so a pointer to a device model storage can be used. Change constructor of DeviceModel for this purpose as well. Signed-off-by: Maaike Zijderveld, Alfen --- include/ocpp/common/ocpp_logging.hpp | 1 + include/ocpp/v201/charge_point.hpp | 15 +++++++++++++++ include/ocpp/v201/device_model.hpp | 4 ++-- include/ocpp/v201/device_model_storage_sqlite.hpp | 1 + lib/ocpp/v201/charge_point.cpp | 12 +++++++++++- lib/ocpp/v201/device_model.cpp | 8 ++++---- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/ocpp/common/ocpp_logging.hpp b/include/ocpp/common/ocpp_logging.hpp index af0fef7dfa..6e956cacad 100644 --- a/include/ocpp/common/ocpp_logging.hpp +++ b/include/ocpp/common/ocpp_logging.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/include/ocpp/v201/charge_point.hpp b/include/ocpp/v201/charge_point.hpp index 63db5e5992..abca358433 100644 --- a/include/ocpp/v201/charge_point.hpp +++ b/include/ocpp/v201/charge_point.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -318,6 +319,20 @@ class ChargePoint : ocpp::ChargingStationBase { const std::string& core_database_path, const std::string& sql_init_path, const std::string& message_log_path, const std::string& certs_path, const Callbacks& callbacks); + /// \brief Construct a new ChargePoint object + /// \param evse_connector_structure Map that defines the structure of EVSE and connectors of the chargepoint. The + /// key represents the id of the EVSE and the value represents the number of connectors for this EVSE. The ids of + /// the EVSEs have to increment starting with 1. + /// \param device_model_storage device model storage instance + /// \param ocpp_main_path Path where utility files for OCPP are read and written to + /// \param core_database_path Path to directory where core database is located + /// \param message_log_path Path to where logfiles are written to + /// \param callbacks Callbacks that will be registered for ChargePoint + ChargePoint(const std::map& evse_connector_structure, + std::unique_ptr device_model_storage, const std::string& ocpp_main_path, + const std::string& core_database_path, const std::string& sql_init_path, + const std::string& message_log_path, const std::string& certs_path, const Callbacks& callbacks); + /// \brief Starts the ChargePoint, initializes and connects to the Websocket endpoint /// \param bootreason Optional bootreason (default: PowerUp). void start(BootReasonEnum bootreason = BootReasonEnum::PowerUp); diff --git a/include/ocpp/v201/device_model.hpp b/include/ocpp/v201/device_model.hpp index 6b3ca11a63..59e3d222df 100644 --- a/include/ocpp/v201/device_model.hpp +++ b/include/ocpp/v201/device_model.hpp @@ -80,8 +80,8 @@ class DeviceModel { public: /// \brief Constructor for the device model - /// \param storage_address address fo device model storage - explicit DeviceModel(const std::string& storage_address); + /// \param device_model_storage pointer to a device model storage class + explicit DeviceModel(std::unique_ptr device_model_storage); /// \brief Direct access to value of a VariableAttribute for the given component, variable and attribute_enum. This /// should only be called for variables that have a role standardized in the OCPP2.0.1 specification. diff --git a/include/ocpp/v201/device_model_storage_sqlite.hpp b/include/ocpp/v201/device_model_storage_sqlite.hpp index c736376c55..0fb37701fe 100644 --- a/include/ocpp/v201/device_model_storage_sqlite.hpp +++ b/include/ocpp/v201/device_model_storage_sqlite.hpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace ocpp { diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index 61454e2a17..1670134e9b 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -2,6 +2,7 @@ // Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest #include +#include #include #include @@ -29,6 +30,15 @@ ChargePoint::ChargePoint(const std::map& evse_connector_struct const std::string& core_database_path, const std::string& sql_init_path, const std::string& message_log_path, const std::string& certs_path, const Callbacks& callbacks) : + ChargePoint(evse_connector_structure, std::make_unique(device_model_storage_address), + ocpp_main_path, core_database_path, sql_init_path, message_log_path, certs_path, callbacks) { +} + +ChargePoint::ChargePoint(const std::map& evse_connector_structure, + std::unique_ptr device_model_storage, const std::string& ocpp_main_path, + const std::string& core_database_path, const std::string& sql_init_path, + const std::string& message_log_path, const std::string& certs_path, + const Callbacks& callbacks) : ocpp::ChargingStationBase(), registration_status(RegistrationStatusEnum::Rejected), websocket_connection_status(WebsocketConnectionStatusEnum::Disconnected), @@ -46,7 +56,7 @@ ChargePoint::ChargePoint(const std::map& evse_connector_struct EVLOG_AND_THROW(std::invalid_argument("All non-optional callbacks must be supplied")); } - this->device_model = std::make_unique(device_model_storage_address); + this->device_model = std::make_unique(std::move(device_model_storage)); this->pki_handler = std::make_shared( certs_path, this->device_model->get_optional_value(ControllerComponentVariables::AdditionalRootCertificateCheck) diff --git a/lib/ocpp/v201/device_model.cpp b/lib/ocpp/v201/device_model.cpp index 82f3c70204..9c275bf7ea 100644 --- a/lib/ocpp/v201/device_model.cpp +++ b/lib/ocpp/v201/device_model.cpp @@ -153,15 +153,15 @@ SetVariableStatusEnum DeviceModel::set_value_internal(const Component& component return success ? SetVariableStatusEnum::Accepted : SetVariableStatusEnum::Rejected; }; -DeviceModel::DeviceModel(const std::string& storage_address) { - this->storage = std::make_unique(storage_address); +DeviceModel::DeviceModel(std::unique_ptr device_model_storage) : + storage{std::move(device_model_storage)} { this->device_model = this->storage->get_device_model(); -}; +} SetVariableStatusEnum DeviceModel::set_value(const Component& component, const Variable& variable, const AttributeEnum& attribute_enum, const std::string& value) { return this->set_value_internal(component, variable, attribute_enum, value, false); -}; +} SetVariableStatusEnum DeviceModel::set_read_only_value(const Component& component, const Variable& variable, const AttributeEnum& attribute_enum, const std::string& value) {