Skip to content

Commit 4b395e8

Browse files
authored
Implement file transfer thread (#468)
Fixes #384
2 parents 82d435e + 9924635 commit 4b395e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2226
-320
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "STS1 COBC",
3-
"image": "tuwienspaceteam/sts1-cobc:1.17.0",
3+
"image": "tuwienspaceteam/sts1-cobc:1.20.1",
44
"customizations": {
55
"vscode": {
66
"extensions": [

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
jobs:
1717
format-and-spell-check:
1818
runs-on: ubuntu-24.04
19-
container: tuwienspaceteam/sts1-cobc:1.17.0-linux-x86
19+
container: tuwienspaceteam/sts1-cobc:1.20.1-linux-x86
2020

2121
steps:
2222
- uses: actions/checkout@v4
@@ -32,7 +32,7 @@ jobs:
3232
needs: format-and-spell-check
3333

3434
runs-on: ubuntu-24.04
35-
container: tuwienspaceteam/sts1-cobc:1.17.0-linux-x86
35+
container: tuwienspaceteam/sts1-cobc:1.20.1-linux-x86
3636

3737
steps:
3838
- uses: actions/checkout@v4
@@ -60,7 +60,7 @@ jobs:
6060
needs: format-and-spell-check
6161

6262
runs-on: ubuntu-24.04
63-
container: tuwienspaceteam/sts1-cobc:1.17.0-linux-x86
63+
container: tuwienspaceteam/sts1-cobc:1.20.1-linux-x86
6464

6565
steps:
6666
- uses: actions/checkout@v4
@@ -86,7 +86,7 @@ jobs:
8686
needs: format-and-spell-check
8787

8888
runs-on: ubuntu-24.04
89-
container: tuwienspaceteam/sts1-cobc:1.17.0
89+
container: tuwienspaceteam/sts1-cobc:1.20.1
9090

9191
steps:
9292
- uses: actions/checkout@v4
@@ -123,7 +123,7 @@ jobs:
123123
needs: format-and-spell-check
124124

125125
runs-on: ubuntu-24.04
126-
container: tuwienspaceteam/sts1-cobc:1.17.0
126+
container: tuwienspaceteam/sts1-cobc:1.20.1
127127

128128
steps:
129129
- uses: actions/checkout@v4
@@ -171,7 +171,7 @@ jobs:
171171
needs: format-and-spell-check
172172

173173
runs-on: ubuntu-24.04
174-
container: tuwienspaceteam/sts1-cobc:1.17.0-linux-x86
174+
container: tuwienspaceteam/sts1-cobc:1.20.1-linux-x86
175175

176176
steps:
177177
- uses: actions/checkout@v4

Sts1CobcSw/ChannelCoding/External/ConvolutionalCoding.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <etl/vector.h>
1717

1818
#include <array>
19-
#include <climits>
19+
#include <climits> // IWYU pragma: keep
2020
#include <cstddef>
2121
#include <cstdint>
2222
#include <span>
@@ -88,7 +88,7 @@ class ViterbiCodec
8888
static inline auto outputs = std::array<std::uint8_t, 1U << constraint>();
8989

9090
unsigned int state_ = 0;
91-
unsigned int bytes_ = 0;
91+
[[maybe_unused]] unsigned int bytes_ = 0;
9292
#ifdef USE_PUNCTURING
9393
unsigned int nProcessedBytes_ = 0;
9494
#endif
@@ -113,7 +113,7 @@ constexpr auto ViterbiCodec::EncodedSize(std::size_t unencodedSize,
113113
#else
114114
auto bits = (unencodedSize * CHAR_BIT + flushingBits) * 2;
115115
#endif
116-
auto size = (bits + CHAR_BIT - 1) / CHAR_BIT; // Round up
116+
auto size = (bits + CHAR_BIT - 1) / CHAR_BIT; // Round up
117117
return size;
118118
#endif
119119
}

Sts1CobcSw/Edu/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Generic)
1616
Sts1CobcSw_RodosTime
1717
Sts1CobcSw_Vocabulary
1818
)
19+
set_target_properties(Sts1CobcSw_Edu PROPERTIES INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL OFF)
1920
endif()
2021
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
2122
target_sources(Sts1CobcSw_Edu PRIVATE EduMock.cpp)

Sts1CobcSw/Edu/Edu.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ constexpr auto maxFileSize = maxNPackets * maxDataSize;
7575

7676
constexpr auto nProgramIdDigits =
7777
std::numeric_limits<strong::underlying_type_t<ProgramId>>::digits10 + 1;
78+
constexpr auto nStartTimeDigits =
79+
std::numeric_limits<strong::underlying_type_t<RealTime>>::digits10 + 1;
7880
constexpr auto * programFileExtension = ".zip";
81+
constexpr auto * resultFileExtension = ".cpio";
7982

8083
// Data buffer for potentially large data packets (ReturnResult and StoreProgram)
8184
auto cepDataBuffer = etl::vector<Byte, maxDataSize>{};
@@ -109,9 +112,6 @@ template<>
109112
template<typename T>
110113
[[nodiscard]] auto Retry(auto (*communicationFunction)()->Result<T>, int nTries) -> Result<T>;
111114
auto FlushUartReceiveBuffer() -> void;
112-
113-
auto BuildProgramFilePath(ProgramId programId) -> fs::Path;
114-
auto BuildResultFilePath(ProgramId programId, RealTime startTime) -> fs::Path;
115115
}
116116

117117

@@ -175,7 +175,8 @@ auto StoreProgram(StoreProgramData const & data) -> Result<void>
175175
OUTCOME_TRY(auto fileSize, file.Size());
176176
if(fileSize > maxFileSize)
177177
{
178-
DEBUG_PRINT("Program file %s is too large: %d B\n", path.c_str(), fileSize);
178+
DEBUG_PRINT(
179+
"Program file %s is too large: %i B\n", path.c_str(), static_cast<int>(fileSize));
179180
return ErrorCode::fileTooLarge;
180181
}
181182
OUTCOME_TRY(SendDataPacket(Serialize(data)));
@@ -331,11 +332,42 @@ auto UpdateTime(UpdateTimeData const & data) -> Result<void>
331332
}
332333

