Merge pull request 'Fixes for #190 and #189' (#191) from gaisser/fsfw:gaisser_bugs_fixedMap_FIFO into master

Reviewed-on: fsfw/fsfw#191
This commit is contained in:
Robin Müller 2020-09-10 15:00:34 +02:00
commit a364f36f38
4 changed files with 45 additions and 4 deletions

View File

@ -27,14 +27,27 @@ public:
/** /**
* @brief Custom copy constructor which prevents setting the * @brief Custom copy constructor which prevents setting the
* underlying pointer wrong. * underlying pointer wrong. This function allocates memory!
* @details This is a very heavy operation so try to avoid this!
*
*/ */
DynamicFIFO(const DynamicFIFO& other): FIFOBase<T>(other), DynamicFIFO(const DynamicFIFO& other): FIFOBase<T>(other),
fifoVector(other.maxCapacity) { fifoVector(other.maxCapacity) {
this->fifoVector = other.fifoVector;
this->setContainer(fifoVector.data()); this->setContainer(fifoVector.data());
} }
/**
* @brief Custom assignment operator
* @details This is a very heavy operation so try to avoid this!
* @param other DyamicFIFO to copy from
*/
DynamicFIFO& operator=(const DynamicFIFO& other){
FIFOBase<T>::operator=(other);
this->fifoVector = other.fifoVector;
this->setContainer(fifoVector.data());
return *this;
}
private: private:
std::vector<T> fifoVector; std::vector<T> fifoVector;
}; };

View File

@ -25,9 +25,21 @@ public:
* @param other * @param other
*/ */
FIFO(const FIFO& other): FIFOBase<T>(other) { FIFO(const FIFO& other): FIFOBase<T>(other) {
this->fifoArray = other.fifoArray;
this->setContainer(fifoArray.data()); this->setContainer(fifoArray.data());
} }
/**
* @brief Custom assignment operator
* @param other
*/
FIFO& operator=(const FIFO& other){
FIFOBase<T>::operator=(other);
this->fifoArray = other.fifoArray;
this->setContainer(fifoArray.data());
return *this;
}
private: private:
std::array<T, capacity> fifoArray; std::array<T, capacity> fifoArray;
}; };

View File

@ -4,12 +4,15 @@
#include "ArrayList.h" #include "ArrayList.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include <utility> #include <utility>
#include <type_traits>
/** /**
* \ingroup container * \ingroup container
*/ */
template<typename key_t, typename T> template<typename key_t, typename T>
class FixedMap: public SerializeIF { class FixedMap: public SerializeIF {
static_assert (std::is_trivially_copyable<T>::value or std::is_base_of<SerializeIF, T>::value,
"Types used in FixedMap must either be trivial copy-able or a derived Class from SerializeIF to be serialize-able");
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP;
static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01);

View File

@ -211,8 +211,7 @@ protected:
virtual void doPeriodicOperation(); virtual void doPeriodicOperation();
struct CommandInfo: public SerializeIF{
struct CommandInfo {
struct tcInfo { struct tcInfo {
uint8_t ackFlags; uint8_t ackFlags;
uint16_t tcPacketId; uint16_t tcPacketId;
@ -225,6 +224,20 @@ protected:
Command_t command; Command_t command;
object_id_t objectId; object_id_t objectId;
FIFO<store_address_t, 3> fifo; FIFO<store_address_t, 3> fifo;
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
size_t maxSize, Endianness streamEndianness) const override{
return HasReturnvaluesIF::RETURN_FAILED;
};
virtual size_t getSerializedSize() const override {
return 0;
};
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override{
return HasReturnvaluesIF::RETURN_FAILED;
};
}; };
using CommandMapIter = FixedMap<MessageQueueId_t, using CommandMapIter = FixedMap<MessageQueueId_t,