2024-04-20 12:54:48 +02:00
|
|
|
#include "module_wsfm_instruments.h"
|
2024-08-10 15:50:25 +02:00
|
|
|
#include "common/ccsds/ccsds_aos/demuxer.h"
|
|
|
|
|
#include "common/ccsds/ccsds_aos/vcdu.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "common/tracking/tle.h"
|
|
|
|
|
#include "common/utils.h"
|
2025-05-25 14:30:24 +02:00
|
|
|
#include "core/resources.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "imgui/imgui.h"
|
2025-09-26 10:25:46 +02:00
|
|
|
#include "init.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "logger.h"
|
2024-04-20 12:54:48 +02:00
|
|
|
#include "nlohmann/json_utils.h"
|
2025-07-23 12:21:02 +02:00
|
|
|
#include "products/dataset.h"
|
|
|
|
|
#include "products/image_product.h"
|
2025-05-26 19:21:10 +01:00
|
|
|
#include "utils/stats.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <fstream>
|
2024-04-20 12:54:48 +02:00
|
|
|
|
|
|
|
|
namespace wsfm
|
|
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
WSFMInstrumentsDecoderModule::WSFMInstrumentsDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
|
|
|
|
|
: satdump::pipeline::base::FileStreamToFileStreamModule(input_file, output_file_hint, parameters)
|
2024-04-20 12:54:48 +02:00
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
fsfsm_enable_output = false;
|
2024-04-20 12:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSFMInstrumentsDecoderModule::process()
|
|
|
|
|
{
|
|
|
|
|
uint8_t cadu[1024];
|
|
|
|
|
|
|
|
|
|
logger->info("Demultiplexing and deframing...");
|
|
|
|
|
|
2024-08-10 15:50:25 +02:00
|
|
|
ccsds::ccsds_aos::Demuxer demuxer_vcid35(1010, true, 0);
|
2024-04-20 12:54:48 +02:00
|
|
|
|
|
|
|
|
std::vector<uint8_t> wsfm_scids;
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
while (should_run())
|
2024-04-20 12:54:48 +02:00
|
|
|
{
|
|
|
|
|
// Read buffer
|
2025-05-31 20:26:47 +02:00
|
|
|
read_data((uint8_t *)cadu, 1024);
|
2024-04-20 12:54:48 +02:00
|
|
|
|
|
|
|
|
// Parse this transport frame
|
2024-08-10 15:50:25 +02:00
|
|
|
ccsds::ccsds_aos::VCDU vcdu = ccsds::ccsds_aos::parseVCDU(cadu);
|
2024-04-20 12:54:48 +02:00
|
|
|
|
|
|
|
|
// if (vcdu.spacecraft_id == METOP_A_SCID ||
|
|
|
|
|
// vcdu.spacecraft_id == METOP_B_SCID ||
|
|
|
|
|
// vcdu.spacecraft_id == METOP_C_SCID)
|
|
|
|
|
wsfm_scids.push_back(vcdu.spacecraft_id);
|
|
|
|
|
|
|
|
|
|
if (vcdu.vcid == 35) // MWI
|
|
|
|
|
{
|
|
|
|
|
std::vector<ccsds::CCSDSPacket> ccsdsFrames = demuxer_vcid35.work(cadu);
|
|
|
|
|
for (ccsds::CCSDSPacket &pkt : ccsdsFrames)
|
|
|
|
|
mwi_reader.work(pkt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
cleanup();
|
2024-04-20 12:54:48 +02:00
|
|
|
|
2025-05-26 19:21:10 +01:00
|
|
|
int scid = satdump::most_common(wsfm_scids.begin(), wsfm_scids.end(), 0);
|
2024-04-20 12:54:48 +02:00
|
|
|
wsfm_scids.clear();
|
|
|
|
|
|
|
|
|
|
#define WSFM_1_SCID 120
|
|
|
|
|
#define WSFM_1_NORAD 59481
|
|
|
|
|
|
|
|
|
|
std::string sat_name = "Unknown WSF-M";
|
|
|
|
|
if (scid == WSFM_1_SCID)
|
|
|
|
|
sat_name = "WSF-M1";
|
|
|
|
|
|
|
|
|
|
int norad = 0;
|
|
|
|
|
if (scid == WSFM_1_SCID)
|
|
|
|
|
norad = WSFM_1_NORAD;
|
|
|
|
|
|
|
|
|
|
// Products dataset
|
2025-03-11 21:32:38 +01:00
|
|
|
satdump::products::DataSet dataset;
|
2024-04-20 12:54:48 +02:00
|
|
|
dataset.satellite_name = sat_name;
|
2025-05-26 19:21:10 +01:00
|
|
|
dataset.timestamp = satdump::get_median(mwi_reader.timestamps);
|
2024-04-20 12:54:48 +02:00
|
|
|
|
2025-09-26 10:25:46 +02:00
|
|
|
std::optional<satdump::TLE> satellite_tle = satdump::db_tle->get_from_norad_time(norad, dataset.timestamp);
|
2024-05-24 23:19:50 +02:00
|
|
|
|
2024-04-20 12:54:48 +02:00
|
|
|
// Satellite ID
|
|
|
|
|
{
|
|
|
|
|
logger->info("----------- Satellite");
|
|
|
|
|
logger->info("NORAD : " + std::to_string(norad));
|
|
|
|
|
logger->info("Name : " + sat_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MWI
|
|
|
|
|
{
|
|
|
|
|
mwi_status = SAVING;
|
|
|
|
|
std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/MWI";
|
|
|
|
|
|
|
|
|
|
if (!std::filesystem::exists(directory))
|
|
|
|
|
std::filesystem::create_directory(directory);
|
|
|
|
|
|
|
|
|
|
logger->info("----------- MWI");
|
|
|
|
|
logger->info("Lines : " + std::to_string(mwi_reader.lines));
|
|
|
|
|
|
2025-03-11 21:32:38 +01:00
|
|
|
satdump::products::ImageProduct mwi_products;
|
2024-04-20 12:54:48 +02:00
|
|
|
mwi_products.instrument_name = "wsfm_mwi";
|
2025-03-11 21:32:38 +01:00
|
|
|
mwi_products.set_proj_cfg_tle_timestamps(loadJsonFile(resources::getResourcePath("projections_settings/wsfm_mwi.json")), satellite_tle, mwi_reader.timestamps);
|
2024-04-20 12:54:48 +02:00
|
|
|
|
|
|
|
|
for (int i = 0; i < 17; i++)
|
2025-03-11 21:32:38 +01:00
|
|
|
mwi_products.images.push_back({i, "MWI-" + std::to_string(i + 1), std::to_string(i + 1), mwi_reader.getChannel(i), 16});
|
2024-04-20 12:54:48 +02:00
|
|
|
|
|
|
|
|
mwi_products.save(directory);
|
|
|
|
|
dataset.products_list.push_back("MWI");
|
|
|
|
|
|
|
|
|
|
mwi_status = DONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dataset.save(d_output_file_hint.substr(0, d_output_file_hint.rfind('/')));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSFMInstrumentsDecoderModule::drawUI(bool window)
|
|
|
|
|
{
|
|
|
|
|
ImGui::Begin("WSF-M Instruments Decoder", NULL, window ? 0 : NOWINDOW_FLAGS);
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("##wsfminstrumentstable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
|
|
|
|
|
{
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
|
ImGui::Text("Instrument");
|
|
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
|
ImGui::Text("Lines / Frames");
|
|
|
|
|
ImGui::TableSetColumnIndex(2);
|
|
|
|
|
ImGui::Text("Status");
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
|
ImGui::Text("MWI");
|
|
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
|
ImGui::TextColored(style::theme.green, "%d", mwi_reader.lines);
|
|
|
|
|
ImGui::TableSetColumnIndex(2);
|
|
|
|
|
drawStatus(mwi_status);
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
drawProgressBar();
|
2024-04-20 12:54:48 +02:00
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
std::string WSFMInstrumentsDecoderModule::getID() { return "wsfm_instruments"; }
|
2024-04-20 12:54:48 +02:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
std::shared_ptr<satdump::pipeline::ProcessingModule> WSFMInstrumentsDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
|
2024-04-20 12:54:48 +02:00
|
|
|
{
|
|
|
|
|
return std::make_shared<WSFMInstrumentsDecoderModule>(input_file, output_file_hint, parameters);
|
|
|
|
|
}
|
2025-05-31 20:26:47 +02:00
|
|
|
} // namespace wsfm
|