run auto-formatter
This commit is contained in:
parent
c7b4dc349a
commit
f4beef8c9f
@ -4,7 +4,7 @@
|
|||||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||||
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
|
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
|
||||||
|
|
||||||
class CcsdsUnpacker: public ExecutableObjectIF, public AcceptsTelecommandsIF {
|
class CcsdsUnpacker : public ExecutableObjectIF, public AcceptsTelecommandsIF {
|
||||||
public:
|
public:
|
||||||
CcsdsUnpacker();
|
CcsdsUnpacker();
|
||||||
ReturnValue_t performOperation(uint8_t operationCode) override;
|
ReturnValue_t performOperation(uint8_t operationCode) override;
|
||||||
|
@ -1,57 +1,38 @@
|
|||||||
#ifndef FSFW_UTIL_OBJECTID_H
|
#ifndef FSFW_UTIL_OBJECTID_H
|
||||||
#define FSFW_UTIL_OBJECTID_H
|
#define FSFW_UTIL_OBJECTID_H
|
||||||
|
|
||||||
#include "fsfw/objectmanager.h"
|
|
||||||
#include "UnsignedByteField.h"
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
class ObjectId: public UnsignedByteField<object_id_t> {
|
#include "UnsignedByteField.h"
|
||||||
|
#include "fsfw/objectmanager.h"
|
||||||
|
|
||||||
|
class ObjectId : public UnsignedByteField<object_id_t> {
|
||||||
public:
|
public:
|
||||||
ObjectId(object_id_t id, const char* name): UnsignedByteField<object_id_t>(id), name_(name) {}
|
ObjectId(object_id_t id, const char* name) : UnsignedByteField<object_id_t>(id), name_(name) {}
|
||||||
|
|
||||||
[[nodiscard]] const char* name() const {
|
[[nodiscard]] const char* name() const { return name_; }
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] object_id_t id() const {
|
[[nodiscard]] object_id_t id() const { return getValue(); }
|
||||||
return getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const ObjectId& other) const {
|
bool operator==(const ObjectId& other) const { return id() == other.id(); }
|
||||||
return id() == other.id();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const ObjectId& other) const {
|
bool operator!=(const ObjectId& other) const { return id() != other.id(); }
|
||||||
return id() != other.id();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<(const ObjectId& other) const {
|
bool operator<(const ObjectId& other) const { return id() < other.id(); }
|
||||||
return id() < other.id();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator>(const ObjectId& other) const {
|
bool operator>(const ObjectId& other) const { return id() > other.id(); }
|
||||||
return id() > other.id();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator>=(const ObjectId& other) const {
|
bool operator>=(const ObjectId& other) const { return id() >= other.id(); }
|
||||||
return id() >= other.id();
|
|
||||||
}
|
bool operator<=(const ObjectId& other) const { return id() <= other.id(); }
|
||||||
|
|
||||||
bool operator<=(const ObjectId& other) const {
|
|
||||||
return id() <= other.id();
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
const char* name_;
|
const char* name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
struct std::hash<ObjectId>
|
struct std::hash<ObjectId> {
|
||||||
{
|
std::size_t operator()(ObjectId const& s) const noexcept { return std::hash<uint32_t>{}(s.id()); }
|
||||||
std::size_t operator()(ObjectId const& s) const noexcept
|
|
||||||
{
|
|
||||||
return std::hash<uint32_t>{}(s.id());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FSFW_UTIL_OBJECTID_H
|
#endif // FSFW_UTIL_OBJECTID_H
|
||||||
|
@ -3,50 +3,45 @@
|
|||||||
|
|
||||||
#include "fsfw/serialize.h"
|
#include "fsfw/serialize.h"
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
class UnsignedByteField: public SerializeIF {
|
class UnsignedByteField : public SerializeIF {
|
||||||
public:
|
public:
|
||||||
static_assert(std::is_unsigned<T>::value);
|
static_assert(std::is_unsigned<T>::value);
|
||||||
|
|
||||||
explicit UnsignedByteField(T value): value(value) {}
|
explicit UnsignedByteField(T value) : value(value) {}
|
||||||
[[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
[[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||||
Endianness streamEndianness) const override {
|
Endianness streamEndianness) const override {
|
||||||
return SerializeAdapter::serialize(&value, buffer, size, maxSize, streamEndianness);
|
return SerializeAdapter::serialize(&value, buffer, size, maxSize, streamEndianness);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||||
Endianness streamEndianness) override {
|
Endianness streamEndianness) override {
|
||||||
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
|
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] size_t getSerializedSize() const override {
|
[[nodiscard]] size_t getSerializedSize() const override { return sizeof(T); }
|
||||||
return sizeof(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] T getValue() const {
|
[[nodiscard]] T getValue() const { return value; }
|
||||||
return value;
|
|
||||||
}
|
void setValue(T value_) { value = value_; }
|
||||||
|
|
||||||
void setValue(T value_) {
|
|
||||||
value = value_;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
T value;
|
T value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class U32ByteField: public UnsignedByteField<uint32_t> {
|
class U32ByteField : public UnsignedByteField<uint32_t> {
|
||||||
public:
|
public:
|
||||||
explicit U32ByteField(uint32_t value): UnsignedByteField<uint32_t>(value) {}
|
explicit U32ByteField(uint32_t value) : UnsignedByteField<uint32_t>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class U16ByteField: public UnsignedByteField<uint16_t> {
|
class U16ByteField : public UnsignedByteField<uint16_t> {
|
||||||
public:
|
public:
|
||||||
explicit U16ByteField(uint16_t value): UnsignedByteField<uint16_t>(value) {}
|
explicit U16ByteField(uint16_t value) : UnsignedByteField<uint16_t>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class U8ByteField: public UnsignedByteField<uint8_t> {
|
class U8ByteField : public UnsignedByteField<uint8_t> {
|
||||||
public:
|
public:
|
||||||
explicit U8ByteField(uint8_t value): UnsignedByteField<uint8_t>(value) {}
|
explicit U8ByteField(uint8_t value) : UnsignedByteField<uint8_t>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FSFW_UTIL_UNSIGNEDBYTEFIELD_H
|
#endif // FSFW_UTIL_UNSIGNEDBYTEFIELD_H
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
|
#include <array>
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
#include "fsfw/util/ObjectId.h"
|
#include "fsfw/util/ObjectId.h"
|
||||||
#include <array>
|
|
||||||
|
|
||||||
TEST_CASE("Object Id", "[object-id]") {
|
TEST_CASE("Object Id", "[object-id]") {
|
||||||
auto objectId = ObjectId(10, "TEST_ID");
|
auto objectId = ObjectId(10, "TEST_ID");
|
||||||
std::map<ObjectId, int> testMap;
|
std::map<ObjectId, int> testMap;
|
||||||
|
|
||||||
SECTION("State") {
|
SECTION("State") {
|
||||||
CHECK(objectId.id() == 10);
|
CHECK(objectId.id() == 10);
|
||||||
CHECK(std::strcmp(objectId.name(), "TEST_ID") == 0);
|
CHECK(std::strcmp(objectId.name(), "TEST_ID") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("ID as map key") {
|
SECTION("ID as map key") {
|
||||||
auto insertPair = testMap.emplace(objectId, 10);
|
auto insertPair = testMap.emplace(objectId, 10);
|
||||||
CHECK(insertPair.second);
|
CHECK(insertPair.second);
|
||||||
auto iter = testMap.find(objectId);
|
auto iter = testMap.find(objectId);
|
||||||
CHECK(iter != testMap.end());
|
CHECK(iter != testMap.end());
|
||||||
CHECK(std::strcmp(iter->first.name(), "TEST_ID") == 0);
|
CHECK(std::strcmp(iter->first.name(), "TEST_ID") == 0);
|
||||||
CHECK(iter->second == 10);
|
CHECK(iter->second == 10);
|
||||||
auto otherIdSameName = ObjectId(12, "TEST_ID");
|
auto otherIdSameName = ObjectId(12, "TEST_ID");
|
||||||
insertPair = testMap.emplace(otherIdSameName, 10);
|
insertPair = testMap.emplace(otherIdSameName, 10);
|
||||||
CHECK(insertPair.second);
|
CHECK(insertPair.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
|
#include <array>
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
#include "fsfw/util/UnsignedByteField.h"
|
#include "fsfw/util/UnsignedByteField.h"
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
||||||
auto testByteField = UnsignedByteField<uint32_t>(10);
|
auto testByteField = UnsignedByteField<uint32_t>(10);
|
||||||
auto u32ByteField = U32ByteField(10);
|
auto u32ByteField = U32ByteField(10);
|
||||||
@ -28,7 +27,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Serialize U32") {
|
SECTION("Serialize U32") {
|
||||||
CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) ==
|
||||||
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
CHECK(serLen == 4);
|
CHECK(serLen == 4);
|
||||||
CHECK(buf[0] == 0);
|
CHECK(buf[0] == 0);
|
||||||
CHECK(buf[3] == 10);
|
CHECK(buf[3] == 10);
|
||||||
@ -60,7 +60,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
|||||||
buf[2] = 0x30;
|
buf[2] = 0x30;
|
||||||
buf[3] = 0x20;
|
buf[3] = 0x20;
|
||||||
size_t deserLen = 0;
|
size_t deserLen = 0;
|
||||||
CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) ==
|
||||||
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
CHECK(testByteField.getValue() == 0x50403020);
|
CHECK(testByteField.getValue() == 0x50403020);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
|||||||
buf[0] = 0x50;
|
buf[0] = 0x50;
|
||||||
buf[1] = 0x40;
|
buf[1] = 0x40;
|
||||||
size_t deserLen = 0;
|
size_t deserLen = 0;
|
||||||
CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) ==
|
||||||
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
CHECK(u16ByteField.getValue() == 0x5040);
|
CHECK(u16ByteField.getValue() == 0x5040);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user