mountcontrol/cxx/asibfm700_hardware.h
2025-07-18 19:05:41 +03:00

129 lines
3.3 KiB
C++

#pragma once
/* AstroSIB-FM700 FORK MOUNT CONTROL LIBRARY */
/* HARDWARE WRAPPER IMPLEMENTATION */
#include "../LibSidServo/sidservo.h"
#include "mcc_mount_concepts.h"
#include "mcc_mount_coord.h"
namespace asibfm700
{
/* error codes enum definition */
enum class AsibFM700HardwareErrorCode : int {
// error codes from sidservo library
ERROR_OK = MCC_E_OK,
ERROR_FATAL = MCC_E_FATAL,
ERROR_BADFORMAT = MCC_E_BADFORMAT,
ERROR_ENCODERDEV = MCC_E_ENCODERDEV,
ERROR_MOUNTDEV = MCC_E_MOUNTDEV,
ERROR_FAILED = MCC_E_FAILED,
// my codes ...
};
// error category
struct AsibFM700HardwareErrorCategory : public std::error_category {
const char* name() const noexcept;
std::string message(int ec) const;
static const AsibFM700HardwareErrorCategory& get();
};
inline std::error_code make_error_code(AsibFM700HardwareErrorCode ec)
{
return std::error_code(static_cast<int>(ec), AsibFM700HardwareErrorCategory::get());
}
} // namespace asibfm700
namespace std
{
template <>
class is_error_code_enum<asibfm700::AsibFM700HardwareErrorCode> : public true_type
{
};
} // namespace std
namespace asibfm700
{
class AsibFM700Hardware final
{
public:
// definitions from concept
typedef std::error_code error_t;
typedef mcc::MccAngle coord_t;
typedef std::chrono::system_clock::time_point time_point_t; // UTC time
struct axes_pos_t {
time_point_t time_point;
coord_t x, y;
};
// c++ish wrapper to 'conf_t' struct
struct device_config_t {
std::string MountDevPath; // path to mount device
int MountDevSpeed; // serial speed
std::string EncoderDevPath; // path to encoder device
int EncoderDevSpeed; // serial speed
int SepEncoder; // ==1 if encoder works as separate serial device, ==2 if there's new version with two devices
std::string EncoderXDevPath; // paths to new controller devices
std::string EncoderYDevPath;
double MountReqInterval; // interval between subsequent mount requests (seconds)
double EncoderReqInterval; // interval between subsequent encoder requests (seconds)
};
struct hardware_config_t {
// the 'char*' fields from conf_t:
// wrap it to std::string
std::string MountDevPath;
std::string EncoderDevPath;
std::string EncoderXDevPath;
std::string EncoderYDevPath;
conf_t devConfig;
hardware_configuration_t hwConfig;
};
AsibFM700Hardware(const hardware_config_t& conf);
~AsibFM700Hardware();
AsibFM700Hardware(const AsibFM700Hardware&) = delete;
AsibFM700Hardware& operator=(const AsibFM700Hardware&) = delete;
AsibFM700Hardware(AsibFM700Hardware&&) = default;
AsibFM700Hardware& operator=(AsibFM700Hardware&&) = default;
std::string_view id() const;
error_t setPos(axes_pos_t);
error_t getPos(axes_pos_t&);
error_t stop();
error_t init();
private:
hardware_config_t _hardwareConfig;
// static void moveInst(AsibFM700Hardware* from, AsibFM700Hardware* to);
};
static_assert(mcc::traits::mcc_mount_hardware_c<AsibFM700Hardware>, "AsibFM700Hardware!!!");
} // namespace asibfm700