Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
  • Loading branch information
maaikez committed Jul 3, 2024
1 parent 2db7648 commit 654a121
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/ocpp/v201/init_device_model_db.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
// Copyright Pionix GmbH and Contributors to EVerest

///
/// @file init_device_model_db.hpp
Expand Down
21 changes: 11 additions & 10 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using namespace std::chrono_literals;

const auto DEFAULT_MAX_CUSTOMER_INFORMATION_DATA_LENGTH = 51200;
const std::string VARIABLE_ATTRIBUTE_VALUE_SOURCE = "libocpp";
const std::string VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP = "libocpp";
const std::string VARIABLE_ATTRIBUTE_VALUE_SOURCE_CSMS = "csms";

using DatabaseException = ocpp::common::DatabaseException;
Expand Down Expand Up @@ -960,14 +960,15 @@ void ChargePoint::init_websocket() {
if (active_network_profile_cv.variable.has_value()) {
this->device_model->set_read_only_value(active_network_profile_cv.component,
active_network_profile_cv.variable.value(), AttributeEnum::Actual,
configuration_slot, VARIABLE_ATTRIBUTE_VALUE_SOURCE);
configuration_slot, VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP);
}

const auto& security_profile_cv = ControllerComponentVariables::SecurityProfile;
if (security_profile_cv.variable.has_value()) {
this->device_model->set_read_only_value(
security_profile_cv.component, security_profile_cv.variable.value(), AttributeEnum::Actual,
std::to_string(network_connection_profile.value().securityProfile), VARIABLE_ATTRIBUTE_VALUE_SOURCE);
this->device_model->set_read_only_value(security_profile_cv.component, security_profile_cv.variable.value(),
AttributeEnum::Actual,
std::to_string(network_connection_profile.value().securityProfile),
VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP);
}

this->websocket = std::make_unique<Websocket>(connection_options, this->evse_security, this->logging);
Expand All @@ -978,7 +979,7 @@ void ChargePoint::init_websocket() {
if (security_profile_cv.variable.has_value()) {
this->device_model->set_read_only_value(security_profile_cv.component, security_profile_cv.variable.value(),
AttributeEnum::Actual, std::to_string(security_profile),
VARIABLE_ATTRIBUTE_VALUE_SOURCE);
VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP);
}

if (this->registration_status == RegistrationStatusEnum::Accepted and
Expand Down Expand Up @@ -1170,7 +1171,7 @@ void ChargePoint::remove_network_connection_profiles_below_actual_security_profi
this->device_model->set_value(ControllerComponentVariables::NetworkConnectionProfiles.component,
ControllerComponentVariables::NetworkConnectionProfiles.variable.value(),
AttributeEnum::Actual, network_connection_profiles.dump(),
VARIABLE_ATTRIBUTE_VALUE_SOURCE);
VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP);

// Update the NetworkConfigurationPriority so only remaining profiles are in there
const auto network_priority = ocpp::get_vector_from_csv(
Expand All @@ -1195,7 +1196,7 @@ void ChargePoint::remove_network_connection_profiles_below_actual_security_profi

this->device_model->set_value(ControllerComponentVariables::NetworkConfigurationPriority.component,
ControllerComponentVariables::NetworkConfigurationPriority.variable.value(),
AttributeEnum::Actual, new_network_priority, VARIABLE_ATTRIBUTE_VALUE_SOURCE);
AttributeEnum::Actual, new_network_priority, VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP);
}

