From ea99bc721bee52c013e72bc74a8e25a9d1796a89 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Wed, 16 Apr 2025 18:12:02 +0300 Subject: [PATCH] ... --- cxx/CMakeLists.txt | 5 ++--- cxx/mcc_coord.h | 12 +++++++----- cxx/mount.h | 19 ++++++++++++++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/cxx/CMakeLists.txt b/cxx/CMakeLists.txt index d83ec2d..5f5bc03 100644 --- a/cxx/CMakeLists.txt +++ b/cxx/CMakeLists.txt @@ -120,10 +120,9 @@ set(CNTR_PROTO_LIB comm_proto) add_library(${CNTR_PROTO_LIB} STATIC ${CNTR_PROTO_LIB_SRC}) set(MOUNT_SERVER_APP_SRC mount.h mount_state.h mount_server.cpp comm_server.h comm_server_endpoint.h comm_server_configfile.h mount_astrom.h - mount_astrom_default.h) + mount_astrom_default.h mcc_coord.h) set(MOUNT_SERVER_APP mount_server) -add_executable(${MOUNT_SERVER_APP} ${MOUNT_SERVER_APP_SRC} - mcc_coord.h) +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) diff --git a/cxx/mcc_coord.h b/cxx/mcc_coord.h index 550c74e..38bc313 100644 --- a/cxx/mcc_coord.h +++ b/cxx/mcc_coord.h @@ -73,28 +73,30 @@ public: // auto ang = MccCoordinate{180.0, mcc_degrees}; MccCoordinate(std::convertible_to auto const& val, const MccDegreeTag tag) { - _angleInRads = val * std::numbers::pi / 180.0; + _angleInRads = val * utils::deg2radCoeff; } - // constuct angle from sexagesimal representation, e.g.: + // constuct angle from sexagesimal representation or floating-point number of degrees, e.g.: // auto ang = MccCoordinate{"-12:34:56.789"}; // from degrees:minutes:seconds + // auto ang = MccCoordinate{"123.574698"}; // from degrees MccCoordinate(traits::mcc_input_char_range auto const& val) { auto res = utils::parsAngleString(val); if (res.has_value()) { - _angleInRads = res.value() * std::numbers::pi / 180.0; + _angleInRads = res.value() * utils::deg2radCoeff; } else { throw std::invalid_argument("invalid sexagesimal representation"); } } - // construct angle from sexagesimal representation, e.g.: + // construct angle from sexagesimal representation or floating-point number of degrees, e.g.: // auto ang = MccCoordinate{"01:23:45.6789", mcc_hms}; // from hours:minutes:seconds + // auto ang = MccCoordinate{"123.574698"}; // from degrees MccCoordinate(traits::mcc_input_char_range auto const& val, const MccHMSTag) { auto res = utils::parsAngleString(val, true); if (res.has_value()) { - _angleInRads = res.value() * std::numbers::pi / 180.0; + _angleInRads = res.value() * utils::deg2radCoeff; } else { throw std::invalid_argument("invalid sexagesimal representation"); } diff --git a/cxx/mount.h b/cxx/mount.h index 2651ad8..ff863c7 100644 --- a/cxx/mount.h +++ b/cxx/mount.h @@ -151,7 +151,7 @@ public: MccMount(traits::mcc_input_char_range auto const& logger_mark = "[MOUNT]", std::shared_ptr logger = spdlog::null_logger_mt("NULL")) - : utils::MccSpdlogLogger(logger), _exitCurrentState([]() {}) + : utils::MccSpdlogLogger(logger), _exitCurrentState([]() {}), _currentStateName([]() {}) { std::istringstream strst; @@ -180,9 +180,15 @@ public: _exitCurrentState(); // exit from current state _exitCurrentState = [&state]() { state.exit(); }; + _currentStateName = [&state]() { return state.name(); }; + state.enter(); } + std::string_view currenStateName() const + { + return _currentStateName(); + } MccMountPosition getMountData() const noexcept { @@ -271,7 +277,7 @@ public: // returns a time to reach the prohibited area: // 0 - already in the zone - // std::chrono::sys_time<>::max() - never reach the zone + // std::chrono::duration<>::max() - never reach the zone // the kind of cordinates (e.g. IRCS or apparent, equatorial or horizontal) is a subject of implementation auto pzTimeTo(const MccCoordinate& xcoord, const MccCoordinate& ycoord, @@ -284,7 +290,7 @@ public: // returns a time to exit the prohibited area: // 0 - already out of the zone - // std::chrono::sys_time<>::max() - the zone itself + // std::chrono::duration<>::max() - the zone itself // the kind of cordinates (e.g. IRCS or apparent, equatorial or horizontal) is a subject of implementation auto pzTimeFrom(const MccCoordinate& xcoord, const MccCoordinate& ycoord, @@ -296,6 +302,12 @@ public: } // above two methods in one call + // returns a std::tuple with elements + // 0 - boolean: true - coordinates in zone, false - otherwise + // 1 - time duration to reach the zone (0 - if already in the zone, chrono::duration<>::max() if never reach the + // zone) + // 2 - time duration to exit the zone (0 - if already out of the zone, chrono::duration<>::max() if never + // exit the zone) auto pzCheck(const MccCoordinate& xcoord, const MccCoordinate& ycoord, traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now()) @@ -342,6 +354,7 @@ protected: // std::shared_ptr _mountLogger; std::function _exitCurrentState; + std::function _currentStateName; // time scales related databases astrom::MccLeapSeconds _leapSecondsDB;