333334

335+
auto BuildProgramFilePath(ProgramId programId) -> fs::Path
336+
{
337+
auto path = programsDirectory;
338+
path.append("/");
339+
etl::to_string(value_of(programId),
340+
path,
341+
etl::format_spec().width(nProgramIdDigits).fill('0'),
342+
/*append=*/true);
343+
path.append(programFileExtension);
344+
return path;
345+
}
346+
347+
348+
auto BuildResultFilePath(ProgramId programId, RealTime startTime) -> fs::Path
349+
{
350+
auto path = resultsDirectory;
351+
path.append("/");
352+
etl::to_string(value_of(programId),
353+
path,
354+
etl::format_spec().width(nProgramIdDigits).fill('0'),
355+
/*append=*/true);
356+
path.append("_");
357+
etl::to_string(value_of(startTime),
358+
path,
359+
etl::format_spec().width(nStartTimeDigits).fill('0'),
360+
/*append=*/true);
361+
path.append(resultFileExtension);
362+
return path;
363+
}
364+
365+
334366
auto GetProgramId(fs::Path const & filename) -> Result<ProgramId>
335367
{
336368
static constexpr auto programFilenameLength =
337369
nProgramIdDigits + std::char_traits<char>::length(programFileExtension);
338-
if(filename.size() == programFilenameLength)
370+
if(filename.size() == programFilenameLength and filename.ends_with(programFileExtension))
339371
{
340372
std::uint16_t value = 0;
341373
auto result = std::from_chars(filename.data(), filename.data() + nProgramIdDigits, value);
@@ -345,7 +377,7 @@ auto GetProgramId(fs::Path const & filename) -> Result<ProgramId>
345377
}
346378
}
347379
DEBUG_PRINT("Failed to get EDU program ID from file %s\n", filename.c_str());
348-
return ErrorCode::invalidParameter;
380+
return ErrorCode::invalidEduProgramFilename;
349381
}
350382

