File: module_soft2hard.cpp

package info (click to toggle)
satdump 1.2.2%2Bgb79af48-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 81,648 kB
  • sloc: cpp: 276,768; ansic: 164,598; lisp: 1,219; sh: 283; xml: 106; makefile: 7
file content (128 lines) | stat: -rw-r--r-- 3,966 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "module_soft2hard.h"
#include "logger.h"
#include "imgui/imgui.h"
#include "common/utils.h"

#include "common/codings/differential/nrzm.h"

namespace generic
{
    Soft2HardModule::Soft2HardModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) : ProcessingModule(input_file, output_file_hint, parameters)
    {
        input_buffer = new int8_t[256];
    }

    Soft2HardModule::~Soft2HardModule()
    {
        delete[] input_buffer;
    }

    std::vector<ModuleDataType> Soft2HardModule::getInputTypes()
    {
        return {DATA_FILE, DATA_STREAM};
    }

    std::vector<ModuleDataType> Soft2HardModule::getOutputTypes()
    {
        return {DATA_FILE, DATA_STREAM};
    }

    void Soft2HardModule::process()
    {
        if (input_data_type == DATA_FILE)
            filesize = getFilesize(d_input_file);
        else
            filesize = 0;
        if (input_data_type == DATA_FILE)
            data_in = std::ifstream(d_input_file, std::ios::binary);

        data_out = std::ofstream(d_output_file_hint + ".frm", std::ios::binary);
        d_output_files.push_back(d_output_file_hint + ".frm");

        std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/";

        logger->info("Using input frames " + d_input_file);
        logger->info("Decoding to " + d_output_file_hint + ".frm");

        uint8_t byte_shifter = 0;
        int bitshift_in_byte = 0;
        uint8_t byte_buffer[256];
        int bytes_in_buf = 0;

        diff::NRZMDiff diff;

        time_t lastTime = 0;
        while (input_data_type == DATA_FILE ? !data_in.eof() : input_active.load())
        {
            // Read buffer
            if (input_data_type == DATA_FILE)
                data_in.read((char *)input_buffer, 256);
            else
                input_fifo->read((uint8_t *)input_buffer, 256);

            for (int i = 0; i < 256; i++)
            {
                // Slice
                uint8_t bit = input_buffer[i] > 0;

                byte_shifter = byte_shifter << 1 | bit;
                bitshift_in_byte++;

                if (bitshift_in_byte == 8)
                {
                    byte_buffer[bytes_in_buf] = byte_shifter;
                    bitshift_in_byte = 0;
                    bytes_in_buf++;

                    if (bytes_in_buf == 256)
                    {
                        // diff.decode(byte_buffer, 256);
                        if (output_data_type == DATA_FILE)
                            data_out.write((char *)byte_buffer, 256);
                        else
                            output_fifo->write((uint8_t *)byte_buffer, 256);

                        bytes_in_buf = 0;
                    }
                }
            }

            if (input_data_type == DATA_FILE)
                progress = data_in.tellg();

            if (time(NULL) % 10 == 0 && lastTime != time(NULL))
            {
                lastTime = time(NULL);
                logger->info("Progress " + std::to_string(round(((double)progress / (double)filesize) * 1000.0) / 10.0) + "%%");
            }
        }

        if (input_data_type == DATA_FILE)
            data_in.close();
    }

    void Soft2HardModule::drawUI(bool window)
    {
        ImGui::Begin("Soft To Hard", NULL, window ? 0 : NOWINDOW_FLAGS);

        if (!streamingInput)
            ImGui::ProgressBar((double)progress / (double)filesize, ImVec2(ImGui::GetContentRegionAvail().x, 20 * ui_scale));

        ImGui::End();
    }

    std::string Soft2HardModule::getID()
    {
        return "soft2hard";
    }

    std::vector<std::string> Soft2HardModule::getParameters()
    {
        return {};
    }

    std::shared_ptr<ProcessingModule> Soft2HardModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
    {
        return std::make_shared<Soft2HardModule>(input_file, output_file_hint, parameters);
    }
} // namespace noaa