Skip to content

Commit

Permalink
Add ChargePoint constructor so a pointer to a device model storage ca…
Browse files Browse the repository at this point in the history
…n be used (#188)

* 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 <maaike@iolar.nl>

* bump version to 0.9.2

Signed-off-by: pietfried <pietgoempel@gmail.com>

---------

Signed-off-by: Maaike Zijderveld, Alfen <maaike@iolar.nl>
Signed-off-by: pietfried <pietgoempel@gmail.com>
Co-authored-by: pietfried <pietgoempel@gmail.com>
  • Loading branch information
maaikez and Pietfried authored Sep 28, 2023
1 parent a4716b6 commit 435a0cc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.14)

project(ocpp
VERSION 0.9.1
VERSION 0.9.2
DESCRIPTION "A C++ implementation of the Open Charge Point Protocol"
LANGUAGES CXX
)
Expand Down
1 change: 1 addition & 0 deletions include/ocpp/common/ocpp_logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <thread>

Expand Down
15 changes: 15 additions & 0 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ocpp/v201/ctrlr_component_variables.hpp>
#include <ocpp/v201/database_handler.hpp>
#include <ocpp/v201/device_model.hpp>
#include <ocpp/v201/device_model_storage.hpp>
#include <ocpp/v201/enums.hpp>
#include <ocpp/v201/evse.hpp>
#include <ocpp/v201/ocpp_types.hpp>
Expand Down Expand Up @@ -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<int32_t, int32_t>& evse_connector_structure,
std::unique_ptr<DeviceModelStorage> 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);
Expand Down
4 changes: 2 additions & 2 deletions include/ocpp/v201/device_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceModelStorage> 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.
Expand Down
5 changes: 4 additions & 1 deletion include/ocpp/v201/device_model_storage_sqlite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#ifndef DEVICE_MODEL_STORAGE_SQLITE_HPP
#define DEVICE_MODEL_STORAGE_SQLITE_HPP

#include <ocpp/v201/device_model_storage.hpp>
#include <filesystem>
#include <sqlite3.h>

#include <everest/logging.hpp>
#include <ocpp/v201/device_model_storage.hpp>

namespace ocpp {
namespace v201 {

Expand Down
12 changes: 11 additions & 1 deletion lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest

#include <ocpp/v201/charge_point.hpp>
#include <ocpp/v201/device_model_storage_sqlite.hpp>
#include <ocpp/v201/messages/FirmwareStatusNotification.hpp>
#include <ocpp/v201/messages/LogStatusNotification.hpp>

Expand Down Expand Up @@ -29,6 +30,15 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& 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<DeviceModelStorageSqlite>(device_model_storage_address),
ocpp_main_path, core_database_path, sql_init_path, message_log_path, certs_path, callbacks) {
}

ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
std::unique_ptr<DeviceModelStorage> 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),
Expand All @@ -46,7 +56,7 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
EVLOG_AND_THROW(std::invalid_argument("All non-optional callbacks must be supplied"));
}

this->device_model = std::make_unique<DeviceModel>(device_model_storage_address);
this->device_model = std::make_unique<DeviceModel>(std::move(device_model_storage));
this->pki_handler = std::make_shared<ocpp::PkiHandler>(
certs_path,
this->device_model->get_optional_value<bool>(ControllerComponentVariables::AdditionalRootCertificateCheck)
Expand Down
8 changes: 4 additions & 4 deletions lib/ocpp/v201/device_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceModelStorageSqlite>(storage_address);
DeviceModel::DeviceModel(std::unique_ptr<DeviceModelStorage> 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) {
Expand Down

0 comments on commit 435a0cc

Please sign in to comment.