351383

@@ -362,8 +394,9 @@ auto ProgramsAreAvailableOnCobc() -> bool
362394
directoryIterator.end(),
363395
[](auto const & entryResult)
364396
{
365-
return not entryResult.has_error()
366-
and entryResult.value().type == fs::EntryType::file;
397+
return entryResult.has_value()
398+
and entryResult.value().type == fs::EntryType::file
399+
and GetProgramId(entryResult.value().name).has_value();
367400
});
368401
}
369402

@@ -622,38 +655,5 @@ auto FlushUartReceiveBuffer() -> void
622655
}
623656
}
624657
}
625-
626-
627-
auto BuildProgramFilePath(ProgramId programId) -> fs::Path
628-
{
629-
auto path = programsDirectory;
630-
path.append("/");
631-
etl::to_string(value_of(programId),
632-
path,
633-
etl::format_spec().width(nProgramIdDigits).fill('0'),
634-
/*append=*/true);
635-
path.append(programFileExtension);
636-
return path;
637-
}
638-
639-
640-
auto BuildResultFilePath(ProgramId programId, RealTime startTime) -> fs::Path
641-
{
642-
auto path = resultsDirectory;
643-
path.append("/");
644-
etl::to_string(value_of(programId),
645-
path,
646-
etl::format_spec().width(nProgramIdDigits).fill('0'),
647-
/*append=*/true);
648-
path.append("_");
649-
static constexpr auto nStartTimeDigits =
650-
std::numeric_limits<strong::underlying_type_t<RealTime>>::digits10 + 1;
651-
etl::to_string(value_of(startTime),
652-
path,
653-
etl::format_spec().width(nStartTimeDigits).fill('0'),
654-
/*append=*/true);
655-
path.append(programFileExtension);
656-
return path;
657-
}
658658
}
659659
}

Sts1CobcSw/Edu/Edu.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <Sts1CobcSw/Hal/GpioPin.hpp>
77
#include <Sts1CobcSw/Outcome/Outcome.hpp>
88
#include <Sts1CobcSw/Vocabulary/Ids.hpp>
9+
#include <Sts1CobcSw/Vocabulary/Time.hpp>
910

1011

1112
namespace sts1cobcsw::edu
@@ -29,6 +30,8 @@ auto TurnOff() -> void;
2930
[[nodiscard]] auto ReturnResult(ReturnResultData const & data) -> Result<void>;
3031
[[nodiscard]] auto UpdateTime(UpdateTimeData const & data) -> Result<void>;
3132

33+
[[nodiscard]] auto BuildProgramFilePath(ProgramId programId) -> fs::Path;
34+
[[nodiscard]] auto BuildResultFilePath(ProgramId programId, RealTime startTime) -> fs::Path;
3235
[[nodiscard]] auto GetProgramId(fs::Path const & filename) -> Result<ProgramId>;
3336
[[nodiscard]] auto ProgramsAreAvailableOnCobc() -> bool;
3437
}

Sts1CobcSw/FileSystem/File.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,42 @@ auto Open(Path const & path, unsigned int flags) -> Result<File>
7070
}
7171

7272

73-
auto File::SeekAbsolute(int offset) -> Result<int>
73+
auto File::Resize(std::size_t newSize) -> Result<void>
74+
{
75+
if(not persistentVariables.Load<"flashIsWorking">())
76+
{
77+
return ErrorCode::io;
78+
}
79+
if(not isOpen_)
80+
{
81+
return ErrorCode::fileNotOpen;
82+
}
83+
if((openFlags_ & LFS_O_WRONLY) == 0U)
84+
{
85+
return ErrorCode::unsupportedOperation;
86+
}
87+
auto error = lfs_file_truncate(&lfs, &lfsFile_, newSize);
88+
if(error < 0)
89+
{
90+
return static_cast<ErrorCode>(error);
91+
}
92+
return outcome_v2::success();
93+
}
94+
95+
96+
auto File::SeekAbsolute(int offset) const -> Result<int>
7497
{
7598
return Seek(offset, LFS_SEEK_SET);
7699
}
77100

