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

Rename 'component schemas' to 'component config' #794

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ All documentation and the issue tracking can be found in our main repository her
| ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
| [OCPP 1.6 Security Whitepaper (3rd edition)](https://www.openchargealliance.org/uploads/files/OCPP-1.6-security-whitepaper-edition-3.zip) | :heavy_check_mark: yes |
| [Using ISO 15118 Plug & Charge with OCPP 1.6](https://www.openchargealliance.org/uploads/files/ocpp_1_6_ISO_15118_v10.pdf) | :heavy_check_mark: yes |
| [OCPP & California Pricing Requirements](https://www.openchargealliance.org/uploads/files/ocpp_and_dms_evse_regulation-v2.0.pdf) | |
| [OCPP & California Pricing Requirements](https://www.openchargealliance.org/uploads/files/ocpp_and_dms_evse_regulation-v2.0.pdf) | :heavy_check_mark: yes |

## Support for OCPP 2.0.1

Expand All @@ -88,7 +88,7 @@ The development of OCPP2.0.1 is in progress.

| Whitepapers & Application Notes | Supported |
| ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
| [OCPP & California Pricing Requirements](https://www.openchargealliance.org/uploads/files/ocpp_and_dms_evse_regulation-v2.0.pdf) | |
| [OCPP & California Pricing Requirements](https://www.openchargealliance.org/uploads/files/ocpp_and_dms_evse_regulation-v2.0.pdf) | WIP |



Expand Down Expand Up @@ -158,7 +158,7 @@ This library is automatically integrated as the OCPP and OCPP201 module within [
If you run libocpp with OCPP1.6 with EVerest, the build process of [everest-core](https://github.com/EVerest/everest-core) will take care of installing all necessary dependencies for you.

### Run OCPP2.0.1 with EVerest
If you run libocpp with OCPP1.6 with EVerest, the build process of [everest-core](https://github.com/EVerest/everest-core) will take care of installing all necessary dependencies for you. This includes the initialization of the device model database using the [config.json](config/v201/config.json) file.
If you run libocpp with OCPP1.6 with EVerest, the build process of [everest-core](https://github.com/EVerest/everest-core) will take care of installing all necessary dependencies for you. This includes the initialization of the device model database using the [component config](config/v201/component_config) files.

## Integrate this library with your Charging Station Implementation for OCPP1.6

Expand Down
29 changes: 12 additions & 17 deletions doc/ocpp_201_device_model_initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,32 @@
to true.


## Database, component schemas and config file paths
## Database, component config 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
'custom', both containing device model schemas.
- The path of the config file.
- The path of the directory with the device model config. There should be two directories in it: 'standardized' and
'custom', both containing device model config.


## Component schemas and config file
## Component config

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

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

The config and the component schemas depend on each other. If the definition in the component schema does not match the
definition in the config, no values will be set in the device model database. So if for example there is a variable set
in the config that is not in the component schema, the config values will not be set.
attributes from the component config.

Check notice on line 21 in doc/ocpp_201_device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/ocpp_201_device_model_initialization.md#L21

Expected: 0 or 2; Actual: 1


## Update config values

Each time the ChargePoint class is instantiated, the config file is read and the values will be set to the database
accordingly. Only the initial values will be set to the values in the config file. So if for example the CSMS changed a
value, it will not be updated to the value from the config file.
Each time the ChargePoint class is instantiated, the component config is read and the values will be set to the database

Check notice on line 26 in doc/ocpp_201_device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/ocpp_201_device_model_initialization.md#L26

Expected: 0 or 2; Actual: 1
accordingly. Only the initial values will be set to the values in the component config. So if for example the CSMS
changed a value, it will not be updated to the value from the component config file.


## Update component config

To update a component, just place the correct json schema in the `component_config/custom` folder. When restarting the
software, it will:
To update a component, just place the correct json component config in the `component_config/custom` or
`component_config/standardized` folder. When restarting the software, it will:
- Check if there are Components in the database that are not in the component config's. Those will be removed.
- Check if there are Components in the component config's that are not in the database. Those will be added.
- Check if anything has changed inside the Component (`Variable`, `Characteristics` or `Attributes`).
Expand All @@ -48,3 +41,5 @@
addition of a new one.

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

Note: There should be no duplicate components or variables in the component config files.

Check notice on line 45 in doc/ocpp_201_device_model_initialization.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/ocpp_201_device_model_initialization.md#L45

Expected: 80; Actual: 89
2 changes: 1 addition & 1 deletion include/ocpp/v201/device_model_storage_sqlite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DeviceModelStorageSqlite : public DeviceModelStorage {
/// \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 config_path Path to the device model schemas (only needs to be set if `init_db` is true)
/// \param config_path Path to the device model config (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 = "",
Expand Down
50 changes: 25 additions & 25 deletions include/ocpp/v201/init_device_model_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
/// @details @copydetails ocpp::v201::InitDeviceModelDb
///
/// @class ocpp::v201::InitDeviceModelDb
/// @brief Class to initialize the device model db using the schema's and config file
/// @brief Class to initialize the device model db using the component config files
///
/// This class will read the device model schemas and config file and put them in the device model database.
/// This class will read the device model config files and put them in the device model database.
///
/// If the database already exists and there are some changes on components, this class will make the changes in the
/// database accordingly.
///
/// It will also re-apply the config file. Config items will only be replaced if they are changed and the value in the
/// database is not set by an external source, like the CSMS.
/// It will also re-apply the component config. Config items will only be replaced if they are changed and the value in
/// the database is not set by an external source, like the CSMS.
///
/// The data from the schema json files or database are read into some structs. Some structs could be reused from
/// the DeviceModelStorage class, but some members are missing there and and to prevent too many database reads, some
/// structs are 'redefined' in this class with the proper members.
/// The data from the component config json files or database are read into some structs. Some structs could be reused
/// from the DeviceModelStorage class, but some members are missing there and and to prevent too many database reads,
/// some structs are 'redefined' in this class with the proper members.
///
/// Since the DeviceModel class creates a map based on the device model database in the constructor, this class should
/// first be finished with the initialization before creating the DeviceModel class.
Expand All @@ -43,7 +43,7 @@ namespace ocpp::v201 {
/// \brief Class that holds a component.
///
/// When the component is read from the database, the component id will be set.
/// When the component is read from the schema file, the 'required' vector will be filled.
/// When the component is read from the component config file, the 'required' vector will be filled.
///
struct ComponentKey {
std::optional<uint64_t> db_id; ///< \brief Component id in the database.
Expand Down Expand Up @@ -89,22 +89,22 @@ struct DeviceModelVariable {
bool required;
/// \brief Variable instance
std::optional<std::string> instance;
/// \brief Default value, if this is set in the schemas json
/// \brief Default value, if this is set in the component config json
std::optional<std::string> default_actual_value;
/// \brief Config monitors, if any
std::vector<VariableMonitoringMeta> monitors;
};

/// \brief Convert from json to a ComponentKey struct.
/// The to_json is not implemented as we don't need to write the schema to a json file.
/// The to_json is not implemented as we don't need to write the component config to a json file.
void from_json(const json& j, ComponentKey& c);

/// \brief Convert from json to a DeviceModelVariable struct.
/// The to_json is not implemented for this struct as we don't need to write the schema to a json file.
/// The to_json is not implemented for this struct as we don't need to write the component config to a json file.
void from_json(const json& j, DeviceModelVariable& c);

/// \brief Convert from json to a VariableMonitoringMeta struct.
/// The to_json is not implemented for this struct as we don't need to write the schema to a json file.
/// The to_json is not implemented for this struct as we don't need to write the component config to a json file.
void from_json(const json& j, VariableMonitoringMeta& c);

///
Expand Down Expand Up @@ -147,8 +147,8 @@ class InitDeviceModelDb : public common::DatabaseHandlerCommon {
virtual ~InitDeviceModelDb();

///
/// \brief Initialize the database schema.
/// \param config_path Path to the database schemas.
/// \brief Initialize the database schema and component config.
/// \param config_path Path to the component config.
/// \param delete_db_if_exists Set to true to delete the database if it already exists.
///
/// \throws InitDeviceModelDbError - When database could not be initialized or
Expand All @@ -157,7 +157,7 @@ class InitDeviceModelDb : public common::DatabaseHandlerCommon {
/// \throws std::runtime_error If something went wrong during migration
/// \throws DatabaseMigrationException If something went wrong during migration
/// \throws DatabaseConnectionException If the database could not be opened
/// \throws std::filesystem::filesystem_error If the schemas path does not exist
/// \throws std::filesystem::filesystem_error If the component config path does not exist
///
///
void initialize_database(const std::filesystem::path& config_path, const bool delete_db_if_exists);
Expand All @@ -183,8 +183,8 @@ class InitDeviceModelDb : public common::DatabaseHandlerCommon {
std::vector<std::filesystem::path> get_component_config_from_directory(const std::filesystem::path& directory);

///
/// \brief Read all component schema's from the given directory and create a map holding the structure.
/// \param directory The parent directory containing the standardized and custom schema's.
/// \brief Read all component config files from the given directory and create a map holding the structure.
/// \param directory The parent directory containing the standardized and custom component config files.
/// \return A map with the device model components, variables, characteristics and attributes.
///
std::map<ComponentKey, std::vector<DeviceModelVariable>>
Expand All @@ -209,12 +209,12 @@ class InitDeviceModelDb : public common::DatabaseHandlerCommon {
const std::vector<DeviceModelVariable>& component_variables);

///
/// \brief Read component schemas from given files.
/// \param components_schema_path The paths to the component schema files.
/// \brief Read component config from given files.
/// \param components_config_path The paths to the component config files.
/// \return A map holding the components with its variables, characteristics and attributes.
///
std::map<ComponentKey, std::vector<DeviceModelVariable>>
read_component_config(const std::vector<std::filesystem::path>& components_schema_path);
read_component_config(const std::vector<std::filesystem::path>& components_config_path);

///
/// \brief Get all component properties (variables) from the given (component) json.
Expand Down Expand Up @@ -388,13 +388,13 @@ class InitDeviceModelDb : public common::DatabaseHandlerCommon {
const ComponentKey& component);

///
/// \brief Check if a component exist in the component schema.
/// \param component_schema The map of component / variables read from the json component schema.
/// \brief Check if a component exist in the component config.
/// \param component_config The map of component / variables read from the json component config.
/// \param component The component to check.
/// \return True when the component exists in the schema.
/// \return True when the component exists in the config.
///
bool component_exists_in_schemas(const std::map<ComponentKey, std::vector<DeviceModelVariable>>& component_schema,
const ComponentKey& component);
bool component_exists_in_config(const std::map<ComponentKey, std::vector<DeviceModelVariable>>& component_config,
const ComponentKey& component);

///
/// \brief Remove components from db that do not exist in the component config.
Expand Down
Loading
Loading