diff --git a/.gitignore b/.gitignore index 8ffa5a31..70ed312c 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,15 @@ *.out *.app +# Diagrams +*.svg + # Directories .vscode/ +.cache/ +.cmake/ build/ +debug/ +release/ +docs/html/ +docs/latex/ diff --git a/100.txt b/100.txt deleted file mode 100644 index 9b372a1b..00000000 --- a/100.txt +++ /dev/null @@ -1,100 +0,0 @@ -1 : OK in 0.131622 seconds -3 : OK in 0.170275 seconds -15 : OK in 0.134248 seconds -2 : OK in 0.139993 seconds -7 : OK in 0.132992 seconds -35 : OK in 0.16605 seconds -17 : OK in 0.151257 seconds -12 : OK in 0.142562 seconds -25 : OK in 0.164626 seconds -30 : OK in 0.162764 seconds -18 : OK in 0.1627 seconds -14 : OK in 0.167523 seconds -29 : OK in 0.143779 seconds -34 : OK in 0.156133 seconds -21 : OK in 0.165222 seconds -27 : OK in 0.178725 seconds -10 : OK in 0.146221 seconds -31 : OK in 0.191024 seconds -32 : OK in 0.17652 seconds -13 : OK in 0.185508 seconds -19 : OK in 0.197482 seconds -5 : OK in 0.178266 seconds -11 : OK in 0.186817 seconds -8 : OK in 0.196428 seconds -28 : OK in 0.167224 seconds -26 : OK in 0.179497 seconds -23 : OK in 0.201345 seconds -33 : OK in 0.183377 seconds -44 : OK in 0.179111 seconds -47 : OK in 0.165975 seconds -56 : OK in 0.151585 seconds -50 : OK in 0.168131 seconds -58 : OK in 0.159508 seconds -42 : OK in 0.168596 seconds -41 : OK in 0.196369 seconds -57 : OK in 0.186587 seconds -36 : OK in 0.173034 seconds -43 : OK in 0.194361 seconds -59 : OK in 0.155022 seconds -49 : OK in 0.257182 seconds -48 : OK in 0.23013 seconds -9 : OK in 0.315012 seconds -55 : OK in 0.259476 seconds -74 : OK in 0.14939 seconds -83 : OK in 0.156789 seconds -64 : OK in 0.24709 seconds -65 : OK in 0.241653 seconds -72 : OK in 0.207218 seconds -54 : OK in 0.272634 seconds -69 : OK in 0.217608 seconds -82 : OK in 0.204795 seconds -68 : OK in 0.236746 seconds -52 : OK in 0.273472 seconds -73 : OK in 0.206015 seconds -63 : OK in 0.238569 seconds -60 : OK in 0.255195 seconds -62 : OK in 0.254278 seconds -67 : OK in 0.240239 seconds -16 : OK in 0.344161 seconds -66 : OK in 0.248356 seconds -22 : OK in 0.349986 seconds -88 : OK in 0.140096 seconds -6 : OK in 0.320892 seconds -70 : OK in 0.24922 seconds -81 : OK in 0.243158 seconds -76 : OK in 0.185436 seconds -24 : OK in 0.351951 seconds -80 : OK in 0.227388 seconds -46 : OK in 0.310198 seconds -40 : OK in 0.337583 seconds -84 : OK in 0.231697 seconds -4 : OK in 0.37104 seconds -38 : OK in 0.351712 seconds -79 : OK in 0.213645 seconds -87 : OK in 0.128281 seconds -37 : OK in 0.379381 seconds -53 : OK in 0.317925 seconds -45 : OK in 0.336058 seconds -95 : OK in 0.236194 seconds -97 : OK in 0.133618 seconds -85 : OK in 0.192991 seconds -90 : OK in 0.193727 seconds -86 : OK in 0.151695 seconds -39 : OK in 0.385822 seconds -96 : OK in 0.158553 seconds -89 : OK in 0.12793 seconds -71 : OK in 0.164953 seconds -51 : OK in 0.329716 seconds -77 : OK in 0.147135 seconds -20 : OK in 0.409325 seconds -61 : OK in 0.335699 seconds -91 : OK in 0.148994 seconds -92 : OK in 0.138636 seconds -99 : OK in 0.151468 seconds -100 : OK in 0.148223 seconds -98 : OK in 0.136397 seconds -94 : OK in 0.134048 seconds -93 : OK in 0.174573 seconds -78 : OK in 0.173142 seconds -75 : OK in 0.169184 seconds diff --git a/CMakeLists.txt b/CMakeLists.txt index d01e62d2..28a536fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,59 +1,53 @@ -# You should always specify a range with the newest -# and oldest tested versions of CMake. -cmake_minimum_required(VERSION 3.14) - -# set version -set(PROJECT_VERSION 2.0.0) -set(PROJECT_NAME EGOT_ESI) +# You should always specify a range with the newest and oldest tested versions +# of CMake. +cmake_minimum_required(VERSION 3.18) # This is your project statement. You should always list languages; project( - ${PROJECT_NAME} - VERSION ${PROJECT_VERSION} -) + EGoT + VERSION 0.1.0 + LANGUAGES CXX) -# specify the C++ standard -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # fetch remote packages for development -find_package(Boost REQUIRED filesystem python3) -find_package(PythonLibs 3 REQUIRED) +find_package(Boost REQUIRED python filesystem) + +find_package(Python3 COMPONENTS Interpreter Development) + +include(FindThreads) + +include(FindXercesC) + +include(FindGTest) include(FetchContent) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.11.0 -) + +set(FETCHCONTENT_UPDATES_DISCONNECTED + ON + CACHE BOOL "Do not update everytime I run cmake, please") FetchContent_Declare( flecs - GIT_REPOSITORY https://github.com/SanderMertens/flecs.git - GIT_TAG v3.0.3 -) + GIT_REPOSITORY git@github.com:SanderMertens/flecs.git + GIT_TAG master) -FetchContent_MakeAvailable(googletest flecs) +FetchContent_Declare( + cea2045 + GIT_REPOSITORY https://github.com/epri-dev/CTA-2045-UCM-CPP-Library.git + GIT_TAG v1.0) -add_subdirectory(utilities) -add_subdirectory(standards) -add_subdirectory(ecs) -add_subdirectory(interfaces) -add_subdirectory(dtm) -#add_subdirectory(gsp) -#add_subdirectory(dcm) +FetchContent_MakeAvailable(flecs cea2045) +add_subdirectory(libs) +add_subdirectory(apps) # install resources for programs execute_process( - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_CURRENT_SOURCE_DIR}/resources/ - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ -) + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/resources/ ${CMAKE_BINARY_DIR}/bin/) execute_process( - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_CURRENT_SOURCE_DIR}/ssl/root-ca/ - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/root-ca -) \ No newline at end of file + COMMAND + ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/ssl/root-ca/ + ${CMAKE_BINARY_DIR}/bin/root-ca/) diff --git a/README.md b/README.md index 14ef3e7c..f69a40af 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,56 @@ Department of Energy - Energy Grid of Things System ## Development +- https://tmuxcheatsheet.com/ ### Linux OS ``` cd doe-egot-system -./setup.sh +./tools/setup.sh ``` ## Building +For development the build type should be set to *Debug*, but all performance testing should use *Release*. There may be issues when trying to compile multiple build types so the build folder should have a different name. +```shell +cd doe-egot-system +cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 +cmake --build build +``` +### Documentation +If you would like to build the documentation install the following requirments and run doxygen. +```shell +sudo apt install doxygen graphviz +cd docs +doxygen ``` + +If you would like a PDF of the documentation run install the following requirments and run make within the latex folder. +```shell +sudo apt install texlive-base texlive-latex-recommended texlive-latex-extra +cd docs +doxygen +cd latex +make +``` + +## Running +Running the system as a whole is done through the *run_egot.sh* script found in tools. It will spawn tree tmux sessions: GSP, DTMC, and DERS. The DERS session will have *n* number of DCMS running in individual windows within the session. See snapshot of terminal after running. + + +```shell cd doe-egot-system -cmake -S . -B build -cmake --build build +./tools/run_egot.sh +tmux ls +tmux a -t +``` + +## Stop +Stopping the EGoT system only requires stopping all tmux sessions. + +```shell +tmux kill-server ``` ## Project Organization diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt new file mode 100644 index 00000000..efe21df9 --- /dev/null +++ b/apps/CMakeLists.txt @@ -0,0 +1,11 @@ +add_subdirectory(dtm) +add_subdirectory(dcm) +add_subdirectory(dcm-aosmith) +add_subdirectory(gsp) +add_subdirectory(simple) +execute_process( + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/dtm/ + ${CMAKE_BINARY_DIR}/bin/) +execute_process( + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/me/ + ${CMAKE_BINARY_DIR}/bin/) diff --git a/apps/dcm-aosmith/CMakeLists.txt b/apps/dcm-aosmith/CMakeLists.txt new file mode 100644 index 00000000..93d33542 --- /dev/null +++ b/apps/dcm-aosmith/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(dcm_aosmith src/main.cpp) +target_link_libraries(dcm_aosmith trust::cta2045 ecs::cta2045 sep::models + EGoT::utils Threads::Threads) + +add_executable(dcm_aosmith_test src/test.cpp) +target_link_libraries(dcm_aosmith_test trust::cta2045 ecs::cta2045 EGoT::utils + Threads::Threads) diff --git a/interfaces/modeling-environment/mock_go.cpp b/apps/dcm-aosmith/README.md similarity index 100% rename from interfaces/modeling-environment/mock_go.cpp rename to apps/dcm-aosmith/README.md diff --git a/apps/dcm-aosmith/src/main.cpp b/apps/dcm-aosmith/src/main.cpp new file mode 100644 index 00000000..e1e24bc7 --- /dev/null +++ b/apps/dcm-aosmith/src/main.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +std::string g_program_path; +// create config xml with these values and store somewhere +float frr_time_window; +float comfort_threshold; + +int main(int argc, char **argv) { + std::cout << "Starting DCM for AOSmith water heater\n"; + g_program_path = psu::utilities::getProgramPath(argv); + + flecs::world ecs; + ecs.import (); + ecs.entity().set({0, 0}); + ecs.entity().set({0, 0}); + https::Context dtm_ctx = {"1", g_program_path, "0.0.0.0", "8090"}; + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx); + ecs.app().target_fps(1).run(); + return 0; +} diff --git a/apps/dcm-aosmith/src/test.cpp b/apps/dcm-aosmith/src/test.cpp new file mode 100644 index 00000000..89a9bb95 --- /dev/null +++ b/apps/dcm-aosmith/src/test.cpp @@ -0,0 +1,46 @@ + +#include +#include +#include +#include +#include +#include +#include + +std::string g_program_path; + +int main(int argc, char **argv) { + std::cout << "Starting DCM for AOSmith water heater\n"; + g_program_path = psu::utilities::getProgramPath(argv); + + https::Context dtm_ctx = {"1", g_program_path, "0.0.0.0", "8090"}; + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx); + std::this_thread::sleep_for(std::chrono::seconds(1)); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getOutsideCommunicationStatus(cea2045::OutsideCommuncatonStatusCode::Found); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getOperationalState(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getDeviceInfo(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getCommodity(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).loadUp(0); + std::this_thread::sleep_for(std::chrono::seconds(10)); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getOperationalState(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getCommodity(); + std::this_thread::sleep_for(std::chrono::seconds(10)); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).endShed(0); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).criticalPeakEvent(60); + std::this_thread::sleep_for(std::chrono::seconds(10)); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getOperationalState(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).endShed(0); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).gridEmergency(60); + std::this_thread::sleep_for(std::chrono::seconds(10)); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getOperationalState(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).endShed(0); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).shed(60); + std::this_thread::sleep_for(std::chrono::seconds(10)); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getOperationalState(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).loadUp(0); + std::this_thread::sleep_for(std::chrono::seconds(10)); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getOperationalState(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).getCommodity(); + trust::cta2045Device::getInstance("/dev/ttyAMA0", dtm_ctx).shed(0); +return 0; +} diff --git a/apps/dcm/CMakeLists.txt b/apps/dcm/CMakeLists.txt new file mode 100644 index 00000000..d38c8ef7 --- /dev/null +++ b/apps/dcm/CMakeLists.txt @@ -0,0 +1,14 @@ +add_executable(dcm + src/main.cpp +) + +# target_include_directories(dcm PUBLIC include) + +target_link_libraries(dcm + ecs::client::sep + ecs::simulator + https::client + trust::client + EGoT::utils + Threads::Threads +) \ No newline at end of file diff --git a/dcm/README.md b/apps/dcm/README.md similarity index 100% rename from dcm/README.md rename to apps/dcm/README.md diff --git a/apps/dcm/src/main.cpp b/apps/dcm/src/main.cpp new file mode 100644 index 00000000..f23f72b0 --- /dev/null +++ b/apps/dcm/src/main.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +std::string g_program_path; + +int main(int argc, char **argv) { + std::cout << "Starting Distributed Control Module...\n"; + g_program_path = psu::utilities::getProgramPath(argv); + std::cout << "\tpath : " << g_program_path << std::endl; + + std::string index = argv[1]; + + https::Context me_ctx = {"1", g_program_path, "0.0.0.0", "9000"}; + https::Context gsp_ctx = {"1", g_program_path, "0.0.0.0", "8080"}; + https::Context dtm_ctx = {"1", g_program_path, "0.0.0.0", "8090"}; + + std::cout << "\tgsp client on " << gsp_ctx.host << ":" << gsp_ctx.port + << "\n"; + + std::cout << "\tdtm client on " << dtm_ctx.host << ":" << dtm_ctx.port + << "\n"; + + flecs::world ecs; + ecs.import (); + ecs::singleton::generateClock(ecs); + + https::SingleClient::getInstance(me_ctx); + trust::HttpsClient::getInstance(gsp_ctx, dtm_ctx); + ecs.import (); + ecs.import (); + ecs.import (); + ecs.import (); + ecs.import (); + + sep::DeviceCapabilityLink dcap_link; + dcap_link.href = "/dcap"; + + auto e = ecs.entity(); + e.set(dcap_link); + + ecs.app().target_fps(1).run(); + + return 0; +} diff --git a/dcm/tests/CMakeLists.txt b/apps/dcm/tests/CMakeLists.txt similarity index 100% rename from dcm/tests/CMakeLists.txt rename to apps/dcm/tests/CMakeLists.txt diff --git a/dcm/tests/ecs_tests.cpp b/apps/dcm/tests/ecs_tests.cpp similarity index 100% rename from dcm/tests/ecs_tests.cpp rename to apps/dcm/tests/ecs_tests.cpp diff --git a/dcm/tests/https_tests.cpp b/apps/dcm/tests/https_tests.cpp similarity index 100% rename from dcm/tests/https_tests.cpp rename to apps/dcm/tests/https_tests.cpp diff --git a/dcm/tests/main.cpp b/apps/dcm/tests/main.cpp similarity index 100% rename from dcm/tests/main.cpp rename to apps/dcm/tests/main.cpp diff --git a/apps/dtm/CMakeLists.txt b/apps/dtm/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/apps/dtm/README.md b/apps/dtm/README.md new file mode 100644 index 00000000..26382b38 --- /dev/null +++ b/apps/dtm/README.md @@ -0,0 +1,17 @@ +# Distributed Trust Module Client +Currently there is no need for the setup section as all modules used are base python. + +## Setup + +``` +python3 -m venv .venv +source .venv/bin/activate +pip install --upgrade pip +pip install -r req*.txt +``` + +## Running + +``` +python3 build/bin/dtmc.py +``` \ No newline at end of file diff --git a/apps/dtm/dtmc.py b/apps/dtm/dtmc.py new file mode 100644 index 00000000..b4cd4f59 --- /dev/null +++ b/apps/dtm/dtmc.py @@ -0,0 +1,50 @@ +# https://flaviocopes.com/python-http-server/ +# https://pythonsansar.com/creating-simple-http-server-python/ +import sys, os +from http.server import BaseHTTPRequestHandler, HTTPServer +import ssl +from datetime import datetime + +HOST_NAME = "0.0.0.0" +PORT = 8090 +ROOT = os.path.dirname(__file__) +LOG = ROOT + +def logPost (data): + with open(LOG,'a') as file: + file.write(data) + +class handler(BaseHTTPRequestHandler): + def do_POST(self): + if (self.path != '/na'): + self.send_response(404) + self.end_headers() + else: + self.send_response(201) + self.end_headers() + + content_length = int(self.headers['Content-Length']) + data = self.rfile.read(content_length).decode("utf-8") + logPost(data) + +if __name__ == "__main__": + print(ROOT) + print(f"DTMC started on https://{HOST_NAME}:{PORT}") + + LOG = ROOT + datetime.now().strftime('/log_%H_%M_%d_%m_%Y.log') + print(f"message log found at {LOG}") + + server = HTTPServer((HOST_NAME, PORT), handler) + server.socket = ssl.wrap_socket( + server.socket, + server_side=True, + certfile=ROOT + '/root-ca/server.crt', + keyfile=ROOT + '/root-ca/private/server.key', + ca_certs=ROOT + '/root-ca/cert_chain.crt') + + try: + server.serve_forever() + except KeyboardInterrupt: + server.server_close() + print("Server stopped successfully") + sys.exit(0) \ No newline at end of file diff --git a/apps/dtm/requirements.txt b/apps/dtm/requirements.txt new file mode 100644 index 00000000..e69de29b diff --git a/apps/gsp/CMakeLists.txt b/apps/gsp/CMakeLists.txt new file mode 100644 index 00000000..aea544a8 --- /dev/null +++ b/apps/gsp/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(gsp + src/main.cpp +) + +target_link_libraries(gsp + https::server + https::client + ecs::server::sep + EGoT::utils +) + +add_subdirectory(tests) \ No newline at end of file diff --git a/gsp/README.md b/apps/gsp/README.md similarity index 100% rename from gsp/README.md rename to apps/gsp/README.md diff --git a/apps/gsp/src/main.cpp b/apps/gsp/src/main.cpp new file mode 100644 index 00000000..68cb718d --- /dev/null +++ b/apps/gsp/src/main.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +std::string g_program_path; + +int main(int argc, char **argv) { + g_program_path = psu::utilities::getProgramPath(argv); + + ecs::server::World::getInstance(); + + https::Context me_ctx = {"1", g_program_path, "127.0.0.1", "9000"}; + https::SingleClient::getInstance(me_ctx); + + auto resp = https::SingleClient::getInstance().Get("/time"); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + std::cout << resp << std::endl; + + resp = https::SingleClient::getInstance().Get("/groups"); + msg = boost::beast::buffers_to_string(resp.body().data()); + std::cout << resp << std::endl; + + resp = https::SingleClient::getInstance().Get("/services"); + msg = boost::beast::buffers_to_string(resp.body().data()); + std::cout << resp << std::endl; + + HttpsServer server("0.0.0.0", 8080, g_program_path, 8); +} diff --git a/apps/gsp/tests/CMakeLists.txt b/apps/gsp/tests/CMakeLists.txt new file mode 100644 index 00000000..8b71e301 --- /dev/null +++ b/apps/gsp/tests/CMakeLists.txt @@ -0,0 +1,38 @@ +find_package(GTest REQUIRED) +find_package(Threads REQUIRED) +find_package(Boost REQUIRED filesystem) + +add_executable (gsp_tests + src/main.cpp + src/dcap_tests.cpp + src/edev_tests.cpp + src/edev_list_tests.cpp + src/rg_tests.cpp + src/tm_tests.cpp + src/frq_list_tests.cpp + src/frq_tests.cpp + src/frp_list_tests.cpp + src/frp_tests.cpp + src/rsp_tests.cpp + src/rsp_list_tests.cpp + src/ps_tests.cpp + # src/sdev_tests.cpp + # src/dstat_tests.cpp + # src/fsa_tests.cpp + # src/sub_tests.cpp + # src/ntfy_tests.cpp +) + +target_include_directories(gsp_tests PUBLIC include) + +target_link_libraries(gsp_tests + GTest::GTest + Threads::Threads + Boost::boost + Boost::filesystem + https::server + https::client + sep::xml + ecs::server::sep + EGoT::utils +) diff --git a/interfaces/https/tests/wadl_check.hpp b/apps/gsp/tests/include/wadl_check.hpp similarity index 100% rename from interfaces/https/tests/wadl_check.hpp rename to apps/gsp/tests/include/wadl_check.hpp diff --git a/apps/gsp/tests/src/dcap_tests.cpp b/apps/gsp/tests/src/dcap_tests.cpp new file mode 100644 index 00000000..91bf5e02 --- /dev/null +++ b/apps/gsp/tests/src/dcap_tests.cpp @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsDeviceCapabilityTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/dcap"; +}; + +TEST_F(HttpsDeviceCapabilityTests, GetDeviceCapability) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::cout << resp << std::endl; + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::DeviceCapability dcap; + xml::Parse(msg, &dcap); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + std::cout << e.what() << std::endl; + } +} + +TEST_F(HttpsDeviceCapabilityTests, PostDeviceCapability) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::DeviceCapability dcap; + xml::Parse(msg, &dcap); + + resp = SingleClient::getInstance().Post(path, xml::Serialize(dcap)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsDeviceCapabilityTests, PutDeviceCapability) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::DeviceCapability dcap; + xml::Parse(msg, &dcap); + + resp = SingleClient::getInstance().Put(path, xml::Serialize(dcap)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsDeviceCapabilityTests, DeleteDeviceCapability) { + try { + auto resp = SingleClient::getInstance().Delete("/dcap"); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} diff --git a/interfaces/https/tests/dstat_tests.cpp b/apps/gsp/tests/src/dstat_tests.cpp similarity index 100% rename from interfaces/https/tests/dstat_tests.cpp rename to apps/gsp/tests/src/dstat_tests.cpp diff --git a/apps/gsp/tests/src/edev_list_tests.cpp b/apps/gsp/tests/src/edev_list_tests.cpp new file mode 100644 index 00000000..f9783c74 --- /dev/null +++ b/apps/gsp/tests/src/edev_list_tests.cpp @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsEndDeviceListTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/edev"; +}; + +TEST_F(HttpsEndDeviceListTests, GetEndDeviceList) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::EndDeviceList edev_list; + xml::Parse(msg, &edev_list); + + EXPECT_EQ(edev_list.end_devices[0].lfdi, + SingleClient::getInstance().getLFDI()); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsEndDeviceListTests, PostEndDeviceList) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + sep::EndDeviceList edev_list; + xml::Parse(msg, &edev_list); + + resp = SingleClient::getInstance().Post( + path, xml::Serialize(edev_list.end_devices[0])); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsEndDeviceListTests, PutEndDeviceList) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::EndDeviceList edev_list; + xml::Parse(msg, &edev_list); + + resp = SingleClient::getInstance().Put( + path, xml::Serialize(edev_list.end_devices[0])); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsEndDeviceListTests, DeleteEndDeviceList) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::EndDeviceList edev_list; + xml::Parse(msg, &edev_list); + + resp = SingleClient::getInstance().Delete(path); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/edev_tests.cpp b/apps/gsp/tests/src/edev_tests.cpp new file mode 100644 index 00000000..8671d586 --- /dev/null +++ b/apps/gsp/tests/src/edev_tests.cpp @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsEndDeviceTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/edev"; +}; + +TEST_F(HttpsEndDeviceTests, GetEndDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::EndDevice edev; + xml::Parse(msg, &edev); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsEndDeviceTests, PostEndDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::EndDevice edev; + xml::Parse(msg, &edev); + + resp = SingleClient::getInstance().Post(uri, xml::Serialize(edev)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsEndDeviceTests, PutEndDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::EndDevice edev; + xml::Parse(msg, &edev); + + resp = SingleClient::getInstance().Put(uri, xml::Serialize(edev)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsEndDeviceTests, DeleteEndDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Delete(uri); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/frp_list_tests.cpp b/apps/gsp/tests/src/frp_list_tests.cpp new file mode 100644 index 00000000..a71a0227 --- /dev/null +++ b/apps/gsp/tests/src/frp_list_tests.cpp @@ -0,0 +1,168 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsFlowReservationResponseListTests : public ::testing::Test { +protected: + void SetUp() override { + frq.creation_time = psu::utilities::getTime(); + frq.description = "HttpsFlowReservationResponseListTests"; + frq.duration_requested = 60 * 60; + frq.energy_requested.value = 1000; + frq.energy_requested.multiplier = 1; + frq.power_requested.value = 1000; + frq.power_requested.multiplier = 1; + frq.href = request_path; + frq.interval_requested.start = frq.creation_time; + if (frq.duration_requested.is_initialized()) { + frq.interval_requested.duration = frq.duration_requested.value() * 3; + } + frq.mrid = mrid; + frq.request_status.datetime = frq.creation_time; + frq.request_status.status = sep::RequestStatus::Status::kRequested; + + SingleClient::getInstance().Post(frq.href, xml::Serialize(frq)); + + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + sep::FlowReservationRequest frq; + std::string request_path = "/frq"; + std::string response_path = "/frp"; + sep::mRIDType mrid = 0x4321; + std::string frq_uri = request_path + "/" + xml::util::Hexify(mrid); + std::string frp_uri = response_path + "/" + xml::util::Hexify(mrid); +}; + +TEST_F(HttpsFlowReservationResponseListTests, GetList) { + try { + auto resp = SingleClient::getInstance().Get(response_path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + sep::FlowReservationResponseList frp_list; + xml::Parse(msg, &frp_list); + + bool exists = false; + for (auto &frp : frp_list.flow_reservation_responses) { + if (frp.mrid == mrid) { + exists = true; + } + } + EXPECT_TRUE(exists); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(response_path); + + std::string method = "GET"; + + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationResponseListTests, PostList) { + try { + auto resp = SingleClient::getInstance().Get(response_path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationResponseList frp_list; + xml::Parse(msg, &frp_list); + + resp = SingleClient::getInstance().Post( + frp_list.flow_reservation_responses[0].href, + xml::Serialize(frp_list.flow_reservation_responses[0])); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(response_path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationResponseListTests, PutList) { + try { + auto resp = SingleClient::getInstance().Get(response_path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationResponseList frp_list; + xml::Parse(msg, &frp_list); + + resp = SingleClient::getInstance().Put( + frp_list.flow_reservation_responses[0].href, + xml::Serialize(frp_list.flow_reservation_responses[0])); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(response_path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationResponseListTests, DeleteList) { + try { + auto resp = SingleClient::getInstance().Get(response_path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationResponseList frp_list; + xml::Parse(msg, &frp_list); + + resp = SingleClient::getInstance().Delete( + frp_list.flow_reservation_responses[0].href); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(response_path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/frp_tests.cpp b/apps/gsp/tests/src/frp_tests.cpp new file mode 100644 index 00000000..70edc703 --- /dev/null +++ b/apps/gsp/tests/src/frp_tests.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsFlowReservationResponseTests : public ::testing::Test { +protected: + void SetUp() override { + frq.creation_time = psu::utilities::getTime(); + frq.description = "HttpsFlowReservationResponseListTests"; + frq.duration_requested = 60 * 60; + frq.energy_requested.value = 1000; + frq.energy_requested.multiplier = 1; + frq.power_requested.value = 1000; + frq.power_requested.multiplier = 1; + frq.href = "/frq"; + frq.interval_requested.start = frq.creation_time; + if (frq.duration_requested.is_initialized()) { + frq.interval_requested.duration = frq.duration_requested.value() * 3; + } + frq.mrid = mrid; + frq.request_status.datetime = frq.creation_time; + frq.request_status.status = sep::RequestStatus::Status::kRequested; + + auto resp = SingleClient::getInstance().Post(frq.href, xml::Serialize(frq)); + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + sep::FlowReservationRequest frq; + std::string path = "/frp"; + sep::mRIDType mrid = 0x0001; + std::string uri = path + "/" + xml::util::Hexify(mrid); +}; + +TEST_F(HttpsFlowReservationResponseTests, GetResponseSet) { + try { + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationResponse frp; + xml::Parse(msg, &frp); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationResponseTests, PostResponseSet) { + try { + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationResponse frp; + xml::Parse(msg, &frp); + + resp = SingleClient::getInstance().Post(path, xml::Serialize(frp)); + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationResponseTests, PutResponseSet) { + try { + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationResponse frp; + xml::Parse(msg, &frp); + + resp = SingleClient::getInstance().Put(path, xml::Serialize(frp)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationResponseTests, DeleteResponseSet) { + try { + auto resp = SingleClient::getInstance().Delete(uri); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/frq_list_tests.cpp b/apps/gsp/tests/src/frq_list_tests.cpp new file mode 100644 index 00000000..29fddd22 --- /dev/null +++ b/apps/gsp/tests/src/frq_list_tests.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsFlowReservationRequestListTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/frq"; + sep::mRIDType mrid = 0x4321; + std::string uri = path + "/" + xml::util::Hexify(mrid); +}; + +TEST_F(HttpsFlowReservationRequestListTests, PostList) { + try { + sep::FlowReservationRequest frq; + frq.creation_time = psu::utilities::getTime(); + frq.description = "HttpsFlowReservationResponseListTests"; + frq.duration_requested.emplace(60 * 60); + frq.energy_requested.value = 1000; + frq.energy_requested.multiplier = 1; + frq.power_requested.value = 1000; + frq.power_requested.multiplier = 1; + frq.href = "/frq"; + frq.interval_requested.start = frq.creation_time; + frq.interval_requested.duration = frq.duration_requested.value() * 3; + frq.mrid = mrid; + frq.request_status.datetime = frq.creation_time; + frq.request_status.status = sep::RequestStatus::Status::kRequested; + + auto resp = SingleClient::getInstance().Post(frq.href, xml::Serialize(frq)); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationRequestListTests, GetList) { + try { + + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationRequestList frq_list; + xml::Parse(msg, &frq_list); + bool exists = false; + for (auto &frq : frq_list.flow_reservation_requests) { + if (frq.mrid == mrid) { + exists = true; + } + } + EXPECT_TRUE(exists); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationRequestListTests, PutList) { + try { + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationRequest frq; + xml::Parse(msg, &frq); + + resp = SingleClient::getInstance().Put(uri, xml::Serialize(frq)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationRequestListTests, DeleteList) { + try { + auto resp = SingleClient::getInstance().Delete(uri); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/frq_tests.cpp b/apps/gsp/tests/src/frq_tests.cpp new file mode 100644 index 00000000..572f3b78 --- /dev/null +++ b/apps/gsp/tests/src/frq_tests.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsFlowReservationRequestTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/frq"; +}; + +TEST_F(HttpsFlowReservationRequestTests, Get) { + try { + sep::FlowReservationRequest frq; + frq.creation_time = psu::utilities::getTime(); + frq.description = "HttpsFlowReservationResponseListTests"; + frq.duration_requested.emplace(60 * 60); + frq.energy_requested.value = 1000; + frq.energy_requested.multiplier = 1; + frq.power_requested.value = 1000; + frq.power_requested.multiplier = 1; + frq.href = path; + frq.interval_requested.start = frq.creation_time; + frq.interval_requested.duration = frq.duration_requested.value() * 3; + frq.mrid = 0x9876; + frq.request_status.datetime = frq.creation_time; + frq.request_status.status = sep::RequestStatus::Status::kRequested; + + SingleClient::getInstance().Post(frq.href, xml::Serialize(frq)); + + std::string uri = frq.href + "/" + xml::util::Hexify(frq.mrid); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + xml::Parse(msg, &frq); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationRequestTests, Post) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationRequestList frq_list; + xml::Parse(msg, &frq_list); + sep::FlowReservationRequest frq = frq_list.flow_reservation_requests[0]; + + resp = SingleClient::getInstance().Post(frq.href, xml::Serialize(frq)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationRequestTests, Put) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::FlowReservationRequestList frq_list; + xml::Parse(msg, &frq_list); + sep::FlowReservationRequest frq = frq_list.flow_reservation_requests[0]; + + resp = SingleClient::getInstance().Put(frq.href, xml::Serialize(frq)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsFlowReservationRequestTests, Delete) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Delete(uri); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/interfaces/https/tests/fsa_tests.cpp b/apps/gsp/tests/src/fsa_tests.cpp similarity index 100% rename from interfaces/https/tests/fsa_tests.cpp rename to apps/gsp/tests/src/fsa_tests.cpp diff --git a/apps/gsp/tests/src/main.cpp b/apps/gsp/tests/src/main.cpp new file mode 100644 index 00000000..36ee2fa6 --- /dev/null +++ b/apps/gsp/tests/src/main.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std::chrono_literals; + +std::string g_program_path; + +void func() { HttpsServer server("0.0.0.0", 8080, g_program_path, 4); } + +int main(int argc, char **argv) { + g_program_path = psu::utilities::getProgramPath(argv); + + ecs::server::World::getInstance(); + + https::Context ctx = {"1", g_program_path, "0.0.0.0", "8080"}; + + // init context so other calls don't need it + https::SingleClient::getInstance(ctx); + + // run server in seperate thread and detach for auto cleanup + std::thread first(func); + first.detach(); + + ::testing::InitGoogleTest(&argc, argv); + std::this_thread::sleep_for(1s); + return RUN_ALL_TESTS(); +} diff --git a/interfaces/https/tests/ntfy_tests.cpp b/apps/gsp/tests/src/ntfy_tests.cpp similarity index 100% rename from interfaces/https/tests/ntfy_tests.cpp rename to apps/gsp/tests/src/ntfy_tests.cpp diff --git a/apps/gsp/tests/src/ps_list_tests.cpp b/apps/gsp/tests/src/ps_list_tests.cpp new file mode 100644 index 00000000..cecd4484 --- /dev/null +++ b/apps/gsp/tests/src/ps_list_tests.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsPowerStatusListTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/ps"; +}; + +TEST_F(HttpsPowerStatusListTests, PutResponse) { + try { + sep::PowerStatus ps; + ps.href = path; + ps.poll_rate = 900; + ps.battery_status = sep::BatteryStatus::kNormal; + ps.changed_time = psu::utilities::getTime(); + ps.current_power_source = sep::PowerSourceType::kMains; + + auto resp = SingleClient::getInstance().Put(path, xml::Serialize(ps)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsPowerStatusListTests, GetResponse) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::Response rsp; + xml::Parse(msg, &rsp); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsPowerStatusListTests, PostResponse) { + try { + sep::PowerStatus ps; + ps.href = path; + ps.poll_rate = 900; + ps.battery_status = sep::BatteryStatus::kNormal; + ps.changed_time = psu::utilities::getTime(); + ps.current_power_source = sep::PowerSourceType::kMains; + + auto resp = SingleClient::getInstance().Post(path, xml::Serialize(ps)); + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsPowerStatusListTests, DeleteResponse) { + try { + auto resp = SingleClient::getInstance().Delete(path); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/ps_tests.cpp b/apps/gsp/tests/src/ps_tests.cpp new file mode 100644 index 00000000..ba66eb8e --- /dev/null +++ b/apps/gsp/tests/src/ps_tests.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsPowerStatusListTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/ps"; +}; + +TEST_F(HttpsPowerStatusListTests, PutResponse) { + try { + sep::PowerStatus ps; + ps.href = path; + ps.poll_rate = 900; + ps.battery_status = sep::BatteryStatus::kNormal; + ps.changed_time = psu::utilities::getTime(); + ps.current_power_source = sep::PowerSourceType::kMains; + + auto resp = SingleClient::getInstance().Put(path, xml::Serialize(ps)); + std::cout << resp << std::endl; + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsPowerStatusListTests, PostResponse) { + try { + sep::PowerStatus ps; + ps.href = path; + ps.poll_rate = 900; + ps.battery_status = sep::BatteryStatus::kNormal; + ps.changed_time = psu::utilities::getTime(); + ps.current_power_source = sep::PowerSourceType::kMains; + + auto resp = SingleClient::getInstance().Post(path, xml::Serialize(ps)); + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsPowerStatusListTests, GetResponse) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + std::cout << resp << std::endl; + + sep::PowerStatus ps; + xml::Parse(msg, &ps); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsPowerStatusListTests, DeleteResponse) { + try { + auto resp = SingleClient::getInstance().Delete(path); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/rg_tests.cpp b/apps/gsp/tests/src/rg_tests.cpp new file mode 100644 index 00000000..26aedd37 --- /dev/null +++ b/apps/gsp/tests/src/rg_tests.cpp @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsRegistrationTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/rg"; +}; + +TEST_F(HttpsRegistrationTests, GetRegistration) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::Registration rg; + xml::Parse(msg, &rg); + + EXPECT_EQ(rg.pin, xml::util::generatePIN(xml::util::Hexify( + SingleClient::getInstance().getLFDI()))); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsRegistrationTests, PostRegistration) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::Registration rg; + xml::Parse(msg, &rg); + + resp = SingleClient::getInstance().Post(path, xml::Serialize(rg)); + + EXPECT_EQ(rg.pin, xml::util::generatePIN(xml::util::Hexify( + SingleClient::getInstance().getLFDI()))); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsRegistrationTests, PutRegistration) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::Registration rg; + xml::Parse(msg, &rg); + + resp = SingleClient::getInstance().Put(path, xml::Serialize(rg)); + + EXPECT_EQ(rg.pin, xml::util::generatePIN(xml::util::Hexify( + SingleClient::getInstance().getLFDI()))); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsRegistrationTests, DeleteRegistration) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/rsp_list_tests.cpp b/apps/gsp/tests/src/rsp_list_tests.cpp new file mode 100644 index 00000000..7df60d2b --- /dev/null +++ b/apps/gsp/tests/src/rsp_list_tests.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsResponseListTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/rsp"; +}; + +TEST_F(HttpsResponseListTests, PostResponse) { + try { + sep::Response rsp; + rsp.href = path; + rsp.end_device_lfdi = SingleClient::getInstance().getLFDI(); + rsp.status = sep::Response::Status::kEventAcknowledged; + rsp.subject = 0x9876; + rsp.created_date_time = psu::utilities::getTime(); + + auto resp = SingleClient::getInstance().Post(path, xml::Serialize(rsp)); + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsResponseListTests, GetResponse) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::Response rsp; + xml::Parse(msg, &rsp); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsResponseListTests, PutResponse) { + try { + sep::Response rsp; + rsp.href = path; + rsp.end_device_lfdi = SingleClient::getInstance().getLFDI(); + rsp.status = sep::Response::Status::kEventAcknowledged; + rsp.subject = 12345; + rsp.created_date_time = psu::utilities::getTime(); + + auto resp = SingleClient::getInstance().Put(path, xml::Serialize(rsp)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsResponseListTests, DeleteResponse) { + try { + auto resp = SingleClient::getInstance().Delete(path); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/apps/gsp/tests/src/rsp_tests.cpp b/apps/gsp/tests/src/rsp_tests.cpp new file mode 100644 index 00000000..c989f239 --- /dev/null +++ b/apps/gsp/tests/src/rsp_tests.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsResponseTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/rsp"; +}; + +TEST_F(HttpsResponseTests, PostResponse) { + try { + sep::Response rsp; + rsp.href = ""; + rsp.end_device_lfdi = SingleClient::getInstance().getLFDI(); + rsp.status = sep::Response::Status::kEventAcknowledged; + rsp.subject = 0x9876; + rsp.created_date_time = psu::utilities::getTime(); + + auto resp = SingleClient::getInstance().Post(path, xml::Serialize(rsp)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsResponseTests, GetResponse) { + try { + auto resp = SingleClient::getInstance().Get(path); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + sep::Response rsp; + xml::Parse(msg, &rsp); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsResponseTests, PutResponse) { + try { + sep::Response rsp; + rsp.href = ""; + rsp.end_device_lfdi = SingleClient::getInstance().getLFDI(); + rsp.status = sep::Response::Status::kEventAcknowledged; + rsp.subject = 12345; + rsp.created_date_time = psu::utilities::getTime(); + + auto resp = SingleClient::getInstance().Put(path, xml::Serialize(rsp)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsResponseTests, DeleteResponse) { + try { + auto resp = SingleClient::getInstance().Delete(path); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/interfaces/https/tests/rsps_list_tests.cpp b/apps/gsp/tests/src/rsps_list_tests.cpp similarity index 100% rename from interfaces/https/tests/rsps_list_tests.cpp rename to apps/gsp/tests/src/rsps_list_tests.cpp diff --git a/interfaces/https/tests/rsps_tests.cpp b/apps/gsp/tests/src/rsps_tests.cpp similarity index 100% rename from interfaces/https/tests/rsps_tests.cpp rename to apps/gsp/tests/src/rsps_tests.cpp diff --git a/apps/gsp/tests/src/sdev_tests.cpp b/apps/gsp/tests/src/sdev_tests.cpp new file mode 100644 index 00000000..431b9208 --- /dev/null +++ b/apps/gsp/tests/src/sdev_tests.cpp @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsSelfDeviceTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; + std::string path = "/sdev"; +}; + +TEST_F(HttpsSelfDeviceTests, GetSelfDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + EXPECT_TRUE(validator->ValidateXml(msg)); + + sep::SelfDevice sdev; + xml::Parse(msg, &sdev); + EXPECT_EQ(sdev.lfdi, SingleClient::getInstance().getLFDI()); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "GET"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsSelfDeviceTests, PostSelfDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + EXPECT_TRUE(validator->ValidateXml(msg)); + + sep::SelfDevice sdev; + xml::Parse(msg, &sdev); + + resp = SingleClient::getInstance().Post(uri, xml::Serialize(sdev)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "POST"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsSelfDeviceTests, PutSelfDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Get(uri); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + EXPECT_TRUE(validator->ValidateXml(msg)); + + sep::SelfDevice sdev; + xml::Parse(msg, &sdev); + + resp = SingleClient::getInstance().Put(uri, xml::Serialize(sdev)); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "PUT"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsSelfDeviceTests, DeleteSelfDevice) { + try { + std::string uri = + path + "/" + xml::util::Hexify(SingleClient::getInstance().getLFDI()); + auto resp = SingleClient::getInstance().Delete(uri); + + std::string wadl_path = g_program_path + "/sep_xml/sep_wadl.xml"; + sep::WADLResource wadl_access = + sep::WADL::getInstance(wadl_path)->getResource(path + "/*"); + + std::string method = "DELETE"; + // EXPECT_TRUE(checkContentType(resp.at("Content-Type").to_string(), + // wadl_access.properties[method].content_type)); + EXPECT_TRUE(checkStatus(resp.base().result_int(), + wadl_access.properties[method].status)); + EXPECT_TRUE( + checkParams(headerFields(resp), wadl_access.properties[method].params)); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} \ No newline at end of file diff --git a/interfaces/https/tests/sub_tests.cpp b/apps/gsp/tests/src/sub_tests.cpp similarity index 100% rename from interfaces/https/tests/sub_tests.cpp rename to apps/gsp/tests/src/sub_tests.cpp diff --git a/apps/gsp/tests/src/tm_tests.cpp b/apps/gsp/tests/src/tm_tests.cpp new file mode 100644 index 00000000..7a942cbe --- /dev/null +++ b/apps/gsp/tests/src/tm_tests.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::string g_program_path; +using namespace https; + +class HttpsTimeTests : public ::testing::Test { +protected: + void SetUp() override { + validator = new XmlValidator(g_program_path + "/sep_xml/sep.xsd"); + } + + void TearDown() override { delete validator; } + +protected: + XmlValidator *validator; +}; + +TEST_F(HttpsTimeTests, GetTime) { + try { + auto resp = SingleClient::getInstance().Get("/tm"); + std::string msg = boost::beast::buffers_to_string(resp.body().data()); + + EXPECT_TRUE(validator->ValidateXml(msg)); + + sep::Time tm; + xml::Parse(msg, &tm); + EXPECT_TRUE(tm.href == "/tm"); + } catch (const std::exception &e) { + ASSERT_ANY_THROW(e.what()); + } +} + +TEST_F(HttpsTimeTests, PostTime) { EXPECT_TRUE(false); } + +TEST_F(HttpsTimeTests, PutTime) { EXPECT_TRUE(false); } + +TEST_F(HttpsTimeTests, DeleteTime) { EXPECT_TRUE(false); } \ No newline at end of file diff --git a/apps/me/CMakeLists.txt b/apps/me/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/apps/me/README.md b/apps/me/README.md new file mode 100644 index 00000000..26382b38 --- /dev/null +++ b/apps/me/README.md @@ -0,0 +1,17 @@ +# Distributed Trust Module Client +Currently there is no need for the setup section as all modules used are base python. + +## Setup + +``` +python3 -m venv .venv +source .venv/bin/activate +pip install --upgrade pip +pip install -r req*.txt +``` + +## Running + +``` +python3 build/bin/dtmc.py +``` \ No newline at end of file diff --git a/apps/me/data/groups.xml b/apps/me/data/groups.xml new file mode 100644 index 00000000..1fb4c94f --- /dev/null +++ b/apps/me/data/groups.xml @@ -0,0 +1,1226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/me/data/services.xml b/apps/me/data/services.xml new file mode 100644 index 00000000..f804b185 --- /dev/null +++ b/apps/me/data/services.xml @@ -0,0 +1,21 @@ + + + + 0 + 3600 + 0 + -360000 + 0 + 1200 + 0 + + + 1 + 3600 + 0 + 360000 + 0 + 100 + 0 + + \ No newline at end of file diff --git a/apps/me/data/time.xml b/apps/me/data/time.xml new file mode 100644 index 00000000..ac847576 --- /dev/null +++ b/apps/me/data/time.xml @@ -0,0 +1,12 @@ + + diff --git a/apps/me/me.py b/apps/me/me.py new file mode 100644 index 00000000..74a91c46 --- /dev/null +++ b/apps/me/me.py @@ -0,0 +1,81 @@ +#!/usr/bin/python3 +# https://flaviocopes.com/python-http-server/ +# https://pythonsansar.com/creating-simple-http-server-python/ +import os +import sys +from http.server import BaseHTTPRequestHandler, HTTPServer +import ssl +from urllib.parse import urlparse +from urllib.parse import parse_qs + +HOST_NAME = "127.0.0.1" +PORT = 9000 +ROOT = os.path.dirname(__file__) +LOG = ROOT + + +class handler(BaseHTTPRequestHandler): + def do_GET(self): + if (self.path == '/groups'): + with open(f'{ROOT}/data/groups.xml', 'r') as file: + message = bytes(file.read(), "utf-8") + self.send_response(200) + self.send_header('Content-type', 'application/xml') + self.send_header('Content-Length', str(len(message))) + self.end_headers() + self.wfile.write(message) + elif (self.path == '/services'): + with open(f'{ROOT}/data/services.xml', 'r') as file: + message = bytes(file.read(), "utf-8") + self.send_response(200) + self.send_header('Content-type', 'application/xml') + self.send_header('Content-Length', str(len(message))) + self.end_headers() + self.wfile.write(message) + elif (self.path == '/time'): + with open(f'{ROOT}/data/time.xml', 'r') as file: + message = bytes(file.read(), "utf-8") + self.send_response(200) + self.send_header('Content-type', 'application/xml') + self.send_header('Content-Length', str(len(message))) + self.end_headers() + self.wfile.write(message) + else: + self.send_response(404) + self.end_headers() + + def do_POST(self): + parsed_url = urlparse(self.path) + parsed_qs = parse_qs(parsed_url.query) + lfdi = parsed_qs['lfdi'][0] + print(self.path, lfdi) + if (not lfdi or parsed_url.path != '/der'): + self.send_response(404) + self.end_headers() + else: + self.send_response(201) + self.end_headers() + + with open(f'{ROOT}/data/{lfdi}.csv', 'w') as file: + content_length = int(self.headers['Content-Length']) + file.write(self.rfile.read(content_length).decode("utf-8")) + + +if __name__ == "__main__": + print(ROOT) + print(f"DTMC started on https://{HOST_NAME}:{PORT}") + + server = HTTPServer((HOST_NAME, PORT), handler) + server.socket = ssl.wrap_socket( + server.socket, + server_side=True, + certfile=ROOT + '/root-ca/server.crt', + keyfile=ROOT + '/root-ca/private/server.key', + ca_certs=ROOT + '/root-ca/cert_chain.crt') + + try: + server.serve_forever() + except KeyboardInterrupt: + server.server_close() + print("Server stopped successfully") + sys.exit(0) diff --git a/apps/me/requirements.txt b/apps/me/requirements.txt new file mode 100644 index 00000000..e69de29b diff --git a/apps/simple/CMakeLists.txt b/apps/simple/CMakeLists.txt new file mode 100644 index 00000000..232503a0 --- /dev/null +++ b/apps/simple/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(simple src/main.cpp) + +# target_include_directories(dcm PUBLIC include) + +target_link_libraries(simple flecs Boost::boost Boost::filesystem + Threads::Threads) diff --git a/apps/simple/src/main.cpp b/apps/simple/src/main.cpp new file mode 100644 index 00000000..b63fc82b --- /dev/null +++ b/apps/simple/src/main.cpp @@ -0,0 +1,187 @@ +#include +#include +#include +#include +#include +#include +#include +#include +// Applications can pass context data to a system. A common use case where this +// comes in handy is when a system needs to iterate more than one query. The +// following example shows how to pass a custom query into a system for a simple +// collision detection example. + +struct Service { + std::string group_id; + std::string name; + std::string type; + uint64_t start_time; + uint64_t interval_start; + uint64_t interval_duration; +}; + +struct Energy : public Service { + float power; + float price; + float ramp; +}; +struct Reserve : public Energy {}; +struct Voltage : public Service { + std::unordered_map curve; +}; +struct Regulation : public Service { + std::unordered_map curve; +}; +struct Blackstart : public Energy {}; + +struct Power { + double real, imag; +}; + +struct Forecast { + double power; +}; + +struct Available {}; + +std::string getProgramPath(char *arg[]) { + boost::filesystem::path p = arg[0]; + p = canonical(p); + return p.parent_path().string(); +}; + +using boost::property_tree::ptree; +void spawnTopology(const ptree &pt, flecs::entity &e) { + ptree::const_iterator end = pt.end(); + for (ptree::const_iterator it = pt.begin(); it != end; ++it) { + std::string name = it->second.get(".name", ""); + if (!name.empty()) { + auto child = e.world().entity(name.c_str()).child_of(e); + std::cout << child.path() << std::endl; + spawnTopology(it->second, child); + } else { + spawnTopology(it->second, e); + } + } +}; + +int decendingPower(flecs::entity_t e1, const Power *p1, flecs::entity_t e2, + const Power *p2) { + (void)e1; + (void)e2; + return (p1->real < p2->real); +} + +int main(int argc, char *argv[]) { + flecs::world ecs; + + std::string base = getProgramPath(argv); + + // Create empty property tree object + ptree tree; + + // Parse the XML into the property tree. + try { + std::string file = base + "/data/groups.xml"; + read_xml(file, tree); + auto root = ecs.entity("root"); + spawnTopology(tree, root); + } catch (const std::exception &e) { + std::cout << e.what() << std::endl; + } + + auto sys2 = + ecs.system("reallocate").each([](flecs::entity e, Power &pwr) { + e.set({pwr.real, pwr.imag}); + auto p = e.parent(); + auto f = + e.world().filter_builder().term(flecs::ChildOf, p).build(); + if (f.count() == 0) { + std::cout << e.name() << " reallocated to " << p.parent().name() + << std::endl; + e.remove(); + e.child_of(p.parent()); + } + }); + + auto sys1 = ecs.system("substation-energy") + .each([](flecs::entity e, Energy &t) { + auto p = e.parent(); + auto f = e.world() + .filter_builder() + .term(flecs::ChildOf, p) + .build(); + std::cout << p.name() << " : " << t.power << std::endl; + double cum_sum{0}; + f.each([&cum_sum, p, t](flecs::entity e2, Power &pwr) { + std::cout << '\t' << e2.name() << ":" << pwr.real + << std::endl; + cum_sum += pwr.real; + if (cum_sum > t.power) { + std::cout << e2.name() << " moving to " + << p.parent().name() << "\n"; + e2.add(); + e2.child_of(p.parent()); + } + }); + }); + + ecs.observer().event(flecs::OnSet).each([](flecs::entity e, Power &p) { + std::cout << "Power value has changed !!!! " << e.name() << std::endl; + }); + + Energy abc; + abc.name = "abc"; + abc.type = "Energy"; + abc.group_id = "global"; + abc.power = 3; + abc.ramp = 3; + abc.price = 0; + abc.start_time = 0; + abc.interval_duration = 0; + auto root = ecs.lookup("root"); + std::cout << root.id() << std::endl; + ecs.entity(abc.name.c_str()).child_of(root).set(abc); + + Energy def; + def.name = "def"; + def.type = "Energy"; + def.group_id = "OL630-632"; + def.power = 2; + def.ramp = 2; + def.price = 0; + def.start_time = 0; + def.interval_duration = 0; + auto feeder = ecs.lookup("::root::group-1::OL630-632"); + std::cout << feeder.id() << std::endl; + ecs.entity(def.name.c_str()).child_of(feeder).set(def); + + Energy ghi; + ghi.name = "ghi"; + ghi.type = "Energy"; + ghi.group_id = "UL632-633"; + ghi.power = 1; + ghi.ramp = 1; + ghi.price = 0; + ghi.start_time = 0; + ghi.interval_duration = 0; + auto segment = ecs.lookup("::root::group-1::OL630-632::UL632-633"); + std::cout << segment.id() << std::endl; + ecs.entity(ghi.name.c_str()).child_of(segment).set(ghi); + + auto sp1 = ecs.lookup( + "::root::group-1::OL630-632::UL632-633::xfmr_633_a_1::tlx_633_a_h_1"); + std::cout << sp1.id() << std::endl; + auto sp2 = ecs.lookup( + "::root::group-1::OL630-632::UL632-633::xfmr_633_a_1::tlx_633_a_h_2"); + std::cout << sp2.id() << std::endl; + auto sp3 = ecs.lookup( + "::root::group-1::OL630-632::UL632-633::xfmr_633_a_1::tlx_633_a_h_3"); + std::cout << sp3.id() << std::endl; + ecs.entity("A").child_of(sp1).set({1, 0}); + ecs.entity("B").child_of(sp2).set({2, 0}); + ecs.entity("C").child_of(sp3).set({3, 0}); + + // Run the system + ecs.app().target_fps(1).run(); +} diff --git a/apps/simple/src/solar.cpp b/apps/simple/src/solar.cpp new file mode 100644 index 00000000..9c94c5c7 --- /dev/null +++ b/apps/simple/src/solar.cpp @@ -0,0 +1,78 @@ +#include +#include +struct Position { + double x, y; +}; + +// Tags for local/world position +struct Local {}; +struct World {}; + +int main(int, char *[]) { + flecs::world ecs; + + // Create a hierarchy. For an explanation see the entities/hierarchy example + flecs::entity sun = + ecs.entity("Sun").add().set({1, 1}); + + ecs.entity("Mercury") + .child_of(sun) + .add() + .set({1, 1}); + + ecs.entity("Venus").child_of(sun).add().set( + {2, 2}); + + flecs::entity earth = ecs.entity("Earth") + .child_of(sun) + .add() + .set({3, 3}); + + ecs.entity("Moon") + .child_of(earth) + .add() + .set({0.1, 0.1}); + + // Create a hierarchical query to compute the global position from the + // local position and the parent position. + flecs::query q = + ecs.query_builder() + // Modify terms from template to make sure the query selects the + // local, world and parent position components. + .term_at(1) + .second() + .term_at(2) + .second() + .term_at(3) + .second() + + // Extend the 2nd query argument to select it from the parent + .term_at(2) + // Get from the parent, in breadth-first order (cascade) + .parent() + .cascade() + // Make term component optional so we also match the root (sun) + .optional() + // Finalize the query + .build(); + + // Do the transform + q.iter([](flecs::iter &it, const Position *p, const Position *p_parent, + Position *p_out) { + for (auto i : it) { + auto parent = it.entity(i).parent(); + std::cout << it.entity(i).path() << " , " << parent.path() << std::endl; + p_out[i].x = p[i].x; + p_out[i].y = p[i].y; + if (p_parent) { + p_out[i].x += p_parent->x; + p_out[i].y += p_parent->y; + } + } + }); + + // Print world positions + ecs.each([](flecs::entity e, flecs::pair p) { + std::cout << e.name() << ": {" << p->x << ", " << p->y << "}\n"; + }); +} diff --git a/group.xml b/configs/group.xml similarity index 100% rename from group.xml rename to configs/group.xml diff --git a/dcm/.gitignore b/dcm/.gitignore deleted file mode 100644 index 77ee40e6..00000000 --- a/dcm/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# Directories -build/ -.vscode/ \ No newline at end of file diff --git a/dcm/CMakeLists.txt b/dcm/CMakeLists.txt deleted file mode 100644 index 46f1dd21..00000000 --- a/dcm/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Find packages go here. -find_package(Boost REQUIRED) -find_package(OpenSSL REQUIRED) - -FetchContent_Declare( - flecs - GIT_REPOSITORY https://github.com/SanderMertens/flecs.git - GIT_TAG v2.3.2 -) - -FetchContent_MakeAvailable(flecs) - -# project dirs -add_subdirectory(src) \ No newline at end of file diff --git a/dcm/LICENSE b/dcm/LICENSE deleted file mode 100644 index 36b7cd93..00000000 --- a/dcm/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/dcm/src/CMakeLists.txt b/dcm/src/CMakeLists.txt deleted file mode 100644 index 18e657a2..00000000 --- a/dcm/src/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(communication) -add_subdirectory(ecs) \ No newline at end of file diff --git a/dcm/src/command_pattern/CMakeLists.txt b/dcm/src/command_pattern/CMakeLists.txt deleted file mode 100644 index 3706936f..00000000 --- a/dcm/src/command_pattern/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(COMPONENT_NAME command_pattern) - -add_library(${COMPONENT_NAME} STATIC - dcm_commands.cpp - ecs_dcm.cpp - s_sim_invoker.cpp - simple_sim_receiver.cpp -) - -# Create ALIAS targets. -add_library( ${PROJECT_NAME}::${COMPONENT_NAME} ALIAS ${COMPONENT_NAME} ) - -target_link_libraries(${COMPONENT_NAME} PUBLIC - https_client - SEP::Model - ecs_client - dtm_msg_writer - cta2045_receiver - SEP::XML - pthread -) - -target_include_directories(${COMPONENT_NAME} PUBLIC - $ - ${ecs_client_INCLUDE_DIRS} - ${https_client_INCLUDE_DIRS} - ${dtm_msg_writer_INCLUDE_DIRS} - ${cta2045_receiver_INCLUDE_DIRS} - ${SEP_INCLUDES_DIRS} -) \ No newline at end of file diff --git a/dcm/src/command_pattern/dcm_commands.cpp b/dcm/src/command_pattern/dcm_commands.cpp deleted file mode 100644 index ada1b514..00000000 --- a/dcm/src/command_pattern/dcm_commands.cpp +++ /dev/null @@ -1,247 +0,0 @@ -#include "include/command_pattern/dcm_commands.hpp" - -using namespace dcm; - -BaseCommand::BaseCommand() : https_client_(nullptr), receiver_(nullptr) -{ - // do nothing -} - -BaseCommand::BaseCommand(CombinedHttpsClient *c, BaseReceiver *r) - : https_client_(c), receiver_(r) -{ - // do nothing -} - -BaseCommand::~BaseCommand() -{ - //delete https_client_; - //delete receiver_; -} - -//================================================================================= - -ImportEnergy::ImportEnergy() -{ - // do nothing -} - -ImportEnergy::ImportEnergy(CombinedHttpsClient *client, BaseReceiver *receiver) - : BaseCommand(client, receiver) -{ - std::cout << "ImportEnergy Command Constructed " << std::endl; -} - -ImportEnergy::~ImportEnergy() -{ - // do nothing -} - -std::string ImportEnergy::Execute() -{ - std::string response_from_der = "der response not supported yet"; - std::cout << " ImportEnergy Command Executing... " << std::endl; - - //this is specific to a simulated receiver at this point, and not based on a particular resource. - https_client_->Post("DTM", xml_writer_.WriteMsg("DCM", "DER", "CTA2045_Message", "ImportEnergyCommand", "ImportEnergy")); - - response_from_der = receiver_->Import(); - - //https_client_->Post("DTM", response_from_der); - - //std::cout << "response from DER was: " << response_from_der << std::endl; - //std::string msg_in = xml_writer_.ReturnCustomCommand("DCM", "DER", response_from_der, "na", "na", "response"); - //https_client_->Post("DTM",msg_in); - - return response_from_der; -} - -//================================================================================= - -ExportEnergy::ExportEnergy() -{ - // do nothing -} - -ExportEnergy::ExportEnergy(CombinedHttpsClient *client, BaseReceiver *receiver) - : BaseCommand(client, receiver) -{ - // do nothing -} - -ExportEnergy::~ExportEnergy() -{ - // do nothing -} - -std::string ExportEnergy::Execute() -{ - std::string response_from_der = "der response not supported yet"; - std::cout << " ExportEnergy Command Executing... " << std::endl; - - //this is specific to a simulated receiver at this point, and not based on a particular resource. - https_client_->Post("DTM", xml_writer_.WriteMsg("DCM", "DER", "CTA2045_Message", "ExportEnergyCommand", "ExportEnergy")); - - response_from_der = receiver_->Export(); - //https_client_->Post("DTM", response_from_der); - - return response_from_der; -} - -//================================================================================= - -GetEnergy::GetEnergy() -{ - // do nothing -} - -GetEnergy::GetEnergy(CombinedHttpsClient *client, BaseReceiver *receiver) - : BaseCommand(client, receiver) -{ - // do nothing -} - -GetEnergy::~GetEnergy() -{ - // do nothing -} - -std::string GetEnergy::Execute() -{ - std::string response_from_der = "der response not supported yet"; - std::cout << " GetEnergy Command Executing... " << std::endl; - - //this is specific to a simulated receiver at this point, and not based on a particular resource. - https_client_->Post("DTM", xml_writer_.WriteMsg("DCM", "DER", "CTA2045_Message", "GetEnergyCommand", "GetEnergy")); - response_from_der = receiver_->GetEnergy(); - if (response_from_der[0] == 'C') //if cta2045receiver - { - std::cout << "GetEnergy::Execute() response from der: " << response_from_der << std::endl; - } - https_client_->Post("DTM", xml_writer_.WriteMsg("DER", "DCM", "CTA2045_Message", "GetEnergyResponse", response_from_der)); - return response_from_der; -} - -//================================================================================= - -GetNameplate::GetNameplate() -{ - // do nothing -} - -GetNameplate::GetNameplate(CombinedHttpsClient *client, BaseReceiver *receiver) - : BaseCommand(client, receiver) -{ - // do nothing -} - -GetNameplate::~GetNameplate() -{ - // do nothing -} - -std::string GetNameplate::Execute() -{ - std::string response_from_der = "der response not supported yet"; - std::cout << " GetNameplate Command Executing... " << std::endl; - - https_client_->Post("DTM", xml_writer_.WriteMsg("DCM", "DER", "CTA2045_Message", "GetNameplateCommand", "GetNameplate")); - response_from_der = receiver_->GetNameplate(); - https_client_->Post("DTM", xml_writer_.WriteMsg("DER", "DCM", "CTA2045_Message", "GetNameplateResponse", response_from_der)); - - return response_from_der; -} - -//================================================================================= - -Idle::Idle() -{ - // do nothing -} - -Idle::Idle(CombinedHttpsClient *client, BaseReceiver *receiver) - : BaseCommand(client, receiver) -{ - // do nothing -} - -Idle::~Idle() -{ - // do nothing -} - -std::string Idle::Execute() -{ - std::string response_from_der = "der response not supported yet"; - std::cout << " Idle Command Executing... " << std::endl; - - //this is specific to a simulated receiver at this point, and not based on a particular resource. - https_client_->Post("DTM", xml_writer_.WriteMsg("DCM", "DER", "CTA2045_Message", "IdleCommand", "Idle")); - - response_from_der = receiver_->Idle(); - //https_client_->Post("DTM", response_from_der); - - return response_from_der; -} - -//================================================================================= - -CriticalPeakEvent::CriticalPeakEvent() -{ - // do nothing -} - -CriticalPeakEvent::CriticalPeakEvent(CombinedHttpsClient *client, BaseReceiver *receiver) - : BaseCommand(client, receiver) -{ - // do nothing -} - -CriticalPeakEvent::~CriticalPeakEvent() -{ - // do nothing -} - -std::string CriticalPeakEvent::Execute() -{ - std::string response_from_der = "der response not supported yet"; - std::cout << " CriticalPeakEvent Command Executing... " << std::endl; - - //this is specific to a simulated receiver at this point, and not based on a particular resource. - https_client_->Post("DTM", xml_writer_.WriteMsg("DCM", "DER", "CTA2045_Message", "CriticalPeakEventCommand", "CriticalPeakEvent")); - response_from_der = receiver_->CriticalPeakEvent(); - //https_client_->Post("DTM", response_from_der); - - return response_from_der; -} - -//================================================================================= - -GridEmergencyEvent::GridEmergencyEvent() -{ - // do nothing - -} - -GridEmergencyEvent::GridEmergencyEvent(CombinedHttpsClient *client, BaseReceiver *receiver) - : BaseCommand(client, receiver) -{ - // do nothing -} - -GridEmergencyEvent::~GridEmergencyEvent() -{ - // do nothing -} -std::string GridEmergencyEvent::Execute() -{ - std::string response_from_der; - std::cout << " GridEmergencyEvent Command Executing... " << std::endl; - - //this is specific to a simulated receiver at this point, and not based on a particular resource. - https_client_->Post("DTM", xml_writer_.WriteMsg("DCM", "DER", "CTA2045_Message", "GridEmergencyEventCommand", "GridEmergencyEvent")); - response_from_der = receiver_->GridEmergencyEvent(); - //https_client_->Post("DTM", response_from_der); - - return response_from_der; -} \ No newline at end of file diff --git a/dcm/src/command_pattern/ecs_dcm.cpp b/dcm/src/command_pattern/ecs_dcm.cpp deleted file mode 100644 index 85226a08..00000000 --- a/dcm/src/command_pattern/ecs_dcm.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#include "include/command_pattern/ecs_dcm.hpp" - -using namespace dcm; - -ECS_DCM::ECS_DCM() : - combined_client_(nullptr), - receiver_(nullptr), - sim_flow_invoker_(nullptr), - import_energy_c_(nullptr), - export_energy_c_(nullptr), - get_energy_c_(nullptr), - get_nameplate_c_(nullptr), - idle_c_(nullptr), - crit_peak_c_(nullptr), - grid_emergency_c_(nullptr) -{ - //SetReceiver(); - //need a program path -} - -ECS_DCM::ECS_DCM(const std::string &root) : - combined_client_(nullptr), - receiver_(nullptr), - sim_flow_invoker_(nullptr), - import_energy_c_(nullptr), - export_energy_c_(nullptr), - get_energy_c_(nullptr), - get_nameplate_c_(nullptr), - idle_c_(nullptr), - crit_peak_c_(nullptr), - grid_emergency_c_(nullptr) -{ - std::cout << " ECS_DCM root arg overload constructor reduced" << std::endl; - - combined_client_ = new CombinedHttpsClient(root, "localhost", "4430", root, "localhost", "4430"); - SetReceiver(); //have to init after https init - import_energy_c_ = new ImportEnergy(combined_client_, receiver_); - export_energy_c_ = new ExportEnergy(combined_client_, receiver_); - get_energy_c_ = new GetEnergy(combined_client_, receiver_); - get_nameplate_c_ = new GetNameplate(combined_client_, receiver_); - idle_c_ = new Idle(combined_client_, receiver_); - sim_flow_invoker_ = new SimpleSimulatorFlowResInvoker(&dcm_world_, import_energy_c_, - export_energy_c_, get_energy_c_, - get_nameplate_c_, idle_c_, crit_peak_c_); - crit_peak_c_ = new CriticalPeakEvent(combined_client_, receiver_); - grid_emergency_c_ = new GridEmergencyEvent(combined_client_, receiver_); - dcm_world_.import(); - std::string startup_msg = xml_writer_.WriteMsg("DCM", "DTM", "CTA2045_Message", "DCM_Startup", "DCM system starting up"); - combined_client_->Post("DTM", startup_msg); -} - -ECS_DCM::~ECS_DCM() -{ - std::string shutdown_msg = xml_writer_.WriteMsg("DCM", "DTM", "CTA2045_Message", "DCM_Shutdown", "DCM system shutting down"); - combined_client_->Post("DTM", shutdown_msg); - std::cout << " ECS_DCM Destructor" << std::endl; - if (combined_client_) - delete combined_client_; - std::cout << "1" << std::endl; - if (sim_flow_invoker_) - { - std::cout << "1.5" << std::endl; - delete sim_flow_invoker_; - } - std::cout << "2" << std::endl; - if (receiver_) - delete receiver_; - std::cout << "3" << std::endl; - if (import_energy_c_) - delete import_energy_c_; - std::cout << "4" << std::endl; - if (export_energy_c_) - delete export_energy_c_; - std::cout << "5" << std::endl; - if (get_energy_c_) - delete get_energy_c_; - std::cout << "6" << std::endl; - if (get_nameplate_c_) - delete get_nameplate_c_; - std::cout << "7" << std::endl; - if (idle_c_) - delete idle_c_; - std::cout << "8" << std::endl; - if (crit_peak_c_) - delete crit_peak_c_; - std::cout << "9" << std::endl; - if (grid_emergency_c_) - delete grid_emergency_c_; - std::cout << "10" << std::endl; -} - -void ECS_DCM::SetReceiver() -{ - std::cout << " ECS_DCM::SetReceiver(), please type 0 for simulator and 1 for CTA2045 " << std::endl; - // imaginary comms tests, or pre-defined binary init - int choice = 0; - std::cin >> choice; - std::cin.ignore(100, '\n'); - if (choice) - { - receiver_ = new CTA2045Receiver(combined_client_); - } - else - receiver_ = new SimpleSimulatorReceiver; //emulated DER -} - -void ECS_DCM::RunSimulatorLoop() -{ - // TODO -} - -void ECS_DCM::TestCTA2045Commands() -{ - - bool shutdown = false; - - while (!shutdown) - { - std::cout << "TESTING CTA-2045 COMMANDS" << std::endl; - std::cout << "c - GetEnergy() " << std::endl; - std::cout << "n - GetNameplate() " << std::endl; - std::cout << "i - ImportEnergy() " << std::endl; - std::cout << "e - ExportEnergy() " << std::endl; - std::cout << "d - Idle() " << std::endl; - std::cout << "p - CriticalPeakEvent() " << std::endl; - std::cout << "q - quit " << std::endl; - std::cout << "==============" << std::endl; - - char c = getchar(); - std::cin.ignore(100, '\n'); - - switch (c) - { - case 'c': - get_energy_c_->Execute(); - break; - case 'n': - get_nameplate_c_->Execute(); - break; - case 'i': - import_energy_c_->Execute(); - break; - case 'e': - export_energy_c_->Execute(); - break; - case 'd': - idle_c_->Execute(); - break; - case 'p': - crit_peak_c_->Execute(); - break; - case 'q': - shutdown = true; - break; - default: - std::cout << "invalid command" << std::endl;; - break; - } - std::cout << "==============" << std::endl; - } - -} - -void ECS_DCM::AddFlowResRespEntity(sep::FlowReservationResponse &flowresresp) -{ - // TODO -} - -sep::FlowReservationResponse ECS_DCM::GetFlowResRespFromGSP() -{ - // TODO -} - -void ECS_DCM::InitializeFlowResInvokingSystems() -{ - // TODO -} \ No newline at end of file diff --git a/dcm/src/command_pattern/include/command_pattern/base_invoker.hpp b/dcm/src/command_pattern/include/command_pattern/base_invoker.hpp deleted file mode 100644 index 129a5ae2..00000000 --- a/dcm/src/command_pattern/include/command_pattern/base_invoker.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __BASE_INVOKER_H__ -#define __BASE_INVOKER_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "dcm_commands.hpp" - -namespace dcm -{ - -class BaseInvoker -{ - public: - BaseInvoker( - flecs::world *shared, - ImportEnergy *imp, - ExportEnergy *exp, - GetEnergy *get_e, - GetNameplate *get_n, - Idle *idle, - CriticalPeakEvent *crit); - ~BaseInvoker(); - virtual void ProcessResource(flecs::entity *e) = 0; - - protected: - flecs::world *shared_world_ptr_; - ImportEnergy *import_; - ExportEnergy *export_; - GetEnergy *get_energy_; - GetNameplate *get_nameplate_; - Idle *idle_; - CriticalPeakEvent *crit_; -}; - -} //namespace dcm -#endif //__S_SIM_INVOKER_H__ \ No newline at end of file diff --git a/dcm/src/command_pattern/include/command_pattern/base_receiver.hpp b/dcm/src/command_pattern/include/command_pattern/base_receiver.hpp deleted file mode 100644 index a008429f..00000000 --- a/dcm/src/command_pattern/include/command_pattern/base_receiver.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __BASE_RECEIVER_H__ -#define __BASE_RECEIVER_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace dcm -{ - // abstract class - class BaseReceiver - { - public: - virtual std::string Import() = 0; - virtual std::string Export() = 0; - virtual std::string GetEnergy() = 0; - virtual std::string GetNameplate() = 0; - virtual std::string Idle() = 0; - virtual std::string CriticalPeakEvent() = 0; - virtual std::string GridEmergencyEvent() = 0; - - private: - }; - -} // namespace dcm - -#endif //__SIMPLE_SIM_RECEIVER_H__ \ No newline at end of file diff --git a/dcm/src/command_pattern/include/command_pattern/dcm_commands.hpp b/dcm/src/command_pattern/include/command_pattern/dcm_commands.hpp deleted file mode 100644 index a1f6517c..00000000 --- a/dcm/src/command_pattern/include/command_pattern/dcm_commands.hpp +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef __DCM_COMMANDS_H__ -#define __DCM_COMMANDS_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "simple_sim_receiver.hpp" -#include - -namespace dcm -{ - -class BaseCommand -{ - public: - BaseCommand(); - BaseCommand(CombinedHttpsClient *c, BaseReceiver *r); - ~BaseCommand(); - virtual std::string Execute() = 0; - - protected: - CombinedHttpsClient *https_client_; - BaseReceiver *receiver_; - xml::XMLCommandAdapter xml_writer_; -}; - -//=============================================================================== - -class ImportEnergy : public BaseCommand -{ - public: - ImportEnergy(); - ImportEnergy(CombinedHttpsClient *client, BaseReceiver *receiver); - ~ImportEnergy(); - std::string Execute(); - - private: -}; - -//=============================================================================== - -class ExportEnergy : public BaseCommand -{ - public: - ExportEnergy(); - ExportEnergy(CombinedHttpsClient *client, BaseReceiver *receiver); - ~ExportEnergy(); - std::string Execute(); - - private: -}; - -//=============================================================================== - -class GetEnergy : public BaseCommand -{ - public: - GetEnergy(); - GetEnergy(CombinedHttpsClient *client, BaseReceiver *receiver); - ~GetEnergy(); - std::string Execute(); - - private: -}; - -//=============================================================================== - -class GetNameplate : public BaseCommand -{ - public: - GetNameplate(); - GetNameplate(CombinedHttpsClient *client, BaseReceiver *receiver); - ~GetNameplate(); - std::string Execute(); - - private: -}; - -//=============================================================================== - -class Idle : public BaseCommand -{ - public: - Idle(); - Idle(CombinedHttpsClient *client, BaseReceiver *receiver); - ~Idle(); - std::string Execute(); - - private: -}; - -//=============================================================================== - -class CriticalPeakEvent : public BaseCommand -{ - public: - CriticalPeakEvent(); - CriticalPeakEvent(CombinedHttpsClient *client, BaseReceiver *receiver); - ~CriticalPeakEvent(); - std::string Execute(); - - private: -}; - -class GridEmergencyEvent : public BaseCommand -{ - public: - GridEmergencyEvent(); - GridEmergencyEvent(CombinedHttpsClient *client, BaseReceiver *receiver); - ~GridEmergencyEvent(); - std::string Execute(); - - private: -}; - -} // namespace dcm - -#endif //__DCM_COMMANDS_H__ \ No newline at end of file diff --git a/dcm/src/command_pattern/include/command_pattern/ecs_dcm.hpp b/dcm/src/command_pattern/include/command_pattern/ecs_dcm.hpp deleted file mode 100644 index 7d80f2b9..00000000 --- a/dcm/src/command_pattern/include/command_pattern/ecs_dcm.hpp +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __ECS_DCM_H__ -#define __ECS_DCM_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../../../cta2045_receiver/include/cta2045_receiver/cta2045_receiver.hpp" -#include "s_sim_invoker.hpp" - -static const std::string FLOW_RESERVATION_REQUEST = R"( - - 0FB7 - description1 - 0 - 1 - 0 - - 1 - -140737488355328 - - - 0 - 1 - - - 1 - 1 - - - 1 - 0 - -)"; - -namespace dcm -{ - -class ECS_DCM -{ -public: - ECS_DCM(); - ECS_DCM(const std::string &root); - ~ECS_DCM(); - void SetReceiver(); - void RunSimulatorLoop(); - void TestCTA2045Commands(); - void AddFlowResRespEntity(sep::FlowReservationResponse &flowresresp); - sep::FlowReservationResponse GetFlowResRespFromGSP(); - void InitializeFlowResInvokingSystems(); - -private: - flecs::world dcm_world_; - xml::XMLCommandAdapter xml_writer_; - CombinedHttpsClient *combined_client_; - BaseInvoker *sim_flow_invoker_; - BaseReceiver *receiver_; - ImportEnergy *import_energy_c_; - ExportEnergy *export_energy_c_; - GetEnergy *get_energy_c_; - GetNameplate *get_nameplate_c_; - Idle *idle_c_; - CriticalPeakEvent *crit_peak_c_; - GridEmergencyEvent *grid_emergency_c_; - - //BaseInvoker * sim_invoker_; -}; - -} //namespace dcm -#endif //__ECS_DCM_H__ \ No newline at end of file diff --git a/dcm/src/command_pattern/include/command_pattern/s_sim_invoker.hpp b/dcm/src/command_pattern/include/command_pattern/s_sim_invoker.hpp deleted file mode 100644 index 88190161..00000000 --- a/dcm/src/command_pattern/include/command_pattern/s_sim_invoker.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __S_SIM_INVOKER_H__ -#define __S_SIM_INVOKER_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "dcm_commands.hpp" -#include "base_invoker.hpp" - -namespace dcm -{ -class SimpleSimulatorFlowResInvoker : public BaseInvoker -{ - public: - SimpleSimulatorFlowResInvoker( - flecs::world *shared, - ImportEnergy *imp, - ExportEnergy *exp, - GetEnergy *get_e, - GetNameplate *get_n, - Idle *idle, - CriticalPeakEvent *crit); - ~SimpleSimulatorFlowResInvoker(); - void ProcessResource(flecs::entity *e); - - private: -}; - -} //namespace dcm -#endif //__S_SIM_INVOKER_H__ \ No newline at end of file diff --git a/dcm/src/command_pattern/include/command_pattern/simple_sim_receiver.hpp b/dcm/src/command_pattern/include/command_pattern/simple_sim_receiver.hpp deleted file mode 100644 index acea7136..00000000 --- a/dcm/src/command_pattern/include/command_pattern/simple_sim_receiver.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __SIMPLE_SIM_RECEIVER_H__ -#define __SIMPLE_SIM_RECEIVER_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "base_receiver.hpp" - -namespace dcm -{/* - // abstract class - class BaseReceiver - { - public: - virtual std::string Import() = 0; - virtual std::string Export() = 0; - virtual std::string GetEnergy() = 0; - virtual std::string GetNameplate() = 0; - virtual std::string Idle() = 0; - virtual std::string CriticalPeakEvent() = 0; - virtual std::string GridEmergencyEvent() = 0; - - private: - }; -*/ - // This is a receiver class for interacting with a simulated DER - class SimpleSimulatorReceiver : public BaseReceiver - { - public: - SimpleSimulatorReceiver(); - ~SimpleSimulatorReceiver(); - std::string Import(); - std::string Export(); - std::string GetEnergy(); - std::string GetNameplate(); - std::string Idle(); - std::string CriticalPeakEvent(); - std::string GridEmergencyEvent(); - void IncrementSimulatorProgress(); - - private: - xml::XMLCommandAdapter xml_writer_; - der::DERSimulator *sim_der_; - }; - -} // namespace dcm - -#endif //__SIMPLE_SIM_RECEIVER_H__ \ No newline at end of file diff --git a/dcm/src/command_pattern/s_sim_invoker.cpp b/dcm/src/command_pattern/s_sim_invoker.cpp deleted file mode 100644 index a3200e6e..00000000 --- a/dcm/src/command_pattern/s_sim_invoker.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "include/command_pattern/s_sim_invoker.hpp" - -using namespace dcm; - -BaseInvoker::BaseInvoker( - flecs::world *shared, - ImportEnergy *imp, - ExportEnergy *exp, - GetEnergy *get_e, - GetNameplate *get_n, - Idle *idle, - CriticalPeakEvent *crit) - : shared_world_ptr_(shared), - import_(imp), - export_(exp), - get_energy_(get_e), - get_nameplate_(get_n), - idle_(idle), - crit_(crit) -{ - shared_world_ptr_->import(); -} - -BaseInvoker::~BaseInvoker() -{ - std::cout << " BaseInvoker destructor a" << std::endl; - /* delete idle_; - std::cout << " b " << std::endl; - delete get_nameplate_; - std::cout << " c " << std::endl; - delete get_energy_; - std::cout << " d " << std::endl; - delete export_; - std::cout << " e " << std::endl; - delete import_; - std::cout << " f " << std::endl; - //delete shared_world_ptr_; - std::cout << " g " << std::endl; */ -} - -SimpleSimulatorFlowResInvoker::SimpleSimulatorFlowResInvoker( - flecs::world *shared, - ImportEnergy *imp, - ExportEnergy *exp, - GetEnergy *get_e, - GetNameplate *get_n, - Idle *idle, - CriticalPeakEvent *crit) - : BaseInvoker(shared, imp, exp, get_e, get_n, idle, crit) -{ - std::cout << "SimpleSimulatorFlowResInvoker" << std::endl; -} - -SimpleSimulatorFlowResInvoker::~SimpleSimulatorFlowResInvoker() -{ - std::cout << "SimpleSimulatorFlowResInvoker Destructor " << std::endl; - // do nothing -} - -void SimpleSimulatorFlowResInvoker::ProcessResource(flecs::entity *e) -{ - std::cout << "SSFRI ProcessResource method called" << std::endl; - if (e->has()) - { - std::cout << "entity has flowreservation response" << std::endl; - sep::FlowReservationResponse *flowres_ptr = e->get_mut(); - sep::CurrentStatus *c_status_ptr = e->get_mut(); - - // Hook to change entity's status components based on contents of flowresresp component - // also, we can actually sent commands, though I don't know the specifics of how that logic should work - // Now we can look at the data in the flowres_ptr and call a command or something - - // demo of commands - if (*c_status_ptr == sep::CurrentStatus::kActive) - { - std::cout << "flowres entity currentStatus is Active " << std::endl; - import_->Execute(); - shared_world_ptr_->set({dcm_components_module::DERPrevCommand::kImportEnergy}); - } - } -} \ No newline at end of file diff --git a/dcm/src/command_pattern/simple_sim_receiver.cpp b/dcm/src/command_pattern/simple_sim_receiver.cpp deleted file mode 100644 index 1491815a..00000000 --- a/dcm/src/command_pattern/simple_sim_receiver.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "include/command_pattern/simple_sim_receiver.hpp" - -using namespace dcm; - -SimpleSimulatorReceiver::SimpleSimulatorReceiver() -{ - std::cout << " SimpleSimulatorReceiver default constructor " << std::endl; - sim_der_ = new der::DERSimulator; -} - -SimpleSimulatorReceiver::~SimpleSimulatorReceiver() -{ - std::cout << "SimpleSimulatorReceiver Destructor " << std::endl; - delete sim_der_; -} - -std::string SimpleSimulatorReceiver::Import() -{ - std::string response = sim_der_->ImportEnergy(); - return xml_writer_.ReturnCustomCommand("DCM", "DER", response, "na", "na", "response"); -} - -std::string SimpleSimulatorReceiver::Export() -{ - std::string response = sim_der_->ExportEnergy(); - return xml_writer_.ReturnCustomCommand("DCM", "DER", response, "na", "na", "response"); -} - -std::string SimpleSimulatorReceiver::GetEnergy() -{ - std::string response = sim_der_->GetEnergy(); - return xml_writer_.ReturnCustomCommand("DCM", "DER", response, "na", "na", "response"); -} - -std::string SimpleSimulatorReceiver::GetNameplate() -{ - std::string response = sim_der_->GetNameplate(); - return xml_writer_.ReturnCustomCommand("DCM", "DER", response, "na", "na", "response"); -} - -std::string SimpleSimulatorReceiver::Idle() -{ - std::string response = sim_der_->Idle(); - return xml_writer_.ReturnCustomCommand("DCM", "DER", response, "na", "na", "response"); -} - -std::string SimpleSimulatorReceiver::CriticalPeakEvent() -{ - std::cout << "SimpleSimReceiver CriticalPeakEvent, not supported currently" << std::endl; -} - -std::string SimpleSimulatorReceiver::GridEmergencyEvent() -{ - std::cout << "SimpleSimReceiver GridEmergencyEvent, not supported currently" << std::endl; -} - -void SimpleSimulatorReceiver::IncrementSimulatorProgress() -{ - sim_der_->IncrementProgress(); -} \ No newline at end of file diff --git a/dcm/src/communication/CMakeLists.txt b/dcm/src/communication/CMakeLists.txt deleted file mode 100644 index e4ae9e20..00000000 --- a/dcm/src/communication/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set(COMPONENT_NAME DCM_Comms) -add_library(${COMPONENT_NAME} STATIC - gsp_client.cpp - dtm_client.cpp - trust_cta2045_client.cpp - trust_gsp_client.cpp -) - -# Create ALIAS targets. -add_library( ${PROJECT_NAME}::${COMPONENT_NAME} ALIAS ${COMPONENT_NAME} ) - -target_link_libraries(${COMPONENT_NAME} PUBLIC - trust_xml - cta2045_ucm - utilities - https_client - pthread -) - -target_include_directories(${COMPONENT_NAME} PUBLIC - $ - $ - ${trust_xml_INCLUDE_DIRS} - ${cta2045_ucm_INCLUDES_DIRS} - ${utilities_INCLUDE_DIRS} - ${https_client_INCLUDE_DIRS} -) \ No newline at end of file diff --git a/dcm/src/communication/dtm_client.cpp b/dcm/src/communication/dtm_client.cpp deleted file mode 100644 index 1982f297..00000000 --- a/dcm/src/communication/dtm_client.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "include/dtm_client.hpp" - -DTMClient::DTMClient(const https::Context& context) - : client_(context) -{ - // do nothing -} - -DTMClient::~DTMClient() -{ - delete instance_; -} - -DTMClient* DTMClient::getInstance(const https::Context& context) -{ - std::lock_guard lock(mutex_); - if(instance_ = nullptr) - { - instance_ = new DTMClient(context); - } - return instance_; -} - -DTMClient* DTMClient::getInstance() -{ - std::lock_guard lock(mutex_); - if(instance_ = nullptr) - { - std::cout << "DTMClient : instance not initilized with context" << std::endl; - abort(); - } - return instance_; -} - -sep::LFDIType DTMClient::getLFDI() -{ - return client_.getLFDI(); -} - -boost::beast::http::response DTMClient::Get(const std::string &target, const std::string &query) -{ - return client_.Get(target,query); -} - -boost::beast::http::response DTMClient::Post(const std::string &target, const std::string &resource) -{ - return client_.Post(target,resource); -} - -boost::beast::http::response DTMClient::Put(const std::string &target, const std::string &resource) -{ - return client_.Put(target,resource); -} - -boost::beast::http::response DTMClient::Delete(const std::string &target) -{ - return client_.Delete(target); -} \ No newline at end of file diff --git a/dcm/src/communication/gsp_client.cpp b/dcm/src/communication/gsp_client.cpp deleted file mode 100644 index 779e00e9..00000000 --- a/dcm/src/communication/gsp_client.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "include/gsp_client.hpp" - -GSPClient::GSPClient(const https::Context& context) - : client_(context) -{ - // do nothing -} - -GSPClient::~GSPClient() -{ - delete instance_; -} - -GSPClient* GSPClient::getInstance(const https::Context& context) -{ - std::lock_guard lock(mutex_); - if(instance_ = nullptr) - { - instance_ = new GSPClient(context); - } - return instance_; -} - -GSPClient* GSPClient::getInstance() -{ - std::lock_guard lock(mutex_); - if(instance_ = nullptr) - { - std::cout << "GSPClient : instance not initilized with context" << std::endl; - abort(); - } - return instance_; -} - -sep::LFDIType GSPClient::getLFDI() -{ - return client_.getLFDI(); -} - -boost::beast::http::response GSPClient::Get(const std::string &target, const std::string &query) -{ - return client_.Get(target,query); -} - -boost::beast::http::response GSPClient::Post(const std::string &target, const std::string &resource) -{ - return client_.Post(target,resource); -} - -boost::beast::http::response GSPClient::Put(const std::string &target, const std::string &resource) -{ - return client_.Put(target,resource); -} - -boost::beast::http::response GSPClient::Delete(const std::string &target) -{ - return client_.Delete(target); -} \ No newline at end of file diff --git a/dcm/src/communication/include/dtm_client.hpp b/dcm/src/communication/include/dtm_client.hpp deleted file mode 100644 index 1ca3723a..00000000 --- a/dcm/src/communication/include/dtm_client.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __DTM_CLIENT_H__ -#define __DTM_CLIENT_H__ - -#include -#include - -class DTMClient : public https::AbstractClient -{ -public: - DTMClient(DTMClient &other) = delete; // clonable - - void operator=(const DTMClient &) = delete; // assignable - - static DTMClient* getInstance(const https::Context& context); - static DTMClient* getInstance(); - - sep::LFDIType getLFDI() override; - - boost::beast::http::response Get( - const std::string &target, const std::string &query = "") override; - - boost::beast::http::response Post( - const std::string &target, const std::string &resource) override; - - boost::beast::http::response Put( - const std::string &target, const std::string &resource) override; - - boost::beast::http::response Delete( - const std::string &target) override; - -protected: - DTMClient(const https::Context& context); - ~DTMClient() noexcept; - -private: - static DTMClient *instance_; - static std::mutex mutex_; - https::Client client_; -}; - - -#endif // __DTM_CLIENT_H__ \ No newline at end of file diff --git a/dcm/src/communication/include/gsp_client.hpp b/dcm/src/communication/include/gsp_client.hpp deleted file mode 100644 index b6df1c32..00000000 --- a/dcm/src/communication/include/gsp_client.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __GSP_CLIENT_H__ -#define __GSP_CLIENT_H__ - -#include -#include - -class GSPClient : public https::AbstractClient -{ -public: - GSPClient(GSPClient &other) = delete; // clonable - - void operator=(const GSPClient &) = delete; // assignable - - static GSPClient* getInstance(const https::Context& context); - static GSPClient* getInstance(); - - sep::LFDIType getLFDI() override; - - boost::beast::http::response Get( - const std::string &target, const std::string &query = "") override; - - boost::beast::http::response Post( - const std::string &target, const std::string &resource) override; - - boost::beast::http::response Put( - const std::string &target, const std::string &resource) override; - - boost::beast::http::response Delete( - const std::string &target) override; - -protected: - GSPClient(const https::Context& context); - ~GSPClient() noexcept; - -private: - static GSPClient *instance_; - static std::mutex mutex_; - https::Client client_; -}; - -#endif // __GSP_CLIENT_H__ \ No newline at end of file diff --git a/dcm/src/communication/include/trust_cta2045_client.hpp b/dcm/src/communication/include/trust_cta2045_client.hpp deleted file mode 100644 index 4367350f..00000000 --- a/dcm/src/communication/include/trust_cta2045_client.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef __TRUST_CTA2045_CLIENT_H__ -#define __TRUST_CTA2045_DER_CLIENT_H__ - -#include -#include -#include -#include - -class TrustUCM : public UCM -{ -public: - TrustUCM(); - virtual ~TrustUCM(); - - virtual bool isMessageTypeSupported(cea2045::MessageTypeCode type_code); - virtual cea2045::MaxPayloadLengthCode getMaxPayload(); - virtual void processMaxPayloadResponse(cea2045::MaxPayloadLengthCode payload); - virtual void processDeviceInfoResponse(cea2045::cea2045DeviceInfoResponse *message); - virtual void processCommodityResponse(cea2045::cea2045CommodityResponse *message); - virtual void processSetEnergyPriceResponse(cea2045::cea2045IntermediateResponse *message); - virtual void processSetTemperatureOffsetResponse(cea2045::cea2045IntermediateResponse *message); - virtual void processGetTemperatureOffsetResponse(cea2045::cea2045GetTemperateOffsetResponse *message); - virtual void processSetSetpointsResponse(cea2045::cea2045IntermediateResponse *message); - virtual void processGetSetpointsResponse(cea2045::cea2045GetSetpointsResponse1 *message); - virtual void processGetSetpointsResponse(cea2045::cea2045GetSetpointsResponse2 *message); - virtual void processStartCyclingResponse(cea2045::cea2045IntermediateResponse *message); - virtual void processTerminateCyclingResponse(cea2045::cea2045IntermediateResponse *message); - virtual void processGetPresentTemperatureResponse(cea2045::cea2045GetPresentTemperatureResponse *message); - virtual void processGetUTCTimeResponse(cea2045::cea2045GetUTCTimeResponse *message); - virtual void processAckReceived(cea2045::MessageCode code); - virtual void processNakReceived(cea2045::LinkLayerNakCode nak, cea2045::MessageCode code); - virtual void processAppAckReceived(cea2045::cea2045Basic *message); - virtual void processAppNakReceived(cea2045::cea2045Basic *message); - virtual void processOperationalStateReceived(cea2045::cea2045Basic *message); - virtual void processAppCustomerOverride(cea2045::cea2045Basic *message); - virtual void processIncompleteMessage(const unsigned char *buffer, unsigned int byte_count); - - cea2045::MaxPayloadLengthCode max_payload_; - cta2045::DeviceInfo device_info_; - cta2045::commodity_map commodities_; - cea2045::cea2045GetTemperateOffsetResponse temperature_offset_; - cea2045::cea2045GetSetpointsResponse1 setpoint_1_; - cea2045::cea2045GetSetpointsResponse2 setpoint_2_; - cea2045::cea2045GetPresentTemperatureResponse present_temperature_; - cea2045::cea2045GetUTCTimeResponse utc_time_; -}; - -class TrustCTADevice : public cta2045::AbstractDevice -{ -public: - TrustCTADevice(const std::string &context); - ~TrustCTADevice() noexcept; - - cta2045::DeviceInfo getDeviceInfo() override; - cta2045::commodity_map getCommodity() override; - cea2045::ResponseCodes loadUp(const uint8_t duration = 0) override; - cea2045::ResponseCodes shed(const uint8_t duration = 0) override; - cea2045::ResponseCodes endShed(const uint8_t duration = 0) override; - cea2045::ResponseCodes criticalPeakEvent(const uint8_t duration = 0) override; - cea2045::ResponseCodes gridEmergency(const uint8_t duration = 0) override; - -private: - cea2045::ResponseCodes response_codes_; - cea2045::CEA2045SerialPort *serial_port_; - TrustUCM *ucm_; - cea2045::ICEA2045DeviceUCM *device_; -}; - -class TrustDERClient : public cta2045::AbstractDevice -{ -public: - TrustDERClient(TrustDERClient &other) = delete; // clonable - void operator=(const TrustDERClient &) = delete; // assignable - static TrustDERClient* getInstance(const std::string& context); - static TrustDERClient* getInstance(); - - cta2045::DeviceInfo getDeviceInfo() override; - cta2045::commodity_map getCommodity() override; - cea2045::ResponseCodes loadUp(const uint8_t duration = 0) override; - cea2045::ResponseCodes shed(const uint8_t duration = 0) override; - cea2045::ResponseCodes endShed(const uint8_t duration = 0) override; - cea2045::ResponseCodes criticalPeakEvent(const uint8_t duration = 0) override; - cea2045::ResponseCodes gridEmergency(const uint8_t duration = 0) override; - -protected: - TrustDERClient(const std::string &context); - ~TrustDERClient(); - -private: - // thread-safe singleton instance - static TrustDERClient *instance_; - static std::mutex mutex_; - TrustCTADevice device_; -}; - -#endif // __TRUST_CTA2045_DER_CLIENT_H__ \ No newline at end of file diff --git a/dcm/src/communication/include/trust_gsp_client.hpp b/dcm/src/communication/include/trust_gsp_client.hpp deleted file mode 100644 index f3d31628..00000000 --- a/dcm/src/communication/include/trust_gsp_client.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __TRUST_GSP_CLIENT_H__ -#define __TRUST_GSP_CLIENT_H__ - -#include "gsp_client.hpp" -#include "dtm_client.hpp" -#include -#include - -class TrustGSPClient : public https::AbstractClient -{ -public: - TrustGSPClient(TrustGSPClient &other) = delete; // clonable - - void operator=(const TrustGSPClient &) = delete; // assignable - - static TrustGSPClient* getInstance(const https::Context& gsp, const https::Context& dtm); - static TrustGSPClient* getInstance(); - - sep::LFDIType getLFDI() override; - - boost::beast::http::response Get( - const std::string &target, const std::string &query = "") override; - - boost::beast::http::response Post( - const std::string &target, const std::string &resource) override; - - boost::beast::http::response Put( - const std::string &target, const std::string &resource) override; - - boost::beast::http::response Delete( - const std::string &target) override; - -protected: - TrustGSPClient(const https::Context& gsp, const https::Context& dtm); - ~TrustGSPClient() noexcept; - -private: - static TrustGSPClient *instance_; - static std::mutex mutex_; -}; - -#endif // __TRUST_GSP_CLIENT_H__ \ No newline at end of file diff --git a/dcm/src/communication/trust_cta2045_client.cpp b/dcm/src/communication/trust_cta2045_client.cpp deleted file mode 100644 index 20ec1841..00000000 --- a/dcm/src/communication/trust_cta2045_client.cpp +++ /dev/null @@ -1,400 +0,0 @@ -#include "include/trust_cta2045_client.hpp" -#include "include/dtm_client.hpp" -#include -#include -#include - -using namespace cea2045; - -UCM::UCM() -{ - max_payload_ = cea2045::MaxPayloadLengthCode::LENGTH2; -} - -UCM::~UCM() -{ - // do nothing -} - -bool UCM::isMessageTypeSupported(MessageTypeCode type_code) -{ - if (type_code == MessageTypeCode::NONE) - { - return false; - } - - return true; -} - -MaxPayloadLengthCode UCM::getMaxPayload() -{ - return max_payload_; -} - -void UCM::processMaxPayloadResponse(MaxPayloadLengthCode payload) -{ - dtm::Message msg; - msg.from = "DER"; - msg.to = "DCM"; - msg.command = "processMaxPayloadResponse"; - msg.args["MaxPayloadLengthCode"] = std::to_string((int)payload); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - max_payload_ = payload; -} - -void UCM::processDeviceInfoResponse(cea2045DeviceInfoResponse *message) -{ - //device_info_ = *message; - device_info_.device_type = message->getDeviceType(); - device_info_.capability_map = (uint64_t)message->capability; - device_info_.vendor_id = message->getVendorID(); - device_info_.firmware_day = (uint32_t)message->firmwareDay; - device_info_.firmware_month = (uint32_t)message->firmwareMonth; - device_info_.firmware_year = 2000 + (uint32_t)message->firmwareYear20xx; - device_info_.firmware_minor = (uint32_t)message->firmwareMinor; - device_info_.firmware_major = (uint32_t)message->firmwareMajor; - - dtm::Message msg; - msg.from = "DER"; - msg.to = "DCM"; - msg.command = "processDeviceInfoResponse"; - msg.args["device type"] = std::to_string(device_info_.device_type); - msg.args["capability"] = std::to_string(device_info_.capability_map); - msg.args["vendor id"] = std::to_string(device_info_.vendor_id); - msg.args["firmware day"] = std::to_string(device_info_.firmware_day); - msg.args["firmware month"] = std::to_string(device_info_.firmware_month); - msg.args["firmware year"] = std::to_string(device_info_.firmware_year); - msg.args["firmware minor"] = std::to_string(device_info_.firmware_minor); - msg.args["firmware major"] = std::to_string(device_info_.firmware_major); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); -} - -void UCM::processCommodityResponse(cea2045CommodityResponse *message) -{ - dtm::Message msg; - msg.from = "DER"; - msg.to = "DCM"; - msg.command = "processCommodityResponse"; - msg.timestamp = psu::utilities::getTime(); - - size_t count = message->getCommodityDataCount(); - for (size_t i = 0; i < count; i++) - { - cea2045CommodityData data = *message->getCommodityData(i); - std::string code = std::to_string((uint8_t)data.commodityCode); - commodities_[(uint8_t)data.commodityCode] = data; - msg.args[code + " : code"] = code; - msg.args[code + " : cumulative amount"] = std::to_string(data.getCumulativeAmount()); - msg.args[code + " : instantaneous rate"] = std::to_string(data.getInstantaneousRate()); - } - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); -} - -void UCM::processSetEnergyPriceResponse(cea2045IntermediateResponse *message) -{ - // TODO -} - -void UCM::processSetTemperatureOffsetResponse(cea2045IntermediateResponse *message) -{ - // TODO -} - -void UCM::processGetTemperatureOffsetResponse(cea2045GetTemperateOffsetResponse *message) -{ - // TODO -} - -void UCM::processSetSetpointsResponse(cea2045IntermediateResponse *message) -{ - // TODO -} - -void UCM::processGetSetpointsResponse(cea2045GetSetpointsResponse1 *message) -{ - // TODO -} - -void UCM::processGetSetpointsResponse(cea2045GetSetpointsResponse2 *message) -{ - // TODO -} - -void UCM::processStartCyclingResponse(cea2045IntermediateResponse *message) -{ - // TODO -} - -void UCM::processTerminateCyclingResponse(cea2045IntermediateResponse *message) -{ - // TODO -} - -void UCM::processGetPresentTemperatureResponse(cea2045GetPresentTemperatureResponse *message) -{ - // TODO -} - -void UCM::processGetUTCTimeResponse(cea2045GetUTCTimeResponse *message) -{ - // TODO -} - -void UCM::processAckReceived(MessageCode code) -{ - // TODO -} - -void UCM::processNakReceived(LinkLayerNakCode nak, MessageCode code) -{ - // TODO -} - -void UCM::processAppAckReceived(cea2045Basic *message) -{ - // TODO -} - -void UCM::processAppNakReceived(cea2045Basic *message) -{ - // TODO -} - -void UCM::processOperationalStateReceived(cea2045Basic *message) -{ - // TODO -} - -void UCM::processAppCustomerOverride(cea2045Basic *message) -{ - // TODO -} - -void UCM::processIncompleteMessage(const unsigned char *buffer, unsigned int byte_count) -{ - dtm::Message msg; - msg.from = "DER"; - msg.to = "DCM"; - msg.command = "processIncompleteMessage"; - msg.args["buffer"] = std::to_string(*buffer); - msg.args["byte_count"] = std::to_string(byte_count); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - std::cout << "CTA2045 UCM : incomplete message received. Byte count = " << byte_count << "\n"; -} - -TrustCTADevice::TrustCTADevice(const std::string &context) -{ - serial_port_ = new CEA2045SerialPort(context); - if (!serial_port_->open()) - { - std::cout << "CTA2045 UCM: failed to open serial port\n"; - abort(); - } - - ucm_ = new TrustUCM(); - device_ = DeviceFactory::createUCM(serial_port_, ucm_); - - device_->start(); - - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "querySuportDataLinkMessages"; - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->querySuportDataLinkMessages().get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support data link messages with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "querySuportIntermediateMessages"; - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->querySuportIntermediateMessages().get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support intermediate messages with code = " - << static_cast(response_codes_.responesCode); - abort(); - } -} - -TrustCTADevice::~TrustCTADevice() -{ - device_->shutDown(); - delete device_; - delete ucm_; - delete serial_port_; -} - -cta2045::DeviceInfo TrustCTADevice::getDeviceInfo() -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "intermediateGetDeviceInformation"; - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->intermediateGetDeviceInformation().get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support device info messages with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - return ucm_->device_info_; -} - -cta2045::commodity_map TrustCTADevice::getCommodity() -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "intermediateGetCommodity"; - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->intermediateGetCommodity().get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support get commodity with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - return ucm_->commodities_; -} - -cea2045::ResponseCodes TrustCTADevice::loadUp(const uint8_t duration) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "basicLoadUp"; - msg.args["duration"] = std::to_string(duration); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->basicLoadUp(duration).get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support loadUp with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - return response_codes_; -} - -cea2045::ResponseCodes TrustCTADevice::shed(const uint8_t duration) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "basicLoadUp"; - msg.args["duration"] = std::to_string(duration); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->basicShed(duration).get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support shed with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - return response_codes_; -} - -cea2045::ResponseCodes TrustCTADevice::endShed(const uint8_t duration) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "basicEndShed"; - msg.args["duration"] = std::to_string(duration); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->basicEndShed(duration).get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support endShed with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - return response_codes_; -} - -cea2045::ResponseCodes TrustCTADevice::criticalPeakEvent(const uint8_t duration) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "basicCriticalPeakEvent"; - msg.args["duration"] = std::to_string(duration); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->basicCriticalPeakEvent(duration).get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support criticalPeakEvent with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - return response_codes_; -} - -cea2045::ResponseCodes TrustCTADevice::gridEmergency(const uint8_t duration) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "DER"; - msg.command = "basicGridEmergency"; - msg.args["duration"] = std::to_string(duration); - msg.timestamp = psu::utilities::getTime(); - - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - response_codes_ = device_->basicGridEmergency(duration).get(); - if (response_codes_.responesCode != ResponseCode::OK) - { - std::cout - << "CTA2045 TrustCTADevice: does not support gridEmergency with code = " - << static_cast(response_codes_.responesCode); - abort(); - } - return response_codes_; -} \ No newline at end of file diff --git a/dcm/src/communication/trust_gsp_client.cpp b/dcm/src/communication/trust_gsp_client.cpp deleted file mode 100644 index 5863106a..00000000 --- a/dcm/src/communication/trust_gsp_client.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "include/trust_gsp_client.hpp" -#include -#include - -TrustGSPClient::TrustGSPClient(const https::Context& gsp, const https::Context& dtm) -{ - // init both singleton clients with context. - GSPClient::getInstance(gsp); - DTMClient::getInstance(dtm); -} - -TrustGSPClient::~TrustGSPClient() -{ - delete instance_; -} - -TrustGSPClient* TrustGSPClient::getInstance(const https::Context& gsp, const https::Context& dtm) -{ - std::lock_guard lock(mutex_); - if(instance_ = nullptr) - { - instance_ = new TrustGSPClient(gsp, dtm); - } - return instance_; -} - -TrustGSPClient* TrustGSPClient::getInstance() -{ - std::lock_guard lock(mutex_); - if(instance_ = nullptr) - { - std::cout << "TrustGSPClient : instance not initilized with context" << std::endl; - abort(); - } - return instance_; -} - -sep::LFDIType TrustGSPClient::getLFDI() -{ - return DTMClient::getInstance()->getLFDI(); -} - -boost::beast::http::response TrustGSPClient::Get(const std::string &target, const std::string &query) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "GSP"; - msg.command = "GET"; - msg.args["target"] = target; - msg.args["query"] = query; - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - auto response = GSPClient::getInstance()->Get(target,query); - - msg.from = "GSP"; - msg.to = "DCM"; - msg.command = "GETResponse"; - msg.args["result"] = std::to_string(response.result_int()); - msg.args["body"] = boost::beast::buffers_to_string(response.body().data()); - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - return response; -} - -boost::beast::http::response TrustGSPClient::Post(const std::string &target, const std::string &resource) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "GSP"; - msg.command = "POST"; - msg.args["target"] = target; - msg.args["body"] = resource; - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - auto response = GSPClient::getInstance()->Post(target,resource); - - msg.from = "GSP"; - msg.to = "DCM"; - msg.command = "POSTResponse"; - msg.args["result"] = std::to_string(response.result_int()); - msg.args["body"] = boost::beast::buffers_to_string(response.body().data()); - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - return response; -} - -boost::beast::http::response TrustGSPClient::Put(const std::string &target, const std::string &resource) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "GSP"; - msg.command = "PUT"; - msg.args["target"] = target; - msg.args["body"] = resource; - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - auto response = GSPClient::getInstance()->Put(target,resource); - - msg.from = "GSP"; - msg.to = "DCM"; - msg.command = "PUTResponse"; - msg.args["result"] = std::to_string(response.result_int()); - msg.args["body"] = boost::beast::buffers_to_string(response.body().data()); - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - return response; -} - -boost::beast::http::response TrustGSPClient::Delete(const std::string &target) -{ - dtm::Message msg; - msg.from = "DCM"; - msg.to = "GSP"; - msg.command = "DELETE"; - msg.args["target"] = target; - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - auto response = GSPClient::getInstance()->Delete(target); - - msg.from = "GSP"; - msg.to = "DCM"; - msg.command = "DELETEResponse"; - msg.args["result"] = std::to_string(response.result_int()); - msg.args["body"] = boost::beast::buffers_to_string(response.body().data()); - msg.timestamp = psu::utilities::getTime(); - DTMClient::getInstance()->Post("/na", dtm::Stringify(msg)); - - return response; -} \ No newline at end of file diff --git a/dcm/src/ecs/CMakeLists.txt b/dcm/src/ecs/CMakeLists.txt deleted file mode 100644 index 695fdb97..00000000 --- a/dcm/src/ecs/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(COMPONENT_NAME DCM_ECS) - -add_library(${COMPONENT_NAME} STATIC - cta2045_module.cpp - sep_common_module.cpp - sep_smart_energy_module.cpp - sep_support_module.cpp -) - -# Create ALIAS targets. -add_library( ${PROJECT_NAME}::${COMPONENT_NAME} ALIAS ${COMPONENT_NAME} ) - -target_link_libraries(${COMPONENT_NAME} PUBLIC - flecs - SEP_Models - XML_Validator - Boost::boost - DCM_Comms - pthread -) - -target_include_directories(${COMPONENT_NAME} PUBLIC - $ - $ - ${flecs_INCLUDE_DIRS} - ${SEP_Models_INCLUDE_DIRS} - ${XML_Validator_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} - ${DCM_Comms_INCLUDE_DIRS} -) \ No newline at end of file diff --git a/dcm/src/ecs/cta2045_module.cpp b/dcm/src/ecs/cta2045_module.cpp deleted file mode 100644 index 10b8445b..00000000 --- a/dcm/src/ecs/cta2045_module.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "include/cta2045_module.hpp" -#include "include/sep_support_module.hpp" -#include -#include -#include -#include - -namespace cta2045 -{ - UniversalModule::UniversalModule (flecs::world &ecs) - { - /* Register module with world */ - ecs.module(); - ecs.module(); - - /* Register components */ - ecs.component(); - - /* Register system */ - ecs.system("EnergyTake") - .each([&](flecs::entity e, const cea2045::cea2045CommodityData &data) { - if((uint64_t)data.instantaneousRate >= 1200) - { - sep::FlowReservationRequest frr; - auto resp = TrustGSPClient::getInstance()->Post("/frr", xml::Serialize(frr)); - std::string msg = boost::beast::buffers_to_string(resp.body().data()); - ecs.entity().add(); - - } - }); - } -} // namespace cta2045 diff --git a/dcm/src/ecs/der.cpp b/dcm/src/ecs/der.cpp deleted file mode 100644 index 020fdc6b..00000000 --- a/dcm/src/ecs/der.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "include/der.hpp" -#include -#include - -namespace DER -{ - Module::Module(flecs::world& ecs) - { - ecs.module(); - - ecs.component(); - ecs.component(); - ecs.component(); - ecs.component(); - ecs.component(); - ecs.component(); - - ecs.observer("OnSetRealPower") - .event(flecs::OnSet) - .each([](RealPower& pwr, MaxRealPower& limit){ - if (pwr.value > limit.value){ - pwr.value = limit.value; - std::cout << "Too big: " << pwr.value << std::endl; - } - - if (pwr.value + limit.value < 0){ - pwr.value = 0 - static_cast(limit.value); - std::cout << "Too small: " << pwr.value << std::endl; - } - }); - - ecs.observer("OnSetReactivePower") - .event(flecs::OnSet) - .each([](ReactivePower& pwr, MaxReactivePower& limit){ - if (pwr.value > limit.value){ - pwr.value = limit.value; - std::cout << "Too big: " << pwr.value << std::endl; - } - - if (pwr.value + limit.value < 0){ - pwr.value = 0 - static_cast(limit.value); - std::cout << "Too small: " << pwr.value << std::endl; - } - }); - - ecs.observer("OnSetEnergy") - .event(flecs::OnSet) - .each([](Energy& energy, MaxEnergy& limit){ - if (energy.value > limit.value){ - energy.value = limit.value; - std::cout << "Too big: " << energy.value << std::endl; - } - - if (energy.value + limit.value < 0){ - energy.value = 0 - static_cast(limit.value); - std::cout << "Too small: " << energy.value << std::endl; - } - }); - - } - - -} // namespace DER diff --git a/dcm/src/ecs/include/cta2045_module.hpp b/dcm/src/ecs/include/cta2045_module.hpp deleted file mode 100644 index 0e38dea0..00000000 --- a/dcm/src/ecs/include/cta2045_module.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __DCM_CTA2045_MODULE_H__ -#define __DCM_CTA2045_MODULE_H__ - -#include - - -namespace cta2045 -{ - struct UniversalModule - { - UniversalModule(flecs::world& ecs); - }; -} // namespace sep - -#endif // __DCM_CTA2045_MODULE_H__ \ No newline at end of file diff --git a/dcm/src/ecs/include/der.hpp b/dcm/src/ecs/include/der.hpp deleted file mode 100644 index 39e3d1aa..00000000 --- a/dcm/src/ecs/include/der.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __DER_H__ -#define __DER_H__ - -#include -#include - -namespace DER -{ - struct RealPower - { - float value; - }; - - struct ReactivePower - { - float value; - }; - - // assume +/- boundary for max power - struct MaxRealPower - { - uint32_t value; - }; - - // assume +/- boundary for max power - struct MaxReactivePower - { - uint32_t value; - }; - - struct Energy - { - float value; - }; - - struct MaxEnergy - { - uint32_t value; - }; - - struct Module - { - - Module(flecs::world& ecs); - }; - -} // namespace DER - -#endif // __DER_H__ \ No newline at end of file diff --git a/dcm/src/ecs/include/sep_common_module.hpp b/dcm/src/ecs/include/sep_common_module.hpp deleted file mode 100644 index 5563ec17..00000000 --- a/dcm/src/ecs/include/sep_common_module.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __DCM_SEP_COMMON_MODULE_H__ -#define __DCM_SEP_COMMON_MODULE_H__ - -#include - - -namespace sep -{ - struct CommonModule - { - CommonModule(flecs::world& ecs); - }; -} // namespace sep - - - -#endif // __DCM_SEP_COMMON_MODULE_H__ \ No newline at end of file diff --git a/dcm/src/ecs/include/sep_smart_energy_module.hpp b/dcm/src/ecs/include/sep_smart_energy_module.hpp deleted file mode 100644 index 5692d140..00000000 --- a/dcm/src/ecs/include/sep_smart_energy_module.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __DCM_SEP_SMART_ENERGY_MODULE_H__ -#define __DCM_SEP_SMART_ENERGY_MODULE_H__ - -#include - -namespace sep -{ - struct SmartEnergyModule - { - SmartEnergyModule(flecs::world &ecs); - }; -} // namespace sep - -#endif // __DCM_SEP_SMART_ENERGY_MODULE_H__ \ No newline at end of file diff --git a/dcm/src/ecs/include/sep_support_module.hpp b/dcm/src/ecs/include/sep_support_module.hpp deleted file mode 100644 index e6231449..00000000 --- a/dcm/src/ecs/include/sep_support_module.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __DCM_SEP_SUPPORT_MODULE_H__ -#define __DCM_SEP_SUPPORT_MODULE_H__ - -#include - -namespace sep -{ - struct SupportModule - { - public: - SupportModule(flecs::world &ecs); - }; -} // namespace sep - -#endif // __DCM_SEP_SUPPORT_MODULE_H__ \ No newline at end of file diff --git a/dcm/src/ecs/include/simulation_module.hpp b/dcm/src/ecs/include/simulation_module.hpp deleted file mode 100644 index d8942278..00000000 --- a/dcm/src/ecs/include/simulation_module.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __SIMULATION_MODULE_H__ -#define __SIMULATION_MODULE_H__ - - -#include - -namespace Simulation -{ - struct Power - { - float magnitude; - float angle; - }; - - struct MaxPower - { - int32_t magnitude; - - }; - - struct Energy - { - float value; - }; - - struct MaxEnergy - { - uint32_t value; - }; - - - struct Module - { - - Module(flecs::world& ecs); - }; - -} // namespace Simulation - - - - - -#endif // __SIMULATION_MODULE_H__ \ No newline at end of file diff --git a/dcm/src/ecs/include/waterheater.hpp b/dcm/src/ecs/include/waterheater.hpp deleted file mode 100644 index aa765482..00000000 --- a/dcm/src/ecs/include/waterheater.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __WATERHEATER_H__ -#define __WATERHEATER_H__ - -#include - -namespace WaterHeater -{ - enum State - { - Idle, - Shed, - LoadUp - }; - - struct Module - { - Module(flecs::world& ecs); - }; -} // namespace Simulator - -#endif // __WATERHEATER_H__ \ No newline at end of file diff --git a/dcm/src/ecs/sep_common_module.cpp b/dcm/src/ecs/sep_common_module.cpp deleted file mode 100644 index 2df3545b..00000000 --- a/dcm/src/ecs/sep_common_module.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "include/sep_common_module.hpp" -#include - -namespace sep -{ - CommonModule::CommonModule(flecs::world &ecs) - { - /* Register module with world */ - ecs.module(); - - /* Register components */ - ecs.component