From 049ac75b99ca6e2eb873eb0d1aaeb0618f02a348 Mon Sep 17 00:00:00 2001 From: Jerome Hue Date: Wed, 31 Jul 2024 22:09:59 +0200 Subject: [PATCH] Take rebase into account --- Sts1CobcSw/Edu/ProgramStatusHistory.cpp | 16 +++++----- Sts1CobcSw/Edu/ProgramStatusHistory.hpp | 27 ++++++---------- Sts1CobcSw/Periphery/FramRingBuffer.hpp | 1 + Sts1CobcSw/Periphery/FramRingBuffer.ipp | 18 +++++------ Tests/UnitTests/FramRingBuffer.test.cpp | 42 ++++++++++++++----------- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Sts1CobcSw/Edu/ProgramStatusHistory.cpp b/Sts1CobcSw/Edu/ProgramStatusHistory.cpp index bc2e6fc0..33b3aa37 100644 --- a/Sts1CobcSw/Edu/ProgramStatusHistory.cpp +++ b/Sts1CobcSw/Edu/ProgramStatusHistory.cpp @@ -30,7 +30,7 @@ using sts1cobcsw::SerializeTo; template -auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data) -> void const * +auto DeserializeFrom(void const * source, edu::ProgramStatusHistoryEntry * data) -> void const * { source = DeserializeFrom(source, &(data->programId)); source = DeserializeFrom(source, &(data->startTime)); @@ -39,14 +39,14 @@ auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data) -> v } -template auto DeserializeFrom(void const *, ProgramStatusHistoryEntry *) +template auto DeserializeFrom(void const *, edu::ProgramStatusHistoryEntry *) -> void const *; -template auto DeserializeFrom(void const *, ProgramStatusHistoryEntry *) +template auto DeserializeFrom(void const *, edu::ProgramStatusHistoryEntry *) -> void const *; template -auto SerializeTo(void * destination, ProgramStatusHistoryEntry const & data) -> void * +auto SerializeTo(void * destination, edu::ProgramStatusHistoryEntry const & data) -> void * { destination = SerializeTo(destination, data.programId); destination = SerializeTo(destination, data.startTime); @@ -55,6 +55,8 @@ auto SerializeTo(void * destination, ProgramStatusHistoryEntry const & data) -> } -template auto SerializeTo(void *, ProgramStatusHistoryEntry const &) -> void *; -template auto SerializeTo(void *, ProgramStatusHistoryEntry const &) -> void *; -} +template auto SerializeTo(void *, edu::ProgramStatusHistoryEntry const &) + -> void *; +template auto SerializeTo(void *, edu::ProgramStatusHistoryEntry const &) + -> void *; +} \ No newline at end of file diff --git a/Sts1CobcSw/Edu/ProgramStatusHistory.hpp b/Sts1CobcSw/Edu/ProgramStatusHistory.hpp index 8c5dedfc..758fbeb5 100644 --- a/Sts1CobcSw/Edu/ProgramStatusHistory.hpp +++ b/Sts1CobcSw/Edu/ProgramStatusHistory.hpp @@ -17,9 +17,10 @@ #include -namespace sts1cobcsw -{ -namespace edu +using sts1cobcsw::ProgramId; + + +namespace sts1cobcsw::edu { enum class ProgramStatus : std::uint8_t { @@ -42,14 +43,16 @@ struct ProgramStatusHistoryEntry }; } +namespace sts1cobcsw +{ template<> inline constexpr std::size_t serialSize = totalSerialSize; +} - -namespace edu +namespace sts1cobcsw::edu { inline constexpr auto programStatusHistorySize = 20; @@ -57,17 +60,6 @@ static_assert(programStatusHistorySize * totalSerialSize -inline constexpr std::size_t serialSize = - totalSerialSize; - -namespace edu -{ -inline constexpr auto programStatusHistorySize = 20; - template [[nodiscard]] auto DeserializeFrom(void const * source, ProgramStatusHistoryEntry * data) -> void const *; @@ -81,5 +73,4 @@ extern RODOS::RingBuffer pr auto UpdateProgramStatusHistory(ProgramId programId, std::int32_t startTime, ProgramStatus newStatus) -> void; -} -} +} \ No newline at end of file diff --git a/Sts1CobcSw/Periphery/FramRingBuffer.hpp b/Sts1CobcSw/Periphery/FramRingBuffer.hpp index b1cfe902..735b3d96 100644 --- a/Sts1CobcSw/Periphery/FramRingBuffer.hpp +++ b/Sts1CobcSw/Periphery/FramRingBuffer.hpp @@ -36,6 +36,7 @@ class RingBuffer //! @brief Returns the capacity of the ringbuffer auto Capacity() -> std::size_t; + private: std::uint32_t nextWriteIndex_ = 0; std::uint32_t nextReadIndex_ = 0; diff --git a/Sts1CobcSw/Periphery/FramRingBuffer.ipp b/Sts1CobcSw/Periphery/FramRingBuffer.ipp index b53cca21..55de4e0c 100644 --- a/Sts1CobcSw/Periphery/FramRingBuffer.ipp +++ b/Sts1CobcSw/Periphery/FramRingBuffer.ipp @@ -9,9 +9,8 @@ namespace sts1cobcsw::fram template void RingBuffer::Push(T const & newData) { - auto const address = startAddress + nextWriteIndex_ * serialSize; - fram::WriteTo(address, Span(Serialize(newData)), 0); - + auto const rawaddress = value_of(startAddress) + (nextWriteIndex_ * serialSize); + fram::WriteTo(fram::Address(rawaddress), Span(Serialize(newData)), 0); ++nextWriteIndex_; if(nextWriteIndex_ == bufferSize_) @@ -33,8 +32,8 @@ void RingBuffer::Push(T const & newData) template auto RingBuffer::Front() -> T { - auto const address = startAddress + nextReadIndex_ * serialSize; - auto readData = fram::ReadFrom>(address, 0); + auto const rawAddress = value_of(startAddress) + (nextReadIndex_ * serialSize); + auto readData = fram::ReadFrom>(fram::Address(rawAddress), 0); auto fromRing = Deserialize(std::span(readData)); return fromRing; @@ -54,8 +53,8 @@ auto RingBuffer::Back() -> T readIndex = nextWriteIndex_ - 1; } - auto const address = startAddress + readIndex * serialSize; - auto readData = fram::ReadFrom>(address, 0); + auto const rawaddress = value_of(startAddress) + readIndex * serialSize; + auto readData = fram::ReadFrom>(fram::Address(rawaddress), 0); auto fromRing = Deserialize(std::span(readData)); return fromRing; @@ -65,8 +64,9 @@ auto RingBuffer::Back() -> T template auto RingBuffer::operator[](std::size_t index) -> T { - auto const address = startAddress + ((nextReadIndex_ + index) % bufferSize_) * serialSize; - auto readData = fram::ReadFrom>(address, 0); + auto const rawaddress = + value_of(startAddress) + ((nextReadIndex_ + index) % bufferSize_) * serialSize; + auto readData = fram::ReadFrom>(fram::Address(rawaddress), 0); return Deserialize(std::span(readData)); } diff --git a/Tests/UnitTests/FramRingBuffer.test.cpp b/Tests/UnitTests/FramRingBuffer.test.cpp index aa632278..fa452f67 100644 --- a/Tests/UnitTests/FramRingBuffer.test.cpp +++ b/Tests/UnitTests/FramRingBuffer.test.cpp @@ -40,19 +40,24 @@ TEST_CASE("FramRingBuffer Push function") TEMPLATE_TEST_CASE_SIG("FramRingBuffer Front Address", "", ((typename T, size_t S, fram::Address A), T, S, A), - (int, 10, fram::Address{0}), - (int, 10, fram::Address{31415})) + (int, 10U, fram::Address{0}), + (int, 10U, fram::Address{31415})) { fram::ram::SetAllDoFunctions(); - fram::ram::storage.fill(0x00_b); + fram::ram::memory.fill(0x00_b); fram::Initialize(); fram::RingBuffer buffer; + // FIXME: [] not working buffer.Push(10); + REQUIRE(buffer[0] == 10); + buffer.Push(20); - buffer.Push(30); + REQUIRE(buffer[0] == 10); + REQUIRE(buffer[1] == 20); + buffer.Push(30); REQUIRE(buffer[0] == 10); REQUIRE(buffer[1] == 20); REQUIRE(buffer[2] == 30); @@ -61,10 +66,10 @@ TEMPLATE_TEST_CASE_SIG("FramRingBuffer Front Address", TEST_CASE("FramRingBuffer Back() and Front() methods") { fram::ram::SetAllDoFunctions(); - fram::ram::storage.fill(0x00_b); + fram::ram::memory.fill(0x00_b); fram::Initialize(); - fram::RingBuffer buffer; + auto buffer = fram::RingBuffer(); etl::circular_buffer etlBuffer; // NOLINTNEXTLINE (readability-container-size-empty) @@ -74,21 +79,22 @@ TEST_CASE("FramRingBuffer Back() and Front() methods") buffer.Push(1); buffer.Push(2); + REQUIRE(buffer.Front() == 1); buffer.Push(3); etlBuffer.push(1); etlBuffer.push(2); etlBuffer.push(3); - REQUIRE(etlBuffer.front() == 1); - REQUIRE(etlBuffer.back() == 3); REQUIRE(etlBuffer.size() == 3); REQUIRE(etlBuffer.capacity() == 5); + REQUIRE(etlBuffer.back() == 3); + REQUIRE(etlBuffer.front() == 1); - REQUIRE(buffer.Front() == 1); - REQUIRE(buffer.Back() == 3); REQUIRE(buffer.Size() == 3); REQUIRE(buffer.Capacity() == 5); + REQUIRE(buffer.Back() == 3); + REQUIRE(buffer.Front() == 1); etlBuffer.push(4); etlBuffer.push(5); @@ -118,10 +124,10 @@ TEST_CASE("FramRingBuffer Back() and Front() methods") TEST_CASE("FramRingBuffer Full and Empty conditions") { fram::ram::SetAllDoFunctions(); - fram::ram::storage.fill(0x00_b); + fram::ram::memory.fill(0x00_b); fram::Initialize(); - fram::RingBuffer buffer; + auto buffer = fram::RingBuffer{}; REQUIRE(buffer.Size() == 0); REQUIRE(buffer.Capacity() == 3); @@ -150,10 +156,10 @@ TEST_CASE("FramRingBuffer Full and Empty conditions") TEST_CASE("FramRingBuffer and ETL Circular Buffer") { fram::ram::SetAllDoFunctions(); - fram::ram::storage.fill(0x00_b); + fram::ram::memory.fill(0x00_b); fram::Initialize(); - fram::RingBuffer framBuffer; + fram::RingBuffer framBuffer{}; etl::circular_buffer etlBuffer; for(int i = 0; i < 5; ++i) @@ -178,10 +184,10 @@ TEST_CASE("FramRingBuffer and ETL Circular Buffer") TEST_CASE("FramRingBuffer Stress Test") { fram::ram::SetAllDoFunctions(); - fram::ram::storage.fill(0x00_b); + fram::ram::memory.fill(0x00_b); fram::Initialize(); - fram::RingBuffer buffer; + auto buffer = fram::RingBuffer(); for(int i = 0; i < 10000; ++i) { @@ -199,11 +205,11 @@ TEST_CASE("FramRingBuffer Stress Test") TEST_CASE("Custom Type") { fram::ram::SetAllDoFunctions(); - fram::ram::storage.fill(0x00_b); + fram::ram::memory.fill(0x00_b); fram::Initialize(); - fram::RingBuffer buffer; + fram::RingBuffer buffer; auto pshEntry = sts1cobcsw::edu::ProgramStatusHistoryEntry{ .programId = sts1cobcsw::ProgramId(0),