From 497ff3daf4c38c084749a90018c394ded86c8b33 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 4 Oct 2022 11:20:21 +0200 Subject: [PATCH] completed 03 --- main.cpp | 29 ++++++++++--- ws-objects-tmtc/README.md | 6 ++- .../objects-tmtc-solutions/main-01.cpp | 1 + .../objects-tmtc-solutions/main-02.cpp | 1 + .../objects-tmtc-solutions/main-03.cpp | 42 +++++++++++++++++++ 5 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 ws-objects-tmtc/objects-tmtc-solutions/main-03.cpp diff --git a/main.cpp b/main.cpp index 491b926..cb97058 100644 --- a/main.cpp +++ b/main.cpp @@ -1,23 +1,42 @@ #include "fsfw/objectmanager.h" +#include "fsfw/tasks/TaskFactory.h" +#include #include #include 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(0x10101010); + auto* mySysObj = objManager->get(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; } diff --git a/ws-objects-tmtc/README.md b/ws-objects-tmtc/README.md index 4b5ab7f..c0524bc 100644 --- a/ws-objects-tmtc/README.md +++ b/ws-objects-tmtc/README.md @@ -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 + \ No newline at end of file diff --git a/ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp b/ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp index 485e340..d2425c8 100644 --- a/ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp +++ b/ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp @@ -9,6 +9,7 @@ public: MySystemObject(): SystemObject(0x10101010, false) {} ReturnValue_t initialize() override { cout << "MySystemObject::initialize: Custom init" << endl; + return returnvalue::OK; } }; diff --git a/ws-objects-tmtc/objects-tmtc-solutions/main-02.cpp b/ws-objects-tmtc/objects-tmtc-solutions/main-02.cpp index 491b926..448d14a 100644 --- a/ws-objects-tmtc/objects-tmtc-solutions/main-02.cpp +++ b/ws-objects-tmtc/objects-tmtc-solutions/main-02.cpp @@ -9,6 +9,7 @@ public: MySystemObject(): SystemObject(0x10101010) {} ReturnValue_t initialize() override { cout << "MySystemObject::initialize: Custom init" << endl; + return returnvalue::OK; } }; diff --git a/ws-objects-tmtc/objects-tmtc-solutions/main-03.cpp b/ws-objects-tmtc/objects-tmtc-solutions/main-03.cpp new file mode 100644 index 0000000..cb97058 --- /dev/null +++ b/ws-objects-tmtc/objects-tmtc-solutions/main-03.cpp @@ -0,0 +1,42 @@ +#include "fsfw/objectmanager.h" +#include "fsfw/tasks/TaskFactory.h" +#include +#include +#include + +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(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; +}