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