apply auto-formatter

This commit is contained in:
Robin Müller 2022-07-18 16:07:26 +02:00
parent 490a80e49f
commit ddf38b65c3
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
32 changed files with 242 additions and 192 deletions

View File

@ -104,8 +104,8 @@ if(FSFW_GENERATE_SECTIONS)
option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON)
endif()
option(FSFW_BUILD_TESTS
"Build unittest binary in addition to static library" OFF)
option(FSFW_BUILD_TESTS "Build unittest binary in addition to static library"
OFF)
option(FSFW_CICD_BUILD "Build for CI/CD. This can disable problematic test" OFF)
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
if(FSFW_BUILD_TESTS)

View File

@ -16,8 +16,7 @@ cpp_format="clang-format"
file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp"
if command -v ${cpp_format} &> /dev/null; then
find ./src ${file_selectors} | xargs ${cpp_format} --style=file -i
find ./hal ${file_selectors} | xargs ${cpp_format} --style=file -i
find ./tests ${file_selectors} | xargs ${cpp_format} --style=file -i
find ./unittests ${file_selectors} | xargs ${cpp_format} --style=file -i
else
echo "No ${cpp_format} tool found, not formatting C++/C files"
fi

View File

@ -2,54 +2,75 @@
#include "fsfw/serialize/SerializeAdapter.h"
SpacePacketCreator::SpacePacketCreator(uint16_t packetId_, uint16_t packetSeqCtrl_,
uint16_t dataLen_, uint8_t version_) {
packetId = packetId_;
packetSeqCtrl = packetSeqCtrl_;
SpacePacketCreator::SpacePacketCreator(PacketId packetId_, PacketSeqCtrl psc_, uint16_t dataLen_,
uint8_t version_)
: packetId(packetId_), packetSeqCtrl(psc_) {
dataLen = dataLen_;
version = version_;
valid = true;
checkFieldValidity();
}
SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag,
uint16_t apid, ccsds::SequenceFlags seqFlags,
uint16_t seqCount, uint16_t dataLen_, uint8_t version_) {
if (apid > ccsds::LIMIT_APID) {
valid = false;
return;
}
if (seqCount > ccsds::LIMIT_SEQUENCE_COUNT) {
valid = false;
return;
}
uint16_t seqCount, uint16_t dataLen_, uint8_t version_)
: SpacePacketCreator(PacketId(packetType, secHeaderFlag, apid),
PacketSeqCtrl(seqFlags, seqCount), dataLen_, version_) {
version = version_;
packetId = (static_cast<uint16_t>(packetType) << 12) | (static_cast<uint16_t>(secHeaderFlag) << 11) | apid;
packetSeqCtrl = static_cast<uint8_t>(seqFlags) << 14 | seqCount;
dataLen = dataLen_;
}
uint16_t SpacePacketCreator::getPacketId() const { return packetId; }
uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return packetSeqCtrl; }
uint16_t SpacePacketCreator::getPacketId() const { return packetId.raw(); }
uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return packetSeqCtrl.raw(); }
uint16_t SpacePacketCreator::getPacketDataLen() const { return dataLen; }
ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
uint16_t packetIdAndVersion = version << 13 | packetId;
if (not isValid()) {
return HasReturnvaluesIF::RETURN_FAILED;
}
uint16_t packetIdAndVersion = (static_cast<uint16_t>(version) << 13) | packetId.raw();
ReturnValue_t result =
SerializeAdapter::serialize(&packetIdAndVersion, buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&packetSeqCtrl, buffer, size, maxSize, streamEndianness);
uint16_t pscRaw = packetSeqCtrl.raw();
result = SerializeAdapter::serialize(&pscRaw, buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return SerializeAdapter::serialize(&dataLen, buffer, size, maxSize, streamEndianness);
}
size_t SpacePacketCreator::getSerializedSize() const { return 0; }
size_t SpacePacketCreator::getSerializedSize() const { return 6; }
ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) {
return HasReturnvaluesIF::RETURN_FAILED;
}
bool SpacePacketCreator::isValid() const { return valid; }
ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
void SpacePacketCreator::setApid(uint16_t apid) {
if (apid < ccsds::LIMIT_APID) {
packetId.apid = apid;
}
checkFieldValidity();
}
void SpacePacketCreator::setSeqCount(uint16_t seqCount) {
if (seqCount < ccsds::LIMIT_SEQUENCE_COUNT) {
packetSeqCtrl.seqCount = seqCount;
}
checkFieldValidity();
}
void SpacePacketCreator::setSeqFlags(ccsds::SequenceFlags flags) { packetSeqCtrl.seqFlags = flags; }
void SpacePacketCreator::setDataLen(uint16_t dataLen_) { dataLen = dataLen_; }
void SpacePacketCreator::checkFieldValidity() {
valid = true;
if (packetId.apid > ccsds::LIMIT_APID or packetSeqCtrl.seqCount > ccsds::LIMIT_SEQUENCE_COUNT) {
valid = false;
}
}

