198 lines
4.4 KiB
C++
198 lines
4.4 KiB
C++
#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>>;
|
|
|
|
template <typename T>
|
|
concept mcc_mount_c = requires {
|
|
typename T::mount_config_t;
|
|
requires std::same_as<decltype(T::mountType), MccMountType>;
|
|
requires std::derived_from<T, mcc::MccMount<T::mountType, typename T::mount_config_t>>;
|
|
};
|
|
|
|
} // namespace mcc::traits
|
|
|
|
namespace mcc
|
|
{
|
|
|
|
class MccMountAbstractState
|
|
{
|
|
std::function<void()> _getMountDataFunc{[]() {}};
|
|
|
|
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&) {};
|
|
|
|
MccMountAbstractState(traits::mcc_mount_c auto* mount_ptr,
|
|
std::convertible_to<enter_callback_t> auto&& enter_callback = mcc_noop_callback,
|
|
std::convertible_to<exit_callback_t> auto&& exit_callback = mcc_noop_callback,
|
|
std::convertible_to<error_callback_t> auto&& error_callback = mcc_noop_callback)
|
|
: _enterCallback(std::forward<enter_callback_t>(enter_callback)),
|
|
_exitCallback(std::forward<exit_callback_t>(exit_callback)),
|
|
_errorCallback(std::forward<error_callback_t>(error_callback))
|
|
{
|
|
_getMountDataFunc = [&mount_ptr, this]() { auto mstate = mount_ptr->getMountData(); };
|
|
}
|
|
|
|
|
|
virtual ~MccMountAbstractState() = default;
|
|
|
|
|
|
std::string_view ident() const
|
|
{
|
|
return "MCC-MOUNT-ABSTRACT-STATE";
|
|
}
|
|
|
|
|
|
void enter() {}
|
|
|
|
void exit() {}
|
|
|
|
// #ifdef __cpp_explicit_this_parameter
|
|
// #if __cpp_explicit_this_parameter >= 202110L
|
|
// void aaa() {}
|
|
// #endif
|
|
// #endif
|
|
|
|
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&) {}};
|
|
};
|
|
|
|
|
|
/* */
|
|
class MccMountStateIDLE
|
|
{
|
|
public:
|
|
std::string_view ident() const
|
|
{
|
|
return "MCC-MOUNT-STATE-IDLE";
|
|
}
|
|
};
|
|
|
|
|
|
/* */
|
|
class MccMountStateStoping
|
|
{
|
|
public:
|
|
typedef std::string state_data_t;
|
|
|
|
MccMountStateStoping(traits::mcc_input_char_range auto const& reason) : _reason({reason.begin(), reason.end()}) {}
|
|
|
|
MccMountStateStoping(const char* reason) : MccMountStateStoping(std::string_view{reason}) {}
|
|
|
|
|
|
std::string_view ident() const
|
|
{
|
|
return "MCC-MOUNT-STATE-STOPING";
|
|
}
|
|
|
|
void enter() {}
|
|
|
|
void exit() {}
|
|
|
|
void stop() {}
|
|
|
|
state_data_t stateData()
|
|
{
|
|
return _reason;
|
|
}
|
|
|
|
protected:
|
|
std::string _reason;
|
|
};
|
|
|
|
|
|
/* */
|
|
class MccMountStateStopped
|
|
{
|
|
public:
|
|
typedef std::string state_data_t;
|
|
|
|
MccMountStateStopped(traits::mcc_input_char_range auto const& reason) : _reason({reason.begin(), reason.end()}) {}
|
|
|
|
MccMountStateStopped(const char* reason) : MccMountStateStopped(std::string_view{reason}) {}
|
|
|
|
|
|
std::string_view ident() const
|
|
{
|
|
return "MCC-MOUNT-STATE-STOPPED";
|
|
}
|
|
|
|
void enter() {}
|
|
|
|
void exit() {}
|
|
|
|
void stop() {}
|
|
|
|
state_data_t stateData()
|
|
{
|
|
return _reason;
|
|
}
|
|
|
|
protected:
|
|
std::string _reason;
|
|
};
|
|
|
|
|
|
|
|
/* */
|
|
class MccMountStateSlew
|
|
{
|
|
public:
|
|
struct slew_state_params_t {
|
|
MccCoordPairKind coordKind{MccCoordPairKind::COORDS_KIND_RADEC_APP};
|
|
MccAngle x, y; // according to 'coordKind'
|
|
|
|
bool stop{false}; // stop after
|
|
};
|
|
|
|
MccMountStateSlew(traits::mcc_mount_c auto& mount,
|
|
const slew_state_params_t& params,
|
|
std::string_view ident = "MCC-MOUNT-STATE-SLEW")
|
|
: _ident(ident)
|
|
{
|
|
_stopFunc = [&mount]() {
|
|
//
|
|
mount.setMountState(MccMountStateStopped("stop pointing"));
|
|
};
|
|
}
|
|
|
|
std::string_view ident() const
|
|
{
|
|
return _ident;
|
|
}
|
|
|
|
void enter() {}
|
|
|
|
void exit() {}
|
|
|
|
void stop() {}
|
|
|
|
protected:
|
|
std::string_view _ident;
|
|
|
|
std::function<void()> _stopFunc;
|
|
};
|
|
|
|
|
|
template <MccMountType MOUNT_TYPE, std::derived_from<MccMountConfig> CONFIG_TYPE = MccMountConfig>
|
|
class MccMountStateSlew1 : public MccMount<MOUNT_TYPE, CONFIG_TYPE>::MccMountState
|
|
{
|
|
};
|
|
|
|
} // namespace mcc
|