From e8e9b9ea06d9996c9f0a1012117fa439dfa21e6e Mon Sep 17 00:00:00 2001 From: Pietfried <37657534+Pietfried@users.noreply.github.com> Date: Wed, 27 Sep 2023 13:40:41 +0200 Subject: [PATCH] OCPP201 device model setup in cmake (#190) * added execution of python scripts to setup the device model database to cmake script Signed-off-by: pietfried * allowing to specify ocpp201 config as cmake parameter Signed-off-by: pietfried --------- Signed-off-by: pietfried --- README.md | 14 +------------ config/v201/CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f2ab1bc32..74ad861bc 100644 --- a/README.md +++ b/README.md @@ -103,19 +103,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 -the build process of [everest-core](https://github.com/EVerest/everest-core) will take care of installing all necessary dependencies for you. Additionally for OCPP2.0.1 you need to set up the SQLite device model storage database. - -```bash -cd config/v201 -python3 init_device_model_db.py -python3 insert_device_model_config.py --config config.json --db /tmp/ocpp201/device_model_storage.db -``` - -These two scripts do the following: - -- create the database and tables and it will -- insert the variables with a role standardized within the OCPP2.0.1 specification -- insert the VariableAttributes specified within the config.json +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. ## Integrate this library with your Charging Station Implementation for OCPP1.6 OCPP is a protocol that affects, controls and monitors many areas of a charging station's operation. diff --git a/config/v201/CMakeLists.txt b/config/v201/CMakeLists.txt index e43a31faf..a2f45a90b 100644 --- a/config/v201/CMakeLists.txt +++ b/config/v201/CMakeLists.txt @@ -1,5 +1,7 @@ set(SQL_INIT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/init_core.sql") +option(LIBOCPP_INSTALL_DEVICE_MODEL_DATABASE "Install device model database for OCPP201" ON) + list(APPEND CONFIGS config.json ../logging.ini @@ -10,4 +12,41 @@ install( DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201 ) -install(FILES ${SQL_INIT_FILE} DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201) \ No newline at end of file +install(FILES ${SQL_INIT_FILE} DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP201) + +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 + ) + + set(INIT_DEVICE_MODULE_DB_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/init_device_model_db.py") + set(INSERT_DEVICE_MODULE_CONFIG_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/insert_device_model_config.py") + set(DEVICE_MODEL_DATABASE_FILE "device_model_storage.db") + + if(NOT LIBOCPP_V201_CONFIG_FILE) + set(LIBOCPP_V201_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/config.json") + endif() + + + message(STATUS "Using ocpp v201 config file path: ${LIBOCPP_V201_CONFIG_FILE}") + + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} ${INIT_DEVICE_MODULE_DB_SCRIPT} --out ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} + ) + + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} ${INSERT_DEVICE_MODULE_CONFIG_SCRIPT} --db ${CMAKE_CURRENT_BINARY_DIR}/${DEVICE_MODEL_DATABASE_FILE} --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) +endif()