This commit is contained in:
parent
7c15eb57bb
commit
57f3103e52
@ -9,6 +9,9 @@
|
||||
#include <linux/devices/ScexUartReader.h>
|
||||
#include <unistd.h> // write(), read(), close()
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/globalfunctions/DleEncoder.h"
|
||||
@ -216,7 +219,7 @@ void UartTestClass::scexPeriodic() {
|
||||
// helper.getTotalPacketCounter()) { nach 2min reader->finish();
|
||||
if (helper.getCmd() == FRAM) {
|
||||
if (not fileNameSet) {
|
||||
fileId = gen_random(12);
|
||||
fileId = random_string(12);
|
||||
fileName = "/tmp/scex-fram_" + fileId + ".bin";
|
||||
fileNameSet = true;
|
||||
}
|
||||
@ -382,18 +385,21 @@ void UartTestClass::handleFoundDlePacket(uint8_t* packet, size_t len) {
|
||||
sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
|
||||
}
|
||||
|
||||
std::string UartTestClass::gen_random(const int len) {
|
||||
static const char alphanum[] =
|
||||
std::string UartTestClass::random_string(std::string::size_type length) {
|
||||
static auto& chrs =
|
||||
"0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
std::string tmp_s;
|
||||
tmp_s.reserve(len);
|
||||
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);
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)];
|
||||
}
|
||||
|
||||
return tmp_s;
|
||||
std::string s;
|
||||
|
||||
s.reserve(length);
|
||||
|
||||
while (length--) s += chrs[pick(rg)];
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class UartTestClass : public TestTask {
|
||||
|
||||
static void foundDlePacketHandler(const DleParser::Context& ctx);
|
||||
void handleFoundDlePacket(uint8_t* packet, size_t len);
|
||||
std::string gen_random(const int len);
|
||||
std::string random_string(std::string::size_type length);
|
||||
|
||||
std::string fileId = "";
|
||||
std::string fileName = "";
|
||||
|
Loading…
Reference in New Issue
Block a user