v1.14.0 #304
@ -4,6 +4,7 @@
|
||||
#include <mission/memory/SdCardMountedIF.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
@ -168,7 +169,7 @@ ReturnValue_t ScexDeviceHandler::handleValidReply(size_t remSize, DeviceCommandI
|
||||
ReturnValue_t result = OK;
|
||||
auto multiFileHandler = [&](std::string cmdName) {
|
||||
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
|
||||
fileId = random_string(6);
|
||||
fileId = date_time_string();
|
||||
std::ostringstream oss("/tmp/scex-", std::ostringstream::ate);
|
||||
oss << cmdName << fileId << ".bin";
|
||||
fileName = oss.str();
|
||||
@ -230,7 +231,7 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
||||
|
||||
ReturnValue_t status = OK;
|
||||
auto oneFileHandler = [&](std::string cmdName) {
|
||||
fileId = random_string(6);
|
||||
fileId = date_time_string();
|
||||
std::ostringstream oss("/tmp/scex-", std::ostringstream::ate);
|
||||
oss << cmdName << fileId << ".bin";
|
||||
fileName = oss.str();
|
||||
@ -298,23 +299,32 @@ ReturnValue_t ScexDeviceHandler::initializeLocalDataPool(localpool::DataPool& lo
|
||||
return OK;
|
||||
}
|
||||
|
||||
std::string ScexDeviceHandler::random_string(std::string::size_type length) {
|
||||
static auto& chrs =
|
||||
"0123456789"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
std::string ScexDeviceHandler::date_time_string() {
|
||||
using namespace std;
|
||||
string date_time;
|
||||
time_t now = time(0);
|
||||
tm* ltm = localtime(&now);
|
||||
ostringstream oss(std::ostringstream::ate);
|
||||
|
||||
thread_local static std::mt19937 rg{std::random_device{}()};
|
||||
thread_local static std::uniform_int_distribution<std::string::size_type> pick(0,
|
||||
sizeof(chrs) - 2);
|
||||
if (ltm->tm_hour < 10) {
|
||||
oss << 1900 + ltm->tm_year << 1 + ltm->tm_mon << ltm->tm_mday << "_0" << ltm->tm_hour;
|
||||
} else {
|
||||
oss << 1900 + ltm->tm_year << 1 + ltm->tm_mon << ltm->tm_mday << "_" << ltm->tm_hour;
|
||||
}
|
||||
if (ltm->tm_min < 10) {
|
||||
oss << 0 << ltm->tm_min;
|
||||
} else {
|
||||
oss << ltm->tm_min;
|
||||
}
|
||||
if (ltm->tm_sec < 10) {
|
||||
oss << 0 << ltm->tm_sec;
|
||||
} else {
|
||||
oss << ltm->tm_sec;
|
||||
}
|
||||
|
||||
std::string s;
|
||||
date_time = oss.str();
|
||||
|
||||
s.reserve(length);
|
||||
|
||||
while (length--) s += chrs[pick(rg)];
|
||||
|
||||
return s;
|
||||
return date_time;
|
||||
}
|
||||
|
||||
void ScexDeviceHandler::modeChanged() {}
|
||||
|
@ -28,7 +28,7 @@ class ScexDeviceHandler : public DeviceHandlerBase {
|
||||
SdCardMountedIF *sdcMan = nullptr;
|
||||
Countdown finishCountdown = Countdown(LONG_CD);
|
||||
|
||||
std::string random_string(std::string::size_type length);
|
||||
std::string date_time_string();
|
||||
|
||||
// DeviceHandlerBase private function implementation
|
||||
void doStartUp() override;
|
||||
|
Loading…
Reference in New Issue
Block a user