completed 03

This commit is contained in:
Robin Müller 2022-10-04 11:20:21 +02:00
parent 535840a831
commit 497ff3daf4
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
5 changed files with 73 additions and 6 deletions

View File

@ -1,23 +1,42 @@
#include "fsfw/objectmanager.h"
#include "fsfw/tasks/TaskFactory.h"
#include <thread>
#include <iostream>
#include <iomanip>
using namespace std;
class MySystemObject: public SystemObject {
enum ObjectIds {
TEST_OBJECT = 0x10101010
};
class MyObject: public ExecutableObjectIF, public SystemObject {
public:
MySystemObject(): SystemObject(0x10101010) {}
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 << "MySystemObject::initialize: Custom init" << endl;
cout << "MyObject::initialize: Custom init" << endl;
return returnvalue::OK;
}
};
int main() {
new MySystemObject();
new MyObject(ObjectIds::TEST_OBJECT);
auto* objManager = ObjectManager::instance();
objManager->initialize();
auto* mySysObj = objManager->get<MySystemObject>(0x10101010);
auto* mySysObj = objManager->get<MyObject>(ObjectIds::TEST_OBJECT);
cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) <<
mySysObj->getObjectId() << endl;
auto* taskFactory = TaskFactory::instance();
PeriodicTaskIF* periodicTask = taskFactory->createPeriodicTask("TEST_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
periodicTask->addComponent(ObjectIds::TEST_OBJECT);
periodicTask->startTask();
while(true) {
using namespace std::chrono_literals;
this_thread::sleep_for(5000ms);
}
return 0;
}

View File

@ -98,4 +98,8 @@ of the object, you can also add units to schedule by using their object ID
2. Create a new enum called `ObjectIds` and make your object ID an enum number
if it. If this is not the case already, refactor your `MySystemObject` to expect
the Object ID via constructor argument.
2. Create a `PeriodicTask` and add your custom system object using its object ID
3. Add the `ExecutableObjectIF` to the list of implemented interface in `MySystemObject`
and rename it to `MyObject` to make it executable
3. Create a `PeriodicTask` and add your custom system object using its object ID
4. Schedule the object

View File

@ -9,6 +9,7 @@ public:
MySystemObject(): SystemObject(0x10101010, false) {}
ReturnValue_t initialize() override {
cout << "MySystemObject::initialize: Custom init" << endl;
return returnvalue::OK;
}
};

View File

@ -9,6 +9,7 @@ public:
MySystemObject(): SystemObject(0x10101010) {}
ReturnValue_t initialize() override {
cout << "MySystemObject::initialize: Custom init" << endl;
return returnvalue::OK;
}
};

View File

@ -0,0 +1,42 @@
#include "fsfw/objectmanager.h"
#include "fsfw/tasks/TaskFactory.h"
#include <thread>
#include <iostream>
#include <iomanip>
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();
PeriodicTaskIF* periodicTask = taskFactory->createPeriodicTask("TEST_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
periodicTask->addComponent(ObjectIds::TEST_OBJECT);
periodicTask->startTask();
while(true) {
using namespace std::chrono_literals;
this_thread::sleep_for(5000ms);
}
return 0;
}