void ChargePoint::handle_message(const EnhancedMessage<v201::MessageType>& message) {
Expand Down Expand Up @@ -1433,7 +1434,7 @@ void ChargePoint::update_authorization_cache_size() {
auto size = this->database_handler->authorization_cache_get_binary_size();
this->device_model->set_read_only_value(auth_cache_size.component, auth_cache_size.variable.value(),
AttributeEnum::Actual, std::to_string(size),
VARIABLE_ATTRIBUTE_VALUE_SOURCE);
VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP);
} catch (const DatabaseException& e) {
EVLOG_warning << "Could not get authorization cache binary size from database: " << e.what();
} catch (const std::exception& e) {
Expand Down Expand Up @@ -2474,7 +2475,7 @@ void ChargePoint::handle_set_network_profile_req(Call<SetNetworkProfileRequest>

if (this->device_model->set_value(ControllerComponentVariables::NetworkConnectionProfiles.component,
ControllerComponentVariables::NetworkConnectionProfiles.variable.value(),
AttributeEnum::Actual, VARIABLE_ATTRIBUTE_VALUE_SOURCE,
AttributeEnum::Actual, VARIABLE_ATTRIBUTE_VALUE_SOURCE_LIBOCPP,
network_connection_profiles.dump()) != SetVariableStatusEnum::Accepted) {
EVLOG_warning
<< "CSMS attempted to set a network profile that could not be written to the device model storage";
Expand Down
5 changes: 2 additions & 3 deletions lib/ocpp/v201/device_model_storage_sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ DeviceModelStorageSqlite::DeviceModelStorageSqlite(const fs::path& db_path, cons
const bool init_db) {
if (init_db) {
if (db_path.empty() || migration_files_path.empty() || schemas_path.empty() || config_path.empty()) {
EVLOG_error << "Can not initialize device model storage: one of the paths is empty.";
EVLOG_AND_THROW(
DeviceModelStorageError("Can not initialize device model storage: one of the paths is empty."));
}
Expand All @@ -35,8 +34,8 @@ DeviceModelStorageSqlite::DeviceModelStorageSqlite(const fs::path& db_path, cons
db = std::make_unique<ocpp::common::DatabaseConnection>(db_path);

if (!db->open_connection()) {
EVLOG_error << "Could not open database at provided path: " << db_path;
EVLOG_AND_THROW(std::runtime_error("Could not open device model database at provided path."));
EVLOG_AND_THROW(
std::runtime_error("Could not open device model database at provided path: " + db_path.string()));
} else {
EVLOG_info << "Established connection to device model database successfully: " << db_path;
}
Expand Down
17 changes: 8 additions & 9 deletions lib/ocpp/v201/init_device_model_db.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest
// Copyright Pionix GmbH and Contributors to EVerest

#include <ocpp/v201/init_device_model_db.hpp>

Expand Down Expand Up @@ -58,12 +58,12 @@ void InitDeviceModelDb::initialize_database(const std::filesystem::path& schemas
if (this->database_exists) {
try {
if (this->database->get_user_version() == 0) {
EVLOG_error << "Database does not support migrations yet, please update the database.";
throw InitDeviceModelDbError("Database does not support migrations yet, please update the database.");
EVLOG_AND_THROW(
InitDeviceModelDbError("Database does not support migrations yet, please update the database."));
}
} catch (const std::runtime_error& e) {
EVLOG_error << "Database does not support migrations yet, please update the database.";
throw InitDeviceModelDbError("Database does not support migrations yet, please update the database.");
EVLOG_AND_THROW(
InitDeviceModelDbError("Database does not support migrations yet, please update the database."));
}

existing_components = get_all_connector_and_evse_components_fom_db();
Expand Down Expand Up @@ -93,8 +93,8 @@ bool InitDeviceModelDb::insert_config_and_default_values(const std::filesystem::
std::string errors;

if (!check_config_integrity(components, config_values, errors)) {
EVLOG_error << "Config not consistent with device model component schema's: \n" << errors;
throw InitDeviceModelDbError("Config not consistent with device model component schema's");
EVLOG_AND_THROW(
InitDeviceModelDbError("Config not consistent with device model component schema's: \n" + errors));
}

for (const auto& component_variables : config_values) {
Expand Down Expand Up @@ -158,8 +158,7 @@ void InitDeviceModelDb::execute_init_sql(const bool delete_db_if_exists) {
if (delete_db_if_exists) {
if (std::filesystem::exists(database_path)) {
if (!std::filesystem::remove(database_path)) {
EVLOG_error << "Could not remove database " << database_path.u8string();
throw InitDeviceModelDbError("Could not remove database " + database_path.u8string());
EVLOG_AND_THROW(InitDeviceModelDbError("Could not remove database " + database_path.u8string()));
}

database_exists = false;
Expand Down

0 comments on commit 654a121

Please sign in to comment.