View File

@ -4,27 +4,77 @@
#include "SpacePacketIF.h"
#include "fsfw/serialize/SerializeIF.h"
struct PacketId {
public:
/**
* Simple wrapper for Space Packet IDs. Does not check the APID for validity
* @param packetType_
* @param secHeaderFlag_
* @param apid_
*/
PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_)
: packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {}
/**
* NOTE: If the APID has an invalid value, the invalid bits will be cut off
* @return
*/
[[nodiscard]] uint16_t raw() const {
return (static_cast<uint16_t>(packetType) << 12) |
(static_cast<uint16_t>(secHeaderFlag) << 11) | (apid & 0x7ff);
}
ccsds::PacketType packetType;
bool secHeaderFlag;
uint16_t apid;
};
struct PacketSeqCtrl {
public:
PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount)
: seqFlags(seqFlags), seqCount(seqCount) {}
/**
* NOTE: If the sequence control has an invalid value, the invalid bits will be cut off
* @return
*/
[[nodiscard]] uint16_t raw() const {
return (static_cast<uint16_t>(seqFlags) << 14) | (seqCount & 0x3FFF);
}
ccsds::SequenceFlags seqFlags;
uint16_t seqCount;
};
class SpacePacketCreator : public SerializeIF, public SpacePacketIF {
public:
SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid,
ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen,
uint8_t version = 0);
SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t dataLen,
uint8_t version = 0);
SpacePacketCreator(PacketId packetId, PacketSeqCtrl psc, uint16_t dataLen, uint8_t version = 0);
[[nodiscard]] bool isValid() const;
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
void setApid(uint16_t apid);
void setSeqCount(uint16_t seqCount);
void setSeqFlags(ccsds::SequenceFlags flags);
void setDataLen(uint16_t dataLen);
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const;
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
[[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
private:
bool valid;
uint16_t packetId;
uint16_t packetSeqCtrl;
void checkFieldValidity();
bool valid{};
PacketId packetId;
PacketSeqCtrl packetSeqCtrl;
uint16_t dataLen;
uint8_t version;
};

View File

@ -2,9 +2,9 @@ add_subdirectory(devicehandlers)
add_subdirectory(common)
if(UNIX)
add_subdirectory(linux)
add_subdirectory(linux)
endif()
if(FSFW_HAL_ADD_STM32H7)
add_subdirectory(stm32h7)
add_subdirectory(stm32h7)
endif()

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GpioCookie.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE GpioCookie.cpp)

View File

@ -1,5 +1,3 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GyroL3GD20Handler.cpp
MgmRM3100Handler.cpp
MgmLIS3MDLHandler.cpp
)
target_sources(
${LIB_FSFW_NAME} PRIVATE GyroL3GD20Handler.cpp MgmRM3100Handler.cpp
MgmLIS3MDLHandler.cpp)

View File

@ -1,25 +1,21 @@
if(FSFW_HAL_ADD_RASPBERRY_PI)
add_subdirectory(rpi)
add_subdirectory(rpi)
endif()
target_sources(${LIB_FSFW_NAME} PRIVATE
UnixFileGuard.cpp
CommandExecutor.cpp
utility.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE UnixFileGuard.cpp CommandExecutor.cpp
utility.cpp)
if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS)
if(FSFW_HAL_LINUX_ADD_LIBGPIOD)
add_subdirectory(gpio)
endif()
add_subdirectory(uart)
# Adding those does not really make sense on Apple systems which
# are generally host systems. It won't even compile as the headers
# are missing
if(NOT APPLE)
add_subdirectory(i2c)
add_subdirectory(spi)
endif()
if(FSFW_HAL_LINUX_ADD_LIBGPIOD)
add_subdirectory(gpio)
endif()
add_subdirectory(uart)
# Adding those does not really make sense on Apple systems which are generally
# host systems. It won't even compile as the headers are missing
if(NOT APPLE)
add_subdirectory(i2c)
add_subdirectory(spi)
endif()
endif()
add_subdirectory(uio)

