2023-12-31 22:51:40 +01:00
|
|
|
#include "module_geoscan_decoder.h"
|
|
|
|
|
#include "common/utils.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "imgui/imgui.h"
|
|
|
|
|
#include "logger.h"
|
2023-12-31 22:51:40 +01:00
|
|
|
|
|
|
|
|
#include "../common/scrambling.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include <cstdint>
|
2023-12-31 22:51:40 +01:00
|
|
|
|
|
|
|
|
namespace geoscan
|
|
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
GEOSCANDecoderModule::GEOSCANDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
|
|
|
|
|
: satdump::pipeline::base::FileStreamToFileStreamModule(input_file, output_file_hint, parameters), d_frame_length(parameters["frame_length"].get<int>()),
|
|
|
|
|
d_thresold(parameters["thresold"].get<int>())
|
2023-12-31 22:51:40 +01:00
|
|
|
{
|
|
|
|
|
input_buffer = new int8_t[256];
|
2024-01-03 10:39:07 +01:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
deframer = std::make_unique<def::SimpleDeframer>(0x930B51DE, 32, (int)((d_frame_length + 4) * 8), d_thresold, false, true);
|
2023-12-31 22:51:40 +01:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
fsfsm_file_ext = ".frm";
|
2023-12-31 22:51:40 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
GEOSCANDecoderModule::~GEOSCANDecoderModule() { delete[] input_buffer; }
|
|
|
|
|
|
|
|
|
|
const uint8_t *GEOSCANDecoderModule::PN9_MASK_Generator()
|
|
|
|
|
{
|
2024-11-03 21:53:52 +03:00
|
|
|
uint8_t mask[8192] = {0};
|
|
|
|
|
uint16_t buffer = 0x1FF;
|
|
|
|
|
uint8_t xor_state = 0;
|
2025-05-31 20:26:47 +02:00
|
|
|
uint8_t *mask_bytes = (uint8_t *)malloc(1024 * sizeof(uint8_t));
|
2024-11-03 21:53:52 +03:00
|
|
|
memset(mask_bytes, 0, 1024);
|
2025-05-31 20:26:47 +02:00
|
|
|
for (int i = 0; i < 8192; i++)
|
|
|
|
|
{
|
2024-11-03 21:53:52 +03:00
|
|
|
mask[i] = buffer & 0b1;
|
2025-05-31 20:26:47 +02:00
|
|
|
xor_state = (buffer & 0b1) ^ (buffer >> 5 & 0b1);
|
|
|
|
|
if (xor_state)
|
|
|
|
|
{
|
|
|
|
|
buffer = (buffer >> 1) | 0x0100;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buffer = (buffer >> 1);
|
|
|
|
|
}
|
2024-11-03 21:53:52 +03:00
|
|
|
}
|
2025-05-31 20:26:47 +02:00
|
|
|
for (int i = 0; i < 1024; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < 8; j++)
|
|
|
|
|
{
|
2024-11-03 21:53:52 +03:00
|
|
|
mask_bytes[i] |= (mask[i * 8 + j] & 0x01) << (0 + j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return mask_bytes;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-31 22:51:40 +01:00
|
|
|
void GEOSCANDecoderModule::process()
|
|
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
const uint8_t *pn9_scrambling = GEOSCANDecoderModule::PN9_MASK_Generator();
|
|
|
|
|
while (should_run())
|
2023-12-31 22:51:40 +01:00
|
|
|
{
|
|
|
|
|
// Read buffer
|
2025-05-31 20:26:47 +02:00
|
|
|
read_data((uint8_t *)input_buffer, 256);
|
2023-12-31 22:51:40 +01:00
|
|
|
|
2024-01-03 10:39:07 +01:00
|
|
|
auto frames = deframer->work((uint8_t *)input_buffer, 256 / 8);
|
2023-12-31 22:51:40 +01:00
|
|
|
|
2024-01-03 10:39:07 +01:00
|
|
|
for (auto &framebuf : frames)
|
|
|
|
|
{
|
2024-11-03 21:53:52 +03:00
|
|
|
for (int i = 0; i < (int)d_frame_length; i++)
|
2024-01-03 10:39:07 +01:00
|
|
|
framebuf[4 + i] ^= pn9_scrambling[i];
|
2023-12-31 22:51:40 +01:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
uint16_t crc_frm1 = crc_check.compute(&framebuf[4], (int)(d_frame_length - 2));
|
|
|
|
|
uint16_t crc_frm2 = framebuf[4 + (int)(d_frame_length - 2) + 0] << 8 | framebuf[4 + (int)(d_frame_length - 2) + 1];
|
2023-12-31 22:51:40 +01:00
|
|
|
|
2024-01-03 10:39:07 +01:00
|
|
|
if (crc_frm1 == crc_frm2)
|
2023-12-31 22:51:40 +01:00
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
write_data((uint8_t *)framebuf.data(), framebuf.size());
|
2024-01-03 10:39:07 +01:00
|
|
|
frm_cnt++;
|
2023-12-31 22:51:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger->info("Decoding finished");
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
cleanup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nlohmann::json GEOSCANDecoderModule::getModuleStats()
|
|
|
|
|
{
|
|
|
|
|
auto v = satdump::pipeline::base::FileStreamToFileStreamModule::getModuleStats();
|
|
|
|
|
v["frm_cnt"] = frm_cnt;
|
|
|
|
|
return v;
|
2023-12-31 22:51:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GEOSCANDecoderModule::drawUI(bool window)
|
|
|
|
|
{
|
2024-11-03 21:53:52 +03:00
|
|
|
ImGui::Begin("GEOSCAN Decoder", NULL, window ? 0 : NOWINDOW_FLAGS);
|
2023-12-31 22:51:40 +01:00
|
|
|
|
|
|
|
|
ImGui::Button("Deframer", {200 * ui_scale, 20 * ui_scale});
|
|
|
|
|
{
|
|
|
|
|
ImGui::Text("Frames : ");
|
|
|
|
|
ImGui::SameLine();
|
2024-01-21 14:57:41 -05:00
|
|
|
ImGui::TextColored(style::theme.green, UITO_C_STR(frm_cnt));
|
2023-12-31 22:51:40 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
drawProgressBar();
|
2023-12-31 22:51:40 +01:00
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
std::string GEOSCANDecoderModule::getID() { return "geoscan_decoder"; }
|
2023-12-31 22:51:40 +01:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
std::shared_ptr<satdump::pipeline::ProcessingModule> GEOSCANDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
|
2023-12-31 22:51:40 +01:00
|
|
|
{
|
|
|
|
|
return std::make_shared<GEOSCANDecoderModule>(input_file, output_file_hint, parameters);
|
|
|
|
|
}
|
2025-05-31 20:26:47 +02:00
|
|
|
} // namespace geoscan
|