Merge branch 'development' into mueller/health_helper_bugfix

This commit is contained in:
Steffen Gaisser 2022-11-21 15:24:51 +01:00
commit 0958c3a00e
9 changed files with 39 additions and 29 deletions

View File

@ -32,6 +32,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Changes ## Changes
- Moved some container returnvalues to dedicated header and namespace
to they can be used without template specification.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/707
- Remove default secondary header argument for - Remove default secondary header argument for
`uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)` and `uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)` and
`uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)` `uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag)`

View File

@ -4,6 +4,7 @@
#include "../returnvalues/returnvalue.h" #include "../returnvalues/returnvalue.h"
#include "../serialize/SerializeAdapter.h" #include "../serialize/SerializeAdapter.h"
#include "../serialize/SerializeIF.h" #include "../serialize/SerializeIF.h"
#include "definitions.h"
/** /**
* @brief A List that stores its values in an array. * @brief A List that stores its values in an array.
@ -19,9 +20,6 @@ class ArrayList {
friend class SerialArrayListAdapter; friend class SerialArrayListAdapter;
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST;
static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01);
/** /**
* This is the allocating constructor. * This is the allocating constructor.
* It allocates an array of the specified size. * It allocates an array of the specified size.
@ -187,7 +185,7 @@ class ArrayList {
*/ */
ReturnValue_t insert(T entry) { ReturnValue_t insert(T entry) {
if (size >= maxSize_) { if (size >= maxSize_) {
return FULL; return containers::LIST_FULL;
} }
entries[size] = entry; entries[size] = entry;
++size; ++size;

View File

@ -4,8 +4,8 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include "../returnvalues/returnvalue.h"
#include "ArrayList.h" #include "ArrayList.h"
#include "definitions.h"
/** /**
* @brief Map implementation for maps with a pre-defined size. * @brief Map implementation for maps with a pre-defined size.
@ -24,11 +24,6 @@ class FixedMap : public SerializeIF {
"derived class from SerializeIF to be serialize-able"); "derived class from SerializeIF to be serialize-able");
public: public:
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 MAP_FULL = MAKE_RETURN_CODE(0x02);
static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03);
private: private:
static const key_t EMPTY_SLOT = -1; static const key_t EMPTY_SLOT = -1;
ArrayList<std::pair<key_t, T>, uint32_t> theMap; ArrayList<std::pair<key_t, T>, uint32_t> theMap;
@ -76,10 +71,10 @@ class FixedMap : public SerializeIF {
ReturnValue_t insert(key_t key, T value, Iterator* storedValue = nullptr) { ReturnValue_t insert(key_t key, T value, Iterator* storedValue = nullptr) {
if (exists(key) == returnvalue::OK) { if (exists(key) == returnvalue::OK) {
return KEY_ALREADY_EXISTS; return containers::KEY_ALREADY_EXISTS;
} }
if (_size == theMap.maxSize()) { if (_size == theMap.maxSize()) {
return MAP_FULL; return containers::MAP_FULL;
} }
theMap[_size].first = key; theMap[_size].first = key;
theMap[_size].second = value; theMap[_size].second = value;
@ -93,7 +88,7 @@ class FixedMap : public SerializeIF {
ReturnValue_t insert(std::pair<key_t, T> pair) { return insert(pair.first, pair.second); } ReturnValue_t insert(std::pair<key_t, T> pair) { return insert(pair.first, pair.second); }
ReturnValue_t exists(key_t key) const { ReturnValue_t exists(key_t key) const {
ReturnValue_t result = KEY_DOES_NOT_EXIST; ReturnValue_t result = containers::KEY_DOES_NOT_EXIST;
if (findIndex(key) < _size) { if (findIndex(key) < _size) {
result = returnvalue::OK; result = returnvalue::OK;
} }
@ -103,7 +98,7 @@ class FixedMap : public SerializeIF {
ReturnValue_t erase(Iterator* iter) { ReturnValue_t erase(Iterator* iter) {
uint32_t i; uint32_t i;
if ((i = findIndex((*iter).value->first)) >= _size) { if ((i = findIndex((*iter).value->first)) >= _size) {
return KEY_DOES_NOT_EXIST; return containers::KEY_DOES_NOT_EXIST;
} }
theMap[i] = theMap[_size - 1]; theMap[i] = theMap[_size - 1];
--_size; --_size;
@ -114,7 +109,7 @@ class FixedMap : public SerializeIF {
ReturnValue_t erase(key_t key) { ReturnValue_t erase(key_t key) {
uint32_t i; uint32_t i;
if ((i = findIndex(key)) >= _size) { if ((i = findIndex(key)) >= _size) {
return KEY_DOES_NOT_EXIST; return containers::KEY_DOES_NOT_EXIST;
} }
theMap[i] = theMap[_size - 1]; theMap[i] = theMap[_size - 1];
--_size; --_size;

View File

@ -0,0 +1,14 @@
#ifndef FSFW_CONTAINER_DEFINITIONS_H_
#define FSFW_CONTAINER_DEFINITIONS_H_
#include "fsfw/retval.h"
namespace containers {
static const ReturnValue_t KEY_ALREADY_EXISTS = returnvalue::makeCode(CLASS_ID::FIXED_MAP, 0x01);
static const ReturnValue_t MAP_FULL = returnvalue::makeCode(CLASS_ID::FIXED_MAP, 0x02);
static const ReturnValue_t KEY_DOES_NOT_EXIST = returnvalue::makeCode(CLASS_ID::FIXED_MAP, 0x03);
static const ReturnValue_t LIST_FULL = returnvalue::makeCode(CLASS_ID::ARRAY_LIST, 0x01);
} // namespace containers
#endif /* FSFW_CONTAINER_DEFINITIONS_H_ */

View File

@ -21,7 +21,7 @@ SpacePacketReader::~SpacePacketReader() = default;
inline uint16_t SpacePacketReader::getPacketIdRaw() const { return ccsds::getPacketId(*spHeader); } inline uint16_t SpacePacketReader::getPacketIdRaw() const { return ccsds::getPacketId(*spHeader); }
const uint8_t* SpacePacketReader::getPacketData() { return packetDataField; } const uint8_t* SpacePacketReader::getPacketData() const { return packetDataField; }
ReturnValue_t SpacePacketReader::setData(uint8_t* data, size_t maxSize_, void* args) { ReturnValue_t SpacePacketReader::setData(uint8_t* data, size_t maxSize_, void* args) {
return setInternalFields(data, maxSize_); return setInternalFields(data, maxSize_);

View File

@ -71,7 +71,7 @@ class SpacePacketReader : public SpacePacketIF,
// Helper methods: // Helper methods:
[[nodiscard]] ReturnValue_t checkSize() const; [[nodiscard]] ReturnValue_t checkSize() const;
const uint8_t* getPacketData(); const uint8_t* getPacketData() const;
ReturnValue_t setReadOnlyData(const uint8_t* data, size_t maxSize); ReturnValue_t setReadOnlyData(const uint8_t* data, size_t maxSize);

View File

@ -43,7 +43,7 @@ TEST_CASE("Array List", "[containers]") {
for (auto i = 0; i < 20; i++) { for (auto i = 0; i < 20; i++) {
REQUIRE(list.insert(i) == static_cast<int>(returnvalue::OK)); REQUIRE(list.insert(i) == static_cast<int>(returnvalue::OK));
} }
REQUIRE(list.insert(20) == static_cast<int>(ArrayList<uint16_t>::FULL)); REQUIRE(list.insert(20) == static_cast<int>(containers::LIST_FULL));
ArrayList<uint16_t>::Iterator it = list.begin(); ArrayList<uint16_t>::Iterator it = list.begin();
REQUIRE((*it) == 0); REQUIRE((*it) == 0);
it++; it++;

View File

@ -31,7 +31,7 @@ TEST_CASE("FixedArrayList Tests", "[containers]") {
for (auto i = 1; i < 260; i++) { for (auto i = 1; i < 260; i++) {
REQUIRE(list.insert(i) == static_cast<int>(returnvalue::OK)); REQUIRE(list.insert(i) == static_cast<int>(returnvalue::OK));
} }
REQUIRE(list.insert(260) == static_cast<int>(ArrayList<uint32_t, uint16_t>::FULL)); REQUIRE(list.insert(260) == static_cast<int>(containers::LIST_FULL));
list.clear(); list.clear();
REQUIRE(list.size == 0); REQUIRE(list.size == 0);
} }

View File

@ -7,6 +7,8 @@
template class FixedMap<unsigned int, unsigned short>; template class FixedMap<unsigned int, unsigned short>;
using namespace returnvalue;
TEST_CASE("FixedMap Tests", "[containers]") { TEST_CASE("FixedMap Tests", "[containers]") {
INFO("FixedMap Tests"); INFO("FixedMap Tests");
@ -24,9 +26,9 @@ TEST_CASE("FixedMap Tests", "[containers]") {
REQUIRE(map.find(i)->second == i + 1); REQUIRE(map.find(i)->second == i + 1);
REQUIRE(not map.empty()); REQUIRE(not map.empty());
} }
REQUIRE(map.insert(0, 0) == static_cast<int>(FixedMap<uint32_t, uint16_t>::KEY_ALREADY_EXISTS)); REQUIRE(map.insert(0, 0) == static_cast<int>(containers::KEY_ALREADY_EXISTS));
REQUIRE(map.insert(31, 0) == static_cast<int>(FixedMap<uint32_t, uint16_t>::MAP_FULL)); REQUIRE(map.insert(31, 0) == static_cast<int>(containers::MAP_FULL));
REQUIRE(map.exists(31) == static_cast<int>(FixedMap<uint32_t, uint16_t>::KEY_DOES_NOT_EXIST)); REQUIRE(map.exists(31) == static_cast<int>(containers::KEY_DOES_NOT_EXIST));
REQUIRE(map.size() == 30); REQUIRE(map.size() == 30);
REQUIRE(map.full()); REQUIRE(map.full());
{ {
@ -34,15 +36,14 @@ TEST_CASE("FixedMap Tests", "[containers]") {
REQUIRE(map.find(5, &ptr) == static_cast<int>(returnvalue::OK)); REQUIRE(map.find(5, &ptr) == static_cast<int>(returnvalue::OK));
REQUIRE(*ptr == 6); REQUIRE(*ptr == 6);
REQUIRE(*(map.findValue(6)) == 7); REQUIRE(*(map.findValue(6)) == 7);
REQUIRE(map.find(31, &ptr) == REQUIRE(map.find(31, &ptr) == static_cast<int>(containers::KEY_DOES_NOT_EXIST));
static_cast<int>(FixedMap<uint32_t, uint16_t>::KEY_DOES_NOT_EXIST));
} }
REQUIRE(map.getSerializedSize() == REQUIRE(map.getSerializedSize() ==
(sizeof(uint32_t) + 30 * (sizeof(uint32_t) + sizeof(uint16_t)))); (sizeof(uint32_t) + 30 * (sizeof(uint32_t) + sizeof(uint16_t))));
REQUIRE(map.erase(2) == static_cast<int>(returnvalue::OK)); REQUIRE(map.erase(2) == static_cast<int>(returnvalue::OK));
REQUIRE(map.erase(31) == static_cast<int>(FixedMap<uint32_t, uint16_t>::KEY_DOES_NOT_EXIST)); REQUIRE(map.erase(31) == static_cast<int>(containers::KEY_DOES_NOT_EXIST));
REQUIRE(map.exists(2) == static_cast<int>(FixedMap<uint32_t, uint16_t>::KEY_DOES_NOT_EXIST)); REQUIRE(map.exists(2) == static_cast<int>(containers::KEY_DOES_NOT_EXIST));
REQUIRE(map.size() == 29); REQUIRE(map.size() == 29);
for (auto element : map) { for (auto element : map) {
@ -79,8 +80,7 @@ TEST_CASE("FixedMap Tests", "[containers]") {
REQUIRE(map.insert(37, 38, nullptr) == static_cast<int>(returnvalue::OK)); REQUIRE(map.insert(37, 38, nullptr) == static_cast<int>(returnvalue::OK));
REQUIRE(map.find(37)->second == 38); REQUIRE(map.find(37)->second == 38);
REQUIRE(map.size() == 2); REQUIRE(map.size() == 2);
REQUIRE(map.insert(37, 24, nullptr) == REQUIRE(map.insert(37, 24, nullptr) == static_cast<int>(containers::KEY_ALREADY_EXISTS));
static_cast<int>(FixedMap<uint32_t, uint16_t>::KEY_ALREADY_EXISTS));
REQUIRE(map.find(37)->second != 24); REQUIRE(map.find(37)->second != 24);
REQUIRE(map.size() == 2); REQUIRE(map.size() == 2);
}; };
@ -137,7 +137,7 @@ TEST_CASE("FixedMap Tests", "[containers]") {
FixedMap<uint32_t, uint16_t>::Iterator it; FixedMap<uint32_t, uint16_t>::Iterator it;
std::pair<uint32_t, uint16_t> pair = std::make_pair(44, 43); std::pair<uint32_t, uint16_t> pair = std::make_pair(44, 43);
it = FixedMap<uint32_t, uint16_t>::Iterator(&pair); it = FixedMap<uint32_t, uint16_t>::Iterator(&pair);
REQUIRE(map.erase(&it) == static_cast<int>(FixedMap<uint32_t, uint16_t>::KEY_DOES_NOT_EXIST)); REQUIRE(map.erase(&it) == static_cast<int>(containers::KEY_DOES_NOT_EXIST));
REQUIRE(map.find(45) == map.end()); REQUIRE(map.find(45) == map.end());
size_t toLargeMap = 100; size_t toLargeMap = 100;
const uint8_t* ptr = reinterpret_cast<uint8_t*>(&toLargeMap); const uint8_t* ptr = reinterpret_cast<uint8_t*>(&toLargeMap);