View File

@ -1,16 +1,12 @@
# This abstraction layer requires the gpiod library. You can install this library
# with "sudo apt-get install -y libgpiod-dev". If you are cross-compiling, you need
# to install the package before syncing the sysroot to your host computer.
# This abstraction layer requires the gpiod library. You can install this
# library with "sudo apt-get install -y libgpiod-dev". If you are
# cross-compiling, you need to install the package before syncing the sysroot to
# your host computer.
find_library(LIB_GPIO gpiod)
if(${LIB_GPIO} MATCHES LIB_GPIO-NOTFOUND)
message(STATUS "gpiod library not found, not linking against it")
message(STATUS "gpiod library not found, not linking against it")
else()
target_sources(${LIB_FSFW_NAME} PRIVATE
LinuxLibgpioIF.cpp
)
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
${LIB_GPIO}
)
target_sources(${LIB_FSFW_NAME} PRIVATE LinuxLibgpioIF.cpp)
target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${LIB_GPIO})
endif()

View File

@ -1,8 +1 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
I2cComIF.cpp
I2cCookie.cpp
)
target_sources(${LIB_FSFW_NAME} PUBLIC I2cComIF.cpp I2cCookie.cpp)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GpioRPi.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE GpioRPi.cpp)

View File

@ -1,8 +1 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
SpiComIF.cpp
SpiCookie.cpp
)
target_sources(${LIB_FSFW_NAME} PUBLIC SpiComIF.cpp SpiCookie.cpp)

View File

@ -1,4 +1 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
UartComIF.cpp
UartCookie.cpp
)
target_sources(${LIB_FSFW_NAME} PUBLIC UartComIF.cpp UartCookie.cpp)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
UioMapper.cpp
)
target_sources(${LIB_FSFW_NAME} PUBLIC UioMapper.cpp)

View File

@ -2,6 +2,4 @@ add_subdirectory(spi)
add_subdirectory(gpio)
add_subdirectory(devicetest)
target_sources(${LIB_FSFW_NAME} PRIVATE
dma.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE dma.cpp)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GyroL3GD20H.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE GyroL3GD20H.cpp)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
gpio.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE gpio.cpp)

View File

@ -1,2 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
)
target_sources(${LIB_FSFW_NAME} PRIVATE)

View File

@ -1,9 +1,9 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
spiCore.cpp
spiDefinitions.cpp
spiInterrupts.cpp
mspInit.cpp
SpiCookie.cpp
SpiComIF.cpp
stm32h743zi.cpp
)
target_sources(
${LIB_FSFW_NAME}
PRIVATE spiCore.cpp
spiDefinitions.cpp
spiInterrupts.cpp
mspInit.cpp
SpiCookie.cpp
SpiComIF.cpp
stm32h743zi.cpp)

View File

@ -1,2 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
)
target_sources(${LIB_FSFW_NAME} PRIVATE)

View File

@ -1,7 +1,7 @@
if(FSFW_ADD_INTERNAL_TESTS)
add_subdirectory(internal)
add_subdirectory(internal)
endif()
if(NOT FSFW_BUILD_TESTS)
add_subdirectory(integration)
add_subdirectory(integration)
endif()

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
TestAssembly.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE TestAssembly.cpp)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
TestController.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE TestController.cpp)

View File

@ -1,5 +1,2 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
TestCookie.cpp
TestDeviceHandler.cpp
TestEchoComIF.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE TestCookie.cpp TestDeviceHandler.cpp
TestEchoComIF.cpp)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
TestTask.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE TestTask.cpp)

View File

@ -1,8 +1,6 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
InternalUnitTester.cpp
UnittDefinitions.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE InternalUnitTester.cpp
UnittDefinitions.cpp)
add_subdirectory(osal)
add_subdirectory(serialize)
add_subdirectory(globalfunctions)
add_subdirectory(globalfunctions)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
TestArrayPrinter.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE TestArrayPrinter.cpp)

View File

@ -1,5 +1,2 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
testMq.cpp
testMutex.cpp
testSemaphore.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE testMq.cpp testMutex.cpp
testSemaphore.cpp)

View File

