@@ -75,7 +75,10 @@ constexpr auto maxFileSize = maxNPackets * maxDataSize;
7575
7676constexpr 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 ;
7880constexpr auto * programFileExtension = " .zip" ;
81+ constexpr auto * resultFileExtension = " .cpio" ;
7982
8083// Data buffer for potentially large data packets (ReturnResult and StoreProgram)
8184auto cepDataBuffer = etl::vector<Byte, maxDataSize>{};
@@ -109,9 +112,6 @@ template<>
109112template <typename T>
110113[[nodiscard]] auto Retry (auto (*communicationFunction)()->Result<T>, int nTries) -> Result<T>;
111114auto 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+
334366auto 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}
0 commit comments