create files as well
This commit is contained in:
parent
1f381d9477
commit
e62c527d05
@ -57,14 +57,23 @@ ReturnValue_t TmStore::storePacket(PusTmReader& reader) {
|
|||||||
}
|
}
|
||||||
// It is assumed here that the filesystem is usable.
|
// It is assumed here that the filesystem is usable.
|
||||||
if (not mostRecentFile) {
|
if (not mostRecentFile) {
|
||||||
assignMostRecentFile();
|
assignAndOrCreateMostRecentFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentTv.tv_sec < mostRecentTv.value().tv_sec or
|
if (currentTv.tv_sec < mostRecentTv.value().tv_sec or
|
||||||
currentTv.tv_sec - mostRecentTv.value().tv_sec > static_cast<int>(rolloverDiffSeconds)) {
|
currentTv.tv_sec - mostRecentTv.value().tv_sec > static_cast<int>(rolloverDiffSeconds)) {
|
||||||
if (file_size(mostRecentFile.value()) + reader.getFullPacketLen() > fileBuf.size()) {
|
if (file_size(mostRecentFile.value()) + reader.getFullPacketLen() > fileBuf.size()) {
|
||||||
// TODO: Rename old file to XYZ.1..z , create new file with the same name as old one,
|
uint8_t appendedCounter = 1;
|
||||||
// update most recent file with that name
|
path rolloverName;
|
||||||
|
while (true) {
|
||||||
|
rolloverName = path(mostRecentFile.value().string() + std::to_string(appendedCounter));
|
||||||
|
if (not exists(rolloverName)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
appendedCounter++;
|
||||||
|
}
|
||||||
|
rename(mostRecentFile.value(), rolloverName);
|
||||||
|
std::ofstream of(mostRecentFile.value(), std::ios::binary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +105,7 @@ void TmStore::updateBaseDir() {
|
|||||||
|
|
||||||
ReturnValue_t TmStore::updateCurrentTimestamp() { return Clock::getClock_timeval(¤tTv); }
|
ReturnValue_t TmStore::updateCurrentTimestamp() { return Clock::getClock_timeval(¤tTv); }
|
||||||
|
|
||||||
void TmStore::assignMostRecentFile() {
|
void TmStore::assignAndOrCreateMostRecentFile() {
|
||||||
using namespace std::filesystem;
|
using namespace std::filesystem;
|
||||||
for (auto const& file : directory_iterator(baseDir)) {
|
for (auto const& file : directory_iterator(baseDir)) {
|
||||||
if (file.is_directory()) {
|
if (file.is_directory()) {
|
||||||
@ -123,6 +132,20 @@ void TmStore::assignMostRecentFile() {
|
|||||||
mostRecentFile = file.path();
|
mostRecentFile = file.path();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (not mostRecentFile) {
|
||||||
|
updateCurrentTimestamp();
|
||||||
|
unsigned currentIdx = 0;
|
||||||
|
memcpy(fileBuf.data() + currentIdx, baseName.data(), baseName.size());
|
||||||
|
currentIdx += baseName.size();
|
||||||
|
Clock::TimeOfDay_t tod;
|
||||||
|
Clock::convertTimevalToTimeOfDay(¤tTv, &tod);
|
||||||
|
currentIdx += sprintf(reinterpret_cast<char*>(fileBuf.data() + currentIdx),
|
||||||
|
"%4" SCNu32 "-%2" SCNu32 "-%2" SCNu32 "T%2" SCNu32 ":%2" SCNu32
|
||||||
|
":%2" SCNu32 "Z.bin",
|
||||||
|
tod.year, tod.month, tod.day, tod.hour, tod.minute, tod.second);
|
||||||
|
path newPath(std::string(reinterpret_cast<const char*>(fileBuf.data()), currentIdx));
|
||||||
|
std::ofstream of(newPath, std::ios::binary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TmStore::storePacketInternal(PusTmReader& reader) { return returnvalue::OK; }
|
ReturnValue_t TmStore::storePacketInternal(PusTmReader& reader) { return returnvalue::OK; }
|
||||||
|
@ -47,7 +47,7 @@ class TmStore : public SystemObject {
|
|||||||
SdCardMountedIF& sdcMan;
|
SdCardMountedIF& sdcMan;
|
||||||
|
|
||||||
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
|
void calcDiffSeconds(RolloverInterval intervalUnit, uint32_t intervalCount);
|
||||||
void assignMostRecentFile();
|
void assignAndOrCreateMostRecentFile();
|
||||||
ReturnValue_t storePacketInternal(PusTmReader& reader);
|
ReturnValue_t storePacketInternal(PusTmReader& reader);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user