satdump/src-testing/main.cpp

115 lines
3.3 KiB
C++
Raw Normal View History

/**********************************************************************
* 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! :)
**********************************************************************/
2025-07-05 04:05:20 +02:00
#include "common/ccsds/ccsds_tm/mpdu.h"
#include "logger.h"
2025-05-10 15:33:23 +02:00
2025-07-05 04:05:20 +02:00
#include "common/ccsds/ccsds_tm/demuxer.h"
#include "common/ccsds/ccsds_tm/vcdu.h"
#include "common/simple_deframer.h"
#include <cstdio>
#include <fstream>
2025-05-10 15:33:23 +02:00
2025-07-05 04:05:20 +02:00
#include "image/image.h"
#include "image/io.h"
#include "image/processing.h"
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
#include <cstring>
2025-05-10 15:33:23 +02:00
2025-07-05 04:05:20 +02:00
#include "common/repack.h"
2025-05-10 15:33:23 +02:00
2025-07-05 04:05:20 +02:00
#include "image/bayer/bayer.h"
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
#include "common/codings/reedsolomon/reedsolomon.h"
2025-05-10 15:33:23 +02:00
int main(int argc, char *argv[])
{
2025-05-20 20:33:41 +02:00
initLogger();
2025-07-05 04:05:20 +02:00
std::ifstream data_in(argv[1], std::ios::binary);
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
uint8_t cadu[1279];
2025-05-26 19:21:10 +01:00
2025-07-07 21:56:23 +02:00
ccsds::ccsds_tm::Demuxer vcid_demuxer(1101, true, 0, 4);
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
std::ofstream test_t("/tmp/test.bin");
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
reedsolomon::ReedSolomon rs_check(reedsolomon::RS223);
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
std::vector<uint16_t> msi_channel;
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
while (!data_in.eof())
2025-05-26 19:21:10 +01:00
{
2025-07-05 04:05:20 +02:00
// Read buffer
data_in.read((char *)&cadu, 1279);
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
// // 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;
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
// Parse this transport frame
ccsds::ccsds_tm::VCDU vcdu = ccsds::ccsds_tm::parseVCDU(cadu);
2025-05-26 19:21:10 +01:00
2025-07-05 04:05:20 +02:00
// printf("VCID %d\n", vcdu.vcid);
2025-05-26 19:21:10 +01:00
2025-07-07 21:56:23 +02:00
// printf("SCID %d\n", vcdu.spacecraft_id);
2025-05-26 19:21:10 +01:00
2025-07-07 21:56:23 +02:00
if (vcdu.vcid == 1)
2025-05-26 19:21:10 +01:00
{
2025-07-07 21:56:23 +02:00
#if 1
2025-07-05 04:05:20 +02:00
auto pkts = vcid_demuxer.work(cadu);
for (auto pkt : pkts)
{
2025-07-07 21:56:23 +02:00
// printf("APID %d \n", pkt.header.apid);
if (pkt.header.apid == 1024)
2025-07-05 04:05:20 +02:00
{
// 1027 ?
// 1028 ?
// 1031 !!!!!
// 1032 !!!!!
2025-07-07 21:56:23 +02:00
printf("APID %d SIZE %d\n", pkt.header.apid, pkt.payload.size());
2025-07-05 04:05:20 +02:00
2025-07-07 21:56:23 +02:00
pkt.payload.resize(1018);
2025-07-05 04:05:20 +02:00
2025-07-07 21:56:23 +02:00
// int id = pkt.payload[23];
2025-07-05 04:05:20 +02:00
2025-07-07 21:56:23 +02:00
// if (id == 0)
2025-07-05 04:05:20 +02:00
{
2025-07-07 21:56:23 +02:00
// test_t.write((char *)pkt.header.raw, 6);
// test_t.write((char *)pkt.payload.data(), pkt.payload.size());
test_t.write((char *)pkt.payload.data() + 2, pkt.payload.size() - 2);
2025-07-05 04:05:20 +02:00
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);
}
}
}
}
2025-05-26 19:21:10 +01:00
#endif
2025-07-05 04:05:20 +02:00
// auto mpdu = ccsds::ccsds_tm::parseMPDU(cadu, false, 0, 15);
// if (mpdu.first_header_pointer == 0)
2025-07-07 21:56:23 +02:00
// test_t.write((char *)cadu, 1279);
2025-07-05 04:05:20 +02:00
}
}
2025-07-05 04:05:20 +02:00
image::Image img(msi_channel.data(), 16, 218, msi_channel.size() / 218, 1);
image::save_png(img, "test_earthcare.png");
}