satdump/src-testing/main.cpp

189 lines
5.6 KiB
C++
Raw Normal View History

/**********************************************************************
* This file is used for testing random stuff without running the
* whole of SatDump, which comes in handy for debugging individual
* elements before putting them all together in modules...
*
* If you are an user, ignore this file which will not be built by
* default, and if you're a developper in need of doing stuff here...
* Go ahead!
*
* Don't judge the code you might see in there! :)
**********************************************************************/
2025-07-23 12:21:02 +02:00
#include "init.h"
#include "logger.h"
2025-08-05 19:07:45 +02:00
#include "procfile.h"
#include "product_info.h"
#include "type.h"
#include "utils/file/file_iterators.h"
#include "utils/file/folder_file_iterators.h"
#include "utils/file/zip_file_iterators.h"
2025-10-06 16:01:36 +02:00
#include "utils/http.h"
#include "utils/time.h"
#include <cmath>
2025-07-24 21:55:57 +02:00
#include <cstdint>
#include <filesystem>
#include <functional>
2025-07-24 21:55:57 +02:00
#include <memory>
#include <string>
2025-10-06 16:01:36 +02:00
#include <vector>
2025-05-26 19:21:10 +01:00
2025-07-23 12:21:02 +02:00
int main(int argc, char *argv[])
{
initLogger();
2025-05-26 19:21:10 +01:00
2025-10-06 16:01:36 +02:00
std::string f;
satdump::perform_http_request("https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list", f);
std::istringstream ls_stream(f);
std::string l;
while (std::getline(ls_stream, l))
{
if (l.size() > 0 && l[0] == '#')
continue;
logger->trace(l);
std::vector<std::string> parts;
std::string p;
char lastc = ' ';
for (auto &c : l)
{
if (c == ' ' && lastc != ' ')
{
parts.push_back(p);
p.clear();
}
p.push_back(c);
lastc = c;
}
parts.push_back(p);
// for (auto &p : parts)
// logger->info(p);
if (parts.size() == 6)
{
uint64_t tim = std::stoull(parts[0]) - 2208988800;
int leaps = std::stod(parts[1]);
logger->info("%s : %d", satdump::timestamp_to_string(tim).c_str(), leaps);
}
}
#if 0
2025-07-23 12:21:02 +02:00
logger->set_level(slog::LOG_OFF);
satdump::initSatdump();
completeLoggerInit();
logger->set_level(slog::LOG_TRACE);
#if 1
std::string path = argv[1];
{
2025-08-12 13:42:31 +02:00
satdump::firstparty::FirstPartyProductInfo info;
bool is_zip = std::filesystem::path(path).extension() == ".zip";
bool is_file = std::filesystem::is_regular_file(path);
if (is_zip)
{
satdump::utils::ZipFilesIterator fit(path);
std::shared_ptr<satdump::utils::FilesIteratorItem> f;
while (fit.getNext(f))
{
if (f)
{
2025-08-12 13:42:31 +02:00
info = satdump::firstparty::parseFirstPartyInfo(f);
if (info.type != satdump::firstparty::PRODUCT_NONE)
break;
}
}
}
else if (is_file)
{
std::shared_ptr<satdump::utils::FilesIteratorItem> f = std::make_shared<satdump::utils::FolderFileIteratorItem>(path);
2025-08-12 13:42:31 +02:00
info = satdump::firstparty::parseFirstPartyInfo(f);
}
else
{
logger->error("Not a file or ZIP!");
}
logger->info(info.name);
if (info.group_id.size() || is_zip)
{
logger->trace("Group : " + info.group_id);
std::shared_ptr<satdump::utils::FilesIterator> fit;
if (is_zip)
fit = std::make_shared<satdump::utils::ZipFilesIterator>(path);
else
fit = std::make_shared<satdump::utils::FolderFilesIterator>(std::filesystem::path(path).parent_path());
std::shared_ptr<satdump::utils::FilesIteratorItem> f;
while (fit->getNext(f))
{
if (!f)
continue;
2025-08-12 13:42:31 +02:00
if (info.group_id == satdump::firstparty::parseFirstPartyInfo(f).group_id)
{
logger->trace(" - " + f->name);
}
}
}
else
{
std::shared_ptr<satdump::utils::FilesIteratorItem> f = std::make_shared<satdump::utils::FolderFileIteratorItem>(path);
logger->trace(" - " + f->name);
}
}
#else
2025-07-26 10:46:03 +02:00
#if 1
std::unique_ptr<satdump::utils::FilesIterator> fit = std::make_unique<satdump::utils::FolderFilesIterator>(argv[1]);
#else
std::unique_ptr<satdump::utils::FilesIterator> fit = std::make_unique<satdump::utils::ZipFilesIterator>(
"/tmp/satdump_official/W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--x-x---x_C_EUMT_20250724120349_IDPFI_OPE_20250724120007_20250724120935_N__O_0073_0000.zip");
#endif
std::unique_ptr<satdump::utils::FilesIteratorItem> f;
while (fit->getNext(f))
{
if (f)
{
std::string identified;
2025-07-26 10:46:03 +02:00
for (auto &p : satdump::official::getRegisteredProducts())
{
auto finfo = p.testFile(f);
2025-07-26 10:46:03 +02:00
if (finfo.type != satdump::official::PRODUCT_NONE)
identified = (finfo.group_id.size() ? finfo.group_id + " | " : std::string()) + finfo.name; //+ " " = f->name);
}
if (identified.size())
logger->info(f->name + " =======> " + identified);
else
2025-07-26 10:46:03 +02:00
logger->error(f->name);
#if 0
uint32_t test1, test2, test3;
if (sscanf(f->name.c_str(), "W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI%*d+FCI-1C-RRAD-FDHSI-FD--CHK-BODY---NC4E_C_EUMT_%14u_IDPFI_OPE_%14u_%14u_N__O_%*d_%*d.nc", &test1, &test2, &test3) == 3)
{
logger->trace(f->name + " MTG FCI Images");
}
else
{
logger->info(f->name);
}
#endif
}
}
#endif
2025-10-06 16:01:36 +02:00
#endif
}