Program Listing for File antex_loader.h

Return to documentation for file (interfaces/antex_loader.h)

#pragma once

#include <filesystem>
#include <map>
#include <string>
#include <vector>

#include "lupnt/core/definitions.h"
#include "lupnt/devices/space_comms.h"

namespace lupnt {

  class AntexLoader {
  public:
    AntexLoader() = default;

    explicit AntexLoader(const std::filesystem::path& filepath);

    void LoadFile(const std::filesystem::path& filepath);

    Vec3d GetPco(GnssConst gnss_const, int prn, GnssFreq freq, Real t_tai) const;

    Vec3d GetPco(const std::string& gnss_letter, int prn, const std::string& antex_freq_code,
                 Real t_tai) const;

    std::vector<std::string> GetAvailableFreqCodes(GnssConst gnss_const, int prn, Real t_tai) const;

    bool HasSatellite(GnssConst gnss_const, int prn) const;

    // ---- PCO -> ECEF correction --------------------------------------------

    static Mat3d ComputeIjkToEcefRotation(Real t_tai, const Vec3d& r_sat_ecef);

    static Vec3d ApplyPcoCorrectionEcef(Real t_tai, const Vec3d& pos_sp3_ecef,
                                        const Vec3d& pco_neu_m);

    // ---- Identifier helpers (also used by `GnssConstellation` to build SP3 /
    // ANTEX satellite identifiers, e.g. "G05", from `(GnssConst, prn)`) -------

    static std::string GnssLetter(GnssConst gnss_const);

    static std::string SatId(GnssConst gnss_const, int prn);

  private:
    struct FreqPattern {
      std::string freq_code;
      bool has_pco = false;
      Vec3d pco_neu_m = Vec3d::Zero();  // [N, E, U] meters
    };

    struct SatAntennaEntry {
      std::string sat_id;  // e.g. "G05"
      bool has_valid_from = false;
      bool has_valid_until = false;
      double valid_from_tai = 0.0;
      double valid_until_tai = 0.0;
      std::map<std::string, FreqPattern> freqs;  // ANTEX freq code -> pattern
    };

    std::map<std::string, std::vector<SatAntennaEntry>> sat_index_;  // sat_id -> entries

    void ParseFile(const std::filesystem::path& filepath);

    static std::string FreqToAntexCode(const std::string& gnss_letter,
                                       const std::string& freq_name);

    const SatAntennaEntry& SelectEntry(const std::string& sat_id, double t_tai) const;
  };

}  // namespace lupnt