2021-03-31 12:16:38 +02:00
|
|
|
#include "utils.h"
|
2025-06-08 16:57:37 +02:00
|
|
|
#include "logger.h"
|
2021-03-31 12:16:38 +02:00
|
|
|
#include <cmath>
|
2021-06-28 02:07:42 +02:00
|
|
|
#include <sstream>
|
2021-03-31 12:16:38 +02:00
|
|
|
|
2024-01-21 17:12:11 +01:00
|
|
|
#include "common/dsp_source_sink/format_notated.h"
|
2025-06-08 16:57:37 +02:00
|
|
|
#include "core/config.h"
|
2024-01-21 17:12:11 +01:00
|
|
|
|
2022-02-24 19:33:58 +01:00
|
|
|
// Return filesize
|
2023-11-15 16:08:17 -05:00
|
|
|
uint64_t getFilesize(std::string filepath)
|
2022-02-24 19:33:58 +01:00
|
|
|
{
|
|
|
|
|
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
2023-11-15 16:08:17 -05:00
|
|
|
uint64_t fileSize = file.tellg();
|
2022-02-24 19:33:58 +01:00
|
|
|
file.close();
|
|
|
|
|
return fileSize;
|
2022-03-10 19:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-21 17:12:11 +01:00
|
|
|
std::string prepareAutomatedPipelineFolder(time_t timevalue, double frequency, std::string pipeline_name, std::string folder)
|
|
|
|
|
{
|
|
|
|
|
std::tm *timeReadable = gmtime(&timevalue);
|
2024-04-20 18:02:28 +02:00
|
|
|
if (folder == "")
|
2024-02-17 15:27:06 -05:00
|
|
|
{
|
2025-06-08 16:57:37 +02:00
|
|
|
folder = satdump::satdump_cfg.getValueFromSatDumpDirectories<std::string>("live_processing_path");
|
2024-02-17 15:27:06 -05:00
|
|
|
#ifdef __ANDROID__
|
2024-04-20 18:02:28 +02:00
|
|
|
if (folder == "./live_output")
|
2024-02-17 15:27:06 -05:00
|
|
|
folder = "/storage/emulated/0/live_output";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2024-01-21 17:12:11 +01:00
|
|
|
std::string timestamp = std::to_string(timeReadable->tm_year + 1900) + "-" +
|
|
|
|
|
(timeReadable->tm_mon + 1 > 9 ? std::to_string(timeReadable->tm_mon + 1) : "0" + std::to_string(timeReadable->tm_mon + 1)) + "-" +
|
|
|
|
|
(timeReadable->tm_mday > 9 ? std::to_string(timeReadable->tm_mday) : "0" + std::to_string(timeReadable->tm_mday)) + "_" +
|
|
|
|
|
(timeReadable->tm_hour > 9 ? std::to_string(timeReadable->tm_hour) : "0" + std::to_string(timeReadable->tm_hour)) + "-" +
|
|
|
|
|
(timeReadable->tm_min > 9 ? std::to_string(timeReadable->tm_min) : "0" + std::to_string(timeReadable->tm_min));
|
2024-02-17 15:27:06 -05:00
|
|
|
std::string output_dir = folder + "/" + timestamp + "_" + pipeline_name + "_" + format_notated(frequency, "Hz");
|
2024-01-21 17:12:11 +01:00
|
|
|
std::filesystem::create_directories(output_dir);
|
|
|
|
|
logger->info("Generated folder name : " + output_dir);
|
|
|
|
|
return output_dir;
|
2024-01-21 21:24:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string prepareBasebandFileName(double timeValue_precise, uint64_t samplerate, uint64_t frequency)
|
|
|
|
|
{
|
|
|
|
|
const time_t timevalue = timeValue_precise;
|
|
|
|
|
std::tm *timeReadable = gmtime(&timevalue);
|
|
|
|
|
std::string timestamp = std::to_string(timeReadable->tm_year + 1900) + "-" +
|
|
|
|
|
(timeReadable->tm_mon + 1 > 9 ? std::to_string(timeReadable->tm_mon + 1) : "0" + std::to_string(timeReadable->tm_mon + 1)) + "-" +
|
|
|
|
|
(timeReadable->tm_mday > 9 ? std::to_string(timeReadable->tm_mday) : "0" + std::to_string(timeReadable->tm_mday)) + "_" +
|
|
|
|
|
(timeReadable->tm_hour > 9 ? std::to_string(timeReadable->tm_hour) : "0" + std::to_string(timeReadable->tm_hour)) + "-" +
|
|
|
|
|
(timeReadable->tm_min > 9 ? std::to_string(timeReadable->tm_min) : "0" + std::to_string(timeReadable->tm_min)) + "-" +
|
|
|
|
|
(timeReadable->tm_sec > 9 ? std::to_string(timeReadable->tm_sec) : "0" + std::to_string(timeReadable->tm_sec));
|
|
|
|
|
|
2025-06-08 16:57:37 +02:00
|
|
|
if (satdump::satdump_cfg.getValueFromSatDumpUI<bool>("recorder_baseband_filename_millis_precision"))
|
2024-01-21 21:24:35 +01:00
|
|
|
{
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
|
|
|
|
|
|
double ms_val = fmod(timeValue_precise, 1.0) * 1e3;
|
|
|
|
|
ss << "-" << std::fixed << std::setprecision(0) << std::setw(3) << std::setfill('0') << ms_val;
|
|
|
|
|
timestamp += ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return timestamp + "_" + std::to_string(samplerate) + "SPS_" + std::to_string(frequency) + "Hz";
|
2024-01-23 20:25:27 +01:00
|
|
|
}
|