Compare commits
8 Commits
511d07c0c7
...
33de15205b
Author | SHA1 | Date | |
---|---|---|---|
33de15205b | |||
4d353a1ad2 | |||
6006c97e48 | |||
6e17e45506 | |||
64537d442a | |||
78cf00315d | |||
245886c555 | |||
f84097543e |
@@ -68,7 +68,7 @@ ReturnValue_t FaultCounter::getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
parameterWrapper->set(faultCount);
|
||||
break;
|
||||
case ParameterIds::TIMEOUT:
|
||||
parameterWrapper->set(timer.timeout);
|
||||
parameterWrapper->set(timer.getTimeoutMs());
|
||||
break;
|
||||
default:
|
||||
return INVALID_IDENTIFIER_ID;
|
||||
|
@@ -7,14 +7,17 @@
|
||||
class MutexGuard {
|
||||
public:
|
||||
MutexGuard(MutexIF* mutex, MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::BLOCKING,
|
||||
uint32_t timeoutMs = 0)
|
||||
uint32_t timeoutMs = 0, const char* context = nullptr)
|
||||
: internalMutex(mutex) {
|
||||
if (context == nullptr) {
|
||||
context = "unknown";
|
||||
}
|
||||
if (mutex == nullptr) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "MutexGuard: Passed mutex is invalid!" << std::endl;
|
||||
sif::error << "MutexGuard::" << context << ": Passed mutex is invalid!" << std::endl;
|
||||
#else
|
||||
sif::printError("MutexGuard: Passed mutex is invalid!\n");
|
||||
sif::printError("MutexGuard::%s: Passed mutex is invalid!\n", context);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
return;
|
||||
@@ -23,11 +26,11 @@ class MutexGuard {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
if (result == MutexIF::MUTEX_TIMEOUT) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "MutexGuard: Lock of mutex failed with timeout of " << timeoutMs
|
||||
<< " milliseconds!" << std::endl;
|
||||
sif::error << "MutexGuard::" << context << ": Lock of mutex failed with timeout of "
|
||||
<< timeoutMs << " milliseconds!" << std::endl;
|
||||
#else
|
||||
sif::printError("MutexGuard: Lock of mutex failed with timeout of %lu milliseconds\n",
|
||||
timeoutMs);
|
||||
sif::printError("MutexGuard::%s: Lock of mutex failed with timeout of %lu milliseconds\n",
|
||||
context, timeoutMs);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
|
||||
} else if (result != returnvalue::OK) {
|
||||
|
@@ -16,9 +16,9 @@
|
||||
|
||||
#endif
|
||||
|
||||
TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId,
|
||||
object_id_t tcStoreId)
|
||||
: TmTcBridge("TCP TMTC Bridge", objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||
TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
uint32_t msgQueueDepth, object_id_t tmStoreId, object_id_t tcStoreId)
|
||||
: TmTcBridge("TCP TMTC Bridge", objectId, tcDestination, msgQueueDepth, tmStoreId, tcStoreId) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
// Connection is always up, TM is requested by connecting to server and receiving packets
|
||||
registerCommConnect();
|
||||
|
@@ -38,7 +38,7 @@ class TcpTmTcBridge : public TmTcBridge {
|
||||
* @param tmStoreId TM store object ID. It is recommended to the default object ID
|
||||
* @param tcStoreId TC store object ID. It is recommended to the default object ID
|
||||
*/
|
||||
TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination, uint32_t msgQueueDepth,
|
||||
object_id_t tmStoreId = objects::TM_STORE,
|
||||
object_id_t tcStoreId = objects::TC_STORE);
|
||||
virtual ~TcpTmTcBridge();
|
||||
|
@@ -20,9 +20,9 @@
|
||||
const std::string UdpTmTcBridge::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||
|
||||
UdpTmTcBridge::UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
const std::string &udpServerPort_, object_id_t tmStoreId,
|
||||
object_id_t tcStoreId)
|
||||
: TmTcBridge("UDP TMTC Bridge", objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||
uint32_t msgQueueDepth, const std::string &udpServerPort_,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId)
|
||||
: TmTcBridge("UDP TMTC Bridge", objectId, tcDestination, msgQueueDepth, tmStoreId, tcStoreId) {
|
||||
if (udpServerPort_.empty()) {
|
||||
udpServerPort = DEFAULT_SERVER_PORT;
|
||||
} else {
|
||||
|
@@ -29,7 +29,7 @@ class UdpTmTcBridge : public TmTcBridge, public TcpIpBase {
|
||||
/* The ports chosen here should not be used by any other process. */
|
||||
static const std::string DEFAULT_SERVER_PORT;
|
||||
|
||||
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination, uint32_t msgQueueDepth,
|
||||
const std::string& udpServerPort = "", object_id_t tmStoreId = objects::TM_STORE,
|
||||
object_id_t tcStoreId = objects::TC_STORE);
|
||||
~UdpTmTcBridge() override;
|
||||
|
@@ -79,11 +79,16 @@ ReturnValue_t Clock::getUptime(timeval* uptime) {
|
||||
// TODO This is not posix compatible and delivers only seconds precision
|
||||
// Linux specific file read but more precise.
|
||||
double uptimeSeconds;
|
||||
if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds) {
|
||||
std::ifstream ifile("/proc/uptime");
|
||||
if (ifile.bad()) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
if (ifile >> uptimeSeconds) {
|
||||
uptime->tv_sec = uptimeSeconds;
|
||||
uptime->tv_usec = uptimeSeconds * (double)1e6 - (uptime->tv_sec * 1e6);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
// Wait for new FSFW Clock function delivering seconds uptime.
|
||||
|
@@ -10,7 +10,7 @@ PoolManager::PoolManager(object_id_t setObjectId, const LocalPoolConfig& localPo
|
||||
PoolManager::~PoolManager() { MutexFactory::instance()->deleteMutex(mutex); }
|
||||
|
||||
ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* address) {
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeoutMs);
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeoutMs, LOCK_CTX);
|
||||
ReturnValue_t status = LocalPool::reserveSpace(size, address);
|
||||
return status;
|
||||
}
|
||||
@@ -22,12 +22,12 @@ ReturnValue_t PoolManager::deleteData(store_address_t storeId) {
|
||||
<< storeId.poolIndex << ". id is " << storeId.packetIndex << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeoutMs);
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeoutMs, LOCK_CTX);
|
||||
return LocalPool::deleteData(storeId);
|
||||
}
|
||||
|
||||
ReturnValue_t PoolManager::deleteData(uint8_t* buffer, size_t size, store_address_t* storeId) {
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||
MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeoutMs, LOCK_CTX);
|
||||
ReturnValue_t status = LocalPool::deleteData(buffer, size, storeId);
|
||||
return status;
|
||||
}
|
||||
|
@@ -56,6 +56,7 @@ class PoolManager : public LocalPool {
|
||||
protected:
|
||||
//! Default mutex timeout value to prevent permanent blocking.
|
||||
uint32_t mutexTimeoutMs = 20;
|
||||
static constexpr char LOCK_CTX[] = "PoolManager";
|
||||
|
||||
ReturnValue_t reserveSpace(size_t size, store_address_t* address) override;
|
||||
|
||||
|
@@ -283,7 +283,7 @@ ReturnValue_t Heater::getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
}
|
||||
switch (uniqueId) {
|
||||
case 0:
|
||||
parameterWrapper->set(heaterOnCountdown.timeout);
|
||||
parameterWrapper->set(heaterOnCountdown.getTimeoutMs());
|
||||
break;
|
||||
default:
|
||||
return INVALID_IDENTIFIER_ID;
|
||||
|
@@ -1,49 +1,62 @@
|
||||
#include "fsfw/timemanager/Countdown.h"
|
||||
|
||||
Countdown::Countdown(uint32_t initialTimeout, bool startImmediately) : timeout(initialTimeout) {
|
||||
#include "fsfw/globalfunctions/timevalOperations.h"
|
||||
|
||||
Countdown::Countdown(uint32_t initialTimeout, bool startImmediately) {
|
||||
if (startImmediately) {
|
||||
setTimeout(initialTimeout);
|
||||
} else {
|
||||
timeout = initialTimeout;
|
||||
timeout.tv_sec = initialTimeout / 1000;
|
||||
timeout.tv_usec = (initialTimeout % 1000) * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
Countdown::~Countdown() {}
|
||||
Countdown::~Countdown() = default;
|
||||
|
||||
ReturnValue_t Countdown::setTimeout(uint32_t milliseconds) {
|
||||
ReturnValue_t returnValue = Clock::getUptime(&startTime);
|
||||
timeout = milliseconds;
|
||||
return returnValue;
|
||||
timeout.tv_sec = milliseconds / 1000;
|
||||
timeout.tv_usec = (milliseconds % 1000) * 1000;
|
||||
return Clock::getClock_timeval(&startTime);
|
||||
}
|
||||
|
||||
bool Countdown::hasTimedOut() const {
|
||||
if (uint32_t(this->getCurrentTime() - startTime) >= timeout) {
|
||||
// Account for system clock going back in time.
|
||||
if (getCurrentTime() < startTime) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (getCurrentTime() - startTime >= timeout) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Countdown::isBusy() const { return !hasTimedOut(); }
|
||||
|
||||
ReturnValue_t Countdown::resetTimer() { return setTimeout(timeout); }
|
||||
ReturnValue_t Countdown::resetTimer() { return setTimeoutTv(timeout); }
|
||||
|
||||
void Countdown::timeOut() { startTime = this->getCurrentTime() - timeout; }
|
||||
|
||||
uint32_t Countdown::getRemainingMillis() const {
|
||||
// We fetch the time before the if-statement
|
||||
// to be sure that the return is in
|
||||
// range 0 <= number <= timeout
|
||||
uint32_t currentTime = this->getCurrentTime();
|
||||
if (this->hasTimedOut()) {
|
||||
return 0;
|
||||
} else {
|
||||
return (startTime + timeout) - currentTime;
|
||||
}
|
||||
timeval remainingMillisTv = (startTime + timeout) - this->getCurrentTime();
|
||||
return remainingMillisTv.tv_sec * 1000 + remainingMillisTv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
uint32_t Countdown::getCurrentTime() const {
|
||||
uint32_t currentTime;
|
||||
Clock::getUptime(¤tTime);
|
||||
uint32_t Countdown::timevalToMs(timeval &tv) { return tv.tv_sec * 1000 + tv.tv_usec / 1000; }
|
||||
|
||||
ReturnValue_t Countdown::setTimeoutTv(timeval tv) {
|
||||
timeout = tv;
|
||||
return Clock::getClock_timeval(&startTime);
|
||||
}
|
||||
|
||||
uint32_t Countdown::getTimeoutMs() const { return timeout.tv_sec * 1000 + timeout.tv_usec / 1000; }
|
||||
|
||||
timeval Countdown::getTimeout() const { return timeout; }
|
||||
|
||||
timeval Countdown::getCurrentTime() const {
|
||||
timeval currentTime{};
|
||||
Clock::getClock_timeval(¤tTime);
|
||||
return currentTime;
|
||||
}
|
||||
|
@@ -6,6 +6,10 @@
|
||||
/**
|
||||
*
|
||||
* Countdown keeps track of a timespan.
|
||||
* This class uses the system clock internally to achieve
|
||||
* a high resolution. This means that the API is only partially
|
||||
* resistant against time jumps. The user must take care to account
|
||||
* for time jumps in some from if this relevant.
|
||||
*
|
||||
* Countdown::resetTimer restarts the timer.
|
||||
* Countdown::setTimeout sets a new countdown duration and resets.
|
||||
@@ -39,6 +43,8 @@ class Countdown {
|
||||
* @return Returnvalue from Clock::getUptime
|
||||
*/
|
||||
ReturnValue_t setTimeout(uint32_t milliseconds);
|
||||
ReturnValue_t setTimeoutTv(timeval tv);
|
||||
|
||||
/**
|
||||
* Returns true if the countdown duration has passed.
|
||||
*
|
||||
@@ -61,22 +67,31 @@ class Countdown {
|
||||
* Returns the remaining milliseconds (0 if timeout)
|
||||
*/
|
||||
uint32_t getRemainingMillis() const;
|
||||
|
||||
uint32_t getTimeoutMs() const;
|
||||
|
||||
timeval getTimeout() const;
|
||||
|
||||
/**
|
||||
* Makes hasTimedOut() return true
|
||||
*/
|
||||
void timeOut();
|
||||
/**
|
||||
* Internal countdown duration in milliseconds
|
||||
*/
|
||||
uint32_t timeout;
|
||||
|
||||
static inline uint32_t timevalToMs(timeval& tv);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Last time the timer was started (uptime)
|
||||
* Start time of the countdown.
|
||||
*/
|
||||
uint32_t startTime = 0;
|
||||
timeval startTime{};
|
||||
|
||||
uint32_t getCurrentTime() const;
|
||||
/**
|
||||
* Timeout as timeval type. The countdown has timed out when the
|
||||
* current time exceeds the start time plus the timeout.
|
||||
*/
|
||||
timeval timeout{};
|
||||
|
||||
timeval getCurrentTime() const;
|
||||
};
|
||||
|
||||
#endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#define TMTCBRIDGE_WIRETAPPING 0
|
||||
|
||||
TmTcBridge::TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDestination,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId)
|
||||
uint32_t msgQueueDepth, object_id_t tmStoreId, object_id_t tcStoreId)
|
||||
: SystemObject(objectId),
|
||||
name(name),
|
||||
tmStoreId(tmStoreId),
|
||||
@@ -18,7 +18,7 @@ TmTcBridge::TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDes
|
||||
{
|
||||
auto mqArgs = MqArgs(objectId, static_cast<void*>(this));
|
||||
tmTcReceptionQueue = QueueFactory::instance()->createMessageQueue(
|
||||
TMTC_RECEPTION_QUEUE_DEPTH, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
||||
msgQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
||||
}
|
||||
|
||||
TmTcBridge::~TmTcBridge() { QueueFactory::instance()->deleteMessageQueue(tmTcReceptionQueue); }
|
||||
|
@@ -15,7 +15,6 @@ class TmTcBridge : public AcceptsTelemetryIF,
|
||||
public ExecutableObjectIF,
|
||||
public SystemObject {
|
||||
public:
|
||||
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
|
||||
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
|
||||
static constexpr unsigned int LIMIT_DOWNLINK_PACKETS_STORED = 500;
|
||||
|
||||
@@ -23,7 +22,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
|
||||
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
|
||||
|
||||
TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDestination,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId);
|
||||
uint32_t msgQueueDepth, object_id_t tmStoreId, object_id_t tcStoreId);
|
||||
~TmTcBridge() override;
|
||||
|
||||
/**
|
||||
|
@@ -1,15 +1,18 @@
|
||||
#include <fsfw/timemanager/Countdown.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
|
||||
static constexpr bool TEST_LONGER_CD = false;
|
||||
TEST_CASE("Countdown Tests", "[TestCountdown]") {
|
||||
INFO("Countdown Tests");
|
||||
Countdown count(20);
|
||||
REQUIRE(count.timeout == 20);
|
||||
REQUIRE(count.getTimeoutMs() == 20);
|
||||
REQUIRE(count.setTimeout(100) == static_cast<uint16_t>(returnvalue::OK));
|
||||
REQUIRE(count.timeout == 100);
|
||||
REQUIRE(count.getTimeoutMs() == 100);
|
||||
REQUIRE(count.setTimeout(150) == static_cast<uint16_t>(returnvalue::OK));
|
||||
REQUIRE(count.isBusy());
|
||||
REQUIRE(not count.hasTimedOut());
|
||||
@@ -25,4 +28,19 @@ TEST_CASE("Countdown Tests", "[TestCountdown]") {
|
||||
count.resetTimer();
|
||||
REQUIRE(not count.hasTimedOut());
|
||||
REQUIRE(count.isBusy());
|
||||
count.setTimeout(100);
|
||||
REQUIRE(not count.hasTimedOut());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
REQUIRE(not count.hasTimedOut());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
REQUIRE(count.hasTimedOut());
|
||||
|
||||
// Takes longer, disabled by default
|
||||
if (TEST_LONGER_CD) {
|
||||
count.setTimeout(2500);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
REQUIRE(not count.hasTimedOut());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
REQUIRE(count.hasTimedOut());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user