some more fixes
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-06-23 17:07:07 +02:00
parent 9023405b96
commit 2e041c3013
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 19 additions and 10 deletions

View File

@ -40,12 +40,12 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
if (not fileOrDir.is_regular_file(e)) { if (not fileOrDir.is_regular_file(e)) {
continue; continue;
} }
sif::debug << "Path: " << fileOrDir.path() << std::endl;
dumpParams.fileSize = std::filesystem::file_size(fileOrDir.path(), e); dumpParams.fileSize = std::filesystem::file_size(fileOrDir.path(), e);
if (e) { if (e) {
sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl; sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl;
continue; continue;
} }
// sif::debug << "Path: " << dumpParams.dirEntry.path() << std::endl;
// File empty or can't even read CCSDS header. // File empty or can't even read CCSDS header.
if (dumpParams.fileSize <= 6) { if (dumpParams.fileSize <= 6) {
@ -83,7 +83,7 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
return returnvalue::OK; return returnvalue::OK;
} }
uint8_t PersistentTmStore::extractSuffix(const std::string& pathStr) { std::optional<uint8_t> PersistentTmStore::extractSuffix(const std::string& pathStr) {
std::string numberStr; std::string numberStr;
// Find the position of the dot at the end of the file path // Find the position of the dot at the end of the file path
size_t dotPos = pathStr.find_last_of('.'); size_t dotPos = pathStr.find_last_of('.');
@ -91,11 +91,18 @@ uint8_t PersistentTmStore::extractSuffix(const std::string& pathStr) {
// Extract the substring after the dot // Extract the substring after the dot
numberStr = pathStr.substr(dotPos + 1); numberStr = pathStr.substr(dotPos + 1);
} }
int number = std::stoi(numberStr); std::optional<uint8_t> number;
try {
number = std::stoi(numberStr);
if (number < 0 or number > std::numeric_limits<uint8_t>::max()) { if (number < 0 or number > std::numeric_limits<uint8_t>::max()) {
return 0; return number;
} }
return static_cast<uint8_t>(number);
} catch (std::invalid_argument& exception) {
sif::error << "PersistentTmStore::extractSuffix: Exception " << exception.what()
<< ", invald input string: " << numberStr << std::endl;
}
return number;
} }
ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() { ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() {
@ -195,6 +202,7 @@ ReturnValue_t PersistentTmStore::storePacket(PusTmReader& reader) {
createMostRecentFile(suffix); createMostRecentFile(suffix);
} }
sif::debug << "active file " << activeFile.value() << std::endl;
// Rollover conditions were handled, write to file now // Rollover conditions were handled, write to file now
std::ofstream of(activeFile.value(), std::ios::app | std::ios::binary); std::ofstream of(activeFile.value(), std::ios::app | std::ios::binary);
of.write(reinterpret_cast<const char*>(reader.getFullData()), of.write(reinterpret_cast<const char*>(reader.getFullData()),
@ -229,6 +237,8 @@ bool PersistentTmStore::updateBaseDir() {
path preparedFullFilePath = basePath / baseName; path preparedFullFilePath = basePath / baseName;
basePathSize = preparedFullFilePath.string().length(); basePathSize = preparedFullFilePath.string().length();
std::memcpy(filePathBuf.data(), preparedFullFilePath.c_str(), basePathSize); std::memcpy(filePathBuf.data(), preparedFullFilePath.c_str(), basePathSize);
filePathBuf[basePathSize] = '_';
basePathSize += 1;
baseDirUninitialized = false; baseDirUninitialized = false;
return true; return true;
} }
@ -358,6 +368,7 @@ ReturnValue_t PersistentTmStore::createMostRecentFile(std::optional<uint8_t> suf
size_t currentIdx; size_t currentIdx;
createFileName(currentTv, suffix, currentIdx); createFileName(currentTv, suffix, currentIdx);
path newPath(std::string(reinterpret_cast<const char*>(filePathBuf.data()), currentIdx)); path newPath(std::string(reinterpret_cast<const char*>(filePathBuf.data()), currentIdx));
sif::debug << "creating new file: " << newPath << std::endl;
std::ofstream of(newPath, std::ios::binary); std::ofstream of(newPath, std::ios::binary);
activeFile = newPath; activeFile = newPath;
activeFileTv = currentTv; activeFileTv = currentTv;
@ -383,8 +394,6 @@ void PersistentTmStore::getStartAndEndTimeCurrentOrLastDump(uint32_t& startTime,
ReturnValue_t PersistentTmStore::createFileName(timeval& tv, std::optional<uint8_t> suffix, ReturnValue_t PersistentTmStore::createFileName(timeval& tv, std::optional<uint8_t> suffix,
size_t& fullPathLength) { size_t& fullPathLength) {
unsigned currentIdx = basePathSize; unsigned currentIdx = basePathSize;
fileBuf[currentIdx] = '_';
currentIdx += 1;
time_t epoch = tv.tv_sec; time_t epoch = tv.tv_sec;
struct tm* time = gmtime(&epoch); struct tm* time = gmtime(&epoch);
size_t writtenBytes = strftime(reinterpret_cast<char*>(filePathBuf.data() + currentIdx), size_t writtenBytes = strftime(reinterpret_cast<char*>(filePathBuf.data() + currentIdx),

View File

@ -40,7 +40,7 @@ struct PersistentTmStoreArgs {
struct DumpIndex { struct DumpIndex {
uint32_t epoch; uint32_t epoch;
uint8_t suffixIdx; std::optional<uint8_t> suffixIdx;
// Define a custom comparison function based on the epoch variable // Define a custom comparison function based on the epoch variable
bool operator<(const DumpIndex& other) const { return epoch < other.epoch; } bool operator<(const DumpIndex& other) const { return epoch < other.epoch; }
}; };
@ -140,7 +140,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
void fileToPackets(const std::filesystem::path& path, uint32_t unixStamp); void fileToPackets(const std::filesystem::path& path, uint32_t unixStamp);
ReturnValue_t loadNextDumpFile(); ReturnValue_t loadNextDumpFile();
ReturnValue_t createFileName(timeval& tv, std::optional<uint8_t> suffix, size_t& fullPathLength); ReturnValue_t createFileName(timeval& tv, std::optional<uint8_t> suffix, size_t& fullPathLength);
uint8_t extractSuffix(const std::string& pathStr); std::optional<uint8_t> extractSuffix(const std::string& pathStr);
bool updateBaseDir(); bool updateBaseDir();
ReturnValue_t assignAndOrCreateMostRecentFile(); ReturnValue_t assignAndOrCreateMostRecentFile();
}; };