starting impl

This commit is contained in:
Robin Müller 2022-09-02 09:58:43 +02:00
parent 36fd859867
commit 4b80b8bd64
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
6 changed files with 85 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/build*
/cmake-build*
/.vscode

View File

@ -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()

3
finished/CMakeLists.txt Normal file
View File

@ -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})

72
finished/main.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <iostream>
#include "fsfw/serviceinterface.h"
#include "FSFWConfig.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tasks/TaskFactory.h"
#include <thread>
#include <chrono>
#include <functional>
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);
}

View File

@ -13,7 +13,7 @@ ServiceInterfaceStream sif::warning("WARNING", false);
ServiceInterfaceStream sif::error("ERROR", false, true, true);
#endif
int main() {
cout << "hello world!" << endl;
}