File: diff_decode.h

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 (91 lines) | stat: -rw-r--r-- 2,553 bytes parent folder | download | duplicates (2)
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
#pragma once

#include "tool.h"
#include "imgui/imgui_stdlib.h"
#include <fstream>
#include "common/codings/differential/nrzm.h"
#include "core/style.h"

namespace satdump
{
    class DifferentialTool : public BitViewTool
    {
    private:
        int diff_mode = 0;

        bool should_process = false;

    public:
        std::string getName() { return "Differential Decoder"; }

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

            if (ImGui::RadioButton("NRZ-M", diff_mode == 0))
                diff_mode = 0;
            ImGui::SameLine();
            if (ImGui::RadioButton("NRZ-S", diff_mode == 1))
                diff_mode = 1;

            if (ImGui::Button("Differential Decode"))
                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();

            char name[1000];
            tmpnam(name);
            std::string tmpfile = name;
            std::ofstream file_out(tmpfile, std::ios::binary);
            diff::NRZMDiff nrzm_decoder;

            uint8_t tmp_buf[8192];

            size_t current_ptr = 0;
            while (current_ptr < size)
            {
                size_t csize = std::min<size_t>(8192, size - current_ptr);

                memcpy(tmp_buf, ptr + current_ptr, csize);
                current_ptr += csize;

                nrzm_decoder.decode(tmp_buf, csize);

                if (diff_mode == 1)
                    for (int i = 0; i < csize; i++)
                        tmp_buf[i] ^= 0xFF;

                file_out.write((char *)tmp_buf, csize);

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

            file_out.close();

            std::shared_ptr<satdump::BitContainer> newbitc = std::make_shared<satdump::BitContainer>(container->getName() + (diff_mode == 1 ? " NRZ-S" : " NRZ-M"), tmpfile);
            newbitc->d_bitperiod = container->d_bitperiod;
            newbitc->init_bitperiod();
            newbitc->d_is_temporary = true;

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