Merge branch 'develop' into eive/develop

This commit is contained in:
Robin Müller 2021-10-11 19:21:48 +02:00
commit ad68802fe4
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
15 changed files with 172 additions and 55 deletions

View File

@ -2,7 +2,6 @@
#define MISSION_DEVICES_MGMRM3100HANDLER_H_ #define MISSION_DEVICES_MGMRM3100HANDLER_H_
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
#include "devices/powerSwitcherList.h"
#include "devicedefinitions/MgmRM3100HandlerDefs.h" #include "devicedefinitions/MgmRM3100HandlerDefs.h"
#include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h"

View File

@ -49,7 +49,7 @@ static constexpr uint8_t TMRC_DEFAULT_VALUE = TMRC_DEFAULT_37HZ_VALUE;
static constexpr uint8_t MEASUREMENT_REG_START = 0x24; static constexpr uint8_t MEASUREMENT_REG_START = 0x24;
static constexpr uint8_t BIST_REGISTER = 0x33; static constexpr uint8_t BIST_REGISTER = 0x33;
static constexpr uint8_t DATA_READY_VAL = 0b1000'0000; static constexpr uint8_t DATA_READY_VAL = 0b10000000;
static constexpr uint8_t STATUS_REGISTER = 0x34; static constexpr uint8_t STATUS_REGISTER = 0x34;
static constexpr uint8_t REVID_REGISTER = 0x36; static constexpr uint8_t REVID_REGISTER = 0x36;

View File

