lot of refactoring

This commit is contained in:
Robin Müller 2022-05-12 16:53:34 +02:00
parent 9a4c7589cc
commit c4c340fde1
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
3 changed files with 99 additions and 103 deletions

View File

@ -6,6 +6,7 @@
#include <fsfw/tmtcservices/TmTcMessage.h> #include <fsfw/tmtcservices/TmTcMessage.h>
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
#include "fsfw/returnvalues/FwClassIds.h"
/** /**
* @brief: PUS-Service 11 - Telecommand scheduling. * @brief: PUS-Service 11 - Telecommand scheduling.
@ -34,8 +35,12 @@
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
class Service11TelecommandScheduling final : public PusServiceBase { class Service11TelecommandScheduling final : public PusServiceBase {
public: public:
static constexpr uint8_t CLASS_ID = CLASS_ID::PUS_SERVICE_11;
static constexpr ReturnValue_t INVALID_TYPE_TIME_WINDOW =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
// The types of PUS-11 subservices // The types of PUS-11 subservices
enum Subservice { enum Subservice : uint8_t {
ENABLE_SCHEDULING = 1, ENABLE_SCHEDULING = 1,
DISABLE_SCHEDULING = 2, DISABLE_SCHEDULING = 2,
RESET_SCHEDULING = 3, RESET_SCHEDULING = 3,
@ -103,31 +108,31 @@ class Service11TelecommandScheduling final : public PusServiceBase {
* @brief Logic to be performed on an incoming TC[11,4]. * @brief Logic to be performed on an incoming TC[11,4].
* @return RETURN_OK if successful * @return RETURN_OK if successful
*/ */
ReturnValue_t doInsertActivity(void); ReturnValue_t doInsertActivity(const uint8_t* data, size_t size);
/** /**
* @brief Logic to be performed on an incoming TC[11,5]. * @brief Logic to be performed on an incoming TC[11,5].
* @return RETURN_OK if successful * @return RETURN_OK if successful
*/ */
ReturnValue_t doDeleteActivity(void); ReturnValue_t doDeleteActivity(const uint8_t* data, size_t size);
/** /**
* @brief Logic to be performed on an incoming TC[11,6]. * @brief Logic to be performed on an incoming TC[11,6].
* @return RETURN_OK if successful * @return RETURN_OK if successful
*/ */
ReturnValue_t doFilterDeleteActivity(void); ReturnValue_t doFilterDeleteActivity(const uint8_t* data, size_t size);
/** /**
* @brief Logic to be performed on an incoming TC[11,7]. * @brief Logic to be performed on an incoming TC[11,7].
* @return RETURN_OK if successful * @return RETURN_OK if successful
*/ */
ReturnValue_t doTimeshiftActivity(void); ReturnValue_t doTimeshiftActivity(const uint8_t* data, size_t size);
/** /**
* @brief Logic to be performed on an incoming TC[11,8]. * @brief Logic to be performed on an incoming TC[11,8].
* @return RETURN_OK if successful * @return RETURN_OK if successful
*/ */
ReturnValue_t doFilterTimeshiftActivity(void); ReturnValue_t doFilterTimeshiftActivity(const uint8_t* data, size_t size);
/** /**
* @brief Deserializes a generic type from a payload buffer by using the FSFW * @brief Deserializes a generic type from a payload buffer by using the FSFW
@ -158,7 +163,7 @@ class Service11TelecommandScheduling final : public PusServiceBase {
* @param [out] requestId Request ID * @param [out] requestId Request ID
* @return RETURN_OK if successful * @return RETURN_OK if successful
*/ */
ReturnValue_t getRequestIdFromData(const uint8_t* data, size_t& dataSize, uint64_t& requestId); ReturnValue_t getRequestIdFromData(const uint8_t*& data, size_t& dataSize, uint64_t& requestId);
/** /**
* @brief Builds the Request ID from its three elements. * @brief Builds the Request ID from its three elements.
@ -177,9 +182,10 @@ class Service11TelecommandScheduling final : public PusServiceBase {
* @param [out] itEnd End of filter range * @param [out] itEnd End of filter range
* @return RETURN_OK if successful * @return RETURN_OK if successful
*/ */
ReturnValue_t getMapFilterFromData(const uint8_t* data, size_t dataSize, TcMapIter& itBegin, ReturnValue_t getMapFilterFromData(const uint8_t*& data, size_t& size, TcMapIter& itBegin,
TcMapIter& itEnd); TcMapIter& itEnd);
ReturnValue_t handleInvalidData(const char* ctx);
/** /**
* @brief Prints content of multimap. Use for simple debugging only. * @brief Prints content of multimap. Use for simple debugging only.
*/ */

View File

