2021-12-14 17:49:19 +01:00
|
|
|
#include "FsfwTestController.h"
|
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
#include <fsfw/datapool/PoolReadGuard.h>
|
2021-12-14 17:49:19 +01:00
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
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) {}
|
2021-12-14 17:49:19 +01:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
FsfwTestController::~FsfwTestController() {}
|
2021-12-14 17:49:19 +01:00
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
ReturnValue_t
|
|
|
|
FsfwTestController::handleCommandMessage(CommandMessage *message) {
|
2022-05-05 20:55:28 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
ReturnValue_t FsfwTestController::initializeLocalDataPool(
|
|
|
|
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
2022-05-05 20:55:28 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FsfwTestController::performControlOperation() {
|
2022-05-05 20:55:28 +02:00
|
|
|
// 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) {
|
2022-05-09 00:09:39 +02:00
|
|
|
FSFW_LOGI("Tracing finished\n");
|
2022-05-05 20:55:28 +02:00
|
|
|
traceVariable = false;
|
|
|
|
traceCounter = traceCycles;
|
|
|
|
currentTraceType = TraceTypes::NONE;
|
|
|
|
break;
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
2022-05-05 20:55:28 +02:00
|
|
|
PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGI("Tracing device 0 variable 0 (UINT8), current value: {}",
|
|
|
|
static_cast<int>(deviceDataset0.testUint8Var.value));
|
2022-05-05 20:55:28 +02:00
|
|
|
traceCounter--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (TRACE_DEV_0_VECTOR): {
|
|
|
|
break;
|
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
|
2022-05-05 20:55:28 +02:00
|
|
|
namespace td = testdevice;
|
|
|
|
ReturnValue_t result = TestController::initializeAfterTaskCreation();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2021-12-14 17:49:19 +01:00
|
|
|
return result;
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2022-05-09 00:09:39 +02:00
|
|
|
auto* device0 =
|
2022-05-05 20:55:28 +02:00
|
|
|
ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId());
|
|
|
|
if (device0 == nullptr) {
|
2022-05-09 00:09:39 +02:00
|
|
|
FSFW_LOGW("initializeAfterTaskCreation: Test device handler 0 handle invalid\n");
|
2022-05-05 20:55:28 +02:00
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
2022-05-22 15:30:08 +02:00
|
|
|
ProvidesDataPoolSubscriptionIF *subscriptionIF =
|
|
|
|
device0->getSubscriptionInterface();
|
2022-05-05 20:55:28 +02:00
|
|
|
if (subscriptionIF != nullptr) {
|
|
|
|
/* For DEVICE_0, we only subscribe for notifications */
|
2022-05-22 15:30:08 +02:00
|
|
|
subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(),
|
|
|
|
getCommandQueue(), false);
|
|
|
|
subscriptionIF->subscribeForVariableUpdateMessage(
|
|
|
|
td::PoolIds::TEST_UINT8_ID, getObjectId(), getCommandQueue(), false);
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 00:09:39 +02:00
|
|
|
auto* device1 =
|
2022-05-05 20:55:28 +02:00
|
|
|
ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId());
|
|
|
|
if (device1 == nullptr) {
|
2022-05-09 00:09:39 +02:00
|
|
|
FSFW_LOGW("initializeAfterTaskCreation: Test device handler 1 handle invalid\n");
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
subscriptionIF = device1->getSubscriptionInterface();
|
|
|
|
if (subscriptionIF != nullptr) {
|
|
|
|
/* For DEVICE_1, we will subscribe for snapshots */
|
2022-05-22 15:30:08 +02:00
|
|
|
subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(),
|
|
|
|
getCommandQueue(), true);
|
|
|
|
subscriptionIF->subscribeForVariableUpdateMessage(
|
|
|
|
td::PoolIds::TEST_UINT8_ID, getObjectId(), getCommandQueue(), true);
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
|
|
|
return result;
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
LocalPoolDataSetBase *FsfwTestController::getDataSetHandle(sid_t sid) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
ReturnValue_t FsfwTestController::checkModeCommand(Mode_t mode,
|
|
|
|
Submode_t submode,
|
|
|
|
uint32_t *msToReachTheMode) {
|
2022-05-05 20:55:28 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
void FsfwTestController::handleChangedDataset(sid_t sid,
|
|
|
|
store_address_t storeId,
|
|
|
|
bool *clearMessage) {
|
2022-05-05 20:55:28 +02:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
if (verboseLevel >= 1) {
|
2022-05-22 15:30:08 +02:00
|
|
|
char const *printout = nullptr;
|
2022-05-05 20:55:28 +02:00
|
|
|
if (storeId == storeId::INVALID_STORE_ADDRESS) {
|
|
|
|
printout = "Notification";
|
|
|
|
} else {
|
|
|
|
printout = "Snapshot";
|
|
|
|
}
|
2022-05-09 01:28:41 +02:00
|
|
|
FSFW_LOGI("handleChangedDataset: {} update from object ID {:#010x} and set ID {}\n", printout,
|
2022-05-09 01:14:53 +02:00
|
|
|
sid.objectId, sid.ownerSetId);
|
2021-12-14 17:49:19 +01:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
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];
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGI("Current float vector (3) values: [{},{},{}]\n", floatVec[0], floatVec[1],
|
|
|
|
floatVec[2]);
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We will trace the variables for snapshots and update notifications */
|
|
|
|
if (not traceVariable) {
|
|
|
|
traceVariable = true;
|
|
|
|
traceCounter = traceCycles;
|
|
|
|
currentTraceType = TraceTypes::TRACE_DEV_0_VECTOR;
|
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:30:08 +02:00
|
|
|
void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId,
|
|
|
|
store_address_t storeId,
|
|
|
|
bool *clearMessage) {
|
2022-05-05 20:55:28 +02:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
if (verboseLevel >= 1) {
|
2022-05-22 15:30:08 +02:00
|
|
|
char const *printout = nullptr;
|
2022-05-05 20:55:28 +02:00
|
|
|
if (storeId == storeId::INVALID_STORE_ADDRESS) {
|
|
|
|
printout = "Notification";
|
|
|
|
} else {
|
|
|
|
printout = "Snapshot";
|
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGI(
|
|
|
|
"TestController::handleChangedPoolVariable: {} update from object "
|
|
|
|
"ID {:#010x} and LPID {}\n",
|
2022-05-05 20:55:28 +02:00
|
|
|
printout, globPoolId.objectId, globPoolId.localPoolId);
|
2021-12-14 17:49:19 +01:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
if (storeId == storeId::INVALID_STORE_ADDRESS) {
|
|
|
|
if (globPoolId.objectId == device0Id) {
|
|
|
|
PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
|
2022-05-09 01:14:53 +02:00
|
|
|
FSFW_LOGI("Current test variable 0 (UINT8) value: {}",
|
|
|
|
static_cast<int>(deviceDataset0.testUint8Var.value));
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|
2022-05-05 20:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We will trace the variables for snapshots and update notifications */
|
|
|
|
if (not traceVariable) {
|
|
|
|
traceVariable = true;
|
|
|
|
traceCounter = traceCycles;
|
|
|
|
currentTraceType = TraceTypes::TRACE_DEV_0_UINT8;
|
|
|
|
}
|
2021-12-14 17:49:19 +01:00
|
|
|
}
|