File: main.cpp

package info (click to toggle)
satdump 1.2.2%2Bgb79af48-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 81,624 kB
  • sloc: cpp: 276,770; ansic: 164,598; lisp: 1,219; sh: 283; xml: 106; makefile: 7
file content (102 lines) | stat: -rw-r--r-- 2,997 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
/**********************************************************************
 * This file is used for testing random stuff without running the
 * whole of SatDump, which comes in handy for debugging individual
 * elements before putting them all together in modules...
 *
 * If you are an user, ignore this file which will not be built by
 * default, and if you're a developper in need of doing stuff here...
 * Go ahead!
 *
 * Don't judge the code you might see in there! :)
 **********************************************************************/

#include "logger.h"

#include "common/ccsds/ccsds_tm/vcdu.h"
#include "common/ccsds/ccsds_tm/demuxer.h"
#include <fstream>
#include "common/simple_deframer.h"

#include "common/image/image.h"
#include "common/image/processing.h"
#include "common/image/io.h"

#include <cstring>

#include "common/repack.h"

#include "common/image/bayer/bayer.h"

#include "common/codings/reedsolomon/reedsolomon.h"

int main(int argc, char *argv[])
{
    initLogger();

    std::ifstream data_in(argv[1], std::ios::binary);

    uint8_t cadu[1279];

    ccsds::ccsds_tm::Demuxer vcid_demuxer(1109, false);

    std::ofstream test_t("/tmp/test.bin");

    reedsolomon::ReedSolomon rs_check(reedsolomon::RS223);

    std::vector<uint16_t> msi_channel;

    while (!data_in.eof())
    {
        // Read buffer
        data_in.read((char *)&cadu, 1279);

        // Check RS
        int errors[5];
        rs_check.decode_interlaved(cadu, true, 5, errors);
        if (errors[0] < 0 || errors[1] < 0 || errors[2] < 0 || errors[3] < 0 || errors[4] < 0)
            continue;

        // Parse this transport frame
        ccsds::ccsds_tm::VCDU vcdu = ccsds::ccsds_tm::parseVCDU(cadu);

        // printf("VCID %d\n", vcdu.vcid);

        if (vcdu.vcid == 6)
        {
            auto pkts = vcid_demuxer.work(cadu);

            for (auto pkt : pkts)
            {
                // printf("APID %d \n", pkt.header.apid);
                if (pkt.header.apid == 1228)
                {
                    // 1027 ?
                    // 1028 ?
                    // 1031 !!!!!
                    // 1032 !!!!!

                    printf("APID %d SIZE %d\n", pkt.header.apid, pkt.payload.size());

                    pkt.payload.resize(3000);

                    int id = pkt.payload[23];

                    if (id == 0)
                    {
                        test_t.write((char *)pkt.header.raw, 6);
                        test_t.write((char *)pkt.payload.data(), pkt.payload.size());

                        for (int i = 0; i < 218; i++)
                        {
                            uint16_t val = pkt.payload[28 + i * 2 + 0] << 8 | pkt.payload[28 + i * 2 + 1];
                            msi_channel.push_back(val);
                        }
                    }
                }
            }
        }
    }

    image::Image img(msi_channel.data(), 16, 218, msi_channel.size() / 218, 1);
    image::save_png(img, "test_earthcare.png");
}