Fix AWS DB / Dump support, temporarily remove navatt dumps

This commit is contained in:
Aang23 2024-12-06 19:58:10 +01:00
parent c2179018a2
commit 41db07db5e
4 changed files with 51 additions and 187 deletions

View file

@ -4,8 +4,6 @@
#include "logger.h"
#include "common/utils.h"
#include "nlohmann/json.hpp"
#include <cstdint>
namespace aws
{
@ -13,7 +11,6 @@ namespace aws
{
NavAttReader::NavAttReader()
{
lines = 0;
}
NavAttReader::~NavAttReader()
@ -50,25 +47,9 @@ namespace aws
if (packet.payload.size() != 117)
return;
uint8_t *dat = packet.payload.data();
uint8_t tmVersionNumber = dat[0] >> 4;
uint8_t spacecraftTimeRefStat = dat[0] & 0b1111;
uint8_t serviceType = dat[1];
uint8_t serviceSubType = dat[2];
uint16_t messageTypeCounter = dat[3] << 8 | dat[4];
uint16_t destinationID = dat[5] << 8 | dat[6];
uint8_t preamble = dat[7];
uint32_t cucTimeSecs = dat[8] << 24 | dat[9] << 16 | dat[10] << 8 | dat[11];
uint32_t cucTimeFrac = dat[12] << 16 | dat[13] << 8 | dat[14];
// Data field
uint16_t sid = dat[15] << 8 | dat[16];
double ephem_timestamp = get_double(&dat[17]) + 3657 * 24 * 3600;
uint32_t orbitNumber = dat[25] << 16 | dat[26] << 8 | dat[27];
uint32_t orbitFraction = dat[28] << 24 | dat[29] << 16 | dat[30] << 8 | dat[31];
uint8_t posVelQuality = dat[32];
uint8_t *dat = &packet.payload[21 - 6 + 2];
double ephem_timestamp = get_double(&dat[0]) + 3657 * 24 * 3600;
double ephem_x = get_float(&dat[33]);
double ephem_y = get_float(&dat[37]);
double ephem_z = get_float(&dat[41]);
@ -76,134 +57,7 @@ namespace aws
double ephem_vy = get_float(&dat[49]);
double ephem_vz = get_float(&dat[53]);
uint8_t attitudeQual = dat[65];
double quaternion1 = get_double(&dat[66]);
double quaternion2 = get_double(&dat[74]);
double quaternion3 = get_double(&dat[82]);
double quaternion4 = get_double(&dat[90]);
float xRate = get_float(&dat[98]);
float yRate = get_float(&dat[102]);
float zRate = get_float(&dat[106]);
uint8_t spacecraftMode = dat[110];
uint8_t manoeuvreFlag = dat[111];
uint8_t payloadMode = dat[112];
uint16_t scid = dat[113] << 8 | dat[114];
double epochTimestamp = cucTimeSecs + cucTimeFrac / 16777215.0 + 3657 * 24 * 3600;
telemetry["TM Version Number"].push_back(tmVersionNumber);
if (spacecraftTimeRefStat == 0b0000)
telemetry["Spacecraft Time Reference Status"].push_back("Undefined");
else if (spacecraftTimeRefStat == 0b0001)
telemetry["Spacecraft Time Reference Status"].push_back("Not synchronized");
else if (spacecraftTimeRefStat == 0b0010)
telemetry["Spacecraft Time Reference Status"].push_back("Coarse");
else if (spacecraftTimeRefStat == 0b0011)
telemetry["Spacecraft Time Reference Status"].push_back("Coarse From Fine");
else if (spacecraftTimeRefStat == 0b0100)
telemetry["Spacecraft Time Reference Status"].push_back("Fine");
if (serviceType == 0b0011)
telemetry["Service Type"].push_back("NAVATT");
else if (serviceType == 0b10000000)
telemetry["Service Type"].push_back("SCIENCE");
telemetry["Service Sub-type"].push_back(serviceSubType);
telemetry["Message Type Counter"].push_back(messageTypeCounter);
if (destinationID == 0b0)
telemetry["Destination ID"].push_back("Ground");
else if (destinationID == 0b1)
telemetry["Destination ID"].push_back("On-board");
telemetry["Preamble"].push_back(preamble);
telemetry["CUC Time Seconds"].push_back(cucTimeSecs);
telemetry["CUC Time Fraction"].push_back(cucTimeFrac);
telemetry["Epoch Timestamp"].push_back(epochTimestamp);
// Data field
telemetry["SID"].push_back(sid);
telemetry["Navigation timestamp"].push_back(ephem_timestamp);
telemetry["Orbit Number"].push_back(orbitNumber);
telemetry["Orbit Fraction"].push_back(orbitFraction);
if (posVelQuality == 0b00)
telemetry["Position Velocity Quality"].push_back("None");
else if (posVelQuality == 0b01)
telemetry["Position Velocity Quality"].push_back("TLE");
else if (posVelQuality == 0b10)
telemetry["Position Velocity Quality"].push_back("Propagation");
else if (posVelQuality == 0b11)
telemetry["Position Velocity Quality"].push_back("GNSS");
telemetry["X position"].push_back(ephem_x);
telemetry["Y position"].push_back(ephem_y);
telemetry["Z position"].push_back(ephem_z);
telemetry["X Velocity"].push_back(ephem_vx);
telemetry["Y Velocity"].push_back(ephem_vy);
telemetry["Z Velocity"].push_back(ephem_vz);
telemetry["Attitude timestamp"].push_back(ephem_timestamp);
if (attitudeQual == 0b0000)
telemetry["Attitude Quality"].push_back("None");
else if (attitudeQual == 0b0001)
telemetry["Attitude Quality"].push_back("Torque only");
else if (attitudeQual == 0b0010)
telemetry["Attitude Quality"].push_back("GYR only");
else if (attitudeQual == 0b0011)
telemetry["Attitude Quality"].push_back("ST1 only");
else if (attitudeQual == 0b0100)
telemetry["Attitude Quality"].push_back("ST2 only");
else if (attitudeQual == 0b0101)
telemetry["Attitude Quality"].push_back("ST1 & ST2");
else if (attitudeQual == 0b0111)
telemetry["Attitude Quality"].push_back("ST1 & GYR only");
else if (attitudeQual == 0b1000)
telemetry["Attitude Quality"].push_back("ST1 & GYR only");
else if (attitudeQual == 0b1001)
telemetry["Attitude Quality"].push_back("ST1 & ST2 & GYR");
telemetry["Quaternion 1"].push_back(quaternion1);
telemetry["Quaternion 2"].push_back(quaternion2);
telemetry["Quaternion 3"].push_back(quaternion3);
telemetry["Quaternion 4"].push_back(quaternion4);
telemetry["X Rate"].push_back(xRate);
telemetry["Y Rate"].push_back(yRate);
telemetry["Z Rate"].push_back(zRate);
if (spacecraftMode == 0b0111)
telemetry["Spacecraft Mode"].push_back("Orbit Maintenance Mode");
else if (spacecraftMode == 0b1000)
telemetry["Spacecraft Mode"].push_back("Payload Operations Mode");
if (manoeuvreFlag == 0b00)
telemetry["Manoeuvre Flag"].push_back("None");
else if (manoeuvreFlag == 0b01)
telemetry["Manoeuvre Flag"].push_back("EP Firing");
else if (manoeuvreFlag == 0b10)
telemetry["Manoeuvre Flag"].push_back("Momentum Management");
else if (manoeuvreFlag == 0b11)
telemetry["Manoeuvre Flag"].push_back("EP Firing + Momentum Management");
if (payloadMode == 0b0000)
telemetry["Payload Mode"].push_back("Off");
else if (payloadMode == 0b0001)
telemetry["Payload Mode"].push_back("Bootloader");
else if (payloadMode == 0b0010)
telemetry["Payload Mode"].push_back("Startup");
else if (payloadMode == 0b0011)
telemetry["Payload Mode"].push_back("Operation");
else if (payloadMode == 0b0100)
telemetry["Payload Mode"].push_back("Safe");
else if (payloadMode == 0b0101)
telemetry["Payload Mode"].push_back("Test");
telemetry["SCID"].push_back(scid);
lines++;
//logger->info("NAVATT! %s", timestamp_to_string(ephem_timestamp).c_str());
logger->info("NAVATT! %s", timestamp_to_string(ephem_timestamp).c_str());
#if 0
// double atti_timestamp = get_timestamp(&dat[33]);
@ -218,10 +72,10 @@ namespace aws
if (fabs(ephem_vx) > 8000000 || fabs(ephem_vy) > 8000000 || fabs(ephem_vz) > 8000000)
return;
//printf("%f - %f %f %f - %f %f %f\n",
// ephem_timestamp,
// ephem_x, ephem_y, ephem_z,
// ephem_vx, ephem_vy, ephem_vz);
printf("%f - %f %f %f - %f %f %f\n",
ephem_timestamp,
ephem_x, ephem_y, ephem_z,
ephem_vx, ephem_vy, ephem_vz);
ecef_epehem_to_eci(ephem_timestamp, ephem_x, ephem_y, ephem_z, ephem_vx, ephem_vy, ephem_vz);
@ -236,11 +90,6 @@ namespace aws
ephems_n++;
}
nlohmann::ordered_json NavAttReader::dump_telemetry()
{
return telemetry;
}
nlohmann::json NavAttReader::getEphem()
{
return ephems;

View file

@ -2,7 +2,6 @@
#include "common/ccsds/ccsds.h"
#include <cmath>
#include <cstdint>
#include "nlohmann/json.hpp"
namespace aws
@ -14,7 +13,6 @@ namespace aws
private:
int ephems_n = 0;
nlohmann::json ephems;
nlohmann::ordered_json telemetry;
public:
NavAttReader();
@ -22,8 +20,6 @@ namespace aws
void work(ccsds::CCSDSPacket &packet);
int lines;
nlohmann::ordered_json dump_telemetry();
nlohmann::json getEphem();
};
}

