diff --git a/pipelines/HRPT.json b/pipelines/HRPT.json index bd5a1a25d..173515e73 100644 --- a/pipelines/HRPT.json +++ b/pipelines/HRPT.json @@ -136,6 +136,7 @@ } }, "products": { + "fengyun_satid": {}, "fengyun_virr": {}, "fengyun_erm": {}, "fengyun_mwhs": {}, @@ -182,6 +183,7 @@ } }, "products": { + "fengyun_satid": {}, "fengyun_virr": {}, "fengyun_erm": {}, "fengyun_mwhs": {} @@ -223,6 +225,9 @@ } }, "products": { + "fengyun_satid": { + "scid_hint": "51" + }, "fengyun_virr": {}, "fengyun_erm": {}, "fengyun_mwhs2": {} @@ -268,6 +273,9 @@ } }, "products": { + "fengyun_satid": { + "scid_hint": "51" + }, "fengyun_virr": {}, "fengyun_erm": {}, "fengyun_mwhs2": {} diff --git a/pipelines/X-Band.json b/pipelines/X-Band.json index 9c1e1215d..d354b8fc7 100644 --- a/pipelines/X-Band.json +++ b/pipelines/X-Band.json @@ -58,6 +58,9 @@ } }, "products": { + "fengyun_satid": { + "scid_hint": "52" + }, "fengyun_mersi2": { "correct_bowtie": "1" }, diff --git a/src-core/module.cpp b/src-core/module.cpp index d531679d0..8707120a0 100644 --- a/src-core/module.cpp +++ b/src-core/module.cpp @@ -87,6 +87,7 @@ SATDUMP_DLL std::mapinfo("Demultiplexing and deframing..."); - std::string c10_filename = "FY3x_" + getHRPTReaderTimeStamp() + ".C10"; + // Get satellite info + nlohmann::json satData = loadJsonFile(d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/sat_info.json"); + int scid = satData.contains("scid") > 0 ? satData["scid"].get() : 0; + + // Name the file properly + std::string hpt_prefix = "FY3x_"; + + if (scid == FY3_A_SCID) + hpt_prefix = "FY3A_"; + else if (scid == FY3_B_SCID) + hpt_prefix = "FY3B_"; + else if (scid == FY3_C_SCID) + hpt_prefix = "FY3C_"; + + std::string c10_filename = hpt_prefix + getHRPTReaderTimeStamp() + ".C10"; std::ofstream output_hrpt_reader(directory + "/" + c10_filename, std::ios::binary); d_output_files.push_back(directory + "/" + c10_filename); diff --git a/src-core/modules/fengyun/module_fengyun_satid.cpp b/src-core/modules/fengyun/module_fengyun_satid.cpp new file mode 100644 index 000000000..a1e896cb8 --- /dev/null +++ b/src-core/modules/fengyun/module_fengyun_satid.cpp @@ -0,0 +1,139 @@ +#include "module_fengyun_satid.h" +#include +#include "common/ccsds/ccsds_1_0_1024/vcdu.h" +#include "logger.h" +#include +#include "imgui/imgui.h" +#include "common/utils.h" +#include "fengyun3.h" +#include "nlohmann/json_utils.h" + +#define BUFFER_SIZE 8192 + +// Return filesize +size_t getFilesize(std::string filepath); + +namespace fengyun +{ + namespace satid + { + FengYunSatIDModule::FengYunSatIDModule(std::string input_file, std::string output_file_hint, std::map parameters) : ProcessingModule(input_file, output_file_hint, parameters), + scid_hint(parameters.count("scid_hint") > 0 ? std::stoi(parameters["scid_hint"]) : -1) + { + } + + void FengYunSatIDModule::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[1024]; + + logger->info("Scanning through CADUs..."); + + std::vector scids; + + while (!data_in.eof()) + { + // Read buffer + data_in.read((char *)&cadu, 1024); + + // Parse this transport frame + ccsds::ccsds_1_0_1024::VCDU vcdu = ccsds::ccsds_1_0_1024::parseVCDU(cadu); + + if (vcdu.spacecraft_id == FY3_A_SCID || + vcdu.spacecraft_id == FY3_B_SCID || + vcdu.spacecraft_id == FY3_C_SCID || + vcdu.spacecraft_id == FY3_D_SCID) + scids.push_back(vcdu.spacecraft_id); + + progress = data_in.tellg(); + + if (time(NULL) % 10 == 0 && lastTime != time(NULL)) + { + lastTime = time(NULL); + logger->info("Progress " + std::to_string(round(((float)progress / (float)filesize) * 1000.0f) / 10.0f) + "%"); + } + } + + data_in.close(); + + int scid = most_common(scids.begin(), scids.end()); + + logger->info("SCID " + std::to_string(scid) + " was most common."); + + if (scid_hint > 0) + { + if (scid == scid_hint) + { + logger->debug("That matches with the provided SCID."); + } + else + { + logger->error("Detected SCID did not match expectations! Defaulting to provided value..."); + scid = scid_hint; + } + } + + std::string sat_name = "Unknown FengYun"; + + if (scid == FY3_A_SCID) + sat_name = "FengYun-3A"; + else if (scid == FY3_B_SCID) + sat_name = "FengYun-3B"; + else if (scid == FY3_C_SCID) + sat_name = "FengYun-3C"; + else if (scid == FY3_D_SCID) + sat_name = "FengYun-3D"; + + int norad = 0; + + if (scid == FY3_A_SCID) + norad = FY3_A_NORAD; + else if (scid == FY3_B_SCID) + norad = FY3_B_NORAD; + else if (scid == FY3_C_SCID) + norad = FY3_C_NORAD; + else if (scid == FY3_D_SCID) + norad = FY3_D_NORAD; + + logger->info("This is satellite is " + sat_name + ", NORAD " + std::to_string(norad)); + + nlohmann::json jData; + + jData["scid"] = scid; + jData["name"] = sat_name; + jData["norad"] = norad; + + saveJsonFile(d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/sat_info.json", jData); + } + + void FengYunSatIDModule::drawUI(bool window) + { + ImGui::Begin("FengYun Satellite Identifier", NULL, window ? NULL : NOWINDOW_FLAGS); + + ImGui::ProgressBar((float)progress / (float)filesize, ImVec2(ImGui::GetWindowWidth() - 10, 20 * ui_scale)); + + ImGui::End(); + } + + std::string FengYunSatIDModule::getID() + { + return "fengyun_satid"; + } + + std::vector FengYunSatIDModule::getParameters() + { + return {"scid_hint"}; + } + + std::shared_ptr FengYunSatIDModule::getInstance(std::string input_file, std::string output_file_hint, std::map parameters) + { + return std::make_shared(input_file, output_file_hint, parameters); + } + } // namespace amsu +} // namespace metop \ No newline at end of file diff --git a/src-core/modules/fengyun/module_fengyun_satid.h b/src-core/modules/fengyun/module_fengyun_satid.h new file mode 100644 index 000000000..b9413c838 --- /dev/null +++ b/src-core/modules/fengyun/module_fengyun_satid.h @@ -0,0 +1,28 @@ +#pragma once + +#include "module.h" + +namespace fengyun +{ + namespace satid + { + class FengYunSatIDModule : public ProcessingModule + { + protected: + std::atomic filesize; + std::atomic progress; + + const int scid_hint; + + public: + FengYunSatIDModule(std::string input_file, std::string output_file_hint, std::map parameters); + void process(); + void drawUI(bool window); + + public: + static std::string getID(); + static std::vector getParameters(); + static std::shared_ptr getInstance(std::string input_file, std::string output_file_hint, std::map parameters); + }; + } // namespace amsu +} // namespace metop \ No newline at end of file