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

Feature/656 device model initialization in cpp #681

Merged
merged 36 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dd4b760
Add files and start working on init device model in c++ instead of py…
maaikez Jun 5, 2024
aedf06f
Add function to add components and its properties etc to the database.
maaikez Jun 6, 2024
b08d964
Make more structs from json data.
maaikez Jun 9, 2024
0f03258
Implement all to_json funcitons. Start with the 'insert config' funct…
maaikez Jun 12, 2024
4d9c8b9
Implement 'insert variable' and default values.
maaikez Jun 13, 2024
a0a9753
Some changes to cmakelists to add the schemas to the correct location…
maaikez Jun 14, 2024
bf75238
SQL: Add 'NOT NULL' constraints to foreign keys and 'ON DELETE' const…
maaikez Jun 14, 2024
743b803
Change some structs for already existing structs. Add functions to ch…
maaikez Jun 17, 2024
66932c3
For Connector and / or EVSE Component: change characteristics and att…
maaikez Jun 18, 2024
5348678
Create test for init device model db class. Add flag to database open…
maaikez Jun 19, 2024
09207cf
Add doxygen documentation. Solme reshuffling of functions. Uncomment …
maaikez Jun 20, 2024
472b247
Add value source to Variable Attribute in database. Change interfaces…
maaikez Jun 20, 2024
7403144
Merge branch 'main' into feature/656-device-model-initialization-in-cpp
maaikez Jun 28, 2024
d9b5b0e
Fix build and warnings from buildserver
maaikez Jun 28, 2024
29b33a0
Add exception and throw that specific exception from class. Change so…
maaikez Jun 28, 2024
dbe1291
Fix unit tests and paths. Update unit test device model database.
maaikez Jun 28, 2024
b2354f5
Get device model from database and check integrity of config file. Ad…
maaikez Jun 29, 2024
a7e1fd5
Clangformat. Fix failing smart charging unittest.
maaikez Jul 1, 2024
99f6e14
Add some documentation.
maaikez Jul 1, 2024
e5a500c
Make cmake for device model migrations work. Do another todo (add war…
maaikez Jul 1, 2024
484aa3f
Remove unnecessary todo's
maaikez Jul 1, 2024
7645b2e
Restrict removeing monitor config type if there is a variable monitor…
maaikez Jul 1, 2024
8b52ae4
Add some documentation to the unittests.
maaikez Jul 1, 2024
e17c704
Removed some todo's and outcommented code. Removed python script that…
maaikez Jul 3, 2024
1fcf825
Split function so it is hopefully more readable.
maaikez Jul 3, 2024
2db7648
Review comments: readable error when database is old and does not sup…
maaikez Jul 3, 2024
654a121
Review comments
maaikez Jul 3, 2024
d968c11
Remove values from config that should not be set. Do not warn if a de…
maaikez Jul 3, 2024
6fd006d
Change check_config_integrity so it returns a vector of strings with …
maaikez Jul 4, 2024
048bcf5
Add default value for AvailabilityState so it will not throw an error…
maaikez Jul 4, 2024
a85d9cd
Review comments
maaikez Jul 4, 2024
1fc6fed
Fix some warnings. Remove constructor from device model storage sqlit…
maaikez Jul 5, 2024
a67abf4
Merge main into feature branch
maaikez Jul 5, 2024
2f424dc
Fix update config where there is no default source set.
maaikez Jul 5, 2024
85e90cb
Move check for old database to a place before the migrations, as it d…
maaikez Jul 5, 2024
7697e88
Update config/v201/CMakeLists.txt
Pietfried Jul 6, 2024
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
52 changes: 32 additions & 20 deletions config/v201/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# find all migration files, store only the filenames by showing relative to the folder
set(MIGRATION_FILES_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/core_migrations")
set(MIGRATION_FILES_DEVICE_MODEL_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/device_model_migrations")

include(../CollectMigrationFiles.cmake)

Expand All @@ -9,7 +10,15 @@ collect_migration_files(
)

set(MIGRATION_FILE_VERSION_V201 ${TARGET_MIGRATION_FILE_VERSION} PARENT_SCOPE)

collect_migration_files(
LOCATION ${MIGRATION_FILES_DEVICE_MODEL_LOCATION}
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201/device_model_migrations
)

set(MIGRATION_DEVICE_MODEL_FILE_VERSION_V201 ${TARGET_MIGRATION_FILE_VERSION} PARENT_SCOPE)
set(MIGRATION_FILES_SOURCE_DIR_V201 ${MIGRATION_FILES_LOCATION} PARENT_SCOPE)
set(MIGRATION_FILES_DEVICE_MODEL_SOURCE_DIR_V201 ${MIGRATION_FILES_DEVICE_MODEL_LOCATION} PARENT_SCOPE)

option(LIBOCPP_INSTALL_DEVICE_MODEL_DATABASE "Install device model database for OCPP201" ON)

Expand All @@ -26,14 +35,15 @@ install(
if (LIBOCPP_INSTALL_DEVICE_MODEL_DATABASE)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.json)

find_program(
PYTHON_EXECUTABLE
python3
REQUIRED
)
# find_program(
# PYTHON_EXECUTABLE
# python3
# REQUIRED
# )

set(INIT_DEVICE_MODULE_DB_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/init_device_model_db.py")
set(DEVICE_MODEL_DATABASE_FILE "device_model_storage.db")
# set(INIT_DEVICE_MODULE_DB_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/init_device_model_db.py")
# TODO set correct paths and copy files to data dir!!
set(DEVICE_MODEL_DATABASE_FILE "${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201/device_model_storage.db")

if(NOT LIBOCPP_V201_CONFIG_FILE)
set(LIBOCPP_V201_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/config.json")
Expand All @@ -46,19 +56,21 @@ if (LIBOCPP_INSTALL_DEVICE_MODEL_DATABASE)

message(STATUS "Using ocpp v201 config file path: ${LIBOCPP_V201_CONFIG_FILE}")

execute_process(
COMMAND
${PYTHON_EXECUTABLE} ${INIT_DEVICE_MODULE_DB_SCRIPT} init --db ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} --schemas ${LIBOCPP_COMPONENT_SCHEMAS_PATH}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
# execute_process(
# COMMAND
# ${PYTHON_EXECUTABLE} ${INIT_DEVICE_MODULE_DB_SCRIPT} init --db ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} --schemas ${LIBOCPP_COMPONENT_SCHEMAS_PATH}
# WORKING_DIRECTORY
# ${CMAKE_CURRENT_SOURCE_DIR}
# )

execute_process(
COMMAND
${PYTHON_EXECUTABLE} ${INIT_DEVICE_MODULE_DB_SCRIPT} insert --db ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} --schemas ${LIBOCPP_COMPONENT_SCHEMAS_PATH} --config ${LIBOCPP_V201_CONFIG_FILE}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
# execute_process(
# COMMAND
# ${PYTHON_EXECUTABLE} ${INIT_DEVICE_MODULE_DB_SCRIPT} insert --db ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} --schemas ${LIBOCPP_COMPONENT_SCHEMAS_PATH} --config ${LIBOCPP_V201_CONFIG_FILE}
# WORKING_DIRECTORY
# ${CMAKE_CURRENT_SOURCE_DIR}
# )

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201)
install(FILES ${LIBOCPP_V201_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201)
install(DIRECTORY ${LIBOCPP_COMPONENT_SCHEMAS_PATH} DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,50 @@ CREATE TABLE IF NOT EXISTS COMPONENT (
);
CREATE TABLE IF NOT EXISTS VARIABLE_ATTRIBUTE (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
VARIABLE_ID INTEGER,
VARIABLE_ID INTEGER NOT NULL,
MUTABILITY_ID INTEGER,
PERSISTENT INTEGER,
CONSTANT INTEGER,
TYPE_ID INTEGER,
VALUE_SOURCE TEXT DEFAULT "default",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to leave this empty and use config for the initialization (by the config file) because its more verbose. There might be variables in the database without a value for the variable attribute

"VALUE" TEXT,
FOREIGN KEY (VARIABLE_ID) REFERENCES VARIABLE (ID),
FOREIGN KEY (TYPE_ID) REFERENCES VARIABLE_ATTRIBUTE_TYPE (ID),
FOREIGN KEY (MUTABILITY_ID) REFERENCES MUTABILITY (ID)
FOREIGN KEY (VARIABLE_ID) REFERENCES VARIABLE (ID) ON DELETE CASCADE,
FOREIGN KEY (TYPE_ID) REFERENCES VARIABLE_ATTRIBUTE_TYPE (ID) ON DELETE RESTRICT,
FOREIGN KEY (MUTABILITY_ID) REFERENCES MUTABILITY (ID) ON DELETE RESTRICT
);
CREATE TABLE IF NOT EXISTS VARIABLE_CHARACTERISTICS (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
DATATYPE_ID INTEGER,
DATATYPE_ID INTEGER NOT NULL,
VARIABLE_ID INTEGER NOT NULL,
MAX_LIMIT REAL,
MIN_LIMIT REAL,
SUPPORTS_MONITORING INTEGER,
UNIT TEXT,
VALUES_LIST TEXT,
FOREIGN KEY (DATATYPE_ID) REFERENCES DATATYPE (ID)
FOREIGN KEY (DATATYPE_ID) REFERENCES DATATYPE (ID) ON DELETE RESTRICT
FOREIGN KEY (VARIABLE_ID) REFERENCES VARIABLE (ID) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS VARIABLE_MONITORING (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
VARIABLE_ID INTEGER,
VARIABLE_ID INTEGER NOT NULL,
SEVERITY INTEGER,
"TRANSACTION" INTEGER,
TYPE_ID INTEGER,
TYPE_ID INTEGER NOT NULL,
CONFIG_TYPE_ID INTEGER,
"VALUE" DECIMAL,
REFERENCE_VALUE TEXT,
FOREIGN KEY (VARIABLE_ID) REFERENCES VARIABLE (ID),
FOREIGN KEY (TYPE_ID) REFERENCES MONITOR (ID),
FOREIGN KEY (CONFIG_TYPE_ID) REFERENCES MONITOR_CONFIG_TYPE(ID)
FOREIGN KEY (VARIABLE_ID) REFERENCES VARIABLE (ID) ON DELETE CASCADE,
FOREIGN KEY (TYPE_ID) REFERENCES MONITOR (ID) ON DELETE RESTRICT,
FOREIGN KEY (CONFIG_TYPE_ID) REFERENCES MONITOR_CONFIG_TYPE(ID) ON DELETE RESTRICT
);
CREATE TABLE IF NOT EXISTS VARIABLE (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
NAME TEXT,
INSTANCE TEXT,
COMPONENT_ID INTEGER,
VARIABLE_CHARACTERISTICS_ID INTEGER,
COMPONENT_ID INTEGER NOT NULL,
REQUIRED INTEGER DEFAULT FALSE,
FOREIGN KEY (COMPONENT_ID) REFERENCES COMPONENT (ID),
FOREIGN KEY (VARIABLE_CHARACTERISTICS_ID) REFERENCES VARIABLE_CHARACTERISTICS (ID)
FOREIGN KEY (COMPONENT_ID) REFERENCES COMPONENT (ID) ON DELETE CASCADE
);
BEGIN TRANSACTION;
INSERT
OR REPLACE INTO MUTABILITY
VALUES (0, "ReadOnly");
Expand Down Expand Up @@ -160,4 +160,3 @@ VALUES (2, "MinSet");
INSERT
OR REPLACE INTO VARIABLE_ATTRIBUTE_TYPE
VALUES (3, "MaxSet");
COMMIT;
51 changes: 51 additions & 0 deletions doc/device_model_initialization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Device model initialization and inserting of config values

If there is no custom database used for the device model, and 'initialize_device_model' is set to true in the

Check notice on line 3 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L3

Expected: 0 or 2; Actual: 1
constructor of ChargePoint, the device model will be created or updated when ChargePoint is created. This document will
give more information about the files you need and what will be updated when the 'initialize_device_model' is set

Check notice on line 5 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L5

Expected: 80; Actual: 113
to true.


## Database, component schemas and config file paths

Along with the 'initialize_device_model' flag, a few paths must be given to the constructor:
- The path of the device model migration files (normally `resources/v201/device_model_migration_files`).
- The path of the device model database.
- The path of the directory with the device model schemas. There should be two directories in it: 'standardized' and

Check notice on line 14 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L14

Expected: 0 or 2; Actual: 1

Check notice on line 14 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L14

Expected: 80; Actual: 117
'custom', both containing device model schemas.
- The path of the config file.


## Component schemas and config file

When the database is created for the first time, it will insert all components, variables, characteristics and
attributes from the component schemas.

Check notice on line 22 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L22

Expected: 0 or 2; Actual: 1

It will then set all the values read from the config file.

If anything does not match, no values will be set. So if for example there is a variable set in the config that is

Check notice on line 26 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L26

Expected: 0 or 2; Actual: 1

Check notice on line 26 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L26

Expected: 80; Actual: 115
not in the component schema, the config values will not be set.

Check notice on line 27 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L27

Expected: 0 or 2; Actual: 1


## Update config values

Each time the software starts, the config file is read and the values will be set to the database accordingly. Only

Check notice on line 32 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L32

Expected: 0 or 2; Actual: 1

Check notice on line 32 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L32

Expected: 80; Actual: 116
the initial values will be set to the values in the config file. So if for example the csms changed a value, it will

Check notice on line 33 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L33

Expected: 80; Actual: 117
not be updated to the value from the config file.


## Update component schemas

It is only possible to update the component schemas for `EVSE`'s and `Connector`s. All other components can not be updated.

Check notice on line 39 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L39

Expected: 80; Actual: 123

To update an `EVSE` or `Connector` component, just place the correct `EVSE` / `Connector` json schema in the

Check notice on line 41 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L41

Expected: 0 or 2; Actual: 1

Check notice on line 41 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L41

Expected: 80; Actual: 109
`component_schemas/custom` folder. When restarting the software, it will:
- Check if there are `EVSE`'s or `Connector`s in the database that are not in the component schema's. Those will be

Check notice on line 43 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L43

Expected: 0 or 2; Actual: 1

Check notice on line 43 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L43

Expected: 80; Actual: 116
removed.
- Check if there are `EVSE`'s er `Connectors` in the component schema's that are not in the database. Those will be

Check notice on line 45 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L45

Expected: 0 or 2; Actual: 1

Check notice on line 45 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L45

Expected: 80; Actual: 116
added.
- Check if anything has changed inside the `EVSE`'s or `Connectors` (`Variable`, `Characteristics` or `Attributes`

Check notice on line 47 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L47

Expected: 0 or 2; Actual: 1

Check notice on line 47 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L47

Expected: 80; Actual: 115
removed, changed or added. Those will be removed, changed or added to the database as well.

Check notice on line 48 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L48

Expected: 0 or 2; Actual: 1

Check notice on line 48 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L48

Expected: 80; Actual: 94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Check if anything has changed inside the `EVSE`'s or `Connectors` (`Variable`, `Characteristics` or `Attributes`
removed, changed or added. Those will be removed, changed or added to the database as well.
- Check if anything has changed inside the `EVSE`'s or `Connectors` (`Variable`, `Characteristics` or `Attributes`). Those will be removed, changed or added to the database as well.


Note: When the id of an `EVSE` Component is changed, this is seen as the removal of an `EVSE` and addition of a new

Check notice on line 50 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L50

Expected: 0 or 2; Actual: 1

Check notice on line 50 in doc/device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/device_model_initialization.md#L50

Expected: 80; Actual: 116
`EVSE`. The same applies to the `evse_id` or `connector_id` of a `Connector` component.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add something like:

"OCPP requires EVSE and Connector numbering starting from 1 counting upwards."

2 changes: 2 additions & 0 deletions include/ocpp/common/database/sqlite_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SQLiteStatementInterface {
virtual int bind_null(const int idx) = 0;
virtual int bind_null(const std::string& param) = 0;

virtual int get_number_of_rows() = 0;
virtual int column_type(const int idx) = 0;
virtual std::string column_text(const int idx) = 0;
virtual std::optional<std::string> column_text_nullable(const int idx) = 0;
Expand Down Expand Up @@ -73,6 +74,7 @@ class SQLiteStatement : public SQLiteStatementInterface {
int bind_null(const int idx) override;
int bind_null(const std::string& param) override;

int get_number_of_rows() override;
int column_type(const int idx) override;
std::string column_text(const int idx) override;
std::optional<std::string> column_text_nullable(const int idx) override;
Expand Down
35 changes: 31 additions & 4 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class ChargePointInterface {
/// \return Map containing the SetVariableData as a key and the SetVariableResult as a value for each requested
/// change
virtual std::map<SetVariableData, SetVariableResult>
set_variables(const std::vector<SetVariableData>& set_variable_data_vector) = 0;
set_variables(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source) = 0;
};

/// \brief Class implements OCPP2.0.1 Charging Station
Expand Down Expand Up @@ -524,11 +524,13 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

/// \brief Sets variables specified within \p set_variable_data_vector in the device model and returns the result.
/// \param set_variable_data_vector contains data of the variables to set
/// \param source value source (who sets the value, for example 'csms' or 'libocpp')
/// \param allow_read_only if true, setting VariableAttribute values with mutability ReadOnly is allowed
/// \return Map containing the SetVariableData as a key and the SetVariableResult as a value for each requested
/// change
std::map<SetVariableData, SetVariableResult>
set_variables_internal(const std::vector<SetVariableData>& set_variable_data_vector, const bool allow_read_only);
set_variables_internal(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source,
const bool allow_read_only);

MeterValue get_latest_meter_value_filtered(const MeterValue& meter_value, ReadingContextEnum context,
const RequiredComponentVariable& component_variable);
Expand Down Expand Up @@ -743,7 +745,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
ocpp::CallResult<ResponseType> call_result = enhanced_response.message;
return call_result.msg;
};
};
}

/// \brief Checks if all connectors are effectively inoperative.
/// If this is the case, calls the all_connectors_unavailable_callback
Expand All @@ -761,6 +763,31 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
void execute_change_availability_request(ChangeAvailabilityRequest request, bool persist);

public:
/// \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_address address to device model storage (e.g. location of SQLite database)
/// \param initialize_device_model Set to true to initialize the device model database
/// \param device_model_migration_path Path to the device model database migration files
/// \param device_model_schemas_path Path to the device model schemas
/// \param config_path Path to the chargepoint configuration
/// \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 evse_security Pointer to evse_security that manages security related operations; if nullptr
/// security_configuration must be set
/// \param callbacks Callbacks that will be registered for ChargePoint
/// \param security_configuration specifies the file paths that are required to set up the internal evse_security
/// implementation
ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
const std::string& device_model_storage_address, const bool initialize_device_model,
const std::string& device_model_migration_path, const std::string& device_model_schemas_path,
const std::string& config_path, 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::shared_ptr<EvseSecurity> evse_security,
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
Expand Down Expand Up @@ -875,7 +902,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
std::vector<GetVariableResult> get_variables(const std::vector<GetVariableData>& get_variable_data_vector) override;

std::map<SetVariableData, SetVariableResult>
set_variables(const std::vector<SetVariableData>& set_variable_data_vector) override;
set_variables(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source) override;

/// \brief Requests a value of a VariableAttribute specified by combination of \p component_id and \p variable_id
/// from the device model
Expand Down
7 changes: 5 additions & 2 deletions include/ocpp/v201/device_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,24 @@ class DeviceModel {
/// \param variable_id
/// \param attribute_enum
/// \param value
/// \param source The source of the value (for example 'csms' or 'default').
/// \param allow_read_only If this is true, read-only variables can be changed,
/// otherwise only non read-only variables can be changed. Defaults to false
/// \return Result of the requested operation
SetVariableStatusEnum set_value(const Component& component_id, const Variable& variable_id,
const AttributeEnum& attribute_enum, const std::string& value,
const bool allow_read_only = false);
const std::string& source, const bool allow_read_only = false);
/// \brief Sets the variable_id attribute \p value specified by \p component_id , \p variable_id and \p
/// attribute_enum for read only variables only. Only works on certain allowed components.
/// \param component_id
/// \param variable_id
/// \param attribute_enum
/// \param value
/// \param source The source of the value (for example 'csms' or 'default').
/// \return Result of the requested operation
SetVariableStatusEnum set_read_only_value(const Component& component_id, const Variable& variable_id,
const AttributeEnum& attribute_enum, const std::string& value);
const AttributeEnum& attribute_enum, const std::string& value,
const std::string& source);

/// \brief Gets the VariableMetaData for the given \p component_id and \p variable_id
/// \param component_id
Expand Down
4 changes: 3 additions & 1 deletion include/ocpp/v201/device_model_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ class DeviceModelStorage {
/// \param variable_id
/// \param attribute_enum
/// \param value
/// \param source The source of the value.
/// \return true if the value could be set in the storage, else false
virtual bool set_variable_attribute_value(const Component& component_id, const Variable& variable_id,
const AttributeEnum& attribute_enum, const std::string& value) = 0;
const AttributeEnum& attribute_enum, const std::string& value,
const std::string& source) = 0;

/// \brief Inserts or replaces a variable monitor in the database
/// \param data Monitor data to set
Expand Down
24 changes: 22 additions & 2 deletions include/ocpp/v201/device_model_storage_sqlite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,26 @@ class DeviceModelStorageSqlite : public DeviceModelStorage {

public:
/// \brief Opens SQLite connection at given \p db_path
/// \param db_path path to database
///
/// With this constructor, you can initialize the database as well.
///
/// \param db_path Path to database
/// \param migration_files_path Path to the migration files to initialize the database (only needs to be set if
/// `init_db` is true)
/// \param schemas_path Path to the device model schemas (only needs to be set if `init_db` is true)
/// \param config_path Path to the configuration file (only needs to be set if `init_db` is true)
/// \param init_db True to initialize the database
///
explicit DeviceModelStorageSqlite(const fs::path& db_path, const std::filesystem::path& migration_files_path,
const std::filesystem::path& schemas_path,
const std::filesystem::path& config_path, const bool init_db);

/// \brief Opens SQLite connection at given \p db_path
///
/// Will not initialize the database.
///
/// \param db_path Path to database
///
explicit DeviceModelStorageSqlite(const fs::path& db_path);
~DeviceModelStorageSqlite() = default;

Expand All @@ -38,7 +57,8 @@ class DeviceModelStorageSqlite : public DeviceModelStorage {
const std::optional<AttributeEnum>& attribute_enum) final;

bool set_variable_attribute_value(const Component& component_id, const Variable& variable_id,
const AttributeEnum& attribute_enum, const std::string& value) final;
const AttributeEnum& attribute_enum, const std::string& value,
const std::string& source) final;

std::optional<VariableMonitoringMeta> set_monitoring_data(const SetMonitoringData& data,
const VariableMonitorType type) final;
Expand Down
Loading
Loading