From b827bd8370ad22f6910e1979bfd2f150fc239321 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 10:22:05 +0200 Subject: [PATCH 1/2] update HasReturnvaluesIF 1. Add new retval namespace which contains OK and FAIL returnvalue 2. Also contains makeCode constexpr function 3. Mark HasReturnvaluesIF::makeReturnCode deprecated This prevents from having to implement an interface just to use a shorter version of the general returnvalues. A namespace is better suited for this I think --- src/fsfw/returnvalues/HasReturnvaluesIF.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index eec80228..4d59c26b 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -10,11 +10,21 @@ #define MAKE_RETURN_CODE(number) ((INTERFACE_ID << 8) + (number)) typedef uint16_t ReturnValue_t; +namespace retval { +static constexpr ReturnValue_t OK = 0; +static constexpr ReturnValue_t FAILED = 1; + +static constexpr ReturnValue_t makeCode(uint8_t classId, uint8_t number) { + return (static_cast(classId) << 8) + number; +} +} // namespace retval + class HasReturnvaluesIF { public: - static const ReturnValue_t RETURN_OK = 0; - static const ReturnValue_t RETURN_FAILED = 1; - virtual ~HasReturnvaluesIF() {} + static const ReturnValue_t RETURN_OK = retval::OK; + static const ReturnValue_t RETURN_FAILED = retval::FAILED; + + virtual ~HasReturnvaluesIF() = default; /** * It is discouraged to use the input parameters 0,0 and 0,1 as this @@ -23,8 +33,9 @@ class HasReturnvaluesIF { * @param number * @return */ - static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) { - return (static_cast(classId) << 8) + number; + [[deprecated("Use retval::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode( + uint8_t classId, uint8_t number) { + return retval::makeCode(classId, number); } }; From 88ebb67c8db9c9cc14958216f2443ce989a3a0dc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 10:27:44 +0200 Subject: [PATCH 2/2] fix deprecation warnings --- src/fsfw/cfdp/definitions.h | 18 +++++++++--------- src/fsfw/osal/common/TcpTmTcServer.h | 2 +- src/fsfw/tasks/FixedTimeslotTaskIF.h | 2 +- src/fsfw_tests/internal/osal/testMq.cpp | 10 ++++------ .../serialize/IntTestSerialization.cpp | 15 +++++++-------- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index eb21f5bf..93d15bcb 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -16,27 +16,27 @@ static constexpr uint8_t VERSION_BITS = 0b00100000; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; static constexpr ReturnValue_t INVALID_TLV_TYPE = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 1); + retval::makeCode(CFDP_CLASS_ID, 1); static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELDS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 2); + retval::makeCode(CFDP_CLASS_ID, 2); static constexpr ReturnValue_t INVALID_PDU_DATAFIELD_LEN = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 3); + retval::makeCode(CFDP_CLASS_ID, 3); static constexpr ReturnValue_t INVALID_ACK_DIRECTIVE_FIELDS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 4); + retval::makeCode(CFDP_CLASS_ID, 4); //! Can not parse options. This can also occur because there are options //! available but the user did not pass a valid options array static constexpr ReturnValue_t METADATA_CANT_PARSE_OPTIONS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 5); + retval::makeCode(CFDP_CLASS_ID, 5); static constexpr ReturnValue_t NAK_CANT_PARSE_OPTIONS = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 6); + retval::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FINISHED_CANT_PARSE_FS_RESPONSES = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 6); + retval::makeCode(CFDP_CLASS_ID, 6); static constexpr ReturnValue_t FILESTORE_REQUIRES_SECOND_FILE = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 8); + retval::makeCode(CFDP_CLASS_ID, 8); //! Can not parse filestore response because user did not pass a valid instance //! or remaining size is invalid static constexpr ReturnValue_t FILESTORE_RESPONSE_CANT_PARSE_FS_MESSAGE = - HasReturnvaluesIF::makeReturnCode(CFDP_CLASS_ID, 9); + retval::makeCode(CFDP_CLASS_ID, 9); //! Checksum types according to the SANA Checksum Types registry //! https://sanaregistry.org/r/checksum_identifiers/ diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index faf6e0a1..ae3fce39 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -108,7 +108,7 @@ class TcpTmTcServer : public SystemObject, public TcpIpBase, public ExecutableOb StorageManagerIF* tmStore = nullptr; private: - static constexpr ReturnValue_t CONN_BROKEN = HasReturnvaluesIF::makeReturnCode(1, 0); + static constexpr ReturnValue_t CONN_BROKEN = retval::makeCode(1, 0); //! TMTC bridge is cached. object_id_t tmtcBridgeId = objects::NO_OBJECT; TcpTmTcBridge* tmtcBridge = nullptr; diff --git a/src/fsfw/tasks/FixedTimeslotTaskIF.h b/src/fsfw/tasks/FixedTimeslotTaskIF.h index 3f5e30d8..6a552d81 100644 --- a/src/fsfw/tasks/FixedTimeslotTaskIF.h +++ b/src/fsfw/tasks/FixedTimeslotTaskIF.h @@ -15,7 +15,7 @@ class FixedTimeslotTaskIF : public PeriodicTaskIF { ~FixedTimeslotTaskIF() override = default; static constexpr ReturnValue_t SLOT_LIST_EMPTY = - HasReturnvaluesIF::makeReturnCode(CLASS_ID::FIXED_SLOT_TASK_IF, 0); + retval::makeCode(CLASS_ID::FIXED_SLOT_TASK_IF, 0); /** * Add an object with a slot time and the execution step to the task. diff --git a/src/fsfw_tests/internal/osal/testMq.cpp b/src/fsfw_tests/internal/osal/testMq.cpp index 0f78dbb9..30b46d63 100644 --- a/src/fsfw_tests/internal/osal/testMq.cpp +++ b/src/fsfw_tests/internal/osal/testMq.cpp @@ -7,8 +7,6 @@ #include "fsfw_tests/internal/UnittDefinitions.h" -using retval = HasReturnvaluesIF; - void testmq::testMq() { std::string id = "[testMq]"; MessageQueueIF* testSenderMq = QueueFactory::instance()->createMessageQueue(1); @@ -22,22 +20,22 @@ void testmq::testMq() { testSenderMq->setDefaultDestination(testReceiverMqId); auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { unitt::put_error(id); } MessageQueueMessage recvMessage; result = testReceiverMq->receiveMessage(&recvMessage); - if (result != retval::RETURN_OK or recvMessage.getData()[0] != 42) { + if (result != retval::OK or recvMessage.getData()[0] != 42) { unitt::put_error(id); } result = testSenderMq->sendMessage(testReceiverMqId, &testMessage); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { unitt::put_error(id); } MessageQueueId_t senderId = 0; result = testReceiverMq->receiveMessage(&recvMessage, &senderId); - if (result != retval::RETURN_OK or recvMessage.getData()[0] != 42) { + if (result != retval::OK or recvMessage.getData()[0] != 42) { unitt::put_error(id); } if (senderId != testSenderMqId) { diff --git a/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp b/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp index 8e1f2bdd..1e2a385c 100644 --- a/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp +++ b/src/fsfw_tests/internal/serialize/IntTestSerialization.cpp @@ -8,24 +8,23 @@ #include "fsfw_tests/internal/UnittDefinitions.h" -using retval = HasReturnvaluesIF; std::array testserialize::test_array = {0}; ReturnValue_t testserialize::test_serialization() { // Here, we test all serialization tools. First test basic cases. ReturnValue_t result = test_endianness_tools(); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { return result; } result = test_autoserialization(); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { return result; } result = test_serial_buffer_adapter(); - if (result != retval::RETURN_OK) { + if (result != retval::OK) { return result; } - return retval::RETURN_OK; + return retval::OK; } ReturnValue_t testserialize::test_endianness_tools() { @@ -49,7 +48,7 @@ ReturnValue_t testserialize::test_endianness_tools() { if (test_array[0] != 0 and test_array[1] != 1) { return unitt::put_error(id); } - return retval::RETURN_OK; + return retval::OK; } ReturnValue_t testserialize::test_autoserialization() { @@ -153,7 +152,7 @@ ReturnValue_t testserialize::test_autoserialization() { } // Check overflow - return retval::RETURN_OK; + return retval::OK; } // TODO: Also test for constant buffers. @@ -206,5 +205,5 @@ ReturnValue_t testserialize::test_serial_buffer_adapter() { if (testUint16 != 16) { return unitt::put_error(id); } - return retval::RETURN_OK; + return retval::OK; }