diff --git a/.gitignore b/.gitignore index a89d918..7c05a50 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /build* /cmake-build* +/.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d7116..cde9423 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,16 @@ project(foo VERSION 0.1.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if(BUILD_FINISHED) + add_subdirectory(finished) +endif() add_subdirectory(start) -set(FSFW_OSAL host) -set(FSFW_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/start) +set(FSFW_OSAL host CACHE STRING "FSFW OSAL") +set(FSFW_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(fsfw) target_link_libraries(fsfw-from-zero PRIVATE fsfw) +if(BUILD_FINISHED) + target_link_libraries(fsfw-from-zero-done PRIVATE fsfw) +endif() diff --git a/start/FSFWConfig.h b/FSFWConfig.h similarity index 100% rename from start/FSFWConfig.h rename to FSFWConfig.h diff --git a/finished/CMakeLists.txt b/finished/CMakeLists.txt new file mode 100644 index 0000000..0c89f3c --- /dev/null +++ b/finished/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(fsfw-from-zero-done) +target_sources(fsfw-from-zero-done PRIVATE main.cpp) +target_include_directories(fsfw-from-zero-done PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/finished/main.cpp b/finished/main.cpp new file mode 100644 index 0000000..d45774d --- /dev/null +++ b/finished/main.cpp @@ -0,0 +1,72 @@ +#include + +#include "fsfw/serviceinterface.h" +#include "FSFWConfig.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tasks/TaskFactory.h" +#include +#include +#include + +using namespace std; +using namespace returnvalue; + +#if FSFW_CPP_OSTREAM_ENABLED == 1 +ServiceInterfaceStream sif::debug("DEBUG", false); +ServiceInterfaceStream sif::info("INFO", false); +ServiceInterfaceStream sif::warning("WARNING", false); +ServiceInterfaceStream sif::error("ERROR", false, true, true); +#endif + +class MyExecutable: public SystemObject, public ExecutableObjectIF { + public: + MyExecutable(object_id_t objectId): SystemObject(objectId) {} + + static int myTaskEntryPoint(MyExecutable& self) { + using namespace std::chrono_literals; + while (true) { + self.performOperation(0); + this_thread::sleep_for(1000ms); + } + } + /** + * @brief The performOperation method is executed in a task. + * @details There are no restrictions for calls within this method, so any + * other member of the class can be used. + * @return Currently, the return value is ignored. + */ + ReturnValue_t performOperation(uint8_t operationCode) override { + cout << "hello world from MyExecutable" << endl; + return OK; + } + + ReturnValue_t initialize() override { + cout << "MyExecutable custom init" << endl; + return OK; + } + + private: +}; + +static const object_id_t MY_OBJ = 1; + +void objFactory(void* args); +int main() { + using namespace std::chrono_literals; + cout << "hello world!" << endl; + auto *objMan = ObjectManager::instance(); + objMan->setObjectFactoryFunction(&objFactory, nullptr); + objMan->initialize(); + + PeriodicTaskIF* task = TaskFactory::instance()->createPeriodicTask("MY_EXECUTABLE", 80, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr); + task->addComponent(MY_OBJ); + task->startTask(); + while (true) { + this_thread::sleep_for(5000ms); + } +} + +void objFactory(void* args) { + new MyExecutable(MY_OBJ); +} diff --git a/start/main.cpp b/start/main.cpp index 0dd5eed..2223ce2 100644 --- a/start/main.cpp +++ b/start/main.cpp @@ -13,7 +13,7 @@ ServiceInterfaceStream sif::warning("WARNING", false); ServiceInterfaceStream sif::error("ERROR", false, true, true); #endif - int main() { cout << "hello world!" << endl; + } \ No newline at end of file