@ -357,7 +357,6 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
return status; return status;
} }
ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck, ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
gpio::GpioTypes expectedType, GpioMap& mapToAdd) { gpio::GpioTypes expectedType, GpioMap& mapToAdd) {
// Cross check with private map // Cross check with private map

View File

@ -16,18 +16,38 @@
#cmakedefine FSFW_ADD_MONITORING #cmakedefine FSFW_ADD_MONITORING
#cmakedefine FSFW_ADD_SGP4_PROPAGATOR #cmakedefine FSFW_ADD_SGP4_PROPAGATOR
// FSFW core defines
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED #ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0 #define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
#endif #endif
#ifndef FSFW_CPP_OSTREAM_ENABLED
#define FSFW_CPP_OSTREAM_ENABLED 1
#endif /* FSFW_CPP_OSTREAM_ENABLED */
#ifndef FSFW_VERBOSE_LEVEL
#define FSFW_VERBOSE_LEVEL 1
#endif /* FSFW_VERBOSE_LEVEL */
#ifndef FSFW_USE_REALTIME_FOR_LINUX
#define FSFW_USE_REALTIME_FOR_LINUX 0
#endif /* FSFW_USE_REALTIME_FOR_LINUX */
#ifndef FSFW_NO_C99_IO
#define FSFW_NO_C99_IO 0
#endif /* FSFW_NO_C99_IO */
#ifndef FSFW_USE_PUS_C_TELEMETRY #ifndef FSFW_USE_PUS_C_TELEMETRY
#define FSFW_USE_PUS_C_TELEMETRY 1 #define FSFW_USE_PUS_C_TELEMETRY 1
#endif #endif /* FSFW_USE_PUS_C_TELEMETRY */
#ifndef FSFW_USE_PUS_C_TELECOMMANDS #ifndef FSFW_USE_PUS_C_TELECOMMANDS
#define FSFW_USE_PUS_C_TELECOMMANDS 1 #define FSFW_USE_PUS_C_TELECOMMANDS 1
#endif #endif
// FSFW HAL defines
// Can be used for low-level debugging of the SPI bus // Can be used for low-level debugging of the SPI bus
#ifndef FSFW_HAL_SPI_WIRETAPPING #ifndef FSFW_HAL_SPI_WIRETAPPING
#define FSFW_HAL_SPI_WIRETAPPING 0 #define FSFW_HAL_SPI_WIRETAPPING 0

View File

@ -3,8 +3,8 @@
const char* const FSFW_VERSION_NAME = "ASTP"; const char* const FSFW_VERSION_NAME = "ASTP";
#define FSFW_VERSION 1 #define FSFW_VERSION 2
#define FSFW_SUBVERSION 2 #define FSFW_SUBVERSION 0
#define FSFW_REVISION 0 #define FSFW_REVISION 0
#endif /* FSFW_VERSION_H_ */ #endif /* FSFW_VERSION_H_ */

View File

@ -165,11 +165,9 @@ ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_
if (sourceStream[encodedIndex++] != STX_CHAR) { if (sourceStream[encodedIndex++] != STX_CHAR) {
return DECODING_ERROR; return DECODING_ERROR;
} }
while ((encodedIndex < sourceStreamLen) while ((encodedIndex < sourceStreamLen) and (decodedIndex < maxDestStreamlen)) {
and (decodedIndex < maxDestStreamlen) switch(sourceStream[encodedIndex]) {
and (sourceStream[encodedIndex] != ETX_CHAR) case(DLE_CHAR): {
and (sourceStream[encodedIndex] != STX_CHAR)) {
if (sourceStream[encodedIndex] == DLE_CHAR) {
if(encodedIndex + 1 >= sourceStreamLen) { if(encodedIndex + 1 >= sourceStreamLen) {
//reached the end of the sourceStream //reached the end of the sourceStream
*readLen = sourceStreamLen; *readLen = sourceStreamLen;
@ -197,31 +195,35 @@ ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_
} }
} }
++encodedIndex; ++encodedIndex;
break;
} }
else { case(STX_CHAR): {
*readLen = encodedIndex;
return DECODING_ERROR;
}
case(ETX_CHAR): {
*readLen = ++encodedIndex;
*decodedLen = decodedIndex;
return RETURN_OK;
}
default: {
destStream[decodedIndex] = sourceStream[encodedIndex]; destStream[decodedIndex] = sourceStream[encodedIndex];
break;
}
} }
++encodedIndex; ++encodedIndex;
++decodedIndex; ++decodedIndex;
} }
if (sourceStream[encodedIndex] != ETX_CHAR) {
if(decodedIndex == maxDestStreamlen) { if(decodedIndex == maxDestStreamlen) {
//so far we did not find anything wrong here, so let user try again //so far we did not find anything wrong here, so let user try again
*readLen = 0; *readLen = 0;
return STREAM_TOO_SHORT; return STREAM_TOO_SHORT;
} } else {
else { *readLen = encodedIndex;
*readLen = ++encodedIndex;
return DECODING_ERROR; return DECODING_ERROR;
} }
} }
else {
*readLen = ++encodedIndex;
*decodedLen = decodedIndex;
return RETURN_OK;
}
}
ReturnValue_t DleEncoder::decodeStreamNonEscaped(const uint8_t *sourceStream, ReturnValue_t DleEncoder::decodeStreamNonEscaped(const uint8_t *sourceStream,
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,

View File

@ -13,7 +13,6 @@ target_sources(${LIB_FSFW_NAME}
QueueFactory.cpp QueueFactory.cpp
SemaphoreFactory.cpp SemaphoreFactory.cpp
TaskFactory.cpp TaskFactory.cpp
Timer.cpp
tcpipHelpers.cpp tcpipHelpers.cpp
unixUtility.cpp unixUtility.cpp
CommandExecutor.cpp CommandExecutor.cpp

View File

@ -6,16 +6,14 @@ Countdown::Countdown(uint32_t initialTimeout): timeout(initialTimeout) {
Countdown::~Countdown() { Countdown::~Countdown() {
} }
ReturnValue_t Countdown::setTimeout(uint32_t miliseconds) { ReturnValue_t Countdown::setTimeout(uint32_t milliseconds) {
ReturnValue_t return_value = Clock::getUptime( &startTime ); ReturnValue_t returnValue = Clock::getUptime( &startTime );
timeout = miliseconds; timeout = milliseconds;
return return_value; return returnValue;
} }
bool Countdown::hasTimedOut() const { bool Countdown::hasTimedOut() const {
uint32_t current_time; if ( uint32_t( this->getCurrentTime() - startTime) >= timeout) {
Clock::getUptime( &current_time );
if ( uint32_t(current_time - startTime) >= timeout) {
return true; return true;
} else { } else {
return false; return false;
@ -31,7 +29,23 @@ ReturnValue_t Countdown::resetTimer() {
} }
void Countdown::timeOut() { void Countdown::timeOut() {
uint32_t current_time; startTime = this->getCurrentTime() - timeout;
Clock::getUptime( &current_time ); }
startTime= current_time - 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;
}
}
uint32_t Countdown::getCurrentTime() const {
uint32_t currentTime;
Clock::getUptime( &currentTime );
return currentTime;
} }

View File

@ -4,28 +4,77 @@
#include "Clock.h" #include "Clock.h"
/** /**
* @brief This file defines the Countdown class. *
* @author baetz * Countdown keeps track of a timespan.
*
* Countdown::resetTimer restarts the timer.
* Countdown::setTimeout sets a new countdown duration and resets.
*
* Can be checked with Countdown::hasTimedOut or
* Countdown::isBusy.
*
* Countdown::timeOut will force the timer to time out.
*
*/ */
class Countdown { class Countdown {
public: public:
uint32_t timeout; /**
* Constructor which sets the countdown duration in milliseconds
*
* It does not start the countdown!
* Call resetTimer or setTimeout before usage!
* Otherwise a call to hasTimedOut might return True.
*
* @param initialTimeout Countdown duration in milliseconds
*/
Countdown(uint32_t initialTimeout = 0); Countdown(uint32_t initialTimeout = 0);
~Countdown(); ~Countdown();
ReturnValue_t setTimeout(uint32_t miliseconds); /**
* Call to set a new countdown duration.
*
* Resets the countdown!
*
* @param milliseconds new countdown duration in milliseconds
* @return Returnvalue from Clock::getUptime
*/
ReturnValue_t setTimeout(uint32_t milliseconds);
/**
* Returns true if the countdown duration has passed.
*
* @return True if the countdown has passed
* False if it is still running
*/
bool hasTimedOut() const; bool hasTimedOut() const;
/**
* Complementary to hasTimedOut.
*
* @return True if the countdown is till running
* False if it is still running
*/
bool isBusy() const; bool isBusy() const;
/**
//!< Use last set timeout value and restart timer. * Uses last set timeout value and restarts timer.
*/
ReturnValue_t resetTimer(); ReturnValue_t resetTimer();
/**
//!< Make hasTimedOut() return true * Returns the remaining milliseconds (0 if timeout)
*/
uint32_t getRemainingMillis() const;
/**
* Makes hasTimedOut() return true
*/
void timeOut(); void timeOut();
/**
* Internal countdown duration in milliseconds
*/
uint32_t timeout;
private: private:
/**
* Last time the timer was started (uptime)
*/
uint32_t startTime = 0; uint32_t startTime = 0;
uint32_t getCurrentTime() const;
}; };
#endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */ #endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */

View File

@ -31,7 +31,6 @@ public:
* The class's default destructor. * The class's default destructor.
*/ */
virtual ~SpacePacket(); virtual ~SpacePacket();
/** /**
* With this call, the complete data content (including the CCSDS Primary * With this call, the complete data content (including the CCSDS Primary
* Header) is overwritten with the byte stream given. * Header) is overwritten with the byte stream given.
@ -41,6 +40,7 @@ public:
* @li \c false else. * @li \c false else.
*/ */
bool addWholeData(const uint8_t* p_data, uint32_t packet_size); bool addWholeData(const uint8_t* p_data, uint32_t packet_size);
protected: protected:
/** /**
* This structure defines the data structure of a Space Packet as local data. * This structure defines the data structure of a Space Packet as local data.

View File

@ -30,8 +30,7 @@ TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
initializeTmPacket(apid, service, subservice, packetSubcounter); initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size); memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength( setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
} }
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,

View File

@ -18,4 +18,5 @@ add_subdirectory(serialize)
add_subdirectory(datapoollocal) add_subdirectory(datapoollocal)
add_subdirectory(storagemanager) add_subdirectory(storagemanager)
add_subdirectory(globalfunctions) add_subdirectory(globalfunctions)
add_subdirectory(timemanager)
add_subdirectory(tmtcpacket) add_subdirectory(tmtcpacket)

View File

@ -103,7 +103,7 @@ TEST_CASE("DleEncoder" , "[DleEncoder]") {
for(size_t faultyDestSize = 0; faultyDestSize < expectedVec.size(); faultyDestSize ++) { for(size_t faultyDestSize = 0; faultyDestSize < expectedVec.size(); faultyDestSize ++) {
result = dleEncoder.encode(vecToEncode.data(), vecToEncode.size(), result = dleEncoder.encode(vecToEncode.data(), vecToEncode.size(),
buffer.data(), faultyDestSize, &encodedLen); buffer.data(), faultyDestSize, &encodedLen);
REQUIRE(result == DleEncoder::STREAM_TOO_SHORT); REQUIRE(result == static_cast<int>(DleEncoder::STREAM_TOO_SHORT));
} }
}; };
@ -218,5 +218,10 @@ TEST_CASE("DleEncoder" , "[DleEncoder]") {
REQUIRE(result == static_cast<int>(DleEncoder::DECODING_ERROR)); REQUIRE(result == static_cast<int>(DleEncoder::DECODING_ERROR));
dleEncoder.setEscapeMode(true); dleEncoder.setEscapeMode(true);
testArray1EncodedFaulty = TEST_ARRAY_1_ENCODED_ESCAPED;
testArray1EncodedFaulty[5] = 0;
result = dleEncoder.decode(testArray1EncodedFaulty.data(), testArray1EncodedFaulty.size(),
&readLen, buffer.data(), buffer.size(), &encodedLen);
REQUIRE(result == static_cast<int>(DleEncoder::DECODING_ERROR));
} }
} }

View File

@ -0,0 +1,3 @@
target_sources(${TARGET_NAME} PRIVATE
TestCountdown.cpp
)

View File

@ -0,0 +1,27 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/timemanager/Countdown.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE( "Countdown Tests", "[TestCountdown]") {
INFO("Countdown Tests");
Countdown count(20);
REQUIRE(count.timeout == 20);
REQUIRE(count.setTimeout(100) == static_cast<uint16_t>(HasReturnvaluesIF::RETURN_OK));
REQUIRE(count.timeout == 100);
REQUIRE(count.setTimeout(150) == static_cast<uint16_t>(HasReturnvaluesIF::RETURN_OK));
REQUIRE(count.isBusy());
REQUIRE(not count.hasTimedOut());
uint32_t number = count.getRemainingMillis();
REQUIRE(number > 0);
bool blocked = false;
while(not count.hasTimedOut()){
blocked = true;
};
REQUIRE(blocked);
number = count.getRemainingMillis();
REQUIRE(number==0);
count.resetTimer();
REQUIRE(not count.hasTimedOut());
REQUIRE(count.isBusy());
}