add FSFW example specific controller
This commit is contained in:
parent
f193608c38
commit
0720dc5121
@ -0,0 +1,3 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
FsfwTestController.cpp
|
||||
)
|
217
example/controller/FsfwTestController.cpp
Normal file
217
example/controller/FsfwTestController.cpp
Normal file
@ -0,0 +1,217 @@
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include "FsfwTestController.h"
|
||||
|
||||
FsfwTestController::FsfwTestController(object_id_t objectId, object_id_t device0,
|
||||
object_id_t device1, uint8_t verboseLevel):
|
||||
TestController(objectId, objects::NO_OBJECT, 5), device0Id(device0),
|
||||
device1Id(device1), deviceDataset0(device0), deviceDataset1(device1) {
|
||||
}
|
||||
|
||||
FsfwTestController::~FsfwTestController() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwTestController::handleCommandMessage(CommandMessage *message) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwTestController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void FsfwTestController::performControlOperation() {
|
||||
// We will trace variables if we received an update notification or snapshots
|
||||
if (verboseLevel >= 1) {
|
||||
if(not traceVariable) {
|
||||
return;
|
||||
}
|
||||
switch(currentTraceType) {
|
||||
case(NONE): {
|
||||
break;
|
||||
}
|
||||
case(TRACE_DEV_0_UINT8): {
|
||||
if(traceCounter == 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "Tracing finished" << std::endl;
|
||||
#else
|
||||
sif::printInfo("Tracing finished\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
traceVariable = false;
|
||||
traceCounter = traceCycles;
|
||||
currentTraceType = TraceTypes::NONE;
|
||||
break;
|
||||
}
|
||||
PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "Tracing device 0 variable 0 (UINT8), current value: " <<
|
||||
static_cast<int>(deviceDataset0.testUint8Var.value) << std::endl;
|
||||
#else
|
||||
sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n",
|
||||
deviceDataset0.testUint8Var.value);
|
||||
#endif
|
||||
traceCounter--;
|
||||
break;
|
||||
}
|
||||
case(TRACE_DEV_0_VECTOR): {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
|
||||
namespace td = testdevice;
|
||||
ReturnValue_t result = TestController::initializeAfterTaskCreation();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
HasLocalDataPoolIF* device0 = ObjectManager::instance()->get<HasLocalDataPoolIF>(
|
||||
deviceDataset0.getCreatorObjectId());
|
||||
if(device0 == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 "
|
||||
"handle invalid!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 0 "
|
||||
"handle invalid!");
|
||||
#endif
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface();
|
||||
if(subscriptionIF != nullptr) {
|
||||
/* For DEVICE_0, we only subscribe for notifications */
|
||||
subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(),
|
||||
getCommandQueue(), false);
|
||||
subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID,
|
||||
getObjectId(), getCommandQueue(), false);
|
||||
}
|
||||
|
||||
|
||||
HasLocalDataPoolIF* device1 = ObjectManager::instance()->get<HasLocalDataPoolIF>(
|
||||
deviceDataset0.getCreatorObjectId());
|
||||
if(device1 == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 "
|
||||
"handle invalid!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 1 "
|
||||
"handle invalid!");
|
||||
#endif
|
||||
}
|
||||
|
||||
subscriptionIF = device1->getSubscriptionInterface();
|
||||
if(subscriptionIF != nullptr) {
|
||||
/* For DEVICE_1, we will subscribe for snapshots */
|
||||
subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(),
|
||||
getCommandQueue(), true);
|
||||
subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID,
|
||||
getObjectId(), getCommandQueue(), true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
LocalPoolDataSetBase* FsfwTestController::getDataSetHandle(sid_t sid) {
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwTestController::checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId,
|
||||
bool* clearMessage) {
|
||||
using namespace std;
|
||||
|
||||
if (verboseLevel >= 1) {
|
||||
char const* printout = nullptr;
|
||||
if(storeId == storeId::INVALID_STORE_ADDRESS) {
|
||||
printout = "Notification";
|
||||
}
|
||||
else {
|
||||
printout = "Snapshot";
|
||||
}
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "FsfwTestController::handleChangedDataset: " << printout << " update"
|
||||
"from object ID " << setw(8) << setfill('0') << hex << sid.objectId <<
|
||||
" and set ID " << sid.ownerSetId << dec << setfill(' ') << endl;
|
||||
#else
|
||||
sif::printInfo("FsfwTestController::handleChangedPoolVariable: %s update from"
|
||||
"object ID 0x%08x and set ID %lu\n", printout, sid.objectId, sid.ownerSetId);
|
||||
#endif
|
||||
|
||||
if (storeId == storeId::INVALID_STORE_ADDRESS) {
|
||||
if(sid.objectId == device0Id) {
|
||||
PoolReadGuard readHelper(&deviceDataset0.testFloat3Vec);
|
||||
float floatVec[3];
|
||||
floatVec[0] = deviceDataset0.testFloat3Vec.value[0];
|
||||
floatVec[1] = deviceDataset0.testFloat3Vec.value[1];
|
||||
floatVec[2] = deviceDataset0.testFloat3Vec.value[2];
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " <<
|
||||
floatVec[1] << ", " << floatVec[2] << "]" << std::endl;
|
||||
#else
|
||||
sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n",
|
||||
floatVec[0], floatVec[1], floatVec[2]);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We will trace the variables for snapshots and update notifications */
|
||||
if(not traceVariable) {
|
||||
traceVariable = true;
|
||||
traceCounter = traceCycles;
|
||||
currentTraceType = TraceTypes::TRACE_DEV_0_VECTOR;
|
||||
}
|
||||
}
|
||||
|
||||
void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId,
|
||||
bool* clearMessage) {
|
||||
|
||||
using namespace std;
|
||||
|
||||
if (verboseLevel >= 1) {
|
||||
char const* printout = nullptr;
|
||||
if (storeId == storeId::INVALID_STORE_ADDRESS) {
|
||||
printout = "Notification";
|
||||
}
|
||||
else {
|
||||
printout = "Snapshot";
|
||||
}
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestController::handleChangedPoolVariable: " << printout << " update from object "
|
||||
"ID 0x" << setw(8) << setfill('0') << hex << globPoolId.objectId <<
|
||||
" and local pool ID " << globPoolId.localPoolId << dec << setfill(' ') << endl;
|
||||
#else
|
||||
sif::printInfo("TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and "
|
||||
"local pool ID %lu\n", printout, globPoolId.objectId, globPoolId.localPoolId);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
|
||||
if (storeId == storeId::INVALID_STORE_ADDRESS) {
|
||||
if(globPoolId.objectId == device0Id) {
|
||||
PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "Current test variable 0 (UINT8) value: " << static_cast<int>(
|
||||
deviceDataset0.testUint8Var.value) << std::endl;
|
||||
#else
|
||||
sif::printInfo("Current test variable 0 (UINT8) value %d\n",
|
||||
deviceDataset0.testUint8Var.value);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We will trace the variables for snapshots and update notifications */
|
||||
if(not traceVariable) {
|
||||
traceVariable = true;
|
||||
traceCounter = traceCycles;
|
||||
currentTraceType = TraceTypes::TRACE_DEV_0_UINT8;
|
||||
}
|
||||
}
|
||||
|
||||
|
53
example/controller/FsfwTestController.h
Normal file
53
example/controller/FsfwTestController.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef EXAMPLE_COMMON_EXAMPLE_CONTROLLER_FSFWTESTCONTROLLER_H_
|
||||
#define EXAMPLE_COMMON_EXAMPLE_CONTROLLER_FSFWTESTCONTROLLER_H_
|
||||
|
||||
#include "fsfw/controller/ExtendedControllerBase.h"
|
||||
#include "fsfw_tests/integration/controller/TestController.h"
|
||||
|
||||
class FsfwTestController: public TestController {
|
||||
public:
|
||||
FsfwTestController(object_id_t objectId, object_id_t device0, object_id_t device1,
|
||||
uint8_t verboseLevel = 0);
|
||||
virtual~ FsfwTestController();
|
||||
ReturnValue_t handleCommandMessage(CommandMessage *message) override;
|
||||
|
||||
/**
|
||||
* Periodic helper from ControllerBase, implemented by child class.
|
||||
*/
|
||||
virtual void performControlOperation() override;
|
||||
|
||||
private:
|
||||
|
||||
object_id_t device0Id;
|
||||
object_id_t device1Id;
|
||||
testdevice::TestDataSet deviceDataset0;
|
||||
testdevice::TestDataSet deviceDataset1;
|
||||
|
||||
uint8_t verboseLevel = 0;
|
||||
bool traceVariable = false;
|
||||
uint8_t traceCycles = 5;
|
||||
uint8_t traceCounter = traceCycles;
|
||||
|
||||
enum TraceTypes {
|
||||
NONE,
|
||||
TRACE_DEV_0_UINT8,
|
||||
TRACE_DEV_0_VECTOR
|
||||
};
|
||||
TraceTypes currentTraceType = TraceTypes::NONE;
|
||||
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
void handleChangedDataset(sid_t sid, store_address_t storeId,
|
||||
bool* clearMessage) override;
|
||||
void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId,
|
||||
bool* clearMessage) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode) override ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* EXAMPLE_COMMON_EXAMPLE_CONTROLLER_FSFWTESTCONTROLLER_H_ */
|
@ -1,4 +1,3 @@
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
GenericFactory.cpp
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
GenericFactory.cpp
|
||||
)
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef MISSION_DEMO_MUTEXEXAMPLE_H_
|
||||
#define MISSION_DEMO_MUTEXEXAMPLE_H_
|
||||
#ifndef EXAMPLE_COMMON_MUTEXEXAMPLE_H_
|
||||
#define EXAMPLE_COMMON_MUTEXEXAMPLE_H_
|
||||
|
||||
namespace MutexExample {
|
||||
void example();
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEMO_MUTEXEXAMPLE_H_ */
|
||||
#endif /* EXAMPLE_COMMON_MUTEXEXAMPLE_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user