78101

79-
auto File::SeekRelative(int offset) -> Result<int>
102+
auto File::SeekRelative(int offset) const -> Result<int>
80103
{
81104
return Seek(offset, LFS_SEEK_CUR);
82105
}
83106

84107

85-
auto File::Size() const -> Result<int>
108+
auto File::Size() const -> Result<std::size_t>
86109
{
87110
if(not persistentVariables.Load<"flashIsWorking">())
88111
{
@@ -95,7 +118,7 @@ auto File::Size() const -> Result<int>
95118
auto size = lfs_file_size(&lfs, &lfsFile_);
96119
if(size >= 0)
97120
{
98-
return size;
121+
return static_cast<std::size_t>(size);
99122
}
100123
return static_cast<ErrorCode>(size);
101124
}
@@ -249,7 +272,7 @@ auto File::Write(void const * buffer, std::size_t size) -> Result<int>
249272
}
250273

251274

252-
auto File::Seek(int offset, int whence) -> Result<int>
275+
auto File::Seek(int offset, int whence) const -> Result<int>
253276
{
254277
if(not persistentVariables.Load<"flashIsWorking">())
255278
{

Sts1CobcSw/FileSystem/File.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class File
3030
[[nodiscard]] auto Read(std::span<Byte, extent> data) const -> Result<int>;
3131
template<std::size_t extent>
3232
[[nodiscard]] auto Write(std::span<Byte const, extent> data) -> Result<int>;
33-
[[nodiscard]] auto SeekAbsolute(int offset) -> Result<int>;
34-
[[nodiscard]] auto SeekRelative(int offset) -> Result<int>;
35-
[[nodiscard]] auto Size() const -> Result<int>;
33+
[[nodiscard]] auto Resize(std::size_t newSize) -> Result<void>;
34+
[[nodiscard]] auto SeekAbsolute(int offset) const -> Result<int>;
35+
[[nodiscard]] auto SeekRelative(int offset) const -> Result<int>;
36+
[[nodiscard]] auto Size() const -> Result<std::size_t>;
3637
[[nodiscard]] auto Close() const -> Result<void>;
3738
[[nodiscard]] auto Flush() -> Result<void>;
3839

@@ -44,7 +45,7 @@ class File
4445
[[nodiscard]] auto CreateLockFile() const noexcept -> Result<void>;
4546
[[nodiscard]] auto Read(void * buffer, std::size_t size) const -> Result<int>;
4647
[[nodiscard]] auto Write(void const * buffer, std::size_t size) -> Result<int>;
47-
[[nodiscard]] auto Seek(int offset, int whence) -> Result<int>;
48+
[[nodiscard]] auto Seek(int offset, int whence) const -> Result<int>;
4849
[[nodiscard]] auto CloseAndKeepLockFile() const -> Result<void>;
4950

5051
Path path_ = "";

Sts1CobcSw/FileSystem/LfsMemoryDevice.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace sts1cobcsw::fs
1010
{
1111
inline constexpr auto crcSize = sizeof(std::uint32_t);
1212
inline constexpr auto lfsCacheSize = 256 - crcSize;
13-
// Our longest path should be strlen("/results/65536_4294967295.zip.lock") = 34 characters long
13+
// Our longest path should be strlen("/results/65536_4294967295.cpio.lock") = 35 characters long
1414
inline constexpr auto maxPathLength = 35;
1515
extern lfs_config const lfsConfig;
1616

0 commit comments

Comments
 (0)