From 96106f096cf078f3e41aa304718d81bb7935be4f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 4 Oct 2022 10:35:03 +0200 Subject: [PATCH] 01 solution --- main.cpp | 12 +++++----- ws-objects-tmtc/README.md | 6 +++++ .../objects-tmtc-solutions/main-01.cpp | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp diff --git a/main.cpp b/main.cpp index 8e5b85e..cd68bed 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,12 @@ -#include #include "fsfw/objectmanager.h" - +#include #include using namespace std; class MySystemObject: public SystemObject { public: - MySystemObject(): SystemObject(0x10101010, false) {} + MySystemObject(): SystemObject(0x10101010) {} ReturnValue_t initialize() override { cout << "MySystemObject::initialize: Custom init" << endl; } @@ -15,8 +14,9 @@ public: int main() { auto* mySysObj = new MySystemObject(); - cout << "Object ID: " << setfill('0') << setw(8) << hex << "0x" << + auto* objManager = ObjectManager::instance(); + cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) << mySysObj->getObjectId() << endl; - mySysObj->initialize(); - delete mySysObj; + objManager->initialize(); + return 0; } diff --git a/ws-objects-tmtc/README.md b/ws-objects-tmtc/README.md index 8a48e0f..16f46da 100644 --- a/ws-objects-tmtc/README.md +++ b/ws-objects-tmtc/README.md @@ -72,3 +72,9 @@ all its registered objects. ## Subtasks + 1. Register the `MySystemObject` class into the global object manager. You can do this with a + simple tweak of the base class constructor. + 2. Remove the `delete` call. The object manager will delete all of its contained objects + automatically in its own destructor + 3. Retrieve the global instance of the object manager using its static `instance` method + and use it to initialize all system objects including your custom system object. diff --git a/ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp b/ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp new file mode 100644 index 0000000..485e340 --- /dev/null +++ b/ws-objects-tmtc/objects-tmtc-solutions/main-01.cpp @@ -0,0 +1,22 @@ +#include "fsfw/objectmanager.h" +#include +#include + +using namespace std; + +class MySystemObject: public SystemObject { +public: + MySystemObject(): SystemObject(0x10101010, false) {} + ReturnValue_t initialize() override { + cout << "MySystemObject::initialize: Custom init" << endl; + } +}; + +int main() { + auto* mySysObj = new MySystemObject(); + cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) << + mySysObj->getObjectId() << endl; + mySysObj->initialize(); + delete mySysObj; + return 0; +}