Skip to content

Commit

Permalink
Oops
Browse files Browse the repository at this point in the history
  • Loading branch information
Aang23 committed May 19, 2024
1 parent c708270 commit 048b3b0
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugins/bitview_app/bit_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace satdump
size_t bitstream_pos = offset + line * d_bitperiod + xoffset + i;
size_t raster_pos = line * d_chunk_size + i;

if (bitstream_pos < d_file_memory_size)
if (bitstream_pos < d_file_memory_size * 8)
{
if (xoffset + i < d_bitperiod)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ namespace satdump
size_t bitstream_pos = offset + line * d_bitperiod + xoffset + i * 8;
size_t raster_pos = line * (d_chunk_size / 8) + i;

if (bitstream_pos < d_file_memory_size)
if (bitstream_pos < d_file_memory_size * 8)
{
if (xoffset + i * 8 < d_bitperiod)
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/bitview_app/bitview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "tools/deframer.h"
#include "tools/diff_decode.h"
#include "tools/soft2hard.h"
#include "tools/ccsds_vcid_splitter.h"

namespace satdump
{
Expand All @@ -25,6 +26,7 @@ namespace satdump
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>());
}

BitViewApplication::~BitViewApplication()
Expand Down
97 changes: 97 additions & 0 deletions plugins/bitview_app/tools/ccsds_vcid_splitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#pragma once

#include "tool.h"
#include "imgui/imgui_stdlib.h"
#include <fstream>
#include "core/style.h"
#include "common/ccsds/ccsds_weather/vcdu.h"
#include <map>

namespace satdump
{
class CCSDSVcidSplitterTool : public BitViewTool
{
private:
int cadu_size = 8192;

bool should_process = false;

public:
std::string getName() { return "CCSDS VCID Splitter"; }

void renderMenu(std::shared_ptr<BitContainer> &container, bool is_busy)
{
if (is_busy)
style::beginDisabled();

ImGui::InputInt("CADU Width (bits)", &cadu_size);
if (ImGui::Button("Perform"))
should_process = true;

if (is_busy)
style::endDisabled();
}

bool needToProcess()
{
return should_process;
}

void setProcessed()
{
should_process = false;
}

void process(std::shared_ptr<BitContainer> &container, float &process_progress)
{
uint8_t *ptr = container->get_ptr();
size_t size = container->get_ptr_size();

std::map<int, int> vcid_counts;
std::map<int, std::pair<std::string, std::ofstream>> output_files;

size_t current_ptr = 0;
while (current_ptr < size)
{
size_t csize = std::min<size_t>(cadu_size / 8, size - current_ptr);
if (cadu_size / 8 != csize)
break;

uint8_t *ptr_pos = ptr + current_ptr;

int vcid = 0;
vcid = ccsds::ccsds_weather::parseVCDU(ptr_pos).vcid;

if (output_files.count(vcid) == 0)
{
output_files.emplace(vcid, std::pair<std::string, std::ofstream>{"", std::ofstream()});
vcid_counts.emplace(vcid, 0);

char name[1000];
tmpnam(name);
std::string tmpfile = name;
output_files[vcid].first = tmpfile;
output_files[vcid].second = std::ofstream(tmpfile, std::ios::binary);
}

output_files[vcid].second.write((char *)ptr_pos, cadu_size / 8);
vcid_counts[vcid]++;

current_ptr += csize;

process_progress = double(current_ptr) / double(size);
}

for (auto &f : output_files)
{
f.second.second.close();
std::shared_ptr<satdump::BitContainer> newbitc = std::make_shared<satdump::BitContainer>(container->getName() + " VCID " + std::to_string(f.first) + " (" + std::to_string(vcid_counts[f.first]) + ")", f.second.first);
newbitc->d_bitperiod = cadu_size;
newbitc->init_bitperiod();
newbitc->d_is_temporary = true;

container->all_bit_containers.push_back(newbitc);
}
}
};
}

0 comments on commit 048b3b0

Please sign in to comment.