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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#include "module_aim_instruments.h"
#include <fstream>
#include "common/ccsds/ccsds_tm/vcdu.h"
#include "logger.h"
#include <filesystem>
#include "imgui/imgui.h"
#include "common/utils.h"
#include "common/ccsds/ccsds_tm/demuxer.h"
#include "products/products.h"
#include "products/dataset.h"
#include "common/image/io.h"
namespace aim
{
namespace instruments
{
AIMInstrumentsDecoderModule::AIMInstrumentsDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
: ProcessingModule(input_file, output_file_hint, parameters)
{
}
void AIMInstrumentsDecoderModule::process()
{
filesize = getFilesize(d_input_file);
std::ifstream data_in(d_input_file, std::ios::binary);
logger->info("Using input frames " + d_input_file);
time_t lastTime = 0;
uint8_t cadu[1244];
// Demuxers
ccsds::ccsds_tm::Demuxer demuxer_vcid1(1062, true, 12);
// std::ofstream output("file.ccsds");
// Products dataset
// satdump::ProductDataSet dataset;
// dataset.satellite_name = "AIM";
// dataset.timestamp = time(0); // avg_overflowless(avhrr_reader.timestamps);
cips_readers[0].init(340, 170);
cips_readers[1].init(170, 340);
cips_readers[2].init(340, 170);
cips_readers[3].init(170, 340);
while (!data_in.eof())
{
// Read buffer
data_in.read((char *)&cadu, 1244);
// Parse this transport frame
ccsds::ccsds_tm::VCDU vcdu = ccsds::ccsds_tm::parseVCDU(cadu);
// logger->info(pkt.header.apid);
// logger->info(vcdu.vcid);
if (vcdu.vcid == 1) // Replay VCID
{
std::vector<ccsds::CCSDSPacket> ccsdsFrames = demuxer_vcid1.work(cadu);
for (ccsds::CCSDSPacket &pkt : ccsdsFrames)
{
if (pkt.header.apid == 360)
cips_readers[0].work(pkt);
else if (pkt.header.apid == 361)
cips_readers[1].work(pkt);
else if (pkt.header.apid == 362)
cips_readers[2].work(pkt);
else if (pkt.header.apid == 363)
cips_readers[3].work(pkt);
}
}
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) + "%%");
}
}
data_in.close();
// CIPS
{
for (int i = 0; i < 4; i++)
{
cips_status[i] = SAVING;
logger->info("----------- CIPS %d", i + 1);
logger->info("Images : %d", cips_readers[i].images.size());
std::string cips_directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/CIPS-" + std::to_string(i + 1);
if (!std::filesystem::exists(cips_directory))
std::filesystem::create_directory(cips_directory);
int img_cnt = 0;
for (auto &img : cips_readers[i].images)
{
image::save_img(img, cips_directory + "/CIPS_" + std::to_string(img_cnt++ + 1));
}
cips_status[i] = DONE;
}
}
// dataset.save(d_output_file_hint.substr(0, d_output_file_hint.rfind('/')));
}
void AIMInstrumentsDecoderModule::drawUI(bool window)
{
ImGui::Begin("AIM Instruments Decoder", NULL, window ? 0 : NOWINDOW_FLAGS);
if (ImGui::BeginTable("##aiminstrumentstable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Instrument");
ImGui::TableSetColumnIndex(1);
ImGui::Text("Images / Frames");
ImGui::TableSetColumnIndex(2);
ImGui::Text("Status");
for (int i = 0; i < 4; i++)
{
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("CIPS %d", i + 1);
ImGui::TableSetColumnIndex(1);
ImGui::TextColored(style::theme.green, "%d", (int)cips_readers[i].images.size());
ImGui::TableSetColumnIndex(2);
drawStatus(cips_status[i]);
}
ImGui::EndTable();
}
ImGui::ProgressBar((double)progress / (double)filesize, ImVec2(ImGui::GetContentRegionAvail().x, 20 * ui_scale));
ImGui::End();
}
std::string AIMInstrumentsDecoderModule::getID()
{
return "aim_instruments";
}
std::vector<std::string> AIMInstrumentsDecoderModule::getParameters()
{
return {};
}
std::shared_ptr<ProcessingModule> AIMInstrumentsDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
{
return std::make_shared<AIMInstrumentsDecoderModule>(input_file, output_file_hint, parameters);
}
} // namespace amsu
} // namespace metop
|