fifo replacements

This commit is contained in:
Robin Müller 2020-07-07 17:42:37 +02:00
parent dd48f7ccad
commit 399fc0e287
10 changed files with 48 additions and 61 deletions

27
container/DynamicFIFO.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef FRAMEWORK_CONTAINER_DYNAMICFIFO_H_
#define FRAMEWORK_CONTAINER_DYNAMICFIFO_H_
#include <framework/container/FIFOBase.h>
#include <vector>
/**
* @brief Simple First-In-First-Out data structure. The maximum size
* can be set in the constructor.
* @details
* The maximum capacity can be determined at run-time, so this container
* performs dynamic memory allocation!
* The public interface of FIFOBase exposes the user interface for the FIFO.
* @tparam T Entry Type
* @tparam capacity Maximum capacity
*/
template<typename T>
class DynamicFIFO: public FIFOBase<T> {
public:
DynamicFIFO(size_t maxCapacity): FIFOBase<T>(values.data(), maxCapacity),
values(maxCapacity) {};
private:
std::vector<T> values;
};
#endif /* FRAMEWORK_CONTAINER_DYNAMICFIFO_H_ */

View File

@ -1,31 +1,26 @@
#ifndef FRAMEWORK_CONTAINER_FIFO_H_
#define FRAMEWORK_CONTAINER_FIFO_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/container/FIFOBase.h>
#include <vector>
namespace fsfw {
#include <array>
/**
* @brief Simple First-In-First-Out data structure. The maximum size
* can be set in the constructor.
* @brief Simple First-In-First-Out data structure with size fixed at
* compile time
* @details
* The maximum capacity can be determined at run-time, so this container
* performs dynamic memory allocation!
* Performs no dynamic memory allocation.
* The public interface of FIFOBase exposes the user interface for the FIFO.
* @tparam T Entry Type
* @tparam capacity Maximum capacity
*/
template<typename T>
template<typename T, size_t capacity>
class FIFO: public FIFOBase<T> {
public:
FIFO(size_t maxCapacity): FIFOBase<T>(values.data(), maxCapacity),
values(maxCapacity) {};
FIFO(): FIFOBase<T>(values.data(), capacity) {};
private:
std::vector<T> values;
std::array<T, capacity> values;
};
}
#endif /* FRAMEWORK_CONTAINER_FIFO_H_ */
#endif /* FRAMEWORK_CONTAINERS_STATICFIFO_H_ */

View File

@ -4,8 +4,6 @@
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <cstddef>
namespace fsfw {
template <typename T>
class FIFOBase {
public:
@ -60,6 +58,4 @@ private:
#include <framework/container/FIFOBase.tpp>
}
#endif /* FRAMEWORK_CONTAINER_FIFOBASE_H_ */

View File

@ -17,7 +17,7 @@ SimpleRingBuffer::~SimpleRingBuffer() {
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
uint32_t amount) {
if (availableWriteSpace() >= amount || overwriteOld) {
if (availableWriteSpace() >= amount or overwriteOld) {
uint32_t amountTillWrap = writeTillWrap();
if (amountTillWrap >= amount) {
memcpy(&buffer[write], data, amount);
@ -43,7 +43,7 @@ ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, uint32_t amount,
return HasReturnvaluesIF::RETURN_FAILED;
}
}
if (trueAmount != NULL) {
if (trueAmount != nullptr) {
*trueAmount = amount;
}
if (amountTillWrap >= amount) {
@ -65,7 +65,7 @@ ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
return HasReturnvaluesIF::RETURN_FAILED;
}
}
if (trueAmount != NULL) {
if (trueAmount != nullptr) {
*trueAmount = amount;
}
incrementRead(amount, READ_PTR);

View File

@ -2,7 +2,7 @@
#define FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_
#include <framework/container/RingBufferBase.h>
#include <stddef.h>
#include <cstddef>
/**
* @brief Circular buffer implementation, useful for buffering

View File

@ -1,30 +0,0 @@
#ifndef FRAMEWORK_CONTAINER_STATICFIFO_H_
#define FRAMEWORK_CONTAINER_STATICFIFO_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/container/FIFOBase.h>
#include <array>
namespace fsfw {
/**
* @brief Simple First-In-First-Out data structure with size fixed at
* compile time
* @details
* Performs no dynamic memory allocation.
* The public interface of FIFOBase exposes the user interface for the FIFO.
* @tparam T Entry Type
* @tparam capacity Maximum capacity
*/
template<typename T, size_t capacity>
class StaticFIFO: public FIFOBase<T> {
public:
StaticFIFO(): FIFOBase<T>(values.data(), capacity) {};
private:
std::array<T, capacity> values;
};
}
#endif /* FRAMEWORK_CONTAINERS_STATICFIFO_H_ */

View File

@ -10,7 +10,7 @@
#include <framework/tmtcservices/VerificationReporter.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/container/FixedMap.h>
#include <framework/container/StaticFIFO.h>
#include <framework/container/FIFO.h>
#include <framework/serialize/SerializeIF.h>
class TcPacketStored;
@ -199,7 +199,7 @@ protected:
uint32_t state;
Command_t command;
object_id_t objectId;
fsfw::StaticFIFO<store_address_t, 3> fifo;
FIFO<store_address_t, 3> fifo;
};
using CommandMapIter = FixedMap<MessageQueueId_t,

View File

@ -64,7 +64,7 @@ ReturnValue_t PusParser::readMultiplePackets(const uint8_t *frame,
return HasReturnvaluesIF::RETURN_OK;
}
fsfw::FIFO<PusParser::indexSizePair>* PusParser::fifo(){
DynamicFIFO<PusParser::indexSizePair>* PusParser::fifo(){
return &indexSizePairFIFO;
}

View File

@ -1,8 +1,7 @@
#ifndef FRAMEWORK_TMTCSERVICES_PUSPARSER_H_
#define FRAMEWORK_TMTCSERVICES_PUSPARSER_H_
#include <framework/container/FIFO.h>
#include <framework/container/DynamicFIFO.h>
#include <utility>
#include <cstdint>
@ -55,7 +54,7 @@ public:
* by the parsePusPackets() function.
* @return
*/
fsfw::FIFO<indexSizePair>* fifo();
DynamicFIFO<indexSizePair>* fifo();
/**
* Retrieve the next index and packet size pair from the FIFO.
@ -69,7 +68,7 @@ private:
//! A FIFO is used to store information about multiple PUS packets
//! inside the receive buffer. The maximum number of entries is defined
//! by the first constructor argument.
fsfw::FIFO<indexSizePair> indexSizePairFIFO;
DynamicFIFO<indexSizePair> indexSizePairFIFO;
bool storeSplitPackets = false;

View File

@ -1,6 +1,7 @@
#ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#include <framework/container/FIFO.h>
#include <framework/tmtcservices/AcceptsTelemetryIF.h>
#include <framework/tasks/ExecutableObjectIF.h>
#include <framework/ipc/MessageQueueIF.h>
@ -8,7 +9,6 @@
#include <framework/objectmanager/SystemObject.h>
#include <framework/tmtcservices/TmTcMessage.h>
#include <framework/container/StaticFIFO.h>
class TmTcBridge : public AcceptsTelemetryIF,
public ExecutableObjectIF,
@ -143,7 +143,7 @@ protected:
* This fifo can be used to store downlink data
* which can not be sent at the moment.
*/
fsfw::StaticFIFO<store_address_t, LIMIT_DOWNLINK_PACKETS_STORED> tmFifo;
FIFO<store_address_t, LIMIT_DOWNLINK_PACKETS_STORED> tmFifo;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
};