satdump/plugins/dmsp_support/dmsp/module_dmsp_rtd_decoder.cpp

136 lines
4.2 KiB
C++
Raw Permalink Normal View History

2022-10-23 03:05:39 +02:00
#include "module_dmsp_rtd_decoder.h"
#include "imgui/imgui.h"
#include "logger.h"
2025-07-11 23:19:47 +02:00
#include "nlohmann/json_utils.h"
#include <cstdint>
2025-07-11 23:19:47 +02:00
#include <fstream>
#include <string>
2022-10-23 03:05:39 +02:00
#include <volk/volk.h>
#define BUFFER_SIZE 8192
#define RTD_FRAME_SIZE 19
namespace dmsp
{
DMSPRTDDecoderModule::DMSPRTDDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
: satdump::pipeline::base::FileStreamToFileStreamModule(input_file, output_file_hint, parameters), constellation(1.0, 0.15, demod_constellation_size)
2022-10-23 03:05:39 +02:00
{
def = std::make_shared<DMSP_Deframer>(150, 2);
soft_buffer = new int8_t[BUFFER_SIZE];
soft_bits = new uint8_t[BUFFER_SIZE];
output_frames = new uint8_t[BUFFER_SIZE];
fsfsm_file_ext = ".frm";
2022-10-23 03:05:39 +02:00
}
DMSPRTDDecoderModule::~DMSPRTDDecoderModule()
{
delete[] soft_buffer;
delete[] soft_bits;
delete[] output_frames;
}
void DMSPRTDDecoderModule::process()
{
2025-07-11 23:19:47 +02:00
double start_timestamp = getValueOrDefault(d_parameters["start_timestamp"], -1);
size_t accumulated_samples = 0;
std::ofstream timestamps_out;
if (start_timestamp != -1)
timestamps_out = std::ofstream(d_output_file_hint + "_timestamps.txt", std::ios::binary);
while (should_run())
2022-10-23 03:05:39 +02:00
{
// Read a buffer
read_data((uint8_t *)soft_buffer, BUFFER_SIZE);
2022-10-23 03:05:39 +02:00
for (int i = 0; i < BUFFER_SIZE; i++)
soft_bits[i] = soft_buffer[i] > 0;
int nframes = def->work(soft_bits, BUFFER_SIZE, output_frames);
// Count frames
// frame_count += nframes;
// Write to file
if (nframes > 0)
2025-07-11 23:19:47 +02:00
{
write_data((uint8_t *)output_frames, nframes * RTD_FRAME_SIZE);
2025-07-11 23:19:47 +02:00
accumulated_samples += BUFFER_SIZE;
if (start_timestamp != -1)
{
for (int i = 0; i < nframes; i++)
{
double curr_timestamp = start_timestamp + double(accumulated_samples) / 1.024e6;
timestamps_out << std::to_string(curr_timestamp) << '\n';
}
}
}
2022-10-23 03:05:39 +02:00
}
2025-07-11 23:19:47 +02:00
if (start_timestamp != -1)
timestamps_out.close();
2022-10-23 03:05:39 +02:00
logger->info("Decoding finished");
cleanup();
}
nlohmann::json DMSPRTDDecoderModule::getModuleStats()
{
auto v = satdump::pipeline::base::FileStreamToFileStreamModule::getModuleStats();
std::string deframer_state = def->getState() == def->STATE_NOSYNC ? "NOSYNC" : (def->getState() == def->STATE_SYNCING ? "SYNCING" : "SYNCED");
v["deframer_state"] = deframer_state;
return v;
2022-10-23 03:05:39 +02:00
}
void DMSPRTDDecoderModule::drawUI(bool window)
{
ImGui::Begin("DMSP RTD Decoder", NULL, window ? 0 : NOWINDOW_FLAGS);
ImGui::BeginGroup();
constellation.pushSofttAndGaussian(soft_buffer, 127, BUFFER_SIZE);
constellation.draw();
ImGui::EndGroup();
ImGui::SameLine();
ImGui::BeginGroup();
{
ImGui::Button("Deframer", {200 * ui_scale, 20 * ui_scale});
{
ImGui::Text("State : ");
ImGui::SameLine();
if (def->getState() == def->STATE_NOSYNC)
2024-01-21 14:57:41 -05:00
ImGui::TextColored(style::theme.red, "NOSYNC");
2022-10-23 03:05:39 +02:00
else if (def->getState() == def->STATE_SYNCING)
2024-01-21 14:57:41 -05:00
ImGui::TextColored(style::theme.orange, "SYNCING");
2022-10-23 03:05:39 +02:00
else
2024-01-21 14:57:41 -05:00
ImGui::TextColored(style::theme.green, "SYNCED");
2022-10-23 03:05:39 +02:00
// ImGui::Text("Frames : ");
// ImGui::SameLine();
2024-01-21 14:57:41 -05:00
// ImGui::TextColored(style::theme.green, UITO_C_STR(frame_count));
2022-10-23 03:05:39 +02:00
}
}
ImGui::EndGroup();
drawProgressBar();
2022-10-23 03:05:39 +02:00
ImGui::End();
}
std::string DMSPRTDDecoderModule::getID() { return "dmsp_rtd_decoder"; }
2022-10-23 03:05:39 +02:00
std::shared_ptr<satdump::pipeline::ProcessingModule> DMSPRTDDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
2022-10-23 03:05:39 +02:00
{
return std::make_shared<DMSPRTDDecoderModule>(input_file, output_file_hint, parameters);
}
} // namespace dmsp