Compare commits
32 Commits
245886c555
...
move_seman
Author | SHA1 | Date | |
---|---|---|---|
6fa453940f | |||
9a8d775eb1 | |||
4d6f6e6b23 | |||
55f6825a03 | |||
c162acb7df | |||
87462afe6d | |||
a8de395ea0 | |||
f0bddfcb21 | |||
23d9b44b3e | |||
26e4445189 | |||
9ee3cdf729 | |||
1b7493f945 | |||
7f6ba5f40b | |||
070b48ada2 | |||
d9a139e1ef | |||
c80a3752d9 | |||
af58c414fc | |||
4c48668125 | |||
2745b2080d | |||
e9d9f44605 | |||
2c5af91db1 | |||
5cd7b98ba7 | |||
a39f1271ec | |||
bbf0d7a0d2 | |||
04ee3c7362 | |||
95dab69b35 | |||
33de15205b | |||
4d353a1ad2 | |||
6006c97e48 | |||
6e17e45506 | |||
64537d442a | |||
78cf00315d |
@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## Fixes
|
||||
|
||||
- Add monotonic watchdog Clock API and use it in `Countdown` and `Stopwatch` class.
|
||||
- Bugfix in `Service11TelecommandScheduling` which allowed commands
|
||||
time tagged in the past to be inserted.
|
||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/738
|
||||
|
@ -565,6 +565,9 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
|
||||
*/
|
||||
if (newMode == MODE_ON and continueToNormal) {
|
||||
continueToNormal = false;
|
||||
// TODO: Check whether the following two lines are okay to do so.
|
||||
transitionSourceMode = MODE_ON;
|
||||
transitionSourceSubMode = submode;
|
||||
mode = _MODE_TO_NORMAL;
|
||||
return;
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ const LocalPool::LocalPoolConfig EventManager::poolConfig = {
|
||||
{fsfwconfig::FSFW_EVENTMGMT_EVENTIDMATCHERS, sizeof(EventIdRangeMatcher)},
|
||||
{fsfwconfig::FSFW_EVENTMGMR_RANGEMATCHERS, sizeof(ReporterRangeMatcher)}};
|
||||
|
||||
EventManager::EventManager(object_id_t setObjectId)
|
||||
EventManager::EventManager(object_id_t setObjectId, uint32_t eventQueueDepth)
|
||||
: SystemObject(setObjectId), factoryBackend(0, poolConfig, false, true) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
auto mqArgs = MqArgs(setObjectId, static_cast<void*>(this));
|
||||
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
||||
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE, &mqArgs);
|
||||
eventQueueDepth, EventMessage::EVENT_MESSAGE_SIZE, &mqArgs);
|
||||
}
|
||||
|
||||
EventManager::~EventManager() {
|
||||
|
@ -21,9 +21,9 @@ extern const char* translateEvents(Event event);
|
||||
|
||||
class EventManager : public EventManagerIF, public ExecutableObjectIF, public SystemObject {
|
||||
public:
|
||||
static const uint16_t MAX_EVENTS_PER_CYCLE = 80;
|
||||
static const uint16_t DEFAULT_MAX_EVENTS_PER_CYCLE = 80;
|
||||
|
||||
EventManager(object_id_t setObjectId);
|
||||
EventManager(object_id_t setObjectId, uint32_t eventQueueDepth);
|
||||
virtual ~EventManager();
|
||||
|
||||
void setMutexTimeout(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs);
|
||||
|
@ -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;
|
||||
|
@ -26,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;
|
||||
|
@ -47,7 +47,32 @@ ReturnValue_t Clock::setClock(const timeval* time) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||
ReturnValue_t Clock::getClockMonotonic(timeval* time) {
|
||||
#if defined(PLATFORM_WIN)
|
||||
// TODO: Implement with std::chrono::steady_clock.. or in some other way. I am not even sure
|
||||
// whether this is possible with steady_clock. The conversion we have to do here just to be
|
||||
// generic is kind of awkward..
|
||||
return returnvalue::FAILED;
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
timespec timeMonotonic;
|
||||
int status = clock_gettime(CLOCK_MONOTONIC_RAW, &timeMonotonic);
|
||||
if (status != 0) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
time->tv_sec = timeMonotonic.tv_sec;
|
||||
time->tv_usec = timeMonotonic.tv_nsec / 1000.0;
|
||||
return returnvalue::OK;
|
||||
#else
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "Clock::getUptime: Not implemented for found OS!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("Clock::getUptime: Not implemented for found OS!\n");
|
||||
#endif
|
||||
return returnvalue::FAILED;
|
||||
#endif
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock(timeval* time) {
|
||||
#if defined(PLATFORM_WIN)
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto secondsChrono = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
||||
@ -75,6 +100,8 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||
#endif
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock_timeval(timeval* time) { return Clock::getClock(time); }
|
||||
|
||||
ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
||||
if (time == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
|
@ -42,7 +42,7 @@ ReturnValue_t Clock::setClock(const timeval* time) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||
ReturnValue_t Clock::getClock(timeval* time) {
|
||||
timespec timeUnix{};
|
||||
int status = clock_gettime(CLOCK_REALTIME, &timeUnix);
|
||||
if (status != 0) {
|
||||
@ -53,6 +53,8 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock_timeval(timeval* time) { return Clock::getClock(time); }
|
||||
|
||||
ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
||||
timeval timeVal{};
|
||||
ReturnValue_t result = getClock_timeval(&timeVal);
|
||||
@ -64,6 +66,17 @@ ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClockMonotonic(timeval* time) {
|
||||
timespec timeMonotonic{};
|
||||
int status = clock_gettime(CLOCK_MONOTONIC_RAW, &timeMonotonic);
|
||||
if (status != 0) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
time->tv_sec = timeMonotonic.tv_sec;
|
||||
time->tv_usec = timeMonotonic.tv_nsec / 1000.0;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
timeval Clock::getUptime() {
|
||||
timeval uptime{};
|
||||
auto result = getUptime(&uptime);
|
||||
@ -79,11 +92,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.
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "DummyPowerSwitcher.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
DummyPowerSwitcher::DummyPowerSwitcher(object_id_t objectId, size_t numberOfSwitches,
|
||||
size_t numberOfFuses, bool registerGlobally,
|
||||
uint32_t switchDelayMs)
|
||||
@ -9,11 +11,11 @@ DummyPowerSwitcher::DummyPowerSwitcher(object_id_t objectId, size_t numberOfSwit
|
||||
switchDelayMs(switchDelayMs) {}
|
||||
|
||||
void DummyPowerSwitcher::setInitialSwitcherList(std::vector<ReturnValue_t> switcherList) {
|
||||
this->switcherList = switcherList;
|
||||
this->switcherList = std::move(switcherList);
|
||||
}
|
||||
|
||||
void DummyPowerSwitcher::setInitialFusesList(std::vector<ReturnValue_t> fuseList) {
|
||||
this->fuseList = fuseList;
|
||||
this->fuseList = std::move(fuseList);
|
||||
}
|
||||
|
||||
ReturnValue_t DummyPowerSwitcher::sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) {
|
||||
|
@ -68,6 +68,9 @@ ReturnValue_t CServiceHealthCommanding::prepareCommand(CommandMessage *message,
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
switch (subservice) {
|
||||
case (Subservice::COMMAND_SET_HEALTH): {
|
||||
if (tcDataLen != sizeof(object_id_t) + sizeof(HasHealthIF::HealthState)) {
|
||||
return CommandingServiceBase::INVALID_TC;
|
||||
}
|
||||
HealthSetCommand healthCommand;
|
||||
result = healthCommand.deSerialize(&tcData, &tcDataLen, SerializeIF::Endianness::BIG);
|
||||
if (result != returnvalue::OK) {
|
||||
|
@ -21,6 +21,7 @@ SubsystemBase::~SubsystemBase() { QueueFactory::instance()->deleteMessageQueue(c
|
||||
|
||||
ReturnValue_t SubsystemBase::checkStateAgainstTable(HybridIterator<ModeListEntry> tableIter,
|
||||
Submode_t targetSubmode) {
|
||||
using namespace mode;
|
||||
std::map<object_id_t, ChildInfo>::iterator childIter;
|
||||
|
||||
for (; tableIter.value != NULL; ++tableIter) {
|
||||
@ -34,13 +35,21 @@ ReturnValue_t SubsystemBase::checkStateAgainstTable(HybridIterator<ModeListEntry
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
Submode_t submodeToCheckAgainst = tableIter.value->getSubmode();
|
||||
// Check submodes here.
|
||||
uint8_t mask;
|
||||
bool submodesAllowedMask = tableIter.value->submodesAllowed(&mask);
|
||||
uint8_t submodeToCheckAgainst = tableIter.value->getSubmode();
|
||||
if (tableIter.value->inheritSubmode()) {
|
||||
submodeToCheckAgainst = targetSubmode;
|
||||
}
|
||||
|
||||
if (childIter->second.submode != submodeToCheckAgainst) {
|
||||
return returnvalue::FAILED;
|
||||
if (submodesAllowedMask) {
|
||||
if ((childIter->second.submode | mask) != mask) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
} else {
|
||||
if (childIter->second.submode != submodeToCheckAgainst) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnvalue::OK;
|
||||
|
@ -1,111 +1,126 @@
|
||||
#ifndef FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_
|
||||
#define FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_
|
||||
|
||||
#include "../../modes/HasModesIF.h"
|
||||
#include "../../objectmanager/SystemObjectIF.h"
|
||||
#include "../../serialize/SerialLinkedListAdapter.h"
|
||||
#include "../../serialize/SerializeIF.h"
|
||||
#include "fsfw/modes/HasModesIF.h"
|
||||
#include "fsfw/objectmanager/SystemObjectIF.h"
|
||||
#include "fsfw/serialize/SerialLinkedListAdapter.h"
|
||||
#include "fsfw/serialize/SerializeIF.h"
|
||||
|
||||
class ModeListEntry : public SerializeIF, public LinkedElement<ModeListEntry> {
|
||||
namespace mode {
|
||||
enum SpecialSubmodeFlags : uint8_t { INHERIT = 1 << 0, ALLOWED_MASK = 1 << 1 };
|
||||
}
|
||||
|
||||
class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
|
||||
public LinkedElement<ModeListEntry> {
|
||||
public:
|
||||
ModeListEntry() : LinkedElement<ModeListEntry>(this) {}
|
||||
static constexpr uint8_t ALL_SUBMODES_ALLOWED_MASK = 0xff;
|
||||
|
||||
uint32_t value1 = 0;
|
||||
uint32_t value2 = 0;
|
||||
uint8_t value3 = 0;
|
||||
uint8_t value4 = 0;
|
||||
ModeListEntry() : SerialLinkedListAdapter(), LinkedElement<ModeListEntry>(this) { setLinks(); }
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) const {
|
||||
ReturnValue_t result;
|
||||
SerializeElement<uint32_t> value1 = 0;
|
||||
SerializeElement<uint32_t> value2 = 0;
|
||||
SerializeElement<uint8_t> value3 = 0;
|
||||
SerializeElement<uint8_t> value4 = 0;
|
||||
SerializeElement<uint8_t> value5 = 0;
|
||||
|
||||
result = SerializeAdapter::serialize(&value1, buffer, size, maxSize, streamEndianness);
|
||||
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::serialize(&value2, buffer, size, maxSize, streamEndianness);
|
||||
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::serialize(&value3, buffer, size, maxSize, streamEndianness);
|
||||
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = SerializeAdapter::serialize(&value4, buffer, size, maxSize, streamEndianness);
|
||||
|
||||
return result;
|
||||
ModeListEntry(const ModeListEntry& other)
|
||||
: SerialLinkedListAdapter(), LinkedElement<ModeListEntry>(this) {
|
||||
value1.entry = other.value1.entry;
|
||||
value2.entry = other.value2.entry;
|
||||
value3.entry = other.value3.entry;
|
||||
value4.entry = other.value4.entry;
|
||||
value5.entry = other.value5.entry;
|
||||
setLinks();
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
return sizeof(value1) + sizeof(value2) + sizeof(value3) + sizeof(value4);
|
||||
ModeListEntry& operator=(const ModeListEntry& other) {
|
||||
this->value1.entry = other.value1.entry;
|
||||
this->value2.entry = other.value2.entry;
|
||||
this->value3.entry = other.value3.entry;
|
||||
this->value4.entry = other.value4.entry;
|
||||
this->value5.entry = other.value5.entry;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result;
|
||||
|
||||
result = SerializeAdapter::deSerialize(&value1, buffer, size, streamEndianness);
|
||||
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::deSerialize(&value2, buffer, size, streamEndianness);
|
||||
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::deSerialize(&value3, buffer, size, streamEndianness);
|
||||
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter::deSerialize(&value4, buffer, size, streamEndianness);
|
||||
|
||||
return result;
|
||||
void setLinks() {
|
||||
setStart(&value1);
|
||||
value1.setNext(&value2);
|
||||
value2.setNext(&value3);
|
||||
value3.setNext(&value4);
|
||||
value4.setNext(&value5);
|
||||
}
|
||||
|
||||
// for Sequences
|
||||
Mode_t getTableId() const { return value1; }
|
||||
Mode_t getTableId() const { return value1.entry; }
|
||||
|
||||
void setTableId(Mode_t tableId) { this->value1 = tableId; }
|
||||
void setTableId(Mode_t tableId) { this->value1.entry = tableId; }
|
||||
|
||||
uint8_t getWaitSeconds() const { return value2; }
|
||||
uint8_t getWaitSeconds() const { return value2.entry; }
|
||||
|
||||
void setWaitSeconds(uint8_t waitSeconds) { this->value2 = waitSeconds; }
|
||||
void setWaitSeconds(uint8_t waitSeconds) { this->value2.entry = waitSeconds; }
|
||||
|
||||
bool checkSuccess() const { return value3 == 1; }
|
||||
bool checkSuccess() const { return value3.entry == 1; }
|
||||
|
||||
void setCheckSuccess(bool checkSuccess) { this->value3 = checkSuccess; }
|
||||
void setCheckSuccess(bool checkSuccess) { this->value3.entry = checkSuccess; }
|
||||
|
||||
// for Tables
|
||||
object_id_t getObject() const { return value1; }
|
||||
object_id_t getObject() const { return value1.entry; }
|
||||
|
||||
void setObject(object_id_t object) { this->value1 = object; }
|
||||
void setObject(object_id_t object) { this->value1.entry = object; }
|
||||
|
||||
Mode_t getMode() const { return value2; }
|
||||
Mode_t getMode() const { return value2.entry; }
|
||||
|
||||
void setMode(Mode_t mode) { this->value2 = mode; }
|
||||
void setMode(Mode_t mode) { this->value2.entry = mode; }
|
||||
|
||||
Submode_t getSubmode() const { return value3; }
|
||||
Submode_t getSubmode() const { return value3.entry; }
|
||||
|
||||
void setSubmode(Submode_t submode) { this->value3 = submode; }
|
||||
void setSubmode(Submode_t submode) { this->value3.entry = submode; }
|
||||
|
||||
bool inheritSubmode() const { return value4 == 1; }
|
||||
|
||||
void setInheritSubmode(bool inherit) {
|
||||
if (inherit) {
|
||||
value4 = 1;
|
||||
} else {
|
||||
value4 = 0;
|
||||
bool inheritSubmode() const {
|
||||
return (value4.entry & mode::SpecialSubmodeFlags::INHERIT) ==
|
||||
mode::SpecialSubmodeFlags::INHERIT;
|
||||
}
|
||||
bool submodesAllowed(uint8_t* mask) const {
|
||||
bool submodesAllowed = (value4.entry & mode::SpecialSubmodeFlags::ALLOWED_MASK) ==
|
||||
mode::SpecialSubmodeFlags::ALLOWED_MASK;
|
||||
if (submodesAllowed and mask != nullptr) {
|
||||
*mask = value5.entry;
|
||||
}
|
||||
return submodesAllowed;
|
||||
}
|
||||
|
||||
bool operator==(ModeListEntry other) {
|
||||
return ((value1 == other.value1) && (value2 == other.value2) && (value3 == other.value3));
|
||||
/**
|
||||
* Enable the inheritance of submodes. This is relevant for both the execution
|
||||
* of mode tables and for mode checking.
|
||||
*/
|
||||
void enableInheritSubmode() { value4.entry |= mode::SpecialSubmodeFlags::INHERIT; }
|
||||
/**
|
||||
* Disable the inheritance of submodes. This is relevant for both the execution
|
||||
* of mode tables and for mode checking.
|
||||
*/
|
||||
void disableInheritSubmode() { value4.entry &= ~mode::SpecialSubmodeFlags::INHERIT; }
|
||||
|
||||
/**
|
||||
* Specialization of @enableSubmodeAllowed which allows all submodes.
|
||||
*/
|
||||
void allowAllSubmodes() { enableSubmodeAllowed(ALL_SUBMODES_ALLOWED_MASK); }
|
||||
|
||||
/**
|
||||
* Enable an allowed submode mask for mode checks. Any submode which contains bits
|
||||
* outside of the mask will be declined.
|
||||
*
|
||||
* For example, for a mask of 0b11, only the modes 0b00, 0b01 and 0b11 will be accepted.
|
||||
*/
|
||||
void enableSubmodeAllowed(uint8_t mask) {
|
||||
value4.entry |= mode::SpecialSubmodeFlags::ALLOWED_MASK;
|
||||
value5.entry = mask;
|
||||
}
|
||||
/**
|
||||
* Enforce the equality of submodes for mode checks. This is the default.
|
||||
*/
|
||||
void disableSubmodeAllowed() {
|
||||
value4.entry &= ~mode::SpecialSubmodeFlags::ALLOWED_MASK;
|
||||
value5.entry = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -49,6 +49,13 @@ class Clock {
|
||||
* @return -@c returnvalue::OK on success. Otherwise, the OS failure code is returned.
|
||||
*/
|
||||
static ReturnValue_t setClock(const timeval *time);
|
||||
|
||||
/**
|
||||
* @deprecated Use getClock instead, which does the same.
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t getClock_timeval(timeval *time);
|
||||
/**
|
||||
* This system call returns the current system clock in timeval format.
|
||||
* The timval format has the fields @c tv_sec with seconds and @c tv_usec with
|
||||
@ -56,7 +63,18 @@ class Clock {
|
||||
* @param time A pointer to a timeval struct where the current time is stored.
|
||||
* @return @c returnvalue::OK on success. Otherwise, the OS failure code is returned.
|
||||
*/
|
||||
static ReturnValue_t getClock_timeval(timeval *time);
|
||||
static ReturnValue_t getClock(timeval *time);
|
||||
|
||||
/**
|
||||
* Retrieve a monotonic clock. This clock this is also more suited for measuring elapsed times
|
||||
* between two time points, but less suited when the absolute time is required.
|
||||
*
|
||||
* Implementation example: A generic UNIX implementation can use CLOCK_MONOTONIC_RAW with
|
||||
* `clock_gettime`.
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t getClockMonotonic(timeval *time);
|
||||
|
||||
/**
|
||||
* Get the time since boot in a timeval struct
|
||||
|
@ -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::getClockMonotonic(&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::getClockMonotonic(&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::getClockMonotonic(¤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_ */
|
||||
|
@ -9,10 +9,10 @@
|
||||
Stopwatch::Stopwatch(bool displayOnDestruction, StopwatchDisplayMode displayMode)
|
||||
: displayOnDestruction(displayOnDestruction), displayMode(displayMode) {
|
||||
// Measures start time on initialization.
|
||||
Clock::getClock_timeval(&startTime);
|
||||
Clock::getClockMonotonic(&startTime);
|
||||
}
|
||||
|
||||
void Stopwatch::start() { Clock::getUptime(&startTime); }
|
||||
void Stopwatch::start() { Clock::getClockMonotonic(&startTime); }
|
||||
|
||||
dur_millis_t Stopwatch::stop(bool display) {
|
||||
stopInternal();
|
||||
@ -63,6 +63,6 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const { return displayMode; }
|
||||
|
||||
void Stopwatch::stopInternal() {
|
||||
timeval endTime;
|
||||
Clock::getClock_timeval(&endTime);
|
||||
Clock::getClockMonotonic(&endTime);
|
||||
elapsedTime = endTime - startTime;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,8 @@ ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *da
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
path path(params.path());
|
||||
if (not exists(path)) {
|
||||
std::error_code e;
|
||||
if (not exists(path, e)) {
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
// This is equivalent to "r+" mode, which is what we need here. Only using ::out would truncate
|
||||
@ -35,7 +36,8 @@ ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
path path(params.path());
|
||||
if (not exists(path)) {
|
||||
std::error_code e;
|
||||
if (not exists(path, e)) {
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
ifstream file(path);
|
||||
@ -59,7 +61,8 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
path path(params.path);
|
||||
if (exists(path)) {
|
||||
std::error_code e;
|
||||
if (exists(path, e)) {
|
||||
return HasFileSystemIF::FILE_ALREADY_EXISTS;
|
||||
}
|
||||
ofstream file(path);
|
||||
@ -74,7 +77,8 @@ ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *ar
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
path path(path_);
|
||||
if (not exists(path)) {
|
||||
std::error_code e;
|
||||
if (not exists(path, e)) {
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
if (remove(path, errorCode)) {
|
||||
@ -89,7 +93,8 @@ ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool crea
|
||||
}
|
||||
path dirPath(params.path);
|
||||
|
||||
if (exists(dirPath)) {
|
||||
std::error_code e;
|
||||
if (exists(dirPath, e)) {
|
||||
return HasFileSystemIF::DIRECTORY_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
@ -110,7 +115,8 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
path dirPath(params.path);
|
||||
if (not exists(dirPath)) {
|
||||
std::error_code e;
|
||||
if (not exists(dirPath, e)) {
|
||||
return HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST;
|
||||
}
|
||||
if (is_regular_file(dirPath)) {
|
||||
@ -149,12 +155,14 @@ ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_,
|
||||
|
||||
bool HostFilesystem::fileExists(FilesystemParams params) {
|
||||
path path(params.path);
|
||||
return filesystem::exists(path);
|
||||
std::error_code e;
|
||||
return filesystem::exists(path, e);
|
||||
}
|
||||
|
||||
ReturnValue_t HostFilesystem::truncateFile(FilesystemParams params) {
|
||||
path path(params.path);
|
||||
if (not filesystem::exists(path)) {
|
||||
std::error_code e;
|
||||
if (not filesystem::exists(path, e)) {
|
||||
return FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
ofstream of(path);
|
||||
|
@ -17,7 +17,7 @@ ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool pri
|
||||
return COMMAND_PENDING;
|
||||
}
|
||||
|
||||
currentCmd = command;
|
||||
currentCmd = std::move(command);
|
||||
this->blocking = blocking;
|
||||
this->printOutput = printOutput;
|
||||
if (state == States::IDLE) {
|
||||
|
@ -112,7 +112,7 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
||||
if (i2cCookie->errorCounter < 3) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C "
|
||||
"device with error code "
|
||||
"device from " << deviceFile << " with error code "
|
||||
<< errno << ". Error description: " << strerror(errno) << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ add_subdirectory(util)
|
||||
add_subdirectory(container)
|
||||
add_subdirectory(osal)
|
||||
add_subdirectory(pus)
|
||||
add_subdirectory(subsystem)
|
||||
add_subdirectory(serialize)
|
||||
add_subdirectory(datapoollocal)
|
||||
add_subdirectory(storagemanager)
|
||||
|
1
unittests/subsystem/CMakeLists.txt
Normal file
1
unittests/subsystem/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE testModeDef.cpp)
|
49
unittests/subsystem/testModeDef.cpp
Normal file
49
unittests/subsystem/testModeDef.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/subsystem/modes/ModeDefinitions.h"
|
||||
|
||||
TEST_CASE("Mode Definitions", "[mode]") {
|
||||
ModeListEntry entry;
|
||||
|
||||
SECTION("Basic") {
|
||||
entry.setMode(HasModesIF::MODE_OFF);
|
||||
entry.setSubmode(2);
|
||||
CHECK(entry.getMode() == HasModesIF::MODE_OFF);
|
||||
CHECK(entry.getSubmode() == 2);
|
||||
uint8_t mask;
|
||||
CHECK(entry.submodesAllowed(&mask) == false);
|
||||
}
|
||||
|
||||
SECTION("Allowed submode mask") {
|
||||
entry.allowAllSubmodes();
|
||||
uint8_t mask;
|
||||
CHECK(entry.submodesAllowed(&mask) == true);
|
||||
CHECK(mask == 0xff);
|
||||
}
|
||||
|
||||
SECTION("Serialization") {
|
||||
std::array<uint8_t, 32> buf{};
|
||||
entry.setObject(0x1f2f3f4f);
|
||||
entry.setMode(HasModesIF::MODE_ON);
|
||||
entry.setSubmode(2);
|
||||
entry.enableInheritSubmode();
|
||||
entry.enableSubmodeAllowed(0x1f);
|
||||
uint8_t* serPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
REQUIRE(entry.serialize(&serPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
||||
returnvalue::OK);
|
||||
CHECK(buf[0] == 0x1f);
|
||||
CHECK(buf[1] == 0x2f);
|
||||
CHECK(buf[2] == 0x3f);
|
||||
CHECK(buf[3] == 0x4f);
|
||||
CHECK(buf[4] == 0);
|
||||
CHECK(buf[5] == 0);
|
||||
CHECK(buf[6] == 0);
|
||||
CHECK(buf[7] == HasModesIF::MODE_ON);
|
||||
CHECK(buf[8] == 2);
|
||||
CHECK(buf[9] == (mode::SpecialSubmodeFlags::ALLOWED_MASK | mode::SpecialSubmodeFlags::INHERIT));
|
||||
CHECK(buf[10] == 0x1f);
|
||||
}
|
||||
}
|
@ -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