some smaller tweaks
This commit is contained in:
parent
22b94bfa46
commit
179bbc6ac7
97
main.cpp
97
main.cpp
@ -1,42 +1,93 @@
|
|||||||
#include "fsfw/objectmanager.h"
|
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
|
||||||
#include <thread>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <thread>
|
||||||
|
|
||||||
|
#include "fsfw/platform.h"
|
||||||
|
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||||
|
#include "fsfw/tasks/PeriodicTaskIF.h"
|
||||||
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WIN
|
||||||
|
#include "fsfw/osal/windows/winTaskHelpers.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
enum ObjectIds {
|
class MyExecutableObjectIF {
|
||||||
TEST_OBJECT = 0x10101010
|
public:
|
||||||
|
virtual ~MyExecutableObjectIF() = default;
|
||||||
|
virtual void performOperation() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyObject: public ExecutableObjectIF, public SystemObject {
|
class MyExecutableObject0: public ExecutableObjectIF {
|
||||||
public:
|
public:
|
||||||
MyObject(object_id_t objectId): SystemObject(objectId) {}
|
MyExecutableObject0() = default;
|
||||||
|
|
||||||
ReturnValue_t performOperation(uint8_t opCode) override {
|
ReturnValue_t performOperation(uint8_t opCode) override {
|
||||||
cout << "MyObject::performOperation: Periodic handling" << endl;
|
cout << "Task 0" << endl;
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
ReturnValue_t initialize() override {
|
private:
|
||||||
cout << "MyObject::initialize: Custom init" << endl;
|
};
|
||||||
|
|
||||||
|
class MyExecutableObject1: public ExecutableObjectIF {
|
||||||
|
public:
|
||||||
|
MyExecutableObject1() = default;
|
||||||
|
|
||||||
|
ReturnValue_t performOperation(uint8_t opCode) override {
|
||||||
|
cout << "Task 1" << endl;
|
||||||
return returnvalue::OK;
|
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() {
|
||||||
new MyObject(ObjectIds::TEST_OBJECT);
|
MyExecutableObject0 myExecutableObject0;
|
||||||
auto* objManager = ObjectManager::instance();
|
MyExecutableObject1 myExecutableObject1;
|
||||||
objManager->initialize();
|
MyExecutableObject2 myExecutableObject2;
|
||||||
auto* mySysObj = objManager->get<MyObject>(ObjectIds::TEST_OBJECT);
|
auto* factory = TaskFactory::instance();
|
||||||
cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) <<
|
#ifdef PLATFORM_WIN
|
||||||
mySysObj->getObjectId() << endl;
|
|
||||||
auto* taskFactory = TaskFactory::instance();
|
#endif
|
||||||
PeriodicTaskIF* periodicTask = taskFactory->createPeriodicTask("TEST_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
|
auto* periodicTask0 = factory->createPeriodicTask("TASK_0", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.5, nullptr);
|
||||||
periodicTask->addComponent(ObjectIds::TEST_OBJECT);
|
auto* periodicTask1 = factory->createPeriodicTask("TASK_1", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
|
||||||
periodicTask->startTask();
|
periodicTask0->addComponent(&myExecutableObject0);
|
||||||
|
periodicTask0->addComponent(&myExecutableObject1);
|
||||||
|
periodicTask1->addComponent(&myExecutableObject2);
|
||||||
|
periodicTask0->startTask();
|
||||||
|
periodicTask1->startTask();
|
||||||
while(true) {
|
while(true) {
|
||||||
using namespace std::chrono_literals;
|
|
||||||
this_thread::sleep_for(5000ms);
|
this_thread::sleep_for(5000ms);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
#include "fsfw/objectmanager.h"
|
#include "fsfw/objectmanager.h"
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WIN
|
||||||
|
#include "fsfw/osal/windows/winTaskHelpers.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
enum ObjectIds {
|
enum ObjectIds {
|
||||||
@ -31,7 +36,12 @@ int main() {
|
|||||||
cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) <<
|
cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) <<
|
||||||
mySysObj->getObjectId() << endl;
|
mySysObj->getObjectId() << endl;
|
||||||
auto* taskFactory = TaskFactory::instance();
|
auto* taskFactory = TaskFactory::instance();
|
||||||
PeriodicTaskIF* periodicTask = taskFactory->createPeriodicTask("TEST_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
|
#ifdef PLATFORM_WIN
|
||||||
|
auto prio = tasks::makeWinPriority();
|
||||||
|
#else
|
||||||
|
auto prio = 0;
|
||||||
|
#endif
|
||||||
|
PeriodicTaskIF* periodicTask = taskFactory->createPeriodicTask("TEST_TASK", prio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
|
||||||
periodicTask->addComponent(ObjectIds::TEST_OBJECT);
|
periodicTask->addComponent(ObjectIds::TEST_OBJECT);
|
||||||
periodicTask->startTask();
|
periodicTask->startTask();
|
||||||
while(true) {
|
while(true) {
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include "fsfw/platform.h"
|
||||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||||
#include "fsfw/tasks/PeriodicTaskIF.h"
|
#include "fsfw/tasks/PeriodicTaskIF.h"
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WIN
|
||||||
|
#include "fsfw/osal/windows/winTaskHelpers.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class MyExecutableObjectIF {
|
class MyExecutableObjectIF {
|
||||||
@ -72,8 +77,13 @@ int main() {
|
|||||||
MyExecutableObject1 myExecutableObject1;
|
MyExecutableObject1 myExecutableObject1;
|
||||||
MyExecutableObject2 myExecutableObject2;
|
MyExecutableObject2 myExecutableObject2;
|
||||||
auto* factory = TaskFactory::instance();
|
auto* factory = TaskFactory::instance();
|
||||||
auto* periodicTask0 = factory->createPeriodicTask("TASK_0", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.5, nullptr);
|
#ifdef PLATFORM_WIN
|
||||||
auto* periodicTask1 = factory->createPeriodicTask("TASK_1", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
|
auto prio = tasks::makeWinPriority();
|
||||||
|
#else
|
||||||
|
auto prio = 0;
|
||||||
|
#endif
|
||||||
|
auto* periodicTask0 = factory->createPeriodicTask("TASK_0", prio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.5, nullptr);
|
||||||
|
auto* periodicTask1 = factory->createPeriodicTask("TASK_1", prio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
|
||||||
periodicTask0->addComponent(&myExecutableObject0);
|
periodicTask0->addComponent(&myExecutableObject0);
|
||||||
periodicTask0->addComponent(&myExecutableObject1);
|
periodicTask0->addComponent(&myExecutableObject1);
|
||||||
periodicTask1->addComponent(&myExecutableObject2);
|
periodicTask1->addComponent(&myExecutableObject2);
|
||||||
|
Loading…
Reference in New Issue
Block a user