moved TCScheduling Service to use timeval internally
This commit is contained in:
parent
0e7c6b117f
commit
61620bfce7
@ -91,7 +91,6 @@ class Service11TelecommandScheduling final : public PusServiceBase {
|
|||||||
private:
|
private:
|
||||||
struct TelecommandStruct {
|
struct TelecommandStruct {
|
||||||
uint64_t requestId{};
|
uint64_t requestId{};
|
||||||
uint32_t seconds{};
|
|
||||||
store_address_t storeAddr; // uint16
|
store_address_t storeAddr; // uint16
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,7 +113,7 @@ class Service11TelecommandScheduling final : public PusServiceBase {
|
|||||||
* The telecommand map uses the exectution time as a Unix time stamp as
|
* The telecommand map uses the exectution time as a Unix time stamp as
|
||||||
* the key. This is mapped to a generic telecommand struct.
|
* the key. This is mapped to a generic telecommand struct.
|
||||||
*/
|
*/
|
||||||
using TelecommandMap = etl::multimap<uint32_t, TelecommandStruct, MAX_NUM_TCS>;
|
using TelecommandMap = etl::multimap<timeval, TelecommandStruct, MAX_NUM_TCS>;
|
||||||
using TcMapIter = typename TelecommandMap::iterator;
|
using TcMapIter = typename TelecommandMap::iterator;
|
||||||
|
|
||||||
TelecommandMap telecommandMap;
|
TelecommandMap telecommandMap;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
#include "fsfw/globalfunctions/CRC.h"
|
||||||
|
#include "fsfw/globalfunctions/timevalOperations.h"
|
||||||
#include "fsfw/objectmanager/ObjectManager.h"
|
#include "fsfw/objectmanager/ObjectManager.h"
|
||||||
#include "fsfw/serialize/SerializeAdapter.h"
|
#include "fsfw/serialize/SerializeAdapter.h"
|
||||||
#include "fsfw/serviceinterface.h"
|
#include "fsfw/serviceinterface.h"
|
||||||
@ -150,17 +152,22 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::handleResetCom
|
|||||||
template <size_t MAX_NUM_TCS>
|
template <size_t MAX_NUM_TCS>
|
||||||
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivity(
|
inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivity(
|
||||||
const uint8_t *data, size_t size) {
|
const uint8_t *data, size_t size) {
|
||||||
uint32_t timestamp = 0;
|
uint32_t seconds = 0;
|
||||||
ReturnValue_t result = SerializeAdapter::deSerialize(×tamp, &data, &size, DEF_END);
|
ReturnValue_t result = SerializeAdapter::deSerialize(&seconds, &data, &size, DEF_END);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
timeval scheduledTime;
|
||||||
|
scheduledTime.tv_sec = seconds;
|
||||||
|
scheduledTime.tv_usec = 0;
|
||||||
|
|
||||||
// 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)
|
||||||
timeval tNow = {};
|
timeval tNow = {};
|
||||||
Clock::getClock_timeval(&tNow);
|
Clock::getClock_timeval(&tNow);
|
||||||
if (timestamp - tNow.tv_sec <= RELEASE_TIME_MARGIN_SECONDS) {
|
timeval timeDifference = scheduledTime - tNow;
|
||||||
|
// round subseconds up
|
||||||
|
if (timeDifference.tv_sec + 1 <= RELEASE_TIME_MARGIN_SECONDS) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "Service11TelecommandScheduling::doInsertActivity: Release time too close to "
|
sif::warning << "Service11TelecommandScheduling::doInsertActivity: Release time too close to "
|
||||||
"current time"
|
"current time"
|
||||||
@ -197,11 +204,10 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doInsertActivi
|
|||||||
|
|
||||||
// insert into multimap with new store address
|
// insert into multimap with new store address
|
||||||
TelecommandStruct tc;
|
TelecommandStruct tc;
|
||||||
tc.seconds = timestamp;
|
|
||||||
tc.storeAddr = addr;
|
tc.storeAddr = addr;
|
||||||
tc.requestId = getRequestIdFromTc(); // TODO: Missing sanity check of the returned request id
|
tc.requestId = getRequestIdFromTc(); // TODO: Missing sanity check of the returned request id
|
||||||
|
|
||||||
auto it = telecommandMap.insert(std::pair<uint32_t, TelecommandStruct>(timestamp, tc));
|
auto it = telecommandMap.insert(std::pair<timeval, TelecommandStruct>(scheduledTime, tc));
|
||||||
if (it == telecommandMap.end()) {
|
if (it == telecommandMap.end()) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
@ -391,7 +397,8 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doTimeshiftAct
|
|||||||
|
|
||||||
// temporarily hold the item
|
// temporarily hold the item
|
||||||
TelecommandStruct tempTc(tcToTimeshiftIt->second);
|
TelecommandStruct tempTc(tcToTimeshiftIt->second);
|
||||||
uint32_t tempKey = tcToTimeshiftIt->first + relativeTime;
|
timeval tempKey = tcToTimeshiftIt->first;
|
||||||
|
tempKey.tv_sec += relativeTime;
|
||||||
|
|
||||||
// delete old entry from the mm
|
// delete old entry from the mm
|
||||||
telecommandMap.erase(tcToTimeshiftIt);
|
telecommandMap.erase(tcToTimeshiftIt);
|
||||||
@ -436,7 +443,8 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::doFilterTimesh
|
|||||||
for (auto it = itBegin; it != itEnd;) {
|
for (auto it = itBegin; it != itEnd;) {
|
||||||
// temporarily hold the item
|
// temporarily hold the item
|
||||||
TelecommandStruct tempTc(it->second);
|
TelecommandStruct tempTc(it->second);
|
||||||
uint32_t tempKey = it->first + relativeTime;
|
timeval tempKey = it->first;
|
||||||
|
tempKey.tv_sec += relativeTime;
|
||||||
|
|
||||||
// delete the old entry from the mm
|
// delete the old entry from the mm
|
||||||
telecommandMap.erase(it++);
|
telecommandMap.erase(it++);
|
||||||
@ -533,12 +541,16 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TypeOfTimeWindow::FROM_TIMETAG: {
|
case TypeOfTimeWindow::FROM_TIMETAG: {
|
||||||
uint32_t fromTimestamp = 0;
|
uint32_t fromSeconds = 0;
|
||||||
result = SerializeAdapter::deSerialize(&fromTimestamp, &data, &dataSize, DEF_END);
|
result = SerializeAdapter::deSerialize(&fromSeconds, &data, &dataSize, DEF_END);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeval fromTimestamp;
|
||||||
|
fromTimestamp.tv_sec = fromSeconds;
|
||||||
|
fromTimestamp.tv_usec = 0;
|
||||||
|
|
||||||
itBegin = telecommandMap.begin();
|
itBegin = telecommandMap.begin();
|
||||||
while (itBegin->first < fromTimestamp && itBegin != telecommandMap.end()) {
|
while (itBegin->first < fromTimestamp && itBegin != telecommandMap.end()) {
|
||||||
itBegin++;
|
itBegin++;
|
||||||
@ -549,11 +561,15 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TypeOfTimeWindow::TO_TIMETAG: {
|
case TypeOfTimeWindow::TO_TIMETAG: {
|
||||||
uint32_t toTimestamp;
|
uint32_t toSeconds = 0;
|
||||||
result = SerializeAdapter::deSerialize(&toTimestamp, &data, &dataSize, DEF_END);
|
result = SerializeAdapter::deSerialize(&toSeconds, &data, &dataSize, DEF_END);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
timeval toTimestamp;
|
||||||
|
toTimestamp.tv_sec = toSeconds;
|
||||||
|
toTimestamp.tv_usec = 0;
|
||||||
|
|
||||||
itBegin = telecommandMap.begin();
|
itBegin = telecommandMap.begin();
|
||||||
itEnd = telecommandMap.begin();
|
itEnd = telecommandMap.begin();
|
||||||
while (itEnd->first <= toTimestamp && itEnd != telecommandMap.end()) {
|
while (itEnd->first <= toTimestamp && itEnd != telecommandMap.end()) {
|
||||||
@ -563,19 +579,27 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TypeOfTimeWindow::FROM_TIMETAG_TO_TIMETAG: {
|
case TypeOfTimeWindow::FROM_TIMETAG_TO_TIMETAG: {
|
||||||
uint32_t fromTimestamp;
|
uint32_t fromSeconds = 0;
|
||||||
uint32_t toTimestamp;
|
uint32_t toSeconds = 0;
|
||||||
|
|
||||||
result = SerializeAdapter::deSerialize(&fromTimestamp, &data, &dataSize,
|
result = SerializeAdapter::deSerialize(&fromSeconds, &data, &dataSize,
|
||||||
SerializeIF::Endianness::BIG);
|
SerializeIF::Endianness::BIG);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = SerializeAdapter::deSerialize(&toTimestamp, &data, &dataSize,
|
result = SerializeAdapter::deSerialize(&toSeconds, &data, &dataSize,
|
||||||
SerializeIF::Endianness::BIG);
|
SerializeIF::Endianness::BIG);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
timeval fromTimestamp;
|
||||||
|
fromTimestamp.tv_sec = fromSeconds;
|
||||||
|
fromTimestamp.tv_usec = 0;
|
||||||
|
timeval toTimestamp;
|
||||||
|
toTimestamp.tv_sec = toSeconds;
|
||||||
|
toTimestamp.tv_usec = 0;
|
||||||
|
|
||||||
|
|
||||||
if (fromTimestamp > toTimestamp) {
|
if (fromTimestamp > toTimestamp) {
|
||||||
return INVALID_TIME_WINDOW;
|
return INVALID_TIME_WINDOW;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user