moved some code to fsfw
This commit is contained in:
parent
127a0f6e16
commit
db0af8b29a
@ -1,7 +1,5 @@
|
||||
add_subdirectory(mission)
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(utility)
|
||||
add_subdirectory(example)
|
||||
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include <pollingsequence/pollingSequenceFactory.h>
|
||||
#include <objects/systemObjectList.h>
|
||||
#include "pollingsequence/pollingSequenceFactory.h"
|
||||
#include "objects/systemObjectList.h"
|
||||
|
||||
#include "example/test/FsfwExampleTask.h"
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
|
||||
#include <test/FsfwExampleTask.h>
|
||||
|
||||
|
||||
ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) {
|
||||
uint32_t length = thisSequence->getPeriodMs();
|
||||
|
@ -1,5 +1,5 @@
|
||||
add_subdirectory(controller)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(devices)
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(utility)
|
||||
add_subdirectory(controller)
|
||||
add_subdirectory(assemblies)
|
0
example/controller/CMakeLists.txt
Normal file
0
example/controller/CMakeLists.txt
Normal file
@ -6,16 +6,16 @@
|
||||
#include "tmtc/pusIds.h"
|
||||
#include "objects/systemObjectList.h"
|
||||
|
||||
#include "fsfw_tests/internal/InternalUnitTester.h"
|
||||
#include "test/FsfwExampleTask.h"
|
||||
#include "test/FsfwReaderTask.h"
|
||||
#include "example/utility/TmFunnel.h"
|
||||
#include "example/test/FsfwExampleTask.h"
|
||||
#include "example/test/FsfwReaderTask.h"
|
||||
|
||||
#include "mission/assemblies/TestAssembly.h"
|
||||
#include "mission/devices/TestCookie.h"
|
||||
#include "mission/devices/TestDeviceHandler.h"
|
||||
#include "mission/devices/TestEchoComIF.h"
|
||||
#include "mission/utility/TmFunnel.h"
|
||||
#include "mission/controller/TestController.h"
|
||||
#include "fsfw_tests/internal/InternalUnitTester.h"
|
||||
#include "fsfw_tests/integration/assemblies/TestAssembly.h"
|
||||
#include "fsfw_tests/integration/devices/TestCookie.h"
|
||||
#include "fsfw_tests/integration/devices/TestDeviceHandler.h"
|
||||
#include "fsfw_tests/integration/devices/TestEchoComIF.h"
|
||||
#include "fsfw_tests/integration/controller/TestController.h"
|
||||
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
#include "fsfw/events/EventManager.h"
|
||||
@ -95,12 +95,12 @@ void ObjectFactory::produceGenericObjects() {
|
||||
|
||||
/* Demo device handler object */
|
||||
size_t expectedMaxReplyLen = 64;
|
||||
CookieIF* testCookie = new DummyCookie(
|
||||
CookieIF* testCookie = new TestCookie(
|
||||
static_cast<address_t>(testdevice::DeviceIndex::DEVICE_0), expectedMaxReplyLen);
|
||||
new TestEchoComIF(objects::TEST_ECHO_COM_IF);
|
||||
new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF, testCookie,
|
||||
testdevice::DeviceIndex::DEVICE_0, enableInfoPrintout);
|
||||
testCookie = new DummyCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_1),
|
||||
testCookie = new TestCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_1),
|
||||
expectedMaxReplyLen);
|
||||
new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF, testCookie,
|
||||
testdevice::DeviceIndex::DEVICE_1, enableInfoPrintout);
|
0
example/devices/CMakeLists.txt
Normal file
0
example/devices/CMakeLists.txt
Normal file
12
example/devices/TestDeviceHandler.h
Normal file
12
example/devices/TestDeviceHandler.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef EXAMPLE_COMMON_DEVICES_TESTDEVICEHANDLER_H_
|
||||
#define EXAMPLE_COMMON_DEVICES_TESTDEVICEHANDLER_H_
|
||||
|
||||
//#include "fsfw_tests/integration/TestDeviceHandler.h"
|
||||
//
|
||||
//class FsfwTestDeviceHandler: public TestDeviceHandler {
|
||||
//
|
||||
//};
|
||||
|
||||
|
||||
|
||||
#endif /* EXAMPLE_COMMON_DEVICES_TESTDEVICEHANDLER_H_ */
|
5
example/test/CMakeLists.txt
Normal file
5
example/test/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
FsfwReaderTask.cpp
|
||||
FsfwExampleTask.cpp
|
||||
MutexExample.cpp
|
||||
)
|
@ -1,3 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
utility.cpp
|
||||
TmFunnel.cpp
|
||||
)
|
@ -1,8 +1,9 @@
|
||||
#include "TmFunnel.h"
|
||||
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
#include <fsfw/tmtcpacket/pus/tm.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <mission/utility/TmFunnel.h>
|
||||
|
||||
object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT;
|
||||
object_id_t TmFunnel::storageDestination = objects::NO_OBJECT;
|
@ -1,3 +0,0 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
TestAssembly.cpp
|
||||
)
|
@ -1,200 +0,0 @@
|
||||
#include "commonSystemObjects.h"
|
||||
|
||||
#include <mission/assemblies/TestAssembly.h>
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
|
||||
|
||||
TestAssembly::TestAssembly(object_id_t objectId, object_id_t parentId):
|
||||
AssemblyBase(objectId, parentId) {
|
||||
ModeListEntry newModeListEntry;
|
||||
newModeListEntry.setObject(objects::TEST_DEVICE_HANDLER_0);
|
||||
newModeListEntry.setMode(MODE_OFF);
|
||||
newModeListEntry.setSubmode(SUBMODE_NONE);
|
||||
|
||||
commandTable.insert(newModeListEntry);
|
||||
|
||||
newModeListEntry.setObject(objects::TEST_DEVICE_HANDLER_1);
|
||||
newModeListEntry.setMode(MODE_OFF);
|
||||
newModeListEntry.setSubmode(SUBMODE_NONE);
|
||||
|
||||
commandTable.insert(newModeListEntry);
|
||||
|
||||
}
|
||||
|
||||
TestAssembly::~TestAssembly() {
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::commandChildren(Mode_t mode,
|
||||
Submode_t submode) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestAssembly: Received command to go to mode " << mode <<
|
||||
" submode " << (int) submode << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestAssembly: Received command to go to mode %d submode %d\n", mode, submode);
|
||||
#endif
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
if(mode == MODE_OFF){
|
||||
commandTable[0].setMode(MODE_OFF);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_OFF);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else if(mode == DeviceHandlerIF::MODE_NORMAL) {
|
||||
if(submode == submodes::SINGLE){
|
||||
commandTable[0].setMode(MODE_OFF);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_OFF);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
// We try to prefer 0 here but we try to switch to 1 even if it might fail
|
||||
if(isDeviceAvailable(objects::TEST_DEVICE_HANDLER_0)) {
|
||||
if (childrenMap[objects::TEST_DEVICE_HANDLER_0].mode == MODE_ON) {
|
||||
commandTable[0].setMode(mode);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else {
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (childrenMap[objects::TEST_DEVICE_HANDLER_1].mode == MODE_ON) {
|
||||
commandTable[1].setMode(mode);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
// Dual Mode Normal
|
||||
if (childrenMap[objects::TEST_DEVICE_HANDLER_0].mode == MODE_ON) {
|
||||
commandTable[0].setMode(mode);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
if (childrenMap[objects::TEST_DEVICE_HANDLER_1].mode == MODE_ON) {
|
||||
commandTable[1].setMode(mode);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
//Mode ON
|
||||
if(submode == submodes::SINGLE){
|
||||
commandTable[0].setMode(MODE_OFF);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_OFF);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
// We try to prefer 0 here but we try to switch to 1 even if it might fail
|
||||
if(isDeviceAvailable(objects::TEST_DEVICE_HANDLER_0)){
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
}
|
||||
else{
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
HybridIterator<ModeListEntry> iter(commandTable.begin(),
|
||||
commandTable.end());
|
||||
executeTable(iter);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::isModeCombinationValid(Mode_t mode,
|
||||
Submode_t submode) {
|
||||
switch (mode) {
|
||||
case MODE_OFF:
|
||||
if (submode == SUBMODE_NONE) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
case DeviceHandlerIF::MODE_NORMAL:
|
||||
case MODE_ON:
|
||||
if (submode < 3) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
}
|
||||
return INVALID_MODE;
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::initialize() {
|
||||
ReturnValue_t result = AssemblyBase::initialize();
|
||||
if(result != RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
handler0 = ObjectManager::instance()->get<TestDevice>(objects::TEST_DEVICE_HANDLER_0);
|
||||
handler1 = ObjectManager::instance()->get<TestDevice>(objects::TEST_DEVICE_HANDLER_1);
|
||||
if((handler0 == nullptr) or (handler1 == nullptr)){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
handler0->setParentQueue(this->getCommandQueue());
|
||||
handler1->setParentQueue(this->getCommandQueue());
|
||||
|
||||
|
||||
result = registerChild(objects::TEST_DEVICE_HANDLER_0);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = registerChild(objects::TEST_DEVICE_HANDLER_1);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::checkChildrenStateOn(
|
||||
Mode_t wantedMode, Submode_t wantedSubmode) {
|
||||
if(submode == submodes::DUAL){
|
||||
for(const auto& info:childrenMap) {
|
||||
if(info.second.mode != wantedMode or info.second.mode != wantedSubmode){
|
||||
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
else if(submode == submodes::SINGLE) {
|
||||
for(const auto& info:childrenMap) {
|
||||
if(info.second.mode == wantedMode and info.second.mode != wantedSubmode){
|
||||
return RETURN_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
|
||||
bool TestAssembly::isDeviceAvailable(object_id_t object) {
|
||||
if(healthHelper.healthTable->getHealth(object) == HasHealthIF::HEALTHY){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#ifndef MISSION_ASSEMBLIES_TESTASSEMBLY_H_
|
||||
#define MISSION_ASSEMBLIES_TESTASSEMBLY_H_
|
||||
|
||||
#include <fsfw/devicehandlers/AssemblyBase.h>
|
||||
#include "../devices/TestDeviceHandler.h"
|
||||
|
||||
class TestAssembly: public AssemblyBase {
|
||||
public:
|
||||
TestAssembly(object_id_t objectId, object_id_t parentId);
|
||||
virtual ~TestAssembly();
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
enum submodes: Submode_t{
|
||||
SINGLE = 0,
|
||||
DUAL = 1
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Command children to reach [mode,submode] combination
|
||||
* Can be done by setting #commandsOutstanding correctly,
|
||||
* or using executeTable()
|
||||
* @param mode
|
||||
* @param submode
|
||||
* @return
|
||||
* - @c RETURN_OK if ok
|
||||
* - @c NEED_SECOND_STEP if children need to be commanded again
|
||||
*/
|
||||
ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) override;
|
||||
/**
|
||||
* Check whether desired assembly mode was achieved by checking the modes
|
||||
* or/and health states of child device handlers.
|
||||
* The assembly template class will also call this function if a health
|
||||
* or mode change of a child device handler was detected.
|
||||
* @param wantedMode
|
||||
* @param wantedSubmode
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode)
|
||||
override;
|
||||
|
||||
ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
|
||||
Submode_t wantedSubmode) override;
|
||||
private:
|
||||
FixedArrayList<ModeListEntry, 2> commandTable;
|
||||
TestDevice* handler0 = nullptr;
|
||||
TestDevice* handler1 = nullptr;
|
||||
|
||||
|
||||
bool isDeviceAvailable(object_id_t object);
|
||||
};
|
||||
|
||||
#endif /* MISSION_ASSEMBLIES_TESTASSEMBLY_H_ */
|
@ -1,3 +0,0 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
TestController.cpp
|
||||
)
|
@ -1,214 +0,0 @@
|
||||
#include "TestController.h"
|
||||
#include "OBSWConfig.h"
|
||||
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
TestController::TestController(object_id_t objectId, size_t commandQueueDepth):
|
||||
ExtendedControllerBase(objectId, objects::NO_OBJECT, commandQueueDepth),
|
||||
deviceDataset0(objects::TEST_DEVICE_HANDLER_0),
|
||||
deviceDataset1(objects::TEST_DEVICE_HANDLER_1) {
|
||||
}
|
||||
|
||||
TestController::~TestController() {
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::handleCommandMessage(CommandMessage *message) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void TestController::performControlOperation() {
|
||||
/* We will trace vaiables if we received an update notification or snapshots */
|
||||
#if OBSW_CONTROLLER_PRINTOUT == 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;
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */
|
||||
}
|
||||
|
||||
void TestController::handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) {
|
||||
using namespace std;
|
||||
|
||||
#if OBSW_CONTROLLER_PRINTOUT == 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::handleChangedDataset: " << printout << " update from object "
|
||||
"ID " << setw(8) << setfill('0') << hex << sid.objectId <<
|
||||
" and set ID " << sid.ownerSetId << dec << setfill(' ') << endl;
|
||||
#else
|
||||
sif::printInfo("TestController::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 == objects::TEST_DEVICE_HANDLER_0) {
|
||||
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 */
|
||||
}
|
||||
}
|
||||
#endif /* OBSW_CONTROLLER_PRINTOUT == 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 TestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId,
|
||||
bool* clearMessage) {
|
||||
using namespace std;
|
||||
|
||||
#if OBSW_CONTROLLER_PRINTOUT == 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 == objects::TEST_DEVICE_HANDLER_0) {
|
||||
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 */
|
||||
}
|
||||
}
|
||||
#endif /* OBSW_CONTROLLER_PRINTOUT == 1 */
|
||||
|
||||
/* We will trace the variables for snapshots and update notifications */
|
||||
if(not traceVariable) {
|
||||
traceVariable = true;
|
||||
traceCounter = traceCycles;
|
||||
currentTraceType = TraceTypes::TRACE_DEV_0_UINT8;
|
||||
}
|
||||
}
|
||||
|
||||
LocalPoolDataSetBase* TestController::getDataSetHandle(sid_t sid) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::initializeAfterTaskCreation() {
|
||||
namespace td = testdevice;
|
||||
HasLocalDataPoolIF* device0 = ObjectManager::instance()->get<HasLocalDataPoolIF>(
|
||||
objects::TEST_DEVICE_HANDLER_0);
|
||||
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>(
|
||||
objects::TEST_DEVICE_HANDLER_1);
|
||||
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 HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
#ifndef MISSION_CONTROLLER_TESTCONTROLLER_H_
|
||||
#define MISSION_CONTROLLER_TESTCONTROLLER_H_
|
||||
|
||||
#include "../devices/devicedefinitions/testDeviceDefinitions.h"
|
||||
#include <fsfw/controller/ExtendedControllerBase.h>
|
||||
|
||||
|
||||
class TestController:
|
||||
public ExtendedControllerBase {
|
||||
public:
|
||||
TestController(object_id_t objectId, size_t commandQueueDepth = 10);
|
||||
virtual~ TestController();
|
||||
protected:
|
||||
testdevice::TestDataSet deviceDataset0;
|
||||
testdevice::TestDataSet deviceDataset1;
|
||||
|
||||
/* Extended Controller Base overrides */
|
||||
ReturnValue_t handleCommandMessage(CommandMessage *message) override;
|
||||
void performControlOperation() override;
|
||||
|
||||
/* HasLocalDatapoolIF callbacks */
|
||||
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;
|
||||
|
||||
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode) override;
|
||||
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
private:
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MISSION_CONTROLLER_TESTCONTROLLER_H_ */
|
@ -1,18 +0,0 @@
|
||||
#ifndef MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_
|
||||
#define MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_
|
||||
|
||||
#include <fsfw/objectmanager/SystemObjectIF.h>
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
namespace testcontroller {
|
||||
|
||||
enum sourceObjectIds: object_id_t {
|
||||
DEVICE_0_ID = objects::TEST_DEVICE_HANDLER_0,
|
||||
DEVICE_1_ID = objects::TEST_DEVICE_HANDLER_1,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_ */
|
@ -1,6 +0,0 @@
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
TestCookie.cpp
|
||||
TestDeviceHandler.cpp
|
||||
TestEchoComIF.cpp
|
||||
)
|
@ -1,14 +0,0 @@
|
||||
#include "TestCookie.h"
|
||||
|
||||
DummyCookie::DummyCookie(address_t address, size_t replyMaxLen):
|
||||
address(address), replyMaxLen(replyMaxLen) {}
|
||||
|
||||
DummyCookie::~DummyCookie() {}
|
||||
|
||||
address_t DummyCookie::getAddress() const {
|
||||
return address;
|
||||
}
|
||||
|
||||
size_t DummyCookie::getReplyMaxLen() const {
|
||||
return replyMaxLen;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_TESTCOOKIE_H_
|
||||
#define MISSION_DEVICES_TESTCOOKIE_H_
|
||||
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief Really simple cookie which does not do a lot.
|
||||
*/
|
||||
class DummyCookie: public CookieIF {
|
||||
public:
|
||||
DummyCookie(address_t address, size_t maxReplyLen);
|
||||
virtual ~DummyCookie();
|
||||
|
||||
address_t getAddress() const;
|
||||
size_t getReplyMaxLen() const;
|
||||
private:
|
||||
address_t address = 0;
|
||||
size_t replyMaxLen = 0;
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_TESTCOOKIE_H_ */
|
@ -1,804 +0,0 @@
|
||||
#include "TestDeviceHandler.h"
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
TestDevice::TestDevice(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF * cookie, testdevice::DeviceIndex deviceIdx, bool fullInfoPrintout,
|
||||
bool changingDataset):
|
||||
DeviceHandlerBase(objectId, comIF, cookie), deviceIdx(deviceIdx),
|
||||
dataset(this), fullInfoPrintout(fullInfoPrintout) {
|
||||
}
|
||||
|
||||
TestDevice::~TestDevice() {}
|
||||
|
||||
void TestDevice::performOperationHook() {
|
||||
if(periodicPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::performOperationHook: Alive!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::performOperationHook: Alive!", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(oneShot) {
|
||||
oneShot = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestDevice::doStartUp() {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::doStartUp: Switching On" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::doStartUp: Switching On\n", static_cast<int>(deviceIdx));
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(_MODE_TO_ON);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void TestDevice::doShutDown() {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::doShutDown: Switching Off" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::doShutDown: Switching Off\n", static_cast<int>(deviceIdx));
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(_MODE_SHUT_DOWN);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
||||
using namespace testdevice;
|
||||
*id = TEST_NORMAL_MODE_CMD;
|
||||
if(DeviceHandlerBase::isAwaitingReply()) {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
||||
if(mode == _MODE_TO_ON) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called"
|
||||
" from _MODE_TO_ON mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: "
|
||||
"Was called from _MODE_TO_ON mode\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
if(mode == _MODE_TO_NORMAL) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called "
|
||||
"from _MODE_TO_NORMAL mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: Was called from "
|
||||
" _MODE_TO_NORMAL mode\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(MODE_NORMAL);
|
||||
}
|
||||
if(mode == _MODE_SHUT_DOWN) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called "
|
||||
"from _MODE_SHUT_DOWN mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: Was called from "
|
||||
"_MODE_SHUT_DOWN mode\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(MODE_OFF);
|
||||
}
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
void TestDevice::doTransition(Mode_t modeFrom, Submode_t submodeFrom) {
|
||||
if(mode == _MODE_TO_NORMAL) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::doTransition: Custom transition to "
|
||||
"normal mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::doTransition: Custom transition to normal mode\n",
|
||||
deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
DeviceHandlerBase::doTransition(modeFrom, submodeFrom);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
||||
size_t commandDataLen) {
|
||||
using namespace testdevice;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
switch(deviceCommand) {
|
||||
case(TEST_NORMAL_MODE_CMD): {
|
||||
commandSent = true;
|
||||
result = buildNormalModeCommand(deviceCommand, commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_0): {
|
||||
commandSent = true;
|
||||
result = buildTestCommand0(deviceCommand, commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_1): {
|
||||
commandSent = true;
|
||||
result = buildTestCommand1(deviceCommand, commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
case(TEST_NOTIF_SNAPSHOT_VAR): {
|
||||
if(changingDatasets) {
|
||||
changingDatasets = false;
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset.testUint8Var);
|
||||
if(deviceIdx == testdevice::DeviceIndex::DEVICE_0) {
|
||||
/* This will trigger a variable notification to the demo controller */
|
||||
dataset.testUint8Var = 220;
|
||||
dataset.testUint8Var.setValid(true);
|
||||
}
|
||||
else if(deviceIdx == testdevice::DeviceIndex::DEVICE_1) {
|
||||
/* This will trigger a variable snapshot to the demo controller */
|
||||
dataset.testUint8Var = 30;
|
||||
dataset.testUint8Var.setValid(true);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case(TEST_NOTIF_SNAPSHOT_SET): {
|
||||
if(changingDatasets) {
|
||||
changingDatasets = false;
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset.testFloat3Vec);
|
||||
|
||||
if(deviceIdx == testdevice::DeviceIndex::DEVICE_0) {
|
||||
/* This will trigger a variable notification to the demo controller */
|
||||
dataset.testFloat3Vec.value[0] = 60;
|
||||
dataset.testFloat3Vec.value[1] = 70;
|
||||
dataset.testFloat3Vec.value[2] = 55;
|
||||
dataset.testFloat3Vec.setValid(true);
|
||||
}
|
||||
else if(deviceIdx == testdevice::DeviceIndex::DEVICE_1) {
|
||||
/* This will trigger a variable notification to the demo controller */
|
||||
dataset.testFloat3Vec.value[0] = -60;
|
||||
dataset.testFloat3Vec.value[1] = -70;
|
||||
dataset.testFloat3Vec.value[2] = -55;
|
||||
dataset.testFloat3Vec.setValid(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
result = DeviceHandlerIF::COMMAND_NOT_SUPPORTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::buildNormalModeCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData, size_t commandDataLen) {
|
||||
if(fullInfoPrintout) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 3
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice::buildTestCommand1: Building normal command" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice::buildTestCommand1: Building command from TEST_COMMAND_1\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* OBSW_VERBOSE_LEVEL >= 3 */
|
||||
}
|
||||
|
||||
if(commandDataLen > MAX_BUFFER_SIZE - sizeof(DeviceCommandId_t)) {
|
||||
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
/* The command is passed on in the command buffer as it is */
|
||||
passOnCommand(deviceCommand, commandData, commandDataLen);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildTestCommand0(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData, size_t commandDataLen) {
|
||||
using namespace testdevice;
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTestCommand0: Executing simple command "
|
||||
" with completion reply" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTestCommand0: Executing simple command with "
|
||||
"completion reply\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(commandDataLen > MAX_BUFFER_SIZE - sizeof(DeviceCommandId_t)) {
|
||||
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
|
||||
/* The command is passed on in the command buffer as it is */
|
||||
passOnCommand(deviceCommand, commandData, commandDataLen);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildTestCommand1(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData,
|
||||
size_t commandDataLen) {
|
||||
using namespace testdevice;
|
||||
if(commandDataLen < 7) {
|
||||
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTestCommand1: Executing command with "
|
||||
"data reply" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d:buildTestCommand1: Executing command with data reply\n",
|
||||
deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
deviceCommand = EndianConverter::convertBigEndian(deviceCommand);
|
||||
memcpy(commandBuffer, &deviceCommand, sizeof(deviceCommand));
|
||||
|
||||
/* Assign and check parameters */
|
||||
uint16_t parameter1 = 0;
|
||||
size_t size = commandDataLen;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(¶meter1,
|
||||
&commandData, &size, SerializeIF::Endianness::BIG);
|
||||
if(result == HasReturnvaluesIF::RETURN_FAILED) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Parameter 1 needs to be correct */
|
||||
if(parameter1 != testdevice::COMMAND_1_PARAM1) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
uint64_t parameter2 = 0;
|
||||
result = SerializeAdapter::deSerialize(¶meter2,
|
||||
&commandData, &size, SerializeIF::Endianness::BIG);
|
||||
if(parameter2!= testdevice::COMMAND_1_PARAM2){
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
/* Pass on the parameters to the Echo IF */
|
||||
commandBuffer[4] = (parameter1 & 0xFF00) >> 8;
|
||||
commandBuffer[5] = (parameter1 & 0xFF);
|
||||
parameter2 = EndianConverter::convertBigEndian(parameter2);
|
||||
memcpy(commandBuffer + 6, ¶meter2, sizeof(parameter2));
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = sizeof(deviceCommand) + sizeof(parameter1) +
|
||||
sizeof(parameter2);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void TestDevice::passOnCommand(DeviceCommandId_t command, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
DeviceCommandId_t deviceCommandBe = EndianConverter::convertBigEndian(command);
|
||||
memcpy(commandBuffer, &deviceCommandBe, sizeof(deviceCommandBe));
|
||||
memcpy(commandBuffer + 4, commandData, commandDataLen);
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = sizeof(deviceCommandBe) + commandDataLen;
|
||||
}
|
||||
|
||||
void TestDevice::fillCommandAndReplyMap() {
|
||||
namespace td = testdevice;
|
||||
insertInCommandAndReplyMap(testdevice::TEST_NORMAL_MODE_CMD, 5, &dataset);
|
||||
insertInCommandAndReplyMap(testdevice::TEST_COMMAND_0, 5);
|
||||
insertInCommandAndReplyMap(testdevice::TEST_COMMAND_1, 5);
|
||||
|
||||
/* No reply expected for these commands */
|
||||
insertInCommandMap(td::TEST_NOTIF_SNAPSHOT_SET);
|
||||
insertInCommandMap(td::TEST_NOTIF_SNAPSHOT_VAR);
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
using namespace testdevice;
|
||||
|
||||
/* Unless a command was sent explicitely, we don't expect any replies and ignore this
|
||||
the packet. On a real device, there might be replies which are sent without a previous
|
||||
command. */
|
||||
if(not commandSent) {
|
||||
return DeviceHandlerBase::IGNORE_FULL_PACKET;
|
||||
}
|
||||
else {
|
||||
commandSent = false;
|
||||
}
|
||||
|
||||
if(len < sizeof(object_id_t)) {
|
||||
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
||||
}
|
||||
|
||||
size_t size = len;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(foundId, &start, &size,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
DeviceCommandId_t pendingCmd = this->getPendingCommand();
|
||||
|
||||
switch(pendingCmd) {
|
||||
|
||||
case(TEST_NORMAL_MODE_CMD): {
|
||||
if(fullInfoPrintout) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 3
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice::scanForReply: Reply for normal commnand (ID " <<
|
||||
TEST_NORMAL_MODE_CMD << ") received!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::scanForReply: Reply for normal command (ID %d) "
|
||||
"received!\n", deviceIdx, TEST_NORMAL_MODE_CMD);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
*foundLen = len;
|
||||
*foundId = pendingCmd;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_0): {
|
||||
if(len < TEST_COMMAND_0_SIZE) {
|
||||
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
||||
}
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::scanForReply: Reply for simple command "
|
||||
"(ID " << TEST_COMMAND_0 << ") received!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::scanForReply: Reply for simple command (ID %d) "
|
||||
"received!\n", deviceIdx, TEST_COMMAND_0);
|
||||
#endif
|
||||
}
|
||||
|
||||
*foundLen = TEST_COMMAND_0_SIZE;
|
||||
*foundId = pendingCmd;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_1): {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::scanForReply: Reply for data command "
|
||||
"(ID " << TEST_COMMAND_1 << ") received!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::scanForReply: Reply for data command (ID %d) "
|
||||
"received\n", deviceIdx, TEST_COMMAND_1);
|
||||
#endif
|
||||
}
|
||||
|
||||
*foundLen = len;
|
||||
*foundId = pendingCmd;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
default:
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t* packet) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
switch(id) {
|
||||
/* Periodic replies */
|
||||
case testdevice::TEST_NORMAL_MODE_CMD: {
|
||||
result = interpretingNormalModeReply();
|
||||
break;
|
||||
}
|
||||
/* Simple reply */
|
||||
case testdevice::TEST_COMMAND_0: {
|
||||
result = interpretingTestReply0(id, packet);
|
||||
break;
|
||||
}
|
||||
/* Data reply */
|
||||
case testdevice::TEST_COMMAND_1: {
|
||||
result = interpretingTestReply1(id, packet);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::interpretingNormalModeReply() {
|
||||
CommandMessage directReplyMessage;
|
||||
if(changingDatasets) {
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if(dataset.testUint8Var.value == 0) {
|
||||
dataset.testUint8Var.value = 10;
|
||||
dataset.testUint32Var.value = 777;
|
||||
dataset.testFloat3Vec.value[0] = 2.5;
|
||||
dataset.testFloat3Vec.value[1] = -2.5;
|
||||
dataset.testFloat3Vec.value[2] = 2.5;
|
||||
dataset.setValidity(true, true);
|
||||
}
|
||||
else {
|
||||
dataset.testUint8Var.value = 0;
|
||||
dataset.testUint32Var.value = 0;
|
||||
dataset.testFloat3Vec.value[0] = 0.0;
|
||||
dataset.testFloat3Vec.value[1] = 0.0;
|
||||
dataset.testFloat3Vec.value[2] = 0.0;
|
||||
dataset.setValidity(false, true);
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if(dataset.testUint8Var.value == 0) {
|
||||
/* Reset state */
|
||||
dataset.testUint8Var.value = 128;
|
||||
}
|
||||
else if(dataset.testUint8Var.value > 200) {
|
||||
if(not resetAfterChange) {
|
||||
/* This will trigger an update notification to the controller */
|
||||
dataset.testUint8Var.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
/* Decrement by 30 automatically. This will prevent any additional notifications. */
|
||||
dataset.testUint8Var.value -= 30;
|
||||
}
|
||||
}
|
||||
/* If the value is greater than 0, it will be decremented in a linear way */
|
||||
else if(dataset.testUint8Var.value > 128) {
|
||||
size_t sizeToDecrement = 0;
|
||||
if(dataset.testUint8Var.value > 128 + 30) {
|
||||
sizeToDecrement = 30;
|
||||
}
|
||||
else {
|
||||
sizeToDecrement = dataset.testUint8Var.value - 128;
|
||||
resetAfterChange = false;
|
||||
}
|
||||
dataset.testUint8Var.value -= sizeToDecrement;
|
||||
}
|
||||
else if(dataset.testUint8Var.value < 50) {
|
||||
if(not resetAfterChange) {
|
||||
/* This will trigger an update snapshot to the controller */
|
||||
dataset.testUint8Var.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
}
|
||||
else {
|
||||
/* Increment by 30 automatically. */
|
||||
dataset.testUint8Var.value += 30;
|
||||
}
|
||||
}
|
||||
/* Increment in linear way */
|
||||
else if(dataset.testUint8Var.value < 128) {
|
||||
size_t sizeToIncrement = 0;
|
||||
if(dataset.testUint8Var.value < 128 - 20) {
|
||||
sizeToIncrement = 20;
|
||||
}
|
||||
else {
|
||||
sizeToIncrement = 128 - dataset.testUint8Var.value;
|
||||
resetAfterChange = false;
|
||||
}
|
||||
dataset.testUint8Var.value += sizeToIncrement;
|
||||
}
|
||||
|
||||
/* TODO: Same for vector */
|
||||
float vectorMean = (dataset.testFloat3Vec.value[0] + dataset.testFloat3Vec.value[1] +
|
||||
dataset.testFloat3Vec.value[2]) / 3.0;
|
||||
|
||||
/* Lambda (private local function) */
|
||||
auto sizeToAdd = [](bool tooHigh, float currentVal) {
|
||||
if(tooHigh) {
|
||||
if(currentVal - 20.0 > 10.0) {
|
||||
return -10.0;
|
||||
}
|
||||
else {
|
||||
return 20.0 - currentVal;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(std::abs(currentVal + 20.0) > 10.0) {
|
||||
return 10.0;
|
||||
}
|
||||
else {
|
||||
return -20.0 - currentVal;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if(vectorMean > 20.0 and std::abs(vectorMean - 20.0) > 1.0) {
|
||||
if(not resetAfterChange) {
|
||||
dataset.testFloat3Vec.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
}
|
||||
else {
|
||||
float sizeToDecrementVal0 = 0;
|
||||
float sizeToDecrementVal1 = 0;
|
||||
float sizeToDecrementVal2 = 0;
|
||||
|
||||
sizeToDecrementVal0 = sizeToAdd(true, dataset.testFloat3Vec.value[0]);
|
||||
sizeToDecrementVal1 = sizeToAdd(true, dataset.testFloat3Vec.value[1]);
|
||||
sizeToDecrementVal2 = sizeToAdd(true, dataset.testFloat3Vec.value[2]);
|
||||
|
||||
dataset.testFloat3Vec.value[0] += sizeToDecrementVal0;
|
||||
dataset.testFloat3Vec.value[1] += sizeToDecrementVal1;
|
||||
dataset.testFloat3Vec.value[2] += sizeToDecrementVal2;
|
||||
}
|
||||
}
|
||||
else if (vectorMean < -20.0 and std::abs(vectorMean + 20.0) < 1.0) {
|
||||
if(not resetAfterChange) {
|
||||
dataset.testFloat3Vec.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
}
|
||||
else {
|
||||
float sizeToDecrementVal0 = 0;
|
||||
float sizeToDecrementVal1 = 0;
|
||||
float sizeToDecrementVal2 = 0;
|
||||
|
||||
sizeToDecrementVal0 = sizeToAdd(false, dataset.testFloat3Vec.value[0]);
|
||||
sizeToDecrementVal1 = sizeToAdd(false, dataset.testFloat3Vec.value[1]);
|
||||
sizeToDecrementVal2 = sizeToAdd(false, dataset.testFloat3Vec.value[2]);
|
||||
|
||||
dataset.testFloat3Vec.value[0] += sizeToDecrementVal0;
|
||||
dataset.testFloat3Vec.value[1] += sizeToDecrementVal1;
|
||||
dataset.testFloat3Vec.value[2] += sizeToDecrementVal2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(resetAfterChange) {
|
||||
resetAfterChange = false;
|
||||
}
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::interpretingTestReply0(DeviceCommandId_t id, const uint8_t* packet) {
|
||||
CommandMessage commandMessage;
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice::interpretingTestReply0: Generating step and finish reply" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice::interpretingTestReply0: Generating step and finish reply\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
MessageQueueId_t commander = getCommanderQueueId(id);
|
||||
/* Generate one step reply and the finish reply */
|
||||
actionHelper.step(1, commander, id);
|
||||
actionHelper.finish(true, commander, id);
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::interpretingTestReply1(DeviceCommandId_t id,
|
||||
const uint8_t* packet) {
|
||||
CommandMessage directReplyMessage;
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::interpretingReply1: Setting data reply" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::interpretingReply1: Setting data reply\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
MessageQueueId_t commander = getCommanderQueueId(id);
|
||||
/* Send reply with data */
|
||||
ReturnValue_t result = actionHelper.reportData(commander, id, packet,
|
||||
testdevice::TEST_COMMAND_1_SIZE, false);
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TestDevice" << deviceIdx << "::interpretingReply1: Sending data "
|
||||