This commit is contained in:
Timur A. Fatkhullin 2025-01-27 17:58:39 +03:00
parent e8dfb0de5a
commit 5f404a6291
2 changed files with 60 additions and 0 deletions

View File

@ -49,6 +49,10 @@ static constexpr std::string_view CONTROL_PROTO_STR_TRACK_XVEL = "trackXVEL";
static constexpr std::string_view CONTROL_PROTO_STR_TRACK_YVEL = "trackYVEL"; static constexpr std::string_view CONTROL_PROTO_STR_TRACK_YVEL = "trackYVEL";
static constexpr std::string_view CONTROL_PROTO_STR_STOP = "stop"; static constexpr std::string_view CONTROL_PROTO_STR_STOP = "stop";
// site coordinates
static constexpr std::string_view CONTROL_PROTO_STR_SITE_LON = "siteLON";
static constexpr std::string_view CONTROL_PROTO_STR_SITE_LAT = "siteLAT";
static constexpr std::array CONTROL_PROTO_VALID_COMMAND = {CONTROL_PROTO_STR_SLEW_AZALT, CONTROL_PROTO_STR_SLEW_RADEC}; static constexpr std::array CONTROL_PROTO_VALID_COMMAND = {CONTROL_PROTO_STR_SLEW_AZALT, CONTROL_PROTO_STR_SLEW_RADEC};
class ControlProtoParser class ControlProtoParser

56
cxx/mount.h Normal file
View File

@ -0,0 +1,56 @@
#pragma once
/* MOUNT CONTROL COMPONENTS LIBRARY */
#include <concepts>
#include <cstdint>
#include <functional>
namespace mcc
{
enum class MccMountType : uint8_t { GERMAN_TYPE, FORK_TYPE, CROSSAXIS_TYPE, ALTAZ_TYPE };
// mount state type concept
template <typename T>
concept mcc_mount_state_c = requires(T t, const T t_const) {
typename T::state_id_t;
{ t.ident() } -> std::same_as<typename T::state_id_t>;
typename T::context_t;
{ t.enter(std::declval<const typename T::context_t&>()) } -> std::same_as<void>;
{ t.exit(std::declval<const typename T::context_t&>()) } -> std::same_as<void>;
};
// implements a Finite State Machine Pattern
template <MccMountType MOUNT_TYPE>
class MccMount
{
public:
static constexpr MccMountType mountType = MOUNT_TYPE;
MccMount()
{
_exitCurrentState = []() {}; // do nothing
}
virtual ~MccMount() {}
template <mcc_mount_state_c StateT>
void setMountState(StateT& state)
{
_exitCurrentState(); // exit from current state
_exitCurrentState = [&state, this]() { state.exit(this); };
state.enter(this);
}
protected:
std::function<void()> _exitCurrentState;
};
} // namespace mcc