From e0d57c388296b3c028ec2413c63b387ae562e1cc Mon Sep 17 00:00:00 2001 From: Elena Jochum Date: Sat, 20 Apr 2024 13:44:26 +0000 Subject: [PATCH 01/11] WIP: Add and use a strong type for program ID --- Sts1CobcSw/Edu/ProgramQueue.cpp | 4 ++-- Sts1CobcSw/Edu/ProgramQueue.hpp | 3 ++- Sts1CobcSw/EduProgramQueueThread.cpp | 6 +++--- Sts1CobcSw/ProgramId/CMakeLists.txt | 2 ++ Sts1CobcSw/ProgramId/ProgramId.hpp | 5 +++++ 5 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 Sts1CobcSw/ProgramId/CMakeLists.txt create mode 100644 Sts1CobcSw/ProgramId/ProgramId.hpp diff --git a/Sts1CobcSw/Edu/ProgramQueue.cpp b/Sts1CobcSw/Edu/ProgramQueue.cpp index e682fe1e..3563a39c 100644 --- a/Sts1CobcSw/Edu/ProgramQueue.cpp +++ b/Sts1CobcSw/Edu/ProgramQueue.cpp @@ -16,7 +16,7 @@ std::uint16_t queueIndex = 0; template auto DeserializeFrom(void const * source, QueueEntry * data) -> void const * { - source = DeserializeFrom(source, &(data->programId)); + source = DeserializeFrom(source, &(data->programId.get())); source = DeserializeFrom(source, &(data->startTime)); source = DeserializeFrom(source, &(data->timeout)); return source; @@ -30,7 +30,7 @@ template auto DeserializeFrom(void const *, QueueEntry *) - template auto SerializeTo(void * destination, QueueEntry const & data) -> void * { - destination = SerializeTo(destination, data.programId); + destination = SerializeTo(destination, data.programId.get()); destination = SerializeTo(destination, data.startTime); destination = SerializeTo(destination, data.timeout); return destination; diff --git a/Sts1CobcSw/Edu/ProgramQueue.hpp b/Sts1CobcSw/Edu/ProgramQueue.hpp index eaaf4173..59046c65 100644 --- a/Sts1CobcSw/Edu/ProgramQueue.hpp +++ b/Sts1CobcSw/Edu/ProgramQueue.hpp @@ -1,6 +1,7 @@ #pragma once +#include #include #include @@ -16,7 +17,7 @@ namespace edu { struct QueueEntry { - std::uint16_t programId = 0; + ProgramId programId = ProgramId{0}; std::int32_t startTime = 0; std::int16_t timeout = 0; }; diff --git a/Sts1CobcSw/EduProgramQueueThread.cpp b/Sts1CobcSw/EduProgramQueueThread.cpp index 896a8b7f..063b26ab 100644 --- a/Sts1CobcSw/EduProgramQueueThread.cpp +++ b/Sts1CobcSw/EduProgramQueueThread.cpp @@ -125,9 +125,9 @@ class EduProgramQueueThread : public RODOS::StaticThread auto programId = edu::programQueue[edu::queueIndex].programId; auto timeout = edu::programQueue[edu::queueIndex].timeout; - DEBUG_PRINT("Executing program %d\n", programId); + DEBUG_PRINT("Executing program %d\n", programId.get()); auto executeProgramData = edu::ExecuteProgramData{ - .programId = programId, .startTime = startTime, .timeout = timeout}; + .programId = programId.get(), .startTime = startTime, .timeout = timeout}; // Start Process auto executeProgramResult = edu::ExecuteProgram(executeProgramData); // errorCode = edu::ErrorCode::success; @@ -142,7 +142,7 @@ class EduProgramQueueThread : public RODOS::StaticThread else { edu::programStatusHistory.put( - edu::ProgramStatusHistoryEntry{.programId = programId, + edu::ProgramStatusHistoryEntry{.programId = programId.get(), .startTime = startTime, .status = edu::ProgramStatus::programRunning}); diff --git a/Sts1CobcSw/ProgramId/CMakeLists.txt b/Sts1CobcSw/ProgramId/CMakeLists.txt new file mode 100644 index 00000000..6d483359 --- /dev/null +++ b/Sts1CobcSw/ProgramId/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Sts1CobcSw/ProgramId/NamedType) +target_link_libraries(Sts1CobcSw_ProgramId NamedType::NamedType) diff --git a/Sts1CobcSw/ProgramId/ProgramId.hpp b/Sts1CobcSw/ProgramId/ProgramId.hpp new file mode 100644 index 00000000..9c83141c --- /dev/null +++ b/Sts1CobcSw/ProgramId/ProgramId.hpp @@ -0,0 +1,5 @@ +#include + +#include + +using ProgramId = fluent::NamedType; \ No newline at end of file From 1647f54e59c3ba4070ba8ab18071c429d26d855b Mon Sep 17 00:00:00 2001 From: Elena Jochum Date: Sat, 18 May 2024 16:33:15 +0000 Subject: [PATCH 02/11] Add and use a strong type for program ID --- CMakeLists.txt | 2 + Sts1CobcSw/CommandParser.cpp | 2 +- Sts1CobcSw/Edu/EduMock.cpp | 12 ++++-- Sts1CobcSw/Edu/ProgramQueue.hpp | 2 +- Sts1CobcSw/Edu/ProgramStatusHistory.cpp | 2 +- Sts1CobcSw/Edu/ProgramStatusHistory.hpp | 6 ++- Sts1CobcSw/Edu/Types.hpp | 13 ++++--- Sts1CobcSw/Edu/Types.ipp | 8 ++-- Sts1CobcSw/EduProgramQueueThread.cpp | 6 +-- Sts1CobcSw/FileSystem/FileSystem.cpp | 2 +- Sts1CobcSw/FileSystem/FileSystem.hpp | 3 +- Sts1CobcSw/ProgramId/CMakeLists.txt | 1 - Sts1CobcSw/ProgramId/ProgramId.hpp | 2 +- Tests/GoldenTests/UpdateRingBuffer.test.cpp | 41 ++++++++++++++------- Tests/HardwareTests/EduCommands.test.cpp | 13 ++++--- 15 files changed, 69 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1f78323..de827bfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ include(cmake/clang-tidy-cache.cmake) find_package_and_notify(etl) find_rodos() find_package_and_notify(littlefs) +find_package_and_notify(NamedType) # ---- Declare targets ---- @@ -27,6 +28,7 @@ add_library(Sts1CobcSw_Dummy STATIC) add_library(Sts1CobcSw_Edu STATIC) add_library(Sts1CobcSw_FileSystem STATIC) add_library(Sts1CobcSw_Outcome INTERFACE) +add_library(Sts1CobcSw_ProgramId INTERFACE) add_library(Sts1CobcSw_Serial INTERFACE) add_library(Sts1CobcSw_Utility STATIC) add_library(Sts1CobcSw_Periphery STATIC) diff --git a/Sts1CobcSw/CommandParser.cpp b/Sts1CobcSw/CommandParser.cpp index 1c2fa9fa..3b2a007b 100644 --- a/Sts1CobcSw/CommandParser.cpp +++ b/Sts1CobcSw/CommandParser.cpp @@ -88,7 +88,7 @@ auto ParseAndAddQueueEntries(std::span queueEntries) -> void auto entry = Deserialize(queueEntries.first>()); - DEBUG_PRINT("Prog ID : %" PRIu16 "\n", entry.programId); + DEBUG_PRINT("Prog ID : %" PRIu16 "\n", entry.programId.get()); DEBUG_PRINT("Start Time : %" PRIi32 "\n", entry.startTime); DEBUG_PRINT("Timeout : %" PRIi16 "\n", entry.timeout); diff --git a/Sts1CobcSw/Edu/EduMock.cpp b/Sts1CobcSw/Edu/EduMock.cpp index 4f03100c..dc8dd456 100644 --- a/Sts1CobcSw/Edu/EduMock.cpp +++ b/Sts1CobcSw/Edu/EduMock.cpp @@ -47,7 +47,7 @@ auto TurnOff() -> void auto StoreProgram(StoreProgramData const & data) -> Result { PrintFormattedSystemUtc(); - DEBUG_PRINT("Call to StoreProgram(programId = %d)\n", data.programId); + DEBUG_PRINT("Call to StoreProgram(programId = %" PRIu16 ")\n", data.programId.get()); return outcome_v2::success(); } @@ -55,8 +55,9 @@ auto StoreProgram(StoreProgramData const & data) -> Result auto ExecuteProgram(ExecuteProgramData const & data) -> Result { PrintFormattedSystemUtc(); - DEBUG_PRINT("Call to ExecuteProgram(programId = %d, startTime = %" PRIi32 ", timeout = %d)\n", - data.programId, + DEBUG_PRINT("Call to ExecuteProgram(programId = %" PRIu16 ", startTime = %" PRIi32 + ", timeout = %d)\n", + data.programId.get(), data.startTime, data.timeout); return outcome_v2::success(); @@ -75,7 +76,10 @@ auto GetStatus() -> Result { PrintFormattedSystemUtc(); DEBUG_PRINT("Call to GetStatus()\n"); - return Status{.statusType = StatusType::invalid, .programId = 0, .startTime = 0, .exitCode = 0}; + return Status{.statusType = StatusType::invalid, + .programId = ProgramId(0), + .startTime = 0, + .exitCode = 0}; } diff --git a/Sts1CobcSw/Edu/ProgramQueue.hpp b/Sts1CobcSw/Edu/ProgramQueue.hpp index 59046c65..ec3dd9f6 100644 --- a/Sts1CobcSw/Edu/ProgramQueue.hpp +++ b/Sts1CobcSw/Edu/ProgramQueue.hpp @@ -17,7 +17,7 @@ namespace edu { struct QueueEntry { - ProgramId programId = ProgramId{0}; + ProgramId programId = ProgramId(0); std::int32_t startTime = 0; std::int16_t timeout = 0; }; diff --git a/Sts1CobcSw/Edu/ProgramStatusHistory.cpp b/Sts1CobcSw/Edu/ProgramStatusHistory.cpp index a06a3c9d..7678832e 100644 --- a/Sts1CobcSw/Edu/ProgramStatusHistory.cpp +++ b/Sts1CobcSw/Edu/ProgramStatusHistory.cpp @@ -6,7 +6,7 @@ namespace sts1cobcsw::edu RODOS::RingBuffer programStatusHistory; -auto UpdateProgramStatusHistory(std::uint16_t programId, +auto UpdateProgramStatusHistory(ProgramId programId, std::int32_t startTime, ProgramStatus newStatus) -> void { diff --git a/Sts1CobcSw/Edu/ProgramStatusHistory.hpp b/Sts1CobcSw/Edu/ProgramStatusHistory.hpp index b866dc7c..8fe86609 100644 --- a/Sts1CobcSw/Edu/ProgramStatusHistory.hpp +++ b/Sts1CobcSw/Edu/ProgramStatusHistory.hpp @@ -1,6 +1,8 @@ #pragma once +#include + // clang-format off #include // ringbuffer.h does not include even though it requires it @@ -25,7 +27,7 @@ enum class ProgramStatus : std::uint8_t struct ProgramStatusHistoryEntry { - std::uint16_t programId = 0; + ProgramId programId = ProgramId(0); std::int32_t startTime = 0; ProgramStatus status = ProgramStatus::programRunning; }; @@ -35,7 +37,7 @@ inline constexpr auto programStatusHistorySize = 20; extern RODOS::RingBuffer programStatusHistory; -auto UpdateProgramStatusHistory(std::uint16_t programId, +auto UpdateProgramStatusHistory(ProgramId programId, std::int32_t startTime, ProgramStatus newStatus) -> void; } diff --git a/Sts1CobcSw/Edu/Types.hpp b/Sts1CobcSw/Edu/Types.hpp index 2a2984e7..9ebc9322 100644 --- a/Sts1CobcSw/Edu/Types.hpp +++ b/Sts1CobcSw/Edu/Types.hpp @@ -1,6 +1,7 @@ #pragma once +#include #include #include @@ -42,14 +43,14 @@ enum class StatusType struct StoreProgramData { static constexpr auto id = 0x01_b; - std::uint16_t programId = 0; + ProgramId programId = ProgramId(0); }; struct ExecuteProgramData { static constexpr auto id = 0x02_b; - std::uint16_t programId = 0; + ProgramId programId = ProgramId(0); std::int32_t startTime = 0; std::int16_t timeout = 0; }; @@ -70,7 +71,7 @@ struct GetStatusData struct ReturnResultData { static constexpr auto id = 0x05_b; - std::uint16_t programId = 0; + ProgramId programId = ProgramId(0); std::int32_t startTime = 0; }; @@ -85,7 +86,7 @@ struct UpdateTimeData struct Status { StatusType statusType = StatusType::invalid; - std::uint16_t programId = 0; + ProgramId programId = ProgramId(0); std::int32_t startTime = 0; std::uint8_t exitCode = 0; }; @@ -100,7 +101,7 @@ struct NoEventData struct ProgramFinishedData { static constexpr auto id = 0x01_b; - std::uint16_t programId = 0; + ProgramId programId = ProgramId(0); std::int32_t startTime = 0; std::uint8_t exitCode = 0; }; @@ -109,7 +110,7 @@ struct ProgramFinishedData struct ResultsReadyData { static constexpr auto id = 0x02_b; - std::uint16_t programId = 0; + ProgramId programId = ProgramId(0); std::int32_t startTime = 0; }; diff --git a/Sts1CobcSw/Edu/Types.ipp b/Sts1CobcSw/Edu/Types.ipp index a2711b15..bc7eeacc 100644 --- a/Sts1CobcSw/Edu/Types.ipp +++ b/Sts1CobcSw/Edu/Types.ipp @@ -23,7 +23,7 @@ template auto SerializeTo(void * destination, ExecuteProgramData const & data) -> void * { destination = SerializeTo(destination, ExecuteProgramData::id); - destination = SerializeTo(destination, data.programId); + destination = SerializeTo(destination, data.programId.get()); destination = SerializeTo(destination, data.startTime); destination = SerializeTo(destination, data.timeout); return destination; @@ -50,7 +50,7 @@ template auto SerializeTo(void * destination, ReturnResultData const & data) -> void * { destination = SerializeTo(destination, ReturnResultData::id); - destination = SerializeTo(destination, data.programId); + destination = SerializeTo(destination, data.programId.get()); destination = SerializeTo(destination, data.startTime); return destination; } @@ -79,7 +79,7 @@ auto DeserializeFrom(void const * source, ProgramFinishedData * data) -> void co { auto dummy = ProgramFinishedData::id; source = DeserializeFrom(source, &dummy); - source = DeserializeFrom(source, &(data->programId)); + source = DeserializeFrom(source, &(data->programId.get())); source = DeserializeFrom(source, &(data->startTime)); source = DeserializeFrom(source, &(data->exitCode)); return source; @@ -91,7 +91,7 @@ auto DeserializeFrom(void const * source, ResultsReadyData * data) -> void const { auto dummy = ResultsReadyData::id; source = DeserializeFrom(source, &dummy); - source = DeserializeFrom(source, &(data->programId)); + source = DeserializeFrom(source, &(data->programId.get())); source = DeserializeFrom(source, &(data->startTime)); return source; } diff --git a/Sts1CobcSw/EduProgramQueueThread.cpp b/Sts1CobcSw/EduProgramQueueThread.cpp index 063b26ab..847b9da2 100644 --- a/Sts1CobcSw/EduProgramQueueThread.cpp +++ b/Sts1CobcSw/EduProgramQueueThread.cpp @@ -125,9 +125,9 @@ class EduProgramQueueThread : public RODOS::StaticThread auto programId = edu::programQueue[edu::queueIndex].programId; auto timeout = edu::programQueue[edu::queueIndex].timeout; - DEBUG_PRINT("Executing program %d\n", programId.get()); + DEBUG_PRINT("Executing program %" PRIu16 "\n", programId.get()); auto executeProgramData = edu::ExecuteProgramData{ - .programId = programId.get(), .startTime = startTime, .timeout = timeout}; + .programId = programId, .startTime = startTime, .timeout = timeout}; // Start Process auto executeProgramResult = edu::ExecuteProgram(executeProgramData); // errorCode = edu::ErrorCode::success; @@ -142,7 +142,7 @@ class EduProgramQueueThread : public RODOS::StaticThread else { edu::programStatusHistory.put( - edu::ProgramStatusHistoryEntry{.programId = programId.get(), + edu::ProgramStatusHistoryEntry{.programId = programId, .startTime = startTime, .status = edu::ProgramStatus::programRunning}); diff --git a/Sts1CobcSw/FileSystem/FileSystem.cpp b/Sts1CobcSw/FileSystem/FileSystem.cpp index 9013b5b5..7894342a 100644 --- a/Sts1CobcSw/FileSystem/FileSystem.cpp +++ b/Sts1CobcSw/FileSystem/FileSystem.cpp @@ -98,7 +98,7 @@ auto Unmount() -> int } -auto OpenProgramFile(std::uint16_t programId, int flags) -> int +auto OpenProgramFile(ProgramId programId, int flags) -> int { return 0; } diff --git a/Sts1CobcSw/FileSystem/FileSystem.hpp b/Sts1CobcSw/FileSystem/FileSystem.hpp index 992404f2..66a6194a 100644 --- a/Sts1CobcSw/FileSystem/FileSystem.hpp +++ b/Sts1CobcSw/FileSystem/FileSystem.hpp @@ -1,6 +1,7 @@ #pragma once +#include #include #include @@ -25,7 +26,7 @@ auto Mount() -> int; auto Unmount() -> int; // File stuff -auto OpenProgramFile(std::uint16_t programId, int flags) -> int; +auto OpenProgramFile(ProgramId programId, int flags) -> int; auto CloseProgramFile() -> int; template auto ReadProgramFile(etl::vector * buffer) -> int; diff --git a/Sts1CobcSw/ProgramId/CMakeLists.txt b/Sts1CobcSw/ProgramId/CMakeLists.txt index 6d483359..d5bb0695 100644 --- a/Sts1CobcSw/ProgramId/CMakeLists.txt +++ b/Sts1CobcSw/ProgramId/CMakeLists.txt @@ -1,2 +1 @@ -add_subdirectory(Sts1CobcSw/ProgramId/NamedType) target_link_libraries(Sts1CobcSw_ProgramId NamedType::NamedType) diff --git a/Sts1CobcSw/ProgramId/ProgramId.hpp b/Sts1CobcSw/ProgramId/ProgramId.hpp index 9c83141c..6f74213d 100644 --- a/Sts1CobcSw/ProgramId/ProgramId.hpp +++ b/Sts1CobcSw/ProgramId/ProgramId.hpp @@ -2,4 +2,4 @@ #include -using ProgramId = fluent::NamedType; \ No newline at end of file +using ProgramId = fluent::NamedType; \ No newline at end of file diff --git a/Tests/GoldenTests/UpdateRingBuffer.test.cpp b/Tests/GoldenTests/UpdateRingBuffer.test.cpp index 96e8151e..01674d7c 100644 --- a/Tests/GoldenTests/UpdateRingBuffer.test.cpp +++ b/Tests/GoldenTests/UpdateRingBuffer.test.cpp @@ -38,7 +38,7 @@ void PrintBuffer() { RODOS::PRINTF("Vals[%d] = .id(%d), .status(%s)\n", i, - edu::programStatusHistory.vals[i].programId, + edu::programStatusHistory.vals[i].programId.get(), ToString(edu::programStatusHistory.vals[i].status).data()); } } @@ -50,14 +50,22 @@ class UpdateRingBufferTest : public RODOS::StaticThread<> { printfMask = 1; - edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{ - .programId = 1, .startTime = 1, .status = edu::ProgramStatus::programExecutionFailed}); - edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{ - .programId = 2, .startTime = 1, .status = edu::ProgramStatus::programRunning}); - edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{ - .programId = 3, .startTime = 1, .status = edu::ProgramStatus::programRunning}); - edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{ - .programId = 4, .startTime = 1, .status = edu::ProgramStatus::programRunning}); + edu::programStatusHistory.put( + edu::ProgramStatusHistoryEntry{.programId = ProgramId(1), + .startTime = 1, + .status = edu::ProgramStatus::programExecutionFailed}); + edu::programStatusHistory.put( + edu::ProgramStatusHistoryEntry{.programId = ProgramId(2), + .startTime = 1, + .status = edu::ProgramStatus::programRunning}); + edu::programStatusHistory.put( + edu::ProgramStatusHistoryEntry{.programId = ProgramId(3), + .startTime = 1, + .status = edu::ProgramStatus::programRunning}); + edu::programStatusHistory.put( + edu::ProgramStatusHistoryEntry{.programId = ProgramId(4), + .startTime = 1, + .status = edu::ProgramStatus::programRunning}); auto readCnt = edu::programStatusHistory.readCnt; @@ -66,11 +74,16 @@ class UpdateRingBufferTest : public RODOS::StaticThread<> PrintBuffer(); - edu::UpdateProgramStatusHistory(2, 1, edu::ProgramStatus::programExecutionSucceeded); - edu::UpdateProgramStatusHistory(4, 1, edu::ProgramStatus::programExecutionFailed); - edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{ - .programId = 5, .startTime = 1, .status = edu::ProgramStatus::programRunning}); - edu::UpdateProgramStatusHistory(5, 1, edu::ProgramStatus::programExecutionSucceeded); + edu::UpdateProgramStatusHistory( + ProgramId(2), 1, edu::ProgramStatus::programExecutionSucceeded); + edu::UpdateProgramStatusHistory( + ProgramId(4), 1, edu::ProgramStatus::programExecutionFailed); + edu::programStatusHistory.put( + edu::ProgramStatusHistoryEntry{.programId = ProgramId(5), + .startTime = 1, + .status = edu::ProgramStatus::programRunning}); + edu::UpdateProgramStatusHistory( + ProgramId(5), 1, edu::ProgramStatus::programExecutionSucceeded); // 1, because we did not read anything RODOS::PRINTF("readCnt unchanged : %d\n", diff --git a/Tests/HardwareTests/EduCommands.test.cpp b/Tests/HardwareTests/EduCommands.test.cpp index d4ca2a63..ab9b4ceb 100644 --- a/Tests/HardwareTests/EduCommands.test.cpp +++ b/Tests/HardwareTests/EduCommands.test.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -83,8 +84,8 @@ class EduCommandsTest : public RODOS::StaticThread<> { PRINTF("Please enter a program ID (1 character)\n"); auto userInput = ReadCharacters<1>(); - std::uint16_t programId = 0; - std::from_chars(userInput.begin(), userInput.end(), programId); + ProgramId programId = ProgramId(0); + std::from_chars(userInput.begin(), userInput.end(), programId.get()); PRINTF("Please enter a start time (1 character)\n"); userInput = ReadCharacters<1>(); @@ -99,7 +100,7 @@ class EduCommandsTest : public RODOS::StaticThread<> PRINTF("\n"); PRINTF("Sending ExecuteProgram(programId = %" PRIu16 ", startTime = %" PRIi32 ", timeout = %" PRIi16 ")\n", - programId, + programId.get(), startTime, timeout); auto executeProgramResult = edu::ExecuteProgram( @@ -137,8 +138,8 @@ class EduCommandsTest : public RODOS::StaticThread<> { PRINTF("Please enter a program ID (1 character)\n"); auto userInput = ReadCharacters<1>(); - std::uint16_t programId = 0; - std::from_chars(userInput.begin(), userInput.end(), programId); + ProgramId programId = ProgramId(0); + std::from_chars(userInput.begin(), userInput.end(), programId.get()); PRINTF("Please enter a start time (1 character)\n"); userInput = ReadCharacters<1>(); @@ -148,7 +149,7 @@ class EduCommandsTest : public RODOS::StaticThread<> PRINTF("\n"); PRINTF("Sending ReturnResult(programId = %" PRIu16 ", startTime = %" PRIi32 ")\n", - programId, + programId.get(), startTime); auto returnResultResult = edu::ReturnResult( edu::ReturnResultData{.programId = programId, .startTime = startTime}); From 0393b0bae4427ffc4987cf655265b5c1989c81bc Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 18:30:32 +0000 Subject: [PATCH 03/11] Explicitly link Sts1CobcSw_ProgramId with INTERFACE keyword --- Sts1CobcSw/ProgramId/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sts1CobcSw/ProgramId/CMakeLists.txt b/Sts1CobcSw/ProgramId/CMakeLists.txt index d5bb0695..06b6a496 100644 --- a/Sts1CobcSw/ProgramId/CMakeLists.txt +++ b/Sts1CobcSw/ProgramId/CMakeLists.txt @@ -1 +1 @@ -target_link_libraries(Sts1CobcSw_ProgramId NamedType::NamedType) +target_link_libraries(Sts1CobcSw_ProgramId INTERFACE NamedType::NamedType) From e57b8e6726fc9a9c0eaa4cff6909330e07149a11 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 18:56:56 +0000 Subject: [PATCH 04/11] Add missing #pragma once in ProgramId.hpp --- Sts1CobcSw/ProgramId/ProgramId.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sts1CobcSw/ProgramId/ProgramId.hpp b/Sts1CobcSw/ProgramId/ProgramId.hpp index 6f74213d..1eafa265 100644 --- a/Sts1CobcSw/ProgramId/ProgramId.hpp +++ b/Sts1CobcSw/ProgramId/ProgramId.hpp @@ -1,5 +1,9 @@ +#pragma once + + #include #include -using ProgramId = fluent::NamedType; \ No newline at end of file + +using ProgramId = fluent::NamedType; From 67ca0131baa47bc2198790a5cae35b178b7525c8 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 19:07:40 +0000 Subject: [PATCH 05/11] Put ProgramId into namespace sts1cobcsw --- Sts1CobcSw/ProgramId/ProgramId.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sts1CobcSw/ProgramId/ProgramId.hpp b/Sts1CobcSw/ProgramId/ProgramId.hpp index 1eafa265..4c68f8e6 100644 --- a/Sts1CobcSw/ProgramId/ProgramId.hpp +++ b/Sts1CobcSw/ProgramId/ProgramId.hpp @@ -6,4 +6,7 @@ #include +namespace sts1cobcsw +{ using ProgramId = fluent::NamedType; +} From 81dfa94a1bdb7742bb56344ce49a0af935fff2b1 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 18:54:18 +0000 Subject: [PATCH 06/11] Constrain totalSerialSize<> to types with serialSize<> != 0 Until now it was easy to forget to specialize serialSize<> for a type, but then totalSerialSize<> would compute wrong sizes for all "derived" types since serialSize<> is 0 by default. --- Sts1CobcSw/Serial/Serial.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Sts1CobcSw/Serial/Serial.hpp b/Sts1CobcSw/Serial/Serial.hpp index 70907840..87237d76 100644 --- a/Sts1CobcSw/Serial/Serial.hpp +++ b/Sts1CobcSw/Serial/Serial.hpp @@ -48,6 +48,7 @@ template inline constexpr std::size_t serialSize> = serialSize * size; template + requires((serialSize != 0) and ...) inline constexpr std::size_t totalSerialSize = (serialSize + ...); inline constexpr auto defaultEndianness = std::endian::little; From 6dc01870eb58915df9a40d5cac5be9229a131f71 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 19:09:45 +0000 Subject: [PATCH 07/11] Define serialSize --- Sts1CobcSw/ProgramId/CMakeLists.txt | 2 +- Sts1CobcSw/ProgramId/ProgramId.hpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Sts1CobcSw/ProgramId/CMakeLists.txt b/Sts1CobcSw/ProgramId/CMakeLists.txt index 06b6a496..21cda0da 100644 --- a/Sts1CobcSw/ProgramId/CMakeLists.txt +++ b/Sts1CobcSw/ProgramId/CMakeLists.txt @@ -1 +1 @@ -target_link_libraries(Sts1CobcSw_ProgramId INTERFACE NamedType::NamedType) +target_link_libraries(Sts1CobcSw_ProgramId INTERFACE NamedType::NamedType Sts1CobcSw_Serial) diff --git a/Sts1CobcSw/ProgramId/ProgramId.hpp b/Sts1CobcSw/ProgramId/ProgramId.hpp index 4c68f8e6..7b165eb8 100644 --- a/Sts1CobcSw/ProgramId/ProgramId.hpp +++ b/Sts1CobcSw/ProgramId/ProgramId.hpp @@ -1,6 +1,8 @@ #pragma once +#include + #include #include @@ -9,4 +11,8 @@ namespace sts1cobcsw { using ProgramId = fluent::NamedType; + +// TODO: Maybe make ProgramId completely serializable, i.e., overload (De-)Serialize() as well +template<> +inline constexpr std::size_t serialSize = totalSerialSize; } From fe163e69650af5d8536a5ea26ab51956bb8146e3 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 19:29:02 +0000 Subject: [PATCH 08/11] Fix missing .get() and do some light refactoring --- Sts1CobcSw/Edu/EduMock.cpp | 5 +---- Sts1CobcSw/Edu/Types.ipp | 2 +- Tests/HardwareTests/EduCommands.test.cpp | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Sts1CobcSw/Edu/EduMock.cpp b/Sts1CobcSw/Edu/EduMock.cpp index dc8dd456..99c3ceed 100644 --- a/Sts1CobcSw/Edu/EduMock.cpp +++ b/Sts1CobcSw/Edu/EduMock.cpp @@ -76,10 +76,7 @@ auto GetStatus() -> Result { PrintFormattedSystemUtc(); DEBUG_PRINT("Call to GetStatus()\n"); - return Status{.statusType = StatusType::invalid, - .programId = ProgramId(0), - .startTime = 0, - .exitCode = 0}; + return Status(); } diff --git a/Sts1CobcSw/Edu/Types.ipp b/Sts1CobcSw/Edu/Types.ipp index bc7eeacc..f0664eac 100644 --- a/Sts1CobcSw/Edu/Types.ipp +++ b/Sts1CobcSw/Edu/Types.ipp @@ -14,7 +14,7 @@ template auto SerializeTo(void * destination, StoreProgramData const & data) -> void * { destination = SerializeTo(destination, StoreProgramData::id); - destination = SerializeTo(destination, data.programId); + destination = SerializeTo(destination, data.programId.get()); return destination; } diff --git a/Tests/HardwareTests/EduCommands.test.cpp b/Tests/HardwareTests/EduCommands.test.cpp index ab9b4ceb..7e46c4dc 100644 --- a/Tests/HardwareTests/EduCommands.test.cpp +++ b/Tests/HardwareTests/EduCommands.test.cpp @@ -84,7 +84,7 @@ class EduCommandsTest : public RODOS::StaticThread<> { PRINTF("Please enter a program ID (1 character)\n"); auto userInput = ReadCharacters<1>(); - ProgramId programId = ProgramId(0); + auto programId = ProgramId(0); std::from_chars(userInput.begin(), userInput.end(), programId.get()); PRINTF("Please enter a start time (1 character)\n"); @@ -138,7 +138,7 @@ class EduCommandsTest : public RODOS::StaticThread<> { PRINTF("Please enter a program ID (1 character)\n"); auto userInput = ReadCharacters<1>(); - ProgramId programId = ProgramId(0); + auto programId = ProgramId(0); std::from_chars(userInput.begin(), userInput.end(), programId.get()); PRINTF("Please enter a start time (1 character)\n"); From 056bd4b769369d25e8ae38c8b152cff70b7c08b6 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 20:23:03 +0000 Subject: [PATCH 09/11] Make ProgramId (de-)serializable --- Sts1CobcSw/Edu/ProgramQueue.cpp | 4 ++-- Sts1CobcSw/Edu/Types.ipp | 10 +++++----- Sts1CobcSw/ProgramId/ProgramId.hpp | 9 +++++++++ Sts1CobcSw/ProgramId/ProgramId.ipp | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 Sts1CobcSw/ProgramId/ProgramId.ipp diff --git a/Sts1CobcSw/Edu/ProgramQueue.cpp b/Sts1CobcSw/Edu/ProgramQueue.cpp index 3563a39c..e682fe1e 100644 --- a/Sts1CobcSw/Edu/ProgramQueue.cpp +++ b/Sts1CobcSw/Edu/ProgramQueue.cpp @@ -16,7 +16,7 @@ std::uint16_t queueIndex = 0; template auto DeserializeFrom(void const * source, QueueEntry * data) -> void const * { - source = DeserializeFrom(source, &(data->programId.get())); + source = DeserializeFrom(source, &(data->programId)); source = DeserializeFrom(source, &(data->startTime)); source = DeserializeFrom(source, &(data->timeout)); return source; @@ -30,7 +30,7 @@ template auto DeserializeFrom(void const *, QueueEntry *) - template auto SerializeTo(void * destination, QueueEntry const & data) -> void * { - destination = SerializeTo(destination, data.programId.get()); + destination = SerializeTo(destination, data.programId); destination = SerializeTo(destination, data.startTime); destination = SerializeTo(destination, data.timeout); return destination; diff --git a/Sts1CobcSw/Edu/Types.ipp b/Sts1CobcSw/Edu/Types.ipp index f0664eac..a2711b15 100644 --- a/Sts1CobcSw/Edu/Types.ipp +++ b/Sts1CobcSw/Edu/Types.ipp @@ -14,7 +14,7 @@ template auto SerializeTo(void * destination, StoreProgramData const & data) -> void * { destination = SerializeTo(destination, StoreProgramData::id); - destination = SerializeTo(destination, data.programId.get()); + destination = SerializeTo(destination, data.programId); return destination; } @@ -23,7 +23,7 @@ template auto SerializeTo(void * destination, ExecuteProgramData const & data) -> void * { destination = SerializeTo(destination, ExecuteProgramData::id); - destination = SerializeTo(destination, data.programId.get()); + destination = SerializeTo(destination, data.programId); destination = SerializeTo(destination, data.startTime); destination = SerializeTo(destination, data.timeout); return destination; @@ -50,7 +50,7 @@ template auto SerializeTo(void * destination, ReturnResultData const & data) -> void * { destination = SerializeTo(destination, ReturnResultData::id); - destination = SerializeTo(destination, data.programId.get()); + destination = SerializeTo(destination, data.programId); destination = SerializeTo(destination, data.startTime); return destination; } @@ -79,7 +79,7 @@ auto DeserializeFrom(void const * source, ProgramFinishedData * data) -> void co { auto dummy = ProgramFinishedData::id; source = DeserializeFrom(source, &dummy); - source = DeserializeFrom(source, &(data->programId.get())); + source = DeserializeFrom(source, &(data->programId)); source = DeserializeFrom(source, &(data->startTime)); source = DeserializeFrom(source, &(data->exitCode)); return source; @@ -91,7 +91,7 @@ auto DeserializeFrom(void const * source, ResultsReadyData * data) -> void const { auto dummy = ResultsReadyData::id; source = DeserializeFrom(source, &dummy); - source = DeserializeFrom(source, &(data->programId.get())); + source = DeserializeFrom(source, &(data->programId)); source = DeserializeFrom(source, &(data->startTime)); return source; } diff --git a/Sts1CobcSw/ProgramId/ProgramId.hpp b/Sts1CobcSw/ProgramId/ProgramId.hpp index 7b165eb8..fe277a78 100644 --- a/Sts1CobcSw/ProgramId/ProgramId.hpp +++ b/Sts1CobcSw/ProgramId/ProgramId.hpp @@ -15,4 +15,13 @@ using ProgramId = fluent::NamedType inline constexpr std::size_t serialSize = totalSerialSize; + + +template +[[nodiscard]] inline auto SerializeTo(void * destination, ProgramId const & data) -> void *; +template +[[nodiscard]] inline auto DeserializeFrom(void const * source, ProgramId * data) -> void const *; } + + +#include diff --git a/Sts1CobcSw/ProgramId/ProgramId.ipp b/Sts1CobcSw/ProgramId/ProgramId.ipp new file mode 100644 index 00000000..547bb5f3 --- /dev/null +++ b/Sts1CobcSw/ProgramId/ProgramId.ipp @@ -0,0 +1,21 @@ +#pragma once + + +#include + + +namespace sts1cobcsw +{ +template +inline auto SerializeTo(void * destination, ProgramId const & data) -> void * +{ + return SerializeTo(destination, data.get()); +} + + +template +inline auto DeserializeFrom(void const * source, ProgramId * data) -> void const * +{ + return DeserializeFrom(source, &(data->get())); +} +} From 3636ba08d32508b51d34c7136d72b82c4585c7c6 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 20:23:21 +0000 Subject: [PATCH 10/11] Add ProgramId.hpp/ipp to iwyu.imp --- iwyu.imp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iwyu.imp b/iwyu.imp index 0826322c..f8758a5a 100644 --- a/iwyu.imp +++ b/iwyu.imp @@ -52,6 +52,7 @@ { include: ["\"Sts1CobcSw/Hal/Uart.ipp\"", "private", "", "public"] }, { include: ["\"Sts1CobcSw/Utility/Time.ipp\"", "private", "", "public"] }, { include: ["\"Sts1CobcSw/Periphery/Fram.ipp\"", "private", "", "public"] }, + { include: ["\"Sts1CobcSw/ProgramId/ProgramId.ipp\"", "private", "", "public"] }, { include: ["\"Sts1CobcSw/Serial/Byte.ipp\"", "private", "", "public"] }, { include: ["\"Sts1CobcSw/Serial/Serial.ipp\"", "private", "", "public"] }, { include: ["\"Sts1CobcSw/Utility/Span.ipp\"", "private", "", "public"] }, @@ -76,6 +77,7 @@ { include: ["\"Sts1CobcSw/Periphery/Fram.hpp\"", "public", "", "public"] }, { include: ["\"Sts1CobcSw/Periphery/PersistentState.hpp\"", "public", "", "public"] }, { include: ["\"Sts1CobcSw/Periphery/Rf.hpp\"", "public", "", "public"] }, + { include: ["\"Sts1CobcSw/ProgramId/ProgramId.hpp\"", "public", "", "public"] }, { include: ["\"Sts1CobcSw/Serial/Byte.hpp\"", "public", "", "public"] }, { include: ["\"Sts1CobcSw/Serial/Serial.hpp\"", "public", "", "public"] }, { include: ["\"Sts1CobcSw/Utility/Crc32.hpp\"", "public", "", "public"] }, From 8e41ee4fbb1064f9fb4a77c5898dd0870d95f63f Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 23 May 2024 20:23:55 +0000 Subject: [PATCH 11/11] Fix includes --- Sts1CobcSw/CommandParser.cpp | 1 + Sts1CobcSw/Edu/ProgramQueue.cpp | 1 - Sts1CobcSw/EduProgramQueueThread.cpp | 1 + Sts1CobcSw/FileSystem/FileSystem.hpp | 1 - Sts1CobcSw/FlashStartupTestThread.cpp | 2 ++ Sts1CobcSw/FramEpsStartupTestThread.cpp | 4 ++++ Sts1CobcSw/RfStartupTestThread.cpp | 2 ++ Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp | 2 ++ 8 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sts1CobcSw/CommandParser.cpp b/Sts1CobcSw/CommandParser.cpp index 3b2a007b..3e4c3f06 100644 --- a/Sts1CobcSw/CommandParser.cpp +++ b/Sts1CobcSw/CommandParser.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include diff --git a/Sts1CobcSw/Edu/ProgramQueue.cpp b/Sts1CobcSw/Edu/ProgramQueue.cpp index e682fe1e..1fb67ccd 100644 --- a/Sts1CobcSw/Edu/ProgramQueue.cpp +++ b/Sts1CobcSw/Edu/ProgramQueue.cpp @@ -1,5 +1,4 @@ #include -#include // TODO: Change namespace here too, or move it back to Sts1CobSw/ diff --git a/Sts1CobcSw/EduProgramQueueThread.cpp b/Sts1CobcSw/EduProgramQueueThread.cpp index 847b9da2..dff13bde 100644 --- a/Sts1CobcSw/EduProgramQueueThread.cpp +++ b/Sts1CobcSw/EduProgramQueueThread.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/Sts1CobcSw/FileSystem/FileSystem.hpp b/Sts1CobcSw/FileSystem/FileSystem.hpp index 66a6194a..97845dfa 100644 --- a/Sts1CobcSw/FileSystem/FileSystem.hpp +++ b/Sts1CobcSw/FileSystem/FileSystem.hpp @@ -9,7 +9,6 @@ #include #include -#include namespace sts1cobcsw::fs::deprecated diff --git a/Sts1CobcSw/FlashStartupTestThread.cpp b/Sts1CobcSw/FlashStartupTestThread.cpp index b5eeb0b2..3bb7269f 100644 --- a/Sts1CobcSw/FlashStartupTestThread.cpp +++ b/Sts1CobcSw/FlashStartupTestThread.cpp @@ -2,6 +2,8 @@ #include #include +#include + namespace sts1cobcsw { diff --git a/Sts1CobcSw/FramEpsStartupTestThread.cpp b/Sts1CobcSw/FramEpsStartupTestThread.cpp index 57d63b25..3d32b55b 100644 --- a/Sts1CobcSw/FramEpsStartupTestThread.cpp +++ b/Sts1CobcSw/FramEpsStartupTestThread.cpp @@ -3,6 +3,10 @@ #include #include +#include + +#include + namespace sts1cobcsw { diff --git a/Sts1CobcSw/RfStartupTestThread.cpp b/Sts1CobcSw/RfStartupTestThread.cpp index 4a7cf6bd..c3dcb340 100644 --- a/Sts1CobcSw/RfStartupTestThread.cpp +++ b/Sts1CobcSw/RfStartupTestThread.cpp @@ -2,6 +2,8 @@ #include #include +#include + namespace sts1cobcsw { diff --git a/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp b/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp index d5c2b5cc..29e51deb 100644 --- a/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp +++ b/Sts1CobcSw/SpiStartupTestAndSupervisorThread.cpp @@ -1,6 +1,8 @@ #include #include +#include + namespace sts1cobcsw {