completed 03
This commit is contained in:
parent
535840a831
commit
497ff3daf4
29
main.cpp
29
main.cpp
@ -1,23 +1,42 @@
|
|||||||
#include "fsfw/objectmanager.h"
|
#include "fsfw/objectmanager.h"
|
||||||
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
#include <thread>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class MySystemObject: public SystemObject {
|
enum ObjectIds {
|
||||||
|
TEST_OBJECT = 0x10101010
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyObject: public ExecutableObjectIF, public SystemObject {
|
||||||
public:
|
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 {
|
ReturnValue_t initialize() override {
|
||||||
cout << "MySystemObject::initialize: Custom init" << endl;
|
cout << "MyObject::initialize: Custom init" << endl;
|
||||||
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
new MySystemObject();
|
new MyObject(ObjectIds::TEST_OBJECT);
|
||||||
auto* objManager = ObjectManager::instance();
|
auto* objManager = ObjectManager::instance();
|
||||||
objManager->initialize();
|
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) <<
|
cout << "Object ID: " << setfill('0') << hex << "0x" << setw(8) <<
|
||||||
mySysObj->getObjectId() << endl;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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
|
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
|
if it. If this is not the case already, refactor your `MySystemObject` to expect
|
||||||
the Object ID via constructor argument.
|
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
|
||||||
|
|
@ -9,6 +9,7 @@ public:
|
|||||||
MySystemObject(): SystemObject(0x10101010, false) {}
|
MySystemObject(): SystemObject(0x10101010, false) {}
|
||||||
ReturnValue_t initialize() override {
|
ReturnValue_t initialize() override {
|
||||||
cout << "MySystemObject::initialize: Custom init" << endl;
|
cout << "MySystemObject::initialize: Custom init" << endl;
|
||||||
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ public:
|
|||||||
MySystemObject(): SystemObject(0x10101010) {}
|
MySystemObject(): SystemObject(0x10101010) {}
|
||||||
ReturnValue_t initialize() override {
|
ReturnValue_t initialize() override {
|
||||||
cout << "MySystemObject::initialize: Custom init" << endl;
|
cout << "MySystemObject::initialize: Custom init" << endl;
|
||||||
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
42
ws-objects-tmtc/objects-tmtc-solutions/main-03.cpp
Normal file
42
ws-objects-tmtc/objects-tmtc-solutions/main-03.cpp
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user