satdump/plugins/aws_support/aws/module_aws_instruments.cpp

229 lines
8.6 KiB
C++
Raw Permalink Normal View History

2024-09-16 01:19:16 +02:00
#include "module_aws_instruments.h"
#include "common/ccsds/ccsds_tm/demuxer.h"
#include "common/ccsds/ccsds_tm/vcdu.h"
#include "common/utils.h"
#include "core/resources.h"
#include "imgui/imgui.h"
#include "init.h"
#include "logger.h"
2024-09-16 01:19:16 +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"
#include <cstdint>
#include <filesystem>
#include <fstream>
2024-09-16 01:19:16 +02:00
2024-12-29 20:13:58 +01:00
#include "common/tracking/tle.h"
#define AWS_SCID 104
#define AWS_NORAD 60543
2024-09-16 01:19:16 +02:00
namespace aws
{
AWSInstrumentsDecoderModule::AWSInstrumentsDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
: satdump::pipeline::base::FileStreamToFileStreamModule(input_file, output_file_hint, parameters)
2024-09-16 01:19:16 +02:00
{
}
void AWSInstrumentsDecoderModule::process()
{
uint8_t cadu[1279];
logger->info("Demultiplexing and deframing...");
2024-11-01 21:07:54 -03:00
ccsds::ccsds_tm::Demuxer demuxer_vcid2(1109, false);
2024-09-16 01:19:16 +02:00
ccsds::ccsds_tm::Demuxer demuxer_vcid3(1109, false);
std::vector<uint8_t> aws_scids;
while (should_run())
2024-09-16 01:19:16 +02:00
{
// Read buffer
read_data((uint8_t *)cadu, 1279);
2024-09-16 01:19:16 +02:00
// Parse this transport frame
ccsds::ccsds_tm::VCDU vcdu = ccsds::ccsds_tm::parseVCDU(cadu);
if (vcdu.spacecraft_id == AWS_SCID)
aws_scids.push_back(vcdu.spacecraft_id);
if (vcdu.vcid == 2) // Dump
2024-11-01 21:07:54 -03:00
{
std::vector<ccsds::CCSDSPacket> ccsdsFrames = demuxer_vcid2.work(cadu);
for (ccsds::CCSDSPacket &pkt : ccsdsFrames)
if (pkt.header.apid == 100)
2025-01-05 19:57:26 +01:00
mwr_dump_reader.work(pkt);
2024-11-01 21:07:54 -03:00
else if (pkt.header.apid == 51)
navatt_reader.work(pkt);
}
else if (vcdu.vcid == 3) // DB
2024-09-16 01:19:16 +02:00
{
std::vector<ccsds::CCSDSPacket> ccsdsFrames = demuxer_vcid3.work(cadu);
for (ccsds::CCSDSPacket &pkt : ccsdsFrames)
2024-09-21 08:19:18 +02:00
if (pkt.header.apid == 100)
2025-01-05 19:57:26 +01:00
mwr_reader.work(pkt);
2024-09-21 08:19:18 +02:00
else if (pkt.header.apid == 51)
navatt_reader.work(pkt);
2024-09-16 01:19:16 +02:00
}
}
cleanup();
2024-09-16 01:19:16 +02:00
2025-05-26 19:21:10 +01:00
int scid = satdump::most_common(aws_scids.begin(), aws_scids.end(), 0);
2024-09-16 01:19:16 +02:00
aws_scids.clear();
std::string sat_name = "Unknown AWS";
if (scid == AWS_SCID)
sat_name = "AWS";
int norad = 0;
if (scid == AWS_SCID)
norad = AWS_NORAD;
// Products dataset
2025-01-16 11:38:09 +01:00
satdump::products::DataSet dataset;
2024-09-16 01:19:16 +02:00
dataset.satellite_name = sat_name;
2025-05-26 19:21:10 +01:00
dataset.timestamp = satdump::get_median(mwr_reader.timestamps);
2025-01-05 19:57:26 +01:00
if (dataset.timestamp == -1)
2025-05-26 19:21:10 +01:00
dataset.timestamp = satdump::get_median(mwr_dump_reader.timestamps);
2024-09-16 01:19:16 +02:00
2026-05-30 11:12:24 +02:00
std::optional<satdump::TLE> satellite_tle = satdump::db_keplers->get_from_norad_time(norad, dataset.timestamp);
2024-09-16 01:19:16 +02:00
// Satellite ID
{
logger->info("----------- Satellite");
logger->info("NORAD : " + std::to_string(norad));
logger->info("Name : " + sat_name);
}
2025-01-16 11:38:09 +01:00
// TODOREWORK
double mwr_freqs[19] = {
50.3e9, 52.8e9, 53.246e9, 53.596e9, 54.4e9, 54.94e9, 55.5e9, 57.290344e9, 89e9, 165.5e9, 176.311e9, 178.811e9, 180.311e9, 181.511e9, 182.311e9, 325.15e9, 325.15e9, 325.15e9, 325.15e9,
2025-01-16 11:38:09 +01:00
};
// Channels are aligned by groups. 1 to 8 / 9 / 10 to 15 / 16 to 19
satdump::ChannelTransform tran[19];
double halfscan = 145.0 / 2.0;
for (auto &v : tran)
v.init_none();
tran[8].init_affine_slantx(1, 1, -6.5, 0, halfscan, 11.0 / halfscan);
tran[10] = tran[11] = tran[12] = tran[13] = tran[14] = tran[9].init_affine_slantx(0.92, 1, -0.5, 5, halfscan, 11.0 / halfscan);
tran[15] = tran[16] = tran[17] = tran[18].init_affine_slantx(0.93, 1, 2.8, 4, halfscan, 6.0 / halfscan);
// Sterna DB
2024-09-16 01:19:16 +02:00
{
2025-01-05 19:57:26 +01:00
mwr_status = SAVING;
2025-01-16 11:38:09 +01:00
std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/MWR";
2024-09-16 01:19:16 +02:00
if (!std::filesystem::exists(directory))
std::filesystem::create_directory(directory);
2025-01-16 11:38:09 +01:00
logger->info("----------- MWR");
2025-01-05 19:57:26 +01:00
logger->info("Lines : " + std::to_string(mwr_reader.lines));
2024-09-16 01:19:16 +02:00
2025-01-16 11:38:09 +01:00
satdump::products::ImageProduct mwr_products;
mwr_products.instrument_name = "aws_mwr";
2024-09-21 08:19:18 +02:00
2025-01-16 11:38:09 +01:00
nlohmann::json proj_cfg = loadJsonFile(resources::getResourcePath("projections_settings/aws_mwr.json"));
if (d_parameters["use_ephemeris"].get<bool>())
2024-09-21 08:19:18 +02:00
proj_cfg["ephemeris"] = navatt_reader.getEphem();
2025-01-16 11:38:09 +01:00
mwr_products.set_proj_cfg_tle_timestamps(proj_cfg, satellite_tle, mwr_reader.timestamps);
2024-09-16 01:19:16 +02:00
2024-09-16 11:14:21 +02:00
for (int i = 0; i < 19; i++)
2025-01-16 11:38:09 +01:00
{
mwr_products.images.push_back({i, "MWR-" + std::to_string(i + 1), std::to_string(i + 1), mwr_reader.getChannel(i), 16, tran[i]});
2025-01-16 11:38:09 +01:00
mwr_products.set_channel_frequency(i, mwr_freqs[i]);
2025-08-13 22:42:18 +02:00
mwr_products.set_channel_unit(i, CALIBRATION_ID_EMISSIVE_RADIANCE);
2025-01-16 11:38:09 +01:00
}
2024-09-16 01:19:16 +02:00
2025-08-16 17:35:05 +02:00
// mwr_products.set_calibration("aws_mwr", mwr_reader.getCal());
2025-08-13 22:42:18 +02:00
2025-01-05 19:57:26 +01:00
mwr_products.save(directory);
dataset.products_list.push_back("MWR");
2024-09-16 01:19:16 +02:00
2025-01-05 19:57:26 +01:00
mwr_status = DONE;
2024-09-16 01:19:16 +02:00
}
2024-12-29 20:13:58 +01:00
// Sterna Dump
{
2025-01-05 19:57:26 +01:00
mwr_dump_status = SAVING;
std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/MWR_Dump";
2024-12-29 20:13:58 +01:00
if (!std::filesystem::exists(directory))
std::filesystem::create_directory(directory);
2025-01-05 19:57:26 +01:00
logger->info("----------- MWR Dump");
logger->info("Lines : " + std::to_string(mwr_dump_reader.lines));
2024-12-29 20:13:58 +01:00
2025-01-05 19:57:26 +01:00
satdump::products::ImageProduct mwr_dump_product;
mwr_dump_product.instrument_name = "aws_mwr";
2024-12-29 20:13:58 +01:00
2025-01-16 11:38:09 +01:00
nlohmann::json proj_cfg = loadJsonFile(resources::getResourcePath("projections_settings/aws_mwr.json"));
2024-12-29 20:13:58 +01:00
if (d_parameters["use_ephemeris"].get<bool>())
proj_cfg["ephemeris"] = navatt_reader.getEphem();
2025-01-07 19:07:51 +01:00
mwr_dump_product.set_proj_cfg_tle_timestamps(proj_cfg, satellite_tle, mwr_dump_reader.timestamps);
2024-12-29 20:13:58 +01:00
for (int i = 0; i < 19; i++)
{
mwr_dump_product.images.push_back({i, "MWR-" + std::to_string(i + 1), std::to_string(i + 1), mwr_dump_reader.getChannel(i), 16, tran[i]});
2025-01-05 19:57:26 +01:00
mwr_dump_product.set_channel_frequency(i, mwr_freqs[i]);
2025-08-14 00:19:11 +02:00
mwr_dump_product.set_channel_unit(i, CALIBRATION_ID_EMISSIVE_RADIANCE);
2024-12-29 20:13:58 +01:00
}
2025-08-16 17:35:05 +02:00
//mwr_dump_product.set_calibration("aws_mwr", mwr_dump_reader.getCal());
2025-08-14 00:19:11 +02:00
2025-01-05 19:57:26 +01:00
mwr_dump_product.save(directory);
dataset.products_list.push_back("MWR_Dump");
2024-12-29 20:13:58 +01:00
2025-01-05 19:57:26 +01:00
mwr_dump_status = DONE;
2024-12-29 20:13:58 +01:00
}
2024-11-01 21:07:54 -03:00
2024-09-16 01:19:16 +02:00
dataset.save(d_output_file_hint.substr(0, d_output_file_hint.rfind('/')));
}
void AWSInstrumentsDecoderModule::drawUI(bool window)
{
ImGui::Begin("AWS Instruments Decoder", NULL, window ? 0 : NOWINDOW_FLAGS);
if (ImGui::BeginTable("##sawsinstrumentstable", 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);
2025-01-05 19:57:26 +01:00
ImGui::Text("MWR");
2024-09-16 01:19:16 +02:00
ImGui::TableSetColumnIndex(1);
2025-01-05 19:57:26 +01:00
ImGui::TextColored(style::theme.green, "%d", mwr_reader.lines);
2024-09-16 01:19:16 +02:00
ImGui::TableSetColumnIndex(2);
2025-01-05 19:57:26 +01:00
drawStatus(mwr_status);
2024-09-16 01:19:16 +02:00
2024-11-02 02:03:26 -04:00
ImGui::TableNextRow();
2024-11-01 21:07:54 -03:00
ImGui::TableSetColumnIndex(0);
2025-01-05 19:57:26 +01:00
ImGui::Text("MWR Dump");
2024-11-01 21:07:54 -03:00
ImGui::TableSetColumnIndex(1);
2025-01-05 19:57:26 +01:00
ImGui::TextColored(style::theme.green, "%d", mwr_dump_reader.lines);
2024-11-01 21:07:54 -03:00
ImGui::TableSetColumnIndex(2);
2025-01-05 19:57:26 +01:00
drawStatus(mwr_dump_status);
2024-11-01 21:07:54 -03:00
2024-09-16 01:19:16 +02:00
ImGui::EndTable();
}
drawProgressBar();
2024-09-16 01:19:16 +02:00
ImGui::End();
}
std::string AWSInstrumentsDecoderModule::getID() { return "aws_instruments"; }
2024-09-16 01:19:16 +02:00
std::shared_ptr<satdump::pipeline::ProcessingModule> AWSInstrumentsDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
2024-09-16 01:19:16 +02:00
{
return std::make_shared<AWSInstrumentsDecoderModule>(input_file, output_file_hint, parameters);
}
} // namespace aws