@ -1,3 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
IntTestSerialization.cpp
)
target_sources(${LIB_FSFW_NAME} PRIVATE IntTestSerialization.cpp)

View File

@ -1,3 +1,3 @@
target_sources(${FSFW_TEST_TGT} PRIVATE
testCcsds.cpp
testCcsdsReader.cpp
)

View File

@ -1,43 +0,0 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/tmtcpacket/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
TEST_CASE("CCSDS Test", "[ccsds]") {
SpacePacketCreator base = SpacePacketCreator(
ccsds::PacketType::TC, true, 0x02,
ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
SECTION("Constexpr Helpers") {
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822);
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822);
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff);
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff);
}
SECTION("Basic Test") {
REQUIRE(base.isValid());
REQUIRE(base.getApid() == 0x02);
REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
REQUIRE(base.getVersion() == 0b000);
REQUIRE(base.getSequenceCount() == 0x34);
REQUIRE(base.getPacketDataLen() == 0x16);
REQUIRE(base.getPacketType() == ccsds::PacketType::TC);
REQUIRE(base.getPacketId() == 0x1802);
}
SECTION("Raw Output") {
std::array<uint8_t, 6> buf {};
uint8_t* bufPtr = buf.data();
size_t serLen = 0;
base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::MACHINE);
REQUIRE(buf[0] == 0x18);
REQUIRE(buf[1] == 0x02);
REQUIRE(buf[2] == 0x40);
REQUIRE(buf[3] == 0x34);
REQUIRE(buf[4] == 0x00);
REQUIRE(buf[5] == 0x16);
}
}

View File

@ -0,0 +1,82 @@
#include <array>
#include <cmath>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/tmtcpacket/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
TEST_CASE("CCSDS Test", "[ccsds]") {
SpacePacketCreator base = SpacePacketCreator(
ccsds::PacketType::TC, true, 0x02,
ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
std::array<uint8_t, 6> buf {};
uint8_t* bufPtr = buf.data();
size_t serLen = 0;
SECTION("Constexpr Helpers") {
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822);
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822);
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff);
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff);
}
SECTION("Basic Test") {
REQUIRE(base.isValid());
REQUIRE(base.getApid() == 0x02);
REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
REQUIRE(base.getVersion() == 0b000);
REQUIRE(base.getSequenceCount() == 0x34);
REQUIRE(base.getPacketDataLen() == 0x16);
REQUIRE(base.getPacketType() == ccsds::PacketType::TC);
REQUIRE(base.getPacketId() == 0x1802);
}
SECTION("Raw Output") {
REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
// TC, and secondary header flag is set -> 0b0001100 -> 0x18
REQUIRE(buf[0] == 0x18);
// APID 0x02
REQUIRE(buf[1] == 0x02);
// Sequence count is one byte value, so the only set bit here is the bit
// from the Sequence flag argument, which is the second bit for
// SequenceFlags.FIRST_SEGMENT
REQUIRE(buf[2] == 0x40);
// Sequence Count specified above
REQUIRE(buf[3] == 0x34);
// This byte and the next byte should be 22 big endian (packet length)
REQUIRE(buf[4] == 0x00);
REQUIRE(buf[5] == 0x16);
}
SECTION("All Ones Output") {
base.setApid(static_cast<int>(std::pow(2, 11)) - 1);
base.setSeqCount(static_cast<int>(std::pow(2, 14)) - 1);
base.setSeqFlags(ccsds::SequenceFlags::UNSEGMENTED);
base.setDataLen(static_cast<int>(std::pow(2, 16)) - 1);
REQUIRE(base.isValid());
REQUIRE(base.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(buf[0] == 0x1F);
REQUIRE(buf[1] == 0xFF);
REQUIRE(buf[2] == 0xFF);
REQUIRE(buf[3] == 0xFF);
REQUIRE(buf[4] == 0xFF);
REQUIRE(buf[5] == 0xFF);
}
SECTION("Invalid APID") {
SpacePacketCreator invalid = SpacePacketCreator(
PacketId(ccsds::PacketType::TC, true, 0xFFFF),
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16);
REQUIRE(not invalid.isValid());
REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
}
SECTION("Invalid Seq Count") {
SpacePacketCreator invalid = SpacePacketCreator(
PacketId(ccsds::PacketType::TC, true, 0x02),
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16);
REQUIRE(not invalid.isValid());
REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
}
}