From c0cba8422ff870f857a494a1510aa6c19eaa6240 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Thu, 20 Mar 2025 17:11:17 +0300 Subject: [PATCH] ... --- cxx/CMakeLists.txt | 2 +- cxx/mcc_traits.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++ cxx/mount.h | 26 ++++++++++------- cxx/mount_astrom.h | 8 ------ cxx/mount_state.h | 60 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 19 deletions(-) create mode 100644 cxx/mount_state.h diff --git a/cxx/CMakeLists.txt b/cxx/CMakeLists.txt index 37bc5f3..c685406 100644 --- a/cxx/CMakeLists.txt +++ b/cxx/CMakeLists.txt @@ -114,7 +114,7 @@ set(CNTR_PROTO_LIB_SRC set(CNTR_PROTO_LIB comm_proto) add_library(${CNTR_PROTO_LIB} STATIC ${CNTR_PROTO_LIB_SRC}) -set(MOUNT_SERVER_APP_SRC mount.h mount_server.cpp comm_server.h comm_server_endpoint.h comm_server_configfile.h mount_astrom.h +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) set(MOUNT_SERVER_APP mount_server) add_executable(${MOUNT_SERVER_APP} ${MOUNT_SERVER_APP_SRC}) diff --git a/cxx/mcc_traits.h b/cxx/mcc_traits.h index 784ff59..b27dfdb 100644 --- a/cxx/mcc_traits.h +++ b/cxx/mcc_traits.h @@ -38,5 +38,76 @@ concept mcc_formattable = requires(T v, std::format_context ctx) { std::formatter>().format(v, ctx); }; +/* a callable concept and its signature traits */ + +template +concept mcc_is_callable = std::is_function_v || (std::is_object_v && requires(T) { &T::operator(); }); + + +// helper classes for callable signature deducing +template +struct mcc_func_traits_helper_t; + +template +struct mcc_func_traits_helper_t { + using ret_t = R; + using args_t = std::tuple<>; + using arg1_t = void; + static constexpr size_t arity = 0; +}; + +template +struct mcc_func_traits_helper_t { + using ret_t = R; + using args_t = std::tuple; + using arg1_t = Arg; + static constexpr size_t arity = sizeof...(Args) + 1; +}; + +template +struct mcc_func_traits { + // use of an empty struct here to match std::invoke_result behaivior (at least of GCC) +}; + +template +struct mcc_func_traits : mcc_func_traits_helper_t { +}; + +template +struct mcc_func_traits : mcc_func_traits_helper_t { +}; + +template +struct mcc_func_traits : mcc_func_traits_helper_t { +}; + +template +struct mcc_func_traits : mcc_func_traits_helper_t { +}; + +template + requires mcc_is_callable +struct mcc_func_traits : mcc_func_traits { +}; + +// reference/const ref and rvalue helpers +template +struct mcc_func_traits : mcc_func_traits { +}; + +template +struct mcc_func_traits : mcc_func_traits { +}; + +template +struct mcc_func_traits : mcc_func_traits { +}; + +template +using mcc_retval_t = typename mcc_func_traits::ret_t; + +template +using mcc_func_arg1_t = typename mcc_func_traits::arg1_t; + } // namespace mcc::traits diff --git a/cxx/mount.h b/cxx/mount.h index b9de92d..d97d773 100644 --- a/cxx/mount.h +++ b/cxx/mount.h @@ -6,20 +6,19 @@ #include #include #include -#include #include #include #include "spdlog/sinks/null_sink.h" #include "mcc_spdlog.h" +#include "mcc_traits.h" #include "mount_astrom.h" -#include "mount_astrom_default.h" // low-level functions -namespace lowlevel -{ -#include "../LibSidServo/sidservo.h" -} // namespace lowlevel +// namespace lowlevel +// { +// #include "../LibSidServo/sidservo.h" +// } // namespace lowlevel @@ -29,11 +28,16 @@ namespace mcc namespace traits { + // mount state type concept template concept mcc_mount_state_c = requires(T t, const T t_const) { { t_const.ident() } -> std::same_as; + // requires mcc_is_callable; + // requires mcc_is_callable; + // requires mcc_is_callable; + { t.enter() } -> std::same_as; { t.exit() } -> std::same_as; }; @@ -78,17 +82,19 @@ struct MccMountPosition { mnt_coord_t mntAZ, mntZD; // encoder-measured current mount moving speed (in radians/s) - mnt_speed_t mntSpeedX, - mntSpeedY; // X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ZD for horizontal-type one + // X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ZD for horizontal-type one + mnt_speed_t mntSpeedX, mntSpeedY; - // current refraction coefficient + // current refraction coefficient (for tagZD) mnt_coord_t currRefr; // PCS (pointing correction system) corrections - mnt_coord_t pcsX, pcsY; // X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ZD for horizontal-type one + // X - HA, Y - DEC for equatorial-type mount; X - AZ, Y - ZD for horizontal-type one + mnt_coord_t pcsX, pcsY; }; + /* MOUNT BASE TEMPLATED CLASS WITH BASIC FUNCTIONALITY */ enum class MccMountType : uint8_t { GERMAN_TYPE, FORK_TYPE, CROSSAXIS_TYPE, ALTAZ_TYPE }; diff --git a/cxx/mount_astrom.h b/cxx/mount_astrom.h index 35e6195..c1cb211 100644 --- a/cxx/mount_astrom.h +++ b/cxx/mount_astrom.h @@ -69,17 +69,9 @@ static int mcc_julday(const std::chrono::system_clock::time_point& start_time, int64_t id = (unsigned)ymd.day(); int64_t iy = (int)ymd.year(); - // my = (im - 14) / 12; - // iypmy = (long) (iy + my); - int64_t my = (im - 14LL) / 12LL; int64_t iypmy = iy + my; - // (1461L * (iypmy + 4800L)) / 4L - // + (367L * (long) (im - 2 - 12 * my)) / 12L - // - (3L * ((iypmy + 4900L) / 100L)) / 4L - // + (long) id - 2432076L - // integer part of result MJD int64_t mjd_int = (1461LL * (iypmy + 4800LL)) / 4LL + (367LL * (im - 2LL - 12LL * my)) / 12LL - (3LL * ((iypmy + 4900LL) / 100LL)) / 4LL + id - 2432076LL; diff --git a/cxx/mount_state.h b/cxx/mount_state.h new file mode 100644 index 0000000..2effc3b --- /dev/null +++ b/cxx/mount_state.h @@ -0,0 +1,60 @@ +#pragma once + +#include "mount.h" + + +namespace mcc::traits +{ + +template +concept mcc_mount_c = std::derived_from>; + +} // namespace mcc::traits + +namespace mcc +{ + +class MccMountAbstractState +{ + std::function _getMountStateFunc{[]() {}}; + +public: + typedef std::error_code mount_state_error_t; + + typedef std::function enter_callback_t; + typedef std::function exit_callback_t; + typedef std::function error_callback_t; + + // helper + static constexpr auto mcc_noop_callback = [](const mount_state_error_t&) {}; + + template + MccMountAbstractState(traits::mcc_mount_c auto* mount_ptr, + std::convertible_to auto&& enter_callback, + std::convertible_to auto&& exit_callback, + std::convertible_to auto&& error_callback) + { + _getMountStateFunc = [&mount_ptr, this]() { auto mstate = mount_ptr->getMountData(); }; + } + + + virtual ~MccMountAbstractState() = default; + + + std::string_view ident() const + { + return "MCC-ABSTRACT-MOUNT-STATE"; + } + + + void enter() {} + + void exit() {} + +protected: + enter_callback_t _enterCallback{[](const mount_state_error_t&) {}}; + exit_callback_t _exitCallback{[](const mount_state_error_t&) {}}; + error_callback_t _errorCallback{[](const mount_state_error_t&) {}}; +}; + +} // namespace mcc