@ -6,6 +6,8 @@
#include <cstddef> #include <cstddef>
static constexpr auto DEF_END = SerializeIF::Endianness::BIG;
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline Service11TelecommandScheduling<MAX_NUM_TCS>::Service11TelecommandScheduling( inline Service11TelecommandScheduling<MAX_NUM_TCS>::Service11TelecommandScheduling(
object_id_t objectId, uint16_t apid, uint8_t serviceId, AcceptsTelecommandsIF *tcRecipient, object_id_t objectId, uint16_t apid, uint8_t serviceId, AcceptsTelecommandsIF *tcRecipient,
@ -28,17 +30,23 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::handleRequest(
sif::printInfo("PUS11::handleRequest: Handling request %d\n", subservice); sif::printInfo("PUS11::handleRequest: Handling request %d\n", subservice);
#endif #endif
} }
// Get de-serialized Timestamp
const uint8_t *data = currentPacket.getApplicationData();
size_t size = currentPacket.getApplicationDataSize();
if (data == nullptr) {
return handleInvalidData("handleRequest");
}
switch (subservice) { switch (subservice) {
case Subservice::INSERT_ACTIVITY: case Subservice::INSERT_ACTIVITY:
return doInsertActivity(); return doInsertActivity(data, size);
case Subservice::DELETE_ACTIVITY: case Subservice::DELETE_ACTIVITY:
return doDeleteActivity(); return doDeleteActivity(data, size);
case Subservice::FILTER_DELETE_ACTIVITY: case Subservice::FILTER_DELETE_ACTIVITY:
return doFilterDeleteActivity(); return doFilterDeleteActivity(data, size);
case Subservice::TIMESHIFT_ACTIVITY: case Subservice::TIMESHIFT_ACTIVITY:
return doTimeshiftActivity(); return doTimeshiftActivity(data, size);
case Subservice::FILTER_TIMESHIFT_ACTIVITY: case Subservice::FILTER_TIMESHIFT_ACTIVITY:
return doFilterTimeshiftActivity(); return doFilterTimeshiftActivity(data, size);
default: default:
break; break;
} }
@ -105,17 +113,15 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::initialize() {
} }
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivity(void) { inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivity(
// Get de-serialized Timestamp const uint8_t *data, size_t size) {
const uint8_t *data = currentPacket.getApplicationData();
size_t dataSize = currentPacket.getApplicationDataSize();
uint32_t timestamp = 0; uint32_t timestamp = 0;
if (deserializeViaFsfwInterface<uint32_t>(timestamp, data, dataSize) != RETURN_OK) { const uint8_t *initData = data;
return RETURN_FAILED; size_t initSz = size;
ReturnValue_t result = SerializeAdapter::deSerialize(&timestamp, &data, &size, DEF_END);
if (result != RETURN_OK) {
return result;
} }
data += sizeof(uint32_t); // move ptr past timestamp (for later)
dataSize -= sizeof(uint32_t); // and reduce size accordingly
// Insert possible if sched. time is above margin // Insert possible if sched. time is above margin
// (See requirement for Time margin) // (See requirement for Time margin)
@ -135,8 +141,8 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivi
} }
// store currentPacket and receive the store address // store currentPacket and receive the store address
store_address_t addr; store_address_t addr{};
if (tcStore->addData(&addr, data, dataSize) != RETURN_OK || if (tcStore->addData(&addr, initData, initSz) != RETURN_OK ||
addr.raw == storeId::INVALID_STORE_ADDRESS) { addr.raw == storeId::INVALID_STORE_ADDRESS) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Service11TelecommandScheduling::doInsertActivity: Adding data to TC Store failed" sif::error << "Service11TelecommandScheduling::doInsertActivity: Adding data to TC Store failed"
@ -172,14 +178,13 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivi
} }
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doDeleteActivity(void) { inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doDeleteActivity(
const uint8_t *data = currentPacket.getApplicationData(); const uint8_t *data, size_t size) {
size_t dataSize = currentPacket.getApplicationDataSize();
// Get request ID // Get request ID
uint64_t requestId; uint64_t requestId;
if (getRequestIdFromData(data, dataSize, requestId) != RETURN_OK) { ReturnValue_t result = getRequestIdFromData(data, size, requestId);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
// DEBUG // DEBUG
@ -240,16 +245,15 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doDeleteActivi
} }
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doFilterDeleteActivity(void) { inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doFilterDeleteActivity(
const uint8_t *data = currentPacket.getApplicationData(); const uint8_t *data, size_t size) {
size_t dataSize = currentPacket.getApplicationDataSize();
TcMapIter itBegin; TcMapIter itBegin;
TcMapIter itEnd; TcMapIter itEnd;
ReturnValue_t result = getMapFilterFromData(data, size, itBegin, itEnd);
// get the filter window as map range via dedicated method // get the filter window as map range via dedicated method
if (getMapFilterFromData(data, dataSize, itBegin, itEnd) != RETURN_OK) { if (result != RETURN_OK) {
return RETURN_FAILED; return result;
} }
int deletedTCs = 0; int deletedTCs = 0;
@ -290,26 +294,22 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doFilterDelete
} }
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doTimeshiftActivity(void) { inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doTimeshiftActivity(
const uint8_t *data = currentPacket.getApplicationData(); const uint8_t *data, size_t size) {
size_t dataSize = currentPacket.getApplicationDataSize();
// Get relative time // Get relative time
uint32_t relativeTime = 0; uint32_t relativeTime = 0;
if (deserializeViaFsfwInterface<uint32_t>(relativeTime, data, dataSize) != RETURN_OK) { ReturnValue_t result = SerializeAdapter::deSerialize(&relativeTime, &data, &size, DEF_END);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
if (relativeTime == 0) { if (relativeTime == 0) {
return RETURN_FAILED; return RETURN_FAILED;
} }
// TODO further check sanity of the relative time? // TODO further check sanity of the relative time?
data += sizeof(uint32_t);
dataSize -= sizeof(uint32_t);
// Get request ID // Get request ID
uint64_t requestId; uint64_t requestId;
if (getRequestIdFromData(data, dataSize, requestId) != RETURN_OK) { if (getRequestIdFromData(data, size, requestId) != RETURN_OK) {
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -371,26 +371,24 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doTimeshiftAct
} }
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doFilterTimeshiftActivity(void) { inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doFilterTimeshiftActivity(
const uint8_t *data = currentPacket.getApplicationData(); const uint8_t *data, size_t size) {
uint32_t dataSize = currentPacket.getApplicationDataSize();
// Get relative time // Get relative time
uint32_t relativeTime = 0; uint32_t relativeTime = 0;
if (deserializeViaFsfwInterface<uint32_t>(relativeTime, data, dataSize) != RETURN_OK) { ReturnValue_t result = SerializeAdapter::deSerialize(&relativeTime, &data, &size, DEF_END);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
if (relativeTime == 0) { if (relativeTime == 0) {
return RETURN_FAILED; return RETURN_FAILED;
} }
data += sizeof(uint32_t);
dataSize -= sizeof(uint32_t);
// Do time window // Do time window
TcMapIter itBegin; TcMapIter itBegin;
TcMapIter itEnd; TcMapIter itEnd;
if (getMapFilterFromData(data, dataSize, itBegin, itEnd) != RETURN_OK) { result = getMapFilterFromData(data, size, itBegin, itEnd);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
int shiftedItemsCount = 0; int shiftedItemsCount = 0;
@ -438,27 +436,23 @@ inline uint64_t Service11TelecommandScheduling<MAX_NUM_TCS>::getRequestIdFromDat
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getRequestIdFromData( inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getRequestIdFromData(
const uint8_t *data, size_t &dataSize, uint64_t &requestId) { const uint8_t *&data, size_t &dataSize, uint64_t &requestId) {
uint32_t srcId = 0; uint32_t srcId = 0;
uint16_t apid = 0; uint16_t apid = 0;
uint16_t ssc = 0; uint16_t ssc = 0;
if (deserializeViaFsfwInterface<uint32_t>(srcId, data, dataSize) != RETURN_OK) { ReturnValue_t result = SerializeAdapter::deSerialize(&srcId, &data, &dataSize, DEF_END);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
result = SerializeAdapter::deSerialize(&apid, &data, &dataSize, DEF_END);
data += sizeof(uint32_t); if (result != RETURN_OK) {
dataSize -= sizeof(uint32_t); return result;
if (deserializeViaFsfwInterface<uint16_t>(apid, data, dataSize) != RETURN_OK) {
return RETURN_FAILED;
} }
result = SerializeAdapter::deSerialize(&ssc, &data, &dataSize, DEF_END);
data += sizeof(uint32_t); if (result != RETURN_OK) {
dataSize -= sizeof(uint32_t); return result;
if (deserializeViaFsfwInterface<uint16_t>(ssc, data, dataSize) != RETURN_OK) {
return RETURN_FAILED;
} }
requestId = buildRequestId(srcId, apid, ssc); requestId = buildRequestId(srcId, apid, ssc);
return RETURN_OK; return RETURN_OK;
@ -477,16 +471,17 @@ inline uint64_t Service11TelecommandScheduling<MAX_NUM_TCS>::buildRequestId(uint
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFromData( inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFromData(
const uint8_t *data, size_t dataSize, TcMapIter &itBegin, TcMapIter &itEnd) { const uint8_t *&data, size_t &dataSize, TcMapIter &itBegin, TcMapIter &itEnd) {
// get filter type first // get filter type first
uint32_t typeRaw; uint32_t typeRaw = 0;
if (deserializeViaFsfwInterface(typeRaw, data, dataSize) != RETURN_OK) { ReturnValue_t result = SerializeAdapter::deSerialize(&typeRaw, &data, &dataSize, DEF_END);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
// can be modified as the uint8_t pointer is passed by value (copy of ptr is modified)
data += sizeof(uint32_t);
dataSize -= sizeof(uint32_t);
if (typeRaw > 3) {
return INVALID_TYPE_TIME_WINDOW;
}
TypeOfTimeWindow type = static_cast<TypeOfTimeWindow>(typeRaw); TypeOfTimeWindow type = static_cast<TypeOfTimeWindow>(typeRaw);
// we now have the type of delete activity - so now we set the range to delete, // we now have the type of delete activity - so now we set the range to delete,
@ -501,9 +496,10 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
} }
case TypeOfTimeWindow::FROM_TIMETAG: { case TypeOfTimeWindow::FROM_TIMETAG: {
uint32_t fromTimestamp; uint32_t fromTimestamp = 0;
if (deserializeViaFsfwInterface<uint32_t>(fromTimestamp, data, dataSize) != RETURN_OK) { result = SerializeAdapter::deSerialize(&fromTimestamp, &data, &dataSize, DEF_END);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
itBegin = telecommandMap.begin(); itBegin = telecommandMap.begin();
@ -517,8 +513,9 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
case TypeOfTimeWindow::TO_TIMETAG: { case TypeOfTimeWindow::TO_TIMETAG: {
uint32_t toTimestamp; uint32_t toTimestamp;
if (deserializeViaFsfwInterface<uint32_t>(toTimestamp, data, dataSize) != RETURN_OK) { result = SerializeAdapter::deSerialize(&toTimestamp, &data, &dataSize, DEF_END);
return RETURN_FAILED; if (result != RETURN_OK) {
return result;
} }
itBegin = telecommandMap.begin(); itBegin = telecommandMap.begin();
itEnd = telecommandMap.begin(); itEnd = telecommandMap.begin();
@ -532,14 +529,15 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
uint32_t fromTimestamp; uint32_t fromTimestamp;
uint32_t toTimestamp; uint32_t toTimestamp;
if (deserializeViaFsfwInterface<uint32_t>(fromTimestamp, data, dataSize) != RETURN_OK) { result = SerializeAdapter::deSerialize(&fromTimestamp, &data, &dataSize,
return RETURN_FAILED; SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
return result;
} }
data += sizeof(uint32_t); result = SerializeAdapter::deSerialize(&toTimestamp, &data, &dataSize,
dataSize -= sizeof(uint32_t); SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
if (deserializeViaFsfwInterface<uint32_t>(toTimestamp, data, dataSize) != RETURN_OK) { return result;
return RETURN_FAILED;
} }
itBegin = telecommandMap.begin(); itBegin = telecommandMap.begin();
itEnd = telecommandMap.begin(); itEnd = telecommandMap.begin();
@ -568,25 +566,16 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
} }
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>
template <typename T> inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::handleInvalidData(
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::deserializeViaFsfwInterface( const char *ctx) {
T &output, const uint8_t *buf, size_t bufsize) {
if (buf == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Service11TelecommandScheduling::deserializeViaFsfwInterface: " sif::warning << "Service11TelecommandScheduling:: " << ctx << ": Invalid buffer" << std::endl;
"Invalid buffer"
<< std::endl;
#else #else
sif::printWarning( sif::printWarning("Service11TelecommandScheduling::%s: Invalid buffer\n", ctx);
"Service11TelecommandScheduling::deserializeViaFsfwInterface: "
"Invalid buffer\n");
#endif #endif
#endif #endif
return RETURN_FAILED; return RETURN_FAILED;
}
return SerializeAdapter::deSerialize<T>(&output, &buf, &bufsize, SerializeIF::Endianness::BIG);
} }
template <size_t MAX_NUM_TCS> template <size_t MAX_NUM_TCS>

View File

@ -72,6 +72,7 @@ enum : uint8_t {
DLE_ENCODER, // DLEE DLE_ENCODER, // DLEE
PUS_SERVICE_3, // PUS3 PUS_SERVICE_3, // PUS3
PUS_SERVICE_9, // PUS9 PUS_SERVICE_9, // PUS9
PUS_SERVICE_11, // PUS11
FILE_SYSTEM, // FILS FILE_SYSTEM, // FILS
LINUX_OSAL, // UXOS LINUX_OSAL, // UXOS
HAL_SPI, // HSPI HAL_SPI, // HSPI