Update from upstream #94

Merged
meierj merged 12 commits from mueller/update-from-upstream into develop 2022-05-25 15:24:19 +02:00
4 changed files with 79 additions and 21 deletions
Showing only changes of commit e60a665de4 - Show all commits

View File

@ -27,6 +27,7 @@ enum : uint8_t {
PUS_SERVICE_6 = 86,
PUS_SERVICE_8 = 88,
PUS_SERVICE_9 = 89,
PUS_SERVICE_11 = 91,
PUS_SERVICE_17 = 97,
PUS_SERVICE_23 = 103,
MGM_LIS3MDL = 106,

View File

@ -44,6 +44,12 @@ class Service11TelecommandScheduling final : public PusServiceBase {
static constexpr ReturnValue_t INVALID_RELATIVE_TIME =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_11;
//! [EXPORT] : [COMMENT] Deletion of a TC from the map failed.
//! P1: First 32 bit of request ID, P2. Last 32 bit of Request ID
static constexpr Event TC_DELETION_FAILED = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM);
// The types of PUS-11 subservices
enum Subservice : uint8_t {
ENABLE_SCHEDULING = 1,
@ -75,6 +81,9 @@ class Service11TelecommandScheduling final : public PusServiceBase {
~Service11TelecommandScheduling() override;
void enableExpiredTcDeletion();
void disableExpiredTcDeletion();
/** PusServiceBase overrides */
ReturnValue_t handleRequest(uint8_t subservice) override;
ReturnValue_t performService() override;
@ -92,6 +101,11 @@ class Service11TelecommandScheduling final : public PusServiceBase {
// minimum release time offset to insert into schedule
const uint16_t RELEASE_TIME_MARGIN_SECONDS = 5;
/**
* By default, the scheduling will be disabled. This is a standard requirement
*/
bool schedulingEnabled = false;
bool deleteExpiredTcWhenDisabled = true;
bool debugMode = false;
StorageManagerIF* tcStore = nullptr;
AcceptsTelecommandsIF* tcRecipient = nullptr;
@ -106,6 +120,7 @@ class Service11TelecommandScheduling final : public PusServiceBase {
TelecommandMap telecommandMap;
ReturnValue_t handleResetCommand();
/**
* @brief Logic to be performed on an incoming TC[11,4].
* @return RETURN_OK if successful

View File

@ -38,6 +38,17 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::handleRequest(
return handleInvalidData("handleRequest");
}
switch (subservice) {
case Subservice::ENABLE_SCHEDULING: {
schedulingEnabled = true;
break;
}
case Subservice::DISABLE_SCHEDULING: {
schedulingEnabled = false;
break;
}
case Subservice::RESET_SCHEDULING: {
return handleResetCommand();
}
case Subservice::INSERT_ACTIVITY:
return doInsertActivity(data, size);
case Subservice::DELETE_ACTIVITY:
@ -49,25 +60,26 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::handleRequest(
case Subservice::FILTER_TIMESHIFT_ACTIVITY:
return doFilterTimeshiftActivity(data, size);
default:
break;
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
}
return HasReturnvaluesIF::RETURN_FAILED;
return RETURN_OK;
}
template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::performService() {
// DEBUG
// DebugPrintMultimapContent();
if (not schedulingEnabled) {
return RETURN_OK;
}
// get current time as UNIX timestamp
timeval tNow = {};
Clock::getClock_timeval(&tNow);
// TODO: Optionally limit the max number of released TCs per cycle?
// NOTE: The iterator is increased in the loop here. Increasing the iterator as for-loop arg
// does not work in this case as we are deleting the current element here.
for (auto it = telecommandMap.begin(); it != telecommandMap.end();) {
if (it->first <= tNow.tv_sec) {
if (schedulingEnabled) {
// release tc
TmTcMessage releaseMsg(it->second.storeAddr);
auto sendRet = this->requestQueue->sendMessage(recipientMsgQueueId, &releaseMsg, false);
@ -75,9 +87,6 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::performService
if (sendRet != HasReturnvaluesIF::RETURN_OK) {
return sendRet;
}
telecommandMap.erase(it++);
if (debugMode) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Released TC & erased it from TC map" << std::endl;
@ -85,6 +94,9 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::performService
sif::printInfo("Released TC & erased it from TC map\n");
#endif
}
} else if (deleteExpiredTcWhenDisabled) {
telecommandMap.erase(it++);
}
continue;
}
it++;
@ -113,6 +125,26 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::initialize() {
return res;
}
template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::handleResetCommand() {
for (auto it = telecommandMap.begin(); it != telecommandMap.end(); it++) {
ReturnValue_t result = tcStore->deleteData(it->second.storeAddr);
if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
// This should not happen
sif::warning << "Service11TelecommandScheduling::handleRequestDeleting: Deletion failed"
<< std::endl;
#else
sif::printWarning("Service11TelecommandScheduling::handleRequestDeleting: Deletion failed\n");
#endif
triggerEvent(TC_DELETION_FAILED, (it->second.requestId >> 32) & 0xffffffff,
it->second.requestId & 0xffffffff);
}
}
telecommandMap.clear();
return RETURN_OK;
}
template <size_t MAX_NUM_TCS>
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivity(
const uint8_t *data, size_t size) {
@ -582,7 +614,7 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::handleInvalidD
template <size_t MAX_NUM_TCS>
inline void Service11TelecommandScheduling<MAX_NUM_TCS>::debugPrintMultimapContent() const {
for (const auto &dit : telecommandMap) {
for ([[maybe_unused]] const auto &dit : telecommandMap) {
#if FSFW_DISABLE_PRINTOUT == 0
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Service11TelecommandScheduling::debugPrintMultimapContent: Multimap Content"
@ -600,3 +632,13 @@ inline void Service11TelecommandScheduling<MAX_NUM_TCS>::debugPrintMultimapConte
#endif
}
}
template <size_t MAX_NUM_TCS>
inline void Service11TelecommandScheduling<MAX_NUM_TCS>::enableExpiredTcDeletion() {
deleteExpiredTcWhenDisabled = true;
}
template <size_t MAX_NUM_TCS>
inline void Service11TelecommandScheduling<MAX_NUM_TCS>::disableExpiredTcDeletion() {
deleteExpiredTcWhenDisabled = false;
}

View File

@ -1,7 +1,7 @@
#ifndef FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_
#define FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_
#include "../ipc/MessageQueueSenderIF.h"
#include "fsfw/ipc/MessageQueueSenderIF.h"
/**
* @brief This interface is implemented by classes that are sinks for
@ -20,7 +20,7 @@ class AcceptsTelecommandsIF {
/**
* @brief The virtual destructor as it is mandatory for C++ interfaces.
*/
virtual ~AcceptsTelecommandsIF() {}
virtual ~AcceptsTelecommandsIF() = default;
/**
* @brief Getter for the service id.
* @details Any receiving service (at least any PUS service) shall have a