This commit is contained in:
parent
9023405b96
commit
2e041c3013
@ -40,12 +40,12 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
||||
if (not fileOrDir.is_regular_file(e)) {
|
||||
continue;
|
||||
}
|
||||
sif::debug << "Path: " << fileOrDir.path() << std::endl;
|
||||
dumpParams.fileSize = std::filesystem::file_size(fileOrDir.path(), e);
|
||||
if (e) {
|
||||
sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl;
|
||||
continue;
|
||||
}
|
||||
// sif::debug << "Path: " << dumpParams.dirEntry.path() << std::endl;
|
||||
|
||||
// File empty or can't even read CCSDS header.
|
||||
if (dumpParams.fileSize <= 6) {
|
||||
@ -83,7 +83,7 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
uint8_t PersistentTmStore::extractSuffix(const std::string& pathStr) {
|
||||
std::optional<uint8_t> PersistentTmStore::extractSuffix(const std::string& pathStr) {
|
||||
std::string numberStr;
|
||||
// Find the position of the dot at the end of the file path
|
||||
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
|
||||
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()) {
|
||||
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() {
|
||||
@ -195,6 +202,7 @@ ReturnValue_t PersistentTmStore::storePacket(PusTmReader& reader) {
|
||||
createMostRecentFile(suffix);
|
||||
}
|
||||
|
||||
sif::debug << "active file " << activeFile.value() << std::endl;
|
||||
// Rollover conditions were handled, write to file now
|
||||
std::ofstream of(activeFile.value(), std::ios::app | std::ios::binary);
|
||||
of.write(reinterpret_cast<const char*>(reader.getFullData()),
|
||||
@ -229,6 +237,8 @@ bool PersistentTmStore::updateBaseDir() {
|
||||
path preparedFullFilePath = basePath / baseName;
|
||||
basePathSize = preparedFullFilePath.string().length();
|
||||
std::memcpy(filePathBuf.data(), preparedFullFilePath.c_str(), basePathSize);
|
||||
filePathBuf[basePathSize] = '_';
|
||||
basePathSize += 1;
|
||||
baseDirUninitialized = false;
|
||||
return true;
|
||||
}
|
||||
@ -358,6 +368,7 @@ ReturnValue_t PersistentTmStore::createMostRecentFile(std::optional<uint8_t> suf
|
||||
size_t currentIdx;
|
||||
createFileName(currentTv, suffix, 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);
|
||||
activeFile = newPath;
|
||||
activeFileTv = currentTv;
|
||||
@ -383,8 +394,6 @@ void PersistentTmStore::getStartAndEndTimeCurrentOrLastDump(uint32_t& startTime,
|
||||
ReturnValue_t PersistentTmStore::createFileName(timeval& tv, std::optional<uint8_t> suffix,
|
||||
size_t& fullPathLength) {
|
||||
unsigned currentIdx = basePathSize;
|
||||
fileBuf[currentIdx] = '_';
|
||||
currentIdx += 1;
|
||||
time_t epoch = tv.tv_sec;
|
||||
struct tm* time = gmtime(&epoch);
|
||||
size_t writtenBytes = strftime(reinterpret_cast<char*>(filePathBuf.data() + currentIdx),
|
||||
|
@ -40,7 +40,7 @@ struct PersistentTmStoreArgs {
|
||||
|
||||
struct DumpIndex {
|
||||
uint32_t epoch;
|
||||
uint8_t suffixIdx;
|
||||
std::optional<uint8_t> suffixIdx;
|
||||
// Define a custom comparison function based on the epoch variable
|
||||
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);
|
||||
ReturnValue_t loadNextDumpFile();
|
||||
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();
|
||||
ReturnValue_t assignAndOrCreateMostRecentFile();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user