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 all 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
36 changes: 11 additions & 25 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 @@ -24,16 +33,6 @@ 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
)

set(INIT_DEVICE_MODULE_DB_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/init_device_model_db.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")
Expand All @@ -46,19 +45,6 @@ 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} 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 ${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 @@ -34,7 +34,8 @@
}
],
"description": "This variable reports current availability state for the ChargingStation",
"type": "string"
"type": "string",
"default": ""
},
"ChargingStationPhaseRotation": {
"variable_name": "PhaseRotation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
}
],
"instance": "Cost",
"description": "Instance Cost: Wheter costs are enabled.",
"description": "Instance Cost: Whether costs are enabled.",
"type": "boolean"
},
"TariffFallbackMessage": {
Expand Down
35 changes: 5 additions & 30 deletions config/v201/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
"Actual": true
}
},
"EVSEPower": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering why these variables were removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

They have been removed because they are not configuration but telemetry variables, so there is no reason to have them in the config.

"variable_name": "Power",
"attributes": {
"MaxSet": 22000
}
},
"EVSESupplyPhases": {
"variable_name": "SupplyPhases",
"attributes": {
Expand Down Expand Up @@ -101,12 +95,6 @@
"Actual": true
}
},
"EVSEPower": {
"variable_name": "Power",
"attributes": {
"MaxSet": 22000
}
},
"EVSESupplyPhases": {
"variable_name": "SupplyPhases",
"attributes": {
Expand Down Expand Up @@ -431,8 +419,8 @@
"Actual": true
}
},
"PncEnabled": {
"variable_name": "PncEnabled",
"PnCEnabled": {
"variable_name": "PnCEnabled",
"attributes": {
"Actual": true
}
Expand Down Expand Up @@ -570,24 +558,12 @@
"attributes": {
"Actual": true
}
},
"AuthCacheStorage": {
"variable_name": "Storage",
"attributes": {
"Actual": 0
}
}
}
},
{
"name": "ChargingStation",
"variables": {
"ChargingStationAvailabilityState": {
"variable_name": "AvailabilityState",
"attributes": {
"Actual": ""
}
},
"ChargingStationAvailable": {
"variable_name": "Available",
"attributes": {
Expand Down Expand Up @@ -667,15 +643,13 @@
"variable_name": "ReportingValueSize",
"attributes": {
"Actual": 2500
},
"instance": "SetVariables"
}
},
"ValueSize": {
"variable_name": "ValueSize",
"attributes": {
"Actual": 2500
},
"instance": "SetVariables"
}
},
"DeviceDataCtrlrEnabled": {
"variable_name": "Enabled",
Expand Down Expand Up @@ -708,6 +682,7 @@
},
"TariffCostCtrlrEnabledCost": {
"variable_name": "Enabled",
"instance": "Cost",
"attributes": {
"Actual": false
}
Expand Down
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,
"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;
Loading
Loading