...
This commit is contained in:
parent
e1c546123e
commit
c0cba8422f
@ -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})
|
||||
|
||||
@ -38,5 +38,76 @@ concept mcc_formattable =
|
||||
requires(T v, std::format_context ctx) { std::formatter<std::remove_cvref_t<T>>().format(v, ctx); };
|
||||
|
||||
|
||||
/* a callable concept and its signature traits */
|
||||
|
||||
template <typename T>
|
||||
concept mcc_is_callable = std::is_function_v<T> || (std::is_object_v<T> && requires(T) { &T::operator(); });
|
||||
|
||||
|
||||
// helper classes for callable signature deducing
|
||||
template <typename... Ts>
|
||||
struct mcc_func_traits_helper_t;
|
||||
|
||||
template <typename R>
|
||||
struct mcc_func_traits_helper_t<R> {
|
||||
using ret_t = R;
|
||||
using args_t = std::tuple<>;
|
||||
using arg1_t = void;
|
||||
static constexpr size_t arity = 0;
|
||||
};
|
||||
|
||||
template <typename R, typename Arg, typename... Args>
|
||||
struct mcc_func_traits_helper_t<R, Arg, Args...> {
|
||||
using ret_t = R;
|
||||
using args_t = std::tuple<Arg, Args...>;
|
||||
using arg1_t = Arg;
|
||||
static constexpr size_t arity = sizeof...(Args) + 1;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
struct mcc_func_traits {
|
||||
// use of an empty struct here to match std::invoke_result behaivior (at least of GCC)
|
||||
};
|
||||
|
||||
template <typename R, typename... Args>
|
||||
struct mcc_func_traits<R (*)(Args...)> : mcc_func_traits_helper_t<R, Args...> {
|
||||
};
|
||||
|
||||
template <typename R, typename... Args>
|
||||
struct mcc_func_traits<R(Args...)> : mcc_func_traits_helper_t<R, Args...> {
|
||||
};
|
||||
|
||||
template <typename C, typename R, typename... Args>
|
||||
struct mcc_func_traits<R (C::*)(Args...)> : mcc_func_traits_helper_t<R, Args...> {
|
||||
};
|
||||
|
||||
template <typename C, typename R, typename... Args>
|
||||
struct mcc_func_traits<R (C::*)(Args...) const> : mcc_func_traits_helper_t<R, Args...> {
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
requires mcc_is_callable<F>
|
||||
struct mcc_func_traits<F> : mcc_func_traits<decltype(&F::operator())> {
|
||||
};
|
||||
|
||||
// reference/const ref and rvalue helpers
|
||||
template <typename F>
|
||||
struct mcc_func_traits<F&> : mcc_func_traits<F> {
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
struct mcc_func_traits<const F&> : mcc_func_traits<F> {
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
struct mcc_func_traits<F&&> : mcc_func_traits<F> {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using mcc_retval_t = typename mcc_func_traits<T>::ret_t;
|
||||
|
||||
template <typename T>
|
||||
using mcc_func_arg1_t = typename mcc_func_traits<T>::arg1_t;
|
||||
|
||||
|
||||
} // namespace mcc::traits
|
||||
|
||||
26
cxx/mount.h
26
cxx/mount.h
@ -6,20 +6,19 @@
|
||||
#include <chrono>
|
||||
#include <concepts>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
#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 <typename T>
|
||||
concept mcc_mount_state_c = requires(T t, const T t_const) {
|
||||
{ t_const.ident() } -> std::same_as<std::string_view>;
|
||||
|
||||
// requires mcc_is_callable<typename T::error_callback_t>;
|
||||
// requires mcc_is_callable<typename T::enter_callback_t>;
|
||||
// requires mcc_is_callable<typename T::exit_callback_t>;
|
||||
|
||||
{ t.enter() } -> std::same_as<void>;
|
||||
{ t.exit() } -> std::same_as<void>;
|
||||
};
|
||||
@ -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 };
|
||||
|
||||
@ -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;
|
||||
|
||||
60
cxx/mount_state.h
Normal file
60
cxx/mount_state.h
Normal file
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "mount.h"
|
||||
|
||||
|
||||
namespace mcc::traits
|
||||
{
|
||||
|
||||
template <typename T, mcc::MccMountType MOUNT_TYPE>
|
||||
concept mcc_mount_c = std::derived_from<T, mcc::MccMount<MOUNT_TYPE>>;
|
||||
|
||||
} // namespace mcc::traits
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
|
||||
class MccMountAbstractState
|
||||
{
|
||||
std::function<void()> _getMountStateFunc{[]() {}};
|
||||
|
||||
public:
|
||||
typedef std::error_code mount_state_error_t;
|
||||
|
||||
typedef std::function<void(const mount_state_error_t&)> enter_callback_t;
|
||||
typedef std::function<void(const mount_state_error_t&)> exit_callback_t;
|
||||
typedef std::function<void(const mount_state_error_t&)> error_callback_t;
|
||||
|
||||
// helper
|
||||
static constexpr auto mcc_noop_callback = [](const mount_state_error_t&) {};
|
||||
|
||||
template <MccMountType MOUNT_TYPE>
|
||||
MccMountAbstractState(traits::mcc_mount_c<MOUNT_TYPE> auto* mount_ptr,
|
||||
std::convertible_to<enter_callback_t> auto&& enter_callback,
|
||||
std::convertible_to<exit_callback_t> auto&& exit_callback,
|
||||
std::convertible_to<error_callback_t> 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
|
||||
Loading…
x
Reference in New Issue
Block a user