back to basic for the main

This commit is contained in:
Robin Müller 2022-09-28 19:45:54 +02:00
parent 0513123532
commit 91c81ba3ab
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814

View File

@ -1,85 +1,7 @@
#include <iostream> #include <iostream>
#include <thread>
#include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tasks/PeriodicTaskIF.h"
#include "fsfw/tasks/TaskFactory.h"
using namespace std; using namespace std;
class MyExecutableObjectIF {
public:
virtual ~MyExecutableObjectIF() = default;
virtual void performOperation() = 0;
};
class MyExecutableObject0: public ExecutableObjectIF {
public:
MyExecutableObject0() = default;
ReturnValue_t performOperation(uint8_t opCode) override {
cout << "Task 0" << endl;
return returnvalue::OK;
}
private:
};
class MyExecutableObject1: public ExecutableObjectIF {
public:
MyExecutableObject1() = default;
ReturnValue_t performOperation(uint8_t opCode) override {
cout << "Task 1" << endl;
return returnvalue::OK;
}
private:
};
class MyExecutableObject2: public ExecutableObjectIF {
public:
MyExecutableObject2() = default;
ReturnValue_t performOperation(uint8_t opCode) override {
cout << "Task 2" << endl;
return returnvalue::OK;
}
private:
};
class MyPeriodicTask {
public:
MyPeriodicTask(MyExecutableObjectIF& executable, uint32_t taskFreqMs)
: executable(executable), taskFreqMs(taskFreqMs) {}
std::thread start() {
return std::thread(
MyPeriodicTask::executeTask,
std::reference_wrapper(*this));
}
private:
static void executeTask(MyPeriodicTask& self) {
while(true) {
self.executable.performOperation();
this_thread::sleep_for(std::chrono::milliseconds(self.taskFreqMs));
}
}
MyExecutableObjectIF& executable;
uint32_t taskFreqMs;
};
int main() { int main() {
MyExecutableObject0 myExecutableObject0; cout << "Hello World" << endl;
MyExecutableObject1 myExecutableObject1;
MyExecutableObject2 myExecutableObject2;
auto* factory = TaskFactory::instance();
auto* periodicTask0 = factory->createPeriodicTask("TASK_0", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.5, nullptr);
auto* periodicTask1 = factory->createPeriodicTask("TASK_1", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
periodicTask0->addComponent(&myExecutableObject0);
periodicTask0->addComponent(&myExecutableObject1);
periodicTask1->addComponent(&myExecutableObject2);
periodicTask0->startTask();
periodicTask1->startTask();
while(true) {
this_thread::sleep_for(5000ms);
}
} }