fsfw-from-zero/ws-objects/objects-solutions/main-03.cpp

53 lines
1.5 KiB
C++
Raw Normal View History

2022-10-04 11:20:21 +02:00
#include "fsfw/objectmanager.h"
#include "fsfw/tasks/TaskFactory.h"
2022-10-04 11:33:26 +02:00
2022-10-04 11:20:21 +02:00
#include <thread>
#include <iostream>
#include <iomanip>
2022-10-04 11:33:26 +02:00
#ifdef PLATFORM_WIN
#include "fsfw/osal/windows/winTaskHelpers.h"
#endif
2022-10-04 11:20:21 +02:00
using namespace std;
enum ObjectIds {
TEST_OBJECT = 0x10101010
};
class MyObject: public ExecutableObjectIF, public SystemObject {
public:
MyObject(object_id_t objectId): SystemObject(objectId) {}
ReturnValue_t performOperation(uint8_t opCode) override {
cout << "MyObject::performOperation: Periodic handling" << endl;
return returnvalue::OK;
}
ReturnValue_t initialize() override {
cout << "MyObject::initialize: Custom init" << endl;
return returnvalue::OK;
}
};
int main() {
new MyObject(ObjectIds::TEST_OBJECT);
auto* objManager = ObjectManager::instance();
objManager->initialize();
auto* mySysObj = objManager->get<MyObject>(ObjectIds::TEST_OBJECT);
cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) <<
mySysObj->getObjectId() << endl;
auto* taskFactory = TaskFactory::instance();
2022-10-04 11:33:26 +02:00
#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);
2022-10-04 11:20:21 +02:00
periodicTask->addComponent(ObjectIds::TEST_OBJECT);
periodicTask->startTask();
while(true) {
using namespace std::chrono_literals;
this_thread::sleep_for(5000ms);
}
return 0;
}