Compare commits
14 Commits
mueller/re
...
mueller/da
Author | SHA1 | Date | |
---|---|---|---|
20f0707813 | |||
8d1777fa0c | |||
d675a789a2 | |||
192255df1c | |||
bdd79d060d | |||
c756297e5c | |||
0f27c7e7e7 | |||
20d42add03 | |||
6c2b5ab39e | |||
a7039bad41 | |||
6605ffb6b1 | |||
e2e0190cae | |||
fd278e410b | |||
ff4cbea571 |
@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
# [v6.0.0]
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
|
||||||
- Removed `HasReturnvaluesIF` class in favor of `returnvalue` namespace with `OK` and `FAILED`
|
- Removed `HasReturnvaluesIF` class in favor of `returnvalue` namespace with `OK` and `FAILED`
|
||||||
@ -16,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Added
|
## Added
|
||||||
|
|
||||||
|
- Add `util::DataWrapper` class inside the `util` module. This is a tagged union which allows
|
||||||
|
to specify raw data either as a classic C-style raw pointer and size or as a `SerializeIF`
|
||||||
|
pointer.
|
||||||
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/668
|
||||||
- Add new `UnsignedByteField` class
|
- Add new `UnsignedByteField` class
|
||||||
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/660
|
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/660
|
||||||
|
|
||||||
|
@ -3,6 +3,11 @@ if [[ ! -f README.md ]]; then
|
|||||||
cd ..
|
cd ..
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
folder_list=(
|
||||||
|
"./src"
|
||||||
|
"./unittests"
|
||||||
|
)
|
||||||
|
|
||||||
cmake_fmt="cmake-format"
|
cmake_fmt="cmake-format"
|
||||||
file_selectors="-iname CMakeLists.txt"
|
file_selectors="-iname CMakeLists.txt"
|
||||||
if command -v ${cmake_fmt} &> /dev/null; then
|
if command -v ${cmake_fmt} &> /dev/null; then
|
||||||
@ -15,8 +20,10 @@ fi
|
|||||||
cpp_format="clang-format"
|
cpp_format="clang-format"
|
||||||
file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp"
|
file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp"
|
||||||
if command -v ${cpp_format} &> /dev/null; then
|
if command -v ${cpp_format} &> /dev/null; then
|
||||||
find ./src ${file_selectors} | xargs ${cpp_format} --style=file -i
|
for dir in ${folder_list[@]}; do
|
||||||
find ./unittests ${file_selectors} | xargs ${cpp_format} --style=file -i
|
echo "Auto-formatting ${dir} recursively"
|
||||||
|
find ${dir} ${file_selectors} | xargs clang-format --style=file -i
|
||||||
|
done
|
||||||
else
|
else
|
||||||
echo "No ${cpp_format} tool found, not formatting C++/C files"
|
echo "No ${cpp_format} tool found, not formatting C++/C files"
|
||||||
fi
|
fi
|
||||||
|
@ -588,10 +588,11 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// additional security check, this should never be true
|
// additional security check, this should never be true
|
||||||
if (itBegin->first > itEnd->first) {
|
if (itBegin > itEnd) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "11::getMapFilterFromData: itBegin > itEnd\n" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printError("11::GetMapFilterFromData: itBegin > itEnd\n");
|
sif::printError("11::getMapFilterFromData: itBegin > itEnd\n");
|
||||||
#endif
|
#endif
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
|
76
src/fsfw/util/dataWrapper.h
Normal file
76
src/fsfw/util/dataWrapper.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#ifndef FSFW_UTIL_DATAWRAPPER_H
|
||||||
|
#define FSFW_UTIL_DATAWRAPPER_H
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "fsfw/serialize.h"
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
using BufPair = std::pair<const uint8_t*, size_t>;
|
||||||
|
|
||||||
|
struct RawData {
|
||||||
|
RawData() = default;
|
||||||
|
const uint8_t* data = nullptr;
|
||||||
|
size_t len = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DataTypes { NONE, RAW, SERIALIZABLE };
|
||||||
|
|
||||||
|
union DataUnion {
|
||||||
|
RawData raw{};
|
||||||
|
SerializeIF* serializable;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DataWrapper {
|
||||||
|
|
||||||
|
DataWrapper() = default;
|
||||||
|
|
||||||
|
DataWrapper(const uint8_t* data, size_t size): type(DataTypes::RAW) {
|
||||||
|
setRawData({data, size});
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit DataWrapper(BufPair raw): type(DataTypes::RAW) {
|
||||||
|
setRawData(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit DataWrapper(SerializeIF& serializable): type(DataTypes::SERIALIZABLE) {
|
||||||
|
setSerializable(serializable);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataTypes type = DataTypes::NONE;
|
||||||
|
DataUnion dataUnion;
|
||||||
|
|
||||||
|
[[nodiscard]] size_t getLength() const {
|
||||||
|
if (type == DataTypes::RAW) {
|
||||||
|
return dataUnion.raw.len;
|
||||||
|
} else if (type == DataTypes::SERIALIZABLE and dataUnion.serializable != nullptr) {
|
||||||
|
return dataUnion.serializable->getSerializedSize();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool isNull() const {
|
||||||
|
if ((type == DataTypes::NONE) or (type == DataTypes::RAW and dataUnion.raw.data == nullptr) or
|
||||||
|
(type == DataTypes::SERIALIZABLE and dataUnion.serializable == nullptr)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void setRawData(BufPair bufPair) {
|
||||||
|
type = DataTypes::RAW;
|
||||||
|
dataUnion.raw.data = bufPair.first;
|
||||||
|
dataUnion.raw.len = bufPair.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSerializable(SerializeIF& serializable) {
|
||||||
|
type = DataTypes::SERIALIZABLE;
|
||||||
|
dataUnion.serializable = &serializable;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
|
||||||
|
#endif // FSFW_UTIL_DATAWRAPPER_H
|
@ -1,3 +1,4 @@
|
|||||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||||
testUnsignedByteField.cpp
|
testUnsignedByteField.cpp
|
||||||
|
testDataWrapper.cpp
|
||||||
)
|
)
|
||||||
|
59
unittests/util/testDataWrapper.cpp
Normal file
59
unittests/util/testDataWrapper.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include <array>
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
#include "fsfw/util/dataWrapper.h"
|
||||||
|
#include "mocks/SimpleSerializable.h"
|
||||||
|
|
||||||
|
TEST_CASE("Data Wrapper", "[util]") {
|
||||||
|
util::DataWrapper wrapper;
|
||||||
|
SECTION("State") {
|
||||||
|
REQUIRE(wrapper.isNull());
|
||||||
|
REQUIRE(wrapper.type == util::DataTypes::NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Set Raw Data") {
|
||||||
|
util::DataWrapper* instance = &wrapper;
|
||||||
|
bool deleteInst = false;
|
||||||
|
REQUIRE(wrapper.isNull());
|
||||||
|
std::array<uint8_t, 4> data = {1, 2, 3, 4};
|
||||||
|
SECTION("Setter") {
|
||||||
|
wrapper.setRawData({data.data(), data.size()});
|
||||||
|
}
|
||||||
|
SECTION("Direct Construction Pair") {
|
||||||
|
instance = new util::DataWrapper(util::BufPair(data.data(), data.size()));
|
||||||
|
deleteInst = true;
|
||||||
|
}
|
||||||
|
SECTION("Direct Construction Single Args") {
|
||||||
|
instance = new util::DataWrapper(data.data(), data.size());
|
||||||
|
deleteInst = true;
|
||||||
|
}
|
||||||
|
REQUIRE(not instance->isNull());
|
||||||
|
REQUIRE(instance->type == util::DataTypes::RAW);
|
||||||
|
REQUIRE(instance->dataUnion.raw.data == data.data());
|
||||||
|
REQUIRE(instance->dataUnion.raw.len == data.size());
|
||||||
|
if(deleteInst) {
|
||||||
|
delete instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Simple Serializable") {
|
||||||
|
util::DataWrapper* instance = &wrapper;
|
||||||
|
bool deleteInst = false;
|
||||||
|
REQUIRE(instance->isNull());
|
||||||
|
SimpleSerializable serializable;
|
||||||
|
SECTION("Setter") {
|
||||||
|
wrapper.setSerializable(serializable);
|
||||||
|
}
|
||||||
|
SECTION("Direct Construction") {
|
||||||
|
instance = new util::DataWrapper(serializable);
|
||||||
|
deleteInst = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
REQUIRE(not instance->isNull());
|
||||||
|
REQUIRE(instance->type == util::DataTypes::SERIALIZABLE);
|
||||||
|
REQUIRE(instance->dataUnion.serializable == &serializable);
|
||||||
|
if(deleteInst) {
|
||||||
|
delete instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "fsfw/util/UnsignedByteField.h"
|
#include "fsfw/util/UnsignedByteField.h"
|
||||||
|
|
||||||
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
TEST_CASE("Unsigned Byte Field", "[util]") {
|
||||||
auto testByteField = UnsignedByteField<uint32_t>(10);
|
auto testByteField = UnsignedByteField<uint32_t>(10);
|
||||||
auto u32ByteField = U32ByteField(10);
|
auto u32ByteField = U32ByteField(10);
|
||||||
auto u16ByteField = U16ByteField(5);
|
auto u16ByteField = U16ByteField(5);
|
||||||
|
Reference in New Issue
Block a user