View file

@ -11,6 +11,9 @@
#include "resources.h"
#include "nlohmann/json_utils.h"
#define AWS_SCID 104
#define AWS_NORAD 60543
namespace aws
{
AWSInstrumentsDecoderModule::AWSInstrumentsDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) : ProcessingModule(input_file, output_file_hint, parameters)
@ -41,20 +44,20 @@ namespace aws
// Parse this transport frame
ccsds::ccsds_tm::VCDU vcdu = ccsds::ccsds_tm::parseVCDU(cadu);
aws_scids.push_back(vcdu.spacecraft_id);
if (vcdu.vcid == 2) // Stored S/C Sciente telemetry dataa
if (vcdu.spacecraft_id == AWS_SCID)
aws_scids.push_back(vcdu.spacecraft_id);
if (vcdu.vcid == 2) // Dump
{
std::vector<ccsds::CCSDSPacket> ccsdsFrames = demuxer_vcid2.work(cadu);
for (ccsds::CCSDSPacket &pkt : ccsdsFrames)
if (pkt.header.apid == 100)
sterna_reader.work(pkt);
sterna_dump_reader.work(pkt);
else if (pkt.header.apid == 51)
navatt_reader.work(pkt);
}
if (vcdu.vcid == 3) // DDB service
else if (vcdu.vcid == 3) // DB
{
std::vector<ccsds::CCSDSPacket> ccsdsFrames = demuxer_vcid3.work(cadu);
for (ccsds::CCSDSPacket &pkt : ccsdsFrames)
@ -78,9 +81,6 @@ namespace aws
int scid = most_common(aws_scids.begin(), aws_scids.end(), 0);
aws_scids.clear();
#define AWS_SCID 104
#define AWS_NORAD 60543
std::string sat_name = "Unknown AWS";
if (scid == AWS_SCID)
sat_name = "AWS";
@ -103,7 +103,7 @@ namespace aws
logger->info("Name : " + sat_name);
}
// Sterna
// Sterna DB
{
sterna_status = SAVING;
std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/STERNA";
@ -123,7 +123,7 @@ namespace aws
sterna_products.set_timestamps(sterna_reader.timestamps);
nlohmann::json proj_cfg = loadJsonFile(resources::getResourcePath("projections_settings/aws_sterna.json"));
if (getValueOrDefault(d_parameters["use_ephemeris"], false))
if (d_parameters["use_ephemeris"].get<bool>())
proj_cfg["ephemeris"] = navatt_reader.getEphem();
sterna_products.set_proj_cfg(proj_cfg);
@ -136,20 +136,37 @@ namespace aws
sterna_status = DONE;
}
// NAVATT
// Sterna Dump
{
navatt_status = SAVING;
std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/NAVATT";
sterna_dump_status = SAVING;
std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/STERNA_Dump";
if (!std::filesystem::exists(directory))
std::filesystem::create_directory(directory);
logger->info("----------- NAVATT");
logger->info("Lines : " + std::to_string(navatt_reader.lines));
logger->info("----------- STERNA Dump");
logger->info("Lines : " + std::to_string(sterna_dump_reader.lines));
saveJsonFile(directory + "/NAVATT-Telemetry.json", navatt_reader.dump_telemetry());
satdump::ImageProducts sterna_dump_products;
sterna_dump_products.instrument_name = "sterna";
sterna_dump_products.has_timestamps = true;
sterna_dump_products.set_tle(satellite_tle);
sterna_dump_products.bit_depth = 16;
sterna_dump_products.timestamp_type = satdump::ImageProducts::TIMESTAMP_LINE;
sterna_dump_products.set_timestamps(sterna_dump_reader.timestamps);
navatt_status = DONE;
nlohmann::json proj_cfg = loadJsonFile(resources::getResourcePath("projections_settings/aws_sterna.json"));
if (d_parameters["use_ephemeris"].get<bool>())
proj_cfg["ephemeris"] = navatt_reader.getEphem();
sterna_dump_products.set_proj_cfg(proj_cfg);
for (int i = 0; i < 19; i++)
sterna_dump_products.images.push_back({"STERNA-" + std::to_string(i + 1), std::to_string(i + 1), sterna_dump_reader.getChannel(i)});
sterna_dump_products.save(directory);
dataset.products_list.push_back("STERNA_Dump");
sterna_dump_status = DONE;
}
dataset.save(d_output_file_hint.substr(0, d_output_file_hint.rfind('/')));
@ -171,7 +188,7 @@ namespace aws
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("AWS");
ImGui::Text("Sterna");
ImGui::TableSetColumnIndex(1);
ImGui::TextColored(style::theme.green, "%d", sterna_reader.lines);
ImGui::TableSetColumnIndex(2);
@ -179,16 +196,17 @@ namespace aws
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("NAVATT");
ImGui::Text("Sterna Dump");
ImGui::TableSetColumnIndex(1);
ImGui::TextColored(style::theme.green, "%d", navatt_reader.lines);
ImGui::TextColored(style::theme.green, "%d", sterna_dump_reader.lines);
ImGui::TableSetColumnIndex(2);
drawStatus(navatt_status);
drawStatus(sterna_dump_status);
ImGui::EndTable();
}
ImGui::ProgressBar((double)progress / (double)filesize, ImVec2(ImGui::GetContentRegionAvail().x, 20 * ui_scale));
ImGui::End();
}
@ -206,4 +224,4 @@ namespace aws
{
return std::make_shared<AWSInstrumentsDecoderModule>(input_file, output_file_hint, parameters);
}
}
}

View file

@ -14,11 +14,12 @@ namespace aws
// Readers
sterna::SternaReader sterna_reader;
sterna::SternaReader sterna_dump_reader;
navatt::NavAttReader navatt_reader;
// Statuses
instrument_status_t sterna_status = DECODING;
instrument_status_t navatt_status = DECODING;
instrument_status_t sterna_dump_status = DECODING;
public:
AWSInstrumentsDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
@ -31,4 +32,4 @@ namespace aws
static std::vector<std::string> getParameters();
static std::shared_ptr<ProcessingModule> getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
};
}
}