diff --git a/cxx/CMakeLists.txt b/cxx/CMakeLists.txt index f43994a..a23af11 100644 --- a/cxx/CMakeLists.txt +++ b/cxx/CMakeLists.txt @@ -120,7 +120,7 @@ set(MOUNT_SERVER_APP_SRC mount.h mount_state.h mount_server.cpp comm_server.h co set(MOUNT_SERVER_APP mount_server) add_executable(${MOUNT_SERVER_APP} ${MOUNT_SERVER_APP_SRC}) # target_include_directories(${MOUNT_SERVER_APP} PUBLIC ${ERFA_INCLUDE_DIR}) -target_link_libraries(${MOUNT_SERVER_APP} ${CNTR_PROTO_LIB} spdlog::spdlog_header_only ${ERFA_LIB}) +target_link_libraries(${MOUNT_SERVER_APP} ${CNTR_PROTO_LIB} spdlog::spdlog_header_only ERFA_LIB) if (WITH_TESTS) set(CNTR_PROTO_TEST_APP cntr_proto_test) @@ -133,6 +133,6 @@ if (WITH_TESTS) add_executable(${CFGFILE_TEST_APP} tests/configfile_test.cpp) set(ASTROM_TEST_APP astrom_test) - add_executable(${ASTROM_TEST_APP} tests/astrom_test.cpp - mcc_traits.h) + add_executable(${ASTROM_TEST_APP} tests/astrom_test.cpp) + target_link_libraries(${ASTROM_TEST_APP} ERFA_LIB) endif() diff --git a/cxx/mount.h b/cxx/mount.h index d97d773..f23a287 100644 --- a/cxx/mount.h +++ b/cxx/mount.h @@ -110,6 +110,8 @@ class MccMount : public utils::MccSpdlogLogger public: static constexpr MccMountType mountType = MOUNT_TYPE; + enum IersDatabaseType { IERS_DB_LEAPSECS, IERS_DB_EARTH_ORIENT }; + /* mount main-cycle variable quantities (mount orientation) */ struct mount_orient_t { // time-related @@ -162,23 +164,8 @@ public: logInfo("Load leap seconds and Earth orientation databases ..."); - auto time_db_loader = [this](const std::string& filename, std::string_view type, auto& db) { - if (filename.empty()) { - logWarn("An empty {} filename! Skip and keep default values!", type); - return; - } - - bool ok = db.load(filename); - if (!ok) { - logError("CANNOT parse {} file '{}' or it is not accessible!", type, filename); - logWarn("Keep {} database in default state!", type); - } else { - logInfo("{} database was successfully loaded from '{}' file", type, filename); - } - }; - - time_db_loader(_mountCurrentConfig.leap_seconds_filename, "leap seconds", _leapSecondsDB); - time_db_loader(_mountCurrentConfig.earth_orient_filename, "Earth orientation", _earthOrientDB); + updateIERSDatabase(IERS_DB_LEAPSECS); + updateIERSDatabase(IERS_DB_EARTH_ORIENT); } virtual ~MccMount() @@ -211,6 +198,37 @@ public: _currentMeteo.store(meteo); } + + bool updateIERSDatabase(IersDatabaseType type) + { + auto time_db_loader = [this](const std::string& filename, std::string_view type, auto& db) { + if (filename.empty()) { + logWarn("An empty {} filename! Skip and keep default values!", type); + return false; + } + + bool ok = db.load(filename); + if (!ok) { + logError("CANNOT parse {} file '{}' or it is not accessible!", type, filename); + logWarn("Keep {} database in default state!", type); + } else { + logInfo("{} database was successfully loaded from '{}' file", type, filename); + } + + return ok; + }; + + switch (type) { + case IERS_DB_LEAPSECS: + return time_db_loader(_mountCurrentConfig.leap_seconds_filename, "leap seconds", _leapSecondsDB); + case IERS_DB_EARTH_ORIENT: + return time_db_loader(_mountCurrentConfig.earth_orient_filename, "Earth orientation", _earthOrientDB); + default: + logError("Invalid type for IERS database!"); + return false; + } + } + protected: mount_config_t _mountCurrentConfig; diff --git a/cxx/mount_astrom.h b/cxx/mount_astrom.h index 66d0490..93dfea3 100644 --- a/cxx/mount_astrom.h +++ b/cxx/mount_astrom.h @@ -42,9 +42,8 @@ concept mcc_real_or_char_range = namespace mcc::astrom { -// a time duration represented in radians (the precision is near 1 nanosecond) -// typedef std::chrono::duration> mcc_radsec_duration_t; -typedef std::chrono::duration> mcc_chrono_radians; +// a time duration represented in radians (the precision is about 100 nanosecond for 10E8 secs (~1157 days)) +typedef std::chrono::duration> mcc_chrono_radians; // https://gssc.esa.int/navipedia/index.php?title=CEP_to_ITRF diff --git a/cxx/tests/astrom_test.cpp b/cxx/tests/astrom_test.cpp index 7d8b828..b897579 100644 --- a/cxx/tests/astrom_test.cpp +++ b/cxx/tests/astrom_test.cpp @@ -59,6 +59,15 @@ int main(int argc, char* argv[]) auto st = mcc::astrom::mcc_julday(now, mjd); std::cout << "MJD for now: " << std::setprecision(19) << mjd << " (" << now << ")\n"; + // double pres = 786.6; + // double temp = 0.0; + // double hum = 0.8; + // double A, B; + + // erfa::eraRefco(pres, temp, hum, 0.5, &A, &B); + // const double rr = 180.0 / std::numbers::pi * 60.0; + // std::cout << "A(arcmin) = " << A * rr << "; B(arcmin) = " << B * rr << "\n"; + return ecode; }