2024-05-18 18:05:04 +02:00
|
|
|
#include "bitview.h"
|
2025-06-08 18:49:41 +02:00
|
|
|
#include "core/style.h"
|
2024-05-18 18:05:04 +02:00
|
|
|
#include "imgui/imgui_image.h"
|
|
|
|
|
#include "imgui/imgui_stdlib.h"
|
|
|
|
|
#include "imgui/implot/implot.h"
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include "common/utils.h"
|
2025-06-08 18:49:41 +02:00
|
|
|
#include <fcntl.h>
|
2024-05-18 18:05:04 +02:00
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
|
|
#include "logger.h"
|
|
|
|
|
|
2025-06-08 18:49:41 +02:00
|
|
|
#include "tools/ccsds_vcid_splitter.h"
|
2024-05-19 15:16:25 +02:00
|
|
|
#include "tools/deframer.h"
|
|
|
|
|
#include "tools/diff_decode.h"
|
|
|
|
|
#include "tools/soft2hard.h"
|
2024-05-18 18:54:57 +02:00
|
|
|
|
2024-05-18 18:05:04 +02:00
|
|
|
namespace satdump
|
|
|
|
|
{
|
2025-06-08 18:49:41 +02:00
|
|
|
BitViewHandler::BitViewHandler(std::shared_ptr<BitContainer> c) : current_bit_container(c)
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
2025-02-10 20:09:03 +01:00
|
|
|
c->bitview = this;
|
2025-05-04 17:27:35 +02:00
|
|
|
handler_tree_icon = u8"\uf471";
|
2025-02-10 20:09:03 +01:00
|
|
|
|
2024-05-19 15:16:25 +02:00
|
|
|
all_tools.push_back(std::make_shared<DeframerTool>());
|
|
|
|
|
all_tools.push_back(std::make_shared<DifferentialTool>());
|
|
|
|
|
all_tools.push_back(std::make_shared<Soft2HardTool>());
|
2024-05-19 17:34:10 +02:00
|
|
|
all_tools.push_back(std::make_shared<CCSDSVcidSplitterTool>());
|
2024-05-18 18:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-02-10 20:09:03 +01:00
|
|
|
BitViewHandler::BitViewHandler()
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
2025-05-04 17:27:35 +02:00
|
|
|
handler_tree_icon = u8"\uf471";
|
2024-05-18 18:05:04 +02:00
|
|
|
|
2025-02-10 20:09:03 +01:00
|
|
|
all_tools.push_back(std::make_shared<DeframerTool>());
|
|
|
|
|
all_tools.push_back(std::make_shared<DifferentialTool>());
|
|
|
|
|
all_tools.push_back(std::make_shared<Soft2HardTool>());
|
|
|
|
|
all_tools.push_back(std::make_shared<CCSDSVcidSplitterTool>());
|
2024-05-18 18:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2025-06-08 18:49:41 +02:00
|
|
|
BitViewHandler::~BitViewHandler() {}
|
2024-05-18 18:05:04 +02:00
|
|
|
|
2025-02-10 20:09:03 +01:00
|
|
|
void BitViewHandler::drawMenu()
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
2024-05-18 18:54:57 +02:00
|
|
|
if (is_busy)
|
|
|
|
|
style::beginDisabled();
|
2024-08-04 13:59:08 -04:00
|
|
|
if (ImGui::CollapsingHeader("Files##bitview", ImGuiTreeNodeFlags_DefaultOpen))
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
|
|
|
|
ImGui::Text("Load File :");
|
|
|
|
|
if (select_bitfile_dialog.draw() && select_bitfile_dialog.isValid())
|
2024-08-04 13:59:08 -04:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-02-10 20:09:03 +01:00
|
|
|
current_bit_container = std::make_shared<BitContainer>(std::filesystem::path(select_bitfile_dialog.getPath()).stem().string() +
|
|
|
|
|
std::filesystem::path(select_bitfile_dialog.getPath()).stem().extension().string(),
|
|
|
|
|
select_bitfile_dialog.getPath());
|
|
|
|
|
current_bit_container->bitview = this;
|
2024-08-04 13:59:08 -04:00
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
logger->error("Could not load file: %s", e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-18 18:05:04 +02:00
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::CollapsingHeader("Control"))
|
|
|
|
|
{
|
|
|
|
|
if (current_bit_container)
|
|
|
|
|
{
|
|
|
|
|
double vv = current_bit_container->d_bitperiod;
|
|
|
|
|
if (ImGui::InputDouble("Period", &vv))
|
|
|
|
|
{
|
|
|
|
|
current_bit_container->d_bitperiod = vv;
|
|
|
|
|
current_bit_container->init_bitperiod();
|
|
|
|
|
current_bit_container->forceUpdateAll();
|
|
|
|
|
}
|
2024-05-19 15:16:25 +02:00
|
|
|
|
|
|
|
|
if (ImGui::RadioButton("Bits", current_bit_container->d_display_mode == 0))
|
|
|
|
|
{
|
|
|
|
|
current_bit_container->d_display_mode = 0;
|
|
|
|
|
current_bit_container->forceUpdateAll();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::RadioButton("Bytes", current_bit_container->d_display_mode == 1))
|
|
|
|
|
{
|
|
|
|
|
current_bit_container->d_display_mode = 1;
|
|
|
|
|
current_bit_container->forceUpdateAll();
|
|
|
|
|
}
|
2024-05-18 18:05:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-18 18:54:57 +02:00
|
|
|
if (is_busy)
|
|
|
|
|
style::endDisabled();
|
2024-05-19 15:16:25 +02:00
|
|
|
if (ImGui::CollapsingHeader("Tools"))
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
|
|
|
|
if (current_bit_container)
|
|
|
|
|
{
|
2024-05-19 15:16:25 +02:00
|
|
|
for (auto &tool : all_tools)
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
2024-05-19 15:16:25 +02:00
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Text("%s", tool->getName().c_str());
|
|
|
|
|
ImGui::Separator();
|
2024-05-18 18:05:04 +02:00
|
|
|
|
2024-05-19 15:16:25 +02:00
|
|
|
tool->renderMenu(current_bit_container, is_busy);
|
2024-05-18 18:30:56 +02:00
|
|
|
|
2024-05-19 15:16:25 +02:00
|
|
|
if (tool->needToProcess())
|
|
|
|
|
{
|
|
|
|
|
tool->setProcessed();
|
|
|
|
|
auto func = [this, tool](int)
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
2024-05-19 15:16:25 +02:00
|
|
|
tool->process(current_bit_container, process_progress);
|
|
|
|
|
is_busy = false;
|
|
|
|
|
};
|
|
|
|
|
is_busy = true;
|
|
|
|
|
process_threadp.push(func);
|
|
|
|
|
}
|
2024-05-18 18:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-19 15:16:25 +02:00
|
|
|
ImGui::Spacing();
|
2024-05-18 18:54:57 +02:00
|
|
|
|
2024-05-18 18:05:04 +02:00
|
|
|
ImGui::ProgressBar(process_progress);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 18:49:41 +02:00
|
|
|
void BitViewHandler::drawMenuBar() {}
|
2025-02-10 20:09:03 +01:00
|
|
|
|
|
|
|
|
void BitViewHandler::drawContents(ImVec2 win_size)
|
2024-05-18 18:05:04 +02:00
|
|
|
{
|
2025-02-10 20:09:03 +01:00
|
|
|
ImVec2 window_size = win_size;
|
2024-05-18 18:05:04 +02:00
|
|
|
|
|
|
|
|
if (current_bit_container)
|
|
|
|
|
current_bit_container->doUpdateTextures();
|
|
|
|
|
|
|
|
|
|
ImPlot::BeginPlot("MainPlot", window_size, ImPlotFlags_Equal | ImPlotFlags_NoLegend);
|
|
|
|
|
ImPlot::SetupAxes(nullptr, nullptr, 0, ImPlotAxisFlags_Invert);
|
|
|
|
|
|
|
|
|
|
ImPlotRect c = ImPlot::GetPlotLimits();
|
|
|
|
|
if (current_bit_container)
|
|
|
|
|
current_bit_container->doDrawPlotTextures(c);
|
|
|
|
|
|
|
|
|
|
// ImPlot::GetPlotDrawList()->AddRectFilled(ImPlot::PlotToPixels({0, 0}), ImPlot::PlotToPixels({1, 1}), ImColor(255, 0, 0, 255 * 0.5));
|
|
|
|
|
|
|
|
|
|
ImPlot::EndPlot();
|
|
|
|
|
}
|
2025-06-08 18:49:41 +02:00
|
|
|
